Author: bblfish
Date: Thu Feb 24 13:42:42 2011
New Revision: 1074149

URL: http://svn.apache.org/viewvc?rev=1074149&view=rev
Log:
simplified code, and fixed null pointer exception occurring when database does 
not contain information.

Modified:
    
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/pom.xml
    
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/java/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.java
    
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/profile_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=1074149&r1=1074148&r2=1074149&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 Feb 24 13:42:42 2011
@@ -45,7 +45,7 @@
                                        <instructions>
                                                
<Service-Component>OSGI-INF/serviceComponents.xml</Service-Component>
                                                
<Export-Package>org.apache.clerezza.platform.accountcontrolpanel</Export-Package>
-                                               
<Bundle-SymbolicName>org.apache.clerezza.platform.accountcontrolpanel</Bundle-SymbolicName>
+                                               
<Bundle-SymbolicName>${groupId}.${artifactId}</Bundle-SymbolicName>
                                        </instructions>
                                </configuration>
                        </plugin>

Modified: 
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/java/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/java/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.java?rev=1074149&r1=1074148&r2=1074149&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/java/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.java
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/java/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.java
 Thu Feb 24 13:42:42 2011
@@ -18,7 +18,10 @@
  */
 package org.apache.clerezza.platform.accountcontrolpanel;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Iterator;
+
 import org.apache.clerezza.ssl.keygen.CertSerialisation;
 import org.apache.clerezza.ssl.keygen.Certificate;
 import org.apache.clerezza.foafssl.ontologies.CERT;
@@ -61,14 +64,14 @@ import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.interfaces.RSAPublicKey;
 import java.util.List;
+
 import org.apache.clerezza.platform.typerendering.scala.PageRenderlet;
 import org.apache.clerezza.rdf.ontologies.RDFS;
 import org.apache.clerezza.ssl.keygen.KeygenService;
 
 /**
- *
  * Presents a panel where the user can create a webid and edit her profile.
- * 
+ *
  * @author reto
  */
 //@Component
@@ -78,17 +81,17 @@ import org.apache.clerezza.ssl.keygen.Ke
 public class ProfilePanel extends FileServer {
 
        private static final Logger logger = 
LoggerFactory.getLogger(ProfilePanel.class);
-//     @Reference
+       //      @Reference
        private UserManager userManager;
-//     @Reference
+       //      @Reference
        private org.apache.clerezza.ssl.keygen.KeygenService keygenSrvc;
-//     @Reference
+       //      @Reference
        private TcManager tcManager;
-//     @Reference
+       //      @Reference
        private RenderletManager renderletManager;
-//     @Reference
+       //      @Reference
        private WebIdGraphsService webIdGraphsService;
-//     @Reference
+       //      @Reference
        private PlatformConfig platformConfig;
 
        protected void activate(ComponentContext componentContext) {
@@ -97,7 +100,7 @@ public class ProfilePanel extends FileSe
 //                             null, CONTROLPANEL.ProfilePage,
 //                             "naked", MediaType.APPLICATION_XHTML_XML_TYPE, 
true);
 //equivalent of above with no ssp?
-//             
renderletManager.registerRenderlet("org.apache.clerezza.platform.accountcontrolpanel.profile_panel",
 
+//             
renderletManager.registerRenderlet("org.apache.clerezza.platform.accountcontrolpanel.profile_panel",
 //                             null, CONTROLPANEL.ProfilePage, "naked", 
MediaType.APPLICATION_XHTML_XML_TYPE, true);
                configure(componentContext.getBundleContext(), 
"profile-staticweb");
        }
@@ -139,28 +142,38 @@ public class ProfilePanel extends FileSe
                });
        }
 
