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