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 2011/08/04 20:38:17 UTC

svn commit: r1153964 - in /incubator/stanbol/trunk/cmsadapter: cmis/ cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/repository/ core/ core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/ core/src/main/resources/ core/src/main/resources...

Author: suat
Date: Thu Aug  4 18:38:16 2011
New Revision: 1153964

URL: http://svn.apache.org/viewvc?rev=1153964&view=rev
Log:
STANBOL 306:
-Implemented a RDFBridge interface and an implementation of that interface which takes necessary configuration values through Felix Configuration console. Raw RDF data is annotated according to configurations of RDFBridgeImpl. Detailed information can be found in Javadocs.
-The next task in this issue is to implement components that store annotated RDF data to repository

Added:
    incubator/stanbol/trunk/cmsadapter/cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/repository/CMISRDFMapper.java
    incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/CMSVocabularyAnnotator.java
    incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeImpl.java
    incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeManager.java
    incubator/stanbol/trunk/cmsadapter/core/src/main/resources/
    incubator/stanbol/trunk/cmsadapter/core/src/main/resources/OSGI-INF/
    incubator/stanbol/trunk/cmsadapter/core/src/main/resources/OSGI-INF/metatype/
    incubator/stanbol/trunk/cmsadapter/core/src/main/resources/OSGI-INF/metatype/metatype.properties
    incubator/stanbol/trunk/cmsadapter/jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/repository/JCRRDFMapper.java
    incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFBridge.java
    incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFMapper.java
    incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java
Modified:
    incubator/stanbol/trunk/cmsadapter/cmis/pom.xml
    incubator/stanbol/trunk/cmsadapter/core/pom.xml
    incubator/stanbol/trunk/cmsadapter/jcr/pom.xml
    incubator/stanbol/trunk/cmsadapter/servicesapi/pom.xml
    incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/CMSAdapterVocabulary.java
    incubator/stanbol/trunk/cmsadapter/web/pom.xml
    incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/CMSAdapterWebFragment.java
    incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/BridgeDefinitionsResource.java

Modified: incubator/stanbol/trunk/cmsadapter/cmis/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/cmis/pom.xml?rev=1153964&r1=1153963&r2=1153964&view=diff
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/cmis/pom.xml (original)
+++ incubator/stanbol/trunk/cmsadapter/cmis/pom.xml Thu Aug  4 18:38:16 2011
@@ -1,20 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
@@ -71,6 +65,10 @@
 			<groupId>org.apache.chemistry.opencmis</groupId>
 			<artifactId>chemistry-opencmis-client-api</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>rdf.core</artifactId>
+		</dependency>
 	</dependencies>
 
 </project>

