001    package de.deepamehta.plugins.tags.migrations;
002    
003    import de.deepamehta.core.Topic;
004    import de.deepamehta.core.TopicType;
005    import de.deepamehta.core.model.SimpleValue;
006    import de.deepamehta.core.model.TopicRoleModel;
007    import de.deepamehta.core.model.AssociationModel;
008    import de.deepamehta.core.service.Migration;
009    
010    import java.util.logging.Logger;
011    
012    public class Migration3 extends Migration {
013    
014        private Logger logger = Logger.getLogger(getClass().getName());
015    
016        private String TAG_URI = "dm4.tags.tag";
017        private String TAG_LABEL_URI = "dm4.tags.label";
018        private String TAG_DEFINITION_URI = "dm4.tags.definition";
019    
020        private String WS_DEFAULT_URI = "de.workspaces.deepamehta";
021    
022        @Override
023        public void run() {
024    
025            TopicType tagType = dms.getTopicType(TAG_URI);
026            TopicType tagLabelType = dms.getTopicType(TAG_LABEL_URI);
027            TopicType tagDefinitionType = dms.getTopicType(TAG_DEFINITION_URI);
028            //
029            assignWorkspace(tagType);
030            assignWorkspace(tagLabelType);
031            assignWorkspace(tagDefinitionType);
032    
033        }
034    
035        // === Workspace ===
036    
037        /** Assign types to default workspace in any case. */
038    
039        private void assignWorkspace(Topic topic) {
040            Topic defaultWorkspace = dms.getTopic("uri", new SimpleValue(WS_DEFAULT_URI));
041            dms.createAssociation(new AssociationModel("dm4.core.aggregation",
042                new TopicRoleModel(topic.getId(), "dm4.core.parent_type"),
043                new TopicRoleModel(defaultWorkspace.getId(), "dm4.core.child_type")
044            ));
045        }
046    
047    }