CHeckstyle and JUnit for base package in ONAP-REST
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / util / AbstractPolicyCreation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017, 2019 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.pap.xacml.rest.util;
22
23 import com.att.research.xacml.util.XACMLProperties;
24 import com.google.common.base.Joiner;
25
26 import java.util.UUID;
27
28 import org.onap.policy.rest.XacmlRestProperties;
29 import org.springframework.stereotype.Component;
30
31 @Component
32 public abstract class AbstractPolicyCreation {
33
34     public static String getDomain() {
35         return XACMLProperties.getProperty(XacmlRestProperties.PROP_ADMIN_DOMAIN, "urn");
36     }
37
38     public String newPolicyID() {
39         return Joiner.on(':').skipNulls().join((getDomain().startsWith("urn") ? null : "urn"),
40                 getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID());
41     }
42
43     public String convertDate(String dateTTL) {
44         String formateDate = null;
45         if (dateTTL.contains("/")) {
46             formateDate = dateTTL.replace("/", "-");
47         } else {
48             formateDate = dateTTL;
49         }
50         return formateDate;
51     }
52
53     public void updatePolicyCreationToDatabase() {
54         // Add it into our tree
55         /*
56          * Path finalPolicyPath = null;
57          * finalPolicyPath = Paths.get(successMap.get("success"));
58          * PolicyElasticSearchController controller = new PolicyElasticSearchController();
59          * controller.updateElk(finalPolicyPath.toString());
60          * File file = finalPolicyPath.toFile();
61          * if(file != null){
62          * String policyName = file.toString();
63          * String removePath = policyName.substring(policyName.indexOf("repository")+11);
64          * String removeXml = removePath.replace(".xml", "");
65          * String removeExtension = removeXml.substring(0, removeXml.indexOf("."));
66          * List<Object> policyVersionList = commonClassDao.getDataById(PolicyVersion.class, "policyName",
67          * removeExtension);
68          * if (policyVersionList.size() > 0) {
69          * for(int i = 0; i < policyVersionList.size(); i++) {
70          * PolicyVersion entityItem = (PolicyVersion) policyVersionList.get(i);
71          * if(entityItem.getPolicyName().equals(removeExtension)){
72          * version = entityItem.getHigherVersion() +1;
73          * entityItem.setActiveVersion(version);
74          * entityItem.setHigherVersion(version);
75          * entityItem.setModifiedBy(userId);
76          * commonClassDao.update(entityItem);
77          * if(policyData.isEditPolicy){
78          * PolicyNotificationMail email = new PolicyNotificationMail();
79          * String mode = "EditPolicy";
80          * String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() +
81          * ".xml";
82          * email.sendMail(entityItem, policyNameForEmail, mode, commonClassDao);
83          * }
84          * }
85          * }
86          * }else{
87          * PolicyVersion entityItem = new PolicyVersion();
88          * entityItem.setActiveVersion(version);
89          * entityItem.setHigherVersion(version);
90          * entityItem.setPolicyName(removeExtension);
91          * entityItem.setCreatedBy(userId);
92          * entityItem.setModifiedBy(userId);
93          * commonClassDao.save(entityItem);
94          * }
95          * }
96          */
97     }
98
99 }