Replaced all tabs with spaces in java and pom.xml
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / client / test / emulators / JsonStatusData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.asdc.client.test.emulators;
22
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.HashMap;
26 import java.util.Map;
27 import org.onap.sdc.api.notification.IStatusData;
28 import org.onap.sdc.utils.DistributionStatusEnum;
29 import com.fasterxml.jackson.annotation.JsonAnySetter;
30 import com.fasterxml.jackson.annotation.JsonIgnore;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32
33
34 public class JsonStatusData implements IStatusData {
35
36     @JsonIgnore
37     private static ObjectMapper mapper = new ObjectMapper();
38
39     @JsonIgnore
40     private Map<String, Object> attributesMap = new HashMap<>();
41
42     public JsonStatusData() {
43
44     }
45
46     @Override
47     public String getErrorReason() {
48         return "MSO FAILURE";
49     }
50
51     @Override
52     public String getDistributionID() {
53         // return (String)this.attributesMap.get("distributionID");
54         return "35120a87-1f82-4276-9735-f6de5a244d65";
55     }
56
57     @Override
58     public String getConsumerID() {
59         // return (String)this.attributesMap.get("consumerID");
60         return "mso.123456";
61     }
62
63     @Override
64     public String getComponentName() {
65         // return (String)this.attributesMap.get("componentName");
66         return "SDN-C";
67     }
68
69     @Override
70     public Long getTimestamp() {
71         // return (String)this.attributesMap.get("timestamp");
72         return null;
73     }
74
75     @Override
76     public String getArtifactURL() {
77         // return (String)this.attributesMap.get("artifactURL");
78         return "/sdc/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml";
79     }
80
81     @Override
82     public DistributionStatusEnum getStatus() {
83         // return (DistributionStatusEnum)this.attributesMap.get(DistributionStatusEnum.DEPLOY_OK);
84         return DistributionStatusEnum.COMPONENT_DONE_OK;
85     }
86
87     /**
88      * Method instantiate a INotificationData implementation from a JSON file.
89      * 
90      * @param notifFilePath The file path in String
91      * @return A JsonNotificationData instance
92      * @throws IOException in case of the file is not readable or not accessible
93      */
94     public static JsonStatusData instantiateNotifFromJsonFile(String notifFilePath) throws IOException {
95
96         InputStream is = Thread.currentThread().getContextClassLoader()
97                 .getResourceAsStream(notifFilePath + "status-structure.json");
98
99         // String fileLocation = System.getProperty("mso.config.path") + "notif-structure.json";
100
101         // String source = fileLocation;
102         // InputStream is = IOUtils.toInputStream(source, "UTF-8");
103
104         // String myString = IOUtils.toString(is, "UTF-8");
105
106
107         // System.out.println(myString);
108
109         if (is == null) {
110             // throw new FileExistsException("Resource Path does not exist: "+notifFilePath);
111         }
112         return mapper.readValue(is, JsonStatusData.class);
113     }
114
115     @SuppressWarnings("unused")
116     @JsonAnySetter
117     public final void setAttribute(String attrName, Object attrValue) {
118         if ((null != attrName) && (!attrName.isEmpty()) && (null != attrValue) && (null != attrValue.toString())) {
119             this.attributesMap.put(attrName, attrValue);
120         }
121     }
122
123 }