From f5f13c4f6b6fe3b4d98e349dfd7db59339803436 Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Sun, 19 Feb 2017 12:35:04 +0200 Subject: push addional code Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74 Signed-off-by: Michael Lando --- .../openecomp/sdcrests/common/RestConstants.java | 29 ++++ .../sdcrests/common/mapping/MapErrorCodeToDto.java | 34 +++++ .../common/mapping/MapErrorMessageToDto.java | 33 +++++ .../sdcrests/common/types/ErrorCodeDto.java | 53 +++++++ .../sdcrests/common/types/ErrorMessageDto.java | 44 ++++++ .../sdcrests/errors/DefaultExceptionMapper.java | 163 +++++++++++++++++++++ .../openecomp/sdcrests/mapping/MappingBase.java | 104 +++++++++++++ .../versioning/types/VersioningAction.java | 28 ++++ .../wrappers/GenericCollectionWrapper.java | 107 ++++++++++++++ .../sdcrests/wrappers/StringWrapperResponse.java | 42 ++++++ .../errorCodesToResponseStatusMapping.json | 9 ++ 11 files changed, 646 insertions(+) create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorCodeToDto.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorMessageToDto.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorCodeDto.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorMessageDto.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/versioning/types/VersioningAction.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/StringWrapperResponse.java create mode 100644 openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/resources/errorCodesToResponseStatusMapping.json (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src') 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 new file mode 100644 index 0000000000..499bd6e785 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/RestConstants.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.common; + +public class RestConstants { + public static final String USER_HEADER_PARAM = "USER_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"; +} 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 new file mode 100644 index 0000000000..cad5c69899 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorCodeToDto.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.common.mapping; + +import org.openecomp.sdc.common.errors.ErrorCode; +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()); + } +} 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 new file mode 100644 index 0000000000..83c7b15980 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/mapping/MapErrorMessageToDto.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.common.mapping; + +import org.openecomp.sdc.datatypes.error.ErrorMessage; +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()); + } +} 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 new file mode 100644 index 0000000000..3615f89afc --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorCodeDto.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============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; + } + + public void setId(String id) { + this.id = id; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public ErrorCategory getCategory() { + return 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 new file mode 100644 index 0000000000..f63a9b0ced --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/common/types/ErrorMessageDto.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============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; + } + + public void setLevel(ErrorLevel level) { + this.level = level; + } + + public String getMessage() { + return 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 new file mode 100644 index 0000000000..67da814f48 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java @@ -0,0 +1,163 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.errors; + +import org.codehaus.jackson.map.JsonMappingException; +import org.hibernate.validator.internal.engine.path.PathImpl; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.common.errors.ErrorCodeAndMessage; +import org.openecomp.sdc.common.errors.GeneralErrorBuilder; +import org.openecomp.sdc.common.errors.JsonMappingErrorBuilder; +import org.openecomp.sdc.common.errors.ValidationErrorBuilder; +import org.slf4j.LoggerFactory; + +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; + +public class DefaultExceptionMapper implements ExceptionMapper { + private static final String ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE = + "errorCodesToResponseStatusMapping.json"; + private static Map errorCodeToResponseStatus = JsonUtil + .json2Object(FileUtils.getFileInputStream(ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE), + Map.class); + private static org.slf4j.Logger logger = LoggerFactory.getLogger(DefaultExceptionMapper.class); + + @Override + public Response toResponse(Exception e0) { + Response response; + if (e0 instanceof CoreException) { + response = transform(CoreException.class.cast(e0)); + } else if (e0 instanceof ConstraintViolationException) { + response = transform(ConstraintViolationException.class.cast(e0)); + + } else if (e0 instanceof JsonMappingException) { + response = transform(JsonMappingException.class.cast(e0)); + + } else { + response = transform(e0); + } + + List contentTypes = new ArrayList<>(); + contentTypes.add(MediaType.APPLICATION_JSON); + response.getMetadata().put("Content-Type", contentTypes); + return response; + } + + private Response transform(CoreException coreException) { + 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(errorCodeToResponseStatus.get(code.id()))) { + response = Response + .status(Response.Status.NOT_FOUND) + .entity(toEntity(Response.Status.NOT_FOUND, code)) + .build(); + } else if (Response.Status.BAD_REQUEST.name() + .equals(errorCodeToResponseStatus.get(code.id()))) { + 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(); + } + } else { + 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 (!CommonMethods.isEmpty(constraintViolationSet)) { + // getting the first violation message for the output response. + ConstraintViolation constraintViolation = constraintViolationSet.iterator().next(); + message = constraintViolation.getMessage(); + fieldName = getFieldName(constraintViolation.getPropertyPath()); + + } else { + message = validationException.getMessage(); + } + + 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(); + } + + + 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(); + } + + private Response transform(Exception e0) { + ErrorCode generalErrorCode = new GeneralErrorBuilder(e0.getMessage()).build(); + logger.error(generalErrorCode.message(), e0); + return Response + .status(Response.Status.INTERNAL_SERVER_ERROR) + .entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, generalErrorCode)) + .build(); + } + + private String getFieldName(Path propertyPath) { + return ((PathImpl) propertyPath).getLeafNode().toString(); + } + + private Object toEntity(Response.Status status, ErrorCode code) { + return new ErrorCodeAndMessage(status, code); + } + +} 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 new file mode 100644 index 0000000000..7382ef72eb --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/mapping/MappingBase.java @@ -0,0 +1,104 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.mapping; + +/** + * 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. + *
  3. methods mapSimpleProperties and mapComplexProperties with default implementation, + * these should be overridden by concrete mapping classes for writing mapping logic.
  4. + *
+ */ + +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) { + //TODO: what what? + } else { + preMapping(source, target); + doMapping(source, target); + postMapping(source, target); + + } + return target; + + } + + /** + * This method is called before the doMapping method. + */ + + public void preMapping(final S source, T target) { + } + + /** + * 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) { + } + + /** + * Creates the instance of the input class. + * + * @return Object + */ + + private Object instantiateTarget(final Class clazz) { + Object object = null; + try { + object = clazz.newInstance(); + + } catch (InstantiationException | IllegalAccessException e0) { + //Do nothing + } + return object; + + } + +} + diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/versioning/types/VersioningAction.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/versioning/types/VersioningAction.java new file mode 100644 index 0000000000..8cb5a061b9 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/versioning/types/VersioningAction.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.versioning.types; + +public enum VersioningAction { + Checkout, + Undo_Checkout, + Checkin, + Submit; +} 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 new file mode 100644 index 0000000000..b8d47e4ef3 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/GenericCollectionWrapper.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.wrappers; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * This class represents a generic collection wrapper to be used by paginated results. + * + * @param the type parameter + */ +public class GenericCollectionWrapper implements Serializable { + private static final long serialVersionUID = 1L; + + private List results; + private int listCount; + + /** + * Instantiates a new Generic collection wrapper. + */ + public GenericCollectionWrapper() { + this.results = new ArrayList<>(); + } + + /** + * Instantiates a new Generic collection wrapper. + * + * @param list the list + * @param listCount the list count + */ + public GenericCollectionWrapper(List list, int listCount) { + if (!list.isEmpty()) { + this.results = list; + this.listCount = listCount; + } + } + + /** + * Gets results. + * + * @return the results + */ + public List getResults() { + return results; + } + + /** + * Sets results. + * + * @param results the results + */ + public void setResults(List results) { + this.results = results; + } + + /** + * Gets list count. + * + * @return the list count + */ + public int getListCount() { + return listCount; + } + + /** + * Sets list count. + * + * @param listCount the list count + */ + public void setListCount(int listCount) { + this.listCount = listCount; + } + + /** + * Add boolean. + * + * @param e0 the e 0 + * @return the boolean + */ + public boolean add(T e0) { + if (this.getResults().add(e0)) { + this.setListCount(this.getResults().size()); + return true; + } + 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 new file mode 100644 index 0000000000..d472eb9d14 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/wrappers/StringWrapperResponse.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdcrests.wrappers; + +public class StringWrapperResponse { + private String value; + + public StringWrapperResponse() { + } + + public StringWrapperResponse(String value) { + super(); + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/resources/errorCodesToResponseStatusMapping.json b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/resources/errorCodesToResponseStatusMapping.json new file mode 100644 index 0000000000..e4c6962847 --- /dev/null +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/resources/errorCodesToResponseStatusMapping.json @@ -0,0 +1,9 @@ +{ + "VSP_NOT_FOUND": "NOT_FOUND", + "VSP_INVALID": "BAD_REQUEST", + "UPLOAD_INVALID" : "PRECONDITION_FAILED", + "PACKAGE_NOT_FOUND": "NOT_FOUND", + "PACKAGE_INVALID": "BAD_REQUEST", + "VENDOR_LICENSE_MODEL_NOT_FOUND": "NOT_FOUND", + "VENDOR_LICENSE_ENTITY_NOT_FOUND": "NOT_FOUND" +} \ No newline at end of file -- cgit 1.2.3-korg