diff options
Diffstat (limited to 'BRMSGateway/src')
3 files changed, 24 insertions, 20 deletions
diff --git a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java index 43031861b..a11e8b4b7 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java @@ -95,7 +95,7 @@ public class BRMSHandler implements BackUpHandler{ } } } - Boolean failureFlag = false; + Boolean failureFlag; int i = 0; do{ failureFlag = false; @@ -118,6 +118,7 @@ public class BRMSHandler implements BackUpHandler{ * (non-Javadoc) * @see org.onap.policy.utils.BackUpHandler#runOnNotification(org.onap.policy.api.PDPNotification) */ + @Override public void runOnNotification(PDPNotification notification){ if(notification.getNotificationType().equals(NotificationType.REMOVE)){ removedPolicies(notification.getRemovedPolicies()); 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 c923c3c34..266e090a2 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java @@ -109,6 +109,7 @@ public class BRMSPush { private static final String[] GOALS = { "clean", "deploy" }; private static final String DEFAULT_VERSION = "1.1.0-SNAPSHOT"; private static final String DEPENDENCY_FILE = "dependency.json"; + private static final String BRMSPERSISTENCE = "brmsEclipselink.persistencexml"; private static Map<String, String> modifiedGroups = new HashMap<>(); private static IntegrityMonitor im; @@ -188,8 +189,10 @@ public class BRMSPush { } catch (Exception e) { LOGGER.error("Error starting BackUpMonitor: " + e); } - if(!config.containsKey(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_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(); @@ -388,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); @@ -402,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(); @@ -500,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)) { @@ -514,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); @@ -528,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 @@ -599,7 +602,6 @@ public class BRMSPush { } fos.close(); is.close(); - f = null; LOGGER.info(fileName + " Created.."); } } @@ -641,7 +643,7 @@ public class BRMSPush { private boolean checkRemoteSync(String selectedName, String version) { List<NexusArtifact> artifacts = getArtifactFromNexus(selectedName, version); - return (artifacts.size() == 0) ? false : true; + return artifacts.isEmpty() ? false : true; } private List<NexusArtifact> getArtifactFromNexus(String selectedName, String version) { @@ -690,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); @@ -736,8 +738,9 @@ public class BRMSPush { } if (!modifiedGroups.isEmpty()) { Boolean flag = false; - for (String group : modifiedGroups.keySet()) { + for (Map.Entry<String, String> entry : modifiedGroups.entrySet()) { InvocationResult result = null; + String group = entry.getKey(); try { InvocationRequest request = new DefaultInvocationRequest(); setVersion(group); @@ -761,7 +764,7 @@ public class BRMSPush { if (createFlag) { addNotification(group, "create"); } else { - addNotification(group, modifiedGroups.get(group)); + addNotification(group, entry.getValue()); } flag = true; } else { @@ -795,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; } } @@ -869,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); @@ -1018,7 +1021,7 @@ 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 "); @@ -1069,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); } @@ -1122,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)) { diff --git a/BRMSGateway/src/test/resources/config.properties b/BRMSGateway/src/test/resources/config.properties index 4f9e01305..8c46ec277 100644 --- a/BRMSGateway/src/test/resources/config.properties +++ b/BRMSGateway/src/test/resources/config.properties @@ -65,7 +65,7 @@ javax.persistence.jdbc.user=sa #database password for Integrity Monitor javax.persistence.jdbc.password= #persistence xml -eclipselink.persistencexml=META-INF/persistenceBRMStest.xml +brmsEclipselink.persistencexml=META-INF/persistenceBRMStest.xml #resource name RESOURCE_NAME=site_1.brmsgw_1 #***Properties for IntegrityMonitor integration defined in IntegrityMonitorProperties.java*** |