Author: bblfish
Date: Thu May 12 13:58:20 2011
New Revision: 1102309
URL: http://svn.apache.org/viewvc?rev=1102309&view=rev
Log:
CLEREZZA-509: pingback protocol. A lot of it had been implemented previously.
But now it's at the stage where I can send a ping to someone. to test it, enter
someone's URI eg http://fcns.eu/people/andrei/card#me (he has a pingback
endpoint) in the profile panel person viewer, add him to your friends, then you
can click the "ping" link next to his image that will appear on your profile.
You will arive on a form where you need to enter your webid and his and a
message you can send him. If these are chosen carefully it will work.... Well
the fields should be filled in autoamtically, and a picture of the person you
are to ping should appear there too...
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/pom.xml
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/resources/OSGI-INF/serviceComponents.xml
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/PersonPanel.scala
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/PingBack.scala
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/person_panel.scala
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ping_back_collection_panel.scala
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/pom.xml?rev=1102309&r1=1102308&r2=1102309&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/pom.xml
(original)
+++
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/pom.xml
Thu May 12 13:58:20 2011
@@ -155,5 +155,9 @@
<groupId>org.apache.clerezza</groupId>
<artifactId>platform.security.foafssl.ontologies</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.clerezza.ext</groupId>
+ <artifactId>slf4j-scala-api</artifactId>
+ </dependency>
</dependencies>
</project>
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/resources/OSGI-INF/serviceComponents.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/resources/OSGI-INF/serviceComponents.xml?rev=1102309&r1=1102308&r2=1102309&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/resources/OSGI-INF/serviceComponents.xml
(original)
+++
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/resources/OSGI-INF/serviceComponents.xml
Thu May 12 13:58:20 2011
@@ -86,7 +86,10 @@
<property name="javax.ws.rs" type="Boolean" value="true"/>
<property name="service.pid"
value="org.apache.clerezza.platform.accountcontrolpanel.PingBack"/>
<reference name="tcManager"
interface="org.apache.clerezza.rdf.core.access.TcManager"
- cardinality="1..1" policy="static" bind="bindTcManager"
unbind="unbindTcManager"/>
+ cardinality="1..1" policy="static" bind="bindTcManager"
unbind="unbindTcManager"/>
+ <reference name="webProxy"
interface="org.apache.clerezza.rdf.web.proxy.WebProxy"
+ cardinality="1..1" policy="static" bind="bindWebProxy"
unbind="unbindWebProxy"/>
+
</scr:component>
<scr:component enabled="true"
name="org.apache.clerezza.platform.accountcontrolpanel.ping_back_panel">
<implementation
class="org.apache.clerezza.platform.accountcontrolpanel.ping_back_collection_panel"/>
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/PersonPanel.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/PersonPanel.scala?rev=1102309&r1=1102308&r2=1102309&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/PersonPanel.scala
(original)
+++
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/PersonPanel.scala
Thu May 12 13:58:20 2011
@@ -43,7 +43,7 @@ object PersonPanel {
* @author bblfish
*/
@Path("/user/{id}/people")
-class PersonPanel {
+class PersonPanel {
protected def activate(componentContext: ComponentContext): Unit = {
// this.componentContext = componentContext
}
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/PingBack.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/PingBack.scala?rev=1102309&r1=1102308&r2=1102309&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/PingBack.scala
(original)
+++
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/PingBack.scala
Thu May 12 13:58:20 2011
@@ -22,23 +22,28 @@ import org.apache.clerezza.platform.acco
import org.apache.clerezza.rdf.core.access.{NoSuchEntityException, TcManager}
import org.apache.clerezza.rdf.ontologies.{SIOC, PLATFORM, RDF}
import org.osgi.service.component.ComponentContext
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
import org.apache.clerezza.rdf.core.access.security.TcPermission
import org.apache.clerezza.platform.Constants
import java.security.{PrivilegedAction, AccessController}
import javax.ws.rs.core.{Response, Context, UriInfo}
-import org.apache.clerezza.rdf.core.{MGraph, UriRef}
-import javax.ws.rs.{PathParam, FormParam, POST, QueryParam, GET, Path}
-import java.net.URI
import org.apache.clerezza.rdf.utils.{UnionMGraph, GraphNode}
import org.apache.clerezza.rdf.core.impl.SimpleMGraph
+import org.apache.clerezza.rdf.scala.utils.{EasyGraphNode, EasyGraph}
+import org.apache.clerezza.rdf.web.proxy.WebProxy
+import java.util.Iterator
+import org.apache.clerezza.rdf.core.{Triple, MGraph, UriRef}
+import java.net._
+import org.slf4j.scala.Logger
+import javax.ws.rs._
+import java.io.{StringWriter, IOException, OutputStreamWriter}
+import collection.JavaConversions._
+import java.lang.Appendable
object PingBack {
- private val logger: Logger = LoggerFactory.getLogger(classOf[PingBack])
+ private val log: Logger = Logger(classOf[PingBack])
- val classPathTemplate =
classOf[PingBack].getAnnotation(classOf[Path]).value
+ val pingPathTemplate =
classOf[PingBack].getAnnotation(classOf[Path]).value
val regex = """\{([^}]+)\}""".r
// taken from
http://dcsobral.blogspot.com/2010/01/string-interpolation-in-scala-with.html
@@ -46,6 +51,32 @@ object PingBack {
val it = values.iterator
regex.replaceAllIn(text, _ => it.next)
}
+
+ /**
+ * replace the name in the path with the id of the user, in order to
get his ping collection
+ * and return the full uri for it
+ *
+ * This also suggests that support for relative URIs in the graphs
should be supported
+ *
+ * This is not written with all the tools available to someone with
access to
+ * a full UriInfo implementation or Jersey's ExtendedUriInfo as triaxrs
implementation
+ * UriInfoImpl has many methods that are not yet implemented.
+ * Apparently if they were one could use getMatchedURIs or one of those
methods to build this
+ * more cleanly.
+ * Perhaps one should look at
http://incubator.apache.org/wink/index.html implementations...
+ *
+ * Currently this assumes that the path of the class is a root class,
ie, that it starts with /
+ *
+ * @param id the value of the parameter to replace in the string taken
from the @Path in the class
+ * @param uriInfo the info from the method that called this
+ * @return the full URI of the ping collection as a string
+ */
+ def pingCollUri(id: String, uriInfo: UriInfo): String = {
+ val path = interpolate(pingPathTemplate, id)
+ val uriStr = uriInfo.getBaseUri.resolve(path); //a bit
expensive for something so simple
+ uriStr.toString
+ }
+
}
/**
@@ -66,12 +97,12 @@ class PingBack {
/**
- * The ping form, where you can POST new pings
+ * The ping collection graph, where new pings can be posted and saved
*/
- def pingGraphNode(id: String, uriInfo: UriInfo): GraphNode = {
+ def pingCollection(id: String, uriInfo: UriInfo): EasyGraphNode = {
val pingRef = new UriRef(pingCollUri(id, uriInfo))
- val resultNode: GraphNode = new GraphNode(pingRef,
pingColl(pingRef))
- resultNode
+ val pingCollG: EasyGraph = pingColl(pingRef)
+ pingCollG(pingRef)
}
@GET
@@ -79,20 +110,17 @@ class PingBack {
def pingForm(@Context uriInfo: UriInfo,
@QueryParam("uri") uri: UriRef,
@PathParam("id") id: String):
GraphNode = {
- val resultNode: GraphNode = pingGraphNode(id, uriInfo)
- resultNode.addProperty(RDF.`type`, PLATFORM.HeadedPage)
- resultNode.addProperty(RDF.`type`, PINGBACK.Container)
- return resultNode
+ ( pingCollection(id, uriInfo) â PLATFORM.HeadedPage
+ â PINGBACK.Container )
}
-
/**
* get Ping Collection
*/
- def pingColl(pingCollRef: UriRef): MGraph = {
- AccessController.doPrivileged(new PrivilegedAction[MGraph] {
+ def pingColl(pingCollRef: UriRef): EasyGraph = {
+ val tcgraph =AccessController.doPrivileged(new
PrivilegedAction[MGraph] {
def run: MGraph = try {
tcManager.getMGraph(pingCollRef)
} catch {
@@ -105,26 +133,78 @@ class PingBack {
}
}
})
+ new EasyGraph(tcgraph)
}
/**
- * This is not written with all the tools available to someone with
access to
- * a full UriInfo implementation or Jersey's ExtendedUriInfo as triaxrs
implementation
- * UriInfoImpl has many methods that are not yet implemented.
- * Apparently if they were one could use getMatchedURIs or one of those
methods to build this
- * more cleanly.
- * Perhaps one should look at
http://incubator.apache.org/wink/index.html implementations...
- *
- * Currently this assumes that the path of the class is a root class,
ie, that it starts with /
+ *send a ping to another endpoint
*/
- def pingCollUri(id: String, uriInfo: UriInfo): String = {
- val path = interpolate(classPathTemplate, id)
- val uriStr = uriInfo.getBaseUri.resolve(path); //a bit
expensive for something so simple
- System.out.println("res=" + uriStr)
- uriStr.toString
+ @POST
+ @Produces(Array("text/plain"))
+ def pingSomeone(@FormParam("to") pingTo: UriRef,
+ @FormParam("source") source: UriRef,
+ @FormParam("target") target: UriRef,
+ @FormParam("comment") comment: String): String = {
+ val wr = new StringBuilder()
+ wr append "Sent ping to " append pingTo append "\r\n"
+ wr append "with following parameters:"
+ wr append "Source=" append source append "\r\n"
+ wr append "target=" append target append "\r\n"
+ wr append "comment=" append comment append "\r\n"
+
+ val pingInfo = webProxy.getResourceInfo(pingTo)
+ //initially I just test if something about pingback is there.
+ //todo: make the subject the resource itself.
+ val filter = pingInfo.theGraph.filter(null, RDF.`type`,
PINGBACK.Container)
+ val res = if (filter.hasNext) try {
+ val to = new URL(pingTo.getUnicodeString)
+ if (to.getProtocol == "http" || to.getProtocol ==
"https") {
+ val toReq =
to.openConnection().asInstanceOf[HttpURLConnection]
+ toReq.setConnectTimeout(2 * 1000)
+ toReq.setReadTimeout(5 * 1000)
+ postData(toReq,
+ Map("source" ->
source.getUnicodeString,
+ "target" ->
source.getUnicodeString,
+ "comment" -> comment))
+ wr append "\r\n"
+ wr append "response is"
+ wr append "\r\n"
+ for ((header, list) <- toReq.getHeaderFields) {
+ for (e <- list) wr append header
append ":" append e append "\r\n"
+ }
+ wr append("\r\n\r\n")
+ wr append { for ( line <- new
scala.io.BufferedSource(toReq.getInputStream).getLines) yield line
}.mkString("\r\n")
+ wr
+ } else {
+ "wrong URL type" + pingTo
+ }
+
+ } catch {
+ case e: MalformedURLException => "error: was asked to
ping an endpoint with a malformed URL "+pingTo
+ case io: IOException => "IO exception connecting to
"+io.toString
+ case t: SocketTimeoutException => "Connection is taking
too long to "+pingTo
+ } else { //not a pingback endpoint
+ "the endpoint does not specify itself as a pingback endpoint"
+ }
+ wr append res
+ wr.toString()
+ }
+
+
+ private def postData(conn: HttpURLConnection, attrVals:
Map[String,String]) {
+ conn.setDoOutput(true)
+ conn.connect()
+ val wr = new OutputStreamWriter(conn.getOutputStream())
+ wr.write(encodePostData(attrVals))
+ wr.flush
+ wr.close
}
+ private def encodePostData(data: Map[String, String]) = {
+ import java.net.URLEncoder.encode
+ (for ((name, value) <- data) yield encode(name, "UTF-8") + "=" +
encode(value, "UTF-8")).mkString("&")
+ }
/**
* Add a new Ping Item
@@ -141,30 +221,38 @@ class PingBack {
//create a new Resource for this ping (we'll use time stamps to
get going)
- val pingCollStr: String = pingCollUri(id, uriInfo)
- val pingItem = new UriRef(pingCollStr + "/ts" +
System.currentTimeMillis)
+ val pingCollUriStr: String = pingCollUri(id, uriInfo)
+ val pingItem = new UriRef(pingCollUriStr + "/ts" +
System.currentTimeMillis)
//build the graph and add to the store if ok
- val itemNde: GraphNode = new GraphNode(pingItem, pingColl(new
UriRef(pingCollStr)))
- itemNde.addProperty(RDF.`type`, PINGBACK.Item)
- itemNde.addProperty(PINGBACK.source, source)
- itemNde.addProperty(PINGBACK.target, target)
- itemNde.addPropertyValue(SIOC.content, comment)
- itemNde.addInverseProperty(SIOC.container_of,new
UriRef(pingCollStr))
+ val pingColGr = pingColl(new UriRef(pingCollUriStr))
+ val item = (
+ pingColGr(pingItem) â PINGBACK.Item
+ â PINGBACK.source â¶ source
+ â PINGBACK.target â¶ target
+ â SIOC.content â¶ comment
+ âµ SIOC.container_of â pingCollUriStr)
+
+ val resultNode = item.protect() â PLATFORM.HeadedPage
- val resultNode = new GraphNode(pingItem,new UnionMGraph(new
SimpleMGraph(),itemNde.getGraph))
- resultNode.addProperty(RDF.`type`, PLATFORM.HeadedPage)
//response
Response.ok(resultNode).header("Content-Location",new
URI(pingItem.getUnicodeString).getPath).build()
}
+ /**
+ * view a collection. This will return a collection of pings and a form
+ * @param to if this is set then it will filter the pings sent to that
endpoint and the form will sent something there
+ * @param uriInfo: set by jsr311
+ * @return a GraphNode -- still to be worked out what should be put in
there precisely
+ */
@GET
def viewCollection(@Context uriInfo: UriInfo,
+ @QueryParam("to") to: UriRef,
@PathParam("id") id:
String): GraphNode = {
- val resultNode: GraphNode = pingGraphNode(id,uriInfo )
- resultNode.addProperty(RDF.`type`, PLATFORM.HeadedPage)
- resultNode.addProperty(RDF.`type`, PINGBACK.Container)
- return resultNode
+ val gn = (pingCollection(id,uriInfo ) â PLATFORM.HeadedPage
+
â PINGBACK.Container )
+ if (to != null) gn â PINGBACK.to â¶ to
+ else gn
}
@POST
@@ -172,9 +260,8 @@ class PingBack {
def deleteItems(@Context uriInfo: UriInfo,
@PathParam("id") id: String,
@FormParam("item") items:
java.util.List[UriRef]): GraphNode= {
- import collection.JavaConversions._
- val pingColl: GraphNode = pingGraphNode(id,uriInfo )
+ val pingColl: GraphNode = pingCollection(id,uriInfo )
//todo: verify if access is allowed
for(item <- items) {
new GraphNode(item,pingColl.getGraph).deleteNodeContext
@@ -190,18 +277,14 @@ class PingBack {
@Path("{item}")
def viewPing(@Context uriInfo: UriInfo,
@PathParam("id") id: String,
- @PathParam("item") item: String):
GraphNode = {
+ @PathParam("item") item: String):
EasyGraphNode = {
//ITS the wrong ping collection!!!
- val resultNode: GraphNode = new GraphNode(
- new UriRef(uriInfo.getAbsolutePath.toString),
- pingColl(new UriRef(pingCollUri(id, uriInfo)))
- )
- resultNode.addProperty(RDF.`type`, PLATFORM.HeadedPage)
- resultNode.addProperty(RDF.`type`, PINGBACK.Item)
- return resultNode
-
+ val pinG = pingColl(new UriRef(pingCollUri(id, uriInfo)))
+ ( pinG(new UriRef(uriInfo.getAbsolutePath.toString))â
PLATFORM.HeadedPage
+ â
PINGBACK.Item
+ )
}
protected var tcManager: TcManager = null;
@@ -214,4 +297,14 @@ class PingBack {
this.tcManager = null
}
+ protected var webProxy: WebProxy = null;
+
+ protected def bindWebProxy(proxy: WebProxy) = {
+ this.webProxy = proxy
+ }
+
+ protected def unbindWebProxy(proxy: WebProxy ) = {
+ this.webProxy = null
+ }
+
}
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala?rev=1102309&r1=1102308&r2=1102309&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala
(original)
+++
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala
Thu May 12 13:58:20 2011
@@ -21,6 +21,7 @@ package org.apache.clerezza.platform.acc
import java.util.List
import java.util.Arrays
import java.util.Iterator
+import ontologies.{PINGBACK, CONTROLPANEL}
import org.apache.clerezza.platform.security.UserUtil
import org.apache.clerezza.ssl.keygen.CertSerialisation
import org.apache.clerezza.ssl.keygen.Certificate
@@ -28,7 +29,6 @@ import org.apache.clerezza.foafssl.ontol
import org.apache.clerezza.foafssl.ontologies.RSA
import org.apache.clerezza.jaxrs.utils.RedirectUtil
import org.apache.clerezza.jaxrs.utils.TrailingSlash
-import org.apache.clerezza.platform.accountcontrolpanel.ontologies.CONTROLPANEL
import org.apache.clerezza.platform.config.PlatformConfig
import org.apache.clerezza.platform.usermanager.UserManager
import org.apache.clerezza.rdf.core._
@@ -56,6 +56,7 @@ import org.apache.clerezza.rdf.ontologie
import org.apache.clerezza.ssl.keygen.KeygenService
import org.apache.clerezza.platform.users.WebIdGraphsService
import java.net.URI
+import org.apache.clerezza.rdf.scala.utils.{EasyGraphNode, EasyGraph}
object ProfilePanel {
private val logger: Logger =
LoggerFactory.getLogger(classOf[ProfilePanel])
@@ -71,37 +72,45 @@ object ProfilePanel {
class ProfilePanel {
import ProfilePanel.logger
+ import EasyGraph._
@GET
def getPersonalProfilePage(@Context uriInfo: UriInfo,
@PathParam(value = "id") userName: String):
GraphNode = {
TrailingSlash.enforceNotPresent(uriInfo)
- var resultNode: GraphNode = getPersonalProfile(userName, new
UriRef(uriInfo.getAbsolutePath.toString))
+ var resultNode: GraphNode = getPersonalProfile(userName,
uriInfo)
resultNode.addProperty(RDF.`type`, PLATFORM.HeadedPage)
resultNode.addProperty(RDF.`type`, CONTROLPANEL.ProfilePage)
return resultNode
}
+ //todo: there is a bit of repetition in the graphs, and it is not clear
why these relations should not go straight into the DB. What should, what
should not?
private def getPersonalProfile(userName: String,
- profile: UriRef): GraphNode = {
- return AccessController.doPrivileged(new
PrivilegedAction[GraphNode] {
- def run: GraphNode = {
- val userInSystemGraph: GraphNode =
userManager.getUserInSystemGraph(userName)
- val userNodeInSystemGraph: NonLiteral =
userInSystemGraph.getNode.asInstanceOf[NonLiteral]
- if (userNodeInSystemGraph.isInstanceOf[BNode]) {
- var simpleMGraph: SimpleMGraph = new
SimpleMGraph
- var profileNode: GraphNode = new
GraphNode(new BNode, simpleMGraph)
-
profileNode.addProperty(CONTROLPANEL.isLocalProfile,
LiteralFactory.getInstance.createTypedLiteral(true))
- var suggestedPPDUri: UriRef =
getSuggestedPPDUri(userName)
-
profileNode.addProperty(CONTROLPANEL.suggestedPPDUri,
LiteralFactory.getInstance.createTypedLiteral(suggestedPPDUri))
- var agent: NonLiteral = new BNode
-
profileNode.addProperty(FOAF.primaryTopic, agent)
- simpleMGraph.add(new TripleImpl(agent,
PLATFORM.userName, LiteralFactory.getInstance.createTypedLiteral(userName)))
- return profileNode
- }
- else {
- return
getProfileInUserGraph(userNodeInSystemGraph.asInstanceOf[UriRef], profile)
+ profile: UriInfo): EasyGraphNode = {
+ val profileDocUri = getSuggestedPPDUri(userName)
+ return AccessController.doPrivileged(new
PrivilegedAction[EasyGraphNode] {
+ def run: EasyGraphNode = {
+ val userInSysGraph =
userManager.getUserInSystemGraph(userName)
+ userInSysGraph.getNode match {
+ case blank: BNode => { //user does not
have a webId yet
+ val g = new EasyGraph()
+ return (
+ g.bnode â
CONTROLPANEL.isLocalProfile â¶ true
+ â
CONTROLPANEL.suggestedPPDUri â¶ profileDocUri
+ â
FOAF.primaryTopic â¶ (g.bnode â PLATFORM.userName â¶ userName)
+ )
+ }
+ case webid: UriRef => {
+ var webIDInfo =
webIdGraphsService.getWebIDInfo(webid)
+ var res = new
EasyGraphNode(profileDocUri, new UnionMGraph(new SimpleMGraph,
webIDInfo.publicUserGraph))
+ (res â
CONTROLPANEL.isLocalProfile â¶ webIDInfo.isLocal
+ â FOAF.primaryTopic
â¶ webid)
+ if (webIDInfo.isLocal) {
+ res â PINGBACK.to â¶
new UriRef(PingBack.pingCollUri(userName,profile))
+ }
+ res
+ }
}
}
})
@@ -115,23 +124,6 @@ class ProfilePanel {
return new
UriRef(platformConfig.getDefaultBaseUri.getUnicodeString + "user/" + userName +
"/profile")
}
- /**
- * called in privileged block, when the user has a WebID.
- *
- * @param webId
- * @param profile
- * @return A graph containing some information from the system graph,
the published profile cache if available, and
- * the definedHere graph. Local changes can be written to a
buffer graph, that will not be saved.
- */
- private def getProfileInUserGraph(webId: UriRef, profile: UriRef):
GraphNode = {
- var webIDInfo = webIdGraphsService.getWebIDInfo(webId)
- var userGraph: MGraph = webIDInfo.publicUserGraph
- var resultNode: GraphNode = new GraphNode(profile, new
UnionMGraph(new SimpleMGraph, userGraph))
- resultNode.addProperty(CONTROLPANEL.isLocalProfile,
LiteralFactory.getInstance.createTypedLiteral(webIDInfo.isLocal))
- resultNode.addProperty(FOAF.primaryTopic, webId)
- return resultNode
- }
-
@POST
@Path("set-existing-webid")
def setExistingWebId(@Context uriInfo: UriInfo,
@@ -257,15 +249,15 @@ class ProfilePanel {
val webIdInfo = webIdGraphsService.getWebIDInfo(webidRef);
if (webIdInfo.isLocal)
) {
- val certNode: GraphNode = new GraphNode(new BNode,
webIdInfo.localGraph)
- certNode.addProperty(RDF.`type`, RSA.RSAPublicKey)
- certNode.addProperty(CERT.identity, webidRef)
- certNode.addPropertyValue(RSA.modulus, modulus)
- certNode.addPropertyValue(RSA.public_exponent,
publicExponent)
+ val certNode = new EasyGraph(webIdInfo.localGraph).bnode
+ ( certNode â RSA.RSAPublicKey
+ â CERT.identity â¶ webidRef
+ â RSA.modulus â¶ modulus
+ â RSA.public_exponent â¶ publicExponent
+ â DC.date â¶ cert.getStartDate )
if (comment != null && comment.length > 0) {
- certNode.addPropertyValue(RDFS.comment, comment)
+ certNode â RDFS.comment â¶ comment
}
- certNode.addPropertyValue(DC.date, cert.getStartDate)
}
var resBuild: Response.ResponseBuilder =
Response.ok(ser.getContent, MediaType.valueOf(ser.getMimeType))
return resBuild.build
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/person_panel.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/person_panel.scala?rev=1102309&r1=1102308&r2=1102309&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/person_panel.scala
(original)
+++
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/person_panel.scala
Thu May 12 13:58:20 2011
@@ -18,12 +18,12 @@
*/
package org.apache.clerezza.platform.accountcontrolpanel
+import ontologies.{PINGBACK, CONTROLPANEL}
import org.apache.clerezza.rdf.core._
import org.apache.clerezza.rdf.scala.utils._
import org.apache.clerezza.rdf.scala.utils.Preamble._
import org.apache.clerezza.platform.typerendering.scala._
import org.apache.clerezza.rdf.core.UriRef
-import org.apache.clerezza.platform.accountcontrolpanel.ontologies.CONTROLPANEL
import org.apache.clerezza.rdf.utils.GraphNode
import xml.{NodeSeq, Text, Node}
import java.net.{URLEncoder, URL}
@@ -70,9 +70,15 @@ object person_panel {
case uri: UriRef => uri.getUnicodeString
case _ =>
"http://upload.wikimedia.org/wikipedia/commons/0/0a/Gnome-stock_person.svg"
}
-
val pixml= { <a href={"people?uri="+encode(p*)}><img src={pix}
width="70px" /></a> }
- return pixml ++ new Text(getName(p))
+ val pingXML = (p / PINGBACK.to)! match {
+ case pingto: UriRef => {
+ val ref = "ping?to=" +
URLEncoder.encode(pingto.getUnicodeString, "UTF-8")
+ <a href={ref}>ping me</a>
+ }
+ case other => emptyText
+ }
+ return pixml ++ new Text(getName(p)) ++ pingXML
}
def encode(url: String): String = URLEncoder.encode(url,"UTF8")
@@ -147,7 +153,6 @@ class XmlPerson(args: XmlResult.Argument
resultDocModifier.addNodes2Elem("tx-module-tabs-ol", <li><a
href="control-panel">Settings</a></li>);
resultDocModifier.addNodes2Elem("tx-module-tabs-ol", <li><a
href="profile">Profile</a></li>);
-
//
// the content itself.
// This is the piece that is closest to a pure ssp, though there is
still too much code in it
@@ -182,7 +187,6 @@ class XmlPerson(args: XmlResult.Argument
// Methods called by the content
//
-
def relations() = {
<table>{for (friend <- agent/FOAF.knows) {
<tr><td>{friend*}</td></tr>
@@ -244,7 +248,7 @@ class XmlPerson(args: XmlResult.Argument
ifE(p/FOAF.depiction){f=>(<tr><td>Depictions:</td><td><img
src={f*} /></td></tr>)}++
ifE(p/FOAF.img){f=>(<tr><td>Depictions:</td><td><img src={f*}
/></td></tr>)}++
ifE(p/FOAF.logo){f=>(<tr><td>Logo:</td><td><img src={f*}
/></td></tr>)}++
- ifE(p/FOAF.knows){k=>(<tr><td>claims to
know</td><td><table>{for (fr<-k) yield displayAgent(fr)}</table></td></tr>)}
+ ifE(p/FOAF.knows){k=>(<tr><td>claims to
know</td><td><table>{for (fr<-k) yield displayAgent(fr)}</table></td></tr>)}
}
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ping_back_collection_panel.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ping_back_collection_panel.scala?rev=1102309&r1=1102308&r2=1102309&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ping_back_collection_panel.scala
(original)
+++
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ping_back_collection_panel.scala
Thu May 12 13:58:20 2011
@@ -50,6 +50,7 @@ class XhtmlPingBackDoc(args: XmlResult.A
override def content = {<div id="tx-content"
xmlns:pingback="http://purl.org/net/pingback/" about=""
typeof="pingback:Container">
<h3>Pingback Form</h3>
<form method="POST" action="">
+ { for (to <- res/PINGBACK.to) yield <input
type="hidden" name="to" value={to*}/> }
<table>
<tr><td><label
for="source">Source</label></td><td><input type="text" size="80"
name="source"/></td></tr>
<tr><td><label
for="target">Target</label></td><td><input type="text" size="80"
name="target"/></td></tr>