+       /**
+        * @param userName
+        * @return the suggested Personal Profile Document URI
+        */
        private UriRef getSuggestedPPDUri(String userName) {
                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 local graph. Local changes can be written to a buffer graph, 
that will have not be saved.
+        */
        private GraphNode getProfileInUserGraph(UriRef webId, UriRef profile) {
                WebIdGraphsService.WebIdGraphs webIdGraphs = 
webIdGraphsService.getWebIdGraphs(webId);
                MGraph userGraph = webIdGraphs.publicUserGraph();
-               logger.debug("got publicUserGraph of size {}.", 
userGraph.size());
-               GraphNode userGraphNode = new GraphNode(webId, userGraph);
                GraphNode resultNode = new GraphNode(profile,
-                               new UnionMGraph(new SimpleMGraph(), 
userGraphNode.getGraph()));
+                               new UnionMGraph(new SimpleMGraph(), userGraph));
                resultNode.addProperty(CONTROLPANEL.isLocalProfile,
                                
LiteralFactory.getInstance().createTypedLiteral(webIdGraphs.isLocal()));
-               resultNode.addProperty(FOAF.primaryTopic, 
userGraphNode.getNode());
+               resultNode.addProperty(FOAF.primaryTopic, webId);
                return resultNode;
        }
 
        @POST
        @Path("set-existing-webid")
        public Response setExistingWebId(@Context final UriInfo uriInfo,
-                       @FormParam("webid") final UriRef webId, 
@PathParam(value = "id") final String userName) {
+                                        @FormParam("webid") final UriRef 
webId, @PathParam(value = "id") final String userName) {
                //TODO check that its not local
                //TODO check its not an existing user
                return AccessController.doPrivileged(new 
PrivilegedAction<Response>() {
@@ -177,13 +190,15 @@ public class ProfilePanel extends FileSe
        @POST
        @Path("create-new-web-id")
        public Response createNewWebId(@Context final UriInfo uriInfo,
-                       @PathParam(value = "id") final String userName) {
-               //TODO check its not an existing user
+                                      @PathParam(value = "id") final String 
userName) {
+               //TODO don't pass user name in param. Use logged in user.
                final UriRef ppd = getSuggestedPPDUri(userName);
                final UriRef webId = new UriRef(ppd.getUnicodeString() + "#me");
                final WebIdGraphsService.WebIdGraphs webIdGraphs = 
webIdGraphsService.getWebIdGraphs(webId);
-               webIdGraphs.localGraph().add(new TripleImpl(ppd, 
FOAF.primaryTopic, webId));
-               webIdGraphs.localGraph().add(new TripleImpl(ppd, RDF.type, 
FOAF.PersonalProfileDocument));
+               webIdGraphs.localGraph().addAll(Arrays.asList(
+                               new TripleImpl(ppd, RDF.type, 
FOAF.PersonalProfileDocument),
+                               new TripleImpl(ppd, FOAF.primaryTopic, webId))
+               );
                return AccessController.doPrivileged(new 
PrivilegedAction<Response>() {
 
                        @Override
@@ -198,13 +213,13 @@ public class ProfilePanel extends FileSe
        @POST
        @Path("keygen")
        public Response createCert(@FormParam("webId") UriRef webId,
-                       @FormParam("cn") String commonName,
-                       @FormParam("spkac") String spkac,
-                       @FormParam("crmf") String crmf,
-                       @FormParam("hours") String hours,
-                       @FormParam("days") String days,
-                       @FormParam("csr") String csr,
-                       @FormParam("comment") String comment) {
+                                  @FormParam("cn") String commonName,
+                                  @FormParam("spkac") String spkac,
+                                  @FormParam("crmf") String crmf,
+                                  @FormParam("hours") String hours,
+                                  @FormParam("days") String days,
+                                  @FormParam("csr") String csr,
+                                  @FormParam("comment") String comment) {
 
                logger.info("in keygen code. webId={}", webId);
                logger.info("cn={}", commonName);
@@ -234,7 +249,7 @@ public class ProfilePanel extends FileSe
                        }
                }
                if (cert == null) {
-                       throw new RuntimeException("The server was unable to 
craete a certificate");
+                       throw new RuntimeException("The server was unable to 
create a certificate");
                }
                cert.setSubjectCommonName(commonName);
                cert.addDurationInHours(hours);
@@ -271,22 +286,22 @@ public class ProfilePanel extends FileSe
        @POST
        @Path("deletekey")
        public Response deleteKey(@Context final UriInfo uriInfo,
-                       @FormParam("webId") final UriRef webId,
-                       @FormParam("keyhash") List<String> keys) {
+                                 @FormParam("webId") final UriRef webId,
+                                 @FormParam("keyhash") List<String> keys) {
                final WebIdGraphsService.WebIdGraphs webIdGraphs = 
webIdGraphsService.getWebIdGraphs(webId);
                final GraphNode agent = new GraphNode(webId, 
webIdGraphs.localGraph());
                Iterator<GraphNode> subjects = 
agent.getSubjectNodes(CERT.identity);
-               for (GraphNode nl; subjects.hasNext();  ) {
+               for (GraphNode nl; subjects.hasNext(); ) {
                        nl = subjects.next();
                        Iterator<Resource> modulusIt = 
nl.getObjects(RSA.modulus);
                        if (!modulusIt.hasNext()) break;
                        Resource modLit = modulusIt.next(); //we only get the 
first, any more would be an error
-                       if (modulusIt.hasNext()) logger.warn("data error, a 
modulus too many in cert for "+webId);
+                       if (modulusIt.hasNext()) logger.warn("data error, a 
modulus too many in cert for " + webId);
                        if (!(modLit instanceof TypedLiteral)) {
-                               logger.warn("a public key has a modulus that is 
not a literal for "+webId);
+                               logger.warn("a public key has a modulus that is 
not a literal for " + webId);
                                break;
                        }
-                       BigInteger modulus = 
LiteralFactory.getInstance().createObject(BigInteger.class, 
(TypedLiteral)modLit);
+                       BigInteger modulus = 
LiteralFactory.getInstance().createObject(BigInteger.class, (TypedLiteral) 
modLit);
                        for (String key : keys) {
                                if (modulus.hashCode() == Integer.decode(key)) {
                                        //we delete the key. Even thous it is 
extreemly unlikely that anything could go wrong here
@@ -298,16 +313,16 @@ public class ProfilePanel extends FileSe
                        }
                }
                //shoud one really have a redirect? or should the post just be 
to the profile page?
-           return RedirectUtil.createSeeOtherResponse("../profile", uriInfo);
+               return RedirectUtil.createSeeOtherResponse("../profile", 
uriInfo);
        }
 
        @POST
        @Path("modify")
        public Response modifyProfile(@Context final UriInfo uriInfo,
-                       @PathParam(value = "id") final String userName,
-                       @FormParam("webId") final UriRef webId,
-                       @FormParam("name") final String name,
-                       @FormParam("description") final String description) {
+                                     @PathParam(value = "id") final String 
userName,
+                                     @FormParam("webId") final UriRef webId,
+                                     @FormParam("name") final String name,
+                                     @FormParam("description") final String 
description) {
                final WebIdGraphsService.WebIdGraphs webIdGraphs = 
webIdGraphsService.getWebIdGraphs(webId);
                final GraphNode agent = new GraphNode(webId, 
webIdGraphs.localGraph());
                agent.deleteProperties(FOAF.name);

Modified: 
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/profile_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/profile_panel.scala?rev=1074149&r1=1074148&r2=1074149&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/profile_panel.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/profile_panel.scala
 Thu Feb 24 13:42:42 2011
@@ -180,20 +180,15 @@ class profile_panel extends PageRenderle
                          <tr><th>Delete</th><th>Certificate Details</th></tr>
                          <input name="webId" id="webId" type="hidden" 
value={agent*} />
                          <tbody>{ 
-                                 for (cert <- agent/-CERT.identity )  
-                                       yield { val modulus = 
(cert/RSA.modulus).as[BigInteger]
+                                 for (key <- agent/-CERT.identity )
+                                       yield { val modulus = 
(key/RSA.modulus).as[BigInteger]
                                                   if (modulus == null)  
<span/> //todo: broken public key, should delete it
                                                   else <tr><td><input 
type="checkbox" name="keyhash" value={modulus.hashCode().toString()}/></td>
                                                <td><table>
-                                                       <tr><td 
class="propvalue">Created:</td><td>{if ((cert/DC.date).size > 0) {
-                                                                       
beautify((cert/DC.date).as[Date])
-                                                                       } else {
-                                                                               
"-"
-                                                                       }
-                                                       }</td></tr>
-                                                       <tr><td 
class="propvalue">Comment:</td><td>{ cert/RDFS.comment* }</td></tr>
-                                                       <tr><td 
class="propvalue multiline">Modulus:</td><td><code>{ 
beautify((cert/RSA.modulus).as[BigInteger]) }</code></td></tr>
-                                                       <tr><td 
class="propvalue">Exponent:</td><td><code>{ 
beautify((cert/RSA.public_exponent).as[Integer]) }</code></td></tr>
+                                                       <tr><td 
class="propvalue">Created:</td><td>{beautifyDate(key/DC.date )}</td></tr>
+                                                       <tr><td 
class="propvalue">Comment:</td><td>{ key/RDFS.comment* }</td></tr>
+                                                       <tr><td 
class="propvalue multiline">Modulus:</td><td><code>{ 
beautifyHex(key/RSA.modulus) }</code></td></tr>
+                                                       <tr><td 
class="propvalue">Exponent:</td><td><code>{ 
beautifyInt(key/RSA.public_exponent) }</code></td></tr>
                                                        </table>
                                                </td>
                                                                </tr>}
@@ -225,25 +220,33 @@ class profile_panel extends PageRenderle
        }
   }
 
-  def beautify(resource: Object) = {
-       resource match {
-         case bigint: BigInteger => {
-                 val bstr = bigint.toString(16).toUpperCase;
-                 val sbuf = new StringBuffer(bstr.size + (bstr.size/2)+10)
-                 var cnt = 0
-                 for (c <- bstr.toCharArray) {
-                       if ((cnt % 2) == 0) { sbuf.append(' ') }
-                       sbuf.append(c)
-                       cnt += 1
-                 }
-                 sbuf.toString
-               }
-         case date: Date => 
{DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.FULL).format(date)}
-         case intg: Integer => intg.toString
-         case string: String => string
-         case _ => resource.toString
+  def beautifyDate(dtIt: CollectedIter[RichGraphNode]) {
+         if (dtIt.size = 0) return "_"
+         
DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.FULL).format(dtIt.as[Date])
+  }
+
+
+  def beautifyHex(dtIt: CollectedIter[RichGraphNode]): String = {
+         if (dtIt.size = 0) return "warning! missing. Key invalid"
+         //this is a problem, it should always be here or it is invalid, and 
key should be removed
+         val bigint: BigInteger = dtIt.as[BigInteger]
+         val bstr = bigint.toString(16).toUpperCase;
+         val sbuf = new StringBuffer(bstr.size + (bstr.size/2)+10)
+         var cnt = 0
+         for (c <- bstr.toCharArray) {
+               if ((cnt % 2) == 0) { sbuf.append(' ') }
+               sbuf.append(c)
+               cnt += 1
+         }
+         sbuf.toString
        }
-  }  
+
+
+
+  def beautifyInt(dtIt: CollectedIter[RichGraphNode] ) :String = {
+         if (dtIt.size = 0) return "warning! missing. Key invalid"
+         else return dtIt.as[String]
+  }
 }
 
 


Reply via email to