You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by su...@apache.org on 2012/11/27 10:54:57 UTC

svn commit: r1414049 - in /stanbol/trunk/cmsadapter: cmis/ cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/mapping/ cmis/src/test/ jcr/ jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/mapping/ servicesapi/src/main/java/org/apache/stanbol/cmsa...

Author: suat
Date: Tue Nov 27 09:54:54 2012
New Revision: 1414049

URL: http://svn.apache.org/viewvc?rev=1414049&view=rev
Log:
STANBOL-815:
-CMS specific properties of documents are put into an addition ContentItem part instead of passing them within a separate parameter.

Added:
    stanbol/trunk/cmsadapter/cmis/src/test/
Modified:
    stanbol/trunk/cmsadapter/cmis/pom.xml
    stanbol/trunk/cmsadapter/cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/mapping/CMISContenthubFeeder.java
    stanbol/trunk/cmsadapter/jcr/pom.xml
    stanbol/trunk/cmsadapter/jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/mapping/JCRContenthubFeeder.java
    stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/ContenthubFeeder.java

Modified: stanbol/trunk/cmsadapter/cmis/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/cmsadapter/cmis/pom.xml?rev=1414049&r1=1414048&r2=1414049&view=diff
==============================================================================
--- stanbol/trunk/cmsadapter/cmis/pom.xml (original)
+++ stanbol/trunk/cmsadapter/cmis/pom.xml Tue Nov 27 09:54:54 2012
@@ -31,9 +31,9 @@
 	<build>
 		<plugins>
 			<plugin>
-				<groupId>org.apache.felix</groupId>
-				<artifactId>maven-bundle-plugin</artifactId>
-				<extensions>true</extensions>
+    		  <groupId>org.apache.felix</groupId>
+    		  <artifactId>maven-bundle-plugin</artifactId>
+    		  <extensions>true</extensions>
 			</plugin>
 			<plugin>
 				<groupId>org.apache.felix</groupId>
@@ -45,7 +45,7 @@
 		<dependency>
 			<groupId>org.apache.stanbol</groupId>
 			<artifactId>org.apache.stanbol.cmsadapter.servicesapi</artifactId>
-			<version>0.9.0-incubating</version>
+			<version>0.10.0-SNAPSHOT</version>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.stanbol</groupId>
@@ -55,7 +55,7 @@
 		<dependency>
 			<groupId>org.apache.stanbol</groupId>
 			<artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
-			<version>0.9.0-incubating</version>
+			<version>0.10.0-SNAPSHOT</version>
 		</dependency>
 		
 		<!-- Enhancer -->
@@ -82,14 +82,26 @@
 			<groupId>com.hp.hpl.jena</groupId>
 			<artifactId>jena</artifactId>
 		</dependency>
-		<dependency>
-			<groupId>org.apache.chemistry.opencmis</groupId>
-			<artifactId>chemistry-opencmis-client-api</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.apache.chemistry.opencmis</groupId>
-			<artifactId>chemistry-opencmis-client-impl</artifactId>
-		</dependency>		
+        <dependency>
+          <groupId>org.apache.chemistry.opencmis</groupId>
+          <artifactId>chemistry-opencmis-client-api</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.apache.chemistry.opencmis</groupId>
+          <artifactId>chemistry-opencmis-client-impl</artifactId>
+        </dependency>
+<!--         <dependency> -->
+<!--           <groupId>org.apache.chemistry.opencmis</groupId> -->
+<!--           <artifactId>chemistry-opencmis-commons-api</artifactId> -->
+<!--         </dependency> -->
+<!--         <dependency> -->
+<!--           <groupId>org.apache.chemistry.opencmis</groupId> -->
+<!--           <artifactId>chemistry-opencmis-commons-impl</artifactId> -->
+<!--         </dependency> -->
+<!--         <dependency> -->
+<!--           <groupId>org.apache.chemistry.opencmis</groupId> -->
+<!--           <artifactId>chemistry-opencmis-client-bindings</artifactId> -->
+<!--         </dependency> -->
 		<dependency>
 			<groupId>org.apache.clerezza</groupId>
 			<artifactId>rdf.core</artifactId>

Modified: stanbol/trunk/cmsadapter/cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/mapping/CMISContenthubFeeder.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/cmsadapter/cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/mapping/CMISContenthubFeeder.java?rev=1414049&r1=1414048&r2=1414049&view=diff
==============================================================================
--- stanbol/trunk/cmsadapter/cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/mapping/CMISContenthubFeeder.java (original)
+++ stanbol/trunk/cmsadapter/cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/mapping/CMISContenthubFeeder.java Tue Nov 27 09:54:54 2012
@@ -54,8 +54,8 @@ import org.apache.stanbol.cmsadapter.ser
 import org.apache.stanbol.cmsadapter.servicesapi.mapping.ContenthubFeederException;
 import org.apache.stanbol.cmsadapter.servicesapi.repository.RepositoryAccessException;
 import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
-import org.apache.stanbol.contenthub.servicesapi.store.solr.SolrContentItem;
 import org.apache.stanbol.contenthub.servicesapi.store.solr.SolrStore;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
 import org.osgi.service.cm.ConfigurationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -110,15 +110,15 @@ public class CMISContenthubFeeder implem
     }
 
     @Override
-    public void submitContentItemByCMSObject(Object o, String id) {
-        submitContentItemByCMSObject(o, id, null);
+    public void submitContentItemByCMSObject(Object o) {
+        submitContentItemByCMSObject(o, null);
     }
 
     @Override
-    public void submitContentItemByCMSObject(Object o, String id, String indexName) {
+    public void submitContentItemByCMSObject(Object o, String indexName) {
         CmisObject cmisObject = (CmisObject) o;
         if (hasType(cmisObject, BaseTypeId.CMIS_DOCUMENT)) {
-            processDocumentAndSubmitToContenthub((Document) cmisObject, id, indexName);
+            processDocumentAndSubmitToContenthub((Document) cmisObject, indexName);
         }
     }
 
@@ -206,7 +206,7 @@ public class CMISContenthubFeeder implem
     @Override
     public void deleteContentItemByID(String contentItemID, String indexName) {
         try {
-            solrStore.deleteById(contentItemID, indexName);
+            solrStore.deleteById(attachBaseURI(contentItemID), indexName);
         } catch (StoreException e) {
             log.error(e.getMessage(), e);
         }
@@ -228,7 +228,7 @@ public class CMISContenthubFeeder implem
         }
 
         try {
-            solrStore.deleteById(o.getId(), indexName);
+            solrStore.deleteById(attachBaseURI(o.getId()), indexName);
         } catch (StoreException e) {
             log.error(e.getMessage(), e);
         }
@@ -257,7 +257,7 @@ public class CMISContenthubFeeder implem
         }
         for (Document d : documents) {
             try {
-                solrStore.deleteById(d.getId(), indexName);
+                solrStore.deleteById(attachBaseURI(d.getId()), indexName);
             } catch (StoreException e) {
                 log.error(e.getMessage(), e);
             }
@@ -308,10 +308,6 @@ public class CMISContenthubFeeder implem
     }
 
     private void processDocumentAndSubmitToContenthub(Document d, String indexName) {
-        processDocumentAndSubmitToContenthub(d, null, indexName);
-    }
-
-    private void processDocumentAndSubmitToContenthub(Document d, String id, String indexName) {
         byte[] content;
         try {
             content = IOUtils.toByteArray(d.getContentStream().getStream());
@@ -325,17 +321,19 @@ public class CMISContenthubFeeder implem
         }
         String mimeType = d.getContentStreamMimeType();
         Map<String,List<Object>> constraints = getConstraintsFromDocument(d);
-        id = (id == null || id.equals("")) ? d.getId() : id;
-        SolrContentItem sci = solrStore.create(content, d.getId(), d.getName(), mimeType, constraints);
+        String id = d.getId();
+        id = attachBaseURI(id);
+        ContentItem ci = null;
         try {
-            solrStore.enhanceAndPut(sci, indexName);
+            ci = solrStore.create(content, id, d.getName(), mimeType);
+            ci.addPart(ADDITIONAL_METADATA_URI, constraints);
+            solrStore.enhanceAndPut(ci, indexName, null);
         } catch (StoreException e) {
             log.error(e.getMessage(), e);
         }
         log.info("Document submitted to Contenthub.");
-        log.info("Id: {}", sci.getUri().getUnicodeString());
-        log.info("Mime type: {}", sci.getMimeType());
-        log.info("Constraints: {}", sci.getConstraints().toString());
+        log.info("Id: {}", ci.getUri().getUnicodeString());
+        log.info("Mime type: {}", ci.getMimeType());
     }
 
     private Map<String,List<Object>> getConstraintsFromDocument(Document d) {
@@ -421,4 +419,11 @@ public class CMISContenthubFeeder implem
     private boolean hasType(CmisObject o, BaseTypeId type) {
         return o.getBaseTypeId().equals(type);
     }
+
+    private String attachBaseURI(String id) {
+        if (!id.contains(":")) {
+            id = CONTENT_ITEM_URI_PREFIX + id;
+        }
+        return id;
+    }
 }
\ No newline at end of file

Modified: stanbol/trunk/cmsadapter/jcr/pom.xml
URL: http://svn.apache.org/viewvc/stanbol/trunk/cmsadapter/jcr/pom.xml?rev=1414049&r1=1414048&r2=1414049&view=diff
==============================================================================
--- stanbol/trunk/cmsadapter/jcr/pom.xml (original)
+++ stanbol/trunk/cmsadapter/jcr/pom.xml Tue Nov 27 09:54:54 2012
@@ -46,7 +46,7 @@
 		<dependency>
 			<groupId>org.apache.stanbol</groupId>
 			<artifactId>org.apache.stanbol.cmsadapter.servicesapi</artifactId>
-			<version>0.9.0-incubating</version>
+			<version>0.10.0-SNAPSHOT</version>
 		</dependency>
 		<dependency>
 			<groupId>org.apache.stanbol</groupId>
@@ -58,7 +58,7 @@
 		<dependency>
 			<groupId>org.apache.stanbol</groupId>
 			<artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
-			<version>0.9.0-incubating</version>
+			<version>0.10.0-SNAPSHOT</version>
 		</dependency>
 
 		<!-- Enhancer -->

Modified: stanbol/trunk/cmsadapter/jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/mapping/JCRContenthubFeeder.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/cmsadapter/jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/mapping/JCRContenthubFeeder.java?rev=1414049&r1=1414048&r2=1414049&view=diff
==============================================================================
--- stanbol/trunk/cmsadapter/jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/mapping/JCRContenthubFeeder.java (original)
+++ stanbol/trunk/cmsadapter/jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/mapping/JCRContenthubFeeder.java Tue Nov 27 09:54:54 2012
@@ -19,9 +19,7 @@ package org.apache.stanbol.cmsadapter.jc
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Dictionary;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import javax.jcr.Binary;
 import javax.jcr.ItemNotFoundException;
@@ -32,10 +30,15 @@ import javax.jcr.PropertyIterator;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.Value;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
 import org.apache.commons.io.IOUtils;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Reference;
@@ -46,9 +49,10 @@ import org.apache.stanbol.cmsadapter.ser
 import org.apache.stanbol.cmsadapter.servicesapi.mapping.ContenthubFeeder;
 import org.apache.stanbol.cmsadapter.servicesapi.mapping.ContenthubFeederException;
 import org.apache.stanbol.cmsadapter.servicesapi.repository.RepositoryAccessException;
+import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
 import org.apache.stanbol.contenthub.servicesapi.store.StoreException;
-import org.apache.stanbol.contenthub.servicesapi.store.solr.SolrContentItem;
 import org.apache.stanbol.contenthub.servicesapi.store.solr.SolrStore;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
 import org.osgi.service.cm.ConfigurationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -114,17 +118,17 @@ public class JCRContenthubFeeder impleme
     private List<String> contentProperties;
 
     @Override
-    public void submitContentItemByCMSObject(Object o, String id) {
-        submitContentItemByCMSObject(o, id, null);
+    public void submitContentItemByCMSObject(Object o) {
+        submitContentItemByCMSObject(o, null);
     }
 
     @Override
-    public void submitContentItemByCMSObject(Object o, String id, String indexName) {
+    public void submitContentItemByCMSObject(Object o, String indexName) {
         Node n = (Node) o;
         String actualNodeId = "";
         try {
             actualNodeId = n.getIdentifier();
-            ContentContext contentContext = getContentContextWithBasicInfo(n, id);
+            ContentContext contentContext = getContentContextWithBasicInfo(n);
             processContextAndSubmitToContenthub(contentContext, indexName);
         } catch (RepositoryException e) {
             log.warn("Failed to get basic information of node having id: {}", actualNodeId);
@@ -228,7 +232,7 @@ public class JCRContenthubFeeder impleme
     @Override
     public void deleteContentItemByID(String contentItemID, String indexName) {
         try {
-            solrStore.deleteById(contentItemID, indexName);
+            solrStore.deleteById(attachBaseURI(contentItemID), indexName);
         } catch (StoreException e) {
             log.error(e.getMessage(), e);
         }
@@ -245,7 +249,7 @@ public class JCRContenthubFeeder impleme
         try {
             n = getNodeByPath(contentItemPath);
             try {
-                solrStore.deleteById(n.getIdentifier(), indexName);
+                solrStore.deleteById(attachBaseURI(n.getIdentifier()), indexName);
             } catch (StoreException e) {
                 log.error(e.getMessage(), e);
             }
@@ -266,7 +270,7 @@ public class JCRContenthubFeeder impleme
             nodes = getNodesUnderPath(rootPath);
             for (Node n : nodes) {
                 try {
-                    solrStore.deleteById(n.getIdentifier(), indexName);
+                    solrStore.deleteById(attachBaseURI(n.getIdentifier()), indexName);
                 } catch (StoreException e) {
                     log.error(e.getMessage(), e);
                 }
@@ -292,53 +296,59 @@ public class JCRContenthubFeeder impleme
         return session instanceof Session;
     }
 
-    private void processContextAndSubmitToContenthub(ContentContext contentContext, String indexName) {
-        String id = contentContext.getIdentifier();
+    private void processContextAndSubmitToContenthub(ContentContext contentContext, String indexName) throws RepositoryException {
+        String id = contentContext.getNode().getIdentifier();
+        String contentItemId = contentContext.getIdentifier();
         populateContentContext(contentContext);
         if (contentContext.getContent() == null || contentContext.getContent().length == 0) {
             log.warn("Failed to get content for node having id: {}", id);
             return;
         }
 
-        Map<String,List<Object>> constraints = getConstraintsFromNode(contentContext);
-        if (constraints.isEmpty()) {
-            log.debug("There is no constraint for the node having id: {}", id);
+        MGraph additionalMetadata = getAdditionalMetadataFromNode(contentContext);
+        if (additionalMetadata.isEmpty()) {
+            log.debug("There is no additional metadata for the node having id: {}", id);
         }
 
-        SolrContentItem sci = solrStore.create(contentContext.getContent(), id, contentContext.getNodeName(),
-            contentContext.getContentType(), constraints);
+        ContentItem ci = null;
         try {
-            solrStore.enhanceAndPut(sci, indexName);
+            ci = solrStore.create(contentContext.getContent(), contentItemId, contentContext.getNodeName(),
+                contentContext.getContentType());
+            ci.addPart(ADDITIONAL_METADATA_URI, additionalMetadata);
+            solrStore.enhanceAndPut(ci, indexName, null);
         } catch (StoreException e) {
             log.error(e.getMessage(), e);
         }
         log.info("Document submitted to Contenthub.");
-        log.info("Id: {}", sci.getUri().getUnicodeString());
-        log.info("Mime type: {}", sci.getMimeType());
-        log.info("Constraints: {}", sci.getConstraints().toString());
+        log.info("Id: {}", ci.getUri().getUnicodeString());
+        log.info("Mime type: {}", ci.getMimeType());
     }
 
-    private Map<String,List<Object>> getConstraintsFromNode(ContentContext contentContext) {
-        Map<String,List<Object>> constraints = new HashMap<String,List<Object>>();
+    private MGraph getAdditionalMetadataFromNode(ContentContext contentContext) {
+        MGraph additionalMetadata = new IndexedMGraph();
         try {
             PropertyIterator it = contentContext.getNode().getProperties();
             while (it.hasNext()) {
                 javax.jcr.Property p = it.nextProperty();
-                List<Object> propertyVals = new ArrayList<Object>();
-
                 if (!skipProperty(p)) {
                     if (!p.isMultiple()) {
-                        propertyVals.add(JCRUtils.getTypedPropertyValue(p.getType(), p.getValue()));
+                        additionalMetadata.add(new TripleImpl(new UriRef(contentContext.getIdentifier()),
+                                new UriRef(p.getName()), LiteralFactory.getInstance().createTypedLiteral(
+                                    JCRUtils.getTypedPropertyValue(p.getType(), p.getValue()))));
                     } else {
-                        propertyVals.addAll(JCRUtils.getTypedPropertyValues(p.getType(), p.getValues()));
+                        for (Value value : p.getValues()) {
+                            Object typedValue = JCRUtils.getTypedPropertyValue(p.getType(), value);
+                            additionalMetadata.add(new TripleImpl(new UriRef(contentContext.getIdentifier()),
+                                    new UriRef(p.getName()), LiteralFactory.getInstance().createTypedLiteral(
+                                        typedValue)));
+                        }
                     }
-                    constraints.put(p.getName(), propertyVals);
                 }
             }
         } catch (RepositoryException e) {
             log.warn("Failed to process properties of node having: {}", contentContext.getIdentifier());
         }
-        return constraints;
+        return additionalMetadata;
     }
 
     private boolean skipProperty(javax.jcr.Property p) throws RepositoryException {
@@ -420,15 +430,11 @@ public class JCRContenthubFeeder impleme
     }
 
     private ContentContext getContentContextWithBasicInfo(Node n) throws RepositoryException {
-        return getContentContextWithBasicInfo(n, null);
-    }
-
-    private ContentContext getContentContextWithBasicInfo(Node n, String id) throws RepositoryException {
         ContentContext contentContext = new ContentContext();
-        contentContext.setIdentifier((id == null || id.equals("")) ? n.getIdentifier() : id);
         contentContext.setNode(n);
         contentContext.setNodeType(n.getPrimaryNodeType().getName());
         contentContext.setNodeName(n.getName());
+        contentContext.setIdentifier(attachBaseURI(n.getIdentifier()));
         return contentContext;
     }
 
@@ -509,6 +515,13 @@ public class JCRContenthubFeeder impleme
         }
     }
 
+    private String attachBaseURI(String id) {
+        if (!id.contains(":")) {
+            id = CONTENT_ITEM_URI_PREFIX + id;
+        }
+        return id;
+    }
+
     /**
      * This context class holding the node itself and information related it exists to prevent repetitive
      * request for name, identifier, node type of actual node

Modified: stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/ContenthubFeeder.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/ContenthubFeeder.java?rev=1414049&r1=1414048&r2=1414049&view=diff
==============================================================================
--- stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/ContenthubFeeder.java (original)
+++ stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/ContenthubFeeder.java Tue Nov 27 09:54:54 2012
@@ -18,6 +18,8 @@ package org.apache.stanbol.cmsadapter.se
 
 import java.util.Dictionary;
 
+import org.apache.clerezza.rdf.core.UriRef;
+
 /**
  * This interface provides methods to submit and delete content items to/from Contenthub.
  * 
@@ -47,18 +49,26 @@ public interface ContenthubFeeder {
     public static final String PROP_CONTENT_PROPERTIES = "org.apache.stanbol.cmsadapter.servicesapi.mapping.ContenthubFeeder.contentFields";
 
     /**
+     * When creating a ContentItem from a node, metadata of this node is added as an additional part to
+     * ContentItem through this URI
+     */
+    public static final UriRef ADDITIONAL_METADATA_URI = new UriRef(
+            "org.apache.stanbol.cmsadapter.servicesapi.mapping.ContenthubFeeder.additionalMetadata");
+
+    /*
+     * 
+     */
+    public static final String CONTENT_ITEM_URI_PREFIX = "urn:content-item-";
+
+    /**
      * Creates a content item in Contenthub by leveraging the content repository object itself e.g <b>Node</b>
      * in JCR, <b>Document</b> in CMIS. If there is an already existing content item in the Contenthub with
      * the same id, the existing content item should be deleted first.
      * 
      * @param o
      *            Content repository object to be transformed into a content item in Contenthub
-     * @param id
-     *            Optional ID for the content item in Contenthub. If this parameter is specified, it will be
-     *            used as the ID of the content item in Contenthub. Otherwise, the object's own ID in the
-     *            content repository will be used.
      */
-    void submitContentItemByCMSObject(Object o, String id);
+    void submitContentItemByCMSObject(Object o);
 
     /**
      * Creates a content item in Contenthub by leveraging the content repository object itself e.g <b>Node</b>
@@ -67,15 +77,11 @@ public interface ContenthubFeeder {
      * 
      * @param o
      *            Content repository object to be transformed into a content item in Contenthub
-     * @param id
-     *            Optional ID for the content item in Contenthub. If this parameter is specified, it will be
-     *            used as the ID of the content item in Contenthub. Otherwise, the object's own ID in the
-     *            content repository will be used.
      * @param indexName
      *            Name of the Solr index managed by Contenthub. Specified index will be used to store the
      *            submitted content item
      */
-    void submitContentItemByCMSObject(Object o, String id, String indexName);
+    void submitContentItemByCMSObject(Object o, String indexName);
 
     /**
      * Submits content item by its ID to the Contenthub. If there is an already existing content item in the