Added: incubator/stanbol/trunk/cmsadapter/cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/repository/CMISRDFMapper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/repository/CMISRDFMapper.java?rev=1153964&view=auto
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/repository/CMISRDFMapper.java (added)
+++ incubator/stanbol/trunk/cmsadapter/cmis/src/main/java/org/apache/stanbol/cmsadapter/cmis/repository/CMISRDFMapper.java Thu Aug  4 18:38:16 2011
@@ -0,0 +1,34 @@
+/*
+ * 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.cmsadapter.cmis.repository;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.cmsadapter.servicesapi.mapping.RDFMapper;
+
+@Component(immediate=true)
+@Service
+public class CMISRDFMapper implements RDFMapper {
+
+    @Override
+    public void storeRDFinRepository(Object session, MGraph annotatedGraph) {
+        // TODO Auto-generated method stub
+
+    }
+
+}

Modified: incubator/stanbol/trunk/cmsadapter/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/core/pom.xml?rev=1153964&r1=1153963&r2=1153964&view=diff
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/core/pom.xml (original)
+++ incubator/stanbol/trunk/cmsadapter/core/pom.xml Thu Aug  4 18:38:16 2011
@@ -1,20 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
@@ -76,11 +70,23 @@
 			<groupId>org.apache.stanbol</groupId>
 			<artifactId>org.apache.stanbol.enhancer.servicesapi</artifactId>
 		</dependency>
+		
+		<!-- Entityhub -->
+		<dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.entityhub.servicesapi</artifactId>
+		</dependency>
+		
+		<!-- Clerezza -->
 		<dependency>
 			<groupId>org.apache.clerezza</groupId>
 			<artifactId>rdf.core</artifactId>
 		</dependency>
-		
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>rdf.jena.facade</artifactId>
+		</dependency>
+
 		<dependency>
 			<groupId>javax.jcr</groupId>
 			<artifactId>jcr</artifactId>

Added: incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/CMSVocabularyAnnotator.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/CMSVocabularyAnnotator.java?rev=1153964&view=auto
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/CMSVocabularyAnnotator.java (added)
+++ incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/CMSVocabularyAnnotator.java Thu Aug  4 18:38:16 2011
@@ -0,0 +1,345 @@
+/*
+ * 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.cmsadapter.core.mapping;
+
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.jena.facade.JenaGraph;
+import org.apache.stanbol.cmsadapter.servicesapi.helper.CMSAdapterVocabulary;
+import org.apache.stanbol.cmsadapter.servicesapi.mapping.RDFBridge;
+import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.ontology.OntModel;
+import com.hp.hpl.jena.ontology.OntModelSpec;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.RDFWriter;
+
+public class CMSVocabularyAnnotator {
+    private static final Logger log = LoggerFactory.getLogger(CMSAdapterVocabulary.class);
+
+    private static final UriRef RDF_TYPE = new UriRef(NamespaceEnum.rdf + "Type");
+
+    public void addAnnotationsToGraph(List<RDFBridge> rdfBridges, MGraph graph) {
+        LiteralFactory literalFactory = LiteralFactory.getInstance();
+        Map<UriRef,Object> children;
+        Map<UriRef,Object> properties;
+
+        for (RDFBridge bridge : rdfBridges) {
+            children = bridge.getChildrenResources();
+            properties = bridge.getTargetPropertyResources();
+            Iterator<Triple> tripleIterator = graph.filter(null, bridge.getTargetResourcePredicate(),
+                bridge.getTargetResourceValue());
+            UriRef nameProp = bridge.getNameResource();
+            String targetRootPath = bridge.getTargetCMSPath();
+
+            // add cms object annotations
+            while (tripleIterator.hasNext()) {
+                Triple t = tripleIterator.next();
+                NonLiteral subject = t.getSubject();
+                String name = getResourceStringValue(subject, nameProp, graph);
+
+                // There should be a valid name for CMS Object
+                if (!name.contentEquals("")) {
+                    graph.add(new TripleImpl(subject, RDF_TYPE, CMSAdapterVocabulary.CMS_OBJECT));
+
+                    // if this object has already has name and path annotations, it means that it's already
+                    // processed as child of another object. So, don't put new name and path annotations
+                    if (!graph.filter(subject, CMSAdapterVocabulary.CMS_OBJECT_NAME, null).hasNext()) {
+                        graph.add(new TripleImpl(subject, CMSAdapterVocabulary.CMS_OBJECT_NAME,
+                                literalFactory.createTypedLiteral(name)));
+                    }
+
+                    // check children and add child and parent annotations
+                    for (UriRef childPropURI : children.keySet()) {
+                        Iterator<Triple> childrenIt = graph.filter(subject, childPropURI, null);
+                        Map<String,Integer> childNames = new HashMap<String,Integer>();
+                        while (childrenIt.hasNext()) {
+                            Triple child = childrenIt.next();
+                            NonLiteral childSubject = new UriRef(replaceEndCharacters(child.getObject()
+                                    .toString()));
+
+                            String childName = getNameOfProperty(childSubject, children.get(childPropURI),
+                                graph);
+                            if (!childName.contentEquals("")) {
+                                removeExistingTriple(childSubject, CMSAdapterVocabulary.CMS_OBJECT_NAME,
+                                    graph);
+                                graph.add(new TripleImpl(childSubject, RDF_TYPE,
+                                        CMSAdapterVocabulary.CMS_OBJECT));
+                                graph.add(new TripleImpl(childSubject,
+                                        CMSAdapterVocabulary.CMS_OBJECT_PARENT_REF, subject));
+                                graph.add(new TripleImpl(childSubject, CMSAdapterVocabulary.CMS_OBJECT_NAME,
+                                        literalFactory
+                                                .createTypedLiteral(getChildName(childName, childNames))));
+
+                            } else {
+                                log.warn("Failed to obtain a name for child property: {}", childPropURI);
+                            }
+                        }
+                    }
+
+                    // check desired properties to be mapped
+                    Map<UriRef,UriRef> propertiesNamesInBridge = new HashMap<UriRef,UriRef>();
+                    for (UriRef propURI : properties.keySet()) {
+                        String propertyName = getNameOfProperty(subject, properties.get(propURI), graph);
+                        if (!propertyName.contentEquals("")) {
+                            if (!propertiesNamesInBridge.containsKey(propURI)) {
+
+                                UriRef tempRef = new UriRef(propertyName + "Prop" + bridge.hashCode());
+                                propertiesNamesInBridge.put(propURI, tempRef);
+
+                                graph.add(new TripleImpl(tempRef,
+                                        CMSAdapterVocabulary.CMS_OBJECT_PROPERTY_NAME, literalFactory
+                                                .createTypedLiteral(propertyName)));
+                                graph.add(new TripleImpl(tempRef,
+                                        CMSAdapterVocabulary.CMS_OBJECT_PROPERTY_URI, propURI));
+                            }
+                            graph.add(new TripleImpl(subject, CMSAdapterVocabulary.CMS_OBJECT_HAS_PROPERTY,
+                                    propertiesNamesInBridge.get(propURI)));
+                        } else {
+                            log.warn("Failed to obtain a name for property: {}", propURI);
+                        }
+                    }
+                }
+            }
+
+            /*
+             * it is assumed that any two object to be created from different bridges will not be related with
+             * each other. Otherwise, it is necessary to assign target cms path for each CMS Object
+             */
+            annotatePaths(targetRootPath, graph);
+        }
+
+        // remove code
+        try {
+            saveOntology(graph, ontologyURI, true);
+        } catch (FileNotFoundException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    private static void annotatePaths(String targetRootPath, MGraph graph) {
+        // first detect root objects
+        List<NonLiteral> roots = new ArrayList<NonLiteral>();
+        Iterator<Triple> it = graph.filter(null, RDF_TYPE, CMSAdapterVocabulary.CMS_OBJECT);
+        while (it.hasNext()) {
+            Triple t = it.next();
+            if (isRoot(t, graph)) {
+                roots.add(t.getSubject());
+            }
+        }
+
+        // assign paths to children recursively
+        LiteralFactory literalFactory = LiteralFactory.getInstance();
+        for (NonLiteral root : roots) {
+            assignChildrenPaths(targetRootPath, root, graph, literalFactory, true);
+        }
+    }
+
+    private static void assignChildrenPaths(String cmsRootPath,
+                                            NonLiteral root,
+                                            MGraph graph,
+                                            LiteralFactory literalFactory,
+                                            boolean firstLevel) {
+        String rootName = getResourceStringValue(root, CMSAdapterVocabulary.CMS_OBJECT_NAME, graph);
+        String rootPath = cmsRootPath;
+        if (firstLevel) {
+            rootPath = formRootPath(cmsRootPath, rootName);
+            graph.add(new TripleImpl(root, CMSAdapterVocabulary.CMS_OBJECT_PATH, literalFactory
+                    .createTypedLiteral(rootPath)));
+        }
+
+        Iterator<Triple> it = graph.filter(null, CMSAdapterVocabulary.CMS_OBJECT_PARENT_REF, root);
+        while (it.hasNext()) {
+            NonLiteral childSubject = it.next().getSubject();
+            String childName = getResourceStringValue(childSubject, CMSAdapterVocabulary.CMS_OBJECT_NAME,
+                graph);
+            String childPath = formRootPath(rootPath, childName);
+            graph.add(new TripleImpl(childSubject, CMSAdapterVocabulary.CMS_OBJECT_PATH, literalFactory
+                    .createTypedLiteral(childPath)));
+            assignChildrenPaths(childPath, childSubject, graph, literalFactory, false);
+        }
+    }
+
+    private static boolean isRoot(Triple cmsObjectTriple, MGraph graph) {
+        NonLiteral subject = cmsObjectTriple.getSubject();
+        if (graph.filter(subject, CMSAdapterVocabulary.CMS_OBJECT_PARENT_REF, null).hasNext()) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    private static String formRootPath(String targetRootPath, String objectName) {
+        if (!targetRootPath.endsWith("/")) {
+            targetRootPath += "/";
+        }
+        return targetRootPath + objectName;
+    }
+
+    private static String getNameOfProperty(NonLiteral subject, Object nameProp, MGraph graph) {
+        if (nameProp instanceof String) {
+            return (String) nameProp;
+        } else if (nameProp instanceof UriRef) {
+            return getResourceStringValue(subject, (UriRef) nameProp, graph);
+        } else {
+            log.warn("Only String and UriRef instance can be passed to specify property name");
+            return "";
+        }
+    }
+
+    private static String getChildName(String candidateName, Map<String,Integer> childNames) {
+        Integer childNameCount = childNames.get(candidateName);
+        if (childNameCount != null) {
+            candidateName += (childNameCount + 1);
+            childNames.put(candidateName, (childNameCount + 1));
+        } else {
+            childNames.put(candidateName, 1);
+        }
+        return candidateName;
+    }
+
+    private static String replaceEndCharacters(String resource) {
+        return resource.replace("<", "").replace(">", "");
+    }
+
+    private static String getResourceStringValue(NonLiteral subject, UriRef nameProp, MGraph graph) {
+        Iterator<Triple> it = graph.filter(subject, nameProp, null);
+        if (it.hasNext()) {
+            Triple t = it.next();
+            Resource r = t.getObject();
+            if (r instanceof Literal) {
+                return ((Literal) r).getLexicalForm();
+            } else {
+                log.warn("Resource value is not a Literal for triple: {}", t);
+                return "";
+            }
+        } else {
+            log.warn("Failed to get name from subject: {} and name property: {}", subject, nameProp);
+            return "";
+        }
+    }
+
+    private static void removeExistingTriple(NonLiteral subject, UriRef predicate, MGraph mGraph) {
+        Iterator<Triple> it = mGraph.filter(subject, predicate, null);
+        if (it.hasNext()) {
+            mGraph.remove(it.next());
+        }
+    }
+
+    // /////////////////////////////////////
+
+    private static String ontologyURI = "http://deneme#";
+
+    public static void main(String[] args) throws FileNotFoundException {
+        CMSVocabularyAnnotator cmsVocabularyAnnotator = new CMSVocabularyAnnotator();
+        cmsVocabularyAnnotator.fillCMSObjects();
+    }
+
+    private MGraph fillCMSObjects() throws FileNotFoundException {
+
+        MGraph mGraph = new SimpleMGraph();
+        UriRef cmsObject1 = new UriRef(ontologyURI + "Concept1");
+        UriRef cmsObject2 = new UriRef(ontologyURI + "Concept2");
+        UriRef cmsObject3 = new UriRef(ontologyURI + "Concept3");
+        UriRef populatedPlace2 = new UriRef(ontologyURI + "PopulatedPlace2");
+        UriRef populatedPlace3 = new UriRef(ontologyURI + "PopulatedPlace3");
+        UriRef city1 = new UriRef(ontologyURI + "City1");
+        UriRef city2 = new UriRef(ontologyURI + "City2");
+
+        // types
+        addProperty(cmsObject1, NamespaceEnum.rdf + "Type", new UriRef(NamespaceEnum.skos + "Concept"), null,
+            mGraph);
+        addProperty(cmsObject2, NamespaceEnum.rdf + "Type", new UriRef(NamespaceEnum.skos + "Concept"), null,
+            mGraph);
+        addProperty(cmsObject3, NamespaceEnum.rdf + "Type", new UriRef(NamespaceEnum.skos + "Concept"), null,
+            mGraph);
+        addProperty(populatedPlace2, NamespaceEnum.rdf + "Type", new UriRef(NamespaceEnum.dbpediaOnt
+                                                                            + "PopulatedPlace"), null, mGraph);
+        addProperty(populatedPlace3, NamespaceEnum.rdf + "Type", new UriRef(NamespaceEnum.dbpediaOnt
+                                                                            + "PopulatedPlace"), null, mGraph);
+
+        // labels
+        addProperty(cmsObject1, NamespaceEnum.rdfs + "label", null, "CMSObject1", mGraph);
+        addProperty(cmsObject2, NamespaceEnum.rdfs + "label", null, "CMSObject2", mGraph);
+        addProperty(cmsObject3, NamespaceEnum.rdfs + "label", null, "CMSObject3", mGraph);
+
+        // children
+        addProperty(cmsObject1, NamespaceEnum.skos + "narrower", cmsObject2, null, mGraph);
+        addProperty(cmsObject3, NamespaceEnum.skos + "narrower", cmsObject3, null, mGraph);
+        addProperty(cmsObject1, NamespaceEnum.dbpediaProp + "city", city1, null, mGraph);
+        addProperty(cmsObject2, NamespaceEnum.dbpediaProp + "city", city2, null, mGraph);
+
+        // prop
+        addProperty(cmsObject2, NamespaceEnum.dbpediaProp + "place", populatedPlace2, null, mGraph);
+        addProperty(cmsObject3, NamespaceEnum.dbpediaProp + "place", populatedPlace3, null, mGraph);
+        addProperty(cmsObject1, NamespaceEnum.skos + "definition", null, "CMSObject1Def", mGraph);
+        addProperty(cmsObject2, NamespaceEnum.skos + "definition", null, "CMSObject2Def", mGraph);
+        addProperty(cmsObject3, NamespaceEnum.skos + "definition", null, "CMSObject3Def", mGraph);
+
+        saveOntology(mGraph, ontologyURI, false);
+
+        return mGraph;
+    }
+
+    private void addProperty(UriRef subject, String predicate, UriRef object, Object litObject, MGraph mGraph) {
+        UriRef prop = new UriRef(predicate);
+        if (object != null) {
+            mGraph.add(new TripleImpl(subject, prop, object));
+        } else if (litObject != null) {
+            mGraph.add(new TripleImpl(subject, prop, LiteralFactory.getInstance().createTypedLiteral(
+                litObject)));
+        }
+    }
+
+    private static void saveOntology(TripleCollection tc, String ontologyURI, boolean output) throws FileNotFoundException {
+        JenaGraph jenaGraph = new JenaGraph(tc);
+        Model model = ModelFactory.createModelForGraph(jenaGraph);
+        OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, model);
+
+        FileOutputStream fos;
+        if (output) {
+            fos = new FileOutputStream("/home/srdc/Desktop/cmsAdapterTest/rdfmap/Outmgraph");
+        } else {
+            fos = new FileOutputStream("/home/srdc/Desktop/cmsAdapterTest/rdfmap/mgraph");
+        }
+        RDFWriter rdfWriter = ontModel.getWriter("RDF/XML");
+        rdfWriter.setProperty("xmlbase", ontologyURI);
+        rdfWriter.write(ontModel, fos, ontologyURI);
+    }
+
+    // /////////////////////////////////////
+}

