# HG changeset patch # User Robert Casties # Date 1562650250 -7200 # Node ID bdd1c3fc0897557137377a66a3082e78f637db71 # Parent 742347ef84109647379042d6aecd95c0c5cad225 Much faster DivaImportHttp that puts all entities in a Map first. Also uses ownValue instead of name attribute. diff -r 742347ef8410 -r bdd1c3fc0897 src/main/java/org/mpi/openmind/scripts/DivaImportHttp.java --- a/src/main/java/org/mpi/openmind/scripts/DivaImportHttp.java Mon Jul 08 20:20:07 2019 +0200 +++ b/src/main/java/org/mpi/openmind/scripts/DivaImportHttp.java Tue Jul 09 07:30:50 2019 +0200 @@ -2,6 +2,7 @@ import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,7 +23,6 @@ import org.mpi.openmind.repository.bo.Entity; import org.mpi.openmind.repository.bo.Node; import org.mpi.openmind.repository.services.ServiceRegistry; -import org.mpi.openmind.repository.services.utils.AttributeFilter; /** @@ -83,21 +83,23 @@ // parse JSON directory index of manifest files JSONArray files = new JSONArray(jsonReader); int numFiles = files.length(); - List list = new ArrayList(); + // get all DIGITALIZATION entities + System.out.println("Loading all DIGITALIZATIONs"); + List digiList = omService.getEntitiesByDef(DIGITALIZATION); + // unpack in Map by name/ownValue + Map digiMap = new HashMap(digiList.size()); + for (Entity digi : digiList) { + String name = digi.getOwnValue(); + digiMap.put(name, digi); + } + List saveList = new ArrayList(); // go through all filenames in the list for (int i = 0; i < numFiles; ++i) { JSONObject file = files.getJSONObject(i); String filename = file.getString("name"); System.out.println("check: "+filename); - // create filter to search OpenMind String digiName = filename.replace(".json", ""); - List filters = new ArrayList(); - AttributeFilter filter = new AttributeFilter("name", digiName, "DIGITALIZATION"); - filter.setExactMatch(true); - filters.add(filter); - // get matching DIGITALIZATIONs - Map res = omService.searchEntityByAttributeFilter(filters, -1); - if (res.size() > 0) { + if (digiMap.containsKey(digiName)) { //System.out.println(" exists: "+res); } else { // no existing DIGITALIZATION - create new Entity @@ -107,15 +109,15 @@ digi.addAttribute(new Attribute("name", "text", filename)); digi.addAttribute(new Attribute("num_files", "text", "100")); // add to list - list.add(digi); + saveList.add(digi); } } // ensure http entity is fully consumed EntityUtils.consume(htent); // persist OpenMind entities - omService.saveEntityList(list, userName); + omService.saveEntityList(saveList, userName); System.out.println("Found " + numFiles + " manifests"); - System.out.println("Created " + list.size() + " DIGITALIZATIONs"); + System.out.println("Created " + saveList.size() + " DIGITALIZATIONs"); System.out.println("END"); } finally {