From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- .../openecomp/sdcrests/common/RestConstants.java | 18 ++- .../sdcrests/common/mapping/MapErrorCodeToDto.java | 18 +-- .../common/mapping/MapErrorMessageToDto.java | 16 +-- .../sdcrests/common/types/ErrorCodeDto.java | 48 ++++---- .../sdcrests/common/types/ErrorMessageDto.java | 34 +++--- .../sdcrests/errors/DefaultExceptionMapper.java | 40 ++----- .../sdcrests/errors/ZusammenExceptionMapper.java | 38 +++---- .../sdcrests/filters/SessionContextFilter.java | 55 ++++------ .../openecomp/sdcrests/mapping/EchoMapMapping.java | 9 +- .../openecomp/sdcrests/mapping/MappingBase.java | 121 +++++++++------------ .../wrappers/GenericCollectionWrapper.java | 90 ++++++++------- .../sdcrests/wrappers/StringWrapperResponse.java | 31 +++--- 12 files changed, 228 insertions(+), 290 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main') diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java index 230d1610eb..3f7dd523f9 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java @@ -13,20 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.common; public class RestConstants { - // value Should be equal to com.tlv.sdc.common.api.Constants#USER_ID_HEADER - public static final String USER_ID_HEADER_PARAM = "USER_ID"; - public static final String LAST_DELIVERED_QUERY_PARAM = "LAST_DELIVERED_EVENT_ID"; - public static final String USER_MISSING_ERROR_MSG = - "Field does not conform to predefined criteria : user : may not be null"; - - public static final String INVALID_JSON_ERROR_MESSAGE = - "Field does not conform to predefined criteria : body :must be in JSON format"; - private RestConstants() { + // value Should be equal to com.tlv.sdc.common.api.Constants#USER_ID_HEADER + public static final String USER_ID_HEADER_PARAM = "USER_ID"; + public static final String LAST_DELIVERED_QUERY_PARAM = "LAST_DELIVERED_EVENT_ID"; + public static final String USER_MISSING_ERROR_MSG = "Field does not conform to predefined criteria : user : may not be null"; + public static final String INVALID_JSON_ERROR_MESSAGE = "Field does not conform to predefined criteria : body :must be in JSON format"; - } + private RestConstants() { + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorCodeToDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorCodeToDto.java index cad5c69899..558d2e7c22 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorCodeToDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorCodeToDto.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.common.mapping; import org.openecomp.sdc.common.errors.ErrorCode; @@ -25,10 +24,11 @@ import org.openecomp.sdcrests.common.types.ErrorCodeDto; import org.openecomp.sdcrests.mapping.MappingBase; public class MapErrorCodeToDto extends MappingBase { - @Override - public void doMapping(ErrorCode source, ErrorCodeDto target) { - target.setId(source.id()); - target.setCategory(source.category()); - target.setMessage(source.message()); - } + + @Override + public void doMapping(ErrorCode source, ErrorCodeDto target) { + target.setId(source.id()); + target.setCategory(source.category()); + target.setMessage(source.message()); + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorMessageToDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorMessageToDto.java index 83c7b15980..78262b8c30 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorMessageToDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorMessageToDto.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.common.mapping; import org.openecomp.sdc.datatypes.error.ErrorMessage; @@ -25,9 +24,10 @@ import org.openecomp.sdcrests.common.types.ErrorMessageDto; import org.openecomp.sdcrests.mapping.MappingBase; public class MapErrorMessageToDto extends MappingBase { - @Override - public void doMapping(ErrorMessage source, ErrorMessageDto target) { - target.setMessage(source.getMessage()); - target.setLevel(source.getLevel()); - } + + @Override + public void doMapping(ErrorMessage source, ErrorMessageDto target) { + target.setMessage(source.getMessage()); + target.setLevel(source.getLevel()); + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorCodeDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorCodeDto.java index 3615f89afc..f70d863653 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorCodeDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorCodeDto.java @@ -7,9 +7,9 @@ * 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. @@ -17,37 +17,37 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.common.types; import org.openecomp.sdc.common.errors.ErrorCategory; public class ErrorCodeDto { - private String id; - private String message; - private ErrorCategory category; - public String getId() { - return id; - } + private String id; + private String message; + private ErrorCategory category; + + public String getId() { + return id; + } - public void setId(String id) { - this.id = id; - } + public void setId(String id) { + this.id = id; + } - public String getMessage() { - return message; - } + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } - public ErrorCategory getCategory() { - return category; - } + public ErrorCategory getCategory() { + return category; + } - public void setCategory(ErrorCategory category) { - this.category = category; - } + public void setCategory(ErrorCategory category) { + this.category = category; + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorMessageDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorMessageDto.java index f63a9b0ced..9bac491ed1 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorMessageDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorMessageDto.java @@ -7,9 +7,9 @@ * 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. @@ -17,28 +17,28 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.common.types; import org.openecomp.sdc.datatypes.error.ErrorLevel; public class ErrorMessageDto { - private ErrorLevel level; - private String message; - public ErrorLevel getLevel() { - return level; - } + private ErrorLevel level; + private String message; + + public ErrorLevel getLevel() { + return level; + } - public void setLevel(ErrorLevel level) { - this.level = level; - } + public void setLevel(ErrorLevel level) { + this.level = level; + } - public String getMessage() { - return message; - } + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java index 9fe70fc5e5..0546180575 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java @@ -13,23 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.errors; +import com.fasterxml.jackson.databind.JsonMappingException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; - import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolationException; import javax.validation.Path; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; - import org.apache.commons.collections4.CollectionUtils; -import com.fasterxml.jackson.databind.JsonMappingException; import org.hibernate.validator.internal.engine.path.PathImpl; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.utilities.json.JsonUtil; @@ -47,9 +44,8 @@ public class DefaultExceptionMapper implements ExceptionMapper { private static final String ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE = "errorCodesToResponseStatusMapping.json"; @SuppressWarnings("unchecked") - private static final Map ERROR_CODE_TO_RESPONSE_STATUS = FileUtils.readViaInputStream( - ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE, stream -> JsonUtil.json2Object(stream, Map.class)); - + private static final Map ERROR_CODE_TO_RESPONSE_STATUS = FileUtils + .readViaInputStream(ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE, stream -> JsonUtil.json2Object(stream, Map.class)); private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMapper.class); @Override @@ -59,14 +55,11 @@ public class DefaultExceptionMapper implements ExceptionMapper { response = transform(CoreException.class.cast(exception)); } else if (exception instanceof ConstraintViolationException) { response = transform(ConstraintViolationException.class.cast(exception)); - } else if (exception instanceof JsonMappingException) { response = transform(JsonMappingException.class.cast(exception)); - } else { response = transform(exception); } - List contentTypes = new ArrayList<>(); contentTypes.add(MediaType.APPLICATION_JSON); response.getMetadata().put("Content-Type", contentTypes); @@ -77,32 +70,23 @@ public class DefaultExceptionMapper implements ExceptionMapper { Response response; ErrorCode code = coreException.code(); LOGGER.error(code.message(), coreException); - if (coreException.code().category().equals(ErrorCategory.APPLICATION)) { if (Response.Status.NOT_FOUND.name().equals(ERROR_CODE_TO_RESPONSE_STATUS.get(code.id()))) { - response = Response.status(Response.Status.NOT_FOUND).entity(toEntity(Response.Status.NOT_FOUND, code)) - .build(); + response = Response.status(Response.Status.NOT_FOUND).entity(toEntity(Response.Status.NOT_FOUND, code)).build(); } else if (Response.Status.BAD_REQUEST.name().equals(ERROR_CODE_TO_RESPONSE_STATUS.get(code.id()))) { - response = - Response.status(Response.Status.BAD_REQUEST).entity(toEntity(Response.Status.BAD_REQUEST, code)) - .build(); + response = Response.status(Response.Status.BAD_REQUEST).entity(toEntity(Response.Status.BAD_REQUEST, code)).build(); } else { - response = Response.status(Response.Status.EXPECTATION_FAILED) - .entity(toEntity(Response.Status.EXPECTATION_FAILED, code)).build(); + response = Response.status(Response.Status.EXPECTATION_FAILED).entity(toEntity(Response.Status.EXPECTATION_FAILED, code)).build(); } } else { - response = Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, code)).build(); + response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, code)).build(); } - - return response; } private Response transform(ConstraintViolationException validationException) { Set> constraintViolationSet = validationException.getConstraintViolations(); String message; - String fieldName = null; if (CollectionUtils.isEmpty(constraintViolationSet)) { message = validationException.getMessage(); @@ -111,28 +95,24 @@ public class DefaultExceptionMapper implements ExceptionMapper { ConstraintViolation constraintViolation = constraintViolationSet.iterator().next(); message = constraintViolation.getMessage(); fieldName = getFieldName(constraintViolation.getPropertyPath()); - } - ErrorCode validationErrorCode = new ValidationErrorBuilder(message, fieldName).build(); - LOGGER.error(validationErrorCode.message(), validationException); return Response.status(Response.Status.EXPECTATION_FAILED) //error 417 - .entity(toEntity(Response.Status.EXPECTATION_FAILED, validationErrorCode)).build(); + .entity(toEntity(Response.Status.EXPECTATION_FAILED, validationErrorCode)).build(); } private Response transform(JsonMappingException jsonMappingException) { ErrorCode jsonMappingErrorCode = new JsonMappingErrorBuilder().build(); LOGGER.error(jsonMappingErrorCode.message(), jsonMappingException); return Response.status(Response.Status.EXPECTATION_FAILED) //error 417 - .entity(toEntity(Response.Status.EXPECTATION_FAILED, jsonMappingErrorCode)).build(); + .entity(toEntity(Response.Status.EXPECTATION_FAILED, jsonMappingErrorCode)).build(); } private Response transform(Exception exception) { ErrorCode errorCode = new GeneralErrorBuilder().build(); LOGGER.error(errorCode.message(), exception); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, errorCode)).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, errorCode)).build(); } private String getFieldName(Path propertyPath) { diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java index abf6024701..497d3cfeb7 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java @@ -13,16 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.errors; import com.amdocs.zusammen.datatypes.response.Module; - import java.util.stream.Stream; - import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; - import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.common.errors.ErrorCodeAndMessage; import org.openecomp.sdc.common.errors.GeneralErrorBuilder; @@ -32,19 +28,16 @@ import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; public class ZusammenExceptionMapper implements ExceptionMapper { + private static final String ZUSAMMEN_DB_PREFIX = Module.ZDB + "-"; static final String VLM_VSP_VERSION_ID_DOES_NOT_EXISTS = - ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_NOT_EXIST; + ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_NOT_EXIST; static final String VLM_VSP_ITEM_ID_DOES_NOT_EXISTS = - ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_DOES_NOT_EXIST; - static final String SUB_ENTITY_ID_DOES_NOT_EXISTS = - ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ELEMENT_GET_INFO; - static final String FAILED_TO_SYNC = - ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_SYNC; + ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_DOES_NOT_EXIST; + static final String SUB_ENTITY_ID_DOES_NOT_EXISTS = ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ELEMENT_GET_INFO; + static final String FAILED_TO_SYNC = ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_SYNC; static final String FAILED_TO_PUBLISH_OUT_OF_SYNC = - ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode - .ZU_ITEM_VERSION_PUBLISH_NOT_ALLOWED; - + ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_PUBLISH_NOT_ALLOWED; private static final Logger LOGGER = LoggerFactory.getLogger(ZusammenExceptionMapper.class); @Override @@ -53,29 +46,24 @@ public class ZusammenExceptionMapper implements ExceptionMapper, Map> { - @Override - public void doMapping(Map source, Map target) { - target.putAll(source); - } + @Override + public void doMapping(Map source, Map target) { + target.putAll(source); + } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java index 8b6fca5ae1..68a16e854c 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java @@ -13,86 +13,71 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.mapping; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCode; /** - * Base class for all mapping classes. Mapping classes will perform data mapping from source object - * to target object Base class provides following
  1. provides life cycle of - * mapping class , first mapSimpleProperties is called and then mapComplexProperties is - * called.
  2. methods mapSimpleProperties and mapComplexProperties with default - * implementation, these should be overridden by concrete mapping classes for writing mapping - * logic.