Added: incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeImpl.java?rev=1153964&view=auto
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeImpl.java (added)
+++ incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeImpl.java Thu Aug  4 18:38:16 2011
@@ -0,0 +1,259 @@
+/*
+ * 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.cmsadapter.core.mapping;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.cmsadapter.servicesapi.mapping.RDFBridge;
+import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Main aim of this class is to provide ability to create {@code RDFBridge} instances through the
+ * configuration interface of Felix console. Currently there are 5 configuration field in this implementation
+ * of {@link RDFBridge}:
+ * 
+ * <ul>
+ * <li><b>Resource selector:</b></li> This property is used to filter resources from the RDF data. It should
+ * have the following syntax:<br>
+ * <br>
+ * rdf:Type > skos:Concept <br>
+ * <br>
+ * This example states that triples having <b>rdf:Type</b> predicate and <b>skos:Concept</b> object will be
+ * filtered. And subject of selected triples indicates the resource to be created as node/object in the
+ * repository. It is also acceptable to pass full URIs such as <br>
+ * http://www.w3.org/1999/02/22-rdf-syntax-ns#Type > http://www.w3.org/2004/02/skos/core#Concept<br>
+ * <li><b>Name:</b></li> This property indicates the predicate which points to the name of node/object to be
+ * created in the repository. It should indicate a single URI such as <b>rdfs:label</b> or
+ * <b>http://www.w3.org/2000/01/rdf-schema#label</b>. Actually name value is obtained through the triple
+ * (s,p,o) where s is one of the subjects filtered by the "Resource Selector" configuration parameter, p is
+ * this parameter.<br>
+ * <li><b>Properties:</b></li> This property specifies the properties of nodes/objects to be created in the
+ * repository. Value of this configuration should be like <b>skos:Definition > definition</b> or
+ * <b>skos:Definition</b>. First option states that skos:Definition property of a filtered subject will be
+ * created as a property having name "repository" of repository object. In the second case the name of the
+ * property will directly be "skos:Definition".
+ * <li><b>Children:</b></li> This property specifies the children of nodes/objecs to be created in the
+ * repository. Value of this configuration should be like <b>skos:narrower > narrowerObject</b> or
+ * <b>skos:narrower > rdfs:label</b>. First option has same logic with the previous parameter. In the second
+ * case, rdfs:label of resource representing child object will be set as the name of child object/node in the
+ * repository. This option would be useful to create hierarchies.
+ * </ul>
+ * 
+ * @author suat
+ * 
+ */
+@Component(configurationFactory = true, metatype = true, immediate = true)
+@Service(value = RDFBridge.class)
+@Properties(value = {
+                     @Property(name = RDFBridgeImpl.PROP_RESOURCE_SELECTOR, value = "rdf:Type > skos:Concept"),
+                     @Property(name = RDFBridgeImpl.PROP_NAME, value = "rdfs:label"),
+                     @Property(name = RDFBridgeImpl.PROP_PROPERTIES, cardinality = 1000, value = {
+                                                                                                  "skos:related > relatedWith",
+                                                                                                  "skos:definition > definition"}),
+                     @Property(name = RDFBridgeImpl.PROP_CHILDREN, cardinality = 1000, value = {"skos:narrower > narrowerConcept"}),
+                     @Property(name = RDFBridgeImpl.PROP_CMS_PATH)})
+public class RDFBridgeImpl implements RDFBridge {
+
+    public static final String PROP_RESOURCE_SELECTOR = "org.apache.stanbol.cmsadapter.rdfbridge.resourceSelector";
+    public static final String PROP_PROPERTIES = "org.apache.stanbol.cmsadapter.rdfbridge.properties";
+    public static final String PROP_NAME = "org.apache.stanbol.cmsadapter.rdfbridge.name";
+    public static final String PROP_CHILDREN = "org.apache.stanbol.cmsadapter.rdfbridge.children";
+    public static final String PROP_CMS_PATH = "org.apaches.stanbol.cmsadapter.rdfbridge.cmsPath";
+
+    private static final Logger log = LoggerFactory.getLogger(RDFBridgeImpl.class);
+
+    private String targetCMSPath;
+    private UriRef targetResourcePredicate;
+    private UriRef targetResourceValue;
+    private UriRef nameResource;
+    Map<UriRef,Object> targetPropertyMappings = new HashMap<UriRef,Object>();
+    Map<UriRef,Object> targetChildrenMappings = new HashMap<UriRef,Object>();
+
+    @SuppressWarnings("unchecked")
+    @Activate
+    protected void activate(ComponentContext context) throws ConfigurationException {
+        Dictionary<String,Object> properties = (Dictionary<String,Object>) context.getProperties();
+        parseTargetResourceConfig(properties);
+        parsePropertyMappings(properties);
+        parseChilrenMappings(properties);
+        this.targetCMSPath = (String) checkProperty(properties, PROP_CMS_PATH, true);
+        this.nameResource = parseUriRefFromConfig((String) checkProperty(properties, PROP_NAME, true));
+    }
+
+    @Override
+    public String getTargetCMSPath() {
+        return this.targetCMSPath;
+    }
+
+    @Override
+    public UriRef getTargetResourcePredicate() {
+        return this.targetResourcePredicate;
+    }
+
+    @Override
+    public UriRef getTargetResourceValue() {
+        return this.targetResourceValue;
+    }
+
+    @Override
+    public UriRef getNameResource() {
+        return this.nameResource;
+    }
+
+    @Override
+    public Map<UriRef,Object> getTargetPropertyResources() {
+        return this.targetPropertyMappings;
+    }
+
+    @Override
+    public Map<UriRef,Object> getChildrenResources() {
+        return this.targetChildrenMappings;
+    }
+
+    private void parseTargetResourceConfig(Dictionary<String,Object> properties) throws ConfigurationException {
+        String targetResourceConfig = (String) checkProperty(properties, PROP_RESOURCE_SELECTOR, true);
+        String[] configParts = parseConfigParts(targetResourceConfig, true);
+
+        this.targetResourcePredicate = parseUriRefFromConfig(configParts[0]);
+        this.targetResourceValue = parseUriRefFromConfig(configParts[1]);
+    }
+
+    private void parsePropertyMappings(Dictionary<String,Object> properties) {
+        Object value = null;
+        try {
+            value = checkProperty(properties, PROP_PROPERTIES, false);
+        } catch (ConfigurationException e) {
+            // not the case
+        }
+        if (value != null) {
+            if (value instanceof String) {
+                String config = (String) value;
+                try {
+                    String[] configParts = parseConfigParts(config, false);
+                    this.targetPropertyMappings.put(parseUriRefFromConfig(configParts[0]),
+                        configParts[configParts.length - 1]);
+                } catch (ConfigurationException e) {
+                    log.warn("Failed to parse configuration value: {}", config);
+                    log.warn("Configuration value should be in the format e.g skos:Definition > definition");
+                }
+
+            } else if (value instanceof String[]) {
+                for (String config : (String[]) value) {
+                    try {
+                        String[] configParts = parseConfigParts(config, false);
+                        this.targetPropertyMappings.put(parseUriRefFromConfig(configParts[0]),
+                            configParts[configParts.length - 1]);
+                    } catch (ConfigurationException e) {
+                        log.warn("Failed to parse configuration value: {}", config);
+                        log.warn("Configuration value should be in the format e.g skos:Definition > definition");
+                    }
+                }
+            }
+        }
+    }
+
+    private void parseChilrenMappings(Dictionary<String,Object> properties) {
+        Object value = null;
+        try {
+            value = checkProperty(properties, PROP_CHILDREN, false);
+        } catch (ConfigurationException e) {
+            // not the case
+        }
+        if (value != null) {
+            if (value instanceof String) {
+                String config = (String) value;
+                try {
+                    String[] configParts = parseConfigParts(config, true);
+                    this.targetChildrenMappings.put(parseUriRefFromConfig(configParts[0]),
+                        parsePropertyName(configParts[1], true));
+                } catch (ConfigurationException e) {
+                    log.warn("Failed to parse configuration value: {}", config);
+                    log.warn("Configuration value should be in the format e.g skos:Definition > definition");
+                }
+
+            } else if (value instanceof String[]) {
+                for (String config : (String[]) value) {
+                    try {
+                        String[] configParts = parseConfigParts(config, true);
+                        this.targetChildrenMappings.put(parseUriRefFromConfig(configParts[0]),
+                            parsePropertyName(configParts[1], true));
+                    } catch (ConfigurationException e) {
+                        log.warn("Failed to parse configuration value: {}", config);
+                        log.warn("Configuration value should be in the format e.g skos:Definition > definition");
+                    }
+                }
+            }
+        }
+    }
+
+    private UriRef parseUriRefFromConfig(String config) {
+        return new UriRef(NamespaceEnum.getFullName(config));
+    }
+
+    private Object parsePropertyName(String config, boolean resolveURI) {
+        if (config.contains(":") && resolveURI) {
+            return new UriRef(NamespaceEnum.getFullName(config));
+        } else {
+            return config;
+        }
+    }
+
+    private Object checkProperty(Dictionary<String,Object> properties, String key, boolean required) throws ConfigurationException {
+        Object value = properties.get(key);
+        if (value == null) {
+            if (required) {
+                throw new ConfigurationException(key, "Failed to get value for this property");
+            } else {
+                return null;
+            }
+        } else {
+            return value;
+        }
+    }
+
+    private String[] parseConfigParts(String config, boolean twoParts) throws ConfigurationException {
+        String[] configParts = config.split(">");
+        int parts = configParts.length;
+        if (parts != 2 && twoParts) {
+            throw new ConfigurationException(PROP_RESOURCE_SELECTOR,
+                    "Target resource and resource value should be seperated by a single'>' sign");
+        }
+
+        if (parts == 1 || parts == 2) {
+            configParts[0] = configParts[0].trim();
+            if (parts == 2) {
+                configParts[1] = configParts[1].trim();
+            }
+        } else {
+            throw new ConfigurationException(PROP_RESOURCE_SELECTOR,
+                    "Target resource and resource value should be seperated by a single'>' sign");
+        }
+        return configParts;
+    }
+}

