diff options
Diffstat (limited to 'ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util')
2 files changed, 121 insertions, 20 deletions
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/AbstractPolicyCreation.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/AbstractPolicyCreation.java new file mode 100644 index 000000000..5fa681e85 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/AbstractPolicyCreation.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 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.openecomp.policy.pap.xacml.rest.util; + + +import java.util.UUID; + +import org.openecomp.policy.rest.XACMLRestProperties; +import org.springframework.stereotype.Component; + +import com.att.research.xacml.util.XACMLProperties; +import com.google.common.base.Joiner; + +@Component +public abstract class AbstractPolicyCreation { + + public static String getDomain() { + return XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_DOMAIN, "urn"); + } + + public String newPolicyID() { + return Joiner.on(':').skipNulls().join((getDomain().startsWith("urn") ? null: "urn"), + getDomain().replaceAll("[/\\\\.]", ":"), "xacml", "policy", "id", UUID.randomUUID()); + } + + public String convertDate(String dateTTL, boolean portalType) { + String formateDate = null; + String[] date; + String[] parts; + + if (portalType){ + parts = dateTTL.split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + } else { + date = dateTTL.split("T"); + parts = date[0].split("-"); + formateDate = parts[2] + "-" + parts[1] + "-" + parts[0]; + } + return formateDate; + } + + + + public void updatePolicyCreationToDatabase(){ + // Add it into our tree +/* Path finalPolicyPath = null; + finalPolicyPath = Paths.get(successMap.get("success")); + PolicyElasticSearchController controller = new PolicyElasticSearchController(); + controller.updateElk(finalPolicyPath.toString()); + File file = finalPolicyPath.toFile(); + if(file != null){ + String policyName = file.toString(); + String removePath = policyName.substring(policyName.indexOf("repository")+11); + String removeXml = removePath.replace(".xml", ""); + String removeExtension = removeXml.substring(0, removeXml.indexOf(".")); + List<Object> policyVersionList = commonClassDao.getDataById(PolicyVersion.class, "policyName", removeExtension); + if (policyVersionList.size() > 0) { + for(int i = 0; i < policyVersionList.size(); i++) { + PolicyVersion entityItem = (PolicyVersion) policyVersionList.get(i); + if(entityItem.getPolicyName().equals(removeExtension)){ + version = entityItem.getHigherVersion() +1; + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setModifiedBy(userId); + commonClassDao.update(entityItem); + if(policyData.isEditPolicy){ + PolicyNotificationMail email = new PolicyNotificationMail(); + String mode = "EditPolicy"; + String policyNameForEmail = policyData.getDomainDir() + File.separator + policyData.getOldPolicyFileName() + ".xml"; + email.sendMail(entityItem, policyNameForEmail, mode, commonClassDao); + } + } + } + }else{ + PolicyVersion entityItem = new PolicyVersion(); + entityItem.setActiveVersion(version); + entityItem.setHigherVersion(version); + entityItem.setPolicyName(removeExtension); + entityItem.setCreatedBy(userId); + entityItem.setModifiedBy(userId); + commonClassDao.save(entityItem); + } + }*/ + } + + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JPAUtils.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JPAUtils.java index 5326cb2c7..2db7e42cd 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JPAUtils.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/util/JPAUtils.java @@ -43,7 +43,7 @@ import org.openecomp.policy.common.logging.flexlogger.FlexLogger; import org.openecomp.policy.common.logging.flexlogger.Logger; public class JPAUtils { - private static Logger logger = FlexLogger.getLogger(JPAUtils.class); + private static Logger LOGGER = FlexLogger.getLogger(JPAUtils.class); private EntityManagerFactory emf; private static final Object mapAccess = new Object(); @@ -51,7 +51,6 @@ public class JPAUtils { private static Map<String, FunctionDefinition> mapID2Function = null; private static JPAUtils currentInstance = null; - //private static List<LockdownListener> lockdownListeners = new ArrayList<LockdownListener>(); /** * Get an instance of a JPAUtils. It creates one if it does not exist. @@ -61,7 +60,7 @@ public class JPAUtils { * @throws IllegalStateException if a JPAUtils has already been constructed. Call getJPAUtilsInstance() to get this. */ public static JPAUtils getJPAUtilsInstance(EntityManagerFactory emf) throws Exception{ - logger.debug("getJPAUtilsInstance(EntityManagerFactory emf) as getJPAUtilsInstance("+emf+") called"); + LOGGER.debug("getJPAUtilsInstance(EntityManagerFactory emf) as getJPAUtilsInstance("+emf+") called"); if(currentInstance == null){ if(emf != null){ currentInstance = new JPAUtils(emf); @@ -73,7 +72,7 @@ public class JPAUtils { } private JPAUtils(EntityManagerFactory emf){ - logger.debug("JPAUtils(EntityManagerFactory emf) as JPAUtils("+emf+") called"); + LOGGER.debug("JPAUtils(EntityManagerFactory emf) as JPAUtils("+emf+") called"); this.emf = emf; } @@ -83,7 +82,7 @@ public class JPAUtils { * @throws IllegalStateException if a JPAUtils instance is null. Call getJPAUtilsInstance(EntityManagerFactory emf) to get this. */ public static JPAUtils getJPAUtilsInstance() throws Exception{ - logger.debug("getJPAUtilsInstance() as getJPAUtilsInstance() called"); + LOGGER.debug("getJPAUtilsInstance() as getJPAUtilsInstance() called"); if(currentInstance != null){ return currentInstance; } @@ -96,12 +95,12 @@ public class JPAUtils { if (attribute.getCategoryBean() != null) { designator.setCategory(attribute.getCategoryBean().getXacmlId()); } else { - logger.warn("No category bean"); + LOGGER.warn("No category bean"); } if (attribute.getDatatypeBean() != null) { designator.setDataType(attribute.getDatatypeBean().getXacmlId()); } else { - logger.warn("No datatype bean"); + LOGGER.warn("No datatype bean"); } designator.setIssuer(attribute.getIssuer()); designator.setMustBePresent(attribute.isMustBePresent()); @@ -115,12 +114,12 @@ public class JPAUtils { if (attribute.getCategoryBean() != null) { selector.setCategory(attribute.getCategoryBean().getXacmlId()); } else { - logger.warn("No category bean"); + LOGGER.warn("No category bean"); } if (attribute.getDatatypeBean() != null) { selector.setDataType(attribute.getDatatypeBean().getXacmlId()); } else { - logger.warn("No datatype bean"); + LOGGER.warn("No datatype bean"); } selector.setMustBePresent(attribute.isMustBePresent()); return selector; @@ -139,7 +138,6 @@ public class JPAUtils { try { buildFunctionMaps(); } catch (ServletException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -153,7 +151,6 @@ public class JPAUtils { try { buildFunctionMaps(); } catch (ServletException e) { - // TODO Auto-generated catch block e.printStackTrace(); } } @@ -191,14 +188,14 @@ public class JPAUtils { * @throws ConversionException */ public boolean dbLockdownIgnoreErrors() { - if (logger.isTraceEnabled()) - logger.trace("ENTER"); + if (LOGGER.isTraceEnabled()) + LOGGER.trace("ENTER"); boolean lockdown = false; try { lockdown = dbLockdown(); } catch (Exception e) { - logger.warn("Cannot access DB lockdown value", e); + LOGGER.warn("Cannot access DB lockdown value", e); } return lockdown; } @@ -211,8 +208,8 @@ public class JPAUtils { */ public boolean dbLockdown() throws IllegalAccessException { - if (logger.isTraceEnabled()) - logger.trace("ENTER"); + if (LOGGER.isTraceEnabled()) + LOGGER.trace("ENTER"); EntityManager em = emf.createEntityManager(); Query globalRoleSettingsJPA = em.createNamedQuery("GlobalRoleSettings.findAll"); @@ -222,15 +219,15 @@ public class JPAUtils { if (globalRoleSettings == null) { // this should not happen String msg = "NO GlobalSetttings for " + XacmlAdminAuthorization.Role.ROLE_SUPERADMIN.toString(); - if (logger.isErrorEnabled()) - logger.error(msg); + if (LOGGER.isErrorEnabled()) + LOGGER.error(msg); throw new IllegalAccessException(msg); } if (!globalRoleSettings.getRole().equals(XacmlAdminAuthorization.Role.ROLE_SUPERADMIN.toString())) { String msg = "NOT FOUND db data for " + XacmlAdminAuthorization.Role.ROLE_SUPERADMIN.toString(); - if (logger.isErrorEnabled()) - logger.error(msg); + if (LOGGER.isErrorEnabled()) + LOGGER.error(msg); throw new IllegalAccessException(msg); } |