sortindex updater utilities
authorKatja Luther <k.luther@bgbm.org>
Tue, 19 Jul 2016 12:05:15 +0000 (14:05 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 19 Jul 2016 12:15:58 +0000 (14:15 +0200)
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SortIndexUpdaterConfigurator.java [new file with mode: 0755]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SortIndexUpdaterWrapper.java [new file with mode: 0755]

diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SortIndexUpdaterConfigurator.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SortIndexUpdaterConfigurator.java
new file mode 100755 (executable)
index 0000000..049cc0b
--- /dev/null
@@ -0,0 +1,123 @@
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.io.common;
+
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.model.reference.Reference;
+
+/**
+ * @author k.luther
+ * @date 08.07.2016
+ *
+ */
+public class SortIndexUpdaterConfigurator extends ImportConfiguratorBase<DefaultImportState<SortIndexUpdaterConfigurator>, Object> implements IImportConfigurator{
+
+
+    private boolean doTaxonNode = true;
+    private boolean doFeatureNode = true;
+    private boolean doPolytomousKeyNode = true;
+
+    private SortIndexUpdaterConfigurator(ICdmDataSource destination){
+        super(null);
+        this.setDestination(destination);
+    }
+
+    /**
+     * @param destination
+     * @return
+     */
+    public static SortIndexUpdaterConfigurator NewInstance(ICdmDataSource destination) {
+        SortIndexUpdaterConfigurator result = new SortIndexUpdaterConfigurator(destination);
+        return result;
+    }
+
+    /**
+     * @param destination
+     * @return
+     */
+    public static SortIndexUpdaterConfigurator NewInstance(ICdmDataSource destination, boolean doTaxonNode, boolean doFeatureNode, boolean doPolytomousKeyNode) {
+        SortIndexUpdaterConfigurator result = new SortIndexUpdaterConfigurator(destination);
+        result.doFeatureNode = doFeatureNode;
+        result.doTaxonNode = doTaxonNode;
+        result.doPolytomousKeyNode = doPolytomousKeyNode;
+        return result;
+    }
+
+
+ // **************** GETTER / SETTER ************************************
+
+
+    /**
+     * @return the doTaxonNode
+     */
+    public boolean isDoTaxonNode() {
+        return doTaxonNode;
+    }
+    /**
+     * @param doTaxonNode the doTaxonNode to set
+     */
+    public void setDoTaxonNode(boolean doTaxonNode) {
+        this.doTaxonNode = doTaxonNode;
+    }
+    /**
+     * @return the doPolytomousKeyNode
+     */
+    public boolean isDoPolytomousKeyNode() {
+        return doPolytomousKeyNode;
+    }
+    /**
+     * @param doPolytomousKeyNode the doPolytomousKeyNode to set
+     */
+    public void setDoPolytomousKeyNode(boolean doPolytomousKeyNode) {
+        this.doPolytomousKeyNode = doPolytomousKeyNode;
+    }
+    /**
+     * @return the doFeatureNode
+     */
+    public boolean isDoFeatureNode() {
+        return doFeatureNode;
+    }
+    /**
+     * @param doFeatureNode the doFeatureNode to set
+     */
+    public void setDoFeatureNode(boolean doFeatureNode) {
+        this.doFeatureNode = doFeatureNode;
+    }
+
+    @Override
+    public <STATE extends ImportStateBase> STATE getNewState() {
+        return (STATE) new DefaultImportState(this);
+    }
+
+
+    @Override
+    protected void makeIoClassList() {
+        ioClassList = new Class[]{
+                     SortIndexUpdaterWrapper.class
+        };
+
+
+    }
+
+
+    @Override
+    public Reference getSourceReference() {
+        return null;
+    }
+
+
+    @Override
+    public boolean isValid() {
+        //as no source needs to exist
+        return true;
+    }
+
+
+}
diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SortIndexUpdaterWrapper.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/SortIndexUpdaterWrapper.java
new file mode 100755 (executable)
index 0000000..52ff33a
--- /dev/null
@@ -0,0 +1,94 @@
+// $Id$
+/**
+* Copyright (C) 2016 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.io.common;
+
+import java.sql.SQLException;
+
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
+import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.database.update.CaseType;
+import eu.etaxonomy.cdm.database.update.SortIndexUpdater;
+
+/**
+ * @author k.luther
+ * @date 08.07.2016
+ *
+ */
+@Component
+public class SortIndexUpdaterWrapper extends CdmImportBase<SortIndexUpdaterConfigurator, DefaultImportState<SortIndexUpdaterConfigurator>> {
+
+    private static final long serialVersionUID = 1152526455024556637L;
+    private static final Logger logger = Logger.getLogger(SortIndexUpdaterWrapper.class);
+
+
+    @Override
+    protected void doInvoke(DefaultImportState<SortIndexUpdaterConfigurator> state) {
+        SortIndexUpdaterConfigurator config = state.getConfig();
+        SortIndexUpdater updater;
+        ICdmDataSource source = config.getDestination();
+        CaseType caseType = CaseType.caseTypeOfDatasource(config.getDestination());
+        IProgressMonitor  monitor = DefaultProgressMonitor.NewInstance();
+        if (config.isDoTaxonNode()){
+            updater = SortIndexUpdater.NewInstance("Update taxonnode sortindex", "TaxonNode", "parent_id", "sortIndex", true);
+            try {
+                source.startTransaction();
+                updater.invoke(config.getDestination(), monitor, caseType);
+                source.commitTransaction();
+            } catch (SQLException e) {
+
+                monitor.warning("Stopped sortIndex updater");
+            }
+        }
+        if (config.isDoFeatureNode()){
+            updater = SortIndexUpdater.NewInstance("Update Feature node sortindex", "FeatureNode", "parent_id", "sortIndex", true);
+            try {
+                source.startTransaction();
+                updater.invoke(config.getDestination(), monitor, caseType);
+                source.commitTransaction();
+            } catch (SQLException e) {
+
+                monitor.warning("Stopped sortIndex updater");
+            }
+        }
+        if (config.isDoPolytomousKeyNode()){
+            updater = SortIndexUpdater.NewInstance("Update Polytomouskey node sortindex", "PolytomousKeyNode", "parent_id", "sortindex", true);
+            try {
+                source.startTransaction();
+                updater.invoke(config.getDestination(), monitor, caseType);
+                source.commitTransaction();
+            } catch (SQLException e) {
+
+                monitor.warning("Stopped sortIndex updater");
+            }
+        }
+        return;
+
+    }
+
+
+
+
+    @Override
+    protected boolean doCheck(DefaultImportState<SortIndexUpdaterConfigurator> state) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    protected boolean isIgnore(DefaultImportState<SortIndexUpdaterConfigurator> state) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+}