All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.flowable.engine.migration.ActivityMigrationMapping Maven / Gradle / Ivy

There is a newer version: 7.0.1
Show newest version
/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.flowable.engine.migration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Dennis
 */
public abstract class ActivityMigrationMapping {

    protected String toCallActivityId;
    protected Integer callActivityProcessDefinitionVersion;
    protected String fromCallActivityId;

    public abstract List getFromActivityIds();

    public abstract List getToActivityIds();

    public boolean isToParentProcess() {
        return this.fromCallActivityId != null;
    }

    public boolean isToCallActivity() {
        return this.toCallActivityId != null;
    }

    public String getToCallActivityId() {
        return toCallActivityId;
    }

    public Integer getCallActivityProcessDefinitionVersion() {
        return callActivityProcessDefinitionVersion;
    }

    public String getFromCallActivityId() {
        return fromCallActivityId;
    }

    public static ActivityMigrationMapping.OneToOneMapping createMappingFor(String fromActivityId, String toActivityId) {
        return new OneToOneMapping(fromActivityId, toActivityId);
    }

    public static ActivityMigrationMapping.OneToManyMapping createMappingFor(String fromActivityId, List toActivityIds) {
        return new OneToManyMapping(fromActivityId, toActivityIds);
    }

    public static ActivityMigrationMapping.ManyToOneMapping createMappingFor(List fromActivityIds, String toActivityId) {
        return new ManyToOneMapping(fromActivityIds, toActivityId);
    }

    public static class OneToOneMapping extends ActivityMigrationMapping implements ActivityMigrationMappingOptions.SingleToActivityOptions {

        public String fromActivityId;
        public String toActivityId;
        protected String withNewAssignee;
        protected Map withLocalVariables = new LinkedHashMap<>();

        public OneToOneMapping(String fromActivityId, String toActivityId) {
            this.fromActivityId = fromActivityId;
            this.toActivityId = toActivityId;
        }

        @Override
        public List getFromActivityIds() {
            ArrayList list = new ArrayList<>();
            list.add(fromActivityId);
            return list;
        }

        @Override
        public List getToActivityIds() {
            ArrayList list = new ArrayList<>();
            list.add(toActivityId);
            return list;
        }

        public String getFromActivityId() {
            return fromActivityId;
        }

        public String getToActivityId() {
            return toActivityId;
        }

        @Override
        public OneToOneMapping inParentProcessOfCallActivityId(String fromCallActivityId) {
            this.fromCallActivityId = fromCallActivityId;
            this.toCallActivityId = null;
            this.callActivityProcessDefinitionVersion = null;
            return this;
        }

        @Override
        public OneToOneMapping inSubProcessOfCallActivityId(String toCallActivityId) {
            this.toCallActivityId = toCallActivityId;
            this.callActivityProcessDefinitionVersion = null;
            this.fromCallActivityId = null;
            return this;
        }

        @Override
        public OneToOneMapping inSubProcessOfCallActivityId(String toCallActivityId, int subProcessDefVersion) {
            this.toCallActivityId = toCallActivityId;
            this.callActivityProcessDefinitionVersion = subProcessDefVersion;
            this.fromCallActivityId = null;
            return this;
        }

        @Override
        public OneToOneMapping withNewAssignee(String newAssigneeId) {
            this.withNewAssignee = newAssigneeId;
            return this;
        }

        @Override
        public String getWithNewAssignee() {
            return withNewAssignee;
        }

        @Override
        public OneToOneMapping withLocalVariable(String variableName, Object variableValue) {
            withLocalVariables.put(variableName, variableValue);
            return this;
        }

        @Override
        public OneToOneMapping withLocalVariables(Map variables) {
            withLocalVariables.putAll(variables);
            return this;
        }

        @Override
        public Map getActivityLocalVariables() {
            return withLocalVariables;
        }

        @Override
        public String toString() {
            return "OneToOneMapping{" + "fromActivityId='" + fromActivityId + '\'' + ", toActivityId='" + toActivityId + '\'' + '}';
        }
    }

    public static class OneToManyMapping extends ActivityMigrationMapping implements ActivityMigrationMappingOptions.MultipleToActivityOptions {

        public String fromActivityId;
        public List toActivityIds;
        protected Map> withLocalVariables = new LinkedHashMap<>();

        public OneToManyMapping(String fromActivityId, List toActivityIds) {
            this.fromActivityId = fromActivityId;
            this.toActivityIds = toActivityIds;
        }

        @Override
        public List getFromActivityIds() {
            ArrayList list = new ArrayList<>();
            list.add(fromActivityId);
            return list;
        }

        @Override
        public List getToActivityIds() {
            return new ArrayList<>(toActivityIds);
        }

        public String getFromActivityId() {
            return fromActivityId;
        }

