diff options
Diffstat (limited to 'services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology')
2 files changed, 25 insertions, 42 deletions
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 + "]"; } } |