Added: incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeManager.java?rev=1153964&view=auto
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeManager.java (added)
+++ incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeManager.java Thu Aug  4 18:38:16 2011
@@ -0,0 +1,105 @@
+/*
+ * 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.cmsadapter.core.mapping;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.ReferenceStrategy;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.cmsadapter.servicesapi.mapping.RDFBridge;
+import org.apache.stanbol.cmsadapter.servicesapi.mapping.RDFMapper;
+import org.apache.stanbol.cmsadapter.servicesapi.model.web.ConnectionInfo;
+import org.apache.stanbol.cmsadapter.servicesapi.repository.RepositoryAccess;
+import org.apache.stanbol.cmsadapter.servicesapi.repository.RepositoryAccessException;
+import org.apache.stanbol.cmsadapter.servicesapi.repository.RepositoryAccessManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This component keeps track of {@link RDFBridge}s and {@link RDFMapper}s in the environment and it provides
+ * a method to submit RDF data to be annotated according to <code>RDFBridge</code>s. <code>RDFMapper</code>s
+ * update repository based on the annotated RDF.
+ * 
+ * @author suat
+ * 
+ */
+@Component(immediate = true)
+@Service(value = RDFBridgeManager.class)
+public class RDFBridgeManager {
+
+    private static final Logger log = LoggerFactory.getLogger(RDFBridgeManager.class);
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_MULTIPLE, referenceInterface = RDFBridge.class, policy = ReferencePolicy.DYNAMIC, bind = "bindRDFBridge", unbind = "unbindRDFBridge", strategy = ReferenceStrategy.EVENT)
+    List<RDFBridge> rdfBridges = new CopyOnWriteArrayList<RDFBridge>();
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_MULTIPLE, referenceInterface = RDFMapper.class, policy = ReferencePolicy.DYNAMIC, bind = "bindRDFMapper", unbind = "unbindRDFMapper", strategy = ReferenceStrategy.EVENT)
+    List<RDFMapper> rdfMappers = new CopyOnWriteArrayList<RDFMapper>();
+
+    @Reference
+    RepositoryAccessManager accessManager;
+
+    public void storeRDFToRepository(ConnectionInfo connectionInfo, MGraph rawRDFData) throws RepositoryAccessException {
+        // According to connection type get RDF mapper, repository accessor, session
+        RDFMapper mapper = getRDFMapper(connectionInfo);
+        RepositoryAccess repositoryAccess = accessManager.getRepositoryAccessor(connectionInfo);
+        Object session = repositoryAccess.getSession(connectionInfo);
+
+        // Annotate raw RDF with CMS vocabulary annotations according to bridges
+        CMSVocabularyAnnotator annotator = new CMSVocabularyAnnotator();
+        annotator.addAnnotationsToGraph(rdfBridges, rawRDFData);
+
+        // Store annotated RDF in repository
+        mapper.storeRDFinRepository(session, rawRDFData);
+    }
+
+    private RDFMapper getRDFMapper(ConnectionInfo connectionInfo) {
+        RDFMapper mapper = null;
+        String type = connectionInfo.getConnectionType();
+        for (RDFMapper rdfMapper : rdfMappers) {
+            if (rdfMapper.getClass().getSimpleName().startsWith(type)) {
+                mapper = (RDFMapper) rdfMapper;
+            }
+        }
+        if (mapper == null) {
+            log.warn("Failed to retrieve RDFMapper for connection type: {}", type);
+            throw new IllegalStateException("Failed to retrieve RDFMapper for connection type: " + type);
+        }
+        return mapper;
+    }
+
+    protected void bindRDFBridge(RDFBridge rdfBridge) {
+        rdfBridges.add(rdfBridge);
+    }
+
+    protected void unbindRDFBridge(RDFBridge rdfBridge) {
+        rdfBridges.remove(rdfBridge);
+    }
+
+    protected void bindRDFMapper(RDFMapper rdfMapper) {
+        rdfMappers.add(rdfMapper);
+    }
+
+    protected void unbindRDFMapper(RDFMapper rdfMapper) {
+        rdfMappers.remove(rdfMapper);
+    }
+}

