001package systems.dmx.workspaces.migrations; 002 003import systems.dmx.workspaces.WorkspacesService; 004 005import systems.dmx.core.AssociationDefinition; 006import systems.dmx.core.AssociationType; 007import systems.dmx.core.DMXObject; 008import systems.dmx.core.DMXType; 009import systems.dmx.core.Topic; 010import systems.dmx.core.TopicType; 011import systems.dmx.core.service.Inject; 012import systems.dmx.core.service.Migration; 013 014import java.util.logging.Logger; 015 016 017 018/** 019 * Assigns standard association definitions (and their view config topics) to DMX workspace. 020 * Runs only in UPDATE mode. 021 * <p> 022 * Part of DM 4.6 023 */ 024public class Migration6 extends Migration { 025 026 // ---------------------------------------------------------------------------------------------- Instance Variables 027 028 @Inject 029 private WorkspacesService wsService; 030 031 private long dmxWorkspaceId; 032 033 private long types = 0, standardTypes = 0, assocDefs = 0, configTopics = 0; 034 035 private Logger logger = Logger.getLogger(getClass().getName()); 036 037 // -------------------------------------------------------------------------------------------------- Public Methods 038 039 @Override 040 public void run() { 041 logger.info("########## Assigning standard association definitions (and their view config topics) to " + 042 "DMX workspace"); 043 dmxWorkspaceId = getDMXWorkspace().getId(); 044 // 045 for (TopicType topicType : dmx.getAllTopicTypes()) { 046 assignWorkspace(topicType); 047 } 048 for (AssociationType assocType : dmx.getAllAssociationTypes()) { 049 assignWorkspace(assocType); 050 } 051 // 052 logger.info("########## Assigning standard association definitions (and their view config topics) to " + 053 "DMX workspace complete\n Types processed: " + types + "\n Standard types: " + 054 standardTypes + "\n Association definitions: " + assocDefs + "\n View config topics: " + 055 configTopics); 056 } 057 058 // ------------------------------------------------------------------------------------------------- Private Methods 059 060 private void assignWorkspace(DMXType type) { 061 types++; 062 if (isDMXStandardType(type)) { 063 standardTypes++; 064 for (AssociationDefinition assocDef : type.getAssocDefs()) { 065 assocDefs++; 066 assignToDMXWorkspace(assocDef); 067 for (Topic configTopic : assocDef.getViewConfig().getConfigTopics()) { 068 configTopics++; 069 assignToDMXWorkspace(configTopic); 070 } 071 } 072 } 073 } 074 075 private void assignToDMXWorkspace(DMXObject object) { 076 wsService.assignToWorkspace(object, dmxWorkspaceId); 077 } 078 079 // ### copy in WorkspacesPlugin.java 080 private Topic getDMXWorkspace() { 081 return wsService.getWorkspace(WorkspacesService.DMX_WORKSPACE_URI); 082 } 083 084 // ### copy in WorkspacesPlugin.java 085 private boolean isDMXStandardType(DMXType type) { 086 return type.getUri().startsWith("dmx."); 087 } 088}