X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Futil%2FJPAUtils.java;h=22c44a8ab302bbcc70fd72dc2cdb2d9337f655fb;hb=9bf8e18042746f52b96155bb2654dfb472f09e14;hp=e18ca9ebd5534b4c5cd4f09a97cf5e3b62ba2471;hpb=ed2bcd773ec3dbe07311bad597ec664c4e38c009;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/util/JPAUtils.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/util/JPAUtils.java index e18ca9ebd..22c44a8ab 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/util/JPAUtils.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/util/JPAUtils.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,25 +20,13 @@ package org.onap.policy.pap.xacml.rest.util; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Query; -import javax.servlet.ServletException; import org.onap.policy.rest.XacmlAdminAuthorization; -import org.onap.policy.rest.jpa.Attribute; -import org.onap.policy.rest.jpa.Datatype; -import org.onap.policy.rest.jpa.FunctionDefinition; import org.onap.policy.rest.jpa.GlobalRoleSettings; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeSelectorType; - import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; @@ -46,9 +34,6 @@ public class JPAUtils { private static final Logger LOGGER = FlexLogger.getLogger(JPAUtils.class); private static EntityManagerFactory emf; - private static final Object mapAccess = new Object(); - private static Map> mapDatatype2Function = null; - private static Map mapID2Function = null; private static JPAUtils currentInstance = null; @@ -76,109 +61,6 @@ public class JPAUtils { JPAUtils.emf = emf; } - /** - * Gets the current instance of JPAUtils. - * @return The instance of JPAUtils or throws exception if the given instance is null. - * @throws IllegalStateException if a JPAUtils instance is null. Call getJPAUtilsInstance(EntityManagerFactory emf) to get this. - */ - public static JPAUtils getJPAUtilsInstance(){ - LOGGER.debug("getJPAUtilsInstance() as getJPAUtilsInstance() called"); - if(currentInstance != null){ - return currentInstance; - } - throw new IllegalStateException("The JPAUtils.currentInstance is Null. Use getJPAUtilsInstance(EntityManagerFactory emf)"); - } - - public static AttributeDesignatorType createDesignator(Attribute attribute) { - AttributeDesignatorType designator = new AttributeDesignatorType(); - designator.setAttributeId(attribute.getXacmlId()); - if (attribute.getCategoryBean() != null) { - designator.setCategory(attribute.getCategoryBean().getXacmlId()); - } else { - LOGGER.warn("No category bean"); - } - if (attribute.getDatatypeBean() != null) { - designator.setDataType(attribute.getDatatypeBean().getXacmlId()); - } else { - LOGGER.warn("No datatype bean"); - } - designator.setIssuer(attribute.getIssuer()); - designator.setMustBePresent(attribute.isMustBePresent()); - return designator; - } - - public static AttributeSelectorType createSelector(Attribute attribute) { - AttributeSelectorType selector = new AttributeSelectorType(); - selector.setContextSelectorId(attribute.getXacmlId()); - selector.setPath(attribute.getSelectorPath()); - if (attribute.getCategoryBean() != null) { - selector.setCategory(attribute.getCategoryBean().getXacmlId()); - } else { - LOGGER.warn("No category bean"); - } - if (attribute.getDatatypeBean() != null) { - selector.setDataType(attribute.getDatatypeBean().getXacmlId()); - } else { - LOGGER.warn("No datatype bean"); - } - selector.setMustBePresent(attribute.isMustBePresent()); - return selector; - } - - /** - * Builds a map in memory of a functions return datatype to function definition. Useful in limiting the number - * of SQL calls to DB especially when we don't expect these to change much. - * - * @return - A HashMap of Datatype JPA Container ID's to FunctionDefinition objects - */ - public Map> getFunctionDatatypeMap() { - - synchronized(mapAccess) { - if (mapDatatype2Function == null||mapDatatype2Function.isEmpty()) { - try { - buildFunctionMaps(); - } catch (ServletException e) { - LOGGER.error("Exception Occured"+e); - } - } - } - return mapDatatype2Function; - } - - public Map getFunctionIDMap() { - synchronized(mapAccess) { - if (mapID2Function == null||mapID2Function.isEmpty()) { - try { - buildFunctionMaps(); - } catch (ServletException e) { - LOGGER.error("Exception Occured"+e); - } - } - } - return mapID2Function; - } - - private static void buildFunctionMaps() throws ServletException { - mapDatatype2Function = new HashMap<>(); - mapID2Function = new HashMap<>(); - - EntityManager em = emf.createEntityManager(); - Query getFunctionDefinitions = em.createNamedQuery("FunctionDefinition.findAll"); - List functionList = getFunctionDefinitions.getResultList(); - - for (Object id : functionList) { - FunctionDefinition value = (FunctionDefinition)id; - mapID2Function.put(value.getXacmlid(), value); - if (!mapDatatype2Function.containsKey(value.getDatatypeBean())) { - mapDatatype2Function.put(value.getDatatypeBean(), new ArrayList()); - } - mapDatatype2Function.get(value.getDatatypeBean()).add(value); - } - - em.close(); - - } - /** * Returns the lockdown value, in case of exception it is assumed that lockdown functionality * is not supported and returns false. @@ -233,7 +115,4 @@ public class JPAUtils { return globalRoleSettings.isLockdown(); } - - - }