diff options
author | Dunietz, Irwin <id1681@att.com> | 2020-01-16 15:13:14 -0500 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2020-01-29 19:44:48 +0000 |
commit | b5fe8a69e90b950c07dc11af481eab7e9bab52c6 (patch) | |
tree | 3da81ce60554e65b93776b9aea647f3c6d8679ab /appc-inbound/appc-design-services | |
parent | 9b32cb60360a2a2973c621053510718de0072111 (diff) |
Change code in appc dispatcher for new LCMs in R6
Also introduce some minor improvements to robustness, efficiency, & formatting.
Issue-ID: APPC-1789
Signed-off-by: Dunietz, Irwin <id1681@att.com>
Change-Id: I82d970c2f7cde6c8dab1222af86ea70ce93b7e50
Diffstat (limited to 'appc-inbound/appc-design-services')
11 files changed, 876 insertions, 457 deletions
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.java index 3cbbd88b1..6381aee0d 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.java @@ -2,22 +2,21 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -26,29 +25,34 @@ package org.onap.appc.design.data; import com.fasterxml.jackson.annotation.JsonProperty; public class DesignInfo{ - + @JsonProperty("vnf-type") String vnf_type; - + @JsonProperty("vnfc-type") String vnfc_type; - + @JsonProperty("protocol") String protocol; - + @JsonProperty("incart") String inCart; - + @JsonProperty("action") String action; - + @JsonProperty("artifact-name") String artifact_name; - @JsonProperty("artifact-type") String artifact_type; + @JsonProperty("permission") + String permission; + + @JsonProperty("creatorUserId") + String creatorUserId; + public String getArtifact_type() { return artifact_type; } @@ -105,10 +109,26 @@ public class DesignInfo{ this.inCart = inCart; } + public String getPermission() { + return permission; + } + + public void setPermission(String permission) { + this.permission = permission; + } + + public String getCreatorUserId() { + return creatorUserId; + } + + public void setCreatorUserId(String creatorUserId) { + this.creatorUserId = creatorUserId; + } + @Override public String toString() { return "DesignInfo [vnf_type=" + vnf_type + ", vnfc_type=" + vnfc_type + ", protocol=" + protocol + ", inCart=" + inCart + "]"; } - + } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java index 84fb55cfb..72f60bc80 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java @@ -2,22 +2,21 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -28,19 +27,23 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class DesignResponse{ - @JsonProperty("userID") - String userId ; - + String userId; + @JsonProperty("designInfo") List<DesignInfo> designInfoList; - + @JsonProperty("statusInfo") List<StatusInfo> statusInfoList; - + @JsonProperty("artifactInfo") List<ArtifactInfo> artifactInfo; - + + @JsonProperty("vnf-type") + String vnfType; + + @JsonProperty("users") + List<UserPermissionInfo> users; public List<ArtifactInfo> getArtifactInfo() { return artifactInfo; @@ -65,7 +68,7 @@ public class DesignResponse{ public void setDesignInfoList(List<DesignInfo> designInfoList) { this.designInfoList = designInfoList; } - + public List<StatusInfo> getStatusInfoList() { return statusInfoList; } @@ -73,4 +76,21 @@ public class DesignResponse{ public void setStatusInfoList(List<StatusInfo> statusInfoList) { this.statusInfoList = statusInfoList; } + + public String getVnfType() { + return vnfType; + } + + public void setVnfType(String vnfType) { + this.vnfType = vnfType; + } + + public List<UserPermissionInfo> getUsers() { + return users; + } + + public void setUsers(List<UserPermissionInfo> userPermInfoList) { + this.users = userPermInfoList; + } + } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/UserPermissionInfo.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/UserPermissionInfo.java new file mode 100644 index 000000000..bbe87dee1 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/UserPermissionInfo.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ============================================================================= + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.design.data; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class UserPermissionInfo { + + @JsonProperty("userID") + String userID; + @JsonProperty("permission") + String permission; + + public String getUserID() { + return userID; + } + + public String getPermission() { + return permission; + } + + public void setUserID(String user_id) { + this.userID = user_id; + } + + public void setPermission(String perm) { + this.permission = perm; + } +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java index 5e5f78a53..9ed45be8c 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java @@ -2,22 +2,21 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -31,93 +30,104 @@ import com.att.eelf.configuration.EELFManager; public class DbResponseProcessor { private static final EELFLogger log = EELFManager.getInstance().getLogger(DbResponseProcessor.class); - public String parseResponse(String dbresposne, String action) throws Exception { - - log.info("Starting Parsing the response for action :[" + action + "]\n data:[" + dbresposne +"]" ); - String response ; + public String parseResponse(String dbresponse, String action) throws Exception { + + log.info("Starting Parsing the response for action :[" + action + "]\ndata:[" + dbresponse + "]"); + String response; switch (action) { case DesignServiceConstants.GETDESIGNS: - response = getDesignsResponse(dbresposne); + response = getDesignsResponse(dbresponse); break; case DesignServiceConstants.GETAPPCTIMESTAMPUTC: - response = getAppcTimestampResponse(dbresposne); + response = getAppcTimestampResponse(dbresponse); break; case DesignServiceConstants.ADDINCART: - response = getAddInCartResponse(dbresposne); - break ; + response = getAddInCartResponse(dbresponse); + break; case DesignServiceConstants.GETARTIFACTREFERENCE: - response= getArtifactReferenceResponse(dbresposne); + response = getArtifactReferenceResponse(dbresponse); break; case DesignServiceConstants.GETARTIFACT: - response= getArtifactResponse(dbresposne); + response = getArtifactResponse(dbresponse); break; case DesignServiceConstants.GETGUIREFERENCE: - response= getGuiReferenceResponse(dbresposne); + response = getGuiReferenceResponse(dbresponse); break; case DesignServiceConstants.GETSTATUS: - response= getStatusResponse(dbresposne); + response = getStatusResponse(dbresponse); break; case DesignServiceConstants.UPLOADARTIFACT: - response= getsetStatusResponse(dbresposne); - break; + response = getSetStatusResponse(dbresponse); + break; case DesignServiceConstants.SETPROTOCOLREFERENCE: - response= getsetStatusResponse(dbresposne); - break; + response = getSetStatusResponse(dbresponse); + break; case DesignServiceConstants.SETINCART: - response= getsetStatusResponse(dbresposne); - break; + response = getSetStatusResponse(dbresponse); + break; case DesignServiceConstants.UPLOADADMINARTIFACT: - response= getsetStatusResponse(dbresposne); - break; + response = getSetStatusResponse(dbresponse); + break; case DesignServiceConstants.CHECKVNF: - response= getStatusResponse(dbresposne); - break; + response = getStatusResponse(dbresponse); + break; + case DesignServiceConstants.RETRIEVEVNFPERMISSIONS: + response = getStatusResponse(dbresponse); + break; + case DesignServiceConstants.SAVEVNFPERMISSIONS: + response = getRetrieveVnfPermissionsResponse(dbresponse); + break; default: - log.error("Action " + action + " Not Supported by response Parser"); - throw new Exception(" Action " + action + " not found while processing request "); + log.error("Action " + action + " Not Supported by Response Parser"); + throw new Exception("Action " + action + " not found while processing request"); - } - return response; + } + return response; } - private String getArtifactResponse(String dbresposne) { + private String getArtifactResponse(String dbresponse) { // TODO Auto-generated method stub - return dbresposne; + return dbresponse; } - private String getsetStatusResponse(String dbresposne) { + private String getSetStatusResponse(String dbresponse) { // TODO Auto-generated method stub return null; } - private String getStatusResponse(String dbresposne) { - log.info("Returning reposne from Response Parser " + dbresposne); - return dbresposne; + private String getStatusResponse(String dbresponse) { + log.info("Returning response from Response Parser " + dbresponse); + return dbresponse; } - private String getGuiReferenceResponse(String dbresposne) { + private String getGuiReferenceResponse(String dbresponse) { // TODO Auto-generated method stub return null; } - private String getArtifactReferenceResponse(String dbresposne) { + private String getArtifactReferenceResponse(String dbresponse) { // TODO Auto-generated method stub return null; } - private String getAddInCartResponse(String dbresposne) { + private String getAddInCartResponse(String dbresponse) { // TODO Auto-generated method stub return null; } - private String getDesignsResponse(String dbresposne) { - return dbresposne; - + private String getDesignsResponse(String dbresponse) { + return dbresponse; } - private String getAppcTimestampResponse(String dbresposne) { - log.info("getAppcTimestampResponse:[" + dbresposne +"]" ); - return dbresposne; + private String getAppcTimestampResponse(String dbresponse) { + log.info("getAppcTimestampResponse:[" + dbresponse +"]" ); + return dbresponse; } + + private String getRetrieveVnfPermissionsResponse(String dbresponse) { + log.info("Returning response from Response Parser " + dbresponse); + return dbresponse; + } + } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java index 2353e6b0c..723818f92 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -30,39 +30,45 @@ import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Strings; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.Date; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import org.json.JSONObject; import org.onap.appc.design.data.ArtifactInfo; import org.onap.appc.design.data.DesignInfo; import org.onap.appc.design.data.DesignResponse; import org.onap.appc.design.data.StatusInfo; +import org.onap.appc.design.data.UserPermissionInfo; import org.onap.appc.design.services.util.ArtifactHandlerClient; import org.onap.appc.design.services.util.DesignServiceConstants; import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.apache.commons.lang.StringUtils; public class DesignDBService { private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignDBService.class); private static DesignDBService dgGeneralDBService; - + private static ArtifactHandlerFactory artifactHandlerFactory = new ArtifactHandlerFactory(); private static final String SUCCESS_JSON = "{\"update\" : \"success\" } "; private static final String STATUS = "STATUS"; - private static final String INFO_STR = "Info : "; - private static final String DB_OPERATION_ERROR = "Error while DB operation : "; + private static final String INFO_STR = "Info: "; + private static final String DB_OPERATION_ERROR = "Error during DB operation: "; private static final String VNFC_TYPE = "vnfc-type"; - private static final String QUERY_STR = "Query String :"; + private static final String VNF_TYPE = "vnf-type"; + private static final String QUERY_STR = "Query String: "; private static final String USER_ID = "userID"; + private static final String COLUMN_USER_ID = "user_id"; + private static final String COLUMN_PERMISSION = "permission"; private SvcLogicResource serviceLogic; private DbService dbservice; - private static ArtifactHandlerFactory artifactHandlerFactory = new ArtifactHandlerFactory(); - public static DesignDBService initialise() { if (dgGeneralDBService == null) { dgGeneralDBService = new DesignDBService(); @@ -76,144 +82,277 @@ public class DesignDBService { } } - public String execute(String action, String payload, String requestID) throws Exception { + public String execute(String action, String payload, String requestId) throws Exception { - log.info("Received execute request for action : " + action + " with Payload : " + payload); + log.info("Received execute request for action: " + action + " with Payload: " + payload); RequestValidator.validate(action, payload); String response; dbservice = new DbService(); switch (action) { case DesignServiceConstants.GETDESIGNS: - response = getDesigns(payload, requestID); + response = getDesigns(payload, requestId); break; case DesignServiceConstants.GETAPPCTIMESTAMPUTC: - response = getAppcTimestampUTC( requestID ); + response = getAppcTimestampUTC(requestId); break; case DesignServiceConstants.ADDINCART: - response = setInCart(payload, requestID); + response = setInCart(payload, requestId); break; case DesignServiceConstants.GETARTIFACTREFERENCE: - response = getArtifactReference(payload, requestID); + response = getArtifactReference(payload, requestId); break; case DesignServiceConstants.GETARTIFACT: - response = getArtifact(payload, requestID); + response = getArtifact(payload, requestId); break; case DesignServiceConstants.GETGUIREFERENCE: - response = getGuiReference(payload, requestID); + response = getGuiReference(payload, requestId); break; case DesignServiceConstants.GETSTATUS: - response = getStatus(payload, requestID); + response = getStatus(payload, requestId); break; case DesignServiceConstants.SETSTATUS: - response = setStatus(payload, requestID); + response = setStatus(payload, requestId); break; case DesignServiceConstants.UPLOADARTIFACT: - response = uploadArtifact(payload, requestID); + response = uploadArtifact(payload, requestId); break; case DesignServiceConstants.SETPROTOCOLREFERENCE: - response = setProtocolReference(payload, requestID); + response = setProtocolReference(payload, requestId); break; case DesignServiceConstants.UPLOADADMINARTIFACT: - response = uploadAdminArtifact(payload, requestID); + response = uploadAdminArtifact(payload, requestId); break; case DesignServiceConstants.CHECKVNF: - response = checkVNF(payload, requestID); + response = checkVNF(payload, requestId); + break; + case DesignServiceConstants.RETRIEVEVNFPERMISSIONS: + response = retrieveVnfPermissions(payload, requestId); + break; + case DesignServiceConstants.SAVEVNFPERMISSIONS: + response = saveUserPermissionInfo(payload, requestId); break; default: - throw new DBException(" Action " + action + " not found while processing request "); + throw new DBException("Action " + action + " not found while processing request"); } return response; } + private String saveUserPermissionInfo(String payload, String requestId) throws Exception { + try { + if (requestId == null || requestId.isEmpty()) { + throw new DBException("requestId in saveUserPermissionInfo request is null or Blank"); + } + log.info("Received Save User Permission from " + requestId + " with payload " + payload); + Date startTime = new Date(); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String dbDate = dateFormat.format(startTime); + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + String vnf_type = payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue(); + String modifier = payloadObject.get(DesignServiceConstants.CREATORUSERID).textValue(); + JsonNode users = payloadObject.get("users"); + if (users == null || !users.isArray()) { + throw new DBException("Users list is not provided in the input payload"); + } + for (JsonNode node : users) { + String userId = node.get(DesignServiceConstants.USER_ID).textValue(); + String permission = node.get(DesignServiceConstants.PERMISSION).textValue(); + ArrayList<String> argList = new ArrayList<>(); + argList.add(vnf_type); + argList.add(userId); + log.info("Checking User - " + userId + " current permissions in db for this vnf type"); + String queryString = "SELECT PERMISSION FROM DT_USER_PERMISSIONS WHERE VNF_TYPE = ? AND USER_ID = ?"; + log.info(QUERY_STR + queryString); + String user_permission = null; + int rowCount = 0; + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + while (data.next()) { + rowCount++; + user_permission = data.getString("PERMISSION"); + if (Strings.isNullOrEmpty(permission)) { + log.info("Received request to delete db record for User - " + userId); + ArrayList<String> delArgList = new ArrayList<>(); + delArgList.add(vnf_type); + delArgList.add(userId); + String deleteQuery = "DELETE FROM DT_USER_PERMISSIONS WHERE VNF_TYPE = ? AND USER_ID = ?"; + log.info(QUERY_STR + deleteQuery); + log.info("Arguments List: " + delArgList); + boolean status = dbservice.updateDBData(deleteQuery, delArgList); + if (!status) { + throw new DBException("Error while deleting record from DT_USER_PERMISSIONS"); + } else { + log.info("Record deleted"); + } + } else if (user_permission.matches(permission)) { + log.info("User " + userId + " permission record found in db for same vnf_type " + vnf_type + + ". No update needed."); + } else { + log.info("User's permission record will be updated. New permission: " + permission + + " for user " + userId + " as requested by " + requestId + + " will be saved to database."); + ArrayList<String> updateArgList = new ArrayList<>(); + updateArgList.add(permission); + updateArgList.add(modifier); + updateArgList.add(dbDate); + updateArgList.add(vnf_type); + updateArgList.add(userId); + + String updateQuery = + "UPDATE DT_USER_PERMISSIONS SET PERMISSION = ?, MODIFIER = ?, DATE_MODIFIED = ?" + + " WHERE VNF_TYPE = ? AND USER_ID = ?"; + log.info(QUERY_STR + updateQuery); + log.info("Arguments List: " + updateArgList); + boolean updateStatus = dbservice.updateDBData(updateQuery, updateArgList); + if (!updateStatus) { + throw new DBException("Error while updating User Permissions"); + } + } + } + } + if (rowCount == 0 && !(Strings.isNullOrEmpty(permission))) { + log.info("User not found in database for this vnf_type. The new permission " + permission + + " for user " + userId + " and vnf_type " + vnf_type + " as requested by " + requestId + + " will be saved to database."); + ArrayList<String> insertArgList = new ArrayList<>(); + insertArgList.add(vnf_type); + insertArgList.add(userId); + insertArgList.add(permission); + insertArgList.add(modifier); + String insertQuery = + "INSERT INTO DT_USER_PERMISSIONS (VNF_TYPE, USER_ID, PERMISSION, DATE_MODIFIED, MODIFIER)" + + " VALUES (?, ?, ?, sysdate(), ?)"; + log.info(QUERY_STR + insertQuery); + log.info("Arguments List: " + insertArgList); + boolean updateStatus = dbservice.updateDBData(insertQuery, insertArgList); + if (!updateStatus) { + throw new DBException("Error while inserting record for User Permissions"); + } + } + } + } catch (Exception e) { + log.error("An error occurred in saveUserPermissionInfo " + e.getMessage(), e); + throw e; + } + return SUCCESS_JSON; + } + private String checkVNF(String payload, String requestId) throws Exception { + try { + log.info("Got into Check VNF Request with payload: " + payload); + if (payload == null || payload.isEmpty()) { + throw new DBException("Payload in CheckVNF request is null or Blank"); + } + if (requestId == null || requestId.isEmpty()) { + throw new DBException("requestId in CheckVNF request is null or Blank"); + } + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + String vnfType = payloadObject.get("vnf-type").textValue(); - log.info("Got into Check VNF Request with payload: " + payload); - if (StringUtils.isBlank(payload)) - throw new DBException("Payload in CheckVNF request is null or Blank"); - if (StringUtils.isBlank(requestId)) - throw new DBException("requestId in CheckVNF request is null or Blank"); - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - String vnfType = payloadObject.get("vnf-type").textValue(); - log.info("Check VNF Request with VNF TYPE: " + vnfType); - ArrayList<String> argList = new ArrayList<>(); - argList.add(vnfType); - String queryString = "SELECT DT_ACTION_STATUS_ID,USER FROM sdnctl.DT_ACTION_STATUS WHERE VNF_TYPE = ? ORDER BY DT_ACTION_STATUS_ID DESC LIMIT 1 ; "; - log.info(QUERY_STR + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); - int rowCount = 0; - String user = null; - String dtActionStatusId = null; - while (data.next()) { - rowCount++; - user = data.getString("USER"); - dtActionStatusId = data.getString("DT_ACTION_STATUS_ID"); - } - log.debug("DT_ACTION_STATUS_ID-> " + dtActionStatusId + " user-> " + user); - JSONObject jObject = new JSONObject(); - if (rowCount == 0) { - log.debug("vnf-type does not present in APPC DB, row Count:" + rowCount); - jObject.put("result", "No"); - } else { - log.debug("vnf-type present in APPC DB, row Count:" + rowCount); - jObject.put("result", "Yes"); - jObject.put("user", user); - } - log.info("Check VNF result: " + jObject.toString()); + log.info("Check VNF Request with VNF TYPE: " + vnfType); + + ArrayList<String> argList = new ArrayList<>(); + argList.add(vnfType); + + String queryString = + "SELECT DT_ACTION_STATUS_ID, USER FROM sdnctl.DT_ACTION_STATUS WHERE VNF_TYPE = ?" + + " ORDER BY DT_ACTION_STATUS_ID DESC LIMIT 1;"; + + log.info(QUERY_STR + queryString); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + + int rowCount = 0; + String user = null; + String dtActionStatusId = null; + + while (data.next()) { + rowCount++; + user = data.getString("USER"); + dtActionStatusId = data.getString("DT_ACTION_STATUS_ID"); + } + + log.debug("DT_ACTION_STATUS_ID " + dtActionStatusId + " user " + user); + + JSONObject jObject = new JSONObject(); + + + if (rowCount == 0) { + log.debug("vnf-type not present in APPC DB, row Count: " + rowCount); + jObject.put("result", "No"); + } else { + log.debug("vnf-type present in APPC DB, row Count: " + rowCount); + jObject.put("result", "Yes"); + jObject.put("user", user); + } + + log.info("Check VNF result: " + jObject.toString()); + return jObject.toString(); - return jObject.toString(); + } + } catch (Exception e) { + log.error("An error occurred in checkVNF " + e.getMessage(), e); + throw e; + } } private String uploadAdminArtifact(String payload, String requestId) throws Exception { + try { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); + JsonNode payloadObject = objectMapper.readTree(payload); + log.info("Got upload Admin Artifact with requestId: " + requestId + " & Payload: " + + payloadObject.asText()); + + if (Strings.isNullOrEmpty(requestId)) { + throw new DBException("Request-id is missing in the uploadAdminArtifact payload."); + } + + ArtifactHandlerClient ac = new ArtifactHandlerClient(); + String requestString = ac.createArtifactData(payload, requestId); + ac.execute(requestString, "POST"); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - JsonNode payloadObject = objectMapper.readTree(payload); - log.info("Got upload Admin Aritfact with requestId : " + requestId + " & Payload" + payloadObject.asText()); - if (StringUtils.isBlank(requestId)) { - throw new DBException("Request-id is missing in the uploadAdminArtifact payload . "); - } - ArtifactHandlerClient ac = new ArtifactHandlerClient(); - String requestString = ac.createArtifactData(payload, requestId); - ac.execute(requestString, "POST"); + int sdcArtifactId = getSDCArtifactIDbyRequestID(requestId); + if (sdcArtifactId == 0) { + throw new DBException("Error occurred while validating/Saving the artifact to SDC_ARTIFACTS" + + " or getting SDC_ARTIFACTS_ID."); + } - int sdcArtifactId = getSDCArtifactIDbyRequestID(requestId); - if (sdcArtifactId == 0) - throw new DBException( - "Error occured while validating/Saving the artifact to SDC_ARTIFACTS or getting SDC_ARTIFACTS_ID ."); - JsonNode json = payloadObject.get(DesignServiceConstants.USER_ID); - if (json == null) { - throw new DBException("User Id is null"); - } else if (json.asText().trim().isEmpty()) { - log.info("UserId in Admin Aritfact is blank, User Id : " + json.asText()); - throw new DBException("User Id is blank"); - } + JsonNode json = payloadObject.get(DesignServiceConstants.USER_ID); + if (json == null) { + throw new DBException("User Id is null"); + } else if (json.asText().trim().isEmpty()) { + log.info("UserId in Admin Artifact is blank, User Id: " + json.asText()); + throw new DBException("User Id is blank"); + } - int sdcReferenceId = 0; - createArtifactTrackingRecord(payload, requestId, sdcArtifactId, sdcReferenceId); + int sdcReferenceId = 0; + createArtifactTrackingRecord(payload, requestId, sdcArtifactId, sdcReferenceId); + } catch (Exception e) { + log.error("An error occurred in uploadAdminArtifact: " + e.getMessage(), e); + throw e; + } return SUCCESS_JSON; } - private String getAppcTimestampUTC( String requestID) throws Exception - { - log.info("Starting getAppcTimestampUTC: requestID:" + requestID ); - java.util.TimeZone gmtTZ= java.util.TimeZone.getTimeZone("GMT"); - java.text.SimpleDateFormat formatter = - new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ); - formatter.setTimeZone( gmtTZ ); - java.util.Date dateVal= new java.util.Date(); - log.info("getAppcTimestampUTC: current local Date:[" + dateVal+ "]"); - String timeStr= formatter.format( dateVal ); - log.info("getAppcTimestampUTC: returning:[" + timeStr + "]"); - return timeStr; + private String getAppcTimestampUTC(String requestId) throws Exception { + log.info("Starting getAppcTimestampUTC: requestId: " + requestId); + java.util.TimeZone gmtTZ = java.util.TimeZone.getTimeZone("GMT"); + java.text.SimpleDateFormat formatter = + new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + formatter.setTimeZone(gmtTZ); + java.util.Date dateVal = new java.util.Date(); + log.info("getAppcTimestampUTC: current local Date: [" + dateVal + "]"); + String timeStr = formatter.format(dateVal); + log.info("getAppcTimestampUTC: returning: [" + timeStr + "]"); + return timeStr; } - private String setInCart(String payload, String requestID) throws Exception { + private String setInCart(String payload, String requestId) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); JsonNode payloadObject = objectMapper.readTree(payload); @@ -221,16 +360,16 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.INCART).textValue()); argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); - String queryString = "UPDATE DT_ARTIFACT_TRACKING SET INCART= ? WHERE ASDC_REFERENCE_ID IN " - + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ? "; + String queryString = + "UPDATE DT_ARTIFACT_TRACKING SET INCART = ? WHERE ASDC_REFERENCE_ID IN" + + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ?"; - if (payloadObject.get(DesignServiceConstants.VNF_TYPE) != null && !payloadObject - .get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) { - queryString = queryString + " AND VNFC_TYPE = ? ) AND USER = ? "; + if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null + && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { + queryString += " AND VNFC_TYPE = ?"; argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); - } else { - queryString = queryString + " ) AND USER = ? "; } + queryString += ") AND USER = ?"; argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); log.info(QUERY_STR + queryString); boolean data = dbservice.updateDBData(queryString, argList); @@ -241,7 +380,7 @@ public class DesignDBService { return SUCCESS_JSON; } - private String setProtocolReference(String payload, String requestID) throws Exception { + private String setProtocolReference(String payload, String requestId) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); JsonNode payloadObject = objectMapper.readTree(payload); @@ -252,9 +391,9 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue()); - String queryString = " DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE= ? AND PROTOCOL = ? "; + String queryString = "DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE = ? AND PROTOCOL = ?"; - log.info("Delete Query String :" + queryString); + log.info("Delete Query String: " + queryString); boolean data; log.info("Record Deleted"); @@ -270,10 +409,9 @@ public class DesignDBService { if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { - queryString = queryString + " AND VNFC_TYPE = ? )"; - } else { - queryString = queryString + " ) "; + queryString += " AND VNFC_TYPE = ?"; } + queryString += ")"; log.info(QUERY_STR + queryString); data = dbservice.updateDBData(queryString, argList); @@ -283,33 +421,72 @@ public class DesignDBService { return SUCCESS_JSON; } - private String uploadArtifact(String payload, String requestID) throws Exception { + private String uploadArtifact(String payload, String requestId) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); JsonNode payloadObject = objectMapper.readTree(payload); - log.info("Got upload Aritfact with Payload : " + payloadObject.asText()); + log.info("Got upload Artifact with Payload: " + payloadObject.asText()); try { ArtifactHandlerClient ac = artifactHandlerFactory.ahi(); - String requestString = ac.createArtifactData(payload, requestID); + String requestString = ac.createArtifactData(payload, requestId); ac.execute(requestString, "POST"); - int sdcArtifactId = getSDCArtifactIDbyRequestID(requestID); + int sdcArtifactId = getSDCArtifactIDbyRequestID(requestId); int sdcReferenceId = getSDCReferenceID(payload); - createArtifactTrackingRecord(payload, requestID, sdcArtifactId, sdcReferenceId); + createArtifactTrackingRecord(payload, requestId, sdcArtifactId, sdcReferenceId); String status = getDataFromActionStatus(payload, STATUS); if (status == null || status.isEmpty()) { - log.info("Action Status is: "+ status); - setActionStatus(payload, "Not Tested"); + log.info("Action Status is: " + status); + setActionStatus(payload, "Not Tested"); } linkstatusRelationShip(sdcArtifactId, sdcReferenceId, payload); - + savePermissionInfo(payload, requestId); } catch (Exception e) { - log.error("An error occured in uploadArtifact", e); + log.error("An error occurred in uploadArtifact", e); throw e; } return SUCCESS_JSON; } + private void savePermissionInfo(String payload, String requestId) throws Exception { + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList<String> argList = new ArrayList<>(); + argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + log.info("Entered savePermissionInfo from uploadArtifact with payload " + payload); + String queryString = "SELECT PERMISSION FROM DT_USER_PERMISSIONS WHERE VNF_TYPE = ? AND USER_ID = ?"; + log.info(QUERY_STR + queryString); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + String user_permission = null; + int rowCount = 0; + while (data.next()) { + rowCount++; + user_permission = data.getString("PERMISSION"); + log.info("User exists in database with permission = " + user_permission); + } + if (rowCount == 0) { + log.info("No record found in database"); + log.info("Inserting one record in database"); + String permission = "owner"; + ArrayList<String> insertArgList = new ArrayList<>(); + insertArgList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); + insertArgList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + insertArgList.add(permission); + insertArgList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + String insertQuery = + "INSERT INTO DT_USER_PERMISSIONS (VNF_TYPE, USER_ID, PERMISSION, DATE_MODIFIED, MODIFIER)" + + " VALUES (?, ?, ?, sysdate(), ?)"; + log.info(QUERY_STR + insertQuery); + log.info("Arguments List: " + insertArgList); + boolean updateStatus = dbservice.updateDBData(insertQuery, insertArgList); + if (!updateStatus) { + throw new DBException("Error while inserting record to DT_USER_PERMISSIONS"); + } + } + } + } private void linkstatusRelationShip(int sdcArtifactId, int sdcReferenceId, String payload) throws Exception { @@ -323,21 +500,22 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); String queryString = - "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID,DT_ACTION_STATUS_ID) VALUES " + - "(( SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ? ) , " - + "( SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? "; - - if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject - .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { - queryString = queryString + " AND VNFC_TYPE = ? GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) )"; - } else { - queryString = queryString + " GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) ) "; + "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID, DT_ACTION_STATUS_ID) VALUES" + + " ((SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING" + + " WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ?)," + + " (SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS" + + " WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ?"; + + if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null + && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { + queryString += " AND VNFC_TYPE = ?"; } + queryString += " GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ))"; log.info(QUERY_STR + queryString); boolean data = dbservice.updateDBData(queryString, argList); if (!data) { - throw new DBException("Error while updating RelationShip table"); + throw new DBException("Error while updating Relationship table"); } } @@ -352,29 +530,30 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue()); argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue()); - String queryString = " SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ? " - + " AND ARTIFACT_TYPE = ? AND ARTIFACT_NAME = ? "; + String queryString = + "SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ?" + + " AND ARTIFACT_TYPE = ? AND ARTIFACT_NAME = ?"; - if (payloadObject.get(DesignServiceConstants.ACTION) != null && !payloadObject - .get(DesignServiceConstants.ACTION).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.ACTION) != null + && !payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); - queryString = queryString + " AND ACTION = ? "; + queryString += " AND ACTION = ?"; } - if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject - .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null + && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); - queryString = queryString + " AND VNFC_TYPE = ? "; - + queryString += " AND VNFC_TYPE = ?"; } log.info(QUERY_STR + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); - int sdcReferenceId = 0; - while (data.next()) { - sdcReferenceId = data.getInt("ASDC_REFERENCE_ID"); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + int sdcReferenceId = 0; + while (data.next()) { + sdcReferenceId = data.getInt("ASDC_REFERENCE_ID"); + } + log.info("Got sdcReferenceId = " + sdcReferenceId); + return sdcReferenceId; } - log.info("Got sdcReferenceId= " + sdcReferenceId); - return sdcReferenceId; } private String getDataFromActionStatus(String payload, String dataValue) throws Exception { @@ -386,19 +565,20 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); String queryString = - " SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? "; - if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject - .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { + "SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ?"; + if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null + && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); - queryString = queryString + " AND VNFC_TYPE = ? "; + queryString += " AND VNFC_TYPE = ?"; } log.info(QUERY_STR + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); - while (data.next()) { - status = data.getString(STATUS); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + while (data.next()) { + status = data.getString(STATUS); + } + log.info("DT_ACTION_STATUS Status = " + status); + return status; } - log.info("DT_ACTION_STATUS Status = " + status); - return status; } private void setActionStatus(String payload, String status) throws Exception { @@ -409,16 +589,16 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); String insertQuery = " INSERT INTO DT_ACTION_STATUS (ACTION, VNF_TYPE, VNFC_TYPE, USER, TECHNOLOGY, UPDATED_DATE, STATUS) VALUES (?,?,?,?,?,sysdate() , ?); "; - if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject - .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null + && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); log.info("Vnfc-Type: " + payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); } else { argList.add(null); } argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); - if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject - .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null + && !payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue()); } else { argList.add(null); @@ -428,12 +608,13 @@ public class DesignDBService { log.info("QueryString: " + insertQuery); log.info("Arguments List: " + argList); boolean updateStatus = dbservice.updateDBData(insertQuery, argList); - if (!updateStatus) + if (!updateStatus) { throw new DBException("Error while updating Action Status"); + } } - private void createArtifactTrackingRecord(String payload, String requestID, int sdcArtifactId, int sdcReferenceId) - throws Exception { + private void createArtifactTrackingRecord(String payload, String requestId, int sdcArtifactId, int sdcReferenceId) + throws Exception { ObjectMapper objectMapper = new ObjectMapper(); JsonNode payloadObject = objectMapper.readTree(payload); @@ -442,51 +623,55 @@ public class DesignDBService { argList.add(String.valueOf(sdcArtifactId)); argList.add(String.valueOf(sdcReferenceId)); argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); - if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject - .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null + && !payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue()); } else { argList.add(""); } - if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null && !payloadObject - .get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null + && !payloadObject.get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue()); } else { argList.add(""); } - String queryString = "INSERT INTO DT_ARTIFACT_TRACKING (ASDC_ARTIFACTS_ID, ASDC_REFERENCE_ID, USER, TECHNOLOGY, CREATION_DATE, UPDATED_DATE, ARTIFACT_STATUS, PROTOCOL, IN_CART) VALUES (? , ? , ?, ?, sysdate() , sysdate(), 'Created', ? ,'N' )"; + String queryString = + "INSERT INTO DT_ARTIFACT_TRACKING (ASDC_ARTIFACTS_ID, ASDC_REFERENCE_ID, USER, TECHNOLOGY," + + " CREATION_DATE, UPDATED_DATE, ARTIFACT_STATUS, PROTOCOL, IN_CART)" + + " VALUES (?, ?, ?, ?, sysdate(), sysdate(), 'Created', ?, 'N')"; log.info(QUERY_STR + queryString); boolean data = dbservice.updateDBData(queryString, argList); if (!data) { - throw new DBException("Error Updating DT_ARTIFACT_TRACKING "); + throw new DBException("Error Updating DT_ARTIFACT_TRACKING"); } } - private int getSDCArtifactIDbyRequestID(String requestID) throws Exception { + private int getSDCArtifactIDbyRequestID(String requestId) throws Exception { log.info("Starting getArtifactIDbyRequestID DB Operation"); int artifactId = 0; try { ArrayList<String> argList = new ArrayList<>(); - argList.add("TLSUUID" + requestID); - String queryString = " SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ? "; - log.info(QUERY_STR + queryString+ " & UUID or" + "TLSUUID :" + requestID); - ResultSet data = dbservice.getDBData(queryString, argList); - while (data.next()) { - artifactId = data.getInt("ASDC_ARTIFACTS_ID"); + argList.add("TLSUUID" + requestId); + String queryString = "SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ?"; + log.info(QUERY_STR + queryString + " & UUID: " + "TLSUUID" + requestId); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + while (data.next()) { + artifactId = data.getInt("ASDC_ARTIFACTS_ID"); + } } } catch (Exception e) { log.error("An error occurred in getSDCArtifactIDbyRequestID", e); throw e; } - log.info("Got SDC_ARTIFACTS_ID As :" + artifactId); + log.info("Got SDC_ARTIFACTS_ID As: " + artifactId); return artifactId; } - private String getArtifact(String payload, String requestID) throws Exception { + private String getArtifact(String payload, String requestId) throws Exception { log.info("Starting getArtifact DB Operation"); try { ObjectMapper objectMapper = new ObjectMapper(); @@ -496,29 +681,40 @@ public class DesignDBService { argList.add(artifactName); argList.add(payloadObject.get("artifact-type").textValue()); - String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where " - + " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? "; + String queryString = + "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS" + + " where ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ?"; + log.info(QUERY_STR + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); String artifactContent = null; - int rowCount = 0; - int hightestVerion = -1; - while (data.next()) { - rowCount++; - int version = data.getInt("INTERNAL_VERSION"); - if (hightestVerion < version) { - artifactContent = data.getString("ARTIFACT_CONTENT"); - hightestVerion = version; + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + + int rowCount = 0; + int highestVersion = -1; + + while (data.next()) { + rowCount++; + + int version = data.getInt("INTERNAL_VERSION"); + if (highestVersion < version) { + artifactContent = data.getString("ARTIFACT_CONTENT"); + highestVersion = version; + } + } + + log.debug("No of rows: " + rowCount + " highest Internal Version " + highestVersion); + + if (rowCount == 0) { + throw new DBException( + "Sorry!!! APPC DB doesn't have any artifact Named: " + artifactName); + } + + if (artifactContent == null || artifactContent.isEmpty()) { + throw new DBException("Sorry!!! Artifact Content is stored blank in APPC DB for " + artifactName + + " and Internal version " + highestVersion); } } - log.debug("No of rows: " + rowCount + " highest Inetrnal Version" + hightestVerion); - if (rowCount == 0) { - throw new DBException("Sorry !!!APPC DB doesn't have any artifact Named : " + artifactName); - } - if (artifactContent == null || artifactContent.isEmpty()) { - throw new DBException("Sorry !!! Artifact Content is stored blank in APPC DB for " + artifactName - + " and Internal version " + hightestVerion); - } + DesignResponse designResponse = new DesignResponse(); List<ArtifactInfo> artifactInfoList = new ArrayList<>(); ArtifactInfo artifactInfo = new ArtifactInfo(); @@ -527,7 +723,7 @@ public class DesignDBService { designResponse.setArtifactInfo(artifactInfoList); ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writeValueAsString(designResponse); - log.debug("End of getArtifact:" + INFO_STR + jsonString); + log.debug("End of getArtifact: " + INFO_STR + jsonString); return jsonString; } catch (Exception e) { log.error(DB_OPERATION_ERROR, e); @@ -535,7 +731,7 @@ public class DesignDBService { } } - private String setStatus(String payload, String requestID) throws Exception { + private String setStatus(String payload, String requestId) throws Exception { log.info("Starting getStatus DB Operation"); try { @@ -557,7 +753,7 @@ public class DesignDBService { if (payloadObject.get(VNFC_TYPE) != null && !payloadObject.get(VNFC_TYPE).textValue().isEmpty()) { argList.add(payloadObject.get(VNFC_TYPE).textValue()); - queryString = queryString + " and DAS.VNFC_TYPE = ? "; + queryString += " and DAS.VNFC_TYPE = ?"; } log.info(QUERY_STR + queryString); @@ -579,7 +775,7 @@ public class DesignDBService { } } - private String getStatus(String payload, String requestID) throws Exception { + private String getStatus(String payload, String requestId) throws Exception { log.info("Starting getStatus DB Operation"); try { String vnfcType = null; @@ -595,15 +791,16 @@ public class DesignDBService { argList.add(userID); argList.add(vnfType); - String queryString = "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE, DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS " - + "from DT_ACTION_STATUS DAS , DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR " + - " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID " - + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? " - + " and DAS.VNF_TYPE = ? "; + String queryString = + "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE, DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS" + + " from DT_ACTION_STATUS DAS, DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR" + + " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID" + + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ?" + + " and DAS.VNF_TYPE = ?"; if (vnfcType != null && !vnfcType.isEmpty()) { argList.add(vnfcType); - queryString = queryString + " and DAS.VNFC_TYPE = ? "; + queryString = queryString + " and DAS.VNFC_TYPE = ?"; } log.info(QUERY_STR + queryString); @@ -611,20 +808,21 @@ public class DesignDBService { DesignResponse designResponse = new DesignResponse(); designResponse.setUserId(userID); List<StatusInfo> statusInfoList = new ArrayList<>(); - ResultSet data = dbservice.getDBData(queryString, argList); - while (data.next()) { - StatusInfo statusInfo = new StatusInfo(); - statusInfo.setAction(data.getString("ACTION")); - statusInfo.setAction_status(data.getString(STATUS)); - statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS")); - statusInfo.setVnf_type(data.getString("VNF_TYPE")); - statusInfo.setVnfc_type(data.getString("VNFC_TYPE")); - statusInfoList.add(statusInfo); - } + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + while (data.next()) { + StatusInfo statusInfo = new StatusInfo(); + statusInfo.setAction(data.getString("ACTION")); + statusInfo.setAction_status(data.getString(STATUS)); + statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS")); + statusInfo.setVnf_type(data.getString("VNF_TYPE")); + statusInfo.setVnfc_type(data.getString("VNFC_TYPE")); + statusInfoList.add(statusInfo); + } - if (statusInfoList.isEmpty()) { - throw new DBException( - "OOPS !!!! No VNF information available for VNF-TYPE : " + vnfType + " for User : " + userID); + if (statusInfoList.isEmpty()) { + throw new DBException( + "OOPS!!!! No VNF information available for VNF-TYPE: " + vnfType + " for User: " + userID); + } } designResponse.setStatusInfoList(statusInfoList); ObjectMapper mapper = new ObjectMapper(); @@ -636,22 +834,22 @@ public class DesignDBService { throw e; } catch (Exception e) { log.error(DB_OPERATION_ERROR + e.getMessage()); - log.error("Exception : ", e); + log.error("Exception:", e); throw e; } } - private String getGuiReference(String payload, String requestID) { + private String getGuiReference(String payload, String requestId) { // TODO Auto-generated method stub return null; } - private String getArtifactReference(String payload, String requestID) { + private String getArtifactReference(String payload, String requestId) { // TODO Auto-generated method stub return null; } - private String getDesigns(String payload, String requestID) throws Exception { + private String getDesigns(String payload, String requestId) throws Exception { String queryString; log.info("Starting getDesigns DB Operation"); @@ -666,41 +864,45 @@ public class DesignDBService { } ArrayList<String> argList = new ArrayList<>(); argList.add(userID); + argList.add(userID); + queryString = + "SELECT DISTINCT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME," + + " AR.ARTIFACT_TYPE, DUP.PERMISSION, DAS.USER FROM " + + DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT, " + + DesignServiceConstants.DB_SDC_REFERENCE + " AR, " + DesignServiceConstants.DB_DT_USER_PERMISSIONS + + " DUP, " + DesignServiceConstants.DB_DT_ACTION_STATUS + " DAS " + + " WHERE AR.VNF_TYPE = DUP.VNF_TYPE AND DAS.VNF_TYPE = DUP.VNF_TYPE" + + " AND DAT.ASDC_REFERENCE_ID = AR.ASDC_REFERENCE_ID AND DUP.USER_ID = ? AND AR.VNF_TYPE IN" + + " (SELECT DUP.VNF_TYPE FROM DT_USER_PERMISSIONS DUP" + + " WHERE DUP.PERMISSION IN('owner','contributor') AND DUP.USER_ID = ? GROUP BY VNF_TYPE)"; if (filterKey != null) { - queryString = - "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from " - + - DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " - + DesignServiceConstants.DB_SDC_REFERENCE + - " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? and AR.ARTIFACT_NAME like '%" - + filterKey + "%' GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME"; - } else { - queryString = - "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from " - + - DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " - + DesignServiceConstants.DB_SDC_REFERENCE + - " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME"; + queryString += " AND AR.ARTIFACT_NAME like '%" + filterKey + "%'"; } + queryString += " GROUP BY AR.VNF_TYPE, AR.ARTIFACT_NAME"; + + log.info("QUERY FOR getDesigns: " + queryString); DesignResponse designResponse = new DesignResponse(); designResponse.setUserId(userID); List<DesignInfo> designInfoList = new ArrayList<>(); - ResultSet data = dbservice.getDBData(queryString, argList); - while (data.next()) { - DesignInfo designInfo = new DesignInfo(); - designInfo.setInCart(data.getString("IN_CART")); - designInfo.setProtocol(data.getString("PROTOCOL")); - designInfo.setVnf_type(data.getString("VNF_TYPE")); - designInfo.setVnfc_type(data.getString("VNFC_TYPE")); - designInfo.setAction(data.getString("ACTION")); - designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE")); - designInfo.setArtifact_name(data.getString("ARTIFACT_NAME")); - designInfoList.add(designInfo); - } - if (designInfoList.isEmpty()) { - throw new DBException( - " Welcome to CDT, Looks like you dont have Design Yet... Lets create some...."); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + while (data.next()) { + DesignInfo designInfo = new DesignInfo(); + designInfo.setInCart(data.getString("IN_CART")); + designInfo.setProtocol(data.getString("PROTOCOL")); + designInfo.setVnf_type(data.getString("VNF_TYPE")); + designInfo.setVnfc_type(data.getString("VNFC_TYPE")); + designInfo.setAction(data.getString("ACTION")); + designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE")); + designInfo.setArtifact_name(data.getString("ARTIFACT_NAME")); + designInfo.setPermission(data.getString("PERMISSION")); + designInfo.setCreatorUserId(data.getString("USER")); + designInfoList.add(designInfo); + } + if (designInfoList.isEmpty()) { + throw new DBException( + "Welcome to CDT, Looks like you don't have Design Yet... Let's create some...."); + } } designResponse.setDesignInfoList(designInfoList); ObjectMapper mapper = new ObjectMapper(); @@ -708,15 +910,60 @@ public class DesignDBService { log.info(INFO_STR + jsonString); return jsonString; } catch (Exception e) { - log.error("Error while Starting getDesgins DB operation : ", e); + log.error("Error while Starting getDesigns DB operation:", e); throw e; } } - public static class ArtifactHandlerFactory { + private String retrieveVnfPermissions(String payload, String requestId) throws Exception { + log.info("Starting retrieveVnfPermissions DB Operation"); + + try { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList<String> argList = new ArrayList<>(); + String vnfType = payloadObject.get(VNF_TYPE).textValue(); + argList.add(vnfType); - public ArtifactHandlerClient ahi() throws Exception{ + String queryString = "SELECT USER_ID, PERMISSION FROM DT_USER_PERMISSIONS WHERE VNF_TYPE = ?"; + log.info(QUERY_STR + queryString); + List<UserPermissionInfo> userPermList = new ArrayList<>(); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + + int rowCount = 0; + + while (data.next()) { + rowCount++; + UserPermissionInfo userPermInfo = new UserPermissionInfo(); + userPermInfo.setUserID(data.getString(COLUMN_USER_ID)); + userPermInfo.setPermission(data.getString(COLUMN_PERMISSION)); + userPermList.add(userPermInfo); + } + log.info("Number of rows=" + rowCount + ", for vnf-type=" + vnfType); + + if (userPermList.isEmpty()) { + throw new DBException("No user permissions information available for VNF-TYPE: " + vnfType); + } + } + DesignResponse designResponse = new DesignResponse(); + designResponse.setUsers(userPermList); + designResponse.setVnfType(vnfType); + ObjectMapper mapper = new ObjectMapper(); + String jsonString = mapper.writeValueAsString(designResponse); + log.info("End of retrieveVnfPermissions: " + INFO_STR + jsonString); + return jsonString; + + } catch (Exception e) { + log.error("Error while Starting retrieveVnfPermissions DB operation:", e); + throw e; + } + } + + public static class ArtifactHandlerFactory { + public ArtifactHandlerClient ahi() throws Exception { return new ArtifactHandlerClient(); } } + } + diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java index f98aae46f..778313644 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java @@ -9,15 +9,14 @@ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -87,6 +86,9 @@ public class RequestValidator { case DesignServiceConstants.UPLOADADMINARTIFACT: errorString = resolveUploadArtifactErrorString(payloadObject); break; + case DesignServiceConstants.RETRIEVEVNFPERMISSIONS: + errorString = resolveRetrieveVnfPermissionsErrorString(payloadObject); + break; case SETPROTOCOLREFERENCE: case SETINCART: errorString = resolveErrorString(payloadObject); @@ -94,14 +96,23 @@ public class RequestValidator { case DesignServiceConstants.CHECKVNF: errorString = resolveCheckVNFErrorString(payloadObject); break; + case DesignServiceConstants.SAVEVNFPERMISSIONS: + errorString = resolveSaveUserPermissionErrorString(payloadObject); + break; default: throw new RequestValidationException(" Action " + action + " not found while processing request "); } checkForErrorString(errorString); } + private static String resolveSaveUserPermissionErrorString(JsonNode payloadObject) { + if (nullOrEmpty(payloadObject, VNF_TYPE)) + return VNF_TYPE; + return null; + } + private static String resolveCheckVNFErrorString(JsonNode payloadObject) { - if (nullOrEmpty(payloadObject, VNF_TYPE)) + if (nullOrEmpty(payloadObject, VNF_TYPE)) return VNF_TYPE; return null; } @@ -192,6 +203,10 @@ public class RequestValidator { return payload == null || payload.textValue().trim().isEmpty(); } + private static String resolveRetrieveVnfPermissionsErrorString(JsonNode payloadObject) { + if (nullOrEmpty(payloadObject, VNF_TYPE)) { + return VNF_TYPE; + } + return null; + } } - - diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java index 12f0a368d..e9515dc32 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -11,15 +11,14 @@ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -30,15 +29,6 @@ import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Feature; -import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; - import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -49,13 +39,19 @@ import java.util.Properties; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.ws.rs.HttpMethod; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Feature; import javax.ws.rs.core.MediaType; - +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; public class ArtifactHandlerClient { private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerClient.class); - static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR"; + public static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR"; private Properties props = new Properties(); public ArtifactHandlerClient() throws IOException { @@ -122,7 +118,6 @@ public class ArtifactHandlerClient { sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, new javax.net.ssl.TrustManager[]{secureRestClientTrustManager}, null); - client = ClientBuilder.newBuilder().sslContext(sslContext).hostnameVerifier(getHostnameVerifier()).build(); String password = et.decrypt(props.getProperty("appc.upload.pass")); @@ -133,9 +128,9 @@ public class ArtifactHandlerClient { if (HttpMethod.GET.equalsIgnoreCase(rpc)) { clientResponse = webResource.request(responseDataType).get(Response.class); } else if (HttpMethod.POST.equalsIgnoreCase(rpc)) { - clientResponse = webResource.request(requestDataType).post(Entity.json(payload),Response.class); + clientResponse = webResource.request(requestDataType).post(Entity.json(payload), Response.class); } else if (HttpMethod.PUT.equalsIgnoreCase(rpc)) { - clientResponse = webResource.request(requestDataType).put(Entity.json(payload),Response.class); + clientResponse = webResource.request(requestDataType).put(Entity.json(payload), Response.class); } else if (HttpMethod.DELETE.equalsIgnoreCase(rpc)) { clientResponse = webResource.request().delete(Response.class); } @@ -144,7 +139,7 @@ public class ArtifactHandlerClient { } catch (Exception e) { log.debug("failed in RESTCONT Action", e); - throw new IOException("Error While Sending Rest Request" + e.getMessage(), e); + throw new IOException("Error While Sending Rest Request: " + e.getMessage(), e); } finally { // clean up. if (client != null) { diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java index 42f3d3f3e..e5ceb358d 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -11,15 +11,14 @@ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -39,18 +38,18 @@ public class DesignServiceConstants { public static final String GETDESIGNS = "getDesigns"; public static final String GETAPPCTIMESTAMPUTC = "getAppcTimestampUTC"; - public static final String UPLOADARTIFACTS = "uploadArtifacts"; - public static final String VALIDATETEMPLATE = "validateTemplate"; - public static final String GETSTATUS = "getStatus"; - public static final String SETSTATUS = "setStatus"; + public static final String UPLOADARTIFACTS = "uploadArtifacts"; + public static final String VALIDATETEMPLATE = "validateTemplate"; + public static final String GETSTATUS = "getStatus"; + public static final String SETSTATUS = "setStatus"; public static final String GETGUIREFERENCE = "getGUIReference"; - public static final String GETARTIFACTREFERENCE = "getArtifactReference"; - public static final String GETAAIDATA = "getAAIData"; - public static final String GETINSTARDATA = "getInstarData"; - public static final String PUBLISHARTIFACTS = "publishdArtifacts"; - public static final String ADDINCART = "addInCart"; - - public static final String SUCCESS = "success"; + public static final String GETARTIFACTREFERENCE = "getArtifactReference"; + public static final String GETAAIDATA = "getAAIData"; + public static final String GETINSTARDATA = "getInstarData"; + public static final String PUBLISHARTIFACTS = "publishdArtifacts"; + public static final String ADDINCART = "addInCart"; + + public static final String SUCCESS = "success"; public static final String DESINGTIME = "DesignTime"; public static final String RUNTIME = "RunTime"; public static final String APPC_FLOW_CONTROLLER = "/appc-flow-controller.properties"; @@ -62,21 +61,22 @@ public class DesignServiceConstants { public static final String VNFC = "vnfc"; public static final String DOCUMENT_PARAMETERS = "document-parameters"; - public static final String SERVICE_UUID = "service-uuid"; - public static final String DISTRIBUTION_ID = "distribution-id"; + public static final String SERVICE_UUID = "service-uuid"; + public static final String DISTRIBUTION_ID = "distribution-id"; - public static final String SERVICE_NAME = "service-name"; - public static final String SERVICE_DESCRIPTION ="service-description"; - public static final String SERVICE_ARTIFACTS = "service-artifacts"; - public static final String RESOURCE_UUID ="resource-uuid"; + public static final String SERVICE_NAME = "service-name"; + public static final String SERVICE_DESCRIPTION = "service-description"; + public static final String SERVICE_ARTIFACTS = "service-artifacts"; + public static final String RESOURCE_UUID = "resource-uuid"; public static final String RESOURCE_INSTANCE_NAME = "resource-instance-name"; public static final String REOURCE_NAME = "resource-name"; - public static final String RESOURCE_VERSOIN ="resource-version"; - public static final String RESOURCE_TYPE= "resource-type"; - public static final String ARTIFACT_UUID ="artifact-uuid"; - public static final String ARTIFACT_NAME = "artifact-name"; - - public static final String ARTIFACT_VERSOIN = "artifact-version"; + public static final String RESOURCE_VERSOIN = "resource-version"; + public static final String RESOURCE_TYPE = "resource-type"; + public static final String ARTIFACT_UUID = "artifact-uuid"; + public static final String ARTIFACT_NAME = "artifact-name"; + public static final String DB_DT_ACTION_STATUS = "DT_ACTION_STATUS"; + public static final String DB_DT_USER_PERMISSIONS = "DT_USER_PERMISSIONS"; + public static final String ARTIFACT_VERSOIN = "artifact-version"; public static final String ARTIFACT_DESRIPTION = "artifact-description"; public static final String ARTIFACT_CONTENTS = "artifact-contents"; public static final String REQUEST_INFORMATION = "request-information"; @@ -109,10 +109,16 @@ public class DesignServiceConstants { public static final String INSTAR_V4_MASK = "v4Subnet"; public static final String INSTAR_V6_MASK = "v6Subnet"; public static final String CHECKVNF = "checkVNF"; + public static final String RETRIEVEVNFPERMISSIONS = "retrieveVnfPermissions"; + public static final String SAVEVNFPERMISSIONS = "saveVnfPermissions"; + public static final String CREATORUSERID = "creator-userID"; + public static final String PERMISSION = "permission"; + private DesignServiceConstants() { } public static String getEnvironmentVariable(String env) { return System.getenv(env); } -}
\ No newline at end of file + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java index 7f64863b9..21347ced2 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -13,15 +13,14 @@ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -38,7 +37,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class XResponseProcessor { private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class); - private static final String EXCEPTION_WHILE_RECEIVING_DATA = "Exception occured while receiving data"; + private static final String EXCEPTION_WHILE_RECEIVING_DATA = "Exception occurred while receiving data"; Dme2Client dme2Client; public static XResponseProcessor getInstance() { @@ -61,37 +60,39 @@ public class XResponseProcessor { // check the payload whether its having ipaddr along with subnet ipAddress = payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS) != null ? payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS).textValue() - : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) != null) - ? payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue() - .toUpperCase() - : null; - - mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null - ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue() - : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null) - ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase() - : null; - - // TODO -short format - - /* - * if (mask != null) { queryParam = ipAddress + "," +mask ; - * log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask ); } else { - * queryParam = "ipAddress "+ipAddress ; log.info("Calling Instar with IpAddress "+ - * ipAddress); } - */ - - payload = new HashMap<String, String>(); - payload.put("ipAddress", ipAddress); - payload.put("mask", mask); - log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask); - dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload); - - instarResponse = dme2Client.send(); - - log.debug("Resposne from Instar = " + instarResponse); - if (instarResponse == null || instarResponse.length() < 0) - throw new Exception("No Data received from Instar for this action " + action); + : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) != null) + ? payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue().toUpperCase() + : null; + + mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null + ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue() + + : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null) + ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase() + : null; + + // TODO -short format + + /* if (mask != null) { + * queryParam = ipAddress + "," + mask; + * log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask); + * } else { + * queryParam = "ipAddress " + ipAddress; + * log.info("Calling Instar with IpAddress " + ipAddress); + * } + */ + + payload = new HashMap<String, String>(); + payload.put("ipAddress", ipAddress); + payload.put("mask", mask); + log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask); + dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload); + + instarResponse = dme2Client.send(); + + log.debug("Response from Instar = " + instarResponse); + if (instarResponse == null || instarResponse.length() < 0) + throw new Exception("No Data received from Instar for this action " + action); } catch (Exception e) { log.error(EXCEPTION_WHILE_RECEIVING_DATA, e); throw e; diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.java index 43105a79a..fe59637a6 100644 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.java +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -11,15 +11,14 @@ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -31,19 +30,20 @@ import org.onap.appc.design.dbervices.DbResponseProcessor; public class TestDbResponse { @Test - public void testDbResponse() throws Exception{ + public void testDbResponse() throws Exception { DbResponseProcessor dbResponse = new DbResponseProcessor(); - dbResponse.parseResponse("Test", "getDesigns"); - dbResponse.parseResponse("Test", "addInCart"); - dbResponse.parseResponse("Test", "getArtifactReference"); - dbResponse.parseResponse("Test", "getArtifact"); - dbResponse.parseResponse("Test", "getGUIReference"); - dbResponse.parseResponse("Test", "getStatus"); - dbResponse.parseResponse("Test", "uploadArtifact"); - dbResponse.parseResponse("Test", "setProtocolReference"); - dbResponse.parseResponse("Test", "setInCart"); - dbResponse.parseResponse("Test", "getStatus"); - dbResponse.parseResponse("Test", "getAppcTimestampUTC"); - + dbResponse.parseResponse("Test", "getDesigns"); + dbResponse.parseResponse("Test", "addInCart"); + dbResponse.parseResponse("Test", "getArtifactReference"); + dbResponse.parseResponse("Test", "getArtifact"); + dbResponse.parseResponse("Test", "getGUIReference"); + dbResponse.parseResponse("Test", "getStatus"); + dbResponse.parseResponse("Test", "uploadArtifact"); + dbResponse.parseResponse("Test", "setProtocolReference"); + dbResponse.parseResponse("Test", "setInCart"); + dbResponse.parseResponse("Test", "getStatus"); + dbResponse.parseResponse("Test", "getAppcTimestampUTC"); + dbResponse.parseResponse("Test", "retrieveVnfPermissions"); + dbResponse.parseResponse("Test", "saveVnfPermissions"); } } diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java index 50f7ac65d..cbfca0aec 100644 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java @@ -2,22 +2,21 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * * ============LICENSE_END========================================================= */ @@ -25,12 +24,14 @@ package org.onap.appc.design.validator; import java.util.ArrayList; import java.util.List; +import org.junit.Assert; import org.junit.Test; import org.onap.appc.design.data.ArtifactInfo; import org.onap.appc.design.data.DesignInfo; import org.onap.appc.design.data.DesignRequest; import org.onap.appc.design.data.DesignResponse; import org.onap.appc.design.data.StatusInfo; +import org.onap.appc.design.data.UserPermissionInfo; public class TestDesigndata { @@ -38,64 +39,121 @@ public class TestDesigndata { @Test public void testSetUserID() { - dr.setUserId("00000"); - dr.getUserId(); + String userId = "0000"; + dr.setUserId(userId); + Assert.assertEquals("Unexpected getUserId value", userId, dr.getUserId()); } @Test public void testSetDesignInfoList() { DesignInfo di = new DesignInfo(); List<DesignInfo> li = new ArrayList<DesignInfo>(); - di.setAction("TestAction"); - di.setArtifact_name("TestName"); - di.setArtifact_type("TestType"); - di.setInCart("TestCart"); - di.setProtocol("TestProtocol"); - di.setVnf_type("TestVNF"); - di.setVnfc_type("TestVNFC"); + String action = "TestAction"; + di.setAction(action); + Assert.assertEquals("Unexpected getAction value", action, di.getAction()); + String artifact_name = "TestName"; + di.setArtifact_name(artifact_name); + Assert.assertEquals("Unexpected getArtifact_name value", artifact_name, di.getArtifact_name()); + String artifact_type = "TestType"; + di.setArtifact_type(artifact_type); + Assert.assertEquals("Unexpected getArtifact_type value", artifact_type, di.getArtifact_type()); + String inCart = "TestCart"; + di.setInCart(inCart); + Assert.assertEquals("Unexpected getInCart value", inCart, di.getInCart()); + String protocol = "TestProtocol"; + di.setProtocol(protocol); + Assert.assertEquals("Unexpected getProtocol value", protocol, di.getProtocol()); + String vnf_type = "TestVNF"; + di.setVnf_type(vnf_type); + Assert.assertEquals("Unexpected getVnf_type value", vnf_type, di.getVnf_type()); + String vnfc_type = "TestVNFC"; + di.setVnfc_type(vnfc_type); + Assert.assertEquals("Unexpected getVnfc_type value", vnfc_type, di.getVnfc_type()); li.add(di); dr.setDesignInfoList(li); + Assert.assertEquals("Unexpected getDesignInfoList value", li, dr.getDesignInfoList()); } @Test public void testSetArtifactInfo() { ArtifactInfo ai = new ArtifactInfo(); List<ArtifactInfo> li = new ArrayList<ArtifactInfo>(); - ai.setArtifact_content("TestContent"); + String artifact_content = "TestContent"; + ai.setArtifact_content(artifact_content); + Assert.assertEquals("Unexpected getArtifact_content value", artifact_content, ai.getArtifact_content()); li.add(ai); dr.setArtifactInfo(li); + Assert.assertEquals("Unexpected getArtifactInfo value", li, dr.getArtifactInfo()); } @Test public void testStatusInfo() { StatusInfo si = new StatusInfo(); List<StatusInfo> li = new ArrayList<StatusInfo>(); - si.setAction("TestAction"); - si.setAction_status("TestActionStatus"); - si.setArtifact_status("TestArtifactStatus"); - si.setVnf_type("TestVNF"); - si.setVnfc_type("TestVNFC"); + String action = "TestAction"; + si.setAction(action); + Assert.assertEquals("Unexpected getAction value", action, si.getAction()); + String action_status = "TestActionStatus"; + si.setAction_status(action_status); + Assert.assertEquals("Unexpected getAction_status value", action_status, si.getAction_status()); + String artifact_status = "TestArtifactStatus"; + si.setArtifact_status(artifact_status); + Assert.assertEquals("Unexpected getArtifact_status value", artifact_status, si.getArtifact_status()); + String vnf_type = "TestVNF"; + si.setVnf_type(vnf_type); + Assert.assertEquals("Unexpected getVnf_type value", vnf_type, si.getVnf_type()); + String vnfc_type = "TestVNFC"; + si.setVnfc_type(vnfc_type); + Assert.assertEquals("Unexpected getVnfc_type value", vnfc_type, si.getVnfc_type()); li.add(si); dr.setStatusInfoList(li); + Assert.assertEquals("Unexpected getStatusInfoList value", li, dr.getStatusInfoList()); } @Test public void testDesignRequest() { DesignRequest dreq = new DesignRequest(); - dreq.setAction("TestAction"); - dreq.setArtifact_contents("TestContent"); - dreq.setArtifact_name("TestName"); - dreq.setProtocol("TestProtocol"); - dreq.setUserId("0000"); - dreq.setVnf_type("testvnf"); - dreq.setVnfc_type("testvnfc"); - dreq.getAction(); - dreq.getArtifact_contents(); - dreq.getArtifact_name(); - dreq.getProtocol(); - dreq.getUserId(); - dreq.getVnf_type(); - dreq.getVnfc_type(); - dreq.toString(); + String action = "TestAction"; + dreq.setAction(action); + Assert.assertEquals("Unexpected getAction value", action, dreq.getAction()); + String artifact_contents = "TestContent"; + dreq.setArtifact_contents(artifact_contents); + Assert.assertEquals("Unexpected getArtifact_contents value", artifact_contents, dreq.getArtifact_contents()); + String artifact_name = "TestName"; + dreq.setArtifact_name(artifact_name); + Assert.assertEquals("Unexpected getArtifact_name value", artifact_name, dreq.getArtifact_name()); + String protocol = "TestProtocol"; + dreq.setProtocol(protocol); + Assert.assertEquals("Unexpected getProtocol value", protocol, dreq.getProtocol()); + String userId = "0000"; + dreq.setUserId(userId); + Assert.assertEquals("Unexpected getUserId value", userId, dreq.getUserId()); + String vnf_type = "testvnf"; + dreq.setVnf_type(vnf_type); + Assert.assertEquals("Unexpected getVnf_type value", vnf_type, dreq.getVnf_type()); + String vnfc_type = "testvnfc"; + dreq.setVnfc_type(vnfc_type); + Assert.assertEquals("Unexpected getVnfc_type value", vnfc_type, dreq.getVnfc_type()); + String expecting = + "DesignRequest [userId=" + userId + ", vnf_type=" + vnf_type + ", vnfc_type=" + vnfc_type + ", protocol=" + + protocol + ", action=" + action + ", artifact_name=" + artifact_name + ", artifact_contents=" + + artifact_contents + "]"; + Assert.assertEquals("Unexpected toString value", expecting, dreq.toString()); } + + @Test + public void testUserPermissionInfo() { + UserPermissionInfo upi = new UserPermissionInfo(); + List<UserPermissionInfo> li = new ArrayList<UserPermissionInfo>(); + String userId = "uu1234"; + upi.setUserID(userId); + Assert.assertEquals("Unexpected getUserId value", userId, upi.getUserID()); + String permission = "owner"; + upi.setPermission(permission); + Assert.assertEquals("Unexpected getPermission value", permission, upi.getPermission()); + li.add(upi); + dr.setUsers(li); + Assert.assertEquals("Unexpected getUsers value", li, dr.getUsers()); + } + } |