Added: incubator/stanbol/trunk/cmsadapter/core/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/core/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1153964&view=auto
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/core/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ incubator/stanbol/trunk/cmsadapter/core/src/main/resources/OSGI-INF/metatype/metatype.properties Thu Aug  4 18:38:16 2011
@@ -0,0 +1,32 @@
+# 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.
+
+#===============================================================================
+#Properties and Options used to configure RDF Bridges
+#===============================================================================
+org.apache.stanbol.cmsadapter.rdfbridge.name=Apache Stanbol CMS Adapter RDF Bridge Configurations
+org.apache.stanbol.cmsadapter.rdfbridge.description=This configuration panel allows to configure create bridges between CMS and RDF data
+
+org.apache.stanbol.cmsadapter.rdfbridge.resourceSelector.name=Resource Selector
+org.apache.stanbol.cmsadapter.rdfbridge.resourceSelector.description=Provides obtaining specified resource from RDF data. Fetched resource are created as nodes in the CMS.
+
+org.apache.stanbol.cmsadapter.rdfbridge.properties.name=Properties
+org.apache.stanbol.cmsadapter.rdfbridge.properties.description=Provides specifying target RDF resources to be created as properties of nodes in the CMS. Property names are also specified in these configuration.
+ 
+org.apache.stanbol.cmsadapter.rdfbridge.children.name=Children
+org.apache.stanbol.cmsadapter.rdfbridge.children.description=Provides specifying target RDF resource to be created as child nodes in the CMS. Children names are also specified in these configuration.
+
+org.apache.stanbol.cmsadapter.rdfbridge.cmsPath.name=CMS Path
+org.apache.stanbol.cmsadapter.rdfbridge.cmsPath.description=Provides setting of CMS path in which new nodes will be created or existing ones will be searched.
\ No newline at end of file

Modified: incubator/stanbol/trunk/cmsadapter/jcr/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/jcr/pom.xml?rev=1153964&r1=1153963&r2=1153964&view=diff
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/jcr/pom.xml (original)
+++ incubator/stanbol/trunk/cmsadapter/jcr/pom.xml Thu Aug  4 18:38:16 2011
@@ -1,20 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
@@ -51,6 +45,13 @@
 			<groupId>org.apache.stanbol</groupId>
 			<artifactId>org.apache.stanbol.cmsadapter.servicesapi</artifactId>
 		</dependency>
+		
+		<!-- Need only for NamespaceEnum -->
+		<dependency>
+			<groupId>org.apache.stanbol</groupId>
+			<artifactId>org.apache.stanbol.entityhub.servicesapi</artifactId>
+		</dependency>
+		
 		<dependency>
 			<groupId>org.apache.felix</groupId>
 			<artifactId>org.apache.felix.scr.annotations</artifactId>
@@ -75,6 +76,10 @@
 			<groupId>com.hp.hpl.jena</groupId>
 			<artifactId>jena</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>rdf.core</artifactId>
+		</dependency>
 	</dependencies>
 
 </project>

