[POLICY-73] replace openecomp for policy-engine
[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, boolean portalType) {
44                 String formateDate = null;
45                 String[] date;
46                 String[] parts;
47                 
48                 if (portalType){
49                         parts = dateTTL.split("-");
50                         formateDate = parts[2] + "-" + parts[1] + "-" + parts[0];
51                 } else {
52                         date  = dateTTL.split("T");
53                         parts = date[0].split("-");
54                         formateDate = parts[2] + "-" + parts[1] + "-" + parts[0];
55                 }
56                 return formateDate;
57         }
58         
59
60         
61         public void updatePolicyCreationToDatabase(){
62                 // Add it into our tree
63 /*              Path finalPolicyPath = null;
64                 finalPolicyPath = Paths.get(successMap.get("success"));
65                 PolicyElasticSearchController controller = new PolicyElasticSearchController();
66                 controller.updateElk(finalPolicyPath.toString());
67                 File file = finalPolicyPath.toFile();
68                 if(file != null){
69                         String policyName = file.toString();
70                         String removePath = policyName.substring(policyName.indexOf("repository")+11);
71                         String removeXml = removePath.replace(".xml", "");
72                         String removeExtension = removeXml.substring(0, removeXml.indexOf("."));
73                         List<Object> policyVersionList = commonClassDao.getDataById(PolicyVersion.class, "policyName", removeExtension);
74                         if (policyVersionList.size() > 0) {             
75                                 for(int i = 0;  i < policyVersionList.size(); i++) {
76                                 PolicyVersion entityItem = (PolicyVersion) policyVersionList.get(i);
77                                         if(entityItem.getPolicyName().equals(removeExtension)){
78                                                 version = entityItem.getHigherVersion() +1;
79                                                 entityItem.setActiveVersion(version);
80                                                 entityItem.setHigherVersion(version);
81                                                 entityItem.setModifiedBy(userId);
82                                                 commonClassDao.update(entityItem);
83                                                 if(policyData.isEditPolicy){
84                                                         PolicyNotificationMail email = new PolicyNotificationMail();
85                                                         String mode = "EditPolicy";
86                                                         String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml";
87                                                         email.sendMail(entityItem, policyNameForEmail, mode, commonClassDao);
88                                                 }
89                                         }
90                                 }
91                         }else{
92                                 PolicyVersion entityItem = new PolicyVersion();
93                                 entityItem.setActiveVersion(version);
94                                 entityItem.setHigherVersion(version);
95                                 entityItem.setPolicyName(removeExtension);
96                                 entityItem.setCreatedBy(userId);
97                                 entityItem.setModifiedBy(userId);
98                                 commonClassDao.save(entityItem);
99                         }       
100                 }*/
101         }
102
103
104 }