Author: reto
Date: Wed Feb 16 00:41:40 2011
New Revision: 1071115

URL: http://svn.apache.org/viewvc?rev=1071115&view=rev
Log:
CLEREZZA-304: resources removed from graph when they disappear in filesystem

Modified:
    
incubator/clerezza/trunk/parent/platform.content.fsadaptor/src/main/scala/org/apache/clerezza/platform/content/fsadaptor/BundleFsLoader.scala
    
incubator/clerezza/trunk/parent/platform.content.fsadaptor/src/main/scala/org/apache/clerezza/platform/content/fsadaptor/PathNode2MGraph.scala

Modified: 
incubator/clerezza/trunk/parent/platform.content.fsadaptor/src/main/scala/org/apache/clerezza/platform/content/fsadaptor/BundleFsLoader.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.content.fsadaptor/src/main/scala/org/apache/clerezza/platform/content/fsadaptor/BundleFsLoader.scala?rev=1071115&r1=1071114&r2=1071115&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.content.fsadaptor/src/main/scala/org/apache/clerezza/platform/content/fsadaptor/BundleFsLoader.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.content.fsadaptor/src/main/scala/org/apache/clerezza/platform/content/fsadaptor/BundleFsLoader.scala
 Wed Feb 16 00:41:40 2011
@@ -87,6 +87,11 @@ class BundleFsLoader extends BundleListe
        }
 
        def removeFromGraph(bundle: Bundle) {
+               val pathNode = new BundlePathNode(bundle, 
"CLEREZZA-INF/web-resources");
+               val mGraph: MGraph = tcManager.getMGraph(MGRAPH_NAME);
+               BundleFsLoader.log.info("Size of mgraph before removing 
resources of {}: {}", bundle, mGraph.size)
+               PathNode2MGraph.removeNodesFromGraph(pathNode, mGraph);
+               BundleFsLoader.log.info("Size of mgraph after removing 
resources of {}: {}", bundle, mGraph.size)
 
        }
 

Modified: 
incubator/clerezza/trunk/parent/platform.content.fsadaptor/src/main/scala/org/apache/clerezza/platform/content/fsadaptor/PathNode2MGraph.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.content.fsadaptor/src/main/scala/org/apache/clerezza/platform/content/fsadaptor/PathNode2MGraph.scala?rev=1071115&r1=1071114&r2=1071115&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.content.fsadaptor/src/main/scala/org/apache/clerezza/platform/content/fsadaptor/PathNode2MGraph.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.content.fsadaptor/src/main/scala/org/apache/clerezza/platform/content/fsadaptor/PathNode2MGraph.scala
 Wed Feb 16 00:41:40 2011
@@ -30,6 +30,7 @@ import org.apache.clerezza.rdf.core.impl
 import org.apache.clerezza.rdf.ontologies.DISCOBITS
 import org.apache.clerezza.rdf.ontologies.HIERARCHY
 import org.apache.clerezza.rdf.ontologies.RDF
+import org.apache.clerezza.rdf.utils.GraphNode
 import org.apache.clerezza.web.fileserver.util.MediaTypeGuesser
 import org.wymiwyg.commons.util.dirbrowser.PathNode
 
@@ -100,4 +101,41 @@ object PathNode2MGraph {
                }
                processDirectory(directory)
        }
+
+       def removeNodesFromGraph(directory: PathNode, mGraph: MGraph) {
+               val basePathLength = directory.getPath.length
+               def createUriRef(file: PathNode, isDirectory: Boolean) = {
+                       def addSlashIfNeeded(s: String) = {
+                                if (s.endsWith("/")) {
+                                        s
+                                } else {
+                                        s+'/'
+                                }
+                       }
+                       val path =      if (isDirectory) {
+                               
addSlashIfNeeded(file.getPath.substring(basePathLength))
+                       } else {
+                               file.getPath.substring(basePathLength)
+                       }
+                       new UriRef(URI_PREFIX+path)
+               }
+               def processDirectory(directory: PathNode) {
+                       val directoryResource = createUriRef(directory, true)
+                       mGraph.remove(new TripleImpl(directoryResource, 
RDF.`type`, HIERARCHY.Collection))
+                       for (subPath <- directory.list) {
+                               val file = directory.getSubPath(subPath)
+                               val isDirectory = file.isDirectory
+                               val resource = createUriRef(file, isDirectory)
+                               val node = new GraphNode(resource, mGraph)
+                               if (isDirectory) {
+                                       processDirectory(file)
+                               }
+                               node.deleteProperties(HIERARCHY.parent)
+                               node.deleteProperties(RDF.`type`)
+                               node.deleteProperties(DISCOBITS.infoBit)
+                               node.deleteProperties(DISCOBITS.mediaType)
+                       }
+               }
+               processDirectory(directory)
+       }
 }


Reply via email to