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=========================================================
21 package org.openecomp.sdc.be.model.jsonjanusgraph.utils;
23 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
24 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
25 import org.openecomp.sdc.be.datatypes.elements.CompositionDataDefinition;
26 import org.openecomp.sdc.be.model.jsonjanusgraph.enums.JsonConstantKeysEnum;
27 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ExternalReferencesOperation;
28 import org.openecomp.sdc.common.log.wrappers.Logger;
29 import org.springframework.stereotype.Component;
32 import java.util.Optional;
35 * Created by yavivi on 12/02/2018.
38 public class IdMapper {
40 private static final Logger log = Logger.getLogger(ExternalReferencesOperation.class.getName());
42 public String mapComponentNameToUniqueId(String componentInstanceName, GraphVertex serviceVertex) {
43 return map(componentInstanceName, serviceVertex, true);
46 public String mapUniqueIdToComponentNameTo(String compUniqueId, GraphVertex serviceVertex) {
47 return map(compUniqueId, serviceVertex, false);
50 private String map(String componentUniqueIdOrName, GraphVertex serviceVertex, boolean fromCompName) {
53 Map<String, CompositionDataDefinition> jsonComposition = (Map<String, CompositionDataDefinition>) serviceVertex.getJson();
54 CompositionDataDefinition compositionDataDefinition = jsonComposition.get(JsonConstantKeysEnum.COMPOSITION.getValue());
56 Optional<ComponentInstanceDataDefinition> componentInstanceDataDefinitionOptional = null;
58 componentInstanceDataDefinitionOptional = compositionDataDefinition.getComponentInstances().values().stream().filter(c -> c.getNormalizedName().equals(componentUniqueIdOrName)).findAny();
59 result = componentInstanceDataDefinitionOptional.get().getUniqueId();
60 log.debug("Compponent Instance Unique Id = {}", result);
62 componentInstanceDataDefinitionOptional = compositionDataDefinition.getComponentInstances().values().stream().filter(c -> c.getUniqueId().equals(componentUniqueIdOrName)).findAny();
63 result = componentInstanceDataDefinitionOptional.get().getNormalizedName();
64 log.debug("Compponent Instance Normalized Name = {}", result);
67 } catch (Exception e) {
68 log.error("Failed to map UUID or Normalized name of " + componentUniqueIdOrName, e);