Merge automation from ECOMP's repository
[vid.git] / vid-automation / src / main / java / org / onap / simulator / presetGenerator / presets / aai / PresetAAIGetServiceInstancesByInvariantId.java
1 package org.onap.simulator.presetGenerator.presets.aai;
2
3 import com.google.common.collect.ImmutableList;
4 import com.google.common.collect.ImmutableMap;
5 import com.google.common.collect.Multimap;
6 import org.onap.simulator.presetGenerator.presets.BasePresets.BaseAAIPreset;
7 import org.springframework.http.HttpMethod;
8
9 import java.util.List;
10 import java.util.Map;
11 import java.util.stream.Collectors;
12
13 public class PresetAAIGetServiceInstancesByInvariantId extends BaseAAIPreset {
14
15     private String globalCustomerId;
16     private String serviceType;
17     private String invariantId;
18     private Map<String, Multimap<String, String>> servicesWithRelationships;
19
20     public PresetAAIGetServiceInstancesByInvariantId(String globalCustomerId, String serviceType, String invariantId,
21                                                      Map<String, Multimap<String, String>> servicesWithRelationships) {
22         this.globalCustomerId = globalCustomerId;
23         this.serviceType = serviceType;
24         this.invariantId = invariantId;
25         this.servicesWithRelationships = servicesWithRelationships;
26     }
27
28     @Override
29     public String getResponseBody() {
30         return "{" +
31                 "  \"service-instance\":[" +
32                 servicesWithRelationships.entrySet().stream().map(
33                     entry -> buildServiceInstance(entry.getKey(), entry.getValue())
34                 ).collect(Collectors.joining(",")) +
35                 "  ]" +
36                 "}";
37     }
38
39     private String buildServiceInstance(String serviceInstanceId, Multimap<String, String> relationships) {
40         return "    {" +
41                 "      \"service-instance-id\":\"" + serviceInstanceId + "\"," +
42                 "      \"service-instance-name\":\"service-instance-name\"," +
43                 "      \"service-instance-type\":\"service-instance-type\"," +
44                 "      \"service-instance-role\":\"service-instance-role\"," +
45                 "      \"model-invariant-id\":\"" + invariantId + "\"," +
46                 "      \"model-version-id\":\"7a6ee536-f052-46fa-aa7e-2fca9d674c44\"," +
47                 "      \"resource-version\":\"GARBAGE DATA\"," +
48                 "      \"orchestration-status\":\"GARBAGE DATA\"," +
49                 "      \"relationship-list\":{" +
50                 "        \"relationship\":[" +
51                 relationships.entries().stream().map(
52                         entry -> buildRelationship(entry.getKey(), entry.getValue())
53                 ).collect(Collectors.joining(",")) +
54                 "        ]" +
55                 "      }" +
56                 "    }";
57     }
58
59     private String buildRelationship(String relatedTo, final String relatedLink) {
60         return "" +
61                 "{ " +
62                 "  \"related-to\": \"" + relatedTo + "\", " +
63                 "  \"relationship-label\": \"org.onap.relationships.inventory.ComposedOf\", " +
64                 "  \"related-link\": \"" + relatedLink + "\", " +
65                 "  \"relationship-data\": [" +
66                 "      { " +
67                 "        \"relationship-key\": \"GARBAGE DATA\", " +
68                 "        \"relationship-value\": \"GARBAGE DATA\" " +
69                 "      } " +
70                 "  ] " +
71                 "}";
72     }
73
74     @Override
75     public HttpMethod getReqMethod() {
76         return HttpMethod.GET;
77     }
78
79     @Override
80     public String getReqPath() {
81         return getRootPath() + "/business/customers/customer/" +
82                 globalCustomerId + "/service-subscriptions/service-subscription/" +
83                 serviceType + "/service-instances";
84     }
85
86     @Override
87     public Map<String, List> getQueryParams() {
88         return ImmutableMap.of("model-invariant-id", ImmutableList.of(invariantId));
89     }
90 }