diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2023-07-18 11:35:18 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2023-09-22 07:41:02 +0000 |
commit | 629837b3f7a282c74604987fd531ff4523f98a0c (patch) | |
tree | d1afa021ef1342c72dd0a6ea016084651680caa7 /catalog-be/src/main/java/org | |
parent | 615f2405b8d2dee1d91cf20188a180591ec84ab3 (diff) |
Backend support for operation milestones with activities
Issue-ID: SDC-4577
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: I6a8dab0e48da542424faa017a1dea384ebb2376f
Diffstat (limited to 'catalog-be/src/main/java/org')
5 files changed, 173 insertions, 17 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java index 4e535eb41b..9f0adcf217 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java @@ -16,24 +16,29 @@ * 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())) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java index f4624b1649..e95f16eaac 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java @@ -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 index 0000000000..736988e85e --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaActivity.java @@ -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; +} diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaLifecycleOperationDefinition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaLifecycleOperationDefinition.java index 575c0259d2..53aca457a1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaLifecycleOperationDefinition.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaLifecycleOperationDefinition.java @@ -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 index 0000000000..d04bdd7357 --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaMilestone.java @@ -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; + +} |