changeset 99:5380bdeb7457

add exactMatch option to Filter. use exactMatch in DivaImportHttp for digitalization names.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Tue, 30 Oct 2018 18:29:24 +0100
parents 452d02798054
children 734c0d8c7369
files src/main/java/org/mpi/openmind/repository/services/PersistenceService.java src/main/java/org/mpi/openmind/repository/services/utils/Filter.java src/main/java/org/mpi/openmind/scripts/DivaImportHttp.java
diffstat 3 files changed, 19 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/mpi/openmind/repository/services/PersistenceService.java	Wed Oct 17 18:44:59 2018 +0200
+++ b/src/main/java/org/mpi/openmind/repository/services/PersistenceService.java	Tue Oct 30 18:29:24 2018 +0100
@@ -1262,6 +1262,8 @@
                         hql += "att.normalizedOwnValue LIKE :ownValue" + count + " ";
                     } else if (filter.isRegex()) {
                         hql += "REGEXP(att.ownValue, :ownValue" + count + ") = 1 ";
+                    } else if (filter.isExactMatch()) {
+                        hql += "att.ownValue = :ownValue" + count + " ";
                     } else {
                         hql += "att.ownValue LIKE :ownValue" + count + " ";
                     }
@@ -1300,6 +1302,9 @@
                     if (filter.isRegex()) {
                         // ownValue rlike :ownValue
                         query.setString("ownValue" + count, filter.getOwnValue());
+                    } else if (filter.isExactMatch()) {
+                        // ownValue = :ownValue
+                        query.setString("ownValue" + count, filter.getOwnValue());
                     } else {
                         // ownValue like %:ownValue%
                         query.setString("ownValue" + count, "%" + filter.getOwnValue() + "%");
--- a/src/main/java/org/mpi/openmind/repository/services/utils/Filter.java	Wed Oct 17 18:44:59 2018 +0200
+++ b/src/main/java/org/mpi/openmind/repository/services/utils/Filter.java	Tue Oct 30 18:29:24 2018 +0100
@@ -1,16 +1,15 @@
 package org.mpi.openmind.repository.services.utils;
 
-import java.text.Normalizer;
-
 /**
  *
  * @author jurzua
  */
 public abstract class Filter {
 	
-    private String ownValue;
-    private boolean normalize = false;
+    protected String ownValue;
+    protected boolean normalize = false;
     protected boolean isRegex = false;
+    protected boolean exactMatch = false;
 
     public boolean isNormalize() {
         return normalize;
@@ -41,4 +40,12 @@
     public void setRegex(boolean isRegex) {
         this.isRegex = isRegex;
     }
+
+	public boolean isExactMatch() {
+		return exactMatch;
+	}
+
+	public void setExactMatch(boolean exactMatch) {
+		this.exactMatch = exactMatch;
+	}
 }
--- a/src/main/java/org/mpi/openmind/scripts/DivaImportHttp.java	Wed Oct 17 18:44:59 2018 +0200
+++ b/src/main/java/org/mpi/openmind/scripts/DivaImportHttp.java	Tue Oct 30 18:29:24 2018 +0100
@@ -59,72 +59,6 @@
 	}
 	
 	/**
-	 * Create and persist data model for DIGITALIZATION and the relation 
-	 * is_digitalization_of and the necessary attributes
-	 * for CODEX and WITNESS.
-	 * 
-	 * @param ontology
-	 */
-	private static void createDataModel(WrapperService ontology) {
-		
-		try {
-			
-			Entity digi = new Entity(Node.TYPE_TBOX, Node.TYPE_TBOX, false);
-			digi.setOwnValue(DIGITALIZATION);
-			
-			digi = ontology.saveLWDefinition(digi, userName);
-			
-			Attribute attName = new Attribute(Node.TYPE_TBOX, "text", "name");
-			attName.setSourceId(digi.getId());
-			attName.setSourceObjectClass(Node.TYPE_TBOX);
-			attName.setSourceModif(digi.getModificationTime());
-			attName.setSystemStatus(Node.SYS_STATUS_CURRENT_VERSION);
-			
-			ontology.saveDefAttribute(attName, userName);
-			
-			Attribute num_files = new Attribute(Node.TYPE_TBOX, "text", "num_files");
-			num_files.setSourceId(digi.getId());
-			num_files.setSourceObjectClass(Node.TYPE_TBOX);
-			num_files.setSourceModif(digi.getModificationTime());
-			num_files.setSystemStatus(Node.SYS_STATUS_CURRENT_VERSION);
-			
-			ontology.saveDefAttribute(num_files, userName);
-			
-			
-			//DIGI is_digitalization_of CODEX
-			Entity codex = ontology.getDefinition("CODEX");
-			Relation rel = new Relation(digi, codex, "is_digitalization_of");
-			
-			ontology.saveDefRelation(rel, userName);
-			
-			//-----------
-			Entity witness = ontology.getDefinition("WITNESS");
-			
-			Attribute end_page = new Attribute(Node.TYPE_TBOX, "text", "end_page");
-			end_page.setSourceId(witness.getId());
-			end_page.setSourceObjectClass(Node.TYPE_TBOX);
-			end_page.setSourceModif(witness.getModificationTime());
-			end_page.setSystemStatus(Node.SYS_STATUS_CURRENT_VERSION);
-			
-			ontology.saveDefAttribute(end_page, userName);
-			
-			Attribute start_page = new Attribute(Node.TYPE_TBOX, "text", "start_page");
-			start_page.setSourceId(witness.getId());
-			start_page.setSourceObjectClass(Node.TYPE_TBOX);
-			start_page.setSourceModif(witness.getModificationTime());
-			start_page.setSystemStatus(Node.SYS_STATUS_CURRENT_VERSION);
-			
-			ontology.saveDefAttribute(start_page, userName);
-			
-			
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		
-		
-	}
-	
-	/**
 	 * Downloads a list of Diva manifest files from the repository and checks if
 	 * each manifest has a corresponding DIGITALIZATION object. Creates missing
 	 * DIGITALIZATION objects.
@@ -157,7 +91,9 @@
                     System.out.println("check: "+dirName);
                     // create filter to search OpenMind
 		            List<AttributeFilter> filters = new ArrayList<AttributeFilter>();
-		            filters.add(new AttributeFilter("name", dirName, "DIGITALIZATION"));
+		            AttributeFilter filter = new AttributeFilter("name", dirName, "DIGITALIZATION");
+		            filter.setExactMatch(true);
+					filters.add(filter);
 		            // get matching DIGITALIZATIONs
                     Map<Entity, Attribute> res = omService.searchEntityByAttributeFilter(filters, -1);
                     if (res.size() > 0) {