You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by su...@apache.org on 2012/08/09 15:08:56 UTC
svn commit: r1371191 [1/2] - in
/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub:
bundlelist/src/main/bundles/ defaults/src/main/resources/config/ index/
index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/
index/src/m...
Author: suat
Date: Thu Aug 9 13:08:55 2012
New Revision: 1371191
URL: http://svn.apache.org/viewvc?rev=1371191&view=rev
Log:
STANBOL-498, STANBOL-499:
-While submitting content to the Contenthub, additional constraints are added into a ContentPart of the ContentItem to be created.
-Now, it is possible to specify the name of the IndexingSource of an LDPathSemanticIndex
-Usage of FileStore in tests are adjusted. Instead of the commmon FileStore implementation, dummy Store instances are created.
-Some bugs are fixed when obtaining changes from the RevisionManager
-The LDPath program is now executed on the ContentItem also. This enables to execute the LDPath program over the TripleCollection based content parts of a ContentItem
Modified:
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/bundlelist/src/main/bundles/list.xml
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/defaults/src/main/resources/config/org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex-default.config
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/pom.xml
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndexManager.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/OSGI-INF/metatype/metatype.properties
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/StoreDBManager.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/RevisionManagerTest.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/StoreDBManagerTest.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/ (props changed)
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/LDPathSemanticIndexResource.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/imports/doc/indexLdpathRestApi.ftl
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/LDPathSemanticIndexResource/index.ftl
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/bundlelist/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/bundlelist/src/main/bundles/list.xml?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/bundlelist/src/main/bundles/list.xml (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/bundlelist/src/main/bundles/list.xml Thu Aug 9 13:08:55 2012
@@ -11,20 +11,22 @@
language governing permissions and limitations under the License. -->
<bundles>
- <startLevel level="23">
+ <startLevel level="22">
<bundle>
<groupId>org.apache.stanbol</groupId>
- <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
+ <artifactId>org.apache.stanbol.contenthub.revisionmanager</artifactId>
<version>0.10.0-incubating-SNAPSHOT</version>
</bundle>
+ </startLevel>
+ <startLevel level="23">
<bundle>
<groupId>org.apache.stanbol</groupId>
- <artifactId>org.apache.stanbol.contenthub.store.file</artifactId>
+ <artifactId>org.apache.stanbol.contenthub.servicesapi</artifactId>
<version>0.10.0-incubating-SNAPSHOT</version>
</bundle>
<bundle>
<groupId>org.apache.stanbol</groupId>
- <artifactId>org.apache.stanbol.contenthub.revisionmanager</artifactId>
+ <artifactId>org.apache.stanbol.contenthub.store.file</artifactId>
<version>0.10.0-incubating-SNAPSHOT</version>
</bundle>
<bundle>
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/defaults/src/main/resources/config/org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex-default.config
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/defaults/src/main/resources/config/org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex-default.config?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/defaults/src/main/resources/config/org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex-default.config (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/defaults/src/main/resources/config/org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex-default.config Thu Aug 9 13:08:55 2012
@@ -23,6 +23,7 @@ entity_given_names\ \=\ foaf:givenName\
entity_captions\ \=\ dbp-prop:caption\ ::\ xsd:string;"
org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.indexContent=B"true"
org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.batchSize=I"10"
-org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.storeCheckPeriod=I"5"
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.indexingSourceName="contenthubFileStore"
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.indexingSourceCheckPeriod=I"5"
org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.solrCheckTime=I"5"
service.ranking=I"0"
\ No newline at end of file
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/pom.xml?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/pom.xml (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/pom.xml Thu Aug 9 13:08:55 2012
@@ -82,6 +82,11 @@
<version>0.11.0-incubating-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.enhancer.ldpath</artifactId>
+ <version>0.10.0-incubating-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>at.newmedialab.ldpath</groupId>
<artifactId>ldpath-api</artifactId>
</dependency>
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java Thu Aug 9 13:08:55 2012
@@ -17,6 +17,9 @@
package org.apache.stanbol.contenthub.index.ldpath;
import java.io.IOException;
+import java.io.StringReader;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
@@ -41,9 +44,6 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
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.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
@@ -68,6 +68,8 @@ import org.apache.stanbol.contenthub.ser
import org.apache.stanbol.contenthub.servicesapi.index.search.solr.SolrSearch;
import org.apache.stanbol.contenthub.servicesapi.store.vocabulary.SolrVocabulary;
import org.apache.stanbol.contenthub.servicesapi.store.vocabulary.SolrVocabulary.SolrFieldName;
+import org.apache.stanbol.enhancer.ldpath.EnhancerLDPath;
+import org.apache.stanbol.enhancer.ldpath.backend.ContentItemBackend;
import org.apache.stanbol.enhancer.servicesapi.Blob;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
import org.apache.stanbol.enhancer.servicesapi.NoSuchPartException;
@@ -92,6 +94,7 @@ import org.osgi.service.component.Compon
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.newmedialab.ldpath.LDPath;
import at.newmedialab.ldpath.exception.LDPathParseException;
import at.newmedialab.ldpath.model.fields.FieldMapping;
import at.newmedialab.ldpath.model.programs.Program;
@@ -108,9 +111,14 @@ import at.newmedialab.ldpath.model.progr
* <li><b>Description:</b> Description of the index</li>
* <li><b>LDPathProgram: </b> LDPath program that will be used as a source to create the semantic index. Index
* fields and Solr specific configurations regarding those index fields are given in this parameter.</li>
+ * <li><b>Index Content: </b> If this configuration is true plain text content of the {@link ContentItem} is
+ * also indexed to be used in the full text search.</li>
* <li><b>Batch Size:</b> Maximum number of changes to be processed in a single step while iteratively
- * checking the changes in the {@link Store}</li>
- * <li><b>Store Check Period:</b> Time to check changes in the {@link Store} in second units</li>
+ * checking the changes in the {@link IndexingSource}</li>
+ * <li><b>Indexing Source Name: </b> Name of the {@link IndexingSource} instance to be checked for updates.
+ * This {@link IndexingSource} should be an IndexingSource<ContentItem> implementation.
+ * <li><b>Indexing Source Check Period:</b> Time to check changes in the {@link IndexingSource} in second
+ * units</li>
* <li><b>Solr Server Check Time:</b> Maximum time in seconds to wait for the availability of the Solr core
* associated with this index</li>
* <li><b>Service Ranking:</b> To be able adjust priorities of {@link SemanticIndex}es with same name or same
@@ -124,12 +132,14 @@ import at.newmedialab.ldpath.model.progr
*/
@Component(configurationFactory = true, policy = ConfigurationPolicy.REQUIRE, metatype = true, immediate = true)
@Service
-@Properties(value = {@Property(name = SemanticIndex.PROP_NAME),
+@Properties(value = {
+ @Property(name = SemanticIndex.PROP_NAME),
@Property(name = SemanticIndex.PROP_DESCRIPTION),
@Property(name = LDPathSemanticIndex.PROP_LD_PATH_PROGRAM),
@Property(name = LDPathSemanticIndex.PROP_INDEX_CONTENT, boolValue = true),
@Property(name = LDPathSemanticIndex.PROP_BATCH_SIZE, intValue = 10),
- @Property(name = LDPathSemanticIndex.PROP_STORE_CHECK_PERIOD, intValue = 10),
+ @Property(name = LDPathSemanticIndex.PROP_INDEXING_SOURCE_NAME, value = "contenthubFileStore"),
+ @Property(name = LDPathSemanticIndex.PROP_INDEXING_SOURCE_CHECK_PERIOD, intValue = 10),
@Property(name = LDPathSemanticIndex.PROP_SOLR_CHECK_TIME, intValue = 5),
@Property(name = Constants.SERVICE_RANKING, intValue = 0)})
public class LDPathSemanticIndex implements SemanticIndex<ContentItem> {
@@ -137,7 +147,8 @@ public class LDPathSemanticIndex impleme
public static final String PROP_LD_PATH_PROGRAM = "org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.ldPathProgram";
public static final String PROP_INDEX_CONTENT = "org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.indexContent";
public static final String PROP_BATCH_SIZE = "org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.batchSize";
- public static final String PROP_STORE_CHECK_PERIOD = "org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.storeCheckPeriod";
+ public static final String PROP_INDEXING_SOURCE_NAME = "org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.indexingSourceName";
+ public static final String PROP_INDEXING_SOURCE_CHECK_PERIOD = "org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.indexingSourceCheckPeriod";
public static final String PROP_SOLR_CHECK_TIME = "org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.solrCheckTime";
private final Logger logger = LoggerFactory.getLogger(LDPathSemanticIndex.class);
@@ -148,8 +159,7 @@ public class LDPathSemanticIndex impleme
@Reference(target = "(org.apache.solr.core.CoreContainer.name=contenthub)")
private ManagedSolrServer managedSolrServer;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY, referenceInterface = IndexingSource.class, policy = ReferencePolicy.DYNAMIC, bind = "bindIndexingSource", unbind = "unbindIndexingSource", strategy = ReferenceStrategy.EVENT)
- private IndexingSource<ContentItem> store;
+ private IndexingSource<ContentItem> indexingSource;
@Reference
private SiteManager siteManager;
@@ -157,11 +167,12 @@ public class LDPathSemanticIndex impleme
private String name;
private String description;
private String ldPathProgram;
- private Program<Object> program;
+ private Program<Object> objectProgram;
private boolean indexContent;
private int batchSize;
private int storeCheckPeriod;
private int solrCheckTime;
+ private long epoch;
private long revision = Long.MIN_VALUE;
private volatile IndexState state = IndexState.UNINIT;
private String pid;
@@ -177,19 +188,24 @@ public class LDPathSemanticIndex impleme
@Activate
protected void activate(ComponentContext context) throws IndexException,
IndexManagementException,
- ConfigurationException {
+ ConfigurationException,
+ StoreException {
@SuppressWarnings("rawtypes")
Dictionary properties = context.getProperties();
this.name = (String) OsgiUtils.checkProperty(properties, PROP_NAME);
this.ldPathProgram = (String) OsgiUtils.checkProperty(properties, PROP_LD_PATH_PROGRAM);
- this.program = getProgram();
this.indexContent = (Boolean) OsgiUtils.checkProperty(properties, PROP_INDEX_CONTENT);
this.description = (String) OsgiUtils.checkProperty(properties, PROP_DESCRIPTION);
this.batchSize = (Integer) OsgiUtils.checkProperty(properties, PROP_BATCH_SIZE);
- this.storeCheckPeriod = (Integer) OsgiUtils.checkProperty(properties, PROP_STORE_CHECK_PERIOD);
+ this.storeCheckPeriod = (Integer) OsgiUtils.checkProperty(properties,
+ PROP_INDEXING_SOURCE_CHECK_PERIOD);
this.solrCheckTime = (Integer) OsgiUtils.checkProperty(properties, PROP_SOLR_CHECK_TIME);
this.componentContext = context;
this.indexingCount = 0;
+
+ initializeStore((String) OsgiUtils.checkProperty(properties, PROP_INDEXING_SOURCE_NAME), context);
+ getPrograms();
+
// create index if it is not already done. When an instance of this component is created through the
// REST/Java services first the Solr core initalized and then the associated OSGI component is
// activated
@@ -199,6 +215,7 @@ public class LDPathSemanticIndex impleme
logger.info("New Solr core will be created for the Semantic Index: {}", this.name);
ldpathSemanticIndexManager.createIndex(getConfigProperties());
this.state = IndexState.ACTIVE;
+ this.epoch = indexingSource.getEpoch();
} else {
// solr core has already been created or the semantic index component is re-activated second or
@@ -212,6 +229,7 @@ public class LDPathSemanticIndex impleme
this.name);
// ldpath has changed, reindexing is needed
this.state = IndexState.REINDEXING;
+ this.epoch = Long.parseLong((String) oldMetadata.getProperty(SemanticIndex.PROP_EPOCH));
this.reindexerThread = new Thread(new Reindexer());
this.reindexerThread.start();
@@ -220,11 +238,14 @@ public class LDPathSemanticIndex impleme
if (oldMetadata.get(SemanticIndex.PROP_REVISION) != null) {
// load revision of the index and update the index state
this.revision = Long.parseLong((String) oldMetadata.get(SemanticIndex.PROP_REVISION));
+ this.epoch = Long.parseLong((String) oldMetadata.getProperty(SemanticIndex.PROP_EPOCH));
this.state = IndexState.valueOf(oldMetadata.getProperty(SemanticIndex.PROP_STATE));
+
} else {
// newly created index, store the metadata. Index was created through the REST/Java
// services
this.state = IndexState.ACTIVE;
+ this.epoch = indexingSource.getEpoch();
}
}
}
@@ -240,6 +261,39 @@ public class LDPathSemanticIndex impleme
logger.info("The SemanticIndex: {} initialized successfully", this.name);
}
+ @SuppressWarnings("unchecked")
+ private void initializeStore(String indexingSourceName, ComponentContext componentContext) throws ConfigurationException {
+ BundleContext bundleContext = componentContext.getBundleContext();
+ try {
+ ServiceReference[] indexingSources = bundleContext.getServiceReferences(
+ IndexingSource.class.getName(), null);
+ for (ServiceReference serviceReference : indexingSources) {
+ Object indexingSource = bundleContext.getService(serviceReference);
+ Type[] genericInterfaces = indexingSource.getClass().getGenericInterfaces();
+ if (genericInterfaces.length == 1 && genericInterfaces[0] instanceof ParameterizedType) {
+ Type[] types = ((ParameterizedType) genericInterfaces[0]).getActualTypeArguments();
+ try {
+ @SuppressWarnings("unused")
+ Class<ContentItem> contentItemClass = (Class<ContentItem>) types[0];
+ if (((IndexingSource<ContentItem>) indexingSource).getName().equals(
+ indexingSourceName)) {
+ this.indexingSource = (IndexingSource<ContentItem>) indexingSource;
+ }
+ } catch (ClassCastException e) {
+ // ignore
+ }
+ }
+ }
+ if (this.indexingSource == null) {
+ throw new ConfigurationException(PROP_INDEXING_SOURCE_NAME,
+ "There is no IndexingSource<ContentItem> for the given store name: "
+ + indexingSourceName);
+ }
+ } catch (InvalidSyntaxException e) {
+ // ignore as there is no filter
+ }
+ }
+
private void initializeTracker(String name) {
try {
registeredServerTracker = new RegisteredSolrServerTracker(componentContext.getBundleContext(),
@@ -287,18 +341,51 @@ public class LDPathSemanticIndex impleme
return false;
}
- private Program<Object> getProgram() throws IndexException, IndexManagementException {
+ private void getPrograms() throws IndexException, IndexManagementException {
+ // create program for EntityhubLDPath
SiteManagerBackend backend = new SiteManagerBackend(siteManager);
ValueFactory vf = InMemoryValueFactory.getInstance();
EntityhubLDPath ldPath = new EntityhubLDPath(backend, vf);
- Program<Object> program = null;
try {
- program = ldPath.parseProgram(LDPathUtils.constructReader(this.ldPathProgram));
+ this.objectProgram = ldPath.parseProgram(LDPathUtils.constructReader(this.ldPathProgram));
} catch (LDPathParseException e) {
logger.error("Should never happen!!!!!", e);
throw new IndexException("Failed to create Program from the parsed LDPath", e);
}
- return program;
+ }
+
+ @Deactivate
+ protected void deactivate(ComponentContext context) throws IndexManagementException {
+ // close store check thread and solr core tracker
+ deactivate = true;
+ if (pollingThread != null) {
+ pollingThread.interrupt();
+ }
+ if (registeredServerTracker != null) {
+ registeredServerTracker.close();
+ }
+
+ // check the configuration is deleted or just deactivated
+ ServiceReference reference = context.getBundleContext().getServiceReference(
+ ConfigurationAdmin.class.getName());
+ ConfigurationAdmin configAdmin = (ConfigurationAdmin) context.getBundleContext()
+ .getService(reference);
+ Configuration config;
+ try {
+ config = configAdmin.getConfiguration(this.pid);
+ // if the configuration for the index has been removed, clear all files for this index
+ if (config.getProperties() == null) {
+ logger.info(
+ "Configuration for the Semantic Index: {} has been deleted. All resources will be removed.",
+ this.name);
+ if (ldpathSemanticIndexManager.isConfigured(pid)) {
+ // this case is a check for the remove operation from the felix web console
+ ldpathSemanticIndexManager.removeIndex(this.pid);
+ }
+ } // the index is deactivated. do not nothing.
+ } catch (IOException e) {
+ logger.error("Failed to obtain configuration for the Semantic Index: {}.", this.name, e);
+ }
}
@Override
@@ -383,7 +470,7 @@ public class LDPathSemanticIndex impleme
}
SolrInputDocument doc = new SolrInputDocument();
doc.addField(SolrFieldName.ID.toString(), ci.getUri().getUnicodeString());
- Map<String,Collection<?>> results = executeProgram(contexts);
+ Map<String,Collection<?>> results = executeProgram(contexts, ci);
for (Entry<String,Collection<?>> entry : results.entrySet()) {
doc.addField(entry.getKey(), entry.getValue());
}
@@ -394,7 +481,7 @@ public class LDPathSemanticIndex impleme
Iterator<String> keyIterator = constraints.keys();
while (keyIterator.hasNext()) {
String key = keyIterator.next();
- Iterator<FieldMapping<?,Object>> fieldIt = this.program.getFields().iterator();
+ Iterator<FieldMapping<?,Object>> fieldIt = this.objectProgram.getFields().iterator();
boolean contains = false;
while (fieldIt.hasNext()) {
FieldMapping<?,Object> fm = fieldIt.next();
@@ -672,24 +759,30 @@ public class LDPathSemanticIndex impleme
* This method executes the LDPath program, which was used to configure this index, on the enhancements of
* submitted content by means of the Entityhub. In other words, additional information is gathered from
* the Entityhub for each entity detected in the enhancements by querying the ldpath of this index.
+ * Furthermore, the same LDPath is also executed on the given {@link ContentItem} through the
+ * {@link ContentItemBackend}.
*
* @param contexts
* a {@link Set} of URIs (string representations) that are used as starting nodes to execute
* LDPath program of this index. The context are the URIs of the entities detected in the
* enhancements of the content submitted.
+ * @param ci
+ * {@link ContentItem} on on which the LDPath associated with this index will be executed
* @return the {@link Map} containing the results obtained by executing the given program on the given
* contexts. Keys of the map corresponds to fields in the program and values of the map
* corresponds to results obtained for the field specified in the key.
* @throws IndexManagementException
*/
- private Map<String,Collection<?>> executeProgram(Set<String> contexts) throws IndexManagementException {
+ private Map<String,Collection<?>> executeProgram(Set<String> contexts, ContentItem ci) throws IndexManagementException {
Map<String,Collection<?>> results = new HashMap<String,Collection<?>>();
+
+ // execute the given LDPath for each context passed in contexts parameter
SiteManagerBackend backend = new SiteManagerBackend(siteManager);
ValueFactory vf = InMemoryValueFactory.getInstance();
- EntityhubLDPath ldPath = new EntityhubLDPath(backend, vf);
+ EntityhubLDPath entityhubPath = new EntityhubLDPath(backend, vf);
Representation representation;
for (String context : contexts) {
- representation = ldPath.execute(vf.createReference(context), this.program);
+ representation = entityhubPath.execute(vf.createReference(context), this.objectProgram);
Iterator<String> fieldNames = representation.getFieldNames();
while (fieldNames.hasNext()) {
String fieldName = fieldNames.next();
@@ -710,6 +803,19 @@ public class LDPathSemanticIndex impleme
}
}
}
+
+ // execute the LDPath on the given ContentItem
+ ContentItemBackend contentItemBackend = new ContentItemBackend(ci, true);
+ LDPath<Resource> resourceLDPath = new LDPath<Resource>(contentItemBackend, EnhancerLDPath.getConfig());
+ Program<Resource> resourceProgram;
+ try {
+ resourceProgram = resourceLDPath.parseProgram(new StringReader(this.ldPathProgram));
+ resourceProgram.execute(contentItemBackend, ci.getUri());
+ // sonuclari birlestir
+ } catch (LDPathParseException e) {
+ logger.error("Failed to create Program<Resource> from the LDPath program", e);
+ }
+
return results;
}
@@ -736,11 +842,14 @@ public class LDPathSemanticIndex impleme
propertiesSubset.put(PROP_LD_PATH_PROGRAM, properties.get(PROP_LD_PATH_PROGRAM));
propertiesSubset.put(PROP_INDEX_CONTENT, properties.get(PROP_INDEX_CONTENT));
propertiesSubset.put(PROP_BATCH_SIZE, properties.get(PROP_BATCH_SIZE));
+ propertiesSubset.put(PROP_INDEXING_SOURCE_NAME, properties.get(PROP_INDEXING_SOURCE_NAME));
propertiesSubset.put(PROP_SOLR_CHECK_TIME, properties.get(PROP_SOLR_CHECK_TIME));
- propertiesSubset.put(PROP_STORE_CHECK_PERIOD, properties.get(PROP_STORE_CHECK_PERIOD));
+ propertiesSubset.put(PROP_INDEXING_SOURCE_CHECK_PERIOD,
+ properties.get(PROP_INDEXING_SOURCE_CHECK_PERIOD));
propertiesSubset.put(Constants.SERVICE_PID, properties.get(Constants.SERVICE_PID));
propertiesSubset.put(Constants.SERVICE_RANKING, properties.get(Constants.SERVICE_RANKING));
propertiesSubset.put(PROP_REVISION, this.revision);
+ propertiesSubset.put(PROP_EPOCH, this.epoch);
propertiesSubset.put(PROP_STATE, this.state.name());
return propertiesSubset;
}
@@ -768,50 +877,6 @@ public class LDPathSemanticIndex impleme
pollingThread.start();
}
- protected void bindIndexingSource(IndexingSource<ContentItem> indexingSource) {
- if (indexingSource.getName().equals("contenthubFileStore")) {
- this.store = indexingSource;
- }
- }
-
- protected void unbindIndexingSource(IndexingSource<ContentItem> indexingSource) {
- this.store = null;
- }
-
- @Deactivate
- protected void deactivate(ComponentContext context) throws IndexManagementException {
- // close store check thread and solr core tracker
- deactivate = true;
- if (pollingThread != null) {
- pollingThread.interrupt();
- }
- if (registeredServerTracker != null) {
- registeredServerTracker.close();
- }
-
- // check the configuration is deleted or just deactivated
- ServiceReference reference = context.getBundleContext().getServiceReference(
- ConfigurationAdmin.class.getName());
- ConfigurationAdmin configAdmin = (ConfigurationAdmin) context.getBundleContext()
- .getService(reference);
- Configuration config;
- try {
- config = configAdmin.getConfiguration(this.pid);
- // if the configuration for the index has been removed, clear all files for this index
- if (config.getProperties() == null) {
- logger.info(
- "Configuration for the Semantic Index: {} has been deleted. All resources will be removed.",
- this.name);
- if (ldpathSemanticIndexManager.isConfigured(pid)) {
- // this case is a check for the remove operation from the felix web console
- ldpathSemanticIndexManager.removeIndex(this.pid);
- }
- } // the index is deactivated. do not nothing.
- } catch (IOException e) {
- logger.error("Failed to obtain configuration for the Semantic Index: {}.", this.name, e);
- }
- }
-
/**
* Separate thread to perform reindexing operation in the background. It creates a temporary Solr core,
* indexes all documents obtained from the {@link Store} using the new LDPath program. After the indexing
@@ -835,7 +900,8 @@ public class LDPathSemanticIndex impleme
logger.error("Failed to create temporary Solr core while reindexing the index: {}", name, e);
return;
}
- String temporaryCoreName = temporaryCoreMetadata.getIndexName();;
+ String temporaryCoreName = temporaryCoreMetadata.getIndexName();
+
try {
// initialize solr server tracker for the temporary core
initializeTracker(temporaryCoreName);
@@ -901,11 +967,11 @@ public class LDPathSemanticIndex impleme
long revision = Long.MIN_VALUE;
boolean noChange = false;
do {
- cs = store.changes(store.getEpoch(), revision, batchSize);
+ cs = indexingSource.changes(indexingSource.getEpoch(), revision, batchSize);
Iterator<String> changedItr = cs.iterator();
while (changedItr.hasNext()) {
String changed = changedItr.next();
- ContentItem ci = store.get(changed);
+ ContentItem ci = indexingSource.get(changed);
if (ci == null) {
performRemove(changed);
} else {
@@ -940,19 +1006,20 @@ public class LDPathSemanticIndex impleme
ChangeSet<ContentItem> changeSet = null;
try {
- changeSet = store.changes(store.getEpoch(), revision, batchSize);
+ changeSet = indexingSource.changes(epoch, revision, batchSize);
} catch (StoreException e) {
logger.error(
String.format(
"Failed to get changes from FileRevisionManager with start revision: %s and batch size: %s for Store: %s",
- revision, batchSize, store.getName()), e);
+ revision, batchSize, indexingSource.getName()), e);
} catch (EpochException e) {
if (e.getActiveEpoch() > e.getRequestEpoch()) {
// epoch of the store has increased. So, a reindexing is needed.
// Start the reindexing thread and terminate this one
logger.info(
"Epoch of the Store: {} has increase. So, a reindexing will be in progress",
- store.getName());
+ indexingSource.getName());
+ epoch = e.getActiveEpoch();
state = IndexState.REINDEXING;
reindexerThread = new Thread(new Reindexer());
reindexerThread.start();
@@ -966,7 +1033,7 @@ public class LDPathSemanticIndex impleme
String changedItem = changedItems.next();
ContentItem ci;
try {
- ci = store.get(changedItem);
+ ci = indexingSource.get(changedItem);
if (ci != null) {
index(ci);
logger.info("ContentItem with Uri {} is indexed to {}", changedItem, name);
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndexManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndexManager.java?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndexManager.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndexManager.java Thu Aug 9 13:08:55 2012
@@ -130,7 +130,7 @@ public class LDPathSemanticIndexManager
* <ul>
* <li>{@link LDPathSemanticIndex#PROP_INDEX_CONTENT}: {@code true}</li>
* <li>{@link LDPathSemanticIndex#PROP_BATCH_SIZE}: 10</li>
- * <li>{@link LDPathSemanticIndex#PROP_STORE_CHECK_PERIOD}: 10</li>
+ * <li>{@link LDPathSemanticIndex#PROP_INDEXING_SOURCE_CHECK_PERIOD}: 10</li>
* <li>{@link LDPathSemanticIndex#PROP_SOLR_CHECK_TIME}: 5</li>
* <li>{@link Constants#SERVICE_RANKING}: 0</li>
* </ul>
@@ -175,7 +175,7 @@ public class LDPathSemanticIndexManager
* <ul>
* <li>{@link LDPathSemanticIndex#PROP_INDEX_CONTENT}: {@code true}</li>
* <li>{@link LDPathSemanticIndex#PROP_BATCH_SIZE}: 10</li>
- * <li>{@link LDPathSemanticIndex#PROP_STORE_CHECK_PERIOD}: 10</li>
+ * <li>{@link LDPathSemanticIndex#PROP_INDEXING_SOURCE_CHECK_PERIOD}: 10</li>
* <li>{@link LDPathSemanticIndex#PROP_SOLR_CHECK_TIME}: 5</li>
* <li>{@link Constants#SERVICE_RANKING}: 0</li>
* </ul>
@@ -251,8 +251,11 @@ public class LDPathSemanticIndexManager
if (indexMetadata.get(LDPathSemanticIndex.PROP_BATCH_SIZE) == null) {
indexMetadata.put(LDPathSemanticIndex.PROP_BATCH_SIZE, 10);
}
- if (indexMetadata.get(LDPathSemanticIndex.PROP_STORE_CHECK_PERIOD) == null) {
- indexMetadata.put(LDPathSemanticIndex.PROP_STORE_CHECK_PERIOD, 10);
+ if (indexMetadata.get(LDPathSemanticIndex.PROP_INDEXING_SOURCE_NAME) == null) {
+ indexMetadata.put(LDPathSemanticIndex.PROP_INDEXING_SOURCE_NAME, "contenthubFileStore");
+ }
+ if (indexMetadata.get(LDPathSemanticIndex.PROP_INDEXING_SOURCE_CHECK_PERIOD) == null) {
+ indexMetadata.put(LDPathSemanticIndex.PROP_INDEXING_SOURCE_CHECK_PERIOD, 10);
}
if (indexMetadata.get(LDPathSemanticIndex.PROP_SOLR_CHECK_TIME) == null) {
indexMetadata.put(LDPathSemanticIndex.PROP_SOLR_CHECK_TIME, 5);
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/resources/OSGI-INF/metatype/metatype.properties Thu Aug 9 13:08:55 2012
@@ -34,6 +34,9 @@ org.apache.stanbol.contenthub.index.ldpa
org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.batchSize.name=Batch Size
org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.batchSize.description=Maximum number of changes to be returned
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.storeName.name=Store Name
+org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.storeName.description=Name of the Store instance to be checked for updates.
+
org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.storeCheckPeriod.name=Store Check Period
org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex.storeCheckPeriod.description=Time to check changes in the Contenthub Store in second units
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java Thu Aug 9 13:08:55 2012
@@ -63,7 +63,7 @@ public class RevisionManager {
private String SELECT_CHANGES = "SELECT id, revision FROM %s WHERE revision > ? ORDER BY revision ASC";
- private String SELECT_MORECHANGES = "SELECT id, revision FROM %s WHERE revision >= ? ORDER BY revision ASC";
+ private String SELECT_MORECHANGES = "SELECT id, revision FROM %s WHERE revision > ? AND revision <= ? ORDER BY revision ASC OFFSET ? ROWS";
private String SELECT_EPOCH = "SELECT epoch FROM " + StoreDBManager.EPOCH_TABLE_NAME
+ " WHERE tableName = ?";
@@ -167,78 +167,64 @@ public class RevisionManager {
* @throws StoreException
*/
public <Item> ChangeSet<Item> getChanges(Store<Item> store, long revision, int batchSize) throws StoreException {
- synchronized (RevisionManager.class) {
+ Set<String> changedUris = new LinkedHashSet<String>();
+ long to, from;
- // get connection
- Connection con = dbManager.getConnection();
- String revisionTableName = getStoreID(store);
- batchSize = batchSize == Integer.MAX_VALUE ? batchSize - 1 : batchSize;
-
- // check existence of record for the given content item id
- PreparedStatement ps = null;
- ResultSet rs = null;
+ // get connection
+ Connection con = dbManager.getConnection();
+ String revisionTableName = getStoreID(store);
+ batchSize = batchSize == Integer.MAX_VALUE ? batchSize - 1 : batchSize;
+
+ // check existence of record for the given content item id
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ try {
+ boolean moreChanges = false;
+ long lastRowRevision = 0;
try {
ps = con.prepareStatement(String.format(SELECT_CHANGES, revisionTableName),
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ps.setLong(1, revision);
+ // set max rows one more than the batchsize to be able to see if there are other changes for
+ // the given revision beyond the batchsize
ps.setMaxRows(batchSize + 1);
rs = ps.executeQuery();
- Set<String> changedUris = new LinkedHashSet<String>();
-
+ // if there is no row, return an empty ChangeSet
if (!rs.first()) {
return new ChangeSetImpl<Item>(store, store.getEpoch(), Long.MIN_VALUE, Long.MAX_VALUE,
changedUris);
}
+
+ // if the number of changes >= batchsize + 1
if (rs.absolute(batchSize + 1)) {
- long lastRowRevision = rs.getLong(2);
+ lastRowRevision = rs.getLong(2);
rs.previous();
long nextToLastRowRevision = rs.getLong(2);
rs.beforeFirst();
- // if we are in the middle of a revision, add all changes in that revision to changedUris
+ // if we are in the middle of a revision, set the moreChanges flag to add all changes in
+ // that revision to changedUris
if (lastRowRevision == nextToLastRowRevision) {
- PreparedStatement ps2 = null;
- ResultSet rs2 = null;
- try {
- ps2 = con.prepareStatement(String.format(SELECT_MORECHANGES, revisionTableName),
- ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- ps2.setLong(1, revision);
- rs2 = ps2.executeQuery();
-
- while (rs2.next()) {
- changedUris.add(rs2.getString(1));
- }
- } finally {
- dbManager.closeResultSet(rs2);
- dbManager.closeStatement(ps2);
- }
- } else {
- while (rs.next()) {
- if (rs.isLast()) {
- break;
- }
- changedUris.add(rs.getString(1));
+ moreChanges = true;
+ }
+ while (rs.next()) {
+ if(rs.isLast()) {
+ break;
}
+ changedUris.add(rs.getString(1));
}
-
+ rs.previous();
} else {
rs.beforeFirst();
while (rs.next()) {
changedUris.add(rs.getString(1));
}
- }
-
- // set minimum and maximum revision numbers of the change set
- if (rs.isLast()) {
- rs.previous();
- } else {
rs.last();
}
- long to = rs.getLong(2);
- rs.first();
- long from = rs.getLong(2);
- return new ChangeSetImpl<Item>(store, store.getEpoch(), from, to, changedUris);
+ to = rs.getLong(2);
+ rs.first();
+ from = rs.getLong(2);
} catch (SQLException e) {
log.error("Failed to get changes", e);
@@ -246,8 +232,30 @@ public class RevisionManager {
} finally {
dbManager.closeResultSet(rs);
dbManager.closeStatement(ps);
- dbManager.closeConnection(con);
}
+ if (moreChanges) {
+ try {
+ ps = con.prepareStatement(String.format(SELECT_MORECHANGES, revisionTableName),
+ ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ ps.setLong(1, revision);
+ ps.setLong(2, lastRowRevision);
+ ps.setLong(3, batchSize);
+ rs = ps.executeQuery();
+
+ while (rs.next()) {
+ changedUris.add(rs.getString(1));
+ }
+ } catch (SQLException e) {
+ log.error("Failed to get changes", e);
+ throw new StoreException("Failed to get changes", e);
+ } finally {
+ dbManager.closeResultSet(rs);
+ dbManager.closeStatement(ps);
+ }
+ }
+ return new ChangeSetImpl<Item>(store, store.getEpoch(), from, to, changedUris);
+ } finally {
+ dbManager.closeConnection(con);
}
}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/StoreDBManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/StoreDBManager.java?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/StoreDBManager.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/StoreDBManager.java Thu Aug 9 13:08:55 2012
@@ -60,6 +60,7 @@ public class StoreDBManager {
@Activate
protected void activate(ComponentContext componentContext) throws StoreException {
+ System.setProperty("derby.language.statementCacheSize", "0");
String stanbolHome = componentContext.getBundleContext().getProperty("sling.home");
DB_URL = "jdbc:derby:" + stanbolHome + "/contenthub/store/revisions;create=true";
// initialize the epoch table
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java Thu Aug 9 13:08:55 2012
@@ -91,9 +91,9 @@ import org.slf4j.LoggerFactory;
* suitable with the types of the parts.
* </p>
* <p>
- * Revisions of {@link ContentItem}s submitted to this store is managed through the
- * {@link FileRevisionManager}. Once a document added, updated or deleted the revision of the
- * {@link ContentItem} is set as {@link System#currentTimeMillis()}.
+ * Revisions of {@link ContentItem}s submitted to this store is managed through the {@link RevisionManager}.
+ * Once a document added, updated or deleted the revision of the {@link ContentItem} is set as
+ * {@link System#currentTimeMillis()}.
* </p>
* <p>
* To be able to populate the HTML interface, this implementation also provides additional metadata regarding
@@ -213,8 +213,9 @@ public class FileStore implements Store<
*
* @param name
*/
- public FileStore(String name) {
+ public FileStore(String name, RevisionManager revisionManager) {
this.name = name;
+ this.revisionManager = revisionManager;
}
@Activate
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java Thu Aug 9 13:08:55 2012
@@ -72,7 +72,7 @@ public class LDPathSemanticIndexTest {
private static Logger logger = LoggerFactory.getLogger(LDPathSemanticIndexTest.class);
- private static final int TESTCOUNT = 16;
+ private static final int TESTCOUNT = 15;
@TestReference
private LDPathSemanticIndexManager ldPathSemanticIndexManager;
@@ -89,8 +89,6 @@ public class LDPathSemanticIndexTest {
@TestReference
private EnhancementJobManager jobManager;
- private Store<ContentItem> fileStore;
-
@TestReference
private BundleContext bundleContext;
@@ -99,6 +97,8 @@ public class LDPathSemanticIndexTest {
private static String pid;
private static int counter = 0;
+ private Store<ContentItem> store;
+
@Before
public void before() throws IndexManagementException, IndexException, InterruptedException, IOException {
String name = "test_index_name";
@@ -112,10 +112,10 @@ public class LDPathSemanticIndexTest {
semanticIndex = (LDPathSemanticIndex) tempSemanticIndex;
solrServer = semanticIndex.getServer();
}
- if (fileStore == null) {
+ if (store == null) {
if (bundleContext != null) {
- fileStore = getContenthubStore();
- if (fileStore == null) {
+ store = getContenthubStore();
+ if (store == null) {
throw new IllegalStateException("Null Store");
}
} else {
@@ -381,50 +381,6 @@ public class LDPathSemanticIndexTest {
}
}
- @Test
- public void epochChangeTest() throws IndexManagementException,
- InterruptedException,
- IOException,
- IndexException,
- StoreException,
- SearchException {
- String name = "test_index_name_for_epoch";
- String program = "@prefix dbp-ont: <http://dbpedia.org/ontology/>; person_entities = .[rdf:type is dbp-ont:Person]:: xsd:anyURI (termVectors=\"true\");";
- Properties props = new Properties();
- props.put(LDPathSemanticIndex.PROP_NAME, name);
- props.put(LDPathSemanticIndex.PROP_LD_PATH_PROGRAM, program);
- props.put(LDPathSemanticIndex.PROP_DESCRIPTION, "epoch program");
- props.put(LDPathSemanticIndex.PROP_INDEX_CONTENT, false);
- props.put(LDPathSemanticIndex.PROP_BATCH_SIZE, 10);
- props.put(LDPathSemanticIndex.PROP_STORE_CHECK_PERIOD, 1);
- props.put(LDPathSemanticIndex.PROP_SOLR_CHECK_TIME, 5);
- String pid = ldPathSemanticIndexManager.createIndex(props);
-
- try {
- SemanticIndex<ContentItem> semanticIndex = getLDPathSemanticIndex(name);
- ContentItem ci = contentItemFactory.createContentItem(new StringSource(
- "Michael Jackson is a very famous person, and he was born in Indiana."));
- fileStore.put(ci);
- fileStore.removeAll();
-
- // make sure that the index will perform reindexing
- Thread.sleep(1500);
-
- // index ci to new semantic index
- while (semanticIndex.getState() != IndexState.ACTIVE) {
- Thread.sleep(500);
- }
-
- String query = "*:*";
- SolrDocumentList sdl = solrSearch.search(query, name).getResults();
- assertNotNull("Result must not be null for query " + query, sdl);
- assertTrue("There should be no indexed item", sdl.size() == 0);
-
- } finally {
- ldPathSemanticIndexManager.removeIndex(pid);
- }
- }
-
@After
public void after() throws IndexManagementException {
counter++;
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/RevisionManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/RevisionManagerTest.java?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/RevisionManagerTest.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/RevisionManagerTest.java Thu Aug 9 13:08:55 2012
@@ -19,9 +19,6 @@ package org.apache.stanbol.contenthub.te
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.IOException;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -31,21 +28,14 @@ import java.util.Iterator;
import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
import org.apache.sling.junit.annotations.TestReference;
-import org.apache.stanbol.commons.semanticindex.index.IndexException;
-import org.apache.stanbol.commons.semanticindex.index.IndexManagementException;
import org.apache.stanbol.commons.semanticindex.store.ChangeSet;
-import org.apache.stanbol.commons.semanticindex.store.Store;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
import org.apache.stanbol.contenthub.revisionmanager.RevisionManager;
import org.apache.stanbol.contenthub.revisionmanager.StoreDBManager;
import org.apache.stanbol.contenthub.store.file.FileStore;
-import org.apache.stanbol.enhancer.servicesapi.ContentItem;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,22 +52,6 @@ public class RevisionManagerTest {
@TestReference
private BundleContext bundleContext;
- private Store<?> store;
-
- @Before
- public void before() throws IndexManagementException, IndexException, InterruptedException, IOException {
- if (store == null) {
- if (bundleContext != null) {
- store = getContenthubStore();
- if (store == null) {
- throw new IllegalStateException("Null Store");
- }
- } else {
- throw new IllegalStateException("Null bundle context");
- }
- }
- }
-
@Test
public void revisionManagerTest() {
assertNotNull("Expecting RevisionManager to be injected by Sling test runner", revisionManager);
@@ -95,18 +69,21 @@ public class RevisionManagerTest {
@Test
public void updateRevisionTest() throws StoreException, SQLException {
+ FileStore fileStore = new FileStore("updateRevisionTestStore", revisionManager);
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
// do the update
String contentItemID = "contenthub_test_content_item_id";
- long newRevision = revisionManager.updateRevision(store, contentItemID);
+ long newRevision;
boolean recordExist = false;
long revisionNumber = Long.MAX_VALUE;
String query;
try {
+ revisionManager.initializeRevisionTables(fileStore);
+ newRevision = revisionManager.updateRevision(fileStore, contentItemID);
query = String.format("SELECT id, revision FROM %s WHERE id = ?",
- revisionManager.getStoreID(store));
+ revisionManager.getStoreID(fileStore));
// check the update
con = dbManager.getConnection();
@@ -117,50 +94,29 @@ public class RevisionManagerTest {
recordExist = true;
revisionNumber = rs.getLong(2);
}
- dbManager.closeStatement(ps);
assertTrue("failed to obtain content item revision", recordExist);
assertTrue("wrong revision number", (revisionNumber == newRevision));
- } catch (SQLException e) {
- log.warn("Failed to remove the test record", e);
} finally {
- // clear the update
- try {
- query = String.format("DELETE FROM %s WHERE id = ?", revisionManager.getStoreID(store));
- ps = con.prepareStatement(query);
- ps.setString(1, contentItemID);
- int result = ps.executeUpdate();
- if (result != 1) {
- log.warn(
- "Wrong number of updated records while removing the test record. Updated record number: {}",
- result);
- }
- } finally {
- dbManager.closeResultSet(rs);
- dbManager.closeStatement(ps);
- dbManager.closeConnection(con);
- }
+ dbManager.closeResultSet(rs);
+ dbManager.closeStatement(ps);
+ clearDummyStoreResources(fileStore, con);
}
}
- /**
- * IMPORTANT NOTE: At time of executing the test below, there MUST be no other requests updating the
- * revision table, otherwise the test will fail.
- *
- * @throws InterruptedException
- * @throws SQLException
- */
@Test
public void iterativeChangesTest() throws StoreException, InterruptedException, SQLException {
- log.warn("DO NOT UPDATE THE STORE: {} DURING EXECUTION OF THIS TEST", store.getName());
- Connection con = dbManager.getConnection();
+ FileStore fileStore = new FileStore("iterativeChangesTestStore", revisionManager);
+ Connection con = null;
String contentItemID = "contenthub_test_content_item_id";
PreparedStatement ps = null;
- int insertCount = 0;
try {
+ con = dbManager.getConnection();
+ revisionManager.initializeRevisionTables(fileStore);
+
// do the update
- String query = "INSERT INTO " + revisionManager.getStoreID(store)
+ String query = "INSERT INTO " + revisionManager.getStoreID(fileStore)
+ " (id, revision) VALUES (?,?)";
long startRevision = System.currentTimeMillis();
long revision = System.currentTimeMillis();
@@ -171,11 +127,10 @@ public class RevisionManagerTest {
ps.setLong(2, ++revision);
ps.executeUpdate();
ps.clearParameters();
- insertCount++;
}
// check changes
- ChangeSet<?> changeSet = revisionManager.getChanges(store, startRevision, 3);
+ ChangeSet<?> changeSet = revisionManager.getChanges(fileStore, startRevision, 3);
Iterator<String> changedItems = changeSet.iterator();
int itemCount = 0;
while (changedItems.hasNext()) {
@@ -198,7 +153,7 @@ public class RevisionManagerTest {
assertTrue("Changes does not include correct toRevision value",
(changeSet.toRevision() == revision - 2));
- changeSet = revisionManager.getChanges(store, revision - 2, 3);
+ changeSet = revisionManager.getChanges(fileStore, revision - 2, 3);
itemCount = 0;
changedItems = changeSet.iterator();
while (changedItems.hasNext()) {
@@ -222,40 +177,22 @@ public class RevisionManagerTest {
assertTrue("Changes does not include correct toRevision value",
(changeSet.toRevision() == revision));
} finally {
- // clear test changes
- String query = String.format(
- "DELETE FROM %s WHERE id = ? OR id = ? OR id = ? OR id = ? OR id = ?",
- revisionManager.getStoreID(store));
- try {
- ps = con.prepareStatement(query);
- for (int i = 0; i < insertCount; i++) {
- ps.setString(i + 1, contentItemID + i);
- }
- int result = ps.executeUpdate();
- if (result != 5) {
- log.warn(
- "Wrong number of updated records while removing the test record. Updated record number: {}",
- result);
- }
- } catch (SQLException e) {
- log.warn("Failed to remove the test record", e);
- } finally {
- dbManager.closeStatement(ps);
- dbManager.closeConnection(con);
- }
+ dbManager.closeStatement(ps);
+ clearDummyStoreResources(fileStore, con);
}
}
@Test
public void batchSizeDoesNotFitToRevisionTest() throws StoreException, SQLException {
- log.warn("DO NOT UPDATE THE STORE: {} DURING EXECUTION OF THIS TEST", store.getName());
- Connection con = dbManager.getConnection();
+ FileStore fileStore = new FileStore("batchSizeDoesNotFitToRevisionTestStore", revisionManager);
+ Connection con = null;
String contentItemID = "contenthub_test_content_item_id";
PreparedStatement ps = null;
- int insertCount = 0;
try {
+ revisionManager.initializeRevisionTables(fileStore);
+ con = dbManager.getConnection();
// do the update
- String query = "INSERT INTO " + revisionManager.getStoreID(store)
+ String query = "INSERT INTO " + revisionManager.getStoreID(fileStore)
+ " (id, revision) VALUES (?,?)";
long revision = System.currentTimeMillis();
for (int i = 0; i < 2; i++) {
@@ -264,11 +201,10 @@ public class RevisionManagerTest {
ps.setLong(2, revision + 1);
ps.executeUpdate();
ps.clearParameters();
- insertCount++;
}
// get changes
- ChangeSet<?> changeSet = revisionManager.getChanges(store, revision, 1);
+ ChangeSet<?> changeSet = revisionManager.getChanges(fileStore, revision, 1);
int itemCount = 0;
Iterator<String> changedItems = changeSet.iterator();
while (changedItems.hasNext()) {
@@ -287,47 +223,37 @@ public class RevisionManagerTest {
assertTrue("Changes does not include correct URIs", itemCount < 2);
}
} finally {
- // clear test changes
- String query = String.format("DELETE FROM %s WHERE id = ? OR id = ?",
- revisionManager.getStoreID(store));
- try {
- ps = con.prepareStatement(query);
- for (int i = 0; i < insertCount; i++) {
- ps.setString(i + 1, contentItemID + i);
- }
- int result = ps.executeUpdate();
- if (result != 2) {
- log.warn(
- "Wrong number of updated records while removing the test record. Updated record number: {}",
- result);
- }
- } catch (SQLException e) {
- log.warn("Failed to remove the test record", e);
- } finally {
- dbManager.closeStatement(ps);
- dbManager.closeConnection(con);
- }
+ dbManager.closeStatement(ps);
+ clearDummyStoreResources(fileStore, con);
}
}
@Test
public void emptyChangesTest() throws StoreException {
- long revision = System.currentTimeMillis();
- ChangeSet<?> changeSet = revisionManager.getChanges(store, revision, 1);
- assertTrue("There must be no changes", !changeSet.iterator().hasNext());
+ FileStore fileStore = new FileStore("emptyChangesTestStore", revisionManager);
+ try {
+ revisionManager.initializeRevisionTables(fileStore);
+ long revision = System.currentTimeMillis();
+ ChangeSet<?> changeSet = revisionManager.getChanges(fileStore, revision, 1);
+ assertTrue("There must be no changes", !changeSet.iterator().hasNext());
+ } finally {
+ clearDummyStoreResources(fileStore, dbManager.getConnection());
+ }
}
@Test
public void getStoreIDTest() {
- assertTrue("Store ID must be same with the name of the Store", revisionManager.getStoreID(store)
- .equals(store.getName()));
+ FileStore fileStore = new FileStore("getStoreIDTestStore", null);
+ assertTrue("Store ID must be same with the name of the Store", revisionManager.getStoreID(fileStore)
+ .equals(fileStore.getName()));
}
@Test
public void initializeRevisionTablesTest() throws StoreException, SQLException {
- FileStore fileStore = new FileStore("revisionManagerTestStore");
+ FileStore fileStore = new FileStore("revisionManagerTestStore", revisionManager);
Connection con = null;
PreparedStatement ps = null;
+ ResultSet rs = null;
String tableName = revisionManager.getStoreID(fileStore);
try {
revisionManager.initializeRevisionTables(fileStore);
@@ -337,73 +263,45 @@ public class RevisionManagerTest {
// check epoch table entry
con = dbManager.getConnection();
- ps = null;
- ResultSet rs = null;
boolean recordExists = false;
- try {
- ps = con.prepareStatement("SELECT epoch FROM " + StoreDBManager.EPOCH_TABLE_NAME
- + " WHERE tableName = ?");
- ps.setString(1, tableName);
- rs = ps.executeQuery();
- if (rs.next()) {
- recordExists = true;
- }
-
- assertTrue(String.format("There is no entry for tableName: %s in epochTable", tableName),
- recordExists);
- } finally {
- dbManager.closeResultSet(rs);
- dbManager.closeStatement(ps);
- }
- } finally {
- // clear test data
- Statement stmt = null;
- try {
- // first remove the the table
- stmt = con.createStatement();
- stmt.executeUpdate("DROP TABLE " + tableName);
-
- } finally {
- dbManager.closeStatement(stmt);
+ ps = con.prepareStatement("SELECT epoch FROM " + StoreDBManager.EPOCH_TABLE_NAME
+ + " WHERE tableName = ?");
+ ps.setString(1, tableName);
+ rs = ps.executeQuery();
+ if (rs.next()) {
+ recordExists = true;
}
- try {
- // delete the entry from epoch table
- ps = con.prepareStatement("DELETE FROM " + StoreDBManager.EPOCH_TABLE_NAME
- + " WHERE tableName = ?");
- ps.setString(1, tableName);
- ps.executeUpdate();
- } finally {
- dbManager.closeStatement(ps);
- dbManager.closeConnection(con);
- }
+ assertTrue(String.format("There is no entry for tableName: %s in epochTable", tableName),
+ recordExists);
+ } finally {
+ dbManager.closeResultSet(rs);
+ dbManager.closeStatement(ps);
+ clearDummyStoreResources(fileStore, con);
}
}
- @SuppressWarnings("unchecked")
- private Store<ContentItem> getContenthubStore() {
- Store<ContentItem> contentHubStore = null;
+ private void clearDummyStoreResources(FileStore store, Connection con) {
+ Statement stmt = null;
+ PreparedStatement ps = null;
+ String tableName = revisionManager.getStoreID(store);
try {
- ServiceReference[] stores = bundleContext.getServiceReferences(Store.class.getName(), null);
- for (ServiceReference serviceReference : stores) {
- Object store = bundleContext.getService(serviceReference);
- Type[] genericInterfaces = store.getClass().getGenericInterfaces();
- if (genericInterfaces.length == 1 && genericInterfaces[0] instanceof ParameterizedType) {
- Type[] types = ((ParameterizedType) genericInterfaces[0]).getActualTypeArguments();
- try {
- @SuppressWarnings("unused")
- Class<ContentItem> contentItemClass = (Class<ContentItem>) types[0];
- if (((Store<ContentItem>) store).getName().equals("contenthubFileStore")) {
- contentHubStore = (Store<ContentItem>) store;
- }
- } catch (ClassCastException e) {
- // ignore
- }
- }
- }
- } catch (InvalidSyntaxException e) {
- // ignore as there is no filter
+ // first remove the the table
+ stmt = con.createStatement();
+ stmt.executeUpdate("DROP TABLE " + tableName);
+
+ // delete the entry from epoch table
+ ps = con.prepareStatement("DELETE FROM " + StoreDBManager.EPOCH_TABLE_NAME
+ + " WHERE tableName = ?");
+ ps.setString(1, tableName);
+ ps.executeUpdate();
+
+ } catch (SQLException e) {
+ log.error("Failed clear test resources for the table: {}", tableName);
+ } finally {
+ dbManager.closeStatement(stmt);
+ dbManager.closeStatement(ps);
+ dbManager.closeConnection(con);
}
- return contentHubStore;
}
}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/StoreDBManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/StoreDBManagerTest.java?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/StoreDBManagerTest.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/revisionmanager/StoreDBManagerTest.java Thu Aug 9 13:08:55 2012
@@ -28,13 +28,10 @@ import java.sql.Statement;
import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
import org.apache.sling.junit.annotations.TestReference;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
-import org.apache.stanbol.contenthub.revisionmanager.RevisionManager;
import org.apache.stanbol.contenthub.revisionmanager.StoreDBManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.BundleContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
@RunWith(SlingAnnotationsTestRunner.class)
public class StoreDBManagerTest {
@@ -42,9 +39,6 @@ public class StoreDBManagerTest {
private StoreDBManager dbManager;
@TestReference
- private RevisionManager revisionManager;
-
- @TestReference
private BundleContext bundleContext;
@Test
@@ -53,11 +47,6 @@ public class StoreDBManagerTest {
}
@Test
- public void dbRevisionManagerTest() {
- assertNotNull("Expecting RevisionManager to be injected by Sling test runner", revisionManager);
- }
-
- @Test
public void bundleContextTest() {
assertNotNull("Expecting BundleContext to be injected by Sling test runner", bundleContext);
}
Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug 9 13:08:55 2012
@@ -0,0 +1 @@
+TestResource.java
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/LDPathSemanticIndexResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/LDPathSemanticIndexResource.java?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/LDPathSemanticIndexResource.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/LDPathSemanticIndexResource.java Thu Aug 9 13:08:55 2012
@@ -46,10 +46,12 @@ import javax.ws.rs.core.Response.Status;
import org.apache.stanbol.commons.semanticindex.index.IndexException;
import org.apache.stanbol.commons.semanticindex.index.IndexManagementException;
+import org.apache.stanbol.commons.semanticindex.store.IndexingSource;
import org.apache.stanbol.commons.web.base.ContextHelper;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
import org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex;
import org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndexManager;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -106,10 +108,13 @@ public class LDPathSemanticIndexResource
* @param program
* LDPath program that will be used as a source to create the semantic index. Index fields and
* Solr specific configurations regarding those index fields are given in this parameter.
+ * @param indexContent
+ * If this configuration is true plain text content of the {@link ContentItem} is also indexed
+ * to be used in the full text search
* @param batchsize
* Maximum number of changes to be returned
- * @param storecheckperiod
- * Time to check changes in the Contenthub Store in second units
+ * @param indexingSourceCheckperiod
+ * Time to check changes in the {@link IndexingSource} in second units
* @param solrchecktime
* Maximum time in seconds to wait for the availability of the Solr Server
* @param ranking
@@ -128,9 +133,10 @@ public class LDPathSemanticIndexResource
@FormParam("description") String description,
@FormParam("program") String program,
@FormParam("indexContent") boolean indexContent,
- @FormParam("batchsize") @DefaultValue("10") int batchsize,
- @FormParam("storecheckperiod") @DefaultValue("10") int storecheckperiod,
- @FormParam("solrchecktime") @DefaultValue("5") int solrchecktime,
+ @FormParam("batchSize") @DefaultValue("10") int batchsize,
+ @FormParam("indexingSourceName") @DefaultValue("contenthubFileStore") String indexingSourceName,
+ @FormParam("indexingSourceCheckPeriod") @DefaultValue("10") int indexingSourceCheckperiod,
+ @FormParam("solrCheckTime") @DefaultValue("5") int solrchecktime,
@FormParam("ranking") @DefaultValue("0") int ranking,
@Context ServletContext context,
@Context HttpHeaders headers) throws IndexManagementException,
@@ -143,7 +149,8 @@ public class LDPathSemanticIndexResource
parameters.put(LDPathSemanticIndex.PROP_LD_PATH_PROGRAM, program);
parameters.put(LDPathSemanticIndex.PROP_INDEX_CONTENT, indexContent);
parameters.put(LDPathSemanticIndex.PROP_BATCH_SIZE, batchsize);
- parameters.put(LDPathSemanticIndex.PROP_STORE_CHECK_PERIOD, storecheckperiod);
+ parameters.put(LDPathSemanticIndex.PROP_INDEXING_SOURCE_NAME, indexingSourceName);
+ parameters.put(LDPathSemanticIndex.PROP_INDEXING_SOURCE_CHECK_PERIOD, indexingSourceCheckperiod);
parameters.put(LDPathSemanticIndex.PROP_SOLR_CHECK_TIME, solrchecktime);
parameters.put(Constants.SERVICE_RANKING, ranking);
programManager.createIndex(parameters);
@@ -164,8 +171,10 @@ public class LDPathSemanticIndexResource
indexMetadataMapValues.add(properties.get(LDPathSemanticIndex.PROP_DESCRIPTION).toString());
indexMetadataMapValues.add(properties.get(LDPathSemanticIndex.PROP_INDEX_CONTENT).toString());
indexMetadataMapValues.add(properties.get(LDPathSemanticIndex.PROP_BATCH_SIZE).toString());
- indexMetadataMapValues
- .add(properties.get(LDPathSemanticIndex.PROP_STORE_CHECK_PERIOD).toString());
+ indexMetadataMapValues.add(properties.get(LDPathSemanticIndex.PROP_INDEXING_SOURCE_NAME)
+ .toString());
+ indexMetadataMapValues.add(properties.get(LDPathSemanticIndex.PROP_INDEXING_SOURCE_CHECK_PERIOD)
+ .toString());
indexMetadataMapValues.add(properties.get(LDPathSemanticIndex.PROP_SOLR_CHECK_TIME).toString());
indexMetadataMapValues.add(properties.get(LDPathSemanticIndex.PROP_LD_PATH_PROGRAM).toString());
indexMetadataMap.put(indexMetadata.getKey(), indexMetadataMapValues);
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java?rev=1371191&r1=1371190&r2=1371191&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java Thu Aug 9 13:08:55 2012
@@ -51,8 +51,10 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
+import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
@@ -77,12 +79,16 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.UriInfo;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
import org.apache.clerezza.rdf.core.serializedform.Serializer;
import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
import org.apache.stanbol.commons.semanticindex.store.Store;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
import org.apache.stanbol.commons.web.base.ContextHelper;
@@ -95,6 +101,8 @@ import org.apache.stanbol.enhancer.servi
import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
import org.apache.stanbol.enhancer.servicesapi.impl.ByteArraySource;
import org.apache.stanbol.enhancer.servicesapi.impl.StringSource;
+import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
+import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.osgi.framework.BundleContext;
@@ -198,7 +206,8 @@ public class StoreResource extends BaseS
this.tcManager = ContextHelper.getServiceFromContext(TcManager.class, context);
this.cif = ContextHelper.getServiceFromContext(ContentItemFactory.class, context);
this.serializer = ContextHelper.getServiceFromContext(Serializer.class, context);
- this.enhancementJobManager = ContextHelper.getServiceFromContext(EnhancementJobManager.class, context);
+ this.enhancementJobManager = ContextHelper
+ .getServiceFromContext(EnhancementJobManager.class, context);
this.store = getStoreFromBundleContext(bundleContext);
if (this.store == null || this.cif == null || this.enhancementJobManager == null
|| this.serializer == null || this.tcManager == null) {
@@ -628,7 +637,26 @@ public class StoreResource extends BaseS
ci = cif.createContentItem(new UriRef(contentURI),
new ByteArraySource(content, mediaType.toString()));
if (constraints != null && !constraints.trim().equals("")) {
- ci.addPart(FileStore.CONSTRAINTS_URI, cif.createBlob(new StringSource(constraints)));
+ MGraph g = new IndexedMGraph();
+ UriRef uri = ci.getUri();
+ JSONObject cons = new JSONObject(constraints);
+ @SuppressWarnings("unchecked")
+ Iterator<String> keys = cons.keys();
+ while (keys.hasNext()) {
+ String key = keys.next();
+ String predicate = NamespaceEnum.getFullName(key);
+ if (key.equals(predicate)) {
+ log.error("Undefined namespace in predicate: {}", predicate);
+ throw new StoreException(String.format("Undefined namespace in predicate: %s",
+ predicate));
+ }
+ JSONArray jsonArray = cons.getJSONArray(key);
+ for (int i = 0; i < jsonArray.length(); i++) {
+ g.add(new TripleImpl(uri, new UriRef(predicate), LiteralFactory.getInstance()
+ .createTypedLiteral(inferObjectType(jsonArray.get(i)))));
+ }
+ }
+ ci.addPart(FileStore.CONSTRAINTS_URI, g);
}
if (title != null && !title.trim().equals("")) {
JSONObject htmlMetadata = new JSONObject();
@@ -643,6 +671,9 @@ public class StoreResource extends BaseS
} catch (IOException e) {
log.error("Failed to create the ContentItem", e);
throw new StoreException("Failed to create the ContentItem", e);
+ } catch (JSONException e) {
+ log.error("Failed to create JSONObject from constraints: {}", constraints);
+ throw new StoreException("Failed to create JSONObject from constraints", e);
}
store.put(ci);
@@ -694,6 +725,28 @@ public class StoreResource extends BaseS
return createEnhanceAndRedirect(data, mediaType, contentURI, false, null, null, headers);
}
+ private Object inferObjectType(Object val) {
+ Object ret = null;
+ try {
+ ret = DateFormat.getInstance().parse(val.toString());
+ } catch (Exception e) {
+ try {
+ ret = Long.valueOf(val.toString());
+ } catch (Exception e1) {
+ try {
+ ret = Double.valueOf(val.toString());
+ } catch (Exception e2) {
+ try {
+ ret = String.valueOf(val.toString());
+ } catch (Exception e3) {}
+ }
+ }
+ }
+
+ if (ret == null) ret = val;
+ return ret;
+ }
+
/*
* Services to draw HTML view
*/