Added: incubator/stanbol/trunk/cmsadapter/jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/repository/JCRRDFMapper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/repository/JCRRDFMapper.java?rev=1153964&view=auto
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/repository/JCRRDFMapper.java (added)
+++ incubator/stanbol/trunk/cmsadapter/jcr/src/main/java/org/apache/stanbol/cmsadapter/jcr/repository/JCRRDFMapper.java Thu Aug  4 18:38:16 2011
@@ -0,0 +1,25 @@
+package org.apache.stanbol.cmsadapter.jcr.repository;
+
+import java.util.Iterator;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.cmsadapter.servicesapi.helper.CMSAdapterVocabulary;
+import org.apache.stanbol.cmsadapter.servicesapi.mapping.RDFMapper;
+import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
+
+@Component(immediate = true)
+@Service
+public class JCRRDFMapper implements RDFMapper {
+
+	@Override
+	public void storeRDFinRepository(Object session, MGraph annotatedGraph) {
+		Iterator<Triple> cmsObjectIt = annotatedGraph.filter(null, new UriRef(NamespaceEnum.rdf + "Type"),
+				CMSAdapterVocabulary.CMS_OBJECT);
+		
+	}
+
+}

Modified: incubator/stanbol/trunk/cmsadapter/servicesapi/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/servicesapi/pom.xml?rev=1153964&r1=1153963&r2=1153964&view=diff
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/servicesapi/pom.xml (original)
+++ incubator/stanbol/trunk/cmsadapter/servicesapi/pom.xml Thu Aug  4 18:38:16 2011
@@ -1,20 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
@@ -69,5 +63,9 @@
 			<groupId>com.hp.hpl.jena</groupId>
 			<artifactId>jena</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>rdf.core</artifactId>
+		</dependency>
 	</dependencies>
 </project>

Modified: incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/CMSAdapterVocabulary.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/CMSAdapterVocabulary.java?rev=1153964&r1=1153963&r2=1153964&view=diff
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/CMSAdapterVocabulary.java (original)
+++ incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/CMSAdapterVocabulary.java Thu Aug  4 18:38:16 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.stanbol.cmsadapter.servicesapi.helper;
 
+import org.apache.clerezza.rdf.core.UriRef;
+
 import com.hp.hpl.jena.rdf.model.Property;
 import com.hp.hpl.jena.rdf.model.Resource;
 import com.hp.hpl.jena.rdf.model.ResourceFactory;
@@ -28,15 +30,13 @@ import com.hp.hpl.jena.rdf.model.Resourc
  * 
  */
 public class CMSAdapterVocabulary {
-    private static final String RESOURCE_DELIMITER = "#";
     private static final String PATH_DELIMITER = "/";
 
     public static final String DEFAULT_NS_URI = "http://org.apache.stanbol";
 
     public static final String CMS_ADAPTER_VOCABULARY_PREFIX = "cmsad";
     public static final String CMS_ADAPTER_VOCABULARY_URI = DEFAULT_NS_URI + PATH_DELIMITER
-                                                            + CMS_ADAPTER_VOCABULARY_PREFIX
-                                                            + RESOURCE_DELIMITER;
+                                                            + CMS_ADAPTER_VOCABULARY_PREFIX;
 
     /*
      * Property to represent the path of the CMS item
@@ -120,4 +120,48 @@ public class CMSAdapterVocabulary {
         URI = OntologyResourceHelper.addResourceDelimiter(URI);
         return ResourceFactory.createResource(URI + local);
     }
+
+    /**
+     * Represent the RDF type of CMS Object in the content management system
+     */
+    public static final UriRef CMS_OBJECT = new UriRef(CMS_ADAPTER_VOCABULARY_URI + PATH_DELIMITER
+                                                       + "CMSObject");
+
+    /**
+     * Represents a reference to name of a CMS Object
+     */
+    public static final UriRef CMS_OBJECT_NAME = new UriRef(CMS_ADAPTER_VOCABULARY_URI + "#name");
+    
+    /**
+     * Represents a reference to path of a CMS Object
+     */
+    public static final UriRef CMS_OBJECT_PATH = new UriRef(CMS_ADAPTER_VOCABULARY_URI + "#path");
+    
+    /**
+     * Represents a reference to parent of a CMS Object
+     */
+    public static final UriRef CMS_OBJECT_PARENT_REF = new UriRef(CMS_ADAPTER_VOCABULARY_URI + "#parentRef");
+
+    /**
+     * Represents a reference to a property of a CMS Object
+     */
+    public static final UriRef CMS_OBJECT_HAS_PROPERTY = new UriRef(CMS_ADAPTER_VOCABULARY_URI
+                                                                    + "#hasProperty");
+
+    /**
+     * Represents a reference to name of a property of a CMS Object
+     */
+    public static final UriRef CMS_OBJECT_PROPERTY_NAME = new UriRef(CMS_ADAPTER_VOCABULARY_URI
+                                                                     + "#propertyName");
+
+    /**
+     * Represents a reference to URI of a property of a CMS Object
+     */
+    public static final UriRef CMS_OBJECT_PROPERTY_URI = new UriRef(CMS_ADAPTER_VOCABULARY_URI
+                                                                   + "#propertyURI");
+
+    /**
+     * Represents a reference to a child of a CMS Object
+     */
+    public static final UriRef CMS_OBJECT_HAS_CHILD = new UriRef(CMS_ADAPTER_VOCABULARY_URI + "#childRef");
 }

