aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ToscaDefinitionPathCalculatorImpl.java
blob: 01a730a0525233cc69e362e57b5b5f058208204c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package org.openecomp.sdc.be.model.operations.impl;

import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.operations.api.ToscaDefinitionPathCalculator;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Component("tosca-path-calculator")
public class ToscaDefinitionPathCalculatorImpl implements ToscaDefinitionPathCalculator {

    @Override
    public List<String> calculateToscaDefinitionPath(ComponentInstance componentInstance, GraphEdge edge) {
        String ownerId = getCapReqOwner(edge);
        String instanceId = componentInstance.getUniqueId();
        return ownerId.equals(instanceId) ? Collections.singletonList(instanceId) : Arrays.asList(instanceId, ownerId);
    }

    private String getCapReqOwner(GraphEdge edge) {
        String ownerIdKey = GraphEdgePropertiesDictionary.OWNER_ID.getProperty();
        return (String)edge.getProperties().get(ownerIdKey);
    }
}