[CLAMP-1] Initial ONAP CLAMP seed code commit
[clamp.git] / src / main / java / org / onap / clamp / clds / service / CldsService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); 
9  * you may not use this file except in compliance with the License. 
10  * You may obtain a copy of the License at
11  * 
12  * http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software 
15  * distributed under the License is distributed on an "AS IS" BASIS, 
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
17  * See the License for the specific language governing permissions and 
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 package org.onap.clamp.clds.service;
25
26 import com.att.ajsc.common.AjscService;
27 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
28 import com.fasterxml.jackson.core.JsonProcessingException;
29 import com.fasterxml.jackson.databind.JsonNode;
30 import com.fasterxml.jackson.databind.ObjectMapper;
31 import com.fasterxml.jackson.databind.node.ObjectNode;
32 import org.onap.clamp.clds.client.SdcCatalogServices;
33 import org.onap.clamp.clds.dao.CldsDao;
34 import org.onap.clamp.clds.model.prop.ModelProperties;
35 import org.onap.clamp.clds.model.refprop.RefProp;
36 import org.onap.clamp.clds.transform.XslTransformer;
37 import org.apache.commons.lang3.StringUtils;
38 import org.camunda.bpm.engine.RuntimeService;
39 import org.camunda.bpm.engine.runtime.ProcessInstance;
40 import org.jboss.resteasy.spi.BadRequestException;
41 import org.onap.clamp.clds.model.*;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.beans.factory.annotation.Value;
46 import org.springframework.context.ApplicationContext;
47 import org.springframework.core.io.Resource;
48
49 import javax.ws.rs.*;
50 import javax.ws.rs.core.MediaType;
51 import javax.xml.transform.TransformerConfigurationException;
52 import javax.xml.transform.TransformerException;
53 import java.io.IOException;
54 import java.util.HashMap;
55 import java.util.List;
56 import java.util.Map;
57 import java.util.Properties;
58
59 /**
60  * Service to save and retrieve the CLDS model attributes.
61  */
62 @AjscService
63 @Path("/clds")
64 public class CldsService extends SecureServiceBase {
65
66     @Autowired
67     private ApplicationContext appContext;
68
69     private static final Logger logger = LoggerFactory.getLogger(CldsService.class);
70
71     @Value("${CLDS_PERMISSION_TYPE_CL:org.onap.clamp.clds.cl}")
72     private static String CLDS_PERMISSION_TYPE_CL;
73
74     @Value("${CLDS_PERMISSION_TYPE_CL_MANAGE:org.onap.clamp.clds.cl.manage}")
75     private static String CLDS_PERMISSION_TYPE_CL_MANAGE;
76
77     @Value("${CLDS_PERMISSION_TYPE_CL_EVENT:/META-INF/securityFilterRules.json}")
78     private static String CLDS_PERMISSION_TYPE_CL_EVENT;
79
80     @Value("${CLDS_PERMISSION_TYPE_FILTER_VF:/META-INF/securityFilterRules.json}")
81     private static String CLDS_PERMISSION_TYPE_FILTER_VF;
82
83     @Value("${CLDS_PERMISSION_INSTANCE:/META-INF/securityFilterRules.json}")
84     private static String CLDS_PERMISSION_INSTANCE;
85
86     private static final SecureServicePermission PERMISSION_READ_CL = SecureServicePermission.create(CLDS_PERMISSION_TYPE_CL, CLDS_PERMISSION_INSTANCE, "read");
87
88     private static final SecureServicePermission PERMISSION_UPDATE_CL = SecureServicePermission.create(CLDS_PERMISSION_TYPE_CL, CLDS_PERMISSION_INSTANCE, "update");
89
90     @Value("${org.onap.clamp.config.files.globalClds:classpath:/clds/globalClds.properties}")
91     private String globalClds;
92     private Properties globalCldsProperties;
93
94     @Autowired
95     private CldsDao cldsDao;
96     @Autowired
97     private RuntimeService runtimeService;
98     @Autowired
99     private XslTransformer cldsBpmnTransformer;
100
101     @Autowired
102     private RefProp refProp;
103
104     @Autowired
105     private SdcCatalogServices asdcCatalogServices;
106     //
107
108     public CldsService() {
109     }
110
111     public CldsService(RefProp refProp) {
112         this.refProp = refProp;
113     }
114
115     /**
116      * REST service that retrieves BPMN for a CLDS model name from the database.
117      * This is subset of the json getModel.
118      * This is only expected to be used for testing purposes, not by the UI.
119      *
120      * @param modelName
121      * @return bpmn xml text - content of bpmn given name
122      */
123     @GET
124     @Path("/model/bpmn/{modelName}")
125     @Produces(MediaType.TEXT_XML)
126     public String getBpmnXml(@PathParam("modelName") String modelName) {
127         isAuthorized(PERMISSION_READ_CL);
128         logger.info("GET bpmnText for modelName={}", modelName);
129         CldsModel model = CldsModel.retrieve(cldsDao, modelName, false);
130         return model.getBpmnText();
131     }
132
133     /**
134      * REST service that saves BPMN for a CLDS model by name in the database.
135      * This is subset of the json putModel.
136      * This is only expected to be used for testing purposes, not by the UI.
137      *
138      * @param modelName
139      */
140     @PUT
141     @Path("/model/bpmn/{modelName}")
142     @Consumes(MediaType.TEXT_XML)
143     public String putBpmnXml(@PathParam("modelName") String modelName, String bpmnText) {
144         isAuthorized(PERMISSION_UPDATE_CL);
145         logger.info("PUT bpmnText for modelName={}", modelName);
146         logger.info("PUT bpmnText={}", bpmnText);
147         CldsModel cldsModel = CldsModel.retrieve(cldsDao, modelName, true);
148         cldsModel.setBpmnText(bpmnText);
149         cldsModel.save(cldsDao, getUserid());
150         return "wrote bpmnText for modelName=" + modelName;
151     }
152
153     /**
154      * REST service that retrieves image for a CLDS model name from the database.
155      * This is subset of the json getModel.
156      * This is only expected to be used for testing purposes, not by the UI.
157      *
158      * @param modelName
159      * @return image xml text - content of image given name
160      */
161     @GET
162     @Path("/model/image/{modelName}")
163     @Produces(MediaType.TEXT_XML)
164     public String getImageXml(@PathParam("modelName") String modelName) {
165         isAuthorized(PERMISSION_READ_CL);
166         logger.info("GET imageText for modelName={}", modelName);
167         CldsModel model = CldsModel.retrieve(cldsDao, modelName, false);
168         return model.getImageText();
169     }
170
171     /**
172      * REST service that saves image for a CLDS model by name in the database.
173      * This is subset of the json putModel.
174      * This is only expected to be used for testing purposes, not by the UI.
175      *
176      * @param modelName
177      */
178     @PUT
179     @Path("/model/image/{modelName}")
180     @Consumes(MediaType.TEXT_XML)
181     public String putImageXml(@PathParam("modelName") String modelName, String imageText) {
182         isAuthorized(PERMISSION_UPDATE_CL);
183         logger.info("PUT iamgeText for modelName={}", modelName);
184         logger.info("PUT imageText={}", imageText);
185         CldsModel cldsModel = CldsModel.retrieve(cldsDao, modelName, true);
186         cldsModel.setImageText(imageText);
187         cldsModel.save(cldsDao, getUserid());
188         return "wrote imageText for modelName=" + modelName;
189     }
190
191     /**
192      * REST service that retrieves a CLDS model by name from the database.
193      *
194      * @param modelName
195      * @return clds model - clds model for the given model name
196      * @throws NotAuthorizedException
197      */
198     @GET
199     @Path("/model/{modelName}")
200     @Produces(MediaType.APPLICATION_JSON)
201     public CldsModel getModel(@PathParam("modelName") String modelName) throws NotAuthorizedException {
202         isAuthorized(PERMISSION_READ_CL);
203         logger.debug("GET model for  modelName={}", modelName);
204         CldsModel cldsModel = CldsModel.retrieve(cldsDao, modelName, false);
205         isAuthorizedForVf(cldsModel);
206         return cldsModel;
207     }
208
209     /**
210      * REST service that saves a CLDS model by name in the database.
211      *
212      * @param modelName
213      * @throws TransformerException
214      * @throws TransformerConfigurationException
215      */
216     @PUT
217     @Path("/model/{modelName}")
218     @Consumes(MediaType.APPLICATION_JSON)
219     @Produces(MediaType.APPLICATION_JSON)
220     public CldsModel putModel(@PathParam("modelName") String modelName, CldsModel cldsModel) throws TransformerException {
221         isAuthorized(PERMISSION_UPDATE_CL);
222         isAuthorizedForVf(cldsModel);
223         logger.info("PUT model for  modelName={}", modelName);
224         logger.info("PUT bpmnText={}", cldsModel.getBpmnText());
225         logger.info("PUT propText={}", cldsModel.getPropText());
226         logger.info("PUT imageText={}", cldsModel.getImageText());
227         cldsModel.setName(modelName);
228
229         if (cldsModel.getTemplateName() != null) {
230             CldsTemplate template = cldsDao.getTemplate(cldsModel.getTemplateName());
231             if (template != null) {
232                 cldsModel.setTemplateId(template.getId());
233                 cldsModel.setDocText(template.getPropText());
234                 cldsModel.setDocId(template.getPropId());
235             }
236         }
237         cldsModel.save(cldsDao, getUserid());
238         return cldsModel;
239     }
240
241     /**
242      * REST service that retrieves a list of CLDS model names.
243      *
244      * @return model names in JSON
245      */
246     @GET
247     @Path("/model-names")
248     @Produces(MediaType.APPLICATION_JSON)
249     public List<ValueItem> getModelNames() {
250 //              isAuthorized(PERMISSION_READ_CL);
251         logger.info("GET list of model names");
252         return cldsDao.getBpmnNames();
253     }
254
255     /**
256      * REST service that saves and processes an action for a CLDS model by name.
257      *
258      * @param action
259      * @param modelName
260      * @param test
261      * @param model
262      * @return
263      * @throws TransformerConfigurationException
264      * @throws TransformerException
265      * @throws IOException
266      * @throws JsonProcessingException
267      * @throws NotAuthorizedException
268      */
269     @PUT
270     @Path("/action/{action}/{modelName}")
271     @Consumes(MediaType.APPLICATION_JSON)
272     @Produces(MediaType.APPLICATION_JSON)
273     public CldsModel putModelAndProcessAction(@PathParam("action") String action, @PathParam("modelName") String modelName, @QueryParam("test") String test, CldsModel model) throws TransformerException, NotAuthorizedException, IOException {
274         String actionCd = action.toUpperCase();
275         SecureServicePermission permisionManage = SecureServicePermission.create(CLDS_PERMISSION_TYPE_CL_MANAGE, CLDS_PERMISSION_INSTANCE, actionCd);
276         isAuthorized(permisionManage);
277         isAuthorizedForVf(model);
278         String userid = getUserid();
279         String actionStateCd = CldsEvent.ACTION_STATE_INITIATED;
280         String processDefinitionKey = "clds-process-action-wf";
281
282         logger.info("PUT actionCd={}", actionCd);
283         logger.info("PUT actionStateCd={}", actionStateCd);
284         logger.info("PUT processDefinitionKey={}", processDefinitionKey);
285         logger.info("PUT modelName={}", modelName);
286         logger.info("PUT test={}", test);
287         logger.info("PUT bpmnText={}", model.getBpmnText());
288         logger.info("PUT propText={}", model.getPropText());
289         logger.info("PUT userid={}", userid);
290
291         if (model.getTemplateName() != null) {
292             CldsTemplate template = cldsDao.getTemplate(model.getTemplateName());
293             if (template != null) {
294                 model.setTemplateId(template.getId());
295                 model.setDocText(template.getPropText());
296                 model.setDocId(template.getPropId());
297             }
298         }
299         // save model to db
300         model.setName(modelName);
301         model.save(cldsDao, getUserid());
302
303         // get vars and format if necessary
304         String prop = model.getPropText();
305         String bpmn = model.getBpmnText();
306         String docText = model.getDocText();
307         String controlName = model.getControlName();
308
309         String bpmnJson = cldsBpmnTransformer.doXslTransformToString(bpmn);
310         logger.info("PUT bpmnJson={}", bpmnJson);
311
312         boolean isTest = false;
313         if (test != null && test.equalsIgnoreCase("true")) {
314             isTest = true;
315         } else {
316             // if action.test.override is true, then any action will be marked as test=true (even if incoming action request had test=false); otherwise, test flag will be unchanged on the action request
317             String actionTestOverride = refProp.getStringValue("action.test.override");
318             if (actionTestOverride != null && actionTestOverride.equalsIgnoreCase("true")) {
319                 logger.info("PUT actionTestOverride={}", actionTestOverride);
320                 logger.info("PUT override test indicator and setting it to true");
321                 isTest = true;
322             }
323         }
324         logger.info("PUT isTest={}", isTest);
325
326
327         boolean isInsertTestEvent = false;
328         String insertTestEvent = refProp.getStringValue("action.insert.test.event");
329         if (insertTestEvent != null && insertTestEvent.equalsIgnoreCase("true")) {
330             isInsertTestEvent = true;
331         }
332         logger.info("PUT isInsertTestEvent={}", isInsertTestEvent);
333
334
335         // determine if requested action is permitted
336         model.validateAction(actionCd);
337
338         // input variables to camunda process
339         Map<String, Object> variables = new HashMap<>();
340         variables.put("actionCd", actionCd);
341         variables.put("modelProp", prop);
342         variables.put("modelBpmnProp", bpmnJson);
343         variables.put("modelName", modelName);
344         variables.put("controlName", controlName);
345         variables.put("docText", docText);
346         variables.put("isTest", isTest);
347         variables.put("userid", userid);
348         variables.put("isInsertTestEvent", isInsertTestEvent);
349
350         // start camunda process
351         ProcessInstance pi = runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);
352
353         // log process info
354         logger.info("Started processDefinitionId={}, processInstanceId={}", pi.getProcessDefinitionId(), pi.getProcessInstanceId());
355
356         // refresh model info from db (get fresh event info)
357         return CldsModel.retrieve(cldsDao, modelName, false);
358     }
359
360     /**
361      * REST service that accepts events for a model.
362      *
363      * @param test
364      * @param dcaeEvent
365      * @throws BadRequestException
366      */
367     @POST
368     @Path("/dcae/event")
369     @Consumes(MediaType.APPLICATION_JSON)
370     @Produces(MediaType.APPLICATION_JSON)
371     public String postDcaeEvent(@QueryParam("test") String test, DcaeEvent dcaeEvent) throws BadRequestException {
372         String userid = null;
373         // TODO: allow auth checking to be turned off by removing the permission type property
374         if (CLDS_PERMISSION_TYPE_CL_EVENT != null && CLDS_PERMISSION_TYPE_CL_EVENT.length() > 0) {
375             SecureServicePermission permissionEvent = SecureServicePermission.create(CLDS_PERMISSION_TYPE_CL_EVENT, CLDS_PERMISSION_INSTANCE, dcaeEvent.getEvent());
376             isAuthorized(permissionEvent);
377             userid = getUserid();
378         }
379
380         boolean isTest = false;
381         if (test != null && test.equalsIgnoreCase("true")) {
382             isTest = true;
383         }
384
385         int instanceCount = 0;
386         if (dcaeEvent.getInstances() != null) {
387             instanceCount = dcaeEvent.getInstances().size();
388         }
389         String msgInfo = "event=" + dcaeEvent.getEvent() + " serviceUUID=" + dcaeEvent.getServiceUUID() + " resourceUUID=" + dcaeEvent.getResourceUUID() + " artifactName=" + dcaeEvent.getArtifactName() + " instance count=" + instanceCount + " isTest=" + isTest;
390         logger.info("POST dcae event {}", msgInfo);
391
392         if (isTest) {
393             logger.warn("Ignorning test event from DCAE");
394         } else {
395             if (DcaeEvent.EVENT_DEPLOYMENT.equalsIgnoreCase(dcaeEvent.getEvent())) {
396                 CldsModel.insertModelInstance(cldsDao, dcaeEvent, userid);
397             } else {
398                 CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userid, dcaeEvent.getCldsActionCd(), CldsEvent.ACTION_STATE_RECEIVED, null);
399             }
400             // EVENT_UNDEPLOYMENT is defunct - DCAE Proxy will not undeploy individual instances.  It will send an empty list of
401             // deployed instances to indicate all have been removed.  Or it will send an updated list to indicate those that
402             // are still deployed with any not on the list considered undeployed.
403             //else if(DcaeEvent.EVENT_UNDEPLOYMENT.equalsIgnoreCase(dcaeEvent.getEvent()))
404             //{
405             //  CldsModel.removeModelInstance(cldsDao, dcaeEvent);
406             //}
407         }
408
409         return msgInfo;
410     }
411
412     /**
413      * REST service that retrieves asdc services
414      *
415      * @throws Exception
416      */
417     @GET
418     @Path("/asdc/services")
419     @Produces(MediaType.APPLICATION_JSON)
420     public String getAsdcServices() throws Exception {
421         String retStr;
422         try {
423             String responseStr = asdcCatalogServices.getAsdcServicesInformation(null);
424             retStr = createUiServiceFormatJson(responseStr);
425         } catch (Exception e) {
426             logger.info("{} {}", e.getClass().getName(), e.getMessage());
427             throw e;
428         }
429         logger.info("value of asdcServices : {}", retStr);
430         return retStr;
431     }
432
433     /**
434      * REST service that retrieves total properties required by UI
435      *
436      * @throws Exception
437      */
438     @GET
439     @Path("/properties")
440     @Produces(MediaType.APPLICATION_JSON)
441     public String getAsdcProperties() throws Exception {
442         return createPropertiesObjectByUUID(getGlobalCldsString(), "{}");
443     }
444
445     /**
446      * REST service that retrieves total properties by using invariantUUID based on refresh and non refresh
447      *
448      * @throws Exception
449      */
450     @GET
451     @Path("/properties/{serviceInvariantUUID}")
452     @Produces(MediaType.APPLICATION_JSON)
453     public String getAsdcPropertiesByServiceUUIDForRefresh(@PathParam("serviceInvariantUUID") String serviceInvariantUUID, @DefaultValue("false") @QueryParam("refresh") String refresh) throws Exception {
454         CldsServiceData cldsServiceData = new CldsServiceData();
455         cldsServiceData.setServiceInvariantUUID(serviceInvariantUUID);
456
457         boolean isCldsAsdcDataExpired = true;
458         //  To getcldsService information from database cache using invariantUUID only when refresh = false
459         if (refresh != null && refresh.equalsIgnoreCase("false")) {
460             cldsServiceData = cldsServiceData.getCldsServiceCache(cldsDao, serviceInvariantUUID);
461             // If cldsService is available in database Cache , verify is data expired or not
462             if (cldsServiceData != null) {
463                 isCldsAsdcDataExpired = asdcCatalogServices.isCldsAsdcCacheDataExpired(cldsServiceData);
464             }
465         }
466         // If user Requested for refresh or database cache expired , get all data from asdc api.
467         if ((refresh != null && refresh.equalsIgnoreCase("true")) || isCldsAsdcDataExpired) {
468             cldsServiceData = asdcCatalogServices.getCldsServiceDataWithAlarmConditions(serviceInvariantUUID);
469             CldsDBServiceCache cldsDBServiceCache = asdcCatalogServices.getCldsDBServiceCacheUsingCldsServiceData(cldsServiceData);
470             if (cldsDBServiceCache != null && cldsDBServiceCache.getInvariantId() != null && cldsDBServiceCache.getServiceId() != null) {
471                 cldsServiceData.setCldsServiceCache(cldsDao, cldsDBServiceCache);
472             }
473         }
474
475         // filter out VFs the user is not authorized for
476         cldsServiceData.filterVfs(this);
477
478         // format retrieved data into properties json
479         return asdcCatalogServices.createPropertiesObjectByUUID(getGlobalCldsString(), cldsServiceData);
480     }
481
482     /**
483      * Determine if the user is authorized for a particular VF by its invariant UUID.
484      *
485      * @param vfInvariantUuid
486      * @throws NotAuthorizedException
487      * @return
488      */
489     public boolean isAuthorizedForVf(String vfInvariantUuid) throws NotAuthorizedException {
490         if (CLDS_PERMISSION_TYPE_FILTER_VF != null && CLDS_PERMISSION_TYPE_FILTER_VF.length() > 0) {
491             SecureServicePermission permission = SecureServicePermission.create(CLDS_PERMISSION_TYPE_FILTER_VF, CLDS_PERMISSION_INSTANCE, vfInvariantUuid);
492             return isAuthorized(permission);
493         } else {
494             // if CLDS_PERMISSION_TYPE_FILTER_VF property is not provided, then VF filtering is turned off
495             logger.warn("VF filtering turned off");
496             return true;
497         }
498     }
499
500     /**
501      * Determine if the user is authorized for a particular VF by its invariant UUID.
502      * If not authorized, then NotAuthorizedException is thrown.
503      *
504      * @param model
505      * @return
506      */
507     private boolean isAuthorizedForVf(CldsModel model) throws NotAuthorizedException {
508         String vf = ModelProperties.getVf(model);
509         if (vf == null || vf.length() == 0) {
510             logger.info("VF not found in model");
511             return true;
512         } else {
513             return isAuthorizedForVf(vf);
514         }
515     }
516
517     private String createUiServiceFormatJson(String responseStr) throws IOException {
518         if (StringUtils.isBlank(responseStr)) {
519             return "";
520         }
521         ObjectMapper objectMapper = new ObjectMapper();
522         List<CldsAsdcServiceInfo> rawList = objectMapper.readValue(responseStr, objectMapper.getTypeFactory().constructCollectionType(List.class, CldsAsdcServiceInfo.class));
523         ObjectNode invariantIdServiceNode = objectMapper.createObjectNode();
524         ObjectNode serviceNode = objectMapper.createObjectNode();
525         logger.info("value of cldsserviceiNfolist: {}", rawList);
526         if (rawList != null && rawList.size() > 0) {
527             List<CldsAsdcServiceInfo> cldsAsdcServiceInfoList = asdcCatalogServices.removeDuplicateServices(rawList);
528
529             for (CldsAsdcServiceInfo currCldsAsdcServiceInfo : cldsAsdcServiceInfoList) {
530                 if (currCldsAsdcServiceInfo != null) {
531                     invariantIdServiceNode.put(currCldsAsdcServiceInfo.getInvariantUUID(), currCldsAsdcServiceInfo.getName());
532                 }
533             }
534             serviceNode.putPOJO("service", invariantIdServiceNode);
535         }
536         return serviceNode.toString();
537     }
538
539     private String createPropertiesObjectByUUID(String globalProps, String cldsResponseStr) throws IOException {
540         ObjectMapper mapper = new ObjectMapper();
541         CldsAsdcServiceDetail cldsAsdcServiceDetail = mapper.readValue(cldsResponseStr, CldsAsdcServiceDetail.class);
542         ObjectNode globalPropsJson = null;
543         if (cldsAsdcServiceDetail != null && cldsAsdcServiceDetail.getUuid() != null) {
544             /**
545              * to create json with vf, alarm and locations
546              */
547             ObjectNode serviceObjectNode = createEmptyVfAlarmObject(mapper);
548             ObjectNode vfObjectNode = mapper.createObjectNode();
549
550             /**
551              * to create json with vf and vfresourceId
552              */
553             createVfObjectNode(vfObjectNode, mapper, cldsAsdcServiceDetail.getResources());
554             serviceObjectNode.putPOJO(cldsAsdcServiceDetail.getInvariantUUID(), vfObjectNode);
555             ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
556             byServiceBasicObjetNode.putPOJO("byService", serviceObjectNode);
557
558             /**
559              * to create json with VFC Node
560              */
561             ObjectNode emptyvfcobjectNode = createByVFCObjectNode(mapper, cldsAsdcServiceDetail.getResources());
562             byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode);
563             globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
564             globalPropsJson.putPOJO("shared", byServiceBasicObjetNode);
565             logger.info("valuie of objNode: {}", globalPropsJson);
566         } else {
567             /**
568              *  to create json with total properties when no serviceUUID passed
569              */
570             globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
571         }
572         return globalPropsJson.toString();
573     }
574
575     private ObjectNode createEmptyVfAlarmObject(ObjectMapper mapper) {
576         ObjectNode emptyObjectNode = mapper.createObjectNode();
577         emptyObjectNode.put("", "");
578         ObjectNode vfObjectNode = mapper.createObjectNode();
579         vfObjectNode.putPOJO("vf", emptyObjectNode);
580         vfObjectNode.putPOJO("location", emptyObjectNode);
581         vfObjectNode.putPOJO("alarmCondition", emptyObjectNode);
582         ObjectNode emptyServiceObjectNode = mapper.createObjectNode();
583         emptyServiceObjectNode.putPOJO("", vfObjectNode);
584         return emptyServiceObjectNode;
585     }
586
587     private void createVfObjectNode(ObjectNode vfObjectNode2, ObjectMapper mapper, List<CldsAsdcResource> rawCldsAsdcResourceList) throws IOException {
588         ObjectNode vfNode = mapper.createObjectNode();
589         vfNode.put("", "");
590
591         // To remove repeated resource instance name from resourceInstanceList
592         List<CldsAsdcResource> cldsAsdcResourceList = asdcCatalogServices.removeDuplicateAsdcResourceInstances(rawCldsAsdcResourceList);
593         /**
594          * Creating vf resource node using cldsAsdcResource Object
595          */
596         if (cldsAsdcResourceList != null && cldsAsdcResourceList.size() > 0) {
597             for (CldsAsdcResource cldsAsdcResource : cldsAsdcResourceList) {
598                 if (cldsAsdcResource != null && cldsAsdcResource.getResoucreType() != null && cldsAsdcResource.getResoucreType().equalsIgnoreCase("VF")) {
599                     vfNode.put(cldsAsdcResource.getResourceUUID(), cldsAsdcResource.getResourceName());
600                 }
601             }
602         }
603         vfObjectNode2.putPOJO("vf", vfNode);
604         String locationStringValue = refProp.getStringValue("ui.location.default");
605         String alarmStringValue = refProp.getStringValue("ui.alarm.default");
606
607         /**
608          *  creating location json object using properties file value
609          */
610         ObjectNode locationJsonNode = (ObjectNode) mapper.readValue(locationStringValue, JsonNode.class);
611         vfObjectNode2.putPOJO("location", locationJsonNode);
612
613         /**
614          * creating alarm json object using properties file value
615          */
616         logger.info("value of alarm: {}", alarmStringValue);
617         ObjectNode alarmStringJsonNode = (ObjectNode) mapper.readValue(alarmStringValue, JsonNode.class);
618         vfObjectNode2.putPOJO("alarmCondition", alarmStringJsonNode);
619     }
620
621     private ObjectNode createByVFCObjectNode(ObjectMapper mapper, List<CldsAsdcResource> cldsAsdcResourceList) {
622         ObjectNode emptyObjectNode = mapper.createObjectNode();
623         ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
624         ObjectNode vfCObjectNode = mapper.createObjectNode();
625         vfCObjectNode.putPOJO("vfC", emptyObjectNode);
626         ObjectNode subVfCObjectNode = mapper.createObjectNode();
627         subVfCObjectNode.putPOJO("vfc", emptyObjectNode);
628         if (cldsAsdcResourceList != null && cldsAsdcResourceList.size() > 0) {
629             for (CldsAsdcResource cldsAsdcResource : cldsAsdcResourceList) {
630                 if (cldsAsdcResource != null && cldsAsdcResource.getResoucreType() != null && cldsAsdcResource.getResoucreType().equalsIgnoreCase("VF")) {
631                     vfCObjectNode.putPOJO(cldsAsdcResource.getResourceUUID(), subVfCObjectNode);
632                 }
633             }
634         }
635         emptyvfcobjectNode.putPOJO("", vfCObjectNode);
636         return emptyvfcobjectNode;
637     }
638     
639     private String getGlobalCldsString() throws Exception {
640         if  (null == globalCldsProperties) {
641             globalCldsProperties = new Properties();
642             globalCldsProperties.load(appContext.getResource(globalClds).getInputStream());
643         }
644         return (String) globalCldsProperties.get("globalCldsProps");
645     }
646 }