diff options
author | Jim Hahn <jrh3@att.com> | 2020-02-26 14:23:16 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-02-26 14:23:16 +0000 |
commit | d1a3d4f7fc8f754937f10e320389825316662b2d (patch) | |
tree | ad5d84906c59bb7f54ea9b4f685b07a2fdc31fa4 /services/services-engine/src/main | |
parent | e1735a6044b9a0b5ec8e3afede88744a7d57782a (diff) | |
parent | 35840d835f581c2d61de1c57fe9963e36eb15c9f (diff) |
Merge "Fix Java 11/Checkstyle/Sonar warnings"
Diffstat (limited to 'services/services-engine/src/main')
7 files changed, 98 insertions, 116 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactory.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactory.java index 30a44e024..2f6922a2b 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactory.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactory.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ public class EventConsumerFactory { * @throws ApexEventException on errors creating the Apex event consumer */ public ApexEventConsumer createConsumer(final String name, final EventHandlerParameters consumerParameters) - throws ApexEventException { + throws ApexEventException { // Get the carrier technology parameters final CarrierTechnologyParameters technologyParameters = consumerParameters.getCarrierTechnologyParameters(); @@ -54,11 +54,11 @@ public class EventConsumerFactory { final String consumerPluginClass = technologyParameters.getEventConsumerPluginClass(); Object consumerPluginObject = null; try { - consumerPluginObject = Class.forName(consumerPluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + consumerPluginObject = Class.forName(consumerPluginClass).getDeclaredConstructor().newInstance(); + } catch (final Exception e) { final String errorMessage = "could not create an Apex event consumer for \"" + name - + "\" for the carrier technology \"" + technologyParameters.getLabel() - + "\", specified event consumer plugin class \"" + consumerPluginClass + "\" not found"; + + "\" for the carrier technology \"" + technologyParameters.getLabel() + + "\", specified event consumer plugin class \"" + consumerPluginClass + "\" not found"; LOGGER.error(errorMessage, e); throw new ApexEventException(errorMessage, e); } @@ -66,9 +66,9 @@ public class EventConsumerFactory { // Check the class is an event consumer if (!(consumerPluginObject instanceof ApexEventConsumer)) { final String errorMessage = "could not create an Apex event consumer \"" + name - + "\" for the carrier technology \"" + technologyParameters.getLabel() - + "\", specified event consumer plugin class \"" + consumerPluginClass - + "\" is not an instance of \"" + ApexEventConsumer.class.getName() + "\""; + + "\" for the carrier technology \"" + technologyParameters.getLabel() + + "\", specified event consumer plugin class \"" + consumerPluginClass + + "\" is not an instance of \"" + ApexEventConsumer.class.getName() + "\""; LOGGER.error(errorMessage); throw new ApexEventException(errorMessage); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactory.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactory.java index 349a6e38f..e87e2fd78 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactory.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactory.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ public class EventProducerFactory { * @throws ApexEventException on errors creating the Apex event producer */ public ApexEventProducer createProducer(final String name, final EventHandlerParameters producerParameters) - throws ApexEventException { + throws ApexEventException { // Get the carrier technology parameters final CarrierTechnologyParameters technologyParameters = producerParameters.getCarrierTechnologyParameters(); @@ -54,11 +54,11 @@ public class EventProducerFactory { final String producerPluginClass = technologyParameters.getEventProducerPluginClass(); Object producerPluginObject = null; try { - producerPluginObject = Class.forName(producerPluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + producerPluginObject = Class.forName(producerPluginClass).getDeclaredConstructor().newInstance(); + } catch (final Exception e) { final String errorMessage = "could not create an Apex event producer for Producer \"" + name - + "\" for the carrier technology \"" + technologyParameters.getLabel() - + "\", specified event producer plugin class \"" + producerPluginClass + "\" not found"; + + "\" for the carrier technology \"" + technologyParameters.getLabel() + + "\", specified event producer plugin class \"" + producerPluginClass + "\" not found"; LOGGER.error(errorMessage, e); throw new ApexEventException(errorMessage, e); } @@ -66,9 +66,9 @@ public class EventProducerFactory { // Check the class is an event producer if (!(producerPluginObject instanceof ApexEventProducer)) { final String errorMessage = "could not create an Apex event producer for Producer \"" + name - + "\" for the carrier technology \"" + technologyParameters.getLabel() - + "\", specified event producer plugin class \"" + producerPluginClass - + "\" is not an instance of \"" + ApexEventProducer.class.getName() + "\""; + + "\" for the carrier technology \"" + technologyParameters.getLabel() + + "\", specified event producer plugin class \"" + producerPluginClass + + "\" is not an instance of \"" + ApexEventProducer.class.getName() + "\""; LOGGER.error(errorMessage); throw new ApexEventException(errorMessage); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactory.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactory.java index b2a6f4754..bb353899a 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactory.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactory.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,17 +46,17 @@ public class EventProtocolFactory { * @return The event converter for converting events to and from Apex format */ public ApexEventProtocolConverter createConverter(final String name, - final EventProtocolParameters eventProtocolParameters) { + final EventProtocolParameters eventProtocolParameters) { // Get the class for the event protocol plugin using reflection final String eventProtocolPluginClass = eventProtocolParameters.getEventProtocolPluginClass(); Object eventProtocolPluginObject = null; try { - eventProtocolPluginObject = Class.forName(eventProtocolPluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + eventProtocolPluginObject = Class.forName(eventProtocolPluginClass).getDeclaredConstructor().newInstance(); + } catch (final Exception e) { final String errorMessage = "could not create an Apex event protocol converter for \"" + name - + "\" for the protocol \"" + eventProtocolParameters.getLabel() - + "\", specified event protocol converter plugin class \"" + eventProtocolPluginClass - + "\" not found"; + + "\" for the protocol \"" + eventProtocolParameters.getLabel() + + "\", specified event protocol converter plugin class \"" + eventProtocolPluginClass + + "\" not found"; LOGGER.error(errorMessage, e); throw new ApexEventRuntimeException(errorMessage, e); } @@ -64,9 +64,9 @@ public class EventProtocolFactory { // Check the class is an event consumer if (!(eventProtocolPluginObject instanceof ApexEventProtocolConverter)) { final String errorMessage = "could not create an Apex event protocol converter for \"" + name - + "\" for the protocol \"" + eventProtocolParameters.getLabel() - + "\", specified event protocol converter plugin class \"" + eventProtocolPluginClass - + "\" is not an instance of \"" + ApexEventProtocolConverter.class.getName() + "\""; + + "\" for the protocol \"" + eventProtocolParameters.getLabel() + + "\", specified event protocol converter plugin class \"" + eventProtocolPluginClass + + "\" is not an instance of \"" + ApexEventProtocolConverter.class.getName() + "\""; LOGGER.error(errorMessage); throw new ApexEventRuntimeException(errorMessage); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java index 5b5c7f49b..4da605dbc 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorker.java @@ -25,6 +25,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonParser; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; @@ -34,7 +35,9 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.BlockingQueue; + import lombok.Setter; + import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.context.ContextRuntimeException; import org.onap.policy.apex.context.SchemaHelper; @@ -113,7 +116,7 @@ final class EngineWorker implements EngineService { * @throws ApexException thrown on errors on worker instantiation */ protected EngineWorker(final AxArtifactKey engineWorkerKey, final BlockingQueue<ApexEvent> queue, - final ApplicationThreadFactory threadFactory) { + final ApplicationThreadFactory threadFactory) { LOGGER.entry(engineWorkerKey); this.engineWorkerKey = engineWorkerKey; @@ -153,7 +156,7 @@ final class EngineWorker implements EngineService { @Override public EngineServiceEventInterface getEngineServiceEventInterface() { throw new UnsupportedOperationException( - "getEngineServiceEventInterface() call is not allowed on an Apex Engine Worker"); + "getEngineServiceEventInterface() call is not allowed on an Apex Engine Worker"); } /** @@ -189,7 +192,7 @@ final class EngineWorker implements EngineService { */ @Override public void updateModel(final AxArtifactKey engineKey, final String engineModel, final boolean forceFlag) - throws ApexException { + throws ApexException { LOGGER.entry(engineKey); // Read the Apex model into memory using the Apex Model Reader @@ -198,7 +201,6 @@ final class EngineWorker implements EngineService { final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class); apexPolicyModel = modelReader.read(new ByteArrayInputStream(engineModel.getBytes())); } catch (final ApexModelException e) { - LOGGER.error("failed to unmarshal the apex model on engine " + engineKey.getId(), e); throw new ApexException("failed to unmarshal the apex model on engine " + engineKey.getId(), e); } @@ -213,14 +215,13 @@ final class EngineWorker implements EngineService { */ @Override public void updateModel(final AxArtifactKey engineKey, final AxPolicyModel apexModel, final boolean forceFlag) - throws ApexException { + throws ApexException { LOGGER.entry(engineKey); // Check if the key on the update request is correct if (!engineWorkerKey.equals(engineKey)) { - String message = ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() - + ENGINE_SUFFIX; - LOGGER.warn(message); + String message = + ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + ENGINE_SUFFIX; throw new ApexException(message); } @@ -230,14 +231,15 @@ final class EngineWorker implements EngineService { final AxPolicyModel currentModel = ModelService.getModel(AxPolicyModel.class); if (!currentModel.getKey().isCompatible(apexModel.getKey())) { if (forceFlag) { - LOGGER.warn("apex model update forced, supplied model with key \"" + apexModel.getKey().getId() - + "\" is not a compatible model update from the existing engine model with key \"" - + currentModel.getKey().getId() + "\""); + LOGGER.warn( + "apex model update forced, supplied model with key \"{}\" is not a compatible model update " + + "from the existing engine model with key \"{}\"", + apexModel.getKey().getId(), currentModel.getKey().getId()); } else { throw new ContextException( - "apex model update failed, supplied model with key \"" + apexModel.getKey().getId() - + "\" is not a compatible model update from the existing engine model with key \"" - + currentModel.getKey().getId() + "\""); + "apex model update failed, supplied model with key \"" + apexModel.getKey().getId() + + "\" is not a compatible model update from the existing engine model with key \"" + + currentModel.getKey().getId() + "\""); } } } @@ -273,16 +275,14 @@ final class EngineWorker implements EngineService { // Check if the key on the start request is correct if (!engineWorkerKey.equals(engineKey)) { - LOGGER.warn( - ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + ENGINE_SUFFIX); - throw new ApexException( - ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + ENGINE_SUFFIX); + throw new ApexException(ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + + ENGINE_SUFFIX); } // Starts the event processing thread that handles incoming events if (processorThread != null && processorThread.isAlive()) { - String message = ENGINE_FOR_KEY_PREFIX + engineWorkerKey.getId() + " is already running with state " - + getState(); + String message = + ENGINE_FOR_KEY_PREFIX + engineWorkerKey.getId() + " is already running with state " + getState(); LOGGER.error(message); throw new ApexException(message); } @@ -312,18 +312,18 @@ final class EngineWorker implements EngineService { public void stop(final AxArtifactKey engineKey) throws ApexException { // Check if the key on the start request is correct if (!engineWorkerKey.equals(engineKey)) { - LOGGER.warn( - ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + ENGINE_SUFFIX); - throw new ApexException( - ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + ENGINE_SUFFIX); + LOGGER.warn(ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + + ENGINE_SUFFIX); + throw new ApexException(ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + + ENGINE_SUFFIX); } // Interrupt the worker to stop its thread if (processorThread == null || !processorThread.isAlive()) { processorThread = null; - LOGGER - .warn(ENGINE_FOR_KEY_PREFIX + engineWorkerKey.getId() + " is already stopped with state " + getState()); + LOGGER.warn( + ENGINE_FOR_KEY_PREFIX + engineWorkerKey.getId() + " is already stopped with state " + getState()); return; } @@ -352,10 +352,10 @@ final class EngineWorker implements EngineService { public void clear(final AxArtifactKey engineKey) throws ApexException { // Check if the key on the start request is correct if (!engineWorkerKey.equals(engineKey)) { - LOGGER.warn( - ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + ENGINE_SUFFIX); - throw new ApexException( - ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + ENGINE_SUFFIX); + LOGGER.warn(ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + + ENGINE_SUFFIX); + throw new ApexException(ENGINE_KEY_PREFIX + engineKey.getId() + BAD_KEY_MATCH_TAG + engineWorkerKey.getId() + + ENGINE_SUFFIX); } // Interrupt the worker to stop its thread @@ -513,18 +513,18 @@ final class EngineWorker implements EngineService { runtimeJsonStringBuilder.append(",\"AlbumContent\":["); // Get the schema helper to use to marshal context album objects to JSON - final AxContextAlbum axContextAlbum = ModelService.getModel(AxContextAlbums.class) - .get(contextAlbumEntry.getKey()); + final AxContextAlbum axContextAlbum = + ModelService.getModel(AxContextAlbums.class).get(contextAlbumEntry.getKey()); SchemaHelper schemaHelper = null; try { // Get a schema helper to manage the translations between objects on the album map // for this album schemaHelper = new SchemaHelperFactory().createSchemaHelper(axContextAlbum.getKey(), - axContextAlbum.getItemSchema()); + axContextAlbum.getItemSchema()); } catch (final ContextRuntimeException e) { - final String resultString = "could not find schema helper to marshal context album \"" + axContextAlbum - + "\" to JSON"; + final String resultString = + "could not find schema helper to marshal context album \"" + axContextAlbum + "\" to JSON"; LOGGER.warn(resultString, e); // End of context album entry @@ -557,8 +557,7 @@ final class EngineWorker implements EngineService { runtimeJsonStringBuilder.append("]}"); // Tidy up the JSON string - final JsonParser jsonParser = new JsonParser(); - final JsonElement jsonElement = jsonParser.parse(runtimeJsonStringBuilder.toString()); + final JsonElement jsonElement = JsonParser.parseString(runtimeJsonStringBuilder.toString()); final String tidiedRuntimeString = gson.toJson(jsonElement); LOGGER.debug("runtime information={}", tidiedRuntimeString); diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJsonAdapter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJsonAdapter.java index 35f648307..b7f2fb81d 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJsonAdapter.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParametersJsonAdapter.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -52,7 +53,6 @@ public class CarrierTechnologyParametersJsonAdapter private static final String VALUE_TAG = "\" value \""; private static final String CARRIER_TECHNOLOGY_PREAMBLE = "carrier technology \""; - private static final String PARAMETER_CLASS_NAME = "parameterClassName"; private static final String CARRIER_TECHNOLOGY_TOKEN = "carrierTechnology"; @@ -62,8 +62,7 @@ public class CarrierTechnologyParametersJsonAdapter private static final Map<String, String> BUILT_IN_CARRIER_TECHNOLOGY_PARMETER_CLASS_MAP = new HashMap<>(); static { - BUILT_IN_CARRIER_TECHNOLOGY_PARMETER_CLASS_MAP.put("FILE", - FileCarrierTechnologyParameters.class.getName()); + BUILT_IN_CARRIER_TECHNOLOGY_PARMETER_CLASS_MAP.put("FILE", FileCarrierTechnologyParameters.class.getName()); BUILT_IN_CARRIER_TECHNOLOGY_PARMETER_CLASS_MAP.put("EVENT_REQUESTOR", EventRequestorCarrierTechnologyParameters.class.getName()); } @@ -151,8 +150,8 @@ public class CarrierTechnologyParametersJsonAdapter // OK no parameters for the carrier technology have been specified, just instantiate the // default parameters try { - carrierTechnologyParameters = - (CarrierTechnologyParameters) carrierTechnologyParameterClass.newInstance(); + carrierTechnologyParameters = (CarrierTechnologyParameters) carrierTechnologyParameterClass + .getDeclaredConstructor().newInstance(); } catch (final Exception e) { final String errorMessage = "could not create default parameters for carrier technology \"" + carrierTechnologyLabel + "\"\n" + e.getMessage(); @@ -164,11 +163,11 @@ public class CarrierTechnologyParametersJsonAdapter // Check that the carrier technology label matches the label in the carrier technology // parameters object if (!carrierTechnologyParameters.getLabel().equals(carrierTechnologyLabel)) { - final String errorMessage = CARRIER_TECHNOLOGY_PREAMBLE + carrierTechnologyLabel - + "\" does not match plugin \"" - + carrierTechnologyParameters.getLabel() + "\" in \"" + carrierTechnologyParameterClassName - + "\", specify correct carrier technology parameter plugin in parameter \"" + PARAMETER_CLASS_NAME - + "\""; + final String errorMessage = + CARRIER_TECHNOLOGY_PREAMBLE + carrierTechnologyLabel + "\" does not match plugin \"" + + carrierTechnologyParameters.getLabel() + "\" in \"" + carrierTechnologyParameterClassName + + "\", specify correct carrier technology parameter plugin in parameter \"" + + PARAMETER_CLASS_NAME + "\""; LOGGER.warn(errorMessage); throw new ParameterRuntimeException(errorMessage); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/RestPluginCarrierTechnologyParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/RestPluginCarrierTechnologyParameters.java index f548f636a..707dcb104 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/RestPluginCarrierTechnologyParameters.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/RestPluginCarrierTechnologyParameters.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +33,8 @@ import javax.ws.rs.core.MultivaluedMap; import lombok.Getter; import lombok.Setter; + import org.apache.commons.lang3.StringUtils; -import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; import org.onap.policy.common.parameters.GroupValidationResult; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.common.utils.validation.ParameterValidationUtils; @@ -68,18 +68,12 @@ public class RestPluginCarrierTechnologyParameters extends CarrierTechnologyPara /** The supported HTTP methods. */ public enum HttpMethod { - GET, PUT, POST, DELETE + GET, + PUT, + POST, + DELETE } - /** The label of this carrier technology. */ - protected String CARRIER_TECHNOLOGY_LABEL; - - /** The producer plugin class for the REST carrier technology. */ - protected String EVENT_PRODUCER_PLUGIN_CLASS; - - /** The consumer plugin class for the REST carrier technology. */ - protected String EVENT_CONSUMER_PLUGIN_CLASS; - /** The default HTTP code filter, allows 2xx HTTP codes through. */ public static final String DEFAULT_HTTP_CODE_FILTER = "[2][0-9][0-9]"; @@ -92,7 +86,7 @@ public class RestPluginCarrierTechnologyParameters extends CarrierTechnologyPara protected static final Pattern patternErrorKey = Pattern.compile("(\\{[^\\{}]*.?\\{)|(\\{[^\\{}]*$)|(\\}[^\\{}]*.?\\})|(^[^\\{}]*.?\\})|\\{\\s*\\}"); - //variable + // variable protected String url = null; protected HttpMethod httpMethod = null; protected String[][] httpHeaders = null; @@ -104,14 +98,6 @@ public class RestPluginCarrierTechnologyParameters extends CarrierTechnologyPara */ public RestPluginCarrierTechnologyParameters() { super(); - - // Set the carrier technology properties for the web socket carrier technology - CARRIER_TECHNOLOGY_LABEL = "RESTPLUGIN"; - EVENT_PRODUCER_PLUGIN_CLASS = "PRODUCER"; - EVENT_CONSUMER_PLUGIN_CLASS = "CONSUMER"; - this.setLabel(CARRIER_TECHNOLOGY_LABEL); - this.setEventProducerPluginClass(EVENT_PRODUCER_PLUGIN_CLASS); - this.setEventConsumerPluginClass(EVENT_CONSUMER_PLUGIN_CLASS); } /** @@ -173,9 +159,8 @@ public class RestPluginCarrierTechnologyParameters extends CarrierTechnologyPara public GroupValidationResult validate() { GroupValidationResult result = super.validate(); - result = validateUrl(result); - - result = validateHttpHeaders(result); + validateUrl(result); + validateHttpHeaders(result); return validateHttpCodeFilter(result); } @@ -195,16 +180,15 @@ public class RestPluginCarrierTechnologyParameters extends CarrierTechnologyPara // @formatter:on public GroupValidationResult validateUrl(final GroupValidationResult result) { // Check if the URL has been set for event output - String URL_ERROR_MSG = "no URL has been set for event sending on " + CARRIER_TECHNOLOGY_LABEL; + String urlErrorMessage = "no URL has been set for event sending on " + getLabel(); if (getUrl() == null) { - result.setResult("url", ValidationStatus.INVALID, URL_ERROR_MSG); + result.setResult("url", ValidationStatus.INVALID, urlErrorMessage); return result; } Matcher matcher = patternErrorKey.matcher(getUrl()); if (matcher.find()) { - result.setResult("url", ValidationStatus.INVALID, - URL_ERROR_MSG); + result.setResult("url", ValidationStatus.INVALID, urlErrorMessage); } return result; @@ -271,7 +255,7 @@ public class RestPluginCarrierTechnologyParameters extends CarrierTechnologyPara */ @Override public String toString() { - return CARRIER_TECHNOLOGY_LABEL +"CarrierTechnologyParameters [url=" + url + ", httpMethod=" + httpMethod + ", httpHeaders=" + return getLabel() + "CarrierTechnologyParameters [url=" + url + ", httpMethod=" + httpMethod + ", httpHeaders=" + Arrays.deepToString(httpHeaders) + ", httpCodeFilter=" + httpCodeFilter + "]"; } } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJsonAdapter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJsonAdapter.java index 10941405b..5a1b165df 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJsonAdapter.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParametersJsonAdapter.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -39,8 +40,7 @@ import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; /** - * This class serialises and deserialises various type of event protocol parameters to and from - * JSON. + * This class serialises and deserialises various type of event protocol parameters to and from JSON. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -132,9 +132,8 @@ public class EventProtocolParametersJsonAdapter try { eventProtocolParameterClass = Class.forName(eventProtocolParameterClassName); } catch (final ClassNotFoundException e) { - final String errorMessage = - EVENT_PROTOCOL_PREFIX + eventProtocolLabel + "\" parameter \"" + PARAMETER_CLASS_NAME + VALUE_TAG - + eventProtocolParameterClassName + "\", could not find class"; + final String errorMessage = EVENT_PROTOCOL_PREFIX + eventProtocolLabel + "\" parameter \"" + + PARAMETER_CLASS_NAME + VALUE_TAG + eventProtocolParameterClassName + "\", could not find class"; LOGGER.warn(errorMessage, e); throw new ParameterRuntimeException(errorMessage, e); } @@ -146,7 +145,8 @@ public class EventProtocolParametersJsonAdapter // OK no parameters for the event protocol have been specified, just instantiate the // default parameters try { - eventProtocolParameters = (EventProtocolParameters) eventProtocolParameterClass.newInstance(); + eventProtocolParameters = + (EventProtocolParameters) eventProtocolParameterClass.getDeclaredConstructor().newInstance(); } catch (final Exception e) { final String errorMessage = "could not create default parameters for event protocol \"" + eventProtocolLabel + "\"\n" + e.getMessage(); |