2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.clds.service;
26 import java.util.Date;
27 import java.util.List;
29 import javax.annotation.PostConstruct;
31 import org.onap.clamp.clds.dao.CldsDao;
32 import org.onap.clamp.clds.model.CldsTemplate;
33 import org.onap.clamp.clds.model.ValueItem;
34 import org.onap.clamp.clds.util.LoggingUtils;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.beans.factory.annotation.Value;
37 import org.springframework.stereotype.Component;
40 * Service to save and retrieve the CLDS model attributes.
43 public class CldsTemplateService extends SecureServiceBase {
45 @Value("${clamp.config.security.permission.type.template:permission-type-template}")
46 private String cldsPermissionTypeTemplate;
47 @Value("${clamp.config.security.permission.instance:dev}")
48 private String cldsPermissionInstance;
49 private SecureServicePermission permissionReadTemplate;
50 private SecureServicePermission permissionUpdateTemplate;
53 private final void afterConstruction() {
54 permissionReadTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance,
56 permissionUpdateTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance,
61 private CldsDao cldsDao;
64 * REST service that retrieves BPMN for a CLDS template name from the
65 * database. This is subset of the json getModel. This is only expected to
66 * be used for testing purposes, not by the UI.
69 * @return bpmn xml text - content of bpmn given name
71 public String getBpmnTemplate(String templateName) {
72 Date startTime = new Date();
73 LoggingUtils.setRequestContext("CldsTemplateService: GET template bpmn", getPrincipalName());
74 isAuthorized(permissionReadTemplate);
75 logger.info("GET bpmnText for templateName=" + templateName);
76 CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false);
78 LoggingUtils.setTimeContext(startTime, new Date());
79 LoggingUtils.setResponseContext("0", "Get template bpmn success", this.getClass().getName());
80 auditLogger.info("GET template bpmn completed");
81 return template.getBpmnText();
85 * REST service that retrieves image for a CLDS template name from the
86 * database. This is subset of the json getModel. This is only expected to
87 * be used for testing purposes, not by the UI.
90 * @return image xml text - content of image given name
92 public String getImageXml(String templateName) {
93 Date startTime = new Date();
94 LoggingUtils.setRequestContext("CldsTemplateService: GET template image", getPrincipalName());
95 isAuthorized(permissionReadTemplate);
96 logger.info("GET imageText for templateName=" + templateName);
97 CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false);
99 LoggingUtils.setTimeContext(startTime, new Date());
100 LoggingUtils.setResponseContext("0", "Get template image success", this.getClass().getName());
101 auditLogger.info("GET template image completed");
102 return template.getImageText();
106 * REST service that retrieves a CLDS template by name from the database.
108 * @param templateName
109 * @return clds template - clds template for the given template name
111 public CldsTemplate getTemplate(String templateName) {
112 Date startTime = new Date();
113 LoggingUtils.setRequestContext("CldsTemplateService: GET template", getPrincipalName());
114 isAuthorized(permissionReadTemplate);
115 logger.info("GET model for templateName=" + templateName);
116 CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false);
117 template.setUserAuthorizedToUpdate(isAuthorizedNoException(permissionUpdateTemplate));
119 LoggingUtils.setTimeContext(startTime, new Date());
120 LoggingUtils.setResponseContext("0", "Get template success", this.getClass().getName());
121 auditLogger.info("GET template completed");
126 * REST service that saves a CLDS template by name in the database.
128 * @param templateName
129 * @param cldsTemplate
130 * @return The CldsTemplate modified and saved in DB
132 public CldsTemplate putTemplate(String templateName, CldsTemplate cldsTemplate) {
133 Date startTime = new Date();
134 LoggingUtils.setRequestContext("CldsTemplateService: PUT template", getPrincipalName());
135 isAuthorized(permissionUpdateTemplate);
136 logger.info("PUT Template for templateName=" + templateName);
137 logger.info("PUT bpmnText=" + cldsTemplate.getBpmnText());
138 logger.info("PUT propText=" + cldsTemplate.getPropText());
139 logger.info("PUT imageText=" + cldsTemplate.getImageText());
140 cldsTemplate.setName(templateName);
141 cldsTemplate.save(cldsDao, null);
143 LoggingUtils.setTimeContext(startTime, new Date());
144 LoggingUtils.setResponseContext("0", "Put template success", this.getClass().getName());
145 auditLogger.info("PUT template completed");
150 * REST service that retrieves a list of CLDS template names.
152 * @return template names in JSON
154 public List<ValueItem> getTemplateNames() {
155 Date startTime = new Date();
156 LoggingUtils.setRequestContext("CldsTemplateService: GET template names", getPrincipalName());
157 isAuthorized(permissionReadTemplate);
158 logger.info("GET list of template names");
159 List<ValueItem> names = cldsDao.getTemplateNames();
161 LoggingUtils.setTimeContext(startTime, new Date());
162 LoggingUtils.setResponseContext("0", "Get template names success", this.getClass().getName());
163 auditLogger.info("GET template names completed");