X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=BRMSGateway%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2FbrmsInterface%2FBRMSPush.java;h=0c104bc14c4f43bfbcc7d148ef7037205c1a84ef;hb=11871d2b3ecd2806f37fdbea645bdaaab9273508;hp=f6f7c12149d6059f313524d40af631066546a8da;hpb=80f072f60509ef3a35369a60857fe05f6c2a993a;p=policy%2Fengine.git diff --git a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java index f6f7c1214..0c104bc14 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java @@ -107,8 +107,9 @@ public class BRMSPush { private static final Logger LOGGER = FlexLogger.getLogger(BRMSPush.class.getName()); private static final String PROJECTSLOCATION = "RuleProjects"; private static final String[] GOALS = { "clean", "deploy" }; - private static final String DEFAULT_VERSION = "1.1.0-SNAPSHOT"; + private static final String DEFAULT_VERSION = "1.1.3-SNAPSHOT"; private static final String DEPENDENCY_FILE = "dependency.json"; + private static final String BRMSPERSISTENCE = "brmsEclipselink.persistencexml"; private static Map modifiedGroups = new HashMap<>(); private static IntegrityMonitor im; @@ -137,6 +138,9 @@ public class BRMSPush { private boolean syncFlag = false; public BRMSPush(String propertiesFile, BackUpHandler handler) throws PolicyException { + if(propertiesFile==null || handler==null){ + throw new PolicyException("Error no propertiesFile or handler"); + } Properties config = new Properties(); Path file = Paths.get(propertiesFile); if (Files.notExists(file)) { @@ -185,7 +189,11 @@ public class BRMSPush { } catch (Exception e) { LOGGER.error("Error starting BackUpMonitor: " + e); } - config.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "META-INF/persistenceBRMS.xml"); + if(!config.containsKey(BRMSPERSISTENCE)){ + config.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "META-INF/persistenceBRMS.xml"); + } else { + config.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, config.getProperty(BRMSPERSISTENCE,"META-INF/persistenceBRMS.xml")); + } EntityManagerFactory emf = Persistence.createEntityManagerFactory("BRMSGW", config); em = emf.createEntityManager(); defaultName = config.getProperty("defaultName"); @@ -383,11 +391,11 @@ public class BRMSPush { selectedName = responseAttributes.get(key); } // kmodule configurations - else if (key.equals("kSessionName")) { + else if ("kSessionName".equals(key)) { kSessionName = responseAttributes.get(key); } // Check User Specific values. - if (key.equals("$controller:")) { + if ("$controller:".equals(key)) { try { PEDependency dependency = PolicyUtils.jsonStringToObject(responseAttributes.get(key), PEDependency.class); @@ -397,7 +405,7 @@ public class BRMSPush { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Controller: " + e); } - } else if (key.equals("$dependency$")) { + } else if ("$dependency$".equals(key)) { String value = responseAttributes.get(key); if (value.startsWith("[") && value.endsWith("]")) { value = value.substring(1, value.length() - 1).trim(); @@ -495,7 +503,7 @@ public class BRMSPush { List pList = query.getResultList(); boolean createFlag = false; BRMSPolicyInfo brmsPolicyInfo = new BRMSPolicyInfo(); - if (pList.size() > 0) { + if (!pList.isEmpty()) { // Already exists. brmsPolicyInfo = (BRMSPolicyInfo) pList.get(0); if (!brmsPolicyInfo.getControllerName().getControllerName().equals(controllerName)) { @@ -509,7 +517,7 @@ public class BRMSPush { query.setParameter("cn", controllerName); List bList = query.getResultList(); BRMSGroupInfo brmsGroupInfo = new BRMSGroupInfo(); - if (bList.size() > 0) { + if (!bList.isEmpty()) { brmsGroupInfo = (BRMSGroupInfo) bList.get(0); } brmsPolicyInfo.setPolicyName(policyName); @@ -523,7 +531,7 @@ public class BRMSPush { private void syncProject(String selectedName) { boolean projectExists = checkProject(selectedName); if (projectExists) { - String version = null; + String version; version = getVersion(selectedName); if (version == null) { LOGGER.error("Error getting local version for the given Controller Name:" + selectedName @@ -594,7 +602,6 @@ public class BRMSPush { } fos.close(); is.close(); - f = null; LOGGER.info(fileName + " Created.."); } } @@ -626,6 +633,9 @@ public class BRMSPush { // Additional Check due to Limitations from Nexus API to check if the artifact is the latest. private NexusArtifact additionalNexusLatestCheck(String selectedName, NexusArtifact result) { + if(result==null){ + return result; + } String nextVersion = incrementVersion(result.getVersion()); List artifact = getArtifactFromNexus(selectedName, nextVersion); return artifact.isEmpty() ? result : additionalNexusLatestCheck(selectedName, artifact.get(0)); @@ -633,7 +643,7 @@ public class BRMSPush { private boolean checkRemoteSync(String selectedName, String version) { List artifacts = getArtifactFromNexus(selectedName, version); - return (artifacts.size() == 0) ? false : true; + return artifacts.isEmpty() ? false : true; } private List getArtifactFromNexus(String selectedName, String version) { @@ -682,7 +692,7 @@ public class BRMSPush { if (artifact != null) { newVersion = incrementVersion(artifact.getVersion()); } - if (newVersion.equals("0.1.0")) { + if ("0.1.0".equals(newVersion)) { createFlag = true; } setVersion(newVersion, selectedName); @@ -728,8 +738,9 @@ public class BRMSPush { } if (!modifiedGroups.isEmpty()) { Boolean flag = false; - for (String group : modifiedGroups.keySet()) { + for (Map.Entry entry : modifiedGroups.entrySet()) { InvocationResult result = null; + String group = entry.getKey(); try { InvocationRequest request = new DefaultInvocationRequest(); setVersion(group); @@ -753,7 +764,7 @@ public class BRMSPush { if (createFlag) { addNotification(group, "create"); } else { - addNotification(group, modifiedGroups.get(group)); + addNotification(group, entry.getValue()); } flag = true; } else { @@ -787,7 +798,7 @@ public class BRMSPush { return policyMap.get(name); } else { syncGroupInfo(); - return (policyMap.containsKey(name)) ? policyMap.get(name) : null; + return policyMap.containsKey(name) ? policyMap.get(name) : null; } } @@ -861,7 +872,7 @@ public class BRMSPush { pub.send("MyPartitionKey", message); final List stuck = pub.close(uebDelay, TimeUnit.SECONDS); - if (stuck.size() > 0) { + if (!stuck.isEmpty()) { LOGGER.error(stuck.size() + " messages unsent"); } else { LOGGER.debug("Clean exit; Message Published on UEB : " + uebList + "for Topic: " + pubTopic); @@ -1010,7 +1021,11 @@ public class BRMSPush { } private void readGroups(Properties config) throws PolicyException { - String[] groupNames = null; + String[] groupNames; + if (!config.containsKey("groupNames") || config.getProperty("groupNames")==null){ + throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + + "groupNames property is missing or empty from the property file "); + } if (config.getProperty("groupNames").contains(",")) { groupNames = config.getProperty("groupNames").replaceAll(" ", "").split(","); } else { @@ -1057,7 +1072,7 @@ public class BRMSPush { query.setParameter("cn", name); List groupList = query.getResultList(); BRMSGroupInfo brmsGroupInfo = null; - if (groupList.size() > 0) { + if (!groupList.isEmpty()) { LOGGER.info("Controller name already Existing in DB. Will be updating the DB Values" + name); brmsGroupInfo = (BRMSGroupInfo) groupList.get(0); } @@ -1110,8 +1125,8 @@ public class BRMSPush { Query query = em.createQuery("select b from BRMSPolicyInfo as b where b.policyName = :pn"); query.setParameter("pn", policyName); List pList = query.getResultList(); - BRMSPolicyInfo brmsPolicyInfo = new BRMSPolicyInfo(); - if (pList.size() > 0) { + BRMSPolicyInfo brmsPolicyInfo; + if (!pList.isEmpty()) { // Already exists. brmsPolicyInfo = (BRMSPolicyInfo) pList.get(0); if (brmsPolicyInfo.getControllerName().getControllerName().equals(controllerName)) {