aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorXue Gao <xg353y@intl.att.com>2019-06-18 12:43:58 +0000
committerGerrit Code Review <gerrit@onap.org>2019-06-18 12:43:58 +0000
commit87dd6b9a1680c31a736164b29e2b663a27fbe2a7 (patch)
treee3fcddfb6126c80eca2cc9b3b70c8e1c3283ca65 /src/main
parenteb216ac66f47c2b9d2b69a6e080d3969f75d78af (diff)
parentbd60a90dedf1dbc0052b6e1a1d20010640cc15a0 (diff)
Merge "Fixed Checkstyle issues"
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/clamp/clds/ClampServlet.java7
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/DistributionStatusMessage.java26
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java7
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java1
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java4
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java16
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java30
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsService.java26
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java53
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsToscaService.java48
-rw-r--r--src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java17
12 files changed, 124 insertions, 113 deletions
diff --git a/src/main/java/org/onap/clamp/clds/ClampServlet.java b/src/main/java/org/onap/clamp/clds/ClampServlet.java
index 86524d1c6..54aa95e5d 100644
--- a/src/main/java/org/onap/clamp/clds/ClampServlet.java
+++ b/src/main/java/org/onap/clamp/clds/ClampServlet.java
@@ -32,6 +32,7 @@ import java.io.IOException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.List;
+
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -101,8 +102,8 @@ public class ClampServlet extends CamelHttpTransportServlet {
permissionList.add(SecureServicePermission
.create(applicationContext.getEnvironment().getProperty(PERM_TOSCA), cldsPermissionInstance, READ));
permissionList.add(SecureServicePermission
- .create(applicationContext.getEnvironment().getProperty(PERM_TOSCA), cldsPermissionInstance,
- UPDATE));
+ .create(applicationContext.getEnvironment().getProperty(PERM_TOSCA),
+ cldsPermissionInstance, UPDATE));
}
return permissionList;
}
@@ -139,4 +140,4 @@ public class ClampServlet extends CamelHttpTransportServlet {
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/DistributionStatusMessage.java b/src/main/java/org/onap/clamp/clds/sdc/controller/DistributionStatusMessage.java
index d32c4a179..06c77252c 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/DistributionStatusMessage.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/DistributionStatusMessage.java
@@ -34,13 +34,27 @@ public class DistributionStatusMessage implements IDistributionStatusMessage {
private DistributionStatusEnum distributionStatus;
private long timestamp;
+ /**
+ * Distribution status message constructor.
+ *
+ * @param artifactUrl
+ * Url of specific SDC artifact(resource)
+ * @param consumerId
+ * Unique ID of SDC component instance
+ * @param distributionId
+ * Distribution ID published in the distribution notification.
+ * @param distributionStatusEnum
+ * Status to send in the message
+ * @param timestamp
+ * Timestamp of the message
+ */
public DistributionStatusMessage(final String artifactUrl, final String consumerId, final String distributionId,
- final DistributionStatusEnum distributionStatusEnum, final long timestampL) {
- artifactURL = artifactUrl;
- consumerID = consumerId;
- distributionID = distributionId;
- distributionStatus = distributionStatusEnum;
- timestamp = timestampL;
+ final DistributionStatusEnum distributionStatusEnum, final long timestamp) {
+ this.artifactURL = artifactUrl;
+ this.consumerID = consumerId;
+ this.distributionID = distributionId;
+ this.distributionStatus = distributionStatusEnum;
+ this.timestamp = timestamp;
}
@Override
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
index 729ef496e..20e13bc7c 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
@@ -38,7 +38,6 @@ import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcDownloadException;
-import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;
import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;
import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller;
@@ -348,8 +347,8 @@ public class SdcSingleController {
return downloadResult;
}
- private void sendSdcNotification(NotificationType notificationType, String artifactUrl, String consumerID,
- String distributionID, DistributionStatusEnum status, String errorReason,
+ private void sendSdcNotification(NotificationType notificationType, String artifactUrl, String consumerId,
+ String distributionId, DistributionStatusEnum status, String errorReason,
long timestamp) {
String event = "Sending " + notificationType.name() + "(" + status.name() + ")"
+ " notification to SDC for artifact:" + artifactUrl;
@@ -359,7 +358,7 @@ public class SdcSingleController {
logger.info(event);
String action = "";
try {
- IDistributionStatusMessage message = new DistributionStatusMessage(artifactUrl, consumerID, distributionID,
+ IDistributionStatusMessage message = new DistributionStatusMessage(artifactUrl, consumerId, distributionId,
status, timestamp);
switch (notificationType) {
case DOWNLOAD:
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java
index 27c5b9cbd..8b555fca1 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java
@@ -20,6 +20,7 @@
* ===================================================================
*
*/
+
package org.onap.clamp.clds.sdc.controller.installer;
import java.util.LinkedList;
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
index 7ef217b4e..f78b9d32d 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
@@ -86,8 +86,8 @@ public class CsarHandler {
return clampCsarPath + "/" + controllerName + "/" + artifactElement.getArtifactName();
}
- private IArtifactInfo searchForUniqueCsar(INotificationData iNotif) throws CsarHandlerException {
- List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts();
+ private IArtifactInfo searchForUniqueCsar(INotificationData notificationData) throws CsarHandlerException {
+ List<IArtifactInfo> serviceArtifacts = notificationData.getServiceArtifacts();
for (IArtifactInfo artifact : serviceArtifacts) {
if (artifact.getArtifactType().equals(CSAR_TYPE)) {
return artifact;
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
index 6c41e9c66..441a7ac11 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
@@ -207,7 +207,7 @@ public class CsarInstallerImpl implements CsarInstaller {
}
private void createPolicyModel(CsarHandler csar) throws PolicyModelException {
- try{
+ try {
Optional<String> policyModelYaml = csar.getPolicyModelYaml();
// save policy model into the database
} catch (IOException e) {
@@ -228,8 +228,8 @@ public class CsarInstallerImpl implements CsarInstaller {
if (policyName != null) {
policyNameList.add(filteredPolicyName);
} else {
- String inputPolicyName = (String) ((Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) ef
- .getValue()).get("properties")).get("policy_id")).get(GET_INPUT_BLUEPRINT_PARAM);
+ String inputPolicyName = (String) ((Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>)
+ ef.getValue()).get("properties")).get("policy_id")).get(GET_INPUT_BLUEPRINT_PARAM);
if (inputPolicyName != null) {
policyNameList.add(GET_INPUT_BLUEPRINT_PARAM);
}
@@ -249,7 +249,7 @@ public class CsarInstallerImpl implements CsarInstaller {
/**
* This call must be done when deploying the SDC notification as this call get
- * the latest version of the artifact (version can be specified to DCAE call)
+ * the latest version of the artifact (version can be specified to DCAE call).
*
* @return The DcaeInventoryResponse object containing the dcae values
*/
@@ -263,9 +263,10 @@ public class CsarInstallerImpl implements CsarInstaller {
private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintArtifact blueprintArtifact,
BlueprintParserFilesConfiguration configFiles) throws IOException, SdcArtifactInstallerException {
- Set<MicroService> microServicesFromBlueprint = blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint()) ;
+ Set<MicroService> microServicesFromBlueprint = blueprintParser.getMicroServices(
+ blueprintArtifact.getDcaeBlueprint()) ;
List<MicroService> microServicesChain = chainGenerator.getChainOfMicroServices(microServicesFromBlueprint);
- if(microServicesChain.isEmpty()) {
+ if (microServicesChain.isEmpty()) {
microServicesChain = blueprintParser.fallbackToOneMicroService(blueprintArtifact.getDcaeBlueprint());
}
String imageText = svgFacade.getSvgImage(microServicesChain);
@@ -290,7 +291,8 @@ public class CsarInstallerImpl implements CsarInstaller {
if (dcaeInventoryResponse == null) {
throw new SdcArtifactInstallerException(
- "DCAE inventory response is NULL, query to DCAE fail to be answered properly, this is required to deploy CSAR properly !!!");
+ "DCAE inventory response is NULL, query to DCAE fail to be answered properly, "
+ + "this is required to deploy CSAR properly !!!");
}
try {
CldsModel cldsModel = new CldsModel();
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
index 9bc7a022a..5bbc980c9 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
@@ -75,7 +75,7 @@ public class MicroService {
}
MicroService that = (MicroService) o;
return name.equals(that.name) && modelType.equals(that.modelType) && inputFrom.equals(that.inputFrom)
- && mappedNameJpa.equals(that.mappedNameJpa);
+ && mappedNameJpa.equals(that.mappedNameJpa);
}
@Override
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java b/src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java
index 76417132b..c228e171a 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java
@@ -5,6 +5,8 @@
* Copyright (C) 2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -53,9 +55,9 @@ public class CldsDictionaryService extends SecureServiceBase {
@Autowired
private CldsDao cldsDao;
-
+
private LoggingUtils util = new LoggingUtils(logger);
-
+
@PostConstruct
private final void initConstruct() {
@@ -73,7 +75,7 @@ public class CldsDictionaryService extends SecureServiceBase {
*/
public ResponseEntity<CldsDictionary> createOrUpdateDictionary(String dictionaryName,
CldsDictionary cldsDictionary) {
- Date startTime = new Date();
+ final Date startTime = new Date();
LoggingUtils.setRequestContext("CldsDictionaryService: createOrUpdateDictionary", getPrincipalName());
// TODO revisit based on new permissions
isAuthorized(permissionUpdateTosca);
@@ -82,9 +84,7 @@ public class CldsDictionaryService extends SecureServiceBase {
cldsDictionary.setDictionaryName(dictionaryName);
}
cldsDictionary.save(dictionaryName, cldsDao, getUserId());
- LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "createOrUpdateDictionary success", this.getClass().getName());
- auditLogger.info("createOrUpdateDictionary completed");
+ auditLogInfo("createOrUpdateDictionary", startTime);
return new ResponseEntity<>(cldsDictionary, HttpStatus.OK);
}
@@ -99,14 +99,12 @@ public class CldsDictionaryService extends SecureServiceBase {
*/
public ResponseEntity<CldsDictionaryItem> createOrUpdateDictionaryElements(String dictionaryName,
CldsDictionaryItem dictionaryItem) {
- Date startTime = new Date();
+ final Date startTime = new Date();
LoggingUtils.setRequestContext("CldsDictionaryService: createOrUpdateDictionaryElements", getPrincipalName());
// TODO revisit based on new permissions
isAuthorized(permissionUpdateTosca);
dictionaryItem.save(dictionaryName, cldsDao, getUserId());
- LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "createOrUpdateDictionaryElements success", this.getClass().getName());
- auditLogger.info("createOrUpdateDictionaryElements completed");
+ auditLogInfo("createOrUpdateDictionaryElements", startTime);
return new ResponseEntity<>(dictionaryItem, HttpStatus.OK);
}
@@ -116,14 +114,12 @@ public class CldsDictionaryService extends SecureServiceBase {
* @return CldsDictionary List List of CldsDictionary available in DB
*/
public ResponseEntity<List<CldsDictionary>> getAllDictionaryNames() {
- Date startTime = new Date();
+ final Date startTime = new Date();
LoggingUtils.setRequestContext("CldsDictionaryService: getAllDictionaryNames", getPrincipalName());
// TODO revisit based on new permissions
isAuthorized(permissionReadTosca);
List<CldsDictionary> dictionaries = cldsDao.getDictionary(null, null);
- LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "getAllDictionaryNames success", this.getClass().getName());
- auditLogger.info("getAllDictionaryNames completed");
+ auditLogInfo("getAllDictionaryNames", startTime);
return new ResponseEntity<>(dictionaries, HttpStatus.OK);
}
@@ -136,14 +132,12 @@ public class CldsDictionaryService extends SecureServiceBase {
* dictionary name
*/
public ResponseEntity<List<CldsDictionaryItem>> getDictionaryElementsByName(String dictionaryName) {
- Date startTime = new Date();
+ final Date startTime = new Date();
LoggingUtils.setRequestContext("CldsDictionaryService: getDictionaryElementsByName", getPrincipalName());
// TODO revisit based on new permissions
isAuthorized(permissionReadTosca);
List<CldsDictionaryItem> dictionaryItems = cldsDao.getDictionaryElements(dictionaryName, null, null);
- LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "getAllDictionaryNames success", this.getClass().getName());
- auditLogger.info("getAllDictionaryNames completed");
+ auditLogInfo("getDictionaryElementsByName", startTime);
return new ResponseEntity<>(dictionaryItems, HttpStatus.OK);
}
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java
index 63a913314..d9956e3ad 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java
@@ -204,8 +204,10 @@ public class CldsService extends SecureServiceBase {
*/
public List<CldsMonitoringDetails> getCldsDetails() {
util.entering(request, "CldsService: GET model details");
- Date startTime = new Date();
- final List<CldsMonitoringDetails> cldsMonitoringDetailsList = cldsDao.getCldsMonitoringDetails();
+
+ final Date startTime = new Date();
+ List<CldsMonitoringDetails> cldsMonitoringDetailsList = cldsDao.getCldsMonitoringDetails();
+
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
auditLogger.info("GET cldsDetails completed");
@@ -221,7 +223,7 @@ public class CldsService extends SecureServiceBase {
*/
public CldsInfo getCldsInfo() {
util.entering(request, "CldsService: GET cldsInfo");
- Date startTime = new Date();
+ final Date startTime = new Date();
LoggingUtils.setTimeContext(startTime, new Date());
CldsInfoProvider cldsInfoProvider = new CldsInfoProvider(this);
@@ -244,7 +246,7 @@ public class CldsService extends SecureServiceBase {
*/
public String getBpmnXml(String modelName) {
util.entering(request, "CldsService: GET model bpmn");
- Date startTime = new Date();
+ final Date startTime = new Date();
isAuthorized(permissionReadCl);
logger.info("GET bpmnText for modelName={}", modelName);
final CldsModel model = CldsModel.retrieve(cldsDao, modelName, false);
@@ -265,7 +267,7 @@ public class CldsService extends SecureServiceBase {
*/
public String getImageXml(String modelName) {
util.entering(request, "CldsService: GET model image");
- Date startTime = new Date();
+ final Date startTime = new Date();
isAuthorized(permissionReadCl);
logger.info("GET imageText for modelName={}", modelName);
final CldsModel model = CldsModel.retrieve(cldsDao, modelName, false);
@@ -334,7 +336,6 @@ public class CldsService extends SecureServiceBase {
logger.info("PUT imageText={}", cldsModel.getImageText());
fillInCldsModel(cldsModel);
cldsModel.save(cldsDao, getUserId());
-
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
auditLogger.info("PUT model completed");
@@ -349,7 +350,7 @@ public class CldsService extends SecureServiceBase {
*/
public List<ValueItem> getModelNames() {
util.entering(request, "CldsService: GET model names");
- Date startTime = new Date();
+ final Date startTime = new Date();
isAuthorized(permissionReadCl);
logger.info("GET list of model names");
final List<ValueItem> names = cldsDao.getModelNames();
@@ -388,7 +389,7 @@ public class CldsService extends SecureServiceBase {
public ResponseEntity<?> putModelAndProcessAction(String action, String modelName, String test, CldsModel model)
throws TransformerException, ParseException {
util.entering(request, "CldsService: Process model action");
- Date startTime = new Date();
+ final Date startTime = new Date();
String errorMessage = "";
String actionCd = "";
try {
@@ -491,7 +492,8 @@ public class CldsService extends SecureServiceBase {
instanceCount = dcaeEvent.getInstances().size();
}
String msgInfo = "event=" + dcaeEvent.getEvent() + " serviceUUID=" + dcaeEvent.getServiceUUID()
- + " resourceUUID=" + dcaeEvent.getResourceUUID() + " artifactName=" + dcaeEvent.getArtifactName()
+ + " resourceUUID=" + dcaeEvent.getResourceUUID()
+ + " artifactName=" + dcaeEvent.getArtifactName()
+ " instance count=" + instanceCount + " isTest=" + isTest;
logger.info("POST dcae event {}", msgInfo);
if (isTest) {
@@ -568,7 +570,7 @@ public class CldsService extends SecureServiceBase {
*/
public ResponseEntity<CldsModel> deployModel(String modelName, CldsModel model) {
util.entering(request, "CldsService: Deploy model");
- Date startTime = new Date();
+ final Date startTime = new Date();
String errorMessage = "";
try {
fillInCldsModel(model);
@@ -624,7 +626,7 @@ public class CldsService extends SecureServiceBase {
*/
public ResponseEntity<CldsModel> unDeployModel(String modelName, CldsModel model) {
util.entering(request, "CldsService: Undeploy model");
- Date startTime = new Date();
+ final Date startTime = new Date();
String errorMessage = "";
try {
SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage,
@@ -714,4 +716,4 @@ public class CldsService extends SecureServiceBase {
public void setLoggingUtil(LoggingUtils utilP) {
util = utilP;
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java
index d107731b0..183db8bdb 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java
@@ -35,8 +35,6 @@ import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.model.CldsTemplate;
import org.onap.clamp.clds.model.ValueItem;
import org.onap.clamp.clds.util.LoggingUtils;
-import org.onap.clamp.clds.util.ONAPLogConstants;
-import org.slf4j.event.Level;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -58,10 +56,10 @@ public class CldsTemplateService extends SecureServiceBase {
@PostConstruct
private final void afterConstruction() {
- permissionReadTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance,
- "read");
- permissionUpdateTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance,
- "update");
+ permissionReadTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate,
+ cldsPermissionInstance, "read");
+ permissionUpdateTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate,
+ cldsPermissionInstance, "update");
}
@Autowired
@@ -78,14 +76,12 @@ public class CldsTemplateService extends SecureServiceBase {
*/
public String getBpmnTemplate(String templateName) {
util.entering(request, "CldsTemplateService: GET template bpmn");
- Date startTime = new Date();
+ final Date startTime = new Date();
isAuthorized(permissionReadTemplate);
logger.info("GET bpmnText for templateName=" + templateName);
- final CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false);
- // audit log
- LoggingUtils.setTimeContext(startTime, new Date());
- auditLogger.info("GET template bpmn completed");
- util.exiting("200", "Get template bpmn success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+
+ CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false);
+ auditLogInfo(util, "GET template bpmn", startTime);
return template.getBpmnText();
}
@@ -99,14 +95,12 @@ public class CldsTemplateService extends SecureServiceBase {
*/
public String getImageXml(String templateName) {
util.entering(request, "CldsTemplateService: GET template image");
- Date startTime = new Date();
+ final Date startTime = new Date();
isAuthorized(permissionReadTemplate);
logger.info("GET imageText for templateName=" + templateName);
- final CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false);
- // audit log
- LoggingUtils.setTimeContext(startTime, new Date());
- auditLogger.info("GET template image completed");
- util.exiting("200", "Get template image success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+
+ CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false);
+ auditLogInfo(util, "GET template image", startTime);
return template.getImageText();
}
@@ -121,12 +115,10 @@ public class CldsTemplateService extends SecureServiceBase {
final Date startTime = new Date();
isAuthorized(permissionReadTemplate);
logger.info("GET model for templateName=" + templateName);
+
CldsTemplate template = CldsTemplate.retrieve(cldsDao, templateName, false);
template.setUserAuthorizedToUpdate(isAuthorizedNoException(permissionUpdateTemplate));
- // audit log
- LoggingUtils.setTimeContext(startTime, new Date());
- auditLogger.info("GET template completed");
- util.exiting("200", "Get template success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+ auditLogInfo(util, "GET template", startTime);
return template;
}
@@ -147,10 +139,7 @@ public class CldsTemplateService extends SecureServiceBase {
logger.info("PUT imageText=" + cldsTemplate.getImageText());
cldsTemplate.setName(templateName);
cldsTemplate.save(cldsDao, null);
- // audit log
- LoggingUtils.setTimeContext(startTime, new Date());
- auditLogger.info("PUT template completed");
- util.exiting("200", "Put template success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+ auditLogInfo(util, "PUT template", startTime);
return cldsTemplate;
}
@@ -161,19 +150,17 @@ public class CldsTemplateService extends SecureServiceBase {
*/
public List<ValueItem> getTemplateNames() {
util.entering(request, "CldsTemplateService: GET template names");
- Date startTime = new Date();
+ final Date startTime = new Date();
isAuthorized(permissionReadTemplate);
logger.info("GET list of template names");
- final List<ValueItem> names = cldsDao.getTemplateNames();
- // audit log
- LoggingUtils.setTimeContext(startTime, new Date());
- auditLogger.info("GET template names completed");
- util.exiting("200", "Get template names success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+
+ List<ValueItem> names = cldsDao.getTemplateNames();
+ auditLogInfo(util, "GET template names", startTime);
return names;
}
// Created for the integration test
public void setLoggingUtil(LoggingUtils utilP) {
- util = utilP;
+ util = utilP;
}
}
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java b/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java
index 81bafef47..0d53e9155 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java
@@ -25,6 +25,7 @@
package org.onap.clamp.clds.service;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Optional;
@@ -92,9 +93,7 @@ public class CldsToscaService extends SecureServiceBase {
isAuthorized(permissionUpdateTosca);
cldsToscaModel.setToscaModelName(toscaModelName);
cldsToscaModel = cldsToscaModel.save(cldsDao, refProp, policyClient, getUserId());
- LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Parse Tosca model and save success", this.getClass().getName());
- auditLogger.info("Parse Tosca model and save completed");
+ auditLogInfo("Parse Tosca model and save", startTime);
return new ResponseEntity<>(cldsToscaModel, HttpStatus.CREATED);
}
@@ -104,16 +103,14 @@ public class CldsToscaService extends SecureServiceBase {
* @return clds tosca models - list of CLDS tosca models
*/
public List<CldsToscaModel> getAllToscaModels() {
-
- Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsToscaService: Get All tosca models", getPrincipalName());
// TODO revisit based on new permissions
+ final Date startTime = new Date();
+ LoggingUtils.setRequestContext("CldsToscaService: Get All tosca models", getPrincipalName());
isAuthorized(permissionReadTosca);
- final List<CldsToscaModel> cldsToscaModels = Optional.ofNullable(cldsDao.getAllToscaModels()).get();
- LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get All tosca models success", this.getClass().getName());
- auditLogger.info("Get All tosca models");
- return cldsToscaModels;
+
+ Optional<List<CldsToscaModel>> cldsToscaModels = Optional.ofNullable(cldsDao.getAllToscaModels());
+ auditLogInfo("Get All tosca models", startTime);
+ return cldsToscaModels.orElse(Collections.emptyList());
}
/**
@@ -126,44 +123,41 @@ public class CldsToscaService extends SecureServiceBase {
* @return clds tosca model - CLDS tosca model for a given tosca model name
*/
public CldsToscaModel getToscaModel(String toscaModelName) {
- Date startTime = new Date();
+ final Date startTime = new Date();
LoggingUtils.setRequestContext("CldsToscaService: Get tosca models by model name", getPrincipalName());
// TODO revisit based on new permissions
isAuthorized(permissionReadTosca);
- final List<CldsToscaModel> cldsToscaModels = Optional.ofNullable(cldsDao.getToscaModelByName(toscaModelName))
- .get();
- LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get tosca models by model name success", this.getClass().getName());
- auditLogger.info("GET tosca models by model name completed");
- return cldsToscaModels.get(0);
+
+ Optional<List<CldsToscaModel>> cldsToscaModels = Optional.ofNullable(
+ cldsDao.getToscaModelByName(toscaModelName));
+ auditLogInfo("Get tosca models by model name", startTime);
+ return cldsToscaModels.map(models -> models.get(0)).orElse(null);
}
/**
* REST service that retrieves a CLDS Tosca model lists for a policy type
* from the database.
- *
* @param policyType
* The type of the policy
* @return clds tosca model - CLDS tosca model for a given policy type
*/
public CldsToscaModel getToscaModelsByPolicyType(String policyType) {
- Date startTime = new Date();
+ final Date startTime = new Date();
LoggingUtils.setRequestContext("CldsToscaService: Get tosca models by policyType", getPrincipalName());
// TODO revisit based on new permissions
isAuthorized(permissionReadTosca);
- final List<CldsToscaModel> cldsToscaModels = Optional.ofNullable(cldsDao.getToscaModelByPolicyType(policyType))
- .get();
- LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get tosca models by policyType success", this.getClass().getName());
- auditLogger.info("GET tosca models by policyType completed");
- return cldsToscaModels.get(0);
+
+ Optional<List<CldsToscaModel>> cldsToscaModels = Optional.ofNullable(
+ cldsDao.getToscaModelByPolicyType(policyType));
+ auditLogInfo("Get tosca models by policyType", startTime);
+ return cldsToscaModels.map(models -> models.get(0)).orElse(null);
}
public ResponseEntity<?> deleteToscaModelById(String toscaModeId) {
// TODO
return null;
}
-
+
// Created for the integration test
public void setLoggingUtil(LoggingUtils utilP) {
util = utilP;
diff --git a/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java b/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java
index f65308903..0e28a4b9d 100644
--- a/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java
+++ b/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java
@@ -30,6 +30,8 @@ import java.util.Date;
import javax.ws.rs.NotAuthorizedException;
import org.onap.clamp.clds.util.LoggingUtils;
+import org.onap.clamp.clds.util.ONAPLogConstants;
+import org.slf4j.event.Level;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
@@ -206,4 +208,19 @@ public abstract class SecureServiceBase {
return false;
}
+
+ protected void auditLogInfo(LoggingUtils util, String actionDescription, Date startTime) {
+ LoggingUtils.setTimeContext(startTime, new Date());
+ auditLogger.info(actionDescription + " completed");
+ util.exiting("200", actionDescription + " success", Level.INFO,
+ ONAPLogConstants.ResponseStatus.COMPLETED);
+ }
+
+ protected void auditLogInfo(String actionDescription, Date startTime) {
+
+ LoggingUtils.setTimeContext(startTime, new Date());
+ LoggingUtils.setResponseContext("0", actionDescription + " success",
+ this.getClass().getName());
+ auditLogger.info(actionDescription + " completed");
+ }
} \ No newline at end of file