Author: suat
Date: Sat Mar 31 00:22:12 2012
New Revision: 1307657

URL: http://svn.apache.org/viewvc?rev=1307657&view=rev
Log:
STANBOL-498:
-Started to change the inmemory store into the file based store

Added:
    
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/
      - copied from r1306220, 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/inmemory/
    
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/inmemory/FileStore.java
      - copied, changed from r1306220, 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/inmemory/src/main/java/org/apache/stanbol/contenthub/store/inmemory/InMemoryStore.java
Removed:
    
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/inmemory/InMemoryStore.java
    
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/inmemory/
Modified:
    
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/pom.xml
    
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/pom.xml

Modified: 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/pom.xml?rev=1307657&r1=1306220&r2=1307657&view=diff
==============================================================================
--- 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/pom.xml
 (original)
+++ 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/pom.xml
 Sat Mar 31 00:22:12 2012
@@ -21,11 +21,11 @@
     <relativePath>../../parent</relativePath>
   </parent>
 
-  <artifactId>org.apache.stanbol.contenthub.store.inmemory</artifactId>
+  <artifactId>org.apache.stanbol.contenthub.store.file</artifactId>
   <packaging>bundle</packaging>
 
-  <name>Apache Stanbol Contenthub InMemory Store Implementation</name>
-  <description>Persists documents into the InMemory Store (lives in 
memory)</description>
+  <name>Apache Stanbol Contenthub File Based First Level Storage 
Implementation</name>
+  <description>Persists documents within the file system</description>
 
   <build>
     <plugins>

Copied: 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/inmemory/FileStore.java
 (from r1306220, 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/inmemory/src/main/java/org/apache/stanbol/contenthub/store/inmemory/InMemoryStore.java)
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/inmemory/FileStore.java?p2=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/inmemory/FileStore.java&p1=incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/inmemory/src/main/java/org/apache/stanbol/contenthub/store/inmemory/InMemoryStore.java&r1=1306220&r2=1307657&rev=1307657&view=diff
==============================================================================
--- 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/inmemory/src/main/java/org/apache/stanbol/contenthub/store/inmemory/InMemoryStore.java
 (original)
+++ 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/inmemory/FileStore.java
 Sat Mar 31 00:22:12 2012
@@ -1,118 +1,128 @@
 /*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.stanbol.contenthub.store.inmemory;
 
-import java.util.HashMap;
-import java.util.Iterator;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.Map;
 
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Triple;
 import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
-import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.contenthub.servicesapi.store.ChangeSet;
 import org.apache.stanbol.contenthub.servicesapi.store.Store;
+import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
 import org.apache.stanbol.enhancer.servicesapi.ContentItem;
-import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
-import org.apache.stanbol.enhancer.servicesapi.helper.InMemoryContentItem;
+import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
-/** Trivial in-memory Store for standalone Stanbol Enhancement server */
 @Component(immediate = false)
 @Service
