aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/org/onap/simulator/presetGenerator/presets/aai/PresetAAIGetServiceInstancesByInvariantId.java
blob: 8f7b6d0fba47d7dabc17b27def223626a55990f6 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package org.onap.simulator.presetGenerator.presets.aai;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
import org.onap.simulator.presetGenerator.presets.BasePresets.BaseAAIPreset;
import org.springframework.http.HttpMethod;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class PresetAAIGetServiceInstancesByInvariantId extends BaseAAIPreset {

    private String globalCustomerId;
    private String serviceType;
    private String invariantId;
    private Map<String, Multimap<String, String>> servicesWithRelationships;

    public PresetAAIGetServiceInstancesByInvariantId(String globalCustomerId, String serviceType, String invariantId,
                                                     Map<String, Multimap<String, String>> servicesWithRelationships) {
        this.globalCustomerId = globalCustomerId;
        this.serviceType = serviceType;
        this.invariantId = invariantId;
        this.servicesWithRelationships = servicesWithRelationships;
    }

    @Override
    public String getResponseBody() {
        return "{" +
                "  \"service-instance\":[" +
                servicesWithRelationships.entrySet().stream().map(
                    entry -> buildServiceInstance(entry.getKey(), entry.getValue())
                ).collect(Collectors.joining(",")) +
                "  ]" +
                "}";
    }

    private String buildServiceInstance(String serviceInstanceId, Multimap<String, String> relationships) {
        return "    {" +
                "      \"service-instance-id\":\"" + serviceInstanceId + "\"," +
                "      \"service-instance-name\":\"service-instance-name\"," +
                "      \"service-instance-type\":\"service-instance-type\"," +
                "      \"service-instance-role\":\"service-instance-role\"," +
                "      \"model-invariant-id\":\"" + invariantId + "\"," +
                "      \"model-version-id\":\"7a6ee536-f052-46fa-aa7e-2fca9d674c44\"," +
                "      \"resource-version\":\"GARBAGE DATA\"," +
                "      \"orchestration-status\":\"GARBAGE DATA\"," +
                "      \"relationship-list\":{" +
                "        \"relationship\":[" +
                relationships.entries().stream().map(
                        entry -> buildRelationship(entry.getKey(), entry.getValue())
                ).collect(Collectors.joining(",")) +
                "        ]" +
                "      }" +
                "    }";
    }

    private String buildRelationship(String relatedTo, final String relatedLink) {
        return "" +
                "{ " +
                "  \"related-to\": \"" + relatedTo + "\", " +
                "  \"relationship-label\": \"org.onap.relationships.inventory.ComposedOf\", " +
                "  \"related-link\": \"" + relatedLink + "\", " +
                "  \"relationship-data\": [" +
                "      { " +
                "        \"relationship-key\": \"GARBAGE DATA\", " +
                "        \"relationship-value\": \"GARBAGE DATA\" " +
                "      } " +
                "  ] " +
                "}";
    }

    @Override
    public HttpMethod getReqMethod() {
        return HttpMethod.GET;
    }

    @Override
    public String getReqPath() {
        return getRootPath() + "/business/customers/customer/" +
                globalCustomerId + "/service-subscriptions/service-subscription/" +
                serviceType + "/service-instances";
    }

    @Override
    public Map<String, List> getQueryParams() {
        return ImmutableMap.of("model-invariant-id", ImmutableList.of(invariantId));
    }
}