001 package com.poemspace.dm4.migrations;
002
003 import static com.poemspace.dm4.MigrationUtils.*;
004
005 import java.util.HashMap;
006 import java.util.Map;
007 import java.util.logging.Logger;
008
009 import de.deepamehta.core.RelatedTopic;
010 import de.deepamehta.core.Topic;
011 import de.deepamehta.core.model.CompositeValueModel;
012 import de.deepamehta.core.model.TopicModel;
013 import de.deepamehta.core.service.Migration;
014
015 public class Migration14 extends Migration {
016
017 private static Logger log = Logger.getLogger(Migration13.class.getName());
018
019 @SuppressWarnings("serial")
020 @Override
021 public void run() {
022
023 // get criteria topics
024 final Map<String, Long> art = getIdsByValue(dms, ART);
025 final Map<String, Long> press = getIdsByValue(dms, PRESS);
026
027 // define mapping
028 Map<String, Map<String, Long>> MAP = new HashMap<String, Map<String, Long>>();
029 MAP.put("Jugendclub", new HashMap<String, Long>() {
030 {
031 put(ART, art.get("Kinder- und Jugendeinrichtung"));
032 }
033 });
034 MAP.put("Kinderclub", new HashMap<String, Long>() {
035 {
036 put(ART, art.get("Kinder- und Jugendeinrichtung"));
037 }
038 });
039 MAP.put("Café", new HashMap<String, Long>() {
040 {
041 put(ART, art.get("Café/Restaurant"));
042 }
043 });
044 MAP.put("Restaurant", new HashMap<String, Long>() {
045 {
046 put(ART, art.get("Café/Restaurant"));
047 }
048 });
049
050 MAP.put("Radio", new HashMap<String, Long>() {
051 {
052 put(PRESS, press.get("Radio"));
053 }
054 });
055 MAP.put("Radio regional", new HashMap<String, Long>() {
056 {
057 put(PRESS, press.get("Radio"));
058 put(PRESS, press.get("regional"));
059 }
060 });
061 MAP.put("Radio Überregional", new HashMap<String, Long>() {
062 {
063 put(PRESS, press.get("Radio"));
064 put(PRESS, press.get("überregional"));
065 }
066 });
067
068 MAP.put("Zeitschrift", new HashMap<String, Long>() {
069 {
070 put(PRESS, press.get("Print"));
071 }
072 });
073 MAP.put("regionale Printmedien", new HashMap<String, Long>() {
074 {
075 put(PRESS, press.get("Print"));
076 put(PRESS, press.get("regional"));
077 }
078 });
079 MAP.put("Überregionale Print", new HashMap<String, Long>() {
080 {
081 put(PRESS, press.get("Print"));
082 put(PRESS, press.get("überregional"));
083 }
084 });
085
086 MAP.put("TV", new HashMap<String, Long>() {
087 {
088 put(PRESS, press.get("Fernsehen"));
089 }
090 });
091 MAP.put("Websites", new HashMap<String, Long>() {
092 {
093 put(PRESS, press.get("Web"));
094 }
095 });
096
097 for (Topic criterion : dms.getTopics(ART, false, 0)) {
098 String criterionName = criterion.getSimpleValue().toString();
099 log.info("reassign members of art criterion " + criterionName);
100 Map<String, Long> criteria = MAP.get(criterionName);
101 if (criteria != null) {
102 // map composite value
103 CompositeValueModel valueUpdate = new CompositeValueModel();
104 for (String uri : criteria.keySet()) {
105 valueUpdate.addRef(uri, criteria.get(uri));
106 }
107
108 // update all related contacts
109 for (String contactTypeUri : CONTACT_URIS) {
110 TopicModel model = new TopicModel(contactTypeUri);
111 model.setCompositeValue(valueUpdate);
112 for (RelatedTopic contact : criterion.getRelatedTopics("dm4.core.aggregation", //
113 "dm4.core.child", "dm4.core.parent", contactTypeUri, false, false, 0)) {
114 log.info("update " + criterionName + " contact " + contact.getSimpleValue());
115 model.setId(contact.getId());
116 dms.updateTopic(model, null);
117 }
118 }
119
120 // delete distribution list
121 dms.deleteTopic(criterion.getId());
122 }
123 }
124 }
125
126 }