001package systems.dmx.core.migrations;
002
003import systems.dmx.core.Association;
004import systems.dmx.core.ChildTopics;
005import systems.dmx.core.Topic;
006import systems.dmx.core.service.Migration;
007
008import java.util.List;
009import java.util.logging.Logger;
010
011
012
013/**
014 * Repairing assoc defs with missing "Include in Label" topic.
015 * Runs only in UPDATE mode.
016 * <p>
017 * Part of DM 4.8.6
018 */
019public class Migration7 extends Migration {
020
021    private int[][] count = new int[2][2];
022
023    private Logger logger = Logger.getLogger(getClass().getName());
024
025    @Override
026    public void run() {
027        logger.info("########## Repairing assoc defs with missing \"Include in Label\" topic");
028        //
029        // - Must repair the label config of the types ("comp def" and "aggr def") BEFORE the instances can be repaired
030        // - Must repair "aggr def" BEFORE "comp def"
031        dmx.getAssociationType("dmx.core.aggregation_def").getAssocDef("dmx.core.assoc_type#dmx.core.custom_assoc_type")
032            .getChildTopics().set("dmx.core.include_in_label", false);
033        dmx.getAssociationType("dmx.core.composition_def").getAssocDef("dmx.core.assoc_type#dmx.core.custom_assoc_type")
034            .getChildTopics().set("dmx.core.include_in_label", false);
035        //
036        process(dmx.getAssociationsByType("dmx.core.composition_def"), 0);
037        process(dmx.getAssociationsByType("dmx.core.aggregation_def"), 1);
038        //
039        logger.info("########## Repairing assoc defs with missing \"Include in Label\" topic complete\n    " +
040            "Composition defs repaired: " + count[0][1] + "/" + count[0][0] + "\n    " +
041            "Aggregation defs repaired: " + count[1][1] + "/" + count[1][0]);
042    }
043
044    private void process(List<Association> assocs, int i) {
045        for (Association assoc : assocs) {
046            ChildTopics childs = assoc.getChildTopics();
047            Topic includeInLabel = childs.getTopicOrNull("dmx.core.include_in_label");
048            if (includeInLabel == null) {
049                childs.set("dmx.core.include_in_label", false);
050                count[i][1]++;
051            }
052            count[i][0]++;
053        }
054    }
055}