From 44fa70bcf389af44484c984c5852e1aad397c43f Mon Sep 17 00:00:00 2001 From: kurczews Date: Mon, 4 Dec 2017 09:07:36 +0100 Subject: Remove duplicated constants Replace duplicated regex patterns with more verbose constant Change-Id: I21b5a1f8f00b8a8d059ab3998536b205ece892ce Issue-ID: SO-353 Signed-off-by: kurczews --- .../catalogrest/QueryServiceMacroHolder.java | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'adapters/mso-catalog-db-adapter/src') diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java index e5147671f3..2e70391c05 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java @@ -30,8 +30,9 @@ import java.util.Map; @XmlRootElement(name = "serviceResources") @NoJackson public class QueryServiceMacroHolder extends CatalogQuery { - private ServiceMacroHolder serviceMacroHolder; - private final String template = + private ServiceMacroHolder serviceMacroHolder; + private static final String LINE_BEGINNING = "(?m)^"; + private static final String template = "{ \"serviceResources\" : {\n"+ "\t\"modelInfo\" : {\n"+ "\t\t\"modelName\" : ,\n"+ @@ -46,7 +47,10 @@ public class QueryServiceMacroHolder extends CatalogQuery { "<_SERVICEALLOTTEDRESOURCES_>\n"+ "\t}}"; - public QueryServiceMacroHolder() { super(); serviceMacroHolder = new ServiceMacroHolder(); } + public QueryServiceMacroHolder() { + super(); + serviceMacroHolder = new ServiceMacroHolder(); + } public QueryServiceMacroHolder(ServiceMacroHolder vlist) { serviceMacroHolder = vlist; } public ServiceMacroHolder getServiceResources(){ return this.serviceMacroHolder; } @@ -58,7 +62,9 @@ public class QueryServiceMacroHolder extends CatalogQuery { @Override public String JSON2(boolean isArray, boolean x) { Service service = serviceMacroHolder.getService(); - if (service == null) return "\"serviceResources\": null"; + if (service == null) { + return "\"serviceResources\": null"; + } StringBuilder buf = new StringBuilder(); Map valueMap = new HashMap<>(); @@ -72,13 +78,13 @@ public class QueryServiceMacroHolder extends CatalogQuery { String subitem; subitem = new QueryServiceVnfs(serviceMacroHolder.getVnfResourceCustomizations()).JSON2(true, true); - valueMap.put("_SERVICEVNFS_", subitem.replaceAll("(?m)^", "\t")); + valueMap.put("_SERVICEVNFS_", subitem.replaceAll(LINE_BEGINNING, "\t")); subitem = new QueryServiceNetworks(serviceMacroHolder.getNetworkResourceCustomization()).JSON2(true, true); - valueMap.put("_SERVICENETWORKS_", subitem.replaceAll("(?m)^", "\t")); + valueMap.put("_SERVICENETWORKS_", subitem.replaceAll(LINE_BEGINNING, "\t")); subitem = new QueryAllottedResourceCustomization(serviceMacroHolder.getAllottedResourceCustomization()).JSON2(true, true); - valueMap.put("_SERVICEALLOTTEDRESOURCES_", subitem.replaceAll("(?m)^", "\t")); + valueMap.put("_SERVICEALLOTTEDRESOURCES_", subitem.replaceAll(LINE_BEGINNING, "\t")); buf.append(this.setTemplate(template, valueMap)); return buf.toString(); -- cgit 1.2.3-korg