2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.be.model.jsonjanusgraph.utils;
23 import java.util.Optional;
24 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
25 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
26 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
27 import org.openecomp.sdc.be.model.jsonjanusgraph.enums.JsonConstantKeysEnum;
28 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ExternalReferencesOperation;
29 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
30 import org.openecomp.sdc.common.log.wrappers.Logger;
31 import org.springframework.stereotype.Component;
34 * Created by yavivi on 12/02/2018.
37 public class IdMapper {
39 private static final Logger log = Logger.getLogger(ExternalReferencesOperation.class.getName());
41 public String mapComponentNameToUniqueId(String componentInstanceName, GraphVertex serviceVertex) {
42 return map(componentInstanceName, serviceVertex, true);
45 public String mapUniqueIdToComponentNameTo(String compUniqueId, GraphVertex serviceVertex) {
46 return map(compUniqueId, serviceVertex, false);
49 private String map(String componentUniqueIdOrName, GraphVertex serviceVertex, boolean fromCompName) {
52 Map<String, CompositionDataDefinition> jsonComposition = (Map<String, CompositionDataDefinition>) serviceVertex.getJson();
53 CompositionDataDefinition compositionDataDefinition = jsonComposition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
54 Optional<ComponentInstanceDataDefinition> componentInstanceDataDefinitionOptional;
56 componentInstanceDataDefinitionOptional = compositionDataDefinition.getComponentInstances().values().stream()
57 .filter(c -> c.getNormalizedName().equals(componentUniqueIdOrName)).findAny();
58 if (componentInstanceDataDefinitionOptional.isPresent()) {
59 result = componentInstanceDataDefinitionOptional.get().getUniqueId();
60 log.debug("Component Instance Unique Id = {}", result);
63 componentInstanceDataDefinitionOptional = compositionDataDefinition.getComponentInstances().values().stream()
64 .filter(c -> c.getUniqueId().equals(componentUniqueIdOrName)).findAny();
65 if (componentInstanceDataDefinitionOptional.isPresent()) {
66 result = componentInstanceDataDefinitionOptional.get().getNormalizedName();
67 log.debug("Component Instance Normalized Name = {}", result);
70 } catch (Exception e) {
71 log.error(EcompLoggerErrorCode.DATA_ERROR, "Failed to map UUID or Normalized name of {}", componentUniqueIdOrName, e);