You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by to...@apache.org on 2011/03/08 13:40:27 UTC

svn commit: r1079344 - /uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java

Author: tommaso
Date: Tue Mar  8 12:40:27 2011
New Revision: 1079344

URL: http://svn.apache.org/viewvc?rev=1079344&view=rev
Log:
[UIMA-2066] - first version of typeSystem fail-fast check

Modified:
    uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java

Modified: uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java?rev=1079344&r1=1079343&r2=1079344&view=diff
==============================================================================
--- uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java (original)
+++ uima/sandbox/trunk/Solrcas/src/main/java/org/apache/uima/solrcas/SolrCASConsumer.java Tue Mar  8 12:40:27 2011
@@ -39,7 +39,10 @@ import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.Feature;
 import org.apache.uima.cas.FeatureStructure;
 import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.impl.TypeImpl;
 import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.tcas.Annotation_Type;
 import org.apache.uima.resource.ResourceAccessException;
 import org.apache.uima.resource.ResourceInitializationException;
 import org.apache.uima.util.Level;
@@ -80,7 +83,7 @@ public class SolrCASConsumer extends Cas
       throw new ResourceInitializationException(e);
     }
 
-      /* set Solr autoCommit parameter */
+    /* set Solr autoCommit parameter */
     try {
       this.autoCommit = getAutoCommitValue();
     } catch (Exception e) {
@@ -90,7 +93,53 @@ public class SolrCASConsumer extends Cas
 
   }
 
-  /* allows retrieve of input stream from a path specifying one of:
+  @Override
+  public void typeSystemInit(TypeSystem typeSystem) throws AnalysisEngineProcessException {
+    super.typeSystemInit(typeSystem);
+    for (String key : mappingConfig.getFeatureStructuresMapping().keySet()) {
+      Type type = typeSystem.getType(key);
+      if (type==null) {
+        throw new AnalysisEngineProcessException("required_feature_structure_missing_from_cas",
+                new Object[]{key});
+      }
+      Map<String, String> stringStringMap = mappingConfig.getFeatureStructuresMapping().get(key);
+      for (String featureName : stringStringMap.keySet()) {
+        if (!"coveredText".equals(featureName) && type.getFeatureByBaseName(featureName)==null) {
+          throw new AnalysisEngineProcessException("required_attribute_missing", 
+                  new Object[]{featureName,type});
+        }
+      }
+    }
+  }
+
+
+  public void process(CAS cas) throws AnalysisEngineProcessException {
+    // create the SolrDocument from the CAS object basing on the mapping configuration
+    SolrInputDocument document = createDocument(cas);
+
+    // send the SolrDocument to SolrServer
+    try {
+      solrServer.add(document);
+    } catch (Exception e) {
+      getContext().getLogger().log(Level.SEVERE, new StringBuilder("Error while adding document").
+              append(document.toString()).toString());
+      throw new AnalysisEngineProcessException(e);
+    }
+
+    // if AutoCommit is enabled send the commit message to the SolrServer
+    if (!autoCommit) {
+      try {
+        solrServer.commit();
+      } catch (Exception e) {
+        getContext().getLogger().log(Level.SEVERE, new StringBuilder("Error while committing document").
+                append(document.toString()).toString());
+        throw new AnalysisEngineProcessException(e);
+      }
+    }
+  }
+
+
+  /* allows retrieving of input stream from a path specifying one of:
    * file://absolute/path
    * http://something.com/res.ext
    * classpath:/path/to/something.xml
@@ -153,31 +202,6 @@ public class SolrCASConsumer extends Cas
     return solrServer;
   }
 
-  public void process(CAS cas) throws AnalysisEngineProcessException {
-    // create the SolrDocument from the CAS object basing on the mapping configuration
-    SolrInputDocument document = createDocument(cas);
-
-    // send the SolrDocument to SolrServer
-    try {
-      solrServer.add(document);
-    } catch (Exception e) {
-      getContext().getLogger().log(Level.SEVERE, new StringBuilder("Error while adding document").
-              append(document.toString()).toString());
-      throw new AnalysisEngineProcessException(e);
-    }
-
-    // if AutoCommit is enabled send the commit message to the SolrServer
-    if (!autoCommit) {
-      try {
-        solrServer.commit();
-      } catch (Exception e) {
-        getContext().getLogger().log(Level.SEVERE, new StringBuilder("Error while committing document").
-                append(document.toString()).toString());
-        throw new AnalysisEngineProcessException(e);
-      }
-    }
-  }
-
   /* create a SolrDocument from the current CAS object and the mapping configuration */
   private SolrInputDocument createDocument(CAS cas) {
     SolrInputDocument document = new SolrInputDocument();