Backend support for operation milestones with activities 07/135507/11
authorJvD_Ericsson <jeff.van.dam@est.tech>
Tue, 18 Jul 2023 10:35:18 +0000 (11:35 +0100)
committerMichael Morris <michael.morris@est.tech>
Fri, 22 Sep 2023 07:41:02 +0000 (07:41 +0000)
Issue-ID: SDC-4577
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: I6a8dab0e48da542424faa017a1dea384ebb2376f

21 files changed:
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaActivity.java [new file with mode: 0644]
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaLifecycleOperationDefinition.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMilestone.java [new file with mode: 0644]
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandlerTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java
catalog-be/src/test/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverterTest.java
catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml
catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml
catalog-be/src/test/resources/interfaceDefinition/interfaceDefinitionInvalidMilestone-tosca1.3.yaml [new file with mode: 0644]
catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/Operation.java
catalog-model/src/test/java/org/openecomp/sdc/be/model/OperationTest.java
common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ActivityDataDefinition.java [new file with mode: 0644]
common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/MilestoneDataDefinition.java [new file with mode: 0644]
common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/OperationDataDefinition.java
common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ActivityTypeEnum.java [new file with mode: 0644]
common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/JsonPresentationFields.java
common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/MilestoneTypeEnum.java [new file with mode: 0644]
common-be/src/main/java/org/openecomp/sdc/be/utils/TypeUtils.java

index 4e535eb..9f0adcf 100644 (file)
  *  SPDX-License-Identifier: Apache-2.0
  *  ============LICENSE_END=========================================================
  */
+
 package org.openecomp.sdc.be.components.impl;
 
 import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.QUOTE;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ACTIVITIES;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DESCRIPTION;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.IMPLEMENTATION;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.INPUTS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.MILESTONES;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NOTIFICATIONS;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.OPERATIONS;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIRED;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.STATUS;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TYPE;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.WORKFLOW;
 
 import com.google.gson.Gson;
 import fj.data.Either;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -45,9 +50,11 @@ import org.apache.commons.collections.MapUtils;
 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.ActivityDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
@@ -126,7 +133,8 @@ public class InterfaceDefinitionHandler {
         }
         final Map<String, InterfaceDefinition> interfaceDefinitionMap = interfaceDefinitionMapEither.left().value();
         final Optional<InterfaceDefinition> interfaceDefinitionOptional = interfaceDefinitionMap.entrySet().stream()
-            .filter(interfaceDefinitionEntry -> interfaceDefinitionEntry.getKey().equalsIgnoreCase(UniqueIdBuilder.buildInterfaceTypeUid(model, interfaceType))).map(Entry::getValue).findFirst();
+            .filter(interfaceDefinitionEntry -> interfaceDefinitionEntry.getKey()
+                .equalsIgnoreCase(UniqueIdBuilder.buildInterfaceTypeUid(model, interfaceType))).map(Entry::getValue).findFirst();
         if (interfaceDefinitionOptional.isEmpty()) {
             throw new ByActionStatusComponentException(ActionStatus.INTERFACE_UNKNOWN, interfaceType);
         }
@@ -160,13 +168,11 @@ public class InterfaceDefinitionHandler {
         final OperationDataDefinition operation = new OperationDataDefinition();
         operation.setUniqueId(UUID.randomUUID().toString());
         operation.setName(operationName);
-        
+
         if (MapUtils.isEmpty(operationDefinitionMap)) {
             return operation;
         }
-        Object operationDescription = operationDefinitionMap.get(
-                DESCRIPTION.getElementName()
-        );
+        Object operationDescription = operationDefinitionMap.get(DESCRIPTION.getElementName());
         if (null != operationDescription) {
             operation.setDescription(operationDescription.toString());
         }
@@ -175,9 +181,55 @@ public class InterfaceDefinitionHandler {
             final Map<String, Object> interfaceInputs = (Map<String, Object>) operationDefinitionMap.get(INPUTS.getElementName());
             operation.setInputs(handleInterfaceOperationInputs(interfaceInputs));
         }
+        if (operationDefinitionMap.containsKey(MILESTONES.getElementName())) {
+            final Map<String, Object> interfaceMilestones = (Map<String, Object>) operationDefinitionMap.get(MILESTONES.getElementName());
+            operation.setMilestones(handleInterfaceOperationMilestones(interfaceMilestones));
+        }
         return operation;
     }
 