Added: incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFBridge.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFBridge.java?rev=1153964&view=auto
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFBridge.java (added)
+++ incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFBridge.java Thu Aug  4 18:38:16 2011
@@ -0,0 +1,101 @@
+package org.apache.stanbol.cmsadapter.servicesapi.mapping;
+
+import java.util.Map;
+
+import org.apache.clerezza.rdf.core.UriRef;
+
+/**
+ * This interface declares the methods to create mappings between RDF data and JCR/CMIS based repositories.
+ * Each {@code RDFBridge} indicates a set of target resource in the RDF data. Resources filtered based on the
+ * configuration of the bridge are created as nodes/object in the repository. This interface also aims to get
+ * configuration values for properties and names of objects to be created in the repository.
+ * 
+ * @author suat
+ * 
+ */
+public interface RDFBridge {
+    /**
+     * Gets the target CMS path of this bridge. Existing CMS objects to be updated will be searched under this
+     * path and new ones will be created considering this as root.
+     * 
+     * @return target CMS path
+     */
+    String getTargetCMSPath();
+
+    /**
+     * Gets the {@link UriRef} to specify target resources for this bridge in RDF. <br>
+     * <br>
+     * For example, if this method returns <b>http://www.w3.org/1999/02/22-rdf-syntax-ns#Type</b> URI, it
+     * means that resources having predicate this URI will be selected for this bridge. Implementations of
+     * this interface should also return corresponding value for this target resource URI with
+     * {@link #getTargetResourceValue()}
+     * 
+     * @return {@link UriRef} of predicate used to obtain resources from RDF
+     * @see {@link #getTargetResourceValue()}
+     */
+    UriRef getTargetResourcePredicate();
+
+    /**
+     * Gets the {@link UriRef} value for target resource returned by {@link #getTargetResourcePredicate()}.
+     * This method and {@link #getTargetResourcePredicate()} specify the resources that are to be created as
+     * nodes in the repository.<br>
+     * <br>
+     * For exapmle, if {@link #getTargetResourcePredicate()} returns
+     * <b>http://www.w3.org/1999/02/22-rdf-syntax-ns#Type</b> and this method returns
+     * <b>http://www.w3.org/2004/02/skos/core#Concept</b>, it means resources that skos:Concept value as their
+     * rdf:Type predicate will be created as nodes in the repository.
+     * 
+     * @return {@link UriRef} of value of predicates to obtain resources from RDF
+     * @see {@link #getTargetResourcePredicate()}
+     */
+    UriRef getTargetResourceValue();
+
+    /**
+     * Gets the {@link UriRef} which specifies the predicate that is used for representing the name of
+     * selected resources. Obtained values are used names of nodes in the repository.<br>
+     * <br>
+     * Considering a triple like (s,p,o), <b>s</b> the subject of the triple is obtained using the values
+     * provided by {@link #getTargetResourcePredicate()} and {@link #getTargetResourceValue()} methods. And
+     * this method provides the predicate <b>p</b>. Eventually, object values as <b>o</b> are used as names of
+     * nodes in the repository.
+     * 
+     * @return {@link UriRef} predicate which represents names of resources that are obtained from RDF
+     */
+    UriRef getNameResource();
+
+    /**
+     * Gets the {@link Map} of which keys represents the {@link UriRef}s predicates that will be created as
+     * properties of nodes in the repository. Values corresponding to those URIs represents the names of the
+     * properties and they should be either {@link String}s or {@link UriRef}s. String values directly used as
+     * the names of properties in the repository. In case of URI, corresponding name value of property is
+     * obtained through the triple whose subject is obtained by {@link #getTargetResourcePredicate()} and
+     * {@link #getTargetResourceValue()} methods and predicate is this URI.
+     * 
+     * @return {@link Map} keeping the URIs and name indicators of properties to be created in the repository
+     */
+    Map<UriRef,Object> getTargetPropertyResources();
+
+    /**
+     * Gets the {@link Map} of which keys represents the {@link UriRef}s of predicates that represents
+     * children of resources that are obtained by {@link #getTargetResourcePredicate()} and
+     * {@link #getTargetResourceValue()} as in other methods of this interface. Values corresponding to those
+     * URIs represents the names of the child nodes and they should be either {@link String}s or
+     * {@link UriRef}s. String values directly used as the names of children in the repository. In case of
+     * URI, corresponding name value of child node is obtained through the property represented by this URI of
+     * child resource.<br>
+     * <br>
+     * Assume we have a resource having subject <b>s</b> and a pair in the map like
+     * <b>(http://www.w3.org/2004/02/skos/core#narrower, narrowConcept)</b>. In this case, child represented
+     * by skos:narrower will be created as child of the node created thanks to resource indicated by <b>s</b>.
+     * And name of the child node will narrowConcept. <br>
+     * <br>
+     * Assume we have a resource having subject <b>s</b> and a pair in the map like
+     * <b>(http://www.w3.org/2004/02/skos/core#narrower, http://www.w3.org/2000/01/rdf-schema#label)</b>. In
+     * this case, child represented by skos:narrower will be created as child of the node created thanks to
+     * resource indicated by <b>s</b>. Let the child resource has <b>s2</b> subject. Then child name
+     * represented by <b>o</b> will be the value obtained throught the triple (s2, rdfs:label, o).
+     * 
+     * @return {@link Map} keeping the URIs and name indicators of child nodes to be created in the repository
+     */
+    Map<UriRef,Object> getChildrenResources();
+}

Added: incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFMapper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFMapper.java?rev=1153964&view=auto
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFMapper.java (added)
+++ incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/mapping/RDFMapper.java Thu Aug  4 18:38:16 2011
@@ -0,0 +1,26 @@
+package org.apache.stanbol.cmsadapter.servicesapi.mapping;
+
+import org.apache.clerezza.rdf.core.MGraph;
+
+/**
+ * Goal of this interface is to provide a uniform mechanism to store RDF data to JCR or CMIS repositories
+ * based on cms vocabulary annotations on top of the raw RDF.
+ * 
+ * @author suat
+ * 
+ */
+public interface RDFMapper {
+
+    /**
+     * This method stores the data passed within an {@link MGraph} to repository according
+     * "CMS vocabulary annotations".
+     * 
+     * @param session
+     *            This is a session object which is used to interact with JCR or CMIS repositories
+     * @param annotatedGraph
+     *            This {@link MGraph} object is an enhanced version of raw RDF data with "CMS vocabulary"
+     *            annotations according to {@link RDFBridge}s.
+     */
+    void storeRDFinRepository(Object session, MGraph annotatedGraph);
+
+}

Modified: incubator/stanbol/trunk/cmsadapter/web/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/web/pom.xml?rev=1153964&r1=1153963&r2=1153964&view=diff
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/web/pom.xml (original)
+++ incubator/stanbol/trunk/cmsadapter/web/pom.xml Thu Aug  4 18:38:16 2011
@@ -1,20 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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. -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
@@ -78,6 +72,10 @@
 		</dependency>
 		<dependency>
 			<groupId>com.sun.jersey</groupId>
+			<artifactId>jersey-core</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.jersey</groupId>
 			<artifactId>jersey-server</artifactId>
 		</dependency>
 		<dependency>
@@ -97,13 +95,13 @@
 			<artifactId>org.osgi.compendium</artifactId>
 		</dependency>
 		<dependency>
-			<groupId>org.apache.felix</groupId>
-			<artifactId>org.osgi.core</artifactId>
-		</dependency>
-		<dependency>
 			<groupId>org.freemarker</groupId>
 			<artifactId>freemarker</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>rdf.core</artifactId>
+		</dependency>
 	</dependencies>
 </project>
 

Modified: incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/CMSAdapterWebFragment.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/CMSAdapterWebFragment.java?rev=1153964&r1=1153963&r2=1153964&view=diff
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/CMSAdapterWebFragment.java (original)
+++ incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/CMSAdapterWebFragment.java Thu Aug  4 18:38:16 2011
@@ -27,6 +27,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.stanbol.cmsadapter.web.resources.BridgeDefinitionsResource;
 import org.apache.stanbol.cmsadapter.web.resources.NotifyResource;
 import org.apache.stanbol.cmsadapter.web.resources.ObjectTypesResource;
+import org.apache.stanbol.cmsadapter.web.resources.RDFMapperResource;
 import org.apache.stanbol.cmsadapter.web.resources.RootResource;
 import org.apache.stanbol.commons.web.base.LinkResource;
 import org.apache.stanbol.commons.web.base.NavigationLink;
@@ -75,6 +76,7 @@ public class CMSAdapterWebFragment imple
         classes.add(NotifyResource.class);
         classes.add(ObjectTypesResource.class);
         classes.add(RootResource.class);
+        classes.add(RDFMapperResource.class);
         return classes;
     }
 

Modified: incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/BridgeDefinitionsResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/BridgeDefinitionsResource.java?rev=1153964&r1=1153963&r2=1153964&view=diff
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/BridgeDefinitionsResource.java (original)
+++ incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/BridgeDefinitionsResource.java Thu Aug  4 18:38:16 2011
@@ -16,14 +16,12 @@
  */
 package org.apache.stanbol.cmsadapter.web.resources;
 
-import java.io.UnsupportedEncodingException;
 import java.util.Hashtable;
 
 import javax.servlet.ServletContext;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.FormParam;
 import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -32,17 +30,12 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 
 import org.apache.stanbol.cmsadapter.core.mapping.MappingConfigurationImpl;
