Mercurial > hg > openmind
view src/main/java/org/mpi/openmind/scripts/CodexOwnValueGenerator.java @ 90:4b6c0b368f46
new UpdateMpiwgDigitalizations script.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 29 May 2018 21:15:06 +0200 |
parents | 615d27dce9b3 |
children |
line wrap: on
line source
package org.mpi.openmind.scripts; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; 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.bo.Node; import org.mpi.openmind.repository.services.PersistenceService; import org.mpi.openmind.repository.services.ServiceRegistry; import org.mpi.openmind.repository.utils.OMUtils; public class CodexOwnValueGenerator { private static Logger logger = Logger.getLogger(CodexOwnValueGenerator.class); private WrapperService ot; private PersistenceService ss; public CodexOwnValueGenerator(WrapperService ot){ this.ot = ot; this.ss = ot.getPS(); } public void execute(){ try { logger.info("Starting CodexOwnValueGenerator"); List<Entity> codexList = ot.getLightweightAssertions("CODEX", null, -1); logger.info("Codices="+ codexList.size()); List<Node> dirtyEntities = new ArrayList<Node>(); int count = 0; int countCodicesNonCollection = 0; for(Entity codex : codexList){ Attribute codexIdAtt = ss.getAttributeByName(codex, "identifier"); if(codexIdAtt == null){ throw new Exception("identifier is null for " + codex); } String ov = new String(); List<Entity> list0 = this.ss.getTargetsForSourceRelation(codex, "is_part_of", "COLLECTION", 1); Entity collection; if(list0.size() > 0){ collection = list0.get(0); if(collection != null){ ov = collection.getOwnValue() + "_" + codexIdAtt.getValue(); }else{ ov = "empty_" + codexIdAtt.getValue(); countCodicesNonCollection++; } if(count % 100 == 0){ int size = codexList.size(); logger.info("* " + OMUtils.percentage(count, size) + " %"); } count++; codex.setOwnValue(ov); dirtyEntities.add(codex); } } ot.saveNodeListOnlyForScripts(dirtyEntities); logger.info("Summary"); logger.info("Codices without collection=" + countCodicesNonCollection); logger.info("Total=" + count); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { ServiceRegistry services = new ServiceRegistry(); CodexOwnValueGenerator script = new CodexOwnValueGenerator(services.getWrapper()); script.execute(); System.exit(0); } }