- * - * + * Base class for all mapping classes. Mapping classes will perform data mapping from source object to target object Base class provides + * following
+ *
  1. provides life cycle of mapping class , first mapSimpleProperties is called and then mapComplexProperties is called.
  2. methods + * mapSimpleProperties and mapComplexProperties with default implementation, these should be overridden by concrete mapping classes for writing + * mapping logic.
*/ - public abstract class MappingBase { - /** - * Method is called for starting mapping from source object to target object method sets context - * in the thread locale and than calls mapSimpleProperties and mapComplexProperties - * respectively. - * - * @param source : source object for mapping - * @param clazz : target Class for mapping - * @return T - instance of type T - */ - - public final T applyMapping(final S source, Class clazz) { - T target = (T) instantiateTarget(clazz); - if (source != null && target != null) { - preMapping(source, target); - doMapping(source, target); - postMapping(source, target); - + /** + * Method is called for starting mapping from source object to target object method sets context in the thread locale and than calls + * mapSimpleProperties and mapComplexProperties respectively. + * + * @param source : source object for mapping + * @param clazz : target Class for mapping + * @return T - instance of type T + */ + public final T applyMapping(final S source, Class clazz) { + T target = (T) instantiateTarget(clazz); + if (source != null && target != null) { + preMapping(source, target); + doMapping(source, target); + postMapping(source, target); + } + return target; } - return target; - - } - /** - * This method is called before the doMapping method. - */ - public void preMapping(final S source, T target) { - // extension point - } - - /** - * The actual method that does the mapping between the source to target - * objects. This method is being called automatically as part of the mapper class. This - * method must be override (it is abstract) by the mapper class. - * - * @param source - the source object. - * @param target - the target object. - */ - - public abstract void doMapping(final S source, T target); - - /** - * This method is called after the doMapping method. - */ - public void postMapping(final S source, T target) { - // extension point - } - - /** - * Creates the instance of the input class. - * - * @return Object - */ + /** + * This method is called before the doMapping method. + */ + public void preMapping(final S source, T target) { + // extension point + } - private Object instantiateTarget(final Class clazz) { + /** + * The actual method that does the mapping between the source to target objects. This method is being called + * automatically as part of the mapper class. This method must be override (it is abstract) by the mapper class. + * + * @param source - the source object. + * @param target - the target object. + */ + public abstract void doMapping(final S source, T target); + + /** + * This method is called after the doMapping method. + */ + public void postMapping(final S source, T target) { + // extension point + } - try { - return clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException exception ) { - throw new CoreException((new ErrorCode.ErrorCodeBuilder()) - .withMessage(exception.getMessage()).build(), exception); + /** + * Creates the instance of the input class. + * + * @return Object + */ + private Object instantiateTarget(final Class clazz) { + try { + return clazz.newInstance(); + } catch (InstantiationException | IllegalAccessException exception) { + throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage(exception.getMessage()).build(), exception); + } } - } } - diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java index b73d2d93c5..7bff3d5b77 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.wrappers; import java.io.Serializable; @@ -25,57 +24,56 @@ import java.util.ArrayList; import java.util.List; public class GenericCollectionWrapper implements Serializable { - private static final long serialVersionUID = 1L; - - private transient List results; - private int listCount; - public GenericCollectionWrapper() { - this.results = new ArrayList<>(); - } + private static final long serialVersionUID = 1L; + private transient List results; + private int listCount; - /** - * Instantiates a new Generic collection wrapper. - * - * @param list the list - */ - public GenericCollectionWrapper(List list) { - if (!list.isEmpty()) { - this.results = list; - this.listCount = list.size(); + public GenericCollectionWrapper() { + this.results = new ArrayList<>(); } - else { - this.results = new ArrayList<>(); + + /** + * Instantiates a new Generic collection wrapper. + * + * @param list the list + */ + public GenericCollectionWrapper(List list) { + if (!list.isEmpty()) { + this.results = list; + this.listCount = list.size(); + } else { + this.results = new ArrayList<>(); + } } - } - public List getResults() { - return results; - } + public List getResults() { + return results; + } - public void setResults(List results) { - this.results = results; - } + public void setResults(List results) { + this.results = results; + } - public int getListCount() { - return listCount; - } + public int getListCount() { + return listCount; + } - public void setListCount(int listCount) { - this.listCount = listCount; - } + public void setListCount(int listCount) { + this.listCount = listCount; + } - /** - * Add boolean. - * - * @param item the list item - * @return the boolean - */ - public boolean add(T item) { - if (this.getResults().add(item)) { - this.setListCount(this.getResults().size()); - return true; + /** + * Add boolean. + * + * @param item the list item + * @return the boolean + */ + public boolean add(T item) { + if (this.getResults().add(item)) { + this.setListCount(this.getResults().size()); + return true; + } + return false; } - return false; - } } diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/StringWrapperResponse.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/StringWrapperResponse.java index aad4e606de..0cfd5838f4 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/StringWrapperResponse.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/StringWrapperResponse.java @@ -13,28 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdcrests.wrappers; public class StringWrapperResponse { - private String value; - public StringWrapperResponse() { - // defualt ctor is used by reflection, for instance JSON mapping - super(); - } + private String value; - public StringWrapperResponse(String value) { - super(); - this.value = value; - } + public StringWrapperResponse() { + // defualt ctor is used by reflection, for instance JSON mapping + super(); + } - public String getValue() { - return value; - } + public StringWrapperResponse(String value) { + super(); + this.value = value; + } - public void setValue(String value) { - this.value = value; - } + public String getValue() { + return value; + } + public void setValue(String value) { + this.value = value; + } } -- cgit 1.2.3-korg