        @Override
        public OneToManyMapping inParentProcessOfCallActivityId(String fromCallActivityId) {
            this.fromCallActivityId = fromCallActivityId;
            this.toCallActivityId = null;
            this.callActivityProcessDefinitionVersion = null;
            return this;
        }

        @Override
        public OneToManyMapping inSubProcessOfCallActivityId(String toCallActivityId) {
            this.toCallActivityId = toCallActivityId;
            this.callActivityProcessDefinitionVersion = null;
            this.fromCallActivityId = null;
            return this;
        }

        @Override
        public OneToManyMapping inSubProcessOfCallActivityId(String toCallActivityId, int subProcessDefVersion) {
            this.toCallActivityId = toCallActivityId;
            this.callActivityProcessDefinitionVersion = subProcessDefVersion;
            this.fromCallActivityId = null;
            return this;
        }

        @Override
        public OneToManyMapping withLocalVariableForActivity(String toActivity, String variableName, Object variableValue) {
            Map activityVariables = withLocalVariables.computeIfAbsent(toActivity, key -> new HashMap<>());
            activityVariables.put(variableName, variableValue);
            return this;
        }

        @Override
        public OneToManyMapping withLocalVariablesForActivity(String toActivity, Map variables) {
            Map activityVariables = withLocalVariables.computeIfAbsent(toActivity, key -> new HashMap<>());
            activityVariables.putAll(variables);
            return this;
        }

        @Override
        public OneToManyMapping withLocalVariableForAllActivities(String variableName, Object variableValue) {
            toActivityIds.forEach(id -> withLocalVariableForActivity(id, variableName, variableValue));
            return this;
        }

        @Override
        public OneToManyMapping withLocalVariablesForAllActivities(Map variables) {
            toActivityIds.forEach(id -> withLocalVariablesForActivity(id, variables));
            return this;
        }

        @Override
        public OneToManyMapping withLocalVariables(Map> mappingVariables) {
            withLocalVariables.putAll(mappingVariables);
            return this;
        }

        @Override
        public Map> getActivitiesLocalVariables() {
            return withLocalVariables;
        }

        @Override
        public String toString() {
            return "OneToManyMapping{" + "fromActivityId='" + fromActivityId + '\'' + ", toActivityIds=" + toActivityIds + '}';
        }
    }

    public static class ManyToOneMapping extends ActivityMigrationMapping implements ActivityMigrationMappingOptions.SingleToActivityOptions {

        public List fromActivityIds;
        public String toActivityId;
        protected String withNewAssignee;
        protected Map withLocalVariables = new LinkedHashMap<>();

        public ManyToOneMapping(List fromActivityIds, String toActivityId) {
            this.fromActivityIds = fromActivityIds;
            this.toActivityId = toActivityId;
        }

        @Override
        public List getFromActivityIds() {
            return new ArrayList<>(fromActivityIds);
        }

        @Override
        public List getToActivityIds() {
            ArrayList list = new ArrayList<>();
            list.add(toActivityId);
            return list;
        }

        public String getToActivityId() {
            return toActivityId;
        }

        @Override
        public ManyToOneMapping inParentProcessOfCallActivityId(String fromCallActivityId) {
            this.fromCallActivityId = fromCallActivityId;
            this.toCallActivityId = null;
            this.callActivityProcessDefinitionVersion = null;
            return this;
        }

        @Override
        public ManyToOneMapping inSubProcessOfCallActivityId(String toCallActivityId) {
            this.toCallActivityId = toCallActivityId;
            this.callActivityProcessDefinitionVersion = null;
            this.fromCallActivityId = null;
            return this;
        }

        @Override
        public ManyToOneMapping inSubProcessOfCallActivityId(String toCallActivityId, int subProcessDefVersion) {
            this.toCallActivityId = toCallActivityId;
            this.callActivityProcessDefinitionVersion = subProcessDefVersion;
            this.fromCallActivityId = null;
            return this;
        }

        @Override
        public ManyToOneMapping withNewAssignee(String newAssigneeId) {
            this.withNewAssignee = newAssigneeId;
            return this;
        }

        @Override
        public String getWithNewAssignee() {
            return withNewAssignee;
        }

        @Override
        public ManyToOneMapping withLocalVariable(String variableName, Object variableValue) {
            withLocalVariables.put(variableName, variableValue);
            return this;
        }

        @Override
        public ManyToOneMapping withLocalVariables(Map variables) {
            withLocalVariables.putAll(variables);
            return this;
        }

        @Override
        public Map getActivityLocalVariables() {
            return withLocalVariables;
        }

        @Override
        public String toString() {
            return "ManyToOneMapping{" + "fromActivityIds=" + fromActivityIds + ", toActivityId='" + toActivityId + '\'' + '}';
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy