summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorSébastien Determe <sebastien.determe@intl.att.com>2019-08-14 15:06:18 +0000
committerGerrit Code Review <gerrit@onap.org>2019-08-14 15:06:18 +0000
commit6da0e17bd212ff5414a9798a2a2c3941b365d930 (patch)
treebae4eb708da67abef93bcb51a0d3f9f94ee2ef6b /src/main/java/org
parent13e8958238c4e7e870c04cca5035ba6d41b37889 (diff)
parenta1aa1d36b2bb500e8d021d2f911f1d24b4113e0d (diff)
Merge "Improve test for DictionaryService."
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java58
1 files changed, 42 insertions, 16 deletions
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 c228e171a..454056cd3 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsDictionaryService.java
@@ -60,47 +60,73 @@ public class CldsDictionaryService extends SecureServiceBase {
@PostConstruct
- private final void initConstruct() {
+ private void initConstruct() {
permissionReadTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance, "read");
permissionUpdateTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance,
"update");
}
/**
- * REST Service that creates or Updates a Dictionary.
- *
+ * REST Service that creates a Dictionary.
+ *
* @param dictionaryName dictionary name
- * @param cldsDictionary clds dictionary
* @return CldsDictionary that was created in DB.
*/
+ public CldsDictionary createDictionary(String dictionaryName) {
+ CldsDictionary cldsDictionary = new CldsDictionary();
+ cldsDictionary.setDictionaryName(dictionaryName);
+ cldsDictionary.save(cldsDictionary.getDictionaryName(), cldsDao, getUserId());
+ return cldsDictionary;
+ }
+
+ /**
+ * REST Service that creates or Updates a Dictionary.
+ * Used in clds-services.xml
+ *
+ * @param cldsDictionary clds dictionary
+ * @return ResponseEntity with CldsDictionary that was created in DB.
+ */
public ResponseEntity<CldsDictionary> createOrUpdateDictionary(String dictionaryName,
- CldsDictionary cldsDictionary) {
- final Date startTime = new Date();
+ CldsDictionary cldsDictionary) {
+
+ Date startTime = new Date();
LoggingUtils.setRequestContext("CldsDictionaryService: createOrUpdateDictionary", getPrincipalName());
// TODO revisit based on new permissions
isAuthorized(permissionUpdateTosca);
+
if (cldsDictionary == null) {
- cldsDictionary = new CldsDictionary();
- cldsDictionary.setDictionaryName(dictionaryName);
+
+ cldsDictionary = createDictionary(dictionaryName);
+ } else {
+
+ if (cldsDictionary.getDictionaryName() == null) {
+ cldsDictionary.setDictionaryName(dictionaryName);
+ }
+
+ cldsDictionary.save(cldsDictionary.getDictionaryName(), cldsDao, getUserId());
}
- cldsDictionary.save(dictionaryName, cldsDao, getUserId());
- auditLogInfo("createOrUpdateDictionary", startTime);
+
+ LoggingUtils.setTimeContext(startTime, new Date());
+ LoggingUtils.setResponseContext("0", "createOrUpdateDictionary success", this.getClass().getName());
+ auditLogger.info("createOrUpdateDictionary completed");
+
return new ResponseEntity<>(cldsDictionary, HttpStatus.OK);
}
/**
* REST Service that creates or Updates a Dictionary Elements for dictionary
* in DB.
- *
+ *
* @param dictionaryName dictionary name
* @param dictionaryItem dictionary item
* @return CldsDictionaryItem A dictionary items that was created or updated
* in DB
*/
public ResponseEntity<CldsDictionaryItem> createOrUpdateDictionaryElements(String dictionaryName,
- CldsDictionaryItem dictionaryItem) {
+ CldsDictionaryItem dictionaryItem) {
final Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsDictionaryService: createOrUpdateDictionaryElements", getPrincipalName());
+ LoggingUtils.setRequestContext("CldsDictionaryService: createOrUpdateDictionaryElements",
+ getPrincipalName());
// TODO revisit based on new permissions
isAuthorized(permissionUpdateTosca);
dictionaryItem.save(dictionaryName, cldsDao, getUserId());
@@ -110,7 +136,7 @@ public class CldsDictionaryService extends SecureServiceBase {
/**
* Rest Service that retrieves all CLDS dictionary in DB.
- *
+ *
* @return CldsDictionary List List of CldsDictionary available in DB
*/
public ResponseEntity<List<CldsDictionary>> getAllDictionaryNames() {
@@ -126,7 +152,7 @@ public class CldsDictionaryService extends SecureServiceBase {
/**
* Rest Service that retrieves all CLDS dictionary items in DB for a give
* dictionary name.
- *
+ *
* @param dictionaryName dictionary name
* @return CldsDictionaryItem list List of CLDS Dictionary items for a given
* dictionary name
@@ -150,4 +176,4 @@ public class CldsDictionaryService extends SecureServiceBase {
util = utilP;
}
-}
+} \ No newline at end of file