Resolved Policy GUI Issues
[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 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 package org.onap.policy.pap.xacml.rest.util;
21
22
23 import java.util.UUID;
24
25 import org.onap.policy.rest.XACMLRestProperties;
26 import org.springframework.stereotype.Component;
27
28 import com.att.research.xacml.util.XACMLProperties;
29 import com.google.common.base.Joiner;
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                 }
48                 return formateDate;
49         }
50         
51
52         
53         public void updatePolicyCreationToDatabase(){
54                 // Add it into our tree
55 /*              Path finalPolicyPath = null;
56                 finalPolicyPath = Paths.get(successMap.get("success"));
57                 PolicyElasticSearchController controller = new PolicyElasticSearchController();
58                 controller.updateElk(finalPolicyPath.toString());
59                 File file = finalPolicyPath.toFile();
60                 if(file != null){
61                         String policyName = file.toString();
62                         String removePath = policyName.substring(policyName.indexOf("repository")+11);
63                         String removeXml = removePath.replace(".xml", "");
64                         String removeExtension = removeXml.substring(0, removeXml.indexOf("."));
65                         List<Object> policyVersionList = commonClassDao.getDataById(PolicyVersion.class, "policyName", removeExtension);
66                         if (policyVersionList.size() > 0) {             
67                                 for(int i = 0;  i < policyVersionList.size(); i++) {
68                                 PolicyVersion entityItem = (PolicyVersion) policyVersionList.get(i);
69                                         if(entityItem.getPolicyName().equals(removeExtension)){
70                                                 version = entityItem.getHigherVersion() +1;
71                                                 entityItem.setActiveVersion(version);
72                                                 entityItem.setHigherVersion(version);
73                                                 entityItem.setModifiedBy(userId);
74                                                 commonClassDao.update(entityItem);
75                                                 if(policyData.isEditPolicy){
76                                                         PolicyNotificationMail email = new PolicyNotificationMail();
77                                                         String mode = "EditPolicy";
78                                                         String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml";
79                                                         email.sendMail(entityItem, policyNameForEmail, mode, commonClassDao);
80                                                 }
81                                         }
82                                 }
83                         }else{
84                                 PolicyVersion entityItem = new PolicyVersion();
85                                 entityItem.setActiveVersion(version);
86                                 entityItem.setHigherVersion(version);
87                                 entityItem.setPolicyName(removeExtension);
88                                 entityItem.setCreatedBy(userId);
89                                 entityItem.setModifiedBy(userId);
90                                 commonClassDao.save(entityItem);
91                         }       
92                 }*/
93         }
94
95
96 }