2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.pypdp;
23 import java.util.UUID;
25 import org.openecomp.policy.api.PolicyConfigException;
26 import org.openecomp.policy.api.PolicyParameters;
27 import org.openecomp.policy.pypdp.model_pojo.PepConfigPolicyRequest;
28 import org.openecomp.policy.std.StdPolicyEngine;
30 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
32 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
34 public class PolicyCreateUpdateRequest {
35 private StdPolicyEngine pe;
36 public PolicyCreateUpdateRequest(StdPolicyEngine pe){
40 public String run(PolicyParameters pep, String requestID, String operation, String userID, String passcode) {
42 if(pep.getRequestID()==null){
43 if (requestID != null && !requestID.isEmpty()) {
45 pep.setRequestID(UUID.fromString(requestID));
47 catch (IllegalArgumentException e) {
48 pep.setRequestID(UUID.randomUUID());
49 PolicyLogger.info("Generated Random UUID: " + pep.getRequestID().toString());
53 // check if this is create
55 if (operation.equalsIgnoreCase("create")) {
56 result = pe.createPolicy(pep, userID, passcode ).getResponseMessage();
58 // this is Update policy.
59 result = pe.updatePolicy(pep, userID, passcode ).getResponseMessage();
62 result = e.getMessage();
67 public String run(PepConfigPolicyRequest pep, String requestID, String operation, String userID, String passcode) {
71 // construct a UUID from the request string
72 UUID requestUUID = null;
73 if (requestID != null && !requestID.isEmpty()) {
75 requestUUID = UUID.fromString(requestID);
77 catch (IllegalArgumentException e) {
78 requestUUID = UUID.randomUUID();
79 PolicyLogger.info("Generated Random UUID: " + requestUUID.toString());
83 if (pep.getPolicyName()!= null && !pep.getPolicyName().isEmpty()) {
84 if (pep.getEcompName() != null && !pep.getEcompName().isEmpty()) {
85 if (pep.getConfigName() != null && !pep.getConfigName().isEmpty()){
86 if (pep.getPolicyScope() != null && !pep.getPolicyScope().isEmpty()) {
89 if (operation.equalsIgnoreCase("create")) {
91 result = pe.createConfigPolicy(pep.getPolicyName(), pep.getPolicyDescription(), pep.getEcompName(),
92 pep.getConfigName(), pep.getConfigAttributes(), pep.getConfigType(), pep.getBody(),
93 pep.getPolicyScope(), requestUUID, userID, passcode, pep.getRiskLevel(), pep.getRiskType(), pep.getGuard(), pep.getTtlDate());
95 result = pe.updateConfigPolicy(pep.getPolicyName(), pep.getPolicyDescription(), pep.getEcompName(),
96 pep.getConfigName(), pep.getConfigAttributes(), pep.getConfigType(), pep.getBody(),
97 pep.getPolicyScope(), requestUUID, userID, passcode, pep.getRiskLevel(), pep.getRiskType(), pep.getGuard(), pep.getTtlDate());
101 } catch (PolicyConfigException e) {
102 result = e.getMessage();
103 } catch (Exception e) {
104 // TODO Auto-generated catch block
109 result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyScope was null or empty.";
113 result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: configName was null or empty.";
116 result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: ecompName was null or empty.";
119 result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyName was null or empty.";