summaryrefslogtreecommitdiffstats
path: root/BRMSGateway/src
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-07-25 14:11:16 +0000
committerGerrit Code Review <gerrit@onap.org>2018-07-25 14:11:16 +0000
commita5ccc101707216e8ffc07773c17799c60360863f (patch)
treef01ea26d027396fd51338c0227be6d8c5ca0e85b /BRMSGateway/src
parent5ad6783ca5a09c0061b661a48210f6d8e22cd7d3 (diff)
parent4553d7ab7bde46adcca13ee00682b8d8591cbb94 (diff)
Merge "Fix sonar issue about nested stmts"
Diffstat (limited to 'BRMSGateway/src')
-rw-r--r--BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java198
1 files changed, 110 insertions, 88 deletions
diff --git a/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java b/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java
index 716b8ec53..b8706bb9b 100644
--- a/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java
+++ b/BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java
@@ -3,6 +3,7 @@
* ONAP Policy Engine
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -424,27 +425,9 @@ public class BrmsPush {
}
// Check User Specific values.
if ("$controller:".equals(key)) {
- try {
- final PEDependency dependency = PolicyUtils.jsonStringToObject(value, PEDependency.class);
- userControllerName = key.replaceFirst("$controller:", "");
- LOGGER.info("addRule: userControllerName - " + userControllerName + ", dependency: - "
- + dependency);
- addToGroup(userControllerName, dependency);
- } catch (final Exception e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Controller: " + e);
- }
-
+ userControllerName = getUserControllerName(key, value);
} else if ("$dependency$".equals(key) && value.startsWith("[") && value.endsWith("]")) {
- value = value.substring(1, value.length() - 1).trim();
- final List<String> dependencyStrings = Arrays.asList(value.split(Pattern.quote("},{")));
- for (final String dependencyString : dependencyStrings) {
- try {
- userDependencies.add(PolicyUtils.jsonStringToObject(dependencyString, PEDependency.class));
- } catch (final Exception e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Dependencies: "
- + e);
- }
- }
+ updateUserDependencies(userDependencies, value);
}
}
if (userControllerName != null) {
@@ -479,6 +462,35 @@ public class BrmsPush {
}
}
+ private String getUserControllerName(String key, String value) {
+ String userControllerName = null;
+ // Check User Specific values.
+ try {
+ final PEDependency dependency = PolicyUtils.jsonStringToObject(value, PEDependency.class);
+ userControllerName = key.replaceFirst("$controller:", "");
+ LOGGER.info("addRule: userControllerName - " + userControllerName + ", dependency: - "
+ + dependency);
+ addToGroup(userControllerName, dependency);
+ } catch (final Exception e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Controller: " + e);
+ }
+ return userControllerName;
+ }
+
+ private void updateUserDependencies(ArrayList<PEDependency> userDependencies, String value) {
+ //update the user dependencies supplied as parameter to this method
+ value = value.substring(1, value.length() - 1).trim();
+ final List<String> dependencyStrings = Arrays.asList(value.split(Pattern.quote("},{")));
+ for (final String dependencyString : dependencyStrings) {
+ try {
+ userDependencies.add(PolicyUtils.jsonStringToObject(dependencyString, PEDependency.class));
+ } catch (final Exception e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Dependencies: "
+ + e);
+ }
+ }
+ }
+
private void syncGroupInfo() {
// Sync DB to JMemory.
final EntityTransaction et = em.getTransaction();
@@ -624,45 +636,49 @@ public class BrmsPush {
try (JarFile jar = new JarFile(jarFileName)) {
final Enumeration<?> enumEntries = jar.entries();
while (enumEntries.hasMoreElements()) {
- final JarEntry jarEntry = (JarEntry) enumEntries.nextElement();
- File file = null;
- final String fileName = jarEntry.getName().substring(jarEntry.getName().lastIndexOf("/") + 1);
- if (jarEntry.getName().endsWith(".drl")) {
- final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src"
- + File.separator + "main" + File.separator + RESOURCES + File.separator + RULES;
- new File(path).mkdirs();
- if (syncFlag && policyMap.containsKey(fileName.replace(".drl", ""))) {
- file = new File(path + File.separator + fileName);
- } else {
- file = new File(path + File.separator + fileName);
- }
- } else if (jarEntry.getName().endsWith(POM_XML_FILE)) {
- final String path = PROJECTSLOCATION + File.separator + artifactId;
- new File(path).mkdirs();
- file = new File(path + File.separator + fileName);
- } else if (jarEntry.getName().endsWith(KMODULE_XML_FILE)) {
- final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src"
- + File.separator + "main" + File.separator + RESOURCES + File.separator + META_INF;
- new File(path).mkdirs();
- file = new File(path + File.separator + fileName);
- }
- if (file != null) {
- try (InputStream is = jar.getInputStream(jarEntry);
- FileOutputStream fos = new FileOutputStream(file)) {
- while (is.available() > 0) {
- fos.write(is.read());
- }
- LOGGER.info(fileName + " Created..");
- } catch (final IOException e) {
- LOGGER.info("exception Occured" + e);
- }
- }
+ parseJarContents(artifactId, jar, enumEntries);
}
} catch (final IOException e) {
LOGGER.info("exception Occured" + e);
}
}
+ private void parseJarContents(String artifactId, JarFile jar, Enumeration<?> enumEntries) {
+ final JarEntry jarEntry = (JarEntry) enumEntries.nextElement();
+ File file = null;
+ final String fileName = jarEntry.getName().substring(jarEntry.getName().lastIndexOf("/") + 1);
+ if (jarEntry.getName().endsWith(".drl")) {
+ final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src"
+ + File.separator + "main" + File.separator + RESOURCES + File.separator + RULES;
+ new File(path).mkdirs();
+ if (syncFlag && policyMap.containsKey(fileName.replace(".drl", ""))) {
+ file = new File(path + File.separator + fileName);
+ } else {
+ file = new File(path + File.separator + fileName);
+ }
+ } else if (jarEntry.getName().endsWith(POM_XML_FILE)) {
+ final String path = PROJECTSLOCATION + File.separator + artifactId;
+ new File(path).mkdirs();
+ file = new File(path + File.separator + fileName);
+ } else if (jarEntry.getName().endsWith(KMODULE_XML_FILE)) {
+ final String path = PROJECTSLOCATION + File.separator + artifactId + File.separator + "src"
+ + File.separator + "main" + File.separator + RESOURCES + File.separator + META_INF;
+ new File(path).mkdirs();
+ file = new File(path + File.separator + fileName);
+ }
+ if (file != null) {
+ try (InputStream is = jar.getInputStream(jarEntry);
+ FileOutputStream fos = new FileOutputStream(file)) {
+ while (is.available() > 0) {
+ fos.write(is.read());
+ }
+ LOGGER.info(fileName + " Created..");
+ } catch (final IOException e) {
+ LOGGER.info("exception Occured" + e);
+ }
+ }
+ }
+
private NexusArtifact getLatestArtifactFromNexus(final String selectedName) {
final List<NexusArtifact> artifacts = getArtifactFromNexus(selectedName, null);
int bigNum = 0;
@@ -771,41 +787,8 @@ public class BrmsPush {
LOGGER.error("Error while starting Transaction " + e);
}
if (!modifiedGroups.isEmpty()) {
- Boolean flag = false;
- for (final Map.Entry<String, String> entry : modifiedGroups.entrySet()) {
- InvocationResult result = null;
- final String group = entry.getKey();
- try {
- LOGGER.info("PushRules: ModifiedGroups, Key: " + group + ", Value: " + entry.getValue());
- final InvocationRequest request = new DefaultInvocationRequest();
- setVersion(group);
- createPom(group);
- request.setPomFile(new File(
- PROJECTSLOCATION + File.separator + getArtifactId(group) + File.separator + POM_XML_FILE));
- request.setGoals(Arrays.asList(GOALS));
- final Invoker invoker = new DefaultInvoker();
- result = invoker.execute(request);
- if (result.getExecutionException() != null) {
- LOGGER.error(result.getExecutionException());
- } else if (result.getExitCode() != 0) {
- LOGGER.error("Maven Invocation failure..!");
- }
- } catch (final Exception e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Maven Invocation issue for "
- + getArtifactId(group) + e.getMessage(), e);
- }
- if (result != null && result.getExitCode() == 0) {
- LOGGER.info("Build Completed..!");
- if (createFlag) {
- addNotification(group, "create");
- } else {
- addNotification(group, entry.getValue());
- }
- flag = true;
- } else {
- throw new PolicyException(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Maven Invocation failure!");
- }
- }
+ Boolean flag;
+ flag = buildAndGenerateJarFile();
if (flag) {
sendNotification(controllers);
}
@@ -828,6 +811,45 @@ public class BrmsPush {
getNameAndSetRemove(controllerName, name);
}
+ private Boolean buildAndGenerateJarFile() throws PolicyException {
+ Boolean flag = false;
+ for (final Map.Entry<String, String> entry : modifiedGroups.entrySet()) {
+ InvocationResult result = null;
+ final String group = entry.getKey();
+ try {
+ LOGGER.info("PushRules: ModifiedGroups, Key: " + group + ", Value: " + entry.getValue());
+ final InvocationRequest request = new DefaultInvocationRequest();
+ setVersion(group);
+ createPom(group);
+ request.setPomFile(new File(
+ PROJECTSLOCATION + File.separator + getArtifactId(group) + File.separator + POM_XML_FILE));
+ request.setGoals(Arrays.asList(GOALS));
+ final Invoker invoker = new DefaultInvoker();
+ result = invoker.execute(request);
+ if (result.getExecutionException() != null) {
+ LOGGER.error(result.getExecutionException());
+ } else if (result.getExitCode() != 0) {
+ LOGGER.error("Maven Invocation failure..!");
+ }
+ } catch (final Exception e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Maven Invocation issue for "
+ + getArtifactId(group) + e.getMessage(), e);
+ }
+ if (result != null && result.getExitCode() == 0) {
+ LOGGER.info("Build Completed..!");
+ if (createFlag) {
+ addNotification(group, "create");
+ } else {
+ addNotification(group, entry.getValue());
+ }
+ flag = true;
+ } else {
+ throw new PolicyException(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Maven Invocation failure!");
+ }
+ }
+ return flag;
+ }
+
private String getGroupName(final String name) {
if (policyMap.containsKey(name)) {
return policyMap.get(name);