-import org.apache.stanbol.cmsadapter.servicesapi.helper.OntologyResourceHelper;
 import org.apache.stanbol.cmsadapter.servicesapi.mapping.MappingConfiguration;
 import org.apache.stanbol.cmsadapter.servicesapi.mapping.MappingEngine;
 import org.apache.stanbol.cmsadapter.servicesapi.model.mapping.BridgeDefinitions;
 import org.apache.stanbol.cmsadapter.servicesapi.model.web.ConnectionInfo;
 import org.apache.stanbol.cmsadapter.servicesapi.repository.RepositoryAccessException;
-import org.apache.stanbol.cmsadapter.web.utils.RestURIHelper;
-import org.apache.stanbol.commons.web.base.ContextHelper;
 import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
-import org.apache.stanbol.ontologymanager.store.rest.client.RestClient;
-import org.apache.stanbol.ontologymanager.store.rest.client.RestClientException;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -51,21 +44,16 @@ import org.osgi.service.component.Compon
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.hp.hpl.jena.ontology.OntModel;
-
 @Path("/cmsadapter/bridgeDefinitions")
 public class BridgeDefinitionsResource extends BaseStanbolResource {
     private static final Logger logger = LoggerFactory.getLogger(BridgeDefinitionsResource.class);
 
     private static final String MAPPING_ENGINE_COMPONENT_FACTORY_FILTER = "(component.factory=org.apache.stanbol.cmsadapter.servicesapi.mapping.MappingEngineFactory)";
 
-    private RestClient storeClient;
-
     private MappingEngine engine;
 
     @SuppressWarnings("rawtypes")
     public BridgeDefinitionsResource(@Context ServletContext context) {
-        this.storeClient = ContextHelper.getServiceFromContext(RestClient.class, context);
         try {
             BundleContext bundleContext = (BundleContext) context.getAttribute(BundleContext.class.getName());
             ServiceReference serviceReference = bundleContext.getServiceReferences(null,
@@ -119,41 +107,4 @@ public class BridgeDefinitionsResource e
 
         return Response.status(Status.INTERNAL_SERVER_ERROR).build();
     }
-
-    /**
-     * Simply executes new bridge definitions and as a result new generated ontology overwrites the existing
-     * one.
-     * 
-     * @param ontologyURI
-     *            URI of the ontology for which the bridge definitions are defined
-     * @param bridgeDefinitions
-     *            New bridge definitions
-     * @return
-     */
-    @PUT
-    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
-    public Response updateBridgeDefinitions(@FormParam("ontologyURI") String ontologyURI,
-                                            @FormParam("bridgeDefinitions") BridgeDefinitions bridgeDefinitions) {
-        try {
-            OntModel model = OntologyResourceHelper.getOntModel(storeClient, ontologyURI,
-                RestURIHelper.getOntologyHref(ontologyURI));
-
-            ConnectionInfo connectionInfo = OntologyResourceHelper.getConnectionInfo(model);
-            MappingConfiguration conf = new MappingConfigurationImpl();
-            conf.setBridgeDefinitions(bridgeDefinitions);
-            conf.setConnectionInfo(connectionInfo);
-            conf.setOntologyURI(ontologyURI);
-            engine.mapCR(conf);
-            return Response.status(Status.OK).build();
-
-        } catch (UnsupportedEncodingException e) {
-            logger.warn("Ontology content could not be transformed to bytes", e);
-        } catch (RestClientException e) {
-            logger.warn("Error occured while interacting with store", e);
-        } catch (RepositoryAccessException e) {
-            logger.warn("Cannot access to repository", e);
-        }
-
-        return Response.status(Status.INTERNAL_SERVER_ERROR).build();
-    }
 }
\ No newline at end of file

Added: incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java?rev=1153964&view=auto
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java (added)
+++ incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java Thu Aug  4 18:38:16 2011
@@ -0,0 +1,102 @@
+package org.apache.stanbol.cmsadapter.web.resources;
+
+import java.io.ByteArrayInputStream;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.serializedform.Parser;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.apache.stanbol.cmsadapter.core.mapping.RDFBridgeManager;
+import org.apache.stanbol.cmsadapter.servicesapi.mapping.RDFBridge;
+import org.apache.stanbol.cmsadapter.servicesapi.model.web.ConnectionInfo;
+import org.apache.stanbol.cmsadapter.servicesapi.repository.RepositoryAccessException;
+import org.apache.stanbol.commons.web.base.ContextHelper;
+import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This resource is currently used to pass RDF data to CMS Adapter so that RDF data will be annotated with
+ * "CMS vocabulary" annotations according to {@link RDFBridge}s. Afterwards, this annotated RDF is transformed
+ * into nodes/object in the repository.
+ */
+
+@Path("/cmsadapter/rdfmap")
+public class RDFMapperResource extends BaseStanbolResource {
+    private static final Logger logger = LoggerFactory.getLogger(RDFMapperResource.class);
+    private Parser clerezzaParser;
+    private RDFBridgeManager bridgeManager;
+
+    public RDFMapperResource(@Context ServletContext context) {
+        clerezzaParser = ContextHelper.getServiceFromContext(Parser.class, context);
+        bridgeManager = ContextHelper.getServiceFromContext(RDFBridgeManager.class, context);
+    }
+
+    /**
+     * This service takes credentials as {@link ConnectionInfo} object to access repository and an RDF data
+     * first to be annotated and then stored in repository based on the annotations.
+     * 
+     * @param connectionInfo
+     *            is the object that holds all necessary information to connect repository. Example connection
+     *            info XML:<br>
+     * <br>
+     * 
+     *            <pre>
+     * &lt;?xml version="1.0" encoding="UTF-8"?>
+     * &lt;connectionInfo
+     *     xmlns="web.model.servicesapi.cmsadapter.stanbol.apache.org">
+     *     &lt;repositoryURL>rmi://localhost:1099/crx&lt;/repositoryURL>
+     *     &lt;workspaceName>demo&lt;/workspaceName>
+     *     &lt;username>admin&lt;/username>
+     *     &lt;password>admin&lt;/password>
+     *     &lt;connectionType>JCR&lt;/connectionType>
+     * &lt;/connectionInfo>
+     * </pre>
+     * 
+     * <br>
+     * @param serializedGraph
+     *            is the serialized RDF graph that is desired to transformed into repository objects
+     * 
+     *            TODO: It would be wise to get as MGraph in request data. Before that connection info should
+     *            be get in a different way.
+     */
+    @POST
+    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+    public Response mapRDF(@FormParam("connectionInfo") ConnectionInfo connectionInfo,
+                           @FormParam("serializedGraph") String serializedGraph) {
+
+        if (connectionInfo == null) {
+            logger.warn("There is no valid connection info specified");
+            return Response.status(Status.BAD_REQUEST).entity("There is no valid connection info specified")
+                    .build();
+        }
+        if (serializedGraph == null) {
+            logger.warn("There is no valid RDF data specified");
+            return Response.status(Status.BAD_REQUEST).entity("There is no valid RDF data specified").build();
+        }
+
+        Graph g = clerezzaParser.parse(new ByteArrayInputStream(serializedGraph.getBytes()),
+            SupportedFormat.RDF_XML);
+        MGraph annotatedGraph = new SimpleMGraph(g.iterator());
+        try {
+            bridgeManager.storeRDFToRepository(connectionInfo, annotatedGraph);
+        } catch (RepositoryAccessException e) {
+            logger.warn("Failed to obtain a session from repository", e);
+            return Response.status(Status.INTERNAL_SERVER_ERROR)
+                    .entity("Failed to obtain a session from repository").build();
+        }
+        return Response.ok().build();
+    }
+
+}