diff options
author | Michael Lando <ml636r@att.com> | 2017-02-19 12:35:04 +0200 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2017-02-19 12:35:04 +0200 |
commit | f5f13c4f6b6fe3b4d98e349dfd7db59339803436 (patch) | |
tree | 72caffc93fab394ffa3b761505775331f1c559b9 /openecomp-be/lib/openecomp-common-lib/src/main/java/org | |
parent | 451a3400b76511393c62a444f588a4ed15f4a549 (diff) |
push addional code
Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-common-lib/src/main/java/org')
9 files changed, 534 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/BaseErrorBuilder.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/BaseErrorBuilder.java new file mode 100644 index 0000000000..367cbf7df6 --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/BaseErrorBuilder.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.sdc.common.errors; + +public abstract class BaseErrorBuilder { + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + public ErrorCode build() { + return builder.build(); + } + + protected ErrorCode.ErrorCodeBuilder getErrorCodeBuilder() { + return builder; + } +} diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/CoreException.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/CoreException.java new file mode 100644 index 0000000000..3b464ca107 --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/CoreException.java @@ -0,0 +1,39 @@ +/*- + * ============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.sdc.common.errors; + +public class CoreException extends RuntimeException { + + private ErrorCode errorCode; + + public CoreException(ErrorCode errorCode) { + this(errorCode, null); + } + + public CoreException(ErrorCode errorCode, Throwable cause) { + super(errorCode.toString(), cause); + this.errorCode = errorCode; + } + + public ErrorCode code() { + return errorCode; + } +} diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCategory.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCategory.java new file mode 100644 index 0000000000..d24ee62124 --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCategory.java @@ -0,0 +1,64 @@ +/*- + * ============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.sdc.common.errors; + +public enum ErrorCategory { + /** + * System-level problems caused by external factors, resources shortage and similar. For instance: + * <ul> + * <li>I/O problems (network connectivity, filesystem access etc)</li> + * <li>Java issues (missing or incompatible class definitions etc)</li> + * <li>Environment problems</li> + * </ul> + */ + SYSTEM, + + /** + * Application-level issues related to implementation of certain functionality (such as detected + * illegal states of a program or data inconsistency). + */ + APPLICATION, + + /** + * Problems related to violations of different rules set either by product metadata (catalog + * definitions or similar) or other types of constraints. + */ + VALIDATION, + + /** + * Problems caused by attempt of a user to perform certain operations which contradict the + * system rules. Mostly applicable to UI-driven flows in presentation tier. + */ + USER, + + /** + * Improper values set in the system configuration (negative numbers, missing or inconsistent + * definitions, mismatch with valid values list etc). + * */ + CONFIGURATION, + + /** + * Security constraint violations (failed login attempts, lack of permissions to perform + * operation and so on). Any problems related to authentication/authorization should use the + * special category for system auditing purposes. + */ + SECURITY +} diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCode.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCode.java new file mode 100644 index 0000000000..aa0b123d4a --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCode.java @@ -0,0 +1,105 @@ +/*- + * ============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.sdc.common.errors; + +import java.io.Serializable; + +public class ErrorCode implements Serializable { + + private static final long serialVersionUID = 1L; + + private String id; + private String message; + private ErrorCategory category; + + protected ErrorCode() { + } + + public String id() { + return id; + } + + @Deprecated + protected void id(String id) { + this.id = id; + } + + public String message() { + return message; + } + + @Deprecated + protected void message(String message) { + this.message = message; + } + + public ErrorCategory category() { + return category; + } + + @Deprecated + protected void category(ErrorCategory category) { + this.category = category; + } + + @Override + public String toString() { + return message; + } + + public static class ErrorCodeBuilder { + + private String id; + private String message; + private ErrorCategory category = ErrorCategory.APPLICATION; + + public ErrorCodeBuilder withId(String id) { + this.id = id; + return this; + } + + //todo remove later + + public ErrorCodeBuilder withMessage(String message) { + this.message = message; + return this; + } + + //todo remove later + public ErrorCodeBuilder withCategory(ErrorCategory category) { + this.category = category; + return this; + } + + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + ErrorCode inst = new ErrorCode(); + inst.id = id; + inst.message = message; + inst.category = category; + return inst; + } + } +} diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCodeAndMessage.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCodeAndMessage.java new file mode 100644 index 0000000000..672397f53c --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ErrorCodeAndMessage.java @@ -0,0 +1,88 @@ +/*- + * ============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.sdc.common.errors; + + +import javax.ws.rs.core.Response; + +/** + * This class represents an error object to be returned in failed REST instead of just returning one + * of HTTP fail statuses. + * + */ +public class ErrorCodeAndMessage { + + /** + * the HTTP status code. + */ + private Response.Status status; + + /** + * Error code no. if available. + */ + private String errorCode; + + /** + * the error message to be displayed. + */ + private String message; + + public ErrorCodeAndMessage() { + } + + /** + * Instantiates a new Error code and message. + * + * @param status the status + * @param errorCode the error code + */ + public ErrorCodeAndMessage(Response.Status status, ErrorCode errorCode) { + this.status = status; + this.message = errorCode.message(); + this.errorCode = errorCode.id(); + } + + + public Response.Status getStatus() { + return status; + } + + public void setStatus(Response.Status status) { + this.status = status; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + +} diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/GeneralErrorBuilder.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/GeneralErrorBuilder.java new file mode 100644 index 0000000000..155d020396 --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/GeneralErrorBuilder.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.sdc.common.errors; + +/** + * The type General error builder. + */ +public class GeneralErrorBuilder { + + private static final String GENERAL_ERROR_REST_ID = "GENERAL_ERROR_REST_ID"; + private static final String GENERAL_ERROR_REST_MSG = "An error has occurred: %s"; + + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Instantiates a new General error builder. + * + * @param detailedError the detailed error + */ + public GeneralErrorBuilder(String detailedError) { + builder.withId(GENERAL_ERROR_REST_ID); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(GENERAL_ERROR_REST_MSG, detailedError)); + } + + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } + +} diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/JsonMappingErrorBuilder.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/JsonMappingErrorBuilder.java new file mode 100644 index 0000000000..2a916dbf90 --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/JsonMappingErrorBuilder.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.sdc.common.errors; + +/** + * The type Json mapping error builder. + */ +public class JsonMappingErrorBuilder { + + private static final String JSON_MAPPING_ERROR_ERR_ID = "JSON_MAPPING_ERROR_ERR_ID"; + private static final String JSON_MAPPING_ERROR_ERR_ERR_MSG = + "Error occurred while parsing the JSON input/body. Further info can be found in the log"; + + + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Instantiates a new Json mapping error builder. + */ + public JsonMappingErrorBuilder() { + builder.withId(JSON_MAPPING_ERROR_ERR_ID); + builder.withCategory(ErrorCategory.APPLICATION); + builder.withMessage(String.format(JSON_MAPPING_ERROR_ERR_ERR_MSG)); + } + + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } + +} diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ValidationErrorBuilder.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ValidationErrorBuilder.java new file mode 100644 index 0000000000..eb60a63a4b --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/ValidationErrorBuilder.java @@ -0,0 +1,68 @@ +/*- + * ============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.sdc.common.errors; + +/** + * The type Validation error builder. + */ +public class ValidationErrorBuilder { + + /** + * The constant FIELD_VALIDATION_ERROR_ERR_ID. + */ + public static final String FIELD_VALIDATION_ERROR_ERR_ID = "FIELD_VALIDATION_ERROR_ERR_ID"; + private static final String FIELD_VALIDATION_ERROR_ERR_MSG = + "Field does not conform to predefined criteria : %s : %s"; + private static final String FIELD_VALIDATION_ERROR_ERR_MSG_USE_PREDEFINED_FOR_FIELD = "%s"; + private static final String FIELD_WITH_PREDEFINED_MESSAGE = "arg\\d"; + + + private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); + + /** + * Instantiates a new Validation error builder. + * + * @param detailedMessage the detailed message + * @param fieldName the field name + */ + public ValidationErrorBuilder(String detailedMessage, String fieldName) { + builder.withId(FIELD_VALIDATION_ERROR_ERR_ID); + builder.withCategory(ErrorCategory.APPLICATION); + + if (fieldName.matches(FIELD_WITH_PREDEFINED_MESSAGE)) { + builder.withMessage( + String.format(FIELD_VALIDATION_ERROR_ERR_MSG_USE_PREDEFINED_FOR_FIELD, detailedMessage)); + } else { + builder + .withMessage(String.format(FIELD_VALIDATION_ERROR_ERR_MSG, fieldName, detailedMessage)); + } + } + + /** + * Build error code. + * + * @return the error code + */ + public ErrorCode build() { + return builder.build(); + } + +} diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/AsdcCommon.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/AsdcCommon.java new file mode 100644 index 0000000000..d3806ff34e --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/AsdcCommon.java @@ -0,0 +1,31 @@ +/*- + * ============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.sdc.common.utils; + +public class AsdcCommon { + + public static final String MANIFEST_NAME = "MANIFEST.json"; + public static final String UPLOAD_FILE = "uploadFile"; + + public static final String HEAT_TO_TOSCA_MAPPING_CONF = "heatToToscaMapping.json"; + public static final String HEAT_META = "HEAT.meta"; + public static final String PARENT = "parent"; +} |