changeset 90:4b6c0b368f46

new UpdateMpiwgDigitalizations script.
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Tue, 29 May 2018 21:15:06 +0200
parents 8adfa8679991
children fa7b1058b776
files src/main/java/org/mpi/openmind/scripts/StabiCollection.java src/main/java/org/mpi/openmind/scripts/UpdateMpiwgDigitalizations.java
diffstat 2 files changed, 114 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/mpi/openmind/scripts/StabiCollection.java	Mon Feb 26 14:39:49 2018 +0100
+++ b/src/main/java/org/mpi/openmind/scripts/StabiCollection.java	Tue May 29 21:15:06 2018 +0200
@@ -3,7 +3,6 @@
 import java.io.BufferedReader;
 import java.io.FileReader;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/org/mpi/openmind/scripts/UpdateMpiwgDigitalizations.java	Tue May 29 21:15:06 2018 +0200
@@ -0,0 +1,114 @@
+package org.mpi.openmind.scripts;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.mpi.openmind.cache.WrapperService;
+import org.mpi.openmind.repository.bo.Attribute;
+import org.mpi.openmind.repository.bo.Entity;
+import org.mpi.openmind.repository.services.ServiceRegistry;
+import org.mpi.openmind.repository.services.utils.AttributeFilter;
+
+/**
+ * Reads a CSV file with McGill scan directory names (DIGITALIZATION name),
+ * MPIWG library directory names and access information ("free", or other)
+ * and updates DIGITALIZATION objects with matching public_manifest_url 
+ * Attribute.
+ *  
+ * @author casties
+ *
+ */
+public class UpdateMpiwgDigitalizations {
+
+	public static String file = "mcgill-mpiwg-mapping.csv";
+	
+	public static final String PUB_URL_ATT_NAME = "public_manifest_url";
+	
+	public static void execute(WrapperService ws) throws Exception {
+		
+		System.out.println("Update MPIWG information in DIGITALIZATIONs");
+		
+		for (String line : getLinesFromFile()) {
+		    String[] fields = line.split(",");
+		    if (fields.length < 3) {
+		        System.out.println("ERROR: empty line: " +  line);
+		        continue;
+		    }
+		    String mcgillDir = fields[0];
+		    String mpiwgDir = fields[1];
+		    String access = fields[2];
+		    // find DIGITALIZATION
+			List<AttributeFilter> filterList = new ArrayList<AttributeFilter>();
+			filterList.add(new AttributeFilter("name", mcgillDir, "DIGITALIZATION"));
+			Map<Entity, Attribute> resultMap = ws.searchEntityByAttributeFilter(filterList, 1);
+			Entity digi = resultMap.keySet().iterator().next();
+			/*
+			// find CODEX
+			List<Entity> tmp = ws.getTargetsForSourceRelation(digi, "is_digitalization_of", "CODEX", 1);
+			Entity codex = tmp.get(0);
+			//System.out.println(codex.getId() + "\t" +  digi.getId());
+			//System.out.println("codexIdList.add(new Long("+ codex.getId() +"));");
+			System.out.print(codex.getId() + ",");
+			*/
+            // update DIGITALIZATION
+            if (digi != null) {
+                ws.getEntityContent(digi);
+                String pubUrl = null;
+                String privUrl = null;
+                // set public url
+                if (access.equalsIgnoreCase("free")) {
+                    pubUrl = "https://digilib.mpiwg-berlin.mpg.de/digitallibrary/Manifester/IIIF/permanent!library!"
+                            + mpiwgDir + "!pageimg";
+                    System.out.println("INFO: set " + PUB_URL_ATT_NAME + " of " + mcgillDir + " to " + pubUrl);
+                    Attribute pubUrlAtt = digi.getAttributeByName(PUB_URL_ATT_NAME);
+                    if (pubUrlAtt == null) {
+                        pubUrlAtt = new Attribute(PUB_URL_ATT_NAME, "text", pubUrl);
+                        digi.addAttribute(pubUrlAtt);
+                    } else {
+                        pubUrlAtt.setValue(pubUrl);
+                    }
+                }
+                // save
+                ws.saveEntity(digi, "update-mpiwg-digitalizations", null);
+
+            } else {
+                System.out.println("WARNING: entity not found: " + mcgillDir);
+            }
+        }
+		
+	}
+	
+	public static List<String> getLinesFromFile(){
+		List<String> rs = new ArrayList<String>();
+		
+		try (FileReader a = new FileReader(file);
+		        BufferedReader br = new BufferedReader(a);) {
+	        String line;
+	        line = br.readLine();
+
+	        while((line = br.readLine()) != null) {
+	        	rs.add(line);
+	        }			
+	        
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		
+		return rs;
+	}
+	
+	
+	public static void main(String[] args) throws Exception {
+	    if (args.length > 0) {
+	        file = args[0];
+	    }
+		ServiceRegistry sr = new ServiceRegistry();
+		execute(sr.getWrapper());
+		
+		System.exit(0);
+	}
+
+}