-// Use a low service ranking so that "real" stores replace this
-@Property(name = "service.ranking", intValue = -1000)
-public class InMemoryStore implements Store {
+public class FileStore implements Store {
+    private static final String FILE_STORE_PATH = "file.store.path";
+    @Property(name = FILE_STORE_PATH, value = "")
+    private static final String REVISION_FILE_NAME = "revisions";
 
-    private final Logger log = LoggerFactory.getLogger(InMemoryStore.class);
+    private static final String METADATA_EXTENSION = "_metadata";
 
-    private final Map<String, ContentItem> data = new HashMap<String, 
ContentItem>();
+    private final Logger log = LoggerFactory.getLogger(FileStore.class);
 
-    @Reference
-    private WeightedTcProvider tcProvider;
+    private File storeFolder;
 
-    @Property(value = 
"http://stanbol.apache.org/enhancer/defaultEnhancementsGraphID";)
-    public static final String GRAPH_URI = 
"org.apache.stanbol.enhancer.standalone.store.graphUri";
+    // TODO replace object with a proper structure
+    private Map<String,Object> revisionMap;
 
-    public InMemoryStore() {
-        super();
-    }
+    @Activate
+    protected void activate(ComponentContext componentContext) throws 
StoreException {
+        String fileStorePath = (String) 
componentContext.getProperties().get(FILE_STORE_PATH);
+        if (fileStorePath.trim().equals("")) {
+            fileStorePath = 
componentContext.getBundleContext().getProperty("sling.home");
+        }
 
-    public ContentItem create(String id, byte[] content, String mimeType) {
-        UriRef uri = id == null ? ContentItemHelper.makeDefaultUrn(content)
-                : new UriRef(id);
-        log.debug("create ContentItem for id " + uri + " on TC Manager= "
-                + tcProvider);
-        final MGraph g = new SimpleMGraph();
-        return new InMemoryContentItem(uri.getUnicodeString(), content, 
mimeType, g);
+        // load revisions
+        File revisionFile = new File(fileStorePath);
+        if (!revisionFile.exists()) {
+            boolean created;
+            try {
+                created = revisionFile.createNewFile();
+                if (!created) {
+                    log.error("Failed to create revision file");
+                    throw new StoreException("Failed to create revision file");
+                }
+
+            } catch (IOException e) {
+                log.error("Failed to create revision file", e);
+                throw new StoreException("Failed to create revision file", e);
+            }
+        } else {
+            
+        }
     }
 
-    public ContentItem get(String id) {
-        ContentItem result;
-        synchronized (data) {
-            result = data.get(id);
+    @Override
+    public ContentItem remove(UriRef id) throws StoreException {
+        checkStoreFolder();
+        try {
+            String urlEncodedId = URLEncoder.encode(id.getUnicodeString(), 
"UTF-8");
+            
+        } catch (UnsupportedEncodingException e) {
+            log.error("Failed to remove content item", e);
         }
-        return result;
+        return null;
     }
 
-    public String put(ContentItem ci) {
-        synchronized (data) {
-
-            data.put(ci.getUri().getUnicodeString(), ci);
+    @Override
+    public UriRef put(ContentItem ci) throws StoreException {
+        // TODO Auto-generated method stub
 
-            // remove any previously stored data about ci
-            MGraph g = getEnhancementGraph();
-            UriRef uri = ci.getUri();
-            Iterator<Triple> toRemove = g.filter(uri, null, null);
-            while (toRemove.hasNext()) {
-                toRemove.next();
-                toRemove.remove();
-            }
-            toRemove = g.filter(null, null, uri);
-            while (toRemove.hasNext()) {
-                toRemove.next();
-                toRemove.remove();
-            }
-            // TODO: how to handle orphan indirect triples?
+        return null;
+    }
 
-            // accumulate all triples recently collected
-            getEnhancementGraph().addAll(ci.getMetadata());
-        }
-        return ci.getUri().getUnicodeString();
+    @Override
+    public ContentItem get(UriRef id) throws StoreException {
+        // TODO Auto-generated method stub
+        return null;
     }
 
     @Override
-    public String toString() {
-        return getClass().getName();
+    public ChangeSet changes(long revision, int batchSize) throws 
StoreException {
+        // TODO Auto-generated method stub
+        return null;
     }
 
-    public MGraph getEnhancementGraph() {
-        final UriRef graphUri = new UriRef(GRAPH_URI);
-        try {
-            return tcProvider.getMGraph(graphUri);
-        } catch (NoSuchEntityException e) {
-            return tcProvider.createMGraph(graphUri);
+    private void checkStoreFolder() throws StoreException {
+        if (!storeFolder.exists()) {
+            throw new StoreException("Store folder does not exist");
         }
     }
+    
+    private void fillRevisionMap() {
+        FilenameFilter revisionFilter = new FilenameFilter() {
+            @Override
+            public boolean accept(File dir, String name) {
+                // TODO Auto-generated method stub
+                return false;
+            }
+        };
+    }
 }

Modified: 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/pom.xml?rev=1307657&r1=1307656&r2=1307657&view=diff
==============================================================================
--- 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/pom.xml
 (original)
+++ 
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/pom.xml
 Sat Mar 31 00:22:12 2012
@@ -49,6 +49,6 @@
        <modules>
                <module>solr</module>
                <module>clerezza</module>
-               <module>inmemory</module>
+               <module>file</module>
        </modules>
 </project>


Reply via email to