summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2019-06-04 13:50:48 +0200
committerk.kedron <k.kedron@partner.samsung.com>2019-06-18 15:51:01 +0200
commita1aa1d36b2bb500e8d021d2f911f1d24b4113e0d (patch)
tree5bfa3c3e3d93ae8ac6b0b601a02a595fb5ee5ca7 /src/main/java/org/onap
parent87dd6b9a1680c31a736164b29e2b663a27fbe2a7 (diff)
Improve test for DictionaryService.
Add new test for CldsDictionaryService. Refactor createOrUpdateDictionary method. Remove useless final from private method. Checkstyle issue. Change-Id: I26e782aeb4a7429d342f90d4231dd24cca2e152f Issue-ID: CLAMP-355 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com>
Diffstat (limited to 'src/main/java/org/onap')
-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