Commits

Sam Adams committed 4b5a719

Refactored deposit processing

Comments (0)

Files changed (2)

chemistry-common/src/main/java/net/chempound/chemistry/cml/CmlUtils.java

+package net.chempound.chemistry.cml;
+
+import nu.xom.Elements;
+import org.xmlcml.cml.base.CMLElement;
+import org.xmlcml.cml.element.CMLModule;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author Sam Adams
+ */
+public class CmlUtils {
+
+    public static CMLModule findModuleByConvention(final CMLElement cml, final QName convention) {
+        final Elements elements = cml.getChildCMLElements("module");
+        for (int i = 0; i < elements.size(); i++) {
+            final CMLModule module = (CMLModule) elements.get(i);
+            if (convention.equals(CmlUtils.getConvention(module))) {
+                return module;
+            }
+        }
+        return null;
+    }
+
+    public static QName getConvention(final CMLModule module) {
+        final String convention = module.getConvention();
+        if (convention != null) {
+            final int i = convention.indexOf(':');
+            if (i == -1) {
+                return new QName(convention);
+            }
+            final String prefix = convention.substring(0, i);
+            final String localPart = convention.substring(i+1);
+            final String namespaceUri = module.getNamespaceURIForPrefix(prefix);
+            return new QName(namespaceUri, localPart, prefix);
+        }
+        return null;
+    }
+
+}

chemistry-search-structure/src/main/java/net/chempound/webapp/search/chemistry/MoleculeIndexer.java

 package net.chempound.webapp.search.chemistry;
 
-import org.apache.commons.io.FileUtils;
-import org.xmlcml.cml.element.CMLMolecule;
 import net.chempound.config.ChempoundConfiguration;
 import net.chempound.index.ContentIndexer;
 import net.chempound.rdf.chempound.Item;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlcml.cml.element.CMLMolecule;
 
 import javax.inject.Inject;
 import java.io.*;
  */
 public class MoleculeIndexer implements ContentIndexer<CMLMolecule> {
 
+    private static final Logger LOG = LoggerFactory.getLogger(MoleculeIndexer.class);
+
     private final ChempoundConfiguration config;
 
     private final File indexFile;
     }
 
     @Override
-    public void index(final Item item, final List<? extends CMLMolecule> objects) throws FileNotFoundException {
+    public void index(final Item item, final List<? extends CMLMolecule> objects) {
         final List<String> smiles = new ArrayList<String>();
         for (final CMLMolecule mol : objects) {
             // TODO generate SMILES
         }
-        appendToIndex(smiles, item.getUri());
+        try {
+            appendToIndex(smiles, item.getUri());
+        } catch (Exception e) {
+            LOG.warn("Error indexing molecule ["+item.getURI()+"]", e);
+        }
     }
 
     private synchronized void appendToIndex(final List<String> smiles, final URI uri) throws FileNotFoundException {