Author: suat
Date: Thu Oct 27 15:35:18 2011
New Revision: 1189810
URL: http://svn.apache.org/viewvc?rev=1189810&view=rev
Log:
STANBOL-364:
Missing files to commit
Added implementation for the CMS Adapter feature that provides submission of
content repository objects to Contenthub. The main interface offering the
functionality is ContenthubFeeder. There are two implementations of it for JCR
and CMIS content repositories.
These implementations basically create SolrContentItems from JCR nodes or CMIS
documents and submit them to the Contenthub. Properties of these content
repository objects are also indexed in Solr as external metadata together with
the actual content. Indexed properties are used to provide faceted search over
the submitted documents.
It is also possible to delete content items from Contenthub based on the
content repository IDs or paths of nodes/documents.
Added:
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/ContenthubFeederManager.java
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/ContenthubFeedResource.java
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/utils/RestUtil.java
Modified:
incubator/stanbol/trunk/cmsadapter/core/src/main/java/ (props changed)
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/helper/TcManagerClient.java
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/BaseRDFMapper.java
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeHelper.java
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeManager.java
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/RDFMapperResource.java
Propchange: incubator/stanbol/trunk/cmsadapter/core/src/main/java/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Oct 27 15:35:18 2011
@@ -0,0 +1 @@
+test
Modified:
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/helper/TcManagerClient.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/helper/TcManagerClient.java?rev=1189810&r1=1189809&r2=1189810&view=diff
==============================================================================
---
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/helper/TcManagerClient.java
(original)
+++
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/helper/TcManagerClient.java
Thu Oct 27 15:35:18 2011
@@ -1,3 +1,19 @@
+/*
+ * 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.helper;
import java.io.ByteArrayInputStream;
@@ -70,7 +86,7 @@ public class TcManagerClient {
* content of the ontology passed in a {@link Model} object
* @param ontologyURI
* URI of the ontology
- */
+ */
public void saveOntology(Model ontology, String ontologyURI) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
RDFWriter rdfWriter = ontology.getWriter("RDF/XML");
Modified:
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/BaseRDFMapper.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/BaseRDFMapper.java?rev=1189810&r1=1189809&r2=1189810&view=diff
==============================================================================
---
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/BaseRDFMapper.java
(original)
+++
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/BaseRDFMapper.java
Thu Oct 27 15:35:18 2011
@@ -1,3 +1,19 @@
+/*
+ * 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 org.apache.clerezza.rdf.core.MGraph;
Added:
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/ContenthubFeederManager.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/ContenthubFeederManager.java?rev=1189810&view=auto
==============================================================================
---
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/ContenthubFeederManager.java
(added)
+++
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/ContenthubFeederManager.java
Thu Oct 27 15:35:18 2011
@@ -0,0 +1,173 @@
+/*
+ * 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.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+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.ContenthubFeeder;
+import
org.apache.stanbol.cmsadapter.servicesapi.mapping.ContenthubFeederException;
+import org.apache.stanbol.cmsadapter.servicesapi.repository.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.osgi.service.component.ComponentFactory;
+import org.osgi.service.component.ComponentInstance;
+
+/**
+ * This class manages the {@link ContenthubFeeder} instances loaded in the
OSGI environment.
+ *
+ * @author suat
+ *
+ */
+@Component(immediate = true)
+@Service(value = ContenthubFeederManager.class)
+public class ContenthubFeederManager {
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY, target =
"(component.factory="
+ +
ContenthubFeeder.JCR_CONTENTHUB_FEEDER_FACTORY
+ +
")")
+ private ComponentFactory defaultJCRContentHubFeederFactory;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY, target =
"(component.factory="
+ +
ContenthubFeeder.CMIS_CONTENTUB_FEEDER_FACTORY
+ +
")")
+ private ComponentFactory defaultCMISContentHubFeederFactory;
+
+ /*
+ * Holds additional ContenthubFeeder implementations if there is any.
+ */
+ @Reference(cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
referenceInterface = ContenthubFeeder.class, policy = ReferencePolicy.DYNAMIC,
bind = "bindContenthubFeeder", unbind = "unbindContenthubFeeder", strategy =
ReferenceStrategy.EVENT)
+ List<ContenthubFeeder> boundedFeeders = new
CopyOnWriteArrayList<ContenthubFeeder>();
+
+ /*
+ * Holds instances of default implementations for JCR and CMIS
ContenthubFeeders for different connection
+ * information. Destruction of invalid instances (instances having invalid
sessions) may be implemented.
+ */
+ private Map<ConnectionInfo,ComponentInstance> defaultFeeders = Collections
+ .synchronizedMap(new HashMap<ConnectionInfo,ComponentInstance>());
+
+ @Reference
+ RepositoryAccessManager accessManager;
+
+ /**
+ * Looks for a suitable {@link ContenthubFeeder} instance based on the
provided
+ * <code>connectionInfo</code>.
+ *
+ * @param connectionInfo
+ * @return {@link ContenthubFeeder} instance.
+ * @throws RepositoryAccessException
+ * @throws ContenthubFeederException
+ * @see #getContenthubFeeder(ConnectionInfo, List)
+ */
+ public ContenthubFeeder getContenthubFeeder(ConnectionInfo connectionInfo)
throws RepositoryAccessException,
+
ContenthubFeederException {
+ return getContenthubFeeder(connectionInfo, null);
+ }
+
+ /**
+ * Looks for a suitable {@link ContenthubFeeder} instance based on the
provided
+ * <code>connectionInfo</code>. If there is an instance of a custom
implementation provided in the
+ * environment suitable for the connection type, it is retrieved first. If
there is no custom
+ * implementations in the OSGI environment, a new instance created based
on the given
+ * <code>connectionInfo</code> or an already existing one is returned.
+ *
+ * @param connectionInfo
+ * @return {@link ContenthubFeeder} instance.
+ * @throws RepositoryAccessException
+ * @throws ContenthubFeederException
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public ContenthubFeeder getContenthubFeeder(ConnectionInfo connectionInfo,
List<String> contentProperties) throws RepositoryAccessException,
+
ContenthubFeederException {
+
+ // check additional implementations according to their connection types
+ String connectionType = connectionInfo.getConnectionType();
+ for (ContenthubFeeder feeder : boundedFeeders) {
+ if (feeder.canFeed(connectionType)) {
+ return feeder;
+ }
+ }
+
+ // check default feeder instances
+ // TODO: check whether the session object is still valid
+ ComponentInstance componentInstance =
defaultFeeders.get(connectionInfo);
+ if (componentInstance != null) {
+ Object value = componentInstance.getInstance();
+ if (value != null) {
+ return (ContenthubFeeder) value;
+ } else {
+ /*
+ * Default feeder instance for this connection info is not
available, so remove it from the
+ * map
+ */
+ defaultFeeders.remove(connectionInfo);
+ }
+ }
+
+ org.apache.stanbol.cmsadapter.servicesapi.model.web.ConnectionInfo
cInfo = mapConnectionInfo(connectionInfo);
+ RepositoryAccess repositoryAccess =
accessManager.getRepositoryAccessor(cInfo);
+ Object session = repositoryAccess.getSession(cInfo);
+
+ final Dictionary props = new Hashtable();
+ props.put(ContenthubFeeder.PROP_SESSION, session);
+ props.put(ContenthubFeeder.PROP_CONTENT_PROPERTIES, contentProperties);
+
+ if (connectionType.equals(ConnectionInfo.JCR_CONNECTION_STRING)) {
+ componentInstance =
defaultJCRContentHubFeederFactory.newInstance(props);
+ } else if
(connectionType.equals(ConnectionInfo.CMIS_CONNECTION_STRING)) {
+ componentInstance =
defaultCMISContentHubFeederFactory.newInstance(props);
+ } else {
+ throw new ContenthubFeederException(String.format("Unexpected
default connection type: %s",
+ connectionType));
+ }
+
+ ContenthubFeeder feeder = (ContenthubFeeder)
componentInstance.getInstance();
+ defaultFeeders.put(connectionInfo, componentInstance);
+ return feeder;
+ }
+
+ private org.apache.stanbol.cmsadapter.servicesapi.model.web.ConnectionInfo
mapConnectionInfo(ConnectionInfo connectionInfo) {
+ org.apache.stanbol.cmsadapter.servicesapi.model.web.ConnectionInfo
cInfo = new
org.apache.stanbol.cmsadapter.servicesapi.model.web.ConnectionInfo();
+ cInfo.setConnectionType(connectionInfo.getConnectionType());
+ cInfo.setPassword(connectionInfo.getPassword());
+ cInfo.setUsername(connectionInfo.getUsername());
+ cInfo.setRepositoryURL(connectionInfo.getRepositoryURL());
+ cInfo.setWorkspaceName(connectionInfo.getWorkspaceIdentifier());
+ return cInfo;
+ }
+
+ protected void bindContenthubFeeder(ContenthubFeeder contenthubFeeder) {
+ boundedFeeders.add(contenthubFeeder);
+
+ }
+
+ protected void unbindContenthubFeeder(ContenthubFeeder contenthubFeeder) {
+ boundedFeeders.remove(contenthubFeeder);
+ }
+}
Modified:
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeHelper.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeHelper.java?rev=1189810&r1=1189809&r2=1189810&view=diff
==============================================================================
---
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeHelper.java
(original)
+++
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeHelper.java
Thu Oct 27 15:35:18 2011
@@ -1,3 +1,19 @@
+/*
+ * 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.ArrayList;
@@ -32,17 +48,6 @@ public class RDFBridgeHelper {
public static final UriRef RDF_TYPE = new UriRef(NamespaceEnum.rdf +
"type");
- public static final UriRef base64Uri = dataTypeURI("base64Binary");
- public static final UriRef dateTimeUri = dataTypeURI("dateTime");
- public static final UriRef booleanUri = dataTypeURI("boolean");
- public static final UriRef stringUri = dataTypeURI("string");
- public static final UriRef xsdInteger = dataTypeURI("integer");
- public static final UriRef xsdInt = dataTypeURI("int");
- public static final UriRef xsdShort = dataTypeURI("short");
- public static final UriRef xsdLong = dataTypeURI("long");
- public static final UriRef xsdDouble = dataTypeURI("double");
- public static final UriRef xsdAnyURI = dataTypeURI("anyURI");
-
private static Pattern pattern = Pattern.compile("\"(.*?)\"");
/**
@@ -341,10 +346,6 @@ public class RDFBridgeHelper {
return targetRootPath + objectName;
}
- private static UriRef dataTypeURI(String type) {
- return new UriRef(NamespaceEnum.xsd + type);
- }
-
/**
* Adds the specified <code>localName</code> at the end of the
<code>baseURI</code>
*
Modified:
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=1189810&r1=1189809&r2=1189810&view=diff
==============================================================================
---
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeManager.java
(original)
+++
incubator/stanbol/trunk/cmsadapter/core/src/main/java/org/apache/stanbol/cmsadapter/core/mapping/RDFBridgeManager.java
Thu Oct 27 15:35:18 2011
@@ -92,13 +92,20 @@ public class RDFBridgeManager {
Object session = repositoryAccess.getSession(connectionInfo);
// Annotate raw RDF with CMS vocabulary annotations according to
bridges
+ log.info("Graph annotation starting...");
MGraph annotatedGraph = new SimpleMGraph();
for (RDFBridge bridge : rdfBridges) {
+ long startAnnotation = System.currentTimeMillis();
annotatedGraph.addAll(bridge.annotateGraph(rawRDFData));
+ log.info("Graph annotated in: " + (System.currentTimeMillis() -
startAnnotation) + "ms");
}
+ log.info("Graph annotation finished");
// Store annotated RDF in repository
+ log.info("Annotated graph mapping started...");
+ long startMap = System.currentTimeMillis();
mapper.storeRDFinRepository(session, annotatedGraph);
+ log.info("Annotated graph mapped in: " + (System.currentTimeMillis() -
startMap) + "ms");
}
/**
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=1189810&r1=1189809&r2=1189810&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 Oct 27 15:35:18 2011
@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.stanbol.cmsadapter.web.resources.BridgeDefinitionsResource;
+import org.apache.stanbol.cmsadapter.web.resources.ContenthubFeedResource;
import org.apache.stanbol.cmsadapter.web.resources.NotifyResource;
import org.apache.stanbol.cmsadapter.web.resources.ObjectTypesResource;
import org.apache.stanbol.cmsadapter.web.resources.RDFMapperResource;
@@ -77,6 +78,7 @@ public class CMSAdapterWebFragment imple
classes.add(ObjectTypesResource.class);
classes.add(RootResource.class);
classes.add(RDFMapperResource.class);
+ classes.add(ContenthubFeedResource.class);
return classes;
}
Added:
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/ContenthubFeedResource.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/ContenthubFeedResource.java?rev=1189810&view=auto
==============================================================================
---
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/ContenthubFeedResource.java
(added)
+++
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/ContenthubFeedResource.java
Thu Oct 27 15:35:18 2011
@@ -0,0 +1,270 @@
+/*
+ * 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.web.resources;
+
+import static javax.ws.rs.core.MediaType.TEXT_HTML;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+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.stanbol.cmsadapter.core.mapping.ContenthubFeederManager;
+import org.apache.stanbol.cmsadapter.servicesapi.mapping.ContenthubFeeder;
+import
org.apache.stanbol.cmsadapter.servicesapi.mapping.ContenthubFeederException;
+import org.apache.stanbol.cmsadapter.servicesapi.repository.ConnectionInfo;
+import
org.apache.stanbol.cmsadapter.servicesapi.repository.RepositoryAccessException;
+import org.apache.stanbol.cmsadapter.web.utils.RestUtil;
+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;
+
+import com.sun.jersey.api.view.Viewable;
+
+/**
+ * This resource provides services to submit content repository objects into
Contenthub component. Submitted
+ * content items are also enhanced by <b>Stanbol Enhancer</b>. This service
also enables deletion of content
+ * items from Contenthub.
+ *
+ * It basically delegates the request suitable {@link ContenthubFeeder}
instance.
+ *
+ * @author suat
+ *
+ */
+@Path("/cmsadapter/contenthubfeed")
+public class ContenthubFeedResource extends BaseStanbolResource {
+ private static final Logger logger =
LoggerFactory.getLogger(ContenthubFeedResource.class);
+
+ ContenthubFeederManager feederManager;
+
+ public ContenthubFeedResource(@Context ServletContext context) {
+ feederManager =
ContextHelper.getServiceFromContext(ContenthubFeederManager.class, context);
+ }
+
+ @GET
+ @Produces(TEXT_HTML)
+ public Response get() {
+ return Response.ok(new Viewable("index", this), TEXT_HTML).build();
+ }
+
+ /**
+ * This service enables submission of content repository objects to
Contenthub. Connection to the content
+ * repository is established by the provided connection information. This
service makes possible to submit
+ * content items through either their IDs or paths in the content
repository. Enhancements of content
+ * items are obtained through <b>Stanbol Enhancer</b> before submitting
them to Contenthub.
+ *
+ * <p>
+ * If <code>id</code> parameter is set, the target object is obtained from
the content repository
+ * according to its ID. If <code>path</code> parameter is set, first the
ID of target object is obtained
+ * from the content repository and then the retrieved ID is used in
submission of content item. When
+ * <code>path</code> parameter is set, it is also possible to process all
content repository objects under
+ * the specified path by setting <code>recursive</code> parameter as
<code>true</code>.
+ *
+ * <p>
+ * For some cases, it is necessary to know the property of the content
repository object that keeps the
+ * actual content e.g while processing a nt:unstructured typed JCR content
repository object. Such custom
+ * properties are specified within the <code>contentProperties</code>
parameter.
+ *
+ *
+ * @param repositoryURL
+ * @param workspaceName
+ * @param username
+ * @param password
+ * @param connectionType
+ * @param id
+ * content repository ID of the content item to be submitted
+ * @param path
+ * content repository path of the content item to be submitted
+ * @param recursive
+ * this parameter is used together with <code>path</code>
parameter. Its default value is
+ * <code>false</code>. If it is set as <code>true</code>. All
content repository objects under
+ * the specified path are processed.
+ * @param contentProperties
+ * this parameter indicates the list of properties that are
possibly holding the actual
+ * content. Possible values are passed as comma separated. Its
default value is <b>content,
+ * skos:definition</b>.
+ *
+ * @return
+ * @throws RepositoryAccessException
+ * @throws ContenthubFeederException
+ */
+ @POST
+ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+ public Response submitObjectsToContenthub(@FormParam("repositoryURL")
String repositoryURL,
+ @FormParam("workspaceName")
String workspaceName,
+ @FormParam("username") String
username,
+ @FormParam("password") String
password,
+ @FormParam("connectionType")
String connectionType,
+ @FormParam("id") String id,
+ @FormParam("path") String path,
+ @FormParam("recursive")
@DefaultValue("false") boolean recursive,
+ @FormParam("contentProperties")
@DefaultValue("skos:definition,content") String contentProperties) throws
RepositoryAccessException,
+
ContenthubFeederException {
+
+ repositoryURL = RestUtil.nullify(repositoryURL);
+ workspaceName = RestUtil.nullify(workspaceName);
+ username = RestUtil.nullify(username);
+ password = RestUtil.nullify(password);
+ connectionType = RestUtil.nullify(connectionType);
+ id = RestUtil.nullify(id);
+ path = RestUtil.nullify(path);
+ contentProperties = RestUtil.nullify(contentProperties);
+
+ if (repositoryURL == null || username == null || password == null ||
connectionType == null) {
+ logger.warn("Repository URL, username, password and connection
type parameters should not be null");
+ return Response
+ .status(Status.BAD_REQUEST)
+ .entity(
+ "Repository URL, username, password and connection
type parameters should not be null")
+ .build();
+ }
+
+ List<String> contentFieldList =
parseContentProperties(contentProperties);
+
+ ContenthubFeeder feeder = feederManager.getContenthubFeeder(
+ formConnectionInfo(repositoryURL, workspaceName, username,
password, connectionType),
+ contentFieldList);
+
+ if (id != null) {
+ feeder.submitContentItemByID(id);
+ } else if (path != null) {
+ if (!recursive) {
+ feeder.submitContentItemByPath(path);
+ } else {
+ feeder.submitContentItemsUnderPath(path);
+ }
+ } else {
+ return Response.status(Status.BAD_REQUEST)
+ .entity("There is no parameter specified to select content
repository objects\n").build();
+ }
+
+ return Response.ok().build();
+ }
+
+ /**
+ * This service enables deletion of content items from Contenthub.
Connection to the content repository is
+ * established by the provided connection information. This service makes
possible to delete content items
+ * through either their IDs or paths in the content repository.
+ *
+ * <p>
+ * If <code>id</code> parameter is set, the content item is directly tried
to be deleted from Contenthub.
+ * If <code>path</code> parameter is set, the ID of the target object is
first obtained from the content
+ * repository according to its path. Then retrieved ID is used to delete
related content item from
+ * Contenthub.
+ *
+ * @param repositoryURL
+ * @param workspaceName
+ * @param username
+ * @param password
+ * @param connectionType
+ * @param id
+ * content repository ID of the content item to be submitted
+ * @param path
+ * content repository path of the content item to be submitted
+ * @param recursive
+ * this parameter is used together with <code>path</code>
parameter. Its default value is
+ * <code>false</code>. If it is set as <code>true</code>. All
content repository objects under
+ * the specified path are processed.
+ * @return
+ * @throws RepositoryAccessException
+ * @throws ContenthubFeederException
+ */
+ @DELETE
+ @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
+ public Response deleteObjectsFromContenthub(@FormParam("repositoryURL")
String repositoryURL,
+ @FormParam("workspaceName")
String workspaceName,
+ @FormParam("username") String
username,
+ @FormParam("password") String
password,
+ @FormParam("connectionType")
String connectionType,
+ @FormParam("id") String id,
+ @FormParam("path") String path,
+ @FormParam("recursive")
@DefaultValue("false") boolean recursive) throws RepositoryAccessException,
+
ContenthubFeederException {
+
+ repositoryURL = RestUtil.nullify(repositoryURL);
+ workspaceName = RestUtil.nullify(workspaceName);
+ username = RestUtil.nullify(username);
+ password = RestUtil.nullify(password);
+ connectionType = RestUtil.nullify(connectionType);
+ id = RestUtil.nullify(id);
+ path = RestUtil.nullify(path);
+
+ if (repositoryURL == null || username == null || password == null ||
connectionType == null) {
+ logger.warn("Repository URL, username, password and connection
type parameters should not be null");
+ return Response
+ .status(Status.BAD_REQUEST)
+ .entity(
+ "Repository URL, username, password and connection
type parameters should not be null")
+ .build();
+ }
+
+ ContenthubFeeder feeder =
feederManager.getContenthubFeeder(formConnectionInfo(repositoryURL,
+ workspaceName, username, password, connectionType));
+
+ if (id != null) {
+ feeder.deleteContentItemByID(id);
+ } else if (path != null) {
+ if (!recursive) {
+ feeder.deleteContentItemByPath(path);
+ } else {
+ feeder.deleteContentItemsUnderPath(path);
+ }
+ } else {
+ return Response.status(Status.BAD_REQUEST)
+ .entity("There is no parameter specified to select content
repository objects\n").build();
+ }
+
+ return Response.ok().build();
+ }
+
+ private ConnectionInfo formConnectionInfo(String repositoryURL,
+ String workspaceName,
+ String username,
+ String password,
+ String connectionType) {
+ ConnectionInfo cInfo = new
org.apache.stanbol.cmsadapter.servicesapi.repository.ConnectionInfo(
+ repositoryURL, workspaceName, username, password,
connectionType);
+ return cInfo;
+ }
+
+ private List<String> parseContentProperties(String contentProperties) {
+ List<String> fieldsList = new ArrayList<String>();
+ if (contentProperties != null) {
+ String[] fields = contentProperties.split(",");
+ for (String field : fields) {
+ String f = field.trim();
+ if (!f.equals("")) {
+ fieldsList.add(f);
+ }
+ }
+ }
+ return fieldsList;
+ }
+}
Modified:
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=1189810&r1=1189809&r2=1189810&view=diff
==============================================================================
---
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java
(original)
+++
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/resources/RDFMapperResource.java
Thu Oct 27 15:35:18 2011
@@ -118,6 +118,7 @@ public class RDFMapperResource extends B
ConnectionInfo connectionInfo = formConnectionInfo(repositoryURL,
workspaceName, username, password,
connectionType);
+ long start = System.currentTimeMillis();
Graph g;
if (serializedGraph != null && !serializedGraph.trim().isEmpty()) {
g = clerezzaParser.parse(new
ByteArrayInputStream(serializedGraph.getBytes()),
@@ -131,7 +132,9 @@ public class RDFMapperResource extends B
.build();
}
- return mapRDF(g, connectionInfo);
+ Response r = mapRDF(g, connectionInfo);
+ logger.info("RDF mapping finished in: {} seconds",
((System.currentTimeMillis() - start) / 1000));
+ return r;
}
/**
@@ -182,7 +185,7 @@ public class RDFMapperResource extends B
}
ConnectionInfo connectionInfo = formConnectionInfo(repositoryURL,
workspaceName, username, password,
connectionType);
-
+ long start = System.currentTimeMillis();
Graph g;
if (rdfFile != null) {
InputStream is = new
ByteArrayInputStream(FileUtils.readFileToByteArray(rdfFile));
@@ -191,7 +194,9 @@ public class RDFMapperResource extends B
logger.warn("There is RDF file specified");
return Response.status(Status.BAD_REQUEST).entity("There is no RDF
file specified").build();
}
+
Response r = mapRDF(g, connectionInfo);
+ logger.info("RDF mapping finished in: {} miliseconds",
((System.currentTimeMillis() - start) / 1000));
if (r.getStatus() == Response.Status.OK.getStatusCode()) {
return get();
} else {
@@ -248,7 +253,9 @@ public class RDFMapperResource extends B
connectionType);
try {
+ long start = System.currentTimeMillis();
MGraph generatedGraph =
bridgeManager.generateRDFFromRepository(connectionInfo);
+ logger.info("CMS mapping finished in: {} seconds",
((System.currentTimeMillis() - start) / 1000));
return Response.ok(generatedGraph,
SupportedFormat.RDF_XML).build();
} catch (RepositoryAccessException e) {
logger.warn("Failed to obtain a session from repository", e);
Added:
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/utils/RestUtil.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/utils/RestUtil.java?rev=1189810&view=auto
==============================================================================
---
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/utils/RestUtil.java
(added)
+++
incubator/stanbol/trunk/cmsadapter/web/src/main/java/org/apache/stanbol/cmsadapter/web/utils/RestUtil.java
Thu Oct 27 15:35:18 2011
@@ -0,0 +1,37 @@
+/*
+ * 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.web.utils;
+
+/**
+ * Utility class for REST services
+ */
+public class RestUtil {
+ /**
+ * @param parameter
+ * parameter to be checked
+ * @return <code>null</code> if parameter has an empty content, otherwise
trimmed <code>parameter</code>
+ */
+ public static String nullify(String parameter) {
+ if (parameter != null) {
+ parameter = parameter.trim();
+ if (parameter.isEmpty()) {
+ parameter = null;
+ }
+ }
+ return parameter;
+ }
+}