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 Migration13 extends Migration {
016
017 private static Logger log = Logger.getLogger(Migration12.class.getName());
018
019 @SuppressWarnings("serial")
020 @Override
021 public void run() {
022
023 // get criteria topics
024 final Map<String, Long> projects = getIdsByValue(dms, PROJECT);
025 final Map<String, Long> years = getIdsByValue(dms, YEAR);
026 final Map<String, Long> affiliations = getIdsByValue(dms, AFFILIATION);
027 final Map<String, Long> publics = getIdsByValue(dms, PUBLIC);
028
029 // define mapping
030 Map<String, Map<String, Long>> MAP = new HashMap<String, Map<String, Long>>();
031 MAP.put("Mitstreiter10", new HashMap<String, Long>() {
032 {
033 put(PROJECT, projects.get("Poesiefrühling"));
034 put(YEAR, years.get("2010"));
035 put(AFFILIATION, affiliations.get("Mitstreiter"));
036 }
037 });
038 MAP.put("Mitstreiter11", new HashMap<String, Long>() {
039 {
040 put(PROJECT, projects.get("Poesiefrühling"));
041 put(YEAR, years.get("2011"));
042 put(AFFILIATION, affiliations.get("Mitstreiter"));
043 }
044 });
045 MAP.put("Mitstreiter 12", new HashMap<String, Long>() {
046 {
047 put(PROJECT, projects.get("Poesiefrühling"));
048 put(YEAR, years.get("2012"));
049 put(AFFILIATION, affiliations.get("Mitstreiter"));
050 }
051 });
052 MAP.put("Printemps des Poètes Berlin09", new HashMap<String, Long>() {
053 {
054 put(PROJECT, projects.get("Poesiefrühling"));
055 put(YEAR, years.get("2009"));
056 }
057 });
058 MAP.put("Printemps des Poètes, Berlin10", new HashMap<String, Long>() {
059 {
060 put(PROJECT, projects.get("Poesiefrühling"));
061 put(YEAR, years.get("2010"));
062 }
063 });
064 MAP.put("Poesiefrühling-2011", new HashMap<String, Long>() {
065 {
066 put(PROJECT, projects.get("Poesiefrühling"));
067 put(YEAR, years.get("2011"));
068 }
069 });
070 MAP.put("Poesiefrühling 2012", new HashMap<String, Long>() {
071 {
072 put(PROJECT, projects.get("Poesiefrühling"));
073 put(YEAR, years.get("2012"));
074 }
075 });
076
077 MAP.put("MeisterInnen12", new HashMap<String, Long>() {
078 {
079 put(PROJECT, projects.get("Meister"));
080 put(YEAR, years.get("2012"));
081 }
082 });
083 MAP.put("MeisterInnen13", new HashMap<String, Long>() {
084 {
085 put(PROJECT, projects.get("Meister"));
086 put(YEAR, years.get("2013"));
087 }
088 });
089
090 MAP.put("wortwedding", new HashMap<String, Long>() {
091 {
092 put(PROJECT, projects.get("wortwedding"));
093 put(AFFILIATION, affiliations.get("Publikum"));
094 }
095 });
096
097 MAP.put("Poem Space Mobil", new HashMap<String, Long>() {
098 {
099 put(PROJECT, projects.get("Poem Space Mobil"));
100 }
101 });
102
103 MAP.put("Stiftungen", new HashMap<String, Long>() {
104 {
105 put(AFFILIATION, affiliations.get("Förderer"));
106 }
107 });
108 MAP.put("Blogs", new HashMap<String, Long>() {
109 {
110 put(PUBLIC, publics.get("Webseite"));
111 }
112 });
113
114 for (Topic list : dms.getTopics(LIST, false, 0)) {
115 String listName = list.getSimpleValue().toString();
116 log.info("reassign members of list " + listName);
117 Map<String, Long> criteria = MAP.get(listName);
118 if (criteria != null) {
119 // map composite value
120 CompositeValueModel valueUpdate = new CompositeValueModel();
121 for (String uri : criteria.keySet()) {
122 valueUpdate.addRef(uri, criteria.get(uri));
123 }
124
125 // update all related contacts
126 for (String contactTypeUri : CONTACT_URIS) {
127 TopicModel model = new TopicModel(contactTypeUri);
128 model.setCompositeValue(valueUpdate);
129 for (RelatedTopic contact : list.getRelatedTopics("dm4.core.association", //
130 null, null, contactTypeUri, false, false, 0)) {
131 log.info("update " + listName + " contact " + contact.getSimpleValue());
132 model.setId(contact.getId());
133 dms.updateTopic(model, null);
134 }
135 }
136
137 // delete distribution list
138 dms.deleteTopic(list.getId());
139 }
140 }
141 }
142 }