From f6cf95c5881e271a4e480b06c0e302ce8d570ec1 Mon Sep 17 00:00:00 2001 From: Munir Ahmad Date: Fri, 2 Mar 2018 19:45:34 -0500 Subject: [PATCH] Make use of lambda Change-Id: I3a9d2b98208bd37f2f0e05cbc3628484acdd96ed Issue-ID: SO-437 Signed-off-by: Munir Ahmad --- .../installer/heat/ToscaResourceInstaller.java | 55 ++++----- .../mso/asdc/util/NotificationLogging.java | 22 ++-- .../core/plugins/LoggingAndURNMappingPlugin.java | 10 +- .../tests/MsoPropertiesFactoryConcurrencyTest.java | 133 ++++++++++----------- 4 files changed, 98 insertions(+), 122 deletions(-) diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java index f22debce1e..65c30b86db 100644 --- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java @@ -419,38 +419,33 @@ public class ToscaResourceInstaller {// implements IVfResourceInstaller { toscaResourceStruct.getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID); logger.debug("vfGroups:" + vfGroups.toString()); - Collections.sort(vfGroups, new Comparator() { - - @Override - public int compare(org.openecomp.sdc.toscaparser.api.Group group1, - org.openecomp.sdc.toscaparser.api.Group group2) { - - // Field name1Field = group1.class.getDeclaredField("name"); - // name1Field.setAccessible(true); - String thisName = group1.getName(); // (String) - // name1Field.get(group1); - String thatName = group2.getName(); // (String) - // name1Field.get(group2); - - Matcher m = lastDigit.matcher(thisName); - Matcher m2 = lastDigit.matcher(thatName); - - String thisDigit = "0"; - String thatDigit = "0"; - if(m.find()) { - thisDigit = m.group(); - } else { - return -1; - } - if(m2.find()) { - thatDigit = m2.group(); - } else { - return 1; - } + Collections.sort(vfGroups, (group1, group2) -> { + + // Field name1Field = group1.class.getDeclaredField("name"); + // name1Field.setAccessible(true); + String thisName = group1.getName(); // (String) + // name1Field.get(group1); + String thatName = group2.getName(); // (String) + // name1Field.get(group2); + + Matcher m = lastDigit.matcher(thisName); + Matcher m2 = lastDigit.matcher(thatName); + + String thisDigit = "0"; + String thatDigit = "0"; + if(m.find()) { + thisDigit = m.group(); + } else { + return -1; + } + if(m2.find()) { + thatDigit = m2.group(); + } else { + return 1; + } - return new Integer(thisDigit).compareTo(new Integer(thatDigit)); + return new Integer(thisDigit).compareTo(new Integer(thatDigit)); - } }); logger.debug("vfGroupsAfter:" + vfGroups.toString()); diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/util/NotificationLogging.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/util/NotificationLogging.java index 126114d2d6..6983b010bb 100644 --- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/util/NotificationLogging.java +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/util/NotificationLogging.java @@ -44,19 +44,15 @@ public class NotificationLogging implements InvocationHandler { protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC); - private static InvocationHandler handler = new InvocationHandler() { - @Override - public Object invoke(Object arg0, Method arg1, Object[] arg2) - throws Throwable { - List methods = objectMethodsToLog.get(arg0); - if ((methods == null) || (methods.isEmpty())) { - // Do nothing for now... - return null; - } - methods.add(arg1); - return arg1.invoke(arg0, arg2); - } - }; + private static InvocationHandler handler = (arg0, arg1, arg2) -> { + List methods = objectMethodsToLog.get(arg0); + if ((methods == null) || (methods.isEmpty())) { + // Do nothing for now... + return null; + } + methods.add(arg1); + return arg1.invoke(arg0, arg2); + }; public static InvocationHandler getHandler() { return handler; diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/plugins/LoggingAndURNMappingPlugin.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/plugins/LoggingAndURNMappingPlugin.java index c346308e2b..07adc3c761 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/plugins/LoggingAndURNMappingPlugin.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/plugins/LoggingAndURNMappingPlugin.java @@ -321,14 +321,8 @@ public class LoggingAndURNMappingPlugin extends AbstractProcessEnginePlugin { } private void loadFromDB(DelegateExecution execution, ProcessEngineConfigurationImpl processEngineConfiguration) { - Command> command = new Command>() { - @SuppressWarnings("unchecked") - @Override - public List execute(CommandContext commandContext) { - return (List) commandContext.getDbSqlSession().selectList( - "mso.urnMapping.selectAll", null); - } - }; + Command> command = commandContext -> (List) commandContext.getDbSqlSession().selectList( + "mso.urnMapping.selectAll", null); CustomMyBatisSessionFactory sessionFactory = new CustomMyBatisSessionFactory(); sessionFactory.initFromProcessEngineConfiguration(processEngineConfiguration, diff --git a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java index f038cbc851..e61da21839 100644 --- a/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java +++ b/common/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoPropertiesFactoryConcurrencyTest.java @@ -70,77 +70,68 @@ public class MsoPropertiesFactoryConcurrencyTest { msoPropertiesFactory.initializeMsoProperties(MSO_PROP_ID, PATH_MSO_PROP1); } - private Callable taskReload = new Callable() { - @Override - public Integer call() { - try { - if (!msoPropertiesFactory.reloadMsoProperties()) { - return 1; - } - } catch (Exception e) { - e.printStackTrace (); - return 1; - } - return 0; - } - }; - - private Callable taskRead = new Callable() { - @Override - public Integer call() { - try { - MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_ID); - String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue"); - String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue"); - String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue"); - String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue"); - String property5 = msoProperties.getProperty("does.not.exist", "defaultValue"); - String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue"); - String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue"); - - assertEquals(property1, "MT"); - assertEquals(property2, "http://localhost:5000/v2.0"); - assertEquals(property3, "John"); - assertEquals(property4, "FD205490A48D48475607C36B9AD902BF"); - assertEquals(property5, "defaultValue"); - assertEquals(property6, "1234"); - assertEquals(property7, "true"); - - } catch (MsoPropertiesException e) { - e.printStackTrace (); - return 1; - } - return 0; - } - }; - - private Callable taskReadAll = new Callable() { - @Override - public Integer call() { - try { - List msoPropertiesList = msoPropertiesFactory.getAllMsoProperties(); - String property1 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue"); - String property2 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue"); - String property3 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.msoId", "defaultValue"); - String property4 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue"); - String property5 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("does.not.exist", "defaultValue"); - String property6 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.test", "defaultValue"); - String property7 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.boolean", "defaultValue"); - - assertEquals(property1, "MT"); - assertEquals(property2, "http://localhost:5000/v2.0"); - assertEquals(property3, "John"); - assertEquals(property4, "FD205490A48D48475607C36B9AD902BF"); - assertEquals(property5, "defaultValue"); - assertEquals(property6, "1234"); - assertEquals(property7, "true"); - } catch (Exception e) { - e.printStackTrace (); - return 1; - } - return 0; - } - }; + private Callable taskReload = () -> { + try { + if (!msoPropertiesFactory.reloadMsoProperties()) { + return 1; + } + } catch (Exception e) { + e.printStackTrace (); + return 1; + } + return 0; + }; + + private Callable taskRead = () -> { + try { + MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_PROP_ID); + String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue"); + String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue"); + String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue"); + String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue"); + String property5 = msoProperties.getProperty("does.not.exist", "defaultValue"); + String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue"); + String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue"); + + assertEquals(property1, "MT"); + assertEquals(property2, "http://localhost:5000/v2.0"); + assertEquals(property3, "John"); + assertEquals(property4, "FD205490A48D48475607C36B9AD902BF"); + assertEquals(property5, "defaultValue"); + assertEquals(property6, "1234"); + assertEquals(property7, "true"); + + } catch (MsoPropertiesException e) { +e.printStackTrace (); + return 1; + } + return 0; + }; + + private Callable taskReadAll = () -> { + try { + List msoPropertiesList = msoPropertiesFactory.getAllMsoProperties(); + String property1 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue"); + String property2 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue"); + String property3 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.msoId", "defaultValue"); + String property4 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue"); + String property5 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("does.not.exist", "defaultValue"); + String property6 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.test", "defaultValue"); + String property7 = ((MsoJavaProperties)msoPropertiesList.get(0)).getProperty("ecomp.mso.cloud.1.boolean", "defaultValue"); + + assertEquals(property1, "MT"); + assertEquals(property2, "http://localhost:5000/v2.0"); + assertEquals(property3, "John"); + assertEquals(property4, "FD205490A48D48475607C36B9AD902BF"); + assertEquals(property5, "defaultValue"); + assertEquals(property6, "1234"); + assertEquals(property7, "true"); + } catch (Exception e) { +e.printStackTrace (); + return 1; + } + return 0; + }; @Test public final void testGetMsoProperties() -- 2.16.6