Additional code for Tosca
[clamp.git] / src / main / java / org / onap / clamp / clds / service / CldsDictionaryService.java
index 5d5e218..0fb1e0f 100644 (file)
@@ -44,106 +44,116 @@ import org.springframework.stereotype.Component;
 @Component
 public class CldsDictionaryService extends SecureServiceBase {
 
-       @Value("${clamp.config.security.permission.type.tosca:permission-type-tosca}")
-       private String cldsPermissionTypeTosca;
-       @Value("${clamp.config.security.permission.instance:dev}")
-       private String cldsPermissionInstance;
-       private SecureServicePermission permissionReadTosca;
-       private SecureServicePermission permissionUpdateTosca;
+    @Value("${clamp.config.security.permission.type.tosca:permission-type-tosca}")
+    private String                  cldsPermissionTypeTosca;
+    @Value("${clamp.config.security.permission.instance:dev}")
+    private String                  cldsPermissionInstance;
+    private SecureServicePermission permissionReadTosca;
+    private SecureServicePermission permissionUpdateTosca;
 
-       @Autowired
-       private CldsDao cldsDao;
+    @Autowired
+    private CldsDao                 cldsDao;
+    
+    private LoggingUtils util = new LoggingUtils(logger);
+    
 
-       @PostConstruct
-       private final void initConstruct() {
-               permissionReadTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance, "read");
-        permissionUpdateTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance, "update");
-       }
+    @PostConstruct
+    private final void initConstruct() {
+        permissionReadTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance, "read");
+        permissionUpdateTosca = SecureServicePermission.create(cldsPermissionTypeTosca, cldsPermissionInstance,
+                "update");
+    }
 
-       /**
-        *  REST Service that creates or Updates a Dictionary
-        *  
-        * @param dictionaryName
-        * @param cldsDictionary
-        * @return CldsDictionary that was created in DB.
-        */
-       public ResponseEntity<CldsDictionary> createOrUpdateDictionary(String dictionaryName,
-                       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.save(dictionaryName, cldsDao, getUserId());
-               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
+     * 
+     * @param dictionaryName
+     * @param cldsDictionary
+     * @return CldsDictionary that was created in DB.
+     */
+    public ResponseEntity<CldsDictionary> createOrUpdateDictionary(String dictionaryName,
+            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.save(dictionaryName, cldsDao, getUserId());
+        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
-        * @param dictionaryItem
-        * @return CldsDictionaryItem
-        *                      A dictionary items that was created or updated in DB
-        */
-       public ResponseEntity<CldsDictionaryItem> createOrUpdateDictionaryElements(String dictionaryName,
-                       CldsDictionaryItem dictionaryItem) {
-               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");
-               return new ResponseEntity<>(dictionaryItem, HttpStatus.OK);
-       }
+    /**
+     * REST Service that creates or Updates a Dictionary Elements for dictionary
+     * in DB
+     * 
+     * @param dictionaryName
+     * @param dictionaryItem
+     * @return CldsDictionaryItem A dictionary items that was created or updated
+     *         in DB
+     */
+    public ResponseEntity<CldsDictionaryItem> createOrUpdateDictionaryElements(String dictionaryName,
+            CldsDictionaryItem dictionaryItem) {
+        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");
+        return new ResponseEntity<>(dictionaryItem, HttpStatus.OK);
+    }
 
-       /**
-        * Rest Service that retrieves all CLDS dictionary in DB
-        * 
-        * @return CldsDictionary List
-        *                      List of CldsDictionary available in DB
-        */
-       public ResponseEntity<List<CldsDictionary>> getAllDictionaryNames() {
-               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");
-               return new ResponseEntity<>(dictionaries, HttpStatus.OK);
-       }
+    /**
+     * Rest Service that retrieves all CLDS dictionary in DB
+     * 
+     * @return CldsDictionary List List of CldsDictionary available in DB
+     */
+    public ResponseEntity<List<CldsDictionary>> getAllDictionaryNames() {
+        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");
+        return new ResponseEntity<>(dictionaries, HttpStatus.OK);
+    }
 
-       /**
-        * Rest Service that retrieves all CLDS dictionary items in DB for a give dictionary name
-        * 
-        * @param dictionaryName
-        * @return CldsDictionaryItem list
-        *                      List of CLDS Dictionary items for a given dictionary name
-        */
-       public ResponseEntity<List<CldsDictionaryItem>> getDictionaryElementsByName(String dictionaryName) {
-               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");
-               return new ResponseEntity<>(dictionaryItems, HttpStatus.OK);
-       }
+    /**
+     * Rest Service that retrieves all CLDS dictionary items in DB for a give
+     * dictionary name
+     * 
+     * @param dictionaryName
+     * @return CldsDictionaryItem list List of CLDS Dictionary items for a given
+     *         dictionary name
+     */
+    public ResponseEntity<List<CldsDictionaryItem>> getDictionaryElementsByName(String dictionaryName) {
+        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");
+        return new ResponseEntity<>(dictionaryItems, HttpStatus.OK);
+    }
 
-       public ResponseEntity<?> deleteDictionary() {
-               return null;
-       }
+    public ResponseEntity<?> deleteDictionary() {
+        return null;
+    }
+
+    // Created for the integration test
+    public void setLoggingUtil(LoggingUtils utilP) {
+        util = utilP;
+    }
 
 }