+    private Map<String, MilestoneDataDefinition> handleInterfaceOperationMilestones(final Map<String, Object> interfaceMilestones) {
+        final Map<String, MilestoneDataDefinition> milestones = new HashMap<>();
+        for (final Entry<String, Object> interfaceInput : interfaceMilestones.entrySet()) {
+            final MilestoneDataDefinition operationMilestone = new MilestoneDataDefinition();
+            ListDataDefinition<ActivityDataDefinition> activities = handleMilestoneActivities(interfaceInput.getValue());
+            if (activities.isEmpty()) {
+                throw new ByActionStatusComponentException(ActionStatus.INVALID_OPERATION_MILESTONE, interfaceInput.getKey());
+            }
+            operationMilestone.setActivities(activities);
+            milestones.put(interfaceInput.getKey(), operationMilestone);
+        }
+        return milestones;
+    }
+
+    private ListDataDefinition<ActivityDataDefinition> handleMilestoneActivities(final Object value) {
+        ListDataDefinition<ActivityDataDefinition> activities = new ListDataDefinition<>();
+        if (value instanceof Map) {
+            final LinkedHashMap<String, Object> activitiesValue = (LinkedHashMap<String, Object>) value;
+            if (activitiesValue.containsKey(ACTIVITIES.getElementName())) {
+                final List<Object> milestoneActivities = (List<Object>) activitiesValue.get(ACTIVITIES.getElementName());
+                for (Object activityValue : milestoneActivities) {
+                    ActivityDataDefinition activity = new ActivityDataDefinition();
+                    if (activityValue instanceof Map) {
+                        Map<String, String> activityMap = (Map<String, String>) activityValue;
+                        if (activityMap.containsKey(TYPE.getElementName()) && activityMap.containsKey(WORKFLOW.getElementName())) {
+                            activity.setType(activityMap.get(TYPE.getElementName()));
+                            activity.setWorkflow(activityMap.get(WORKFLOW.getElementName()));
+                            activities.add(activity);
+                        } else {
+                            return new ListDataDefinition<>();
+                        }
+                    } else {
+                        return new ListDataDefinition<>();
+                    }
+                }
+            } else {
+                return new ListDataDefinition<>();
+            }
+        }
+        return activities;
+    }
+
     private ListDataDefinition<OperationInputDefinition> handleInterfaceOperationInputs(final Map<String, Object> interfaceInputs) {
         final ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>();
         for (final Entry<String, Object> interfaceInput : interfaceInputs.entrySet()) {
@@ -237,10 +289,10 @@ public class InterfaceDefinitionHandler {
             return Optional.empty();
         }
         final ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition();
-        if (operationDefinitionMap.get(IMPLEMENTATION.getElementName()) instanceof Map && 
-                ((Map)operationDefinitionMap.get(IMPLEMENTATION.getElementName())).containsKey("primary")) {
-            Map<String, Object> implDetails = (Map) ((Map)operationDefinitionMap.get(IMPLEMENTATION.getElementName())).get("primary");
-            
+        if (operationDefinitionMap.get(IMPLEMENTATION.getElementName()) instanceof Map &&
+            ((Map) operationDefinitionMap.get(IMPLEMENTATION.getElementName())).containsKey("primary")) {
+            Map<String, Object> implDetails = (Map) ((Map) operationDefinitionMap.get(IMPLEMENTATION.getElementName())).get("primary");
+
             if (implDetails.get("file") != null) {
                 final String file = implDetails.get("file").toString();
                 artifactDataDefinition.setArtifactName(generateArtifactName(file));
@@ -251,11 +303,12 @@ public class InterfaceDefinitionHandler {
             if (implDetails.get("artifact_version") != null) {
                 artifactDataDefinition.setArtifactVersion(implDetails.get("artifact_version").toString());
             }
-            
-            if(implDetails.get("properties") instanceof Map) {
-                List<PropertyDataDefinition> operationProperties = artifactDataDefinition.getProperties() == null ? new ArrayList<>() : artifactDataDefinition.getProperties();
+
+            if (implDetails.get("properties") instanceof Map) {
+                List<PropertyDataDefinition> operationProperties =
+                    artifactDataDefinition.getProperties() == null ? new ArrayList<>() : artifactDataDefinition.getProperties();
                 Map<String, Object> properties = (Map<String, Object>) implDetails.get("properties");
-                properties.forEach((k,v) -> {
+                properties.forEach((k, v) -> {
                     ToscaPropertyType type = getTypeFromObject(v);
                     if (type != null) {
                         PropertyDataDefinition propertyDef = new PropertyDataDefinition();
@@ -289,15 +342,15 @@ public class InterfaceDefinitionHandler {
         }
         return Optional.of(artifactDataDefinition);
     }
-    
+
     private String generateArtifactName(final String name) {
         if (OperationArtifactUtil.artifactNameIsALiteralValue(name)) {
-           return name;
+            return name;
         } else {
             return QUOTE + name + QUOTE;
         }
     }
-    
+
     private ToscaPropertyType getTypeFromObject(final Object value) {
         if (value instanceof String) {
             return ToscaPropertyType.STRING;
@@ -316,7 +369,7 @@ public class InterfaceDefinitionHandler {
         }
         return null;
     }
-    
+
 
     private Map<String, InputDefinition> handleInputs(final Map<String, Object> interfaceDefinitionToscaMap) {
         if (!interfaceDefinitionToscaMap.containsKey(INPUTS.getElementName())) {
index f4624b1..e95f16e 100644 (file)
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.module.SimpleModule;
 import com.google.gson.Gson;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -37,11 +38,16 @@ import org.apache.commons.collections.MapUtils;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.math.NumberUtils;
+import org.openecomp.sdc.be.datatypes.elements.ActivityDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ActivityTypeEnum;
+import org.openecomp.sdc.be.datatypes.enums.MilestoneTypeEnum;
 import org.openecomp.sdc.be.model.Component;
 import org.openecomp.sdc.be.model.ComponentInstance;
 import org.openecomp.sdc.be.model.DataTypeDefinition;
@@ -49,12 +55,14 @@ import org.openecomp.sdc.be.model.InterfaceDefinition;
 import org.openecomp.sdc.be.model.Product;
 import org.openecomp.sdc.be.model.PropertyDefinition;
 import org.openecomp.sdc.be.tosca.PropertyConvertor.PropertyType;
+import org.openecomp.sdc.be.tosca.model.ToscaActivity;
 import org.openecomp.sdc.be.tosca.model.ToscaArtifactDefinition;
 import org.openecomp.sdc.be.tosca.model.ToscaInput;
 import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition;
 import org.openecomp.sdc.be.tosca.model.ToscaInterfaceNodeType;
 import org.openecomp.sdc.be.tosca.model.ToscaInterfaceOperationImplementation;
 import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition;
+import org.openecomp.sdc.be.tosca.model.ToscaMilestone;
 import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
 import org.openecomp.sdc.be.tosca.model.ToscaProperty;
 import org.openecomp.sdc.be.tosca.model.ToscaPropertyAssignment;
@@ -285,6 +293,7 @@ public class InterfacesOperationsConverter {
                     toscaLifecycleOperationDefinition.setDescription(operationEntry.getValue().getDescription());
                 }
                 fillToscaOperationInputs(operationEntry.getValue(), dataTypes, toscaLifecycleOperationDefinition);
+                fillToscaOperationMilestones(operationEntry.getValue(), dataTypes, toscaLifecycleOperationDefinition);
                 toscaOperationMap.put(operationEntry.getValue().getName(), toscaLifecycleOperationDefinition);
             }
         }
@@ -303,6 +312,36 @@ public class InterfacesOperationsConverter {
         toscaInterfaceDefinitions.put(getLastPartOfName(interfaceType), interfaceDefinitionAsMap);
     }
 
+    private void fillToscaOperationMilestones(OperationDataDefinition operation, Map<String, DataTypeDefinition> dataTypes,
+                                              ToscaLifecycleOperationDefinition toscaOperation) {
+        if (Objects.isNull(operation.getMilestones()) || operation.getMilestones().isEmpty()) {
+            toscaOperation.setMilestones(null);
+            return;
+        }
+        Map<String, ToscaMilestone> toscaMilestones = new HashMap<>();
+        for (Entry<String, MilestoneDataDefinition> milestone : operation.getMilestones().entrySet()) {
+            ListDataDefinition<ActivityDataDefinition> activities = milestone.getValue().getActivities();
+            if (MilestoneTypeEnum.getEnum(milestone.getKey()).isEmpty() || activities == null || activities.isEmpty()) {
+                continue;
+            }
+            List<Map<String, ToscaActivity>> toscaActivities = new ArrayList<>();
+            for (ActivityDataDefinition activity : activities.getListToscaDataDefinition()) {
+                if (ActivityTypeEnum.getEnum(activity.getType()).isEmpty()) {
+                    continue;
+                }
+                Map<String, ToscaActivity> toscaActivityMap = new HashMap<>();
+                ToscaActivity toscaActivity = new ToscaActivity();
+                toscaActivity.setWorkflow(activity.getWorkflow());
+                toscaActivityMap.put(activity.getType(), toscaActivity);
+                toscaActivities.add(toscaActivityMap);
+            }
+            ToscaMilestone toscaMilestone = new ToscaMilestone();
+            toscaMilestone.setActivities(toscaActivities);
+            toscaMilestones.put(milestone.getKey(), toscaMilestone);
+        }
+        toscaOperation.setMilestones(toscaMilestones);
+    }
+
     private boolean operationHasAnImplementation(OperationDataDefinition operation) {
         return operation.getImplementation() != null && StringUtils.isNotEmpty(operation.getImplementation().getArtifactName()) &&
             !operation.getImplementation().getArtifactName().equals("''");
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaActivity.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaActivity.java
new file mode 100644 (file)
index 0000000..736988e
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2023 Nordix Foundation.
+ *  ================================================================================
+ *  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.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import lombok.Data;
+
+@Data
+public class ToscaActivity {
+
+    String workflow;
+}
index 575c025..53aca45 100644 (file)
@@ -28,5 +28,6 @@ public class ToscaLifecycleOperationDefinition {
     private String description;
     private Object implementation;
     private Map<String, ToscaProperty> inputs;
+    private Map<String, ToscaMilestone> milestones;
 
 }
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMilestone.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMilestone.java
new file mode 100644 (file)
index 0000000..d04bdd7
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ *
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2023 Nordix Foundation.
+ *  ================================================================================
+ *  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.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import java.util.List;
+import java.util.Map;
+import lombok.Data;
+
+@Data
+public class ToscaMilestone {
+
+    private List<Map<String, ToscaActivity>> activities;
+
+}
index bbbbcfc..800fbc2 100644 (file)
@@ -26,9 +26,10 @@ import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.hasItems;
 import static org.hamcrest.Matchers.hasSize;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.lenient;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DEFAULT;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DESCRIPTION;
 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIRED;
@@ -56,27 +57,36 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
 import org.mockito.junit.jupiter.MockitoExtension;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
 import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.common.api.ConfigurationSource;
+import org.openecomp.sdc.common.impl.ExternalConfiguration;
+import org.openecomp.sdc.common.impl.FSConfigurationSource;
 import org.yaml.snakeyaml.Yaml;
 
 @ExtendWith(MockitoExtension.class)
 class InterfaceDefinitionHandlerTest {
 
-    @Mock
-    private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
-    private InterfaceDefinitionHandler interfaceDefinitionHandler;
-    private InterfaceDefinition interfaceLifecyleStandard;
     private static final Path TEST_RESOURCE_PATH = Paths.get("src/test/resources/interfaceDefinition");
     private static final String CREATE_OPERATION = "create";
     private static final String DELETE_OPERATION = "delete";
     private static final String START_OPERATION = "start";
     private static final String STOP_OPERATION = "stop";
     private static final String INTERFACE_TYPE = "tosca.interfaces.node.lifecycle.Standard";
+    static ConfigurationSource
+        configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be");
+    static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
+    @Mock
+    private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+    private InterfaceDefinitionHandler interfaceDefinitionHandler;
+    private InterfaceDefinition interfaceLifecyleStandard;
 
     @BeforeEach
     void setUp() {
@@ -95,7 +105,7 @@ class InterfaceDefinitionHandlerTest {
         operations.put(DELETE_OPERATION, new OperationDataDefinition());
         interfaceLifecyleStandard.setOperations(operations);
         interfaceTypes.put(INTERFACE_TYPE, interfaceLifecyleStandard);
-        when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(StringUtils.EMPTY)).thenReturn(Either.left(interfaceTypes));
+        lenient().when(interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(StringUtils.EMPTY)).thenReturn(Either.left(interfaceTypes));
     }
 
     @Test
@@ -108,10 +118,20 @@ class InterfaceDefinitionHandlerTest {
     @Test
     void testCreateWithOperationSuccess() throws FileNotFoundException {
         final Map<String, Object> load = loadYaml(Paths.get("interfaceDefinition-tosca1.3.yaml"));
-        final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create( load, StringUtils.EMPTY);
+        final InterfaceDefinition actualInterfaceDefinition = interfaceDefinitionHandler.create(load, StringUtils.EMPTY);
         assertInterfaceDefinition(actualInterfaceDefinition);
     }
 
+    @Test
+    void testCreateWithOperationFailMilestones() throws FileNotFoundException {
+        final Map<String, Object> load = loadYaml(Paths.get("interfaceDefinitionInvalidMilestone-tosca1.3.yaml"));
+        final ByActionStatusComponentException actualException =
+            assertThrows(ByActionStatusComponentException.class, () -> interfaceDefinitionHandler.create(load, StringUtils.EMPTY));
+        assertEquals(ActionStatus.INVALID_OPERATION_MILESTONE, actualException.getActionStatus());
+        assertEquals(1, actualException.getParams().length);
+        assertEquals("on_failure", actualException.getParams()[0]);
+    }
+
     private void assertInterfaceDefinition(final InterfaceDefinition actualInterfaceDefinition) {
         interfaceLifecyleStandard.getOperations().keySet().forEach(operation ->
             assertTrue(actualInterfaceDefinition.hasOperation(operation)));
index 407956d..587b902 100644 (file)
@@ -57,6 +57,7 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.InterfaceInstanceDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
@@ -1052,7 +1053,7 @@ class ServiceBusinessLogicTest extends ServiceBusinessLogicBaseTestSetup {
             new ComponentInstanceInterface("interfaceId", new InterfaceInstanceDataDefinition());
         Map<String, Operation> operationsMap = Maps.newHashMap();
         operationsMap.put(operationId, new Operation(new ArtifactDataDefinition(), "1",
-            new ListDataDefinition<>(), new ListDataDefinition<>()));
+            new ListDataDefinition<>(), new ListDataDefinition<>(), new HashMap<>()));
         componentInstanceInterface.setOperationsMap(operationsMap);
 
         Map<String, List<ComponentInstanceInterface>> componentInstancesInterfacesMap = Maps.newHashMap();
index 5ba29cb..dfe4107 100644 (file)
@@ -42,16 +42,20 @@ import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.openecomp.sdc.be.DummyConfigurationManager;
+import org.openecomp.sdc.be.datatypes.elements.ActivityDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
+import org.openecomp.sdc.be.datatypes.enums.ActivityTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.MilestoneTypeEnum;
 import org.openecomp.sdc.be.model.Component;
 import org.openecomp.sdc.be.model.DataTypeDefinition;
 import org.openecomp.sdc.be.model.InputDefinition;
@@ -98,7 +102,7 @@ class InterfacesOperationsConverterTest {
         component.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName("NodeTypeName");
         InterfaceDefinition addedInterface = new InterfaceDefinition();
         addedInterface.setType("Local");
-        addOperationsToInterface(component, addedInterface, 5, 3, true, false, false);
+        addOperationsToInterface(component, addedInterface, 5, 3, true, false, false, false);
         final String interfaceType = "normalizedComponentName-interface";
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(interfaceType, addedInterface);
@@ -121,7 +125,7 @@ class InterfacesOperationsConverterTest {
         component.getComponentMetadataDefinition().getMetadataDataDefinition().setSystemName("NodeTypeName");
         InterfaceDefinition addedInterface = new InterfaceDefinition();
         addedInterface.setType("Local");
-        addOperationsToInterface(component, addedInterface, 5, 3, true, false, false);
+        addOperationsToInterface(component, addedInterface, 5, 3, true, false, false, false);
         final String interfaceType = "normalizedServiceComponentName-interface";
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(interfaceType, addedInterface);
@@ -142,7 +146,7 @@ class InterfacesOperationsConverterTest {
         InterfaceDefinition addedInterface = new InterfaceDefinition();
         addedInterface.setType("com.some.resource.or.other.resourceName");
 
-        addOperationsToInterface(component, addedInterface, 3, 2, true, false, false);
+        addOperationsToInterface(component, addedInterface, 3, 2, true, false, false, false);
         final String interfaceType = "normalizedComponentName-interface";
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(interfaceType, addedInterface);
@@ -165,7 +169,7 @@ class InterfacesOperationsConverterTest {
         component.setNormalizedName("normalizedServiceComponentName");
         InterfaceDefinition addedInterface = new InterfaceDefinition();
         addedInterface.setType("com.some.service.or.other.serviceName");
-        addOperationsToInterface(component, addedInterface, 3, 2, true, false, false);
+        addOperationsToInterface(component, addedInterface, 3, 2, true, false, false, false);
         final String interfaceType = "normalizedServiceComponentName-interface";
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(interfaceType, addedInterface);
@@ -189,7 +193,7 @@ class InterfacesOperationsConverterTest {
         InterfaceDefinition addedInterface = new InterfaceDefinition();
         addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
         addedInterface.setType("com.some.resource.or.other.resourceName");
-        addOperationsToInterface(component, addedInterface, 3, 2, true, false, false);
+        addOperationsToInterface(component, addedInterface, 3, 2, true, false, false, false);
         final String interfaceType = "normalizedComponentName-interface";
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(interfaceType, addedInterface);
@@ -210,7 +214,7 @@ class InterfacesOperationsConverterTest {
         component.setNormalizedName("normalizedComponentName");
         InterfaceDefinition addedInterface = new InterfaceDefinition();
         addedInterface.setType("com.some.resource.or.other.resourceNameNoInputs");
-        addOperationsToInterface(component, addedInterface, 3, 3, false, false, false);
+        addOperationsToInterface(component, addedInterface, 3, 3, false, false, false, false);
         final String interfaceType = "normalizedComponentName-interface";
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(interfaceType, addedInterface);
@@ -234,7 +238,7 @@ class InterfacesOperationsConverterTest {
         component.setNormalizedName("normalizedComponentName");
         InterfaceDefinition addedInterface = new InterfaceDefinition();
         addedInterface.setType(addedInterfaceType);
-        addOperationsToInterface(component, addedInterface, 2, 2, true, true, false);
+        addOperationsToInterface(component, addedInterface, 2, 2, true, true, false, false);
         addedInterface.getOperationsMap().values().stream()
             .filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
                 "name_for_op_0"))
@@ -268,7 +272,7 @@ class InterfacesOperationsConverterTest {
         InterfaceDefinition addedInterface = new InterfaceDefinition();
         addedInterface.setType(addedInterfaceType);
         addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
-        addOperationsToInterface(component, addedInterface, 2, 2, true, true, false);
+        addOperationsToInterface(component, addedInterface, 2, 2, true, true, false, false);
         addedInterface.getOperationsMap().values().stream()
             .filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
                 "name_for_op_0"))
@@ -281,7 +285,7 @@ class InterfacesOperationsConverterTest {
         InterfaceDefinition secondInterface = new InterfaceDefinition();
         secondInterface.setType(secondInterfaceType);
         secondInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
-        addOperationsToInterface(component, secondInterface, 2, 2, true, true, false);
+        addOperationsToInterface(component, secondInterface, 2, 2, true, true, false, false);
         secondInterface.getOperationsMap().values().stream()
             .filter(operationInputDefinition -> operationInputDefinition.getName().equalsIgnoreCase(
                 "name_for_op_0"))
@@ -396,8 +400,8 @@ class InterfacesOperationsConverterTest {
         assertTrue(expectedListOfStringPropValue.contains("value3"));
     }
 
-    private void addOperationsToInterface(Component component, InterfaceDefinition addedInterface, int numOfOps,
-                                          int numOfInputsPerOp, boolean hasInputs, boolean hasOutputs, boolean addAComplexType) {
+    private void addOperationsToInterface(Component component, InterfaceDefinition addedInterface, int numOfOps, int numOfInputsPerOp,
+                                          boolean hasInputs, boolean hasOutputs, boolean addAComplexType, boolean hasMilestones) {
 
         addedInterface.setOperations(new HashMap<>());
         for (int i = 0; i < numOfOps; i++) {
@@ -407,6 +411,9 @@ class InterfacesOperationsConverterTest {
             final ArtifactDataDefinition implementation = new ArtifactDataDefinition();
             implementation.setArtifactName(i + "_createBPMN.bpmn");
             operation.setImplementation(implementation);
+            if (hasMilestones) {
+                operation.setMilestones(createMilestones());
+            }
             if (hasInputs) {
                 operation.setInputs(createInputs(component, numOfInputsPerOp, addAComplexType));
             }
@@ -418,6 +425,19 @@ class InterfacesOperationsConverterTest {
         }
     }
 
+    private Map<String, MilestoneDataDefinition> createMilestones() {
+        Map<String, MilestoneDataDefinition> toscaMilestones = new HashMap<>();
+        ActivityDataDefinition activity = new ActivityDataDefinition();
+        activity.setType(ActivityTypeEnum.DELEGATE.getValue());
+        activity.setWorkflow("workflow1");
+        ListDataDefinition<ActivityDataDefinition> activities = new ListDataDefinition<>();
+        activities.add(activity);
+        MilestoneDataDefinition milestone = new MilestoneDataDefinition();
+        milestone.setActivities(activities);
+        toscaMilestones.put(MilestoneTypeEnum.ON_ENTRY.getValue(), milestone);
+        return toscaMilestones;
+    }
+
     private InputDataDefinition createInput(final String type, final String description, final Boolean isRequired,
                                             final String defaultValue) {
         final PropertyDataDefinition propertyDataDefinition = new PropertyDataDefinition();
@@ -555,7 +575,7 @@ class InterfacesOperationsConverterTest {
         InterfaceDefinition addedInterface = new InterfaceDefinition();
         addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
         addedInterface.setType("com.some.resource.or.other.resourceName");
-        addOperationsToInterface(component, addedInterface, 3, 2, true, false, true);
+        addOperationsToInterface(component, addedInterface, 3, 2, true, false, true, false);
         final String interfaceType = "normalizedComponentName-interface";
         component.setInterfaces(new HashMap<>());
         component.getInterfaces().put(interfaceType, addedInterface);
@@ -585,6 +605,43 @@ class InterfacesOperationsConverterTest {
         assertEquals("SELF", complexInputStringProp.get("propertySource"));
     }
 
+    @Test
+    void testGetInterfaceAsMapWithMilestones() {
+        Component component = new Resource();
+        component.setNormalizedName("normalizedComponentName");
+        InterfaceDefinition addedInterface = new InterfaceDefinition();
+        addedInterface.setToscaResourceName("com.some.resource.or.other.resourceName");
+        addedInterface.setType("com.some.resource.or.other.resourceName");
+        addOperationsToInterface(component, addedInterface, 2, 0, false, false, false, true);
+        final String interfaceType = "normalizedComponentName-interface";
+        component.setInterfaces(new HashMap<>());
+        component.getInterfaces().put(interfaceType, addedInterface);
+        final var interfacesMap = interfacesOperationsConverter.getInterfacesMap(component, null, component.getInterfaces(), dataTypes, false);
+        assertNotNull(interfacesMap);
+        assertEquals(1, interfacesMap.size());
+        assertTrue(interfacesMap.containsKey("resourceName"));
+        Object resourceName = interfacesMap.get("resourceName");
+        assertNotNull(resourceName);
+        assertTrue(resourceName instanceof Map);
+        assertEquals(3, ((Map) resourceName).size());
+        Map<String, Object> resource = (Map<String, Object>) resourceName;
+        assertTrue(resource.containsKey("name_for_op_0"));
+        Map<String, Object> operation0 = (Map<String, Object>) resource.get("name_for_op_0");
+        assertTrue(operation0.containsKey("milestones"));
+        Map<String, Object> operation0Milestones = (Map<String, Object>) operation0.get("milestones");
+        assertTrue(operation0Milestones.containsKey(MilestoneTypeEnum.ON_ENTRY.getValue()));
+        Map<String, Object> milestone = (Map<String, Object>) operation0Milestones.get(MilestoneTypeEnum.ON_ENTRY.getValue());
+        assertTrue(milestone.containsKey("activities"));
+        List<Map<String, Object>> activities = (List<Map<String, Object>>) milestone.get("activities");
+        assertEquals(1, activities.size());
+        Map<String, Object> activity = activities.get(0);
+        assertEquals(1, activities.size());
+        assertTrue(activity.containsKey("delegate"));
+        Map<String, String> activityVariables = (Map<String, String>) activity.get("delegate");
+        assertTrue(activityVariables.containsKey("workflow"));
+        assertEquals("workflow1", activityVariables.get("workflow"));
+    }
+
     private void addComplexTypeToDataTypes() {
         PropertyDefinition intProp = new PropertyDefinition();
         intProp.setType("integer");
index 49de865..8f350ed 100644 (file)
@@ -46,6 +46,25 @@ start:
         service_restoration_sla: service_restoration_sla_value
         battery_backup: true
         partner_priorty_assist: false
+  milestones:
+    on_failure:
+      activities:
+        - type: delegate
+          workflow: workflow1
+        - type: delegate
+          workflow: workflow2
+    on_success:
+      activities:
+        - type: delegate
+          workflow: workflow1
+        - type: delegate
+          workflow: workflow2
+    on_timeout:
+      activities:
+        - type: delegate
+          workflow: workflow1
+        - type: delegate
+          workflow: workflow2
 stop:
   implementation: "camunda/executeAction"
   inputs:
index 164280d..8adcdcf 100644 (file)
@@ -41,6 +41,25 @@ operations:
           service_restoration_sla: service_restoration_sla_value
           battery_backup: true
           partner_priorty_assist: false
+    milestones:
+      on_failure:
+        activities:
+          - type: delegate
+            workflow: workflow1
+          - type: delegate
+            workflow: workflow2
+      on_success:
+        activities:
+          - type: delegate
+            workflow: workflow1
+          - type: delegate
+            workflow: workflow2
+      on_timeout:
+        activities:
+          - type: delegate
+            workflow: workflow1
+          - type: delegate
+            workflow: workflow2
   stop:
     implementation: "camunda/executeAction"
     inputs:
diff --git a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinitionInvalidMilestone-tosca1.3.yaml b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinitionInvalidMilestone-tosca1.3.yaml
new file mode 100644 (file)
index 0000000..4e3c556
--- /dev/null
@@ -0,0 +1,17 @@
+inputs:
+  stringInput:
+    type: string
+    description: stringInput description
+    required: true
+    default: defaultValue
+    status: aStatus
+  actionInput:
+    type: org.openecomp.resource.datatypes.Action
+type: tosca.interfaces.node.lifecycle.Standard
+operations:
+  start:
+    implementation: "camunda/executeAction"
+    milestones:
+      on_failure:
+      on_success:
+      on_timeout:
\ No newline at end of file
index fbe1c2e..d254b8d 100644 (file)
@@ -106,7 +106,7 @@ public enum ActionStatus {
     //Interface
     INTERFACE_NOT_FOUND_IN_COMPONENT, INTERFACE_UNKNOWN,
     //InterfaceOperation
-    INTERFACE_OPERATION_NOT_FOUND, INTERFACE_OPERATION_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_NAME_MANDATORY, INTERFACE_OPERATION_NAME_INVALID, INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_NOT_DELETED, INTERFACE_OPERATION_MAPPED_OUTPUT_MODIFIED, INTERFACE_OPERATION_DELETE_WITH_MAPPED_OUTPUT, INTERFACE_OPERATION_INPUT_NAME_MANDATORY, INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY, INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT, INTERFACE_OPERATION_INVALID_FOR_LOCAL_TYPE, INTERFACE_OPERATION_INVALID_FOR_GLOBAL_TYPE, INTERFACE_OPERATION_NOT_DEFINED, PROPERTY_USED_BY_OPERATION, DECLARED_INPUT_USED_BY_OPERATION, INVALID_CONSUMPTION_TYPE,
+    INTERFACE_OPERATION_NOT_FOUND, INTERFACE_OPERATION_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_NAME_MANDATORY, INTERFACE_OPERATION_NAME_INVALID, INTERFACE_OPERATION_INPUT_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_OUTPUT_NAME_ALREADY_IN_USE, INTERFACE_OPERATION_NOT_DELETED, INTERFACE_OPERATION_MAPPED_OUTPUT_MODIFIED, INTERFACE_OPERATION_DELETE_WITH_MAPPED_OUTPUT, INTERFACE_OPERATION_INPUT_NAME_MANDATORY, INTERFACE_OPERATION_OUTPUT_NAME_MANDATORY, INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT, INTERFACE_OPERATION_INVALID_FOR_LOCAL_TYPE, INTERFACE_OPERATION_INVALID_FOR_GLOBAL_TYPE, INTERFACE_OPERATION_NOT_DEFINED, PROPERTY_USED_BY_OPERATION, DECLARED_INPUT_USED_BY_OPERATION, INVALID_CONSUMPTION_TYPE, INVALID_OPERATION_MILESTONE,
     //NodeFilter
     NODE_FILTER_NOT_FOUND, UNSUPPORTED_VALUE_PROVIDED, SELECTED_PROPERTY_NOT_PRESENT, FILTER_PROPERTY_NOT_FOUND, UNSUPPORTED_OPERATOR_PROVIDED, CONSTRAINT_FORMAT_INCORRECT, SOURCE_TARGET_PROPERTY_TYPE_MISMATCH, SOURCE_TARGET_SCHEMA_MISMATCH, UNSUPPORTED_PROPERTY_TYPE,
     //Filter
index 92c7c59..a25fd01 100644 (file)
  */
 package org.openecomp.sdc.be.model;
 
+import java.util.Map;
 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.MilestoneDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
 import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition;
+import org.openecomp.sdc.be.datatypes.enums.MilestoneTypeEnum;
 
 /**
  * Defines an operation available to manage particular aspects of the Node Type.
@@ -48,11 +51,12 @@ public class Operation extends OperationDataDefinition implements IOperationPara
     }
 
     public Operation(ArtifactDataDefinition implementation, String description, ListDataDefinition<OperationInputDefinition> inputs,
-                     ListDataDefinition<OperationOutputDefinition> outputs) {
+                     ListDataDefinition<OperationOutputDefinition> outputs, Map<String, MilestoneDataDefinition> milestones) {
         super(description);
         setImplementation(implementation);
         setInputs(inputs);
         setOutputs(outputs);
+        setMilestones(milestones);
     }
 
     @Override
index 2ad9829..f1730ed 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdc.be.model;
 
+import java.util.HashMap;
 import org.junit.Test;
 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
@@ -34,9 +35,9 @@ public class OperationTest {
        @Test
        public void testCtor() throws Exception {
                new Operation(new OperationDataDefinition());
-               new Operation(new ArtifactDataDefinition(), "mock", new ListDataDefinition<>(), new ListDataDefinition<>());
+               new Operation(new ArtifactDataDefinition(), "mock", new ListDataDefinition<>(), new ListDataDefinition<>(), new HashMap<>());
        }
-       
+
        @Test
        public void testIsDefinition() throws Exception {
                Operation testSubject;
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ActivityDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ActivityDataDefinition.java
new file mode 100644 (file)
index 0000000..8d76f68
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2023 Nordix Foundation.
+ *  ================================================================================
+ *  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.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+import java.io.Serializable;
+import lombok.NoArgsConstructor;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+
+@NoArgsConstructor
+public class ActivityDataDefinition extends ToscaDataDefinition implements Serializable {
+
+    public ActivityDataDefinition(ActivityDataDefinition activity) {
+        setType(activity.getType());
+        setWorkflow(getWorkflow());
+    }
+
+    public String getType() {
+        return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
+    }
+
+    public void setType(String type) {
+        setToscaPresentationValue(JsonPresentationFields.TYPE, type);
+    }
+
+    public String getWorkflow() {
+        return (String) getToscaPresentationValue(JsonPresentationFields.OPERATION_ACTIVITIES_WORKFLOW);
+    }
+
+    public void setWorkflow(String workflow) {
+        setToscaPresentationValue(JsonPresentationFields.OPERATION_ACTIVITIES_WORKFLOW, workflow);
+    }
+
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/MilestoneDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/MilestoneDataDefinition.java
new file mode 100644 (file)
index 0000000..78681e1
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ *
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2023 Nordix Foundation.
+ *  ================================================================================
+ *  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.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+import java.io.Serializable;
+import lombok.NoArgsConstructor;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
+
+@NoArgsConstructor
+public class MilestoneDataDefinition extends ToscaDataDefinition implements Serializable {
+
+    public MilestoneDataDefinition(MilestoneDataDefinition milestone) {
+        setActivities(milestone.getActivities());
+    }
+
+    public ListDataDefinition<ActivityDataDefinition> getActivities() {
+        return (ListDataDefinition<ActivityDataDefinition>) getToscaPresentationValue(JsonPresentationFields.OPERATION_ACTIVITIES);
+    }
+
+    public void setActivities(ListDataDefinition<ActivityDataDefinition> activities) {
+        setToscaPresentationValue(JsonPresentationFields.OPERATION_ACTIVITIES, activities);
+    }
+
+}
index f93e41c..a4bc7f1 100644 (file)
@@ -21,7 +21,9 @@
 package org.openecomp.sdc.be.datatypes.elements;
 
 import com.fasterxml.jackson.annotation.JsonCreator;
+import java.util.Map;
 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.MilestoneTypeEnum;
 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
 
 import java.io.Serializable;
@@ -46,6 +48,7 @@ public class OperationDataDefinition extends ToscaDataDefinition implements Seri
     }
 
     public OperationDataDefinition(OperationDataDefinition p) {
+        setMilestones(p.getMilestones());
         setDescription(p.getDescription());
         setImplementation(p.getImplementation());
         setInputs(p.getInputs());
@@ -59,6 +62,15 @@ public class OperationDataDefinition extends ToscaDataDefinition implements Seri
         setWorkflowVersion(p.getWorkflowVersion());
     }
 
+    public void setMilestones(Map<String, MilestoneDataDefinition> milestones) {
+        setToscaPresentationValue(JsonPresentationFields.OPERATION_MILESTONES, milestones);
+    }
+
+    public Map<String, MilestoneDataDefinition>  getMilestones() {
+        return (Map<String, MilestoneDataDefinition> ) getToscaPresentationValue(
+            JsonPresentationFields.OPERATION_MILESTONES);
+    }
+
     public String getDescription() {
         return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
     }
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ActivityTypeEnum.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/ActivityTypeEnum.java
new file mode 100644 (file)
index 0000000..b3594f3
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2023 Nordix Foundation.
+ *  ================================================================================
+ *  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.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.enums;
+
+import java.util.Optional;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum ActivityTypeEnum {
+    DELEGATE("delegate"),
+    INLINE("inline"),
+    CALL_OPERATION("call_operation"),
+    SET_STATE("set_state");
+
+    private final String value;
+
+    public static Optional<ActivityTypeEnum> getEnum(String name) {
+        for (ActivityTypeEnum activityType : values()) {
+            if (activityType.getValue().equals(name)) {
+                return Optional.of(activityType);
+            }
+        }
+        return Optional.empty();
+    }
+}
index 638d23b..c4d22a0 100644 (file)
@@ -257,6 +257,9 @@ public enum JsonPresentationFields {
     OPERATION_IMPLEMENTATION("implementation", null),
     OPERATION_INPUTS("inputs", null),
     OPERATION_OUTPUTS("outputs", null),
+    OPERATION_MILESTONES("milestones", null),
+    OPERATION_ACTIVITIES("activities", null),
+    OPERATION_ACTIVITIES_WORKFLOW("workflow", null),
     INPUTS("inputs", null),
 
     GET_PROPERTY("get_property", null),
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/MilestoneTypeEnum.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/MilestoneTypeEnum.java
new file mode 100644 (file)
index 0000000..1fa96b2
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *
+ *  ============LICENSE_START=======================================================
+ *  Copyright (C) 2023 Nordix Foundation.
+ *  ================================================================================
+ *  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.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.enums;
+
+import java.util.Optional;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum MilestoneTypeEnum {
+    ON_ENTRY("on_entry"),
+    ON_SUCCESS("on_success"),
+    ON_FAILURE("on_failure"),
+    ON_TIMEOUT("on_timeout");
+
+    private final String value;
+
+    public static Optional<MilestoneTypeEnum> getEnum(String name) {
+        for (MilestoneTypeEnum milestoneType : values()) {
+            if (milestoneType.getValue().equals(name)) {
+                return Optional.of(milestoneType);
+            }
+        }
+        return Optional.empty();
+    }
+}
index a7e6975..d4076ae 100644 (file)
@@ -77,6 +77,9 @@ public class TypeUtils {
         DATA_TYPES("data_types"), NODE_TYPES("node_types"), POLICY_TYPES("policy_types"),  IMPORTS("imports"),
         //Operations
         IMPLEMENTATION("implementation"),
+        MILESTONES("milestones"),
+        ACTIVITIES("activities"),
+        WORKFLOW("workflow"),
         SUBSTITUTION_FILTERS("substitution_filter"),
         DERIVED_FROM_NAME("derivedFromName"),
         INTERFACE_TYPES("interface_types"),