diff options
47 files changed, 1151 insertions, 482 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java index c63749e0d6..bff30683ca 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710.java @@ -12,6 +12,7 @@ import org.openecomp.sdc.asdctool.migration.tasks.handlers.XlsOutputHandler; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; @@ -732,7 +733,7 @@ public class UpgradeMigration1710 implements PostMigration { resourceToUpdate.setCategories(((Resource)checkouRes.left().value()).getCategories()); try { Resource updateResourceFromCsarRes = resourceBusinessLogic.validateAndUpdateResourceFromCsar(resourceToUpdate, user, null, null, resourceToUpdate.getUniqueId()); - } catch(ComponentException e){ + } catch(ByResponseFormatComponentException e){ outputHandler.addRecord(resourceToUpdate.getComponentType().name(), resourceToUpdate.getName(), resourceToUpdate.getUUID(), resourceToUpdate.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), e.getResponseFormat().getFormattedMessage()); log.info("Failed to update vf with name {}, invariantUUID {}, version {} and latest VSP {}. ", vf.getName(), vf.getInvariantUUID(), vf.getVersion(), latestVersion); return false; diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710Test.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710Test.java index df5761d893..8d46e61011 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710Test.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/migration/tasks/mig1710/UpgradeMigration1710Test.java @@ -1,6 +1,26 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.asdctool.migration.tasks.mig1710; - import com.google.common.collect.Lists; import fj.data.Either; import org.junit.AfterClass; @@ -15,7 +35,7 @@ import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult; import org.openecomp.sdc.asdctool.migration.tasks.handlers.XlsOutputHandler; import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic; import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic; import org.openecomp.sdc.be.config.Configuration; @@ -291,7 +311,7 @@ public class UpgradeMigration1710Test { mockCheckoutFlow(); when(resourceBusinessLogic.validateAndUpdateResourceFromCsar(any(Resource.class), any(), any(), any(), any())) - .thenThrow(new ComponentException(responseFormat)); + .thenThrow(new ByResponseFormatComponentException(responseFormat)); when(resourceBusinessLogic.deleteResource(anyString(), any())) .thenReturn(responseFormat); mockChangeComponentState(); @@ -304,7 +324,7 @@ public class UpgradeMigration1710Test { mockCheckoutFlow(); when(resourceBusinessLogic.validateAndUpdateResourceFromCsar(any(Resource.class), any(), any(), any(), any())) - .thenThrow(new ComponentException(responseFormat)); + .thenThrow(new ByResponseFormatComponentException(responseFormat)); when(resourceBusinessLogic.deleteResource(anyString(), any())) .thenReturn(responseFormat); mockChangeComponentState(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java index fb7843430f..addd9d2407 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarBusinessLogic.java @@ -1,10 +1,32 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.csar; import fj.data.Either; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.BaseBusinessLogic; import org.openecomp.sdc.be.components.impl.CsarValidationUtils; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.model.NodeTypeInfo; @@ -51,7 +73,7 @@ public class CsarBusinessLogic extends BaseBusinessLogic { } else if (status != StorageOperationStatus.OK) { log.debug("Failed to validate uniqueness of CsarUUID {} for resource", csarUUID, resource.getSystemName()); - throw new ComponentException(componentsUtils.convertFromStorageResponse(status)); + throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status)); } } @@ -86,11 +108,11 @@ public class CsarBusinessLogic extends BaseBusinessLogic { private String logAndThrowComponentException(ResponseFormat responseFormat, String logMessage, String ...params) { log.debug(logMessage, params, responseFormat); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } private ImmutablePair<String,String> throwComponentException(ResponseFormat responseFormat) { - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } private Either<ImmutablePair<String, String>, ResponseFormat> validateAndParseCsar(Resource resource, User user, @@ -142,6 +164,6 @@ public class CsarBusinessLogic extends BaseBusinessLogic { private void auditAndThrowException(Resource resource, User user, AuditingActionEnum auditingAction, ActionStatus status, String... params){ ResponseFormat errorResponse = componentsUtils.getResponseFormat(status, params); componentsUtils.auditResource(errorResponse, user, resource, auditingAction); - throw new ComponentException(errorResponse); + throw new ByResponseFormatComponentException(errorResponse); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java index 53adc3c970..72efb1176f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java @@ -1,8 +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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.csar; import fj.data.Either; import org.apache.commons.collections.CollectionUtils; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.model.NodeTypeInfo; import org.openecomp.sdc.be.model.Resource; @@ -94,7 +115,7 @@ public class CsarInfo { } else { log.debug("Failed to validate complex VFC {}. Loop detected, VSP {}. ", nodeName, getVfResourceName()); - throw new ComponentException(ActionStatus.CFVC_LOOP_DETECTED, + throw new ByActionStatusComponentException(ActionStatus.CFVC_LOOP_DETECTED, getVfResourceName(), nodeName); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index e9b5baa49e..04df614b9d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -1,3 +1,24 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.csar; import com.google.common.collect.Lists; @@ -11,7 +32,7 @@ import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic; import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic; import org.openecomp.sdc.be.components.impl.ImportUtils; import org.openecomp.sdc.be.components.impl.NodeFilterUploadCreator; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; @@ -845,17 +866,17 @@ public class YamlTemplateParsingHandler { private Map<String, Object> failIfNoNodeTemplates(String fileName) { titanDao.rollback(); - throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName); + throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName); } private Object failIfNotTopologyTemplate(String fileName) { titanDao.rollback(); - throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName); + throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName); } private void rollbackWithException(ActionStatus actionStatus, String... params) { titanDao.rollback(); - throw new ComponentException(actionStatus, params); + throw new ByActionStatusComponentException(actionStatus, params); } private void failOnMissingCapabilityTypes(GroupDefinition groupDefinition, List<String> missingCapTypes) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArchiveBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArchiveBusinessLogic.java index 70898fbec2..3cf520d30e 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArchiveBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArchiveBusinessLogic.java @@ -1,8 +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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import com.google.common.annotations.VisibleForTesting; import fj.data.Either; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.validation.AccessValidations; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; @@ -47,7 +68,7 @@ public class ArchiveBusinessLogic { Either<List<String>, ActionStatus> result = this.archiveOperation.archiveComponent(componentId); if (result.isRight()){ - throw new ComponentException(result.right().value(), componentId); + throw new ByActionStatusComponentException(result.right().value(), componentId); } this.auditAction(ArchiveOperation.Action.ARCHIVE, result.left().value(), user, containerComponentType); } @@ -56,7 +77,7 @@ public class ArchiveBusinessLogic { User user = accessValidations.userIsAdminOrDesigner(userId, containerComponentType + "_RESTORE"); Either<List<String>, ActionStatus> result = this.archiveOperation.restoreComponent(componentId); if (result.isRight()){ - throw new ComponentException(result.right().value(), componentId); + throw new ByActionStatusComponentException(result.right().value(), componentId); } this.auditAction(ArchiveOperation.Action.RESTORE, result.left().value(), user, containerComponentType); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java index aef13eea4c..f23057cad0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -34,7 +36,8 @@ import org.openecomp.sdc.be.components.ArtifactsResolver; import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum; import org.openecomp.sdc.be.components.impl.artifact.ArtifactTypeToPayloadTypeSelector; import org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum; @@ -3637,17 +3640,25 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic { User user; try{ user = validateUserExists(userId, auditingAction.getName(), inTransaction); - } catch(ComponentException e){ - user = new User(); - user.setUserId(userId); - ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() : - componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); - handleAuditing(auditingAction, null, componentId, user, null, null, artifactId, responseFormat, componentType, null); + } catch(ByResponseFormatComponentException e){ + ResponseFormat responseFormat = e.getResponseFormat(); + handleComponentException(auditingAction, componentId, artifactId, responseFormat, componentType, userId); + throw e; + } catch(ByActionStatusComponentException e){ + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + handleComponentException(auditingAction, componentId, artifactId, responseFormat, componentType, userId); throw e; } return Either.left(user); } + private void handleComponentException(AuditingActionEnum auditingAction, String componentId, String artifactId, + ResponseFormat responseFormat, ComponentTypeEnum componentType, String userId){ + User user = new User(); + user.setUserId(userId); + handleAuditing(auditingAction, null, componentId, user, null, null, artifactId, responseFormat, componentType, null); + } + protected AuditingActionEnum detectAuditingType(ArtifactOperationInfo operation, String origMd5) { AuditingActionEnum auditingAction = null; switch (operation.getArtifactOperationEnum()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java index 643b9462bc..c77223ba59 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -31,7 +33,7 @@ import java.util.List; import java.util.Map; import java.util.function.Function; import org.apache.commons.lang3.tuple.ImmutablePair; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity; @@ -253,7 +255,7 @@ public abstract class BaseBusinessLogic { private Boolean logAndThrowException(ActionStatus status, String componentId, String name){ log.debug(FAILED_TO_LOCK_COMPONENT_ERROR, componentId, status); - throw new ComponentException(status, name); + throw new ByActionStatusComponentException(status, name); } private ResponseFormat logAndConvertError(ActionStatus status, String componentId, String name){ @@ -372,12 +374,12 @@ public abstract class BaseBusinessLogic { if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) { if (property.getSchema() == null) { log.debug(SCHEMA_DOESN_T_EXISTS_FOR_PROPERTY_OF_TYPE, type); - throw new ComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)); + throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)); } PropertyDataDefinition innerProperty = property.getSchema().getProperty(); if (innerProperty == null) { log.debug(PROPERTY_IN_SCHEMA_DEFINITION_INSIDE_PROPERTY_OF_TYPE_DOESN_T_EXIST, type); - throw new ComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)); + throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE)); } innerType = innerProperty.getType(); } @@ -621,7 +623,7 @@ public abstract class BaseBusinessLogic { } private void failOnIllegalArgument() { - throw new ComponentException( + throw new ByActionStatusComponentException( componentsUtils.convertFromStorageResponse( DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.ILLEGAL_ARGUMENT))); } @@ -711,7 +713,7 @@ public abstract class BaseBusinessLogic { protected void rollbackWithException(ActionStatus actionStatus, String... params) { titanDao.rollback(); - throw new ComponentException(actionStatus, params); + throw new ByActionStatusComponentException(actionStatus, params); } public <T extends ToscaDataDefinition> Either<List<T>, ResponseFormat> declareProperties(String userId, String componentId, diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java index 773dc639a9..d2f845cc00 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -23,7 +25,7 @@ package org.openecomp.sdc.be.components.impl; import fj.data.Either; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -399,7 +401,7 @@ public class CommonImportManager { TypeOperations<T> typeOperations) { Map<String, Object> fieldMap = convertToFieldMap(toscaTypesYml); if (fieldMap==null) { - throw new ComponentException(ActionStatus.INVALID_YAML_FILE); + throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML_FILE); } List<T> elementTypes = createTypesFromToscaJsonMap(createApi, fieldMap); return createTypesByDao(elementTypes, typeOperations); @@ -416,7 +418,7 @@ public class CommonImportManager { ToscaTypeMetadata typeMetaData = toscaTypeMetadata.get(toscaType); if (typeMetaData == null) { log.debug("failing while trying to associate metadata for type {}. type not exist", toscaType); - throw new ComponentException(ActionStatus.GENERAL_ERROR); + throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); } toscaTypeDefinition.setIcon(typeMetaData.getIcon()); toscaTypeDefinition.setName(typeMetaData.getDisplayName()); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java index acf28c2455..dcd0c7b7f0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogic.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -31,7 +33,8 @@ import fj.data.Either; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.config.ConfigurationManager; @@ -119,15 +122,18 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { protected User validateUser(User user, String ecompErrorContext, Component component, AuditingActionEnum auditAction, boolean inTransaction) { User validatedUser; ResponseFormat responseFormat; - try{ + try { validateUserNotEmpty(user, ecompErrorContext); validatedUser = validateUserExists(user, ecompErrorContext, inTransaction); - } catch(ComponentException e){ - if(e.getActionStatus()== ActionStatus.MISSING_INFORMATION){ + } catch(ByActionStatusComponentException e){ + if(e.getActionStatus() == ActionStatus.MISSING_INFORMATION){ user.setUserId("UNKNOWN"); } - responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() - : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + componentsUtils.auditComponentAdmin(responseFormat, user, component, auditAction, component.getComponentType()); + throw e; + } catch(ByResponseFormatComponentException e){ + responseFormat = e.getResponseFormat(); componentsUtils.auditComponentAdmin(responseFormat, user, component, auditAction, component.getComponentType()); throw e; } @@ -139,26 +145,34 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { roles.add(Role.ADMIN); roles.add(Role.DESIGNER); } - try{ + try { validateUserRole(user, roles); - } catch(ComponentException e){ - String commentStr = null; - String distrStatus = null; - ComponentTypeEnum componentType = component.getComponentType(); - if (componentType.equals(ComponentTypeEnum.SERVICE)) { - distrStatus = ((ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getDistributionStatus(); - commentStr = comment; - } - ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() - : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); - componentsUtils.auditComponent(responseFormat, user, component, auditAction, new ResourceCommonInfo(componentType.getValue()), - ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(), - ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(), - commentStr, null, null); + }catch (ByActionStatusComponentException e) { + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + handleComponentException(component, comment, responseFormat, user, auditAction); + throw e; + }catch (ByResponseFormatComponentException e) { + ResponseFormat responseFormat = e.getResponseFormat(); + handleComponentException(component, comment, responseFormat, user, auditAction); throw e; } } + private void handleComponentException(Component component, String comment, ResponseFormat responseFormat, + User user, AuditingActionEnum auditAction){ + String commentStr = null; + String distrStatus = null; + ComponentTypeEnum componentType = component.getComponentType(); + if (componentType.equals(ComponentTypeEnum.SERVICE)) { + distrStatus = ((ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getDistributionStatus(); + commentStr = comment; + } + componentsUtils.auditComponent(responseFormat, user, component, auditAction, new ResourceCommonInfo(componentType.getValue()), + ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(), + ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(), + commentStr, null, null); + } + protected void validateComponentName(User user, Component component, AuditingActionEnum actionEnum) { ComponentTypeEnum type = component.getComponentType(); String componentName = component.getName(); @@ -166,21 +180,21 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { log.debug("component name is empty"); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_COMPONENT_NAME, type.getValue()); componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type); - throw new ComponentException(ActionStatus.MISSING_COMPONENT_NAME, type.getValue()); + throw new ByActionStatusComponentException(ActionStatus.MISSING_COMPONENT_NAME, type.getValue()); } if (!ValidationUtils.validateComponentNameLength(componentName)) { log.debug("Component name exceeds max length {} ", ValidationUtils.COMPONENT_NAME_MAX_LENGTH); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH); componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type); - throw new ComponentException(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT,type.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT,type.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH); } if (!validateTagPattern(componentName)) { log.debug("Component name {} has invalid format", componentName); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPONENT_NAME, type.getValue()); componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type); - throw new ComponentException(ActionStatus.INVALID_COMPONENT_NAME, type.getValue()); + throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPONENT_NAME, type.getValue()); } component.setNormalizedName(ValidationUtils.normaliseComponentName(componentName)); component.setSystemName(ValidationUtils.convertToSystemName(componentName)); @@ -192,15 +206,18 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { if (!ValidationUtils.validateStringNotEmpty(description)) { ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_DESCRIPTION, type.getValue()); componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type); - throw new ComponentException(ActionStatus.COMPONENT_MISSING_DESCRIPTION, type.getValue()); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_DESCRIPTION, type.getValue()); } description = cleanUpText(description); - try{ + try { validateComponentDescription(description, type); - } catch(ComponentException e){ - ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() - : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + } catch(ByActionStatusComponentException e){ + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type); + throw e; + } catch(ByResponseFormatComponentException e){ + ResponseFormat responseFormat = e.getResponseFormat(); componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type); throw e; } @@ -210,11 +227,11 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { private void validateComponentDescription(String description, ComponentTypeEnum type) { if (description != null) { if (!ValidationUtils.validateDescriptionLength(description)) { - throw new ComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH); } if (!ValidationUtils.validateIsEnglish(description)) { - throw new ComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION, type.getValue()); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION, type.getValue()); } } } @@ -254,7 +271,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { log.info("contact is missing."); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue()); componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type); - throw new ComponentException(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue()); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue()); } validateContactId(contactId, user, component, actionEnum, type); } @@ -264,7 +281,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { log.info("contact is invalid."); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue()); componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type); - throw new ComponentException(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue()); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue()); } } @@ -317,13 +334,16 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { log.info("icon is missing."); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_ICON, type.getValue()); componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type); - throw new ComponentException(ActionStatus.COMPONENT_MISSING_ICON, type.getValue()); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_ICON, type.getValue()); } try { validateIcon(icon, type); - } catch(ComponentException e){ - ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() - : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + } catch(ByActionStatusComponentException e){ + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type); + throw e; + } catch(ByResponseFormatComponentException e){ + ResponseFormat responseFormat = e.getResponseFormat(); componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type); throw e; } @@ -333,12 +353,12 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { if (icon != null) { if (!ValidationUtils.validateIconLength(icon)) { log.debug("icon exceeds max length"); - throw new ComponentException(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH); } if (!ValidationUtils.validateIcon(icon)) { log.info("icon is invalid."); - throw new ComponentException(ActionStatus.COMPONENT_INVALID_ICON, type.getValue()); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_ICON, type.getValue()); } } } @@ -347,9 +367,12 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { List<String> tagsList = component.getTags(); try { validateComponentTags(tagsList, component.getName(), component.getComponentType(), user, component, actionEnum); - } catch(ComponentException e){ - ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() - : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + } catch(ByActionStatusComponentException e){ + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType()); + throw e; + } catch(ByResponseFormatComponentException e){ + ResponseFormat responseFormat = e.getResponseFormat(); componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType()); throw e; } @@ -367,7 +390,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { log.debug("tag length exceeds limit {}", ValidationUtils.TAG_MAX_LENGTH); responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH); componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType); - throw new ComponentException(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH); } if (validateTagPattern(tag)) { if (!includesComponentName) { @@ -377,7 +400,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { log.debug("invalid tag {}", tag); responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL); componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType); - throw new ComponentException(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL); + throw new ByActionStatusComponentException(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL); } tagListSize += tag.length() + 1; } @@ -389,18 +412,18 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { log.debug("tags must include component name"); responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME); componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType); - throw new ComponentException(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME); } if (!ValidationUtils.validateTagListLength(tagListSize)) { log.debug("overall tags length exceeds limit {}", ValidationUtils.TAG_LIST_MAX_LENGTH); responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH); componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType); - throw new ComponentException(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH); } } else { responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_TAGS); componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType); - throw new ComponentException(ActionStatus.COMPONENT_MISSING_TAGS); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_TAGS); } } @@ -831,7 +854,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { Either<Resource, ResponseFormat> genericTypeEither = this.genericTypeBusinessLogic.fetchDerivedFromGenericType(component); if(genericTypeEither.isRight()){ log.debug("Failed to fetch latest generic type for component {} of type", component.getName(), component.assetType()); - throw new ComponentException(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType()); + throw new ByActionStatusComponentException(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType()); } Resource genericTypeResource = genericTypeEither.left().value(); component.setDerivedFromGenericInfo(genericTypeResource); @@ -1095,7 +1118,7 @@ public abstract class ComponentBusinessLogic extends BaseBusinessLogic { } public List<GroupDefinition> throwComponentException(ResponseFormat responseFormat) { - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java index 3025084239..8255de63d6 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentBusinessLogicProvider.java @@ -1,6 +1,27 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -30,7 +51,7 @@ public class ComponentBusinessLogicProvider { return resourceBusinessLogic; default: BeEcompErrorManager.getInstance().logBeSystemError("getComponentBL"); - throw new ComponentException(ActionStatus.INVALID_CONTENT_PARAM, componentTypeEnum.getValue()); + throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT_PARAM, componentTypeEnum.getValue()); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java index 7f17d44f57..4e7f86aed6 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CompositionBusinessLogic.java @@ -16,12 +16,14 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; import org.apache.commons.lang3.tuple.ImmutablePair; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; import org.openecomp.sdc.be.model.ComponentInstance; @@ -75,7 +77,7 @@ public class CompositionBusinessLogic { } private List<ComponentInstance> throwComponentException(ResponseFormat responseFormat) { - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } private void setRelativePosition(Entry<ImmutablePair<Double, Double>, ComponentInstance> entry) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java index 8e9f65fce1..746f4e9c27 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogic.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -24,6 +26,8 @@ import fj.data.Either; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEncodedUtils; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; @@ -393,13 +397,15 @@ public class ElementBusinessLogic extends BaseBusinessLogic { User user; try{ user = validateUserExists(userId, "createSubCategory", false); - } catch(ComponentException e){ - log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId); - ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() : - componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); - user = new User(); - user.setUserId(userId); - handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType); + } catch(ByActionStatusComponentException e){ + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + handleComponentException(userId, auditingAction, componentType, parentCategoryName, origSubCategoryName, + responseFormat); + throw e; + } catch(ByResponseFormatComponentException e){ + ResponseFormat responseFormat = e.getResponseFormat(); + handleComponentException(userId, auditingAction, componentType, parentCategoryName, origSubCategoryName, + responseFormat); throw e; } if (componentTypeEnum == null) { @@ -512,6 +518,35 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return Either.left(subCategoryCreated); } + private void handleComponentException(String userId, AuditingActionEnum auditingAction, String componentType, + String parentCategoryName, String origSubCategoryName, ResponseFormat responseFormat) { + User user; + log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId); + user = new User(); + user.setUserId(userId); + handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, + componentType); + } + + private void handleComponentException(GroupingDefinition grouping, String userId, AuditingActionEnum auditingAction, + String componentType, String parentCategoryName, String parentSubCategoryName, ResponseFormat responseFormat) { + User user; + log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId); + user = new User(); + user.setUserId(userId); + String groupingNameForAudit = grouping == null ? null : grouping.getName(); + handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, groupingNameForAudit, + auditingAction, componentType); + } + + private void handleComponentException(String componentType, String userId, ResponseFormat responseFormat) { + User user; + user = new User(); + user.setUserId(userId); + log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId); + componentsUtils.auditGetCategoryHierarchy(user, componentType, responseFormat); + } + public Either<GroupingDefinition, ResponseFormat> createGrouping(GroupingDefinition grouping, String componentTypeParamName, String grandParentCategoryId, String parentSubCategoryId, String userId) { AuditingActionEnum auditingAction = AuditingActionEnum.ADD_GROUPING; @@ -525,14 +560,16 @@ public class ElementBusinessLogic extends BaseBusinessLogic { User user; try{ user = validateUserExists(userId, "create Grouping", false); - } catch(ComponentException e){ - log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId); - ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() : - componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); - user = new User(); - user.setUserId(userId); - String groupingNameForAudit = grouping == null ? null : grouping.getName(); - handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, groupingNameForAudit, auditingAction, componentType); + } catch(ByResponseFormatComponentException e){ + ResponseFormat responseFormat = e.getResponseFormat(); + handleComponentException(grouping, userId, auditingAction, componentType, parentCategoryName, + parentSubCategoryName, + responseFormat); + throw e; + } catch(ByActionStatusComponentException e){ + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + handleComponentException(grouping, userId, auditingAction, componentType, parentCategoryName, + parentSubCategoryName, responseFormat); throw e; } @@ -672,6 +709,8 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return Either.left(groupingCreated); } + + public Either<List<CategoryDefinition>, ResponseFormat> getAllCategories(String componentType, String userId) { ResponseFormat responseFormat; User user = new User(); @@ -683,13 +722,13 @@ public class ElementBusinessLogic extends BaseBusinessLogic { } try { user = validateUserExists(userId, "get All Categories", false); - } catch (ComponentException e){ - user = new User(); - user.setUserId(userId); - log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId); - responseFormat = e.getResponseFormat() != null ? e.getResponseFormat(): - componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); - componentsUtils.auditGetCategoryHierarchy(user, componentType, responseFormat); + } catch (ByActionStatusComponentException e){ + responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + handleComponentException(componentType, userId, responseFormat); + throw e; + } catch (ByResponseFormatComponentException e){ + responseFormat = e.getResponseFormat(); + handleComponentException(componentType, userId, responseFormat); throw e; } ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType); @@ -713,6 +752,8 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return Either.left(categories); } + + public Either<UiCategories, ResponseFormat> getAllCategories(String userId) { ResponseFormat responseFormat; UiCategories categories = new UiCategories(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java index c8266efd42..9bab155cdf 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -27,6 +29,8 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.lock.LockingTransactional; import org.openecomp.sdc.be.components.impl.policy.PolicyTargetsUpdateHandler; @@ -1028,7 +1032,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic { private void validateGroupTypePerComponent(String groupType, Component component) { String specificType = component.getComponentMetadataDefinition().getMetadataDataDefinition().getActualComponentType(); if (!component.isTopologyTemplate()) { - throw new ComponentException(ActionStatus.GROUP_TYPE_ILLEGAL_PER_COMPONENT, groupType, + throw new ByActionStatusComponentException(ActionStatus.GROUP_TYPE_ILLEGAL_PER_COMPONENT, groupType, specificType); } Map<String, Set<String>> excludedGroupTypesMap = ConfigurationManager.getConfigurationManager().getConfiguration() @@ -1037,7 +1041,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic { if (MapUtils.isNotEmpty(excludedGroupTypesMap) && StringUtils.isNotEmpty(specificType)) { Set<String> excludedGroupTypesPerComponent = excludedGroupTypesMap.get(specificType); if (excludedGroupTypesPerComponent!=null && excludedGroupTypesPerComponent.contains(groupType)) { - throw new ComponentException(ActionStatus.GROUP_TYPE_ILLEGAL_PER_COMPONENT, groupType, specificType); + throw new ByActionStatusComponentException(ActionStatus.GROUP_TYPE_ILLEGAL_PER_COMPONENT, groupType, specificType); } } } @@ -1077,13 +1081,13 @@ public class GroupBusinessLogic extends BaseBusinessLogic { private void assertNewNameIsValidAndUnique(String currentGroupName, String updatedGroupName, Component component) { if (!ValidationUtils.validateResourceInstanceNameLength(updatedGroupName)) { - throw new ComponentException(ActionStatus.EXCEEDS_LIMIT, "Group Name", ValidationUtils.RSI_NAME_MAX_LENGTH.toString()); + throw new ByActionStatusComponentException(ActionStatus.EXCEEDS_LIMIT, "Group Name", ValidationUtils.RSI_NAME_MAX_LENGTH.toString()); } if (!ValidationUtils.validateResourceInstanceName(updatedGroupName)) { - throw new ComponentException(ActionStatus.INVALID_VF_MODULE_NAME, updatedGroupName); + throw new ByActionStatusComponentException(ActionStatus.INVALID_VF_MODULE_NAME, updatedGroupName); } if (!ComponentValidations.validateNameIsUniqueInComponent(currentGroupName, updatedGroupName, component)) { - throw new ComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, "Group", updatedGroupName); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, "Group", updatedGroupName); } } @@ -1106,21 +1110,21 @@ public class GroupBusinessLogic extends BaseBusinessLogic { private List<GroupDefinition> onFailedGroupDBOperation(ResponseFormat responseFormat) { titanDao.rollback(); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } private GroupDefinition onFailedUpdateGroupDBOperation(ResponseFormat responseFormat) { titanDao.rollback(); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } private GroupDefinition onGroupNotFoundInComponentError(Component component, String groupId) { - throw new ComponentException(ActionStatus.GROUP_IS_MISSING, groupId, + throw new ByActionStatusComponentException(ActionStatus.GROUP_IS_MISSING, groupId, component.getSystemName(), getComponentTypeForResponse(component)); } private GroupTypeDefinition onGroupTypeNotFound(Component component) { - throw new ComponentException(ActionStatus.GROUP_TYPE_IS_INVALID, component.getSystemName(), + throw new ByActionStatusComponentException(ActionStatus.GROUP_TYPE_IS_INVALID, component.getSystemName(), component.getComponentType().toString()); } @@ -1129,7 +1133,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic { ActionStatus actionStatus = policyTargetsUpdateHandler.removePoliciesTargets(component, groupId, PolicyTargetType.GROUPS); if (ActionStatus.OK != actionStatus) { titanDao.rollback(); - throw new ComponentException(actionStatus, groupId); + throw new ByActionStatusComponentException(actionStatus, groupId); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java index 855e55c415..b234bb6bd6 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicNew.java @@ -1,10 +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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang3.math.NumberUtils; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.lock.LockingTransactional; import org.openecomp.sdc.be.components.validation.AccessValidations; import org.openecomp.sdc.be.components.validation.ComponentValidations; @@ -81,24 +102,24 @@ public class GroupBusinessLogicNew { private ComponentInstance getComponentInstance(Component component, String memberUniqueId) { return componentValidations.getComponentInstance(component, memberUniqueId) - .orElseThrow(() -> new ComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, + .orElseThrow(() -> new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER, memberUniqueId, "", component.getActualComponentType(), component.getSystemName())); } private GroupDefinition getGroup(Component component, String groupUniqueId) { return component.getGroupById(groupUniqueId) - .orElseThrow(() -> new ComponentException(ActionStatus.GROUP_IS_MISSING, + .orElseThrow(() -> new ByActionStatusComponentException(ActionStatus.GROUP_IS_MISSING, component.getSystemName(), component.getActualComponentType())); } private void validateUpdatedPropertiesAndSetEmptyValues(GroupDefinition originalGroup, List<GroupProperty> groupPropertiesToUpdate) { if (CollectionUtils.isEmpty(groupPropertiesToUpdate)) { - throw new ComponentException(ActionStatus.PROPERTY_NOT_FOUND, StringUtils.EMPTY); + throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, StringUtils.EMPTY); } if (CollectionUtils.isEmpty(originalGroup.getProperties())) { - throw new ComponentException(ActionStatus.PROPERTY_NOT_FOUND, groupPropertiesToUpdate.get(NumberUtils.INTEGER_ZERO).getName()); + throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, groupPropertiesToUpdate.get(NumberUtils.INTEGER_ZERO).getName()); } Map<String, GroupProperty> originalProperties = originalGroup.convertToGroupProperties() .stream() @@ -108,10 +129,10 @@ public class GroupBusinessLogicNew { for (GroupProperty gp : groupPropertiesToUpdate) { String updatedPropertyName = gp.getName(); if (!originalProperties.containsKey(updatedPropertyName)) { - throw new ComponentException(ActionStatus.PROPERTY_NOT_FOUND, updatedPropertyName); + throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, updatedPropertyName); } if (!isOnlyGroupPropertyValueChanged(gp, originalProperties.get(updatedPropertyName))) { - throw new ComponentException(ActionStatus.INVALID_PROPERTY, updatedPropertyName); + throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY, updatedPropertyName); } if (StringUtils.isEmpty(gp.getValue())) { gp.setValue(originalProperties.get(updatedPropertyName).getDefaultValue()); @@ -175,15 +196,15 @@ public class GroupBusinessLogicNew { if (isPropertyChanged(newValues, parentValues, PropertyDefinition.PropertyNames.INITIAL_COUNT) && (latestInitialCount > latestMaxInstances || latestInitialCount < latestMinInstances)) { - throw new ComponentException(ActionStatus.INVALID_GROUP_INITIAL_COUNT_PROPERTY_VALUE, PropertyDefinition.PropertyNames.INITIAL_COUNT.getPropertyName(), String.valueOf(latestMinInstances), String.valueOf(latestMaxInstances)); + throw new ByActionStatusComponentException(ActionStatus.INVALID_GROUP_INITIAL_COUNT_PROPERTY_VALUE, PropertyDefinition.PropertyNames.INITIAL_COUNT.getPropertyName(), String.valueOf(latestMinInstances), String.valueOf(latestMaxInstances)); } if (isPropertyChanged(newValues, parentValues, PropertyDefinition.PropertyNames.MAX_INSTANCES) && latestMaxInstances < latestInitialCount) { - throw new ComponentException(ActionStatus.INVALID_GROUP_PROPERTY_VALUE_LOWER_HIGHER, PropertyDefinition.PropertyNames.MAX_INSTANCES.getPropertyName(), "higher", String.valueOf(latestInitialCount)); + throw new ByActionStatusComponentException(ActionStatus.INVALID_GROUP_PROPERTY_VALUE_LOWER_HIGHER, PropertyDefinition.PropertyNames.MAX_INSTANCES.getPropertyName(), "higher", String.valueOf(latestInitialCount)); } if (isPropertyChanged(newValues, parentValues, PropertyDefinition.PropertyNames.MIN_INSTANCES) && latestMinInstances > latestInitialCount) { - throw new ComponentException(ActionStatus.INVALID_GROUP_PROPERTY_VALUE_LOWER_HIGHER, PropertyDefinition.PropertyNames.MIN_INSTANCES.getPropertyName(), "lower", String.valueOf(latestInitialCount)); + throw new ByActionStatusComponentException(ActionStatus.INVALID_GROUP_PROPERTY_VALUE_LOWER_HIGHER, PropertyDefinition.PropertyNames.MIN_INSTANCES.getPropertyName(), "lower", String.valueOf(latestInitialCount)); } } @@ -218,11 +239,11 @@ public class GroupBusinessLogicNew { final String groupTypeValue = groupPropertyToUpdate.getValue(); if (!org.apache.commons.lang3.StringUtils.isEmpty(groupTypeValue)) { if (!ValidationUtils.validateDescriptionLength(groupTypeValue)) { - throw new ComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, NodeTypeEnum.Property.getName(), String.valueOf(ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH)); } else if (!ValidationUtils.validateIsEnglish(groupTypeValue)) { - throw new ComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION, + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION, NodeTypeEnum.Property.getName()); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java index 99c4e9e181..5bc0e5e3c3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java @@ -1,7 +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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import org.apache.commons.lang3.StringUtils; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -62,9 +83,9 @@ public class GroupTypeBusinessLogic { private GroupTypeDefinition failOnGetGroupType(StorageOperationStatus status, String groupType) { titanDao.rollback(); if (status == StorageOperationStatus.NOT_FOUND) { - throw new ComponentException(ActionStatus.GROUP_TYPE_IS_INVALID, groupType); + throw new ByActionStatusComponentException(ActionStatus.GROUP_TYPE_IS_INVALID, groupType); } else { - throw new ComponentException(ActionStatus.GENERAL_ERROR); + throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); } } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java index a98694626f..0936472bb7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -36,6 +38,7 @@ import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ReflectionToStringBuilder; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator; import org.openecomp.sdc.be.components.validation.ComponentValidations; @@ -430,7 +433,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return result; - } catch (ComponentException e) { + } catch (ByResponseFormatComponentException e) { log.error("#createMultipleInputs: Exception thrown: ", e); result = Either.right(e.getResponseFormat()); return result; @@ -491,7 +494,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { toscaOperationFacade.addDataTypesToComponent(dataTypesMap, componentId); if (dataTypeResult.isRight()) { log.debug("#createListInput: DataType creation failed."); - throw new ComponentException(componentsUtils.getResponseFormat(dataTypeResult.right().value())); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(dataTypeResult.right().value())); } // create list input @@ -504,7 +507,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { result = createListInputsInGraph(listInputMap, dataTypesMap, component); if (result.isRight()) { log.debug("#createListInput: createListInputsInGraph failed."); - throw new ComponentException(result.right().value()); + throw new ByResponseFormatComponentException(result.right().value()); } // update properties @@ -517,7 +520,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return result; - } catch (ComponentException e) { + } catch (ByResponseFormatComponentException e) { log.error("#createListInput: Exception thrown", e); result = Either.right(e.getResponseFormat()); return result; @@ -569,7 +572,7 @@ public class InputsBusinessLogic extends BaseBusinessLogic { return Either.left(component); }).left().bind(component -> validateCanWorkOnComponent(component, userId).left().map(result -> component)); if (componentEither.isRight()) { - throw new ComponentException(componentEither.right().value()); + throw new ByResponseFormatComponentException(componentEither.right().value()); } return componentEither.left().value(); } @@ -578,14 +581,14 @@ public class InputsBusinessLogic extends BaseBusinessLogic { // Confirm if type is list if (StringUtils.isEmpty(input.getType()) || !input.getType().equals(ToscaPropertyType.LIST.getType())) { log.debug("#prepareDataTypeForListInput: Type of input is not list."); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE)); } // Confirm schema type is not empty String desiredTypeName = input.getSchemaType(); if (StringUtils.isEmpty(desiredTypeName)) { log.debug("#prepareDataTypeForListInput: Schema type of list input is empty."); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE)); } DataTypeDefinition dataType = new DataTypeDefinition(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java index 8b22d60ce6..30a9f799fe 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogic.java @@ -16,11 +16,14 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; import fj.data.Either; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum; @@ -272,11 +275,11 @@ public class ProductBusinessLogic extends ComponentBusinessLogic { try{ contactUser = validateUserExists(contact, CREATE_PRODUCT, false); validateUserRole(contactUser, contactsRoles); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ log.debug("Cannot set contact with userId {} as product contact, error: {}", contact, e.getActionStatus()); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PRODUCT_CONTACT, contact); componentsUtils.auditComponentAdmin(responseFormat, user, product, actionEnum, ComponentTypeEnum.PRODUCT); - throw new ComponentException(e.getActionStatus(), e.getParams()); + throw new ByActionStatusComponentException(e.getActionStatus(), e.getParams()); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 78e56ac1c9..0968e157e4 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -60,6 +62,8 @@ import org.openecomp.sdc.be.components.csar.CsarInfo; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo; import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.utils.CINodeFilterUtils; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; @@ -380,7 +384,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CSAR_UUID, resource.getName()); componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.CREATE_RESOURCE); - throw new ComponentException(ActionStatus.MISSING_CSAR_UUID, resource.getName()); + throw new ByActionStatusComponentException(ActionStatus.MISSING_CSAR_UUID, resource.getName()); } return updatedResource; } @@ -406,7 +410,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.VSP_ALREADY_EXISTS, csarUUID, resourceLinkedToCsarRes.left().value().getName()); componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.UPDATE_RESOURCE_METADATA); - throw new ComponentException(ActionStatus.VSP_ALREADY_EXISTS, csarUUID, + throw new ByActionStatusComponentException(ActionStatus.VSP_ALREADY_EXISTS, csarUUID, resourceLinkedToCsarRes.left().value().getName()); } } @@ -425,7 +429,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat errorResponse = componentsUtils.getResponseFormat( ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID, oldCsarUUID); componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.UPDATE_RESOURCE_METADATA); - throw new ComponentException(ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID, oldCsarUUID); + throw new ByActionStatusComponentException(ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID, oldCsarUUID); } } @@ -458,7 +462,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either<Boolean, ResponseFormat> lockResult = lockComponent(lockedResourceId, oldResource, "update Resource From Csar"); if (lockResult.isRight()) { - throw new ComponentException(lockResult.right().value()); + throw new ByResponseFormatComponentException(lockResult.right().value()); } Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractNodeTypesInfo(); @@ -468,7 +472,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (findNodeTypesArtifactsToHandleRes.isRight()) { log.debug("failed to find node types for update with artifacts during import csar {}. ", csarInfo.getCsarUUID()); - throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value()); + throw new ByResponseFormatComponentException(findNodeTypesArtifactsToHandleRes.right().value()); } Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = findNodeTypesArtifactsToHandleRes .left().value(); @@ -496,7 +500,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { !oldResource.getLastUpdaterUserId().equals(user.getUserId())) { log.debug("#validateLifecycleState - Current user is not last updater, last updater userId: {}, current user userId: {}", oldResource.getLastUpdaterUserId(), user.getUserId()); - throw new ComponentException(ActionStatus.RESTRICTED_OPERATION); + throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION); } } @@ -529,7 +533,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { uploadComponentInstanceInfoMap = csarBusinessLogic.getParsedToscaYamlInfo(yamlFileContent, yamlFileName, nodeTypesInfo, csarInfo, nodeName); Map<String, UploadComponentInstanceInfo> instances = uploadComponentInstanceInfoMap.getInstances(); if (MapUtils.isEmpty(instances) && newRresource.getResourceType() != ResourceTypeEnum.PNF) { - throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlFileName); + throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlFileName); } preparedResource = updateExistingResourceByImport(newRresource, oldRresource, csarInfo.getModifier(), inTransaction, shouldLock, isNested).left; @@ -540,8 +544,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { preparedResource = createInputsOnResource(preparedResource, uploadComponentInstanceInfoMap.getInputs()); preparedResource = createResourceInstances(yamlFileName, preparedResource, instances, csarInfo.getCreatedNodes()); preparedResource = createResourceInstancesRelations(csarInfo.getModifier(), yamlFileName, preparedResource, instances); - } catch (ComponentException e) { - ResponseFormat responseFormat = e.getResponseFormat() == null ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat(); + } catch (ByResponseFormatComponentException e) { + ResponseFormat responseFormat = e.getResponseFormat(); + log.debug("#updateResourceFromYaml - failed to update resource from yaml {} .The error is {}", yamlFileName, responseFormat); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), preparedResource == null ? oldRresource : preparedResource, actionEnum); + throw e; + } catch (ByActionStatusComponentException e) { + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); log.debug("#updateResourceFromYaml - failed to update resource from yaml {} .The error is {}", yamlFileName, responseFormat); componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), preparedResource == null ? oldRresource : preparedResource, actionEnum); throw e; @@ -556,7 +565,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { preparedResource.getSystemName()); if (validateUpdateVfGroupNamesRes.isRight()) { - throw new ComponentException(validateUpdateVfGroupNamesRes.right().value()); + throw new ByResponseFormatComponentException(validateUpdateVfGroupNamesRes.right().value()); } // add groups to resource Map<String, GroupDefinition> groups; @@ -575,7 +584,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { csarInfo, preparedResource, nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock); if (updateArtifactsEither.isRight()) { log.debug("failed to update artifacts {}", updateArtifactsEither.right().value()); - throw new ComponentException(updateArtifactsEither.right().value()); + throw new ByResponseFormatComponentException(updateArtifactsEither.right().value()); } preparedResource = getResourceWithGroups(updateArtifactsEither.left().value().getUniqueId()); @@ -583,7 +592,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (mergingPropsAndInputsStatus != ActionStatus.OK) { ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(mergingPropsAndInputsStatus, preparedResource); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } compositionBusinessLogic.setPositionsForComponentInstances(preparedResource, csarInfo.getModifier().getUserId()); return preparedResource; @@ -688,7 +697,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.debug("Error occured during fetching node type with tosca name {}, error: {}", currVfcToscaName, status); ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID()); componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.CREATE_RESOURCE); - throw new ComponentException(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID()); + throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID()); } else if (StringUtils.isNotEmpty(currVfcToscaName)) { return (Resource)toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName) .left() @@ -710,7 +719,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { nodeTypeArtifactsToHandle = putFoundArtifacts(artifactsToUpload, artifactsToUpdate, artifactsToDelete); } catch (Exception e) { log.debug("Exception occured when findNodeTypeArtifactsToHandle, error is:{}", e.getMessage(), e); - throw new ComponentException(ActionStatus.GENERAL_ERROR); + throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); } return nodeTypeArtifactsToHandle; } @@ -753,7 +762,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { artifactsToUpload.remove(currNewArtifact); } else { log.debug("Can't upload two artifact with the same name {}.", currNewArtifact.getArtifactName()); - throw new ComponentException(ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, + throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR, currNewArtifact.getArtifactName(), currNewArtifact.getArtifactType(), foundArtifact.get().getArtifactType()); } @@ -937,7 +946,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (findNodeTypesArtifactsToHandleRes.isRight()) { log.debug("failed to find node types for update with artifacts during import csar {}. ", csarInfo.getCsarUUID()); - throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value()); + throw new ByResponseFormatComponentException(findNodeTypesArtifactsToHandleRes.right().value()); } Resource vfResource = createResourceFromYaml(resource, csarInfo.getMainTemplateContent(), csarInfo.getMainTemplateName(), nodeTypesInfo, csarInfo, findNodeTypesArtifactsToHandleRes.left().value(), true, false, @@ -972,15 +981,19 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { try{ ParsedToscaYamlInfo parsedToscaYamlInfo = csarBusinessLogic.getParsedToscaYamlInfo(topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo, nodeName); if (MapUtils.isEmpty(parsedToscaYamlInfo.getInstances()) && resource.getResourceType() != ResourceTypeEnum.PNF) { - throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName); + throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName); } log.debug("#createResourceFromYaml - Going to create resource {} and RIs ", resource.getName()); createdResource = createResourceAndRIsFromYaml(yamlName, resource, parsedToscaYamlInfo, AuditingActionEnum.IMPORT_RESOURCE, false, createdArtifacts, topologyTemplateYaml, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName); log.debug("#createResourceFromYaml - The resource {} has been created ", resource.getName()); - } catch (ComponentException e) { - ResponseFormat responseFormat = e.getResponseFormat() == null ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat(); + } catch (ByActionStatusComponentException e) { + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE); + throw e; + } catch (ByResponseFormatComponentException e) { + ResponseFormat responseFormat = e.getResponseFormat(); componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE); throw e; } catch (StorageException e){ @@ -1000,7 +1013,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either<String, ResultStatusEnum> toscaVersion = findFirstToscaStringElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION); if (toscaVersion.isRight()) { - throw new ComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE); + throw new ByActionStatusComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE); } Map<String, Object> mapToConvert = new HashMap<>(); mapToConvert.put(TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), toscaVersion.left().value()); @@ -1084,7 +1097,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (oldComplexVfcRes.isRight() && oldComplexVfcRes.right().value() != StorageOperationStatus.NOT_FOUND) { log.debug("Failed to fetch previous complex VFC by tosca resource name {}. Status is {}. ", newComplexVfc.getToscaResourceName(), oldComplexVfcRes.right().value()); - throw new ComponentException(ActionStatus.GENERAL_ERROR); + throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); } else if (oldComplexVfcRes.isLeft()) { log.debug(VALIDATE_DERIVED_BEFORE_UPDATE); Either<Boolean, ResponseFormat> eitherValidation = validateNestedDerivedFromDuringUpdate( @@ -1202,7 +1215,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } private ImmutablePair<Resource,ActionStatus> failOnCertification(ResponseFormat error) { - throw new ComponentException(error); + throw new ByResponseFormatComponentException(error); } private UploadResourceInfo fillResourceMetadata(String yamlName, Resource resourceVf, @@ -1213,7 +1226,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (!nodeName.startsWith(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX)) { log.debug("invalid nodeName:{} does not start with {}.", nodeName, Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX); - throw new ComponentException(ActionStatus.INVALID_NODE_TEMPLATE, + throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeName); } @@ -1231,7 +1244,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (!ResourceTypeEnum.containsName(resourceType.toUpperCase())) { log.debug("invalid resourceType:{} the type is not one of the valide types:{}.", resourceType.toUpperCase(), ResourceTypeEnum.values()); - throw new ComponentException(ActionStatus.INVALID_NODE_TEMPLATE, + throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, resourceMetaData.getName(), nodeName); } @@ -1331,7 +1344,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { CREATE_RESOURCE); if (lockResult.isRight()) { rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts); - throw new ComponentException(lockResult.right().value()); + throw new ByResponseFormatComponentException(lockResult.right().value()); } log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult); } @@ -1362,7 +1375,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { .validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), resource.getSystemName()); if (validateUpdateVfGroupNamesRes.isRight()) { rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts); - throw new ComponentException(validateUpdateVfGroupNamesRes.right().value()); + throw new ByResponseFormatComponentException(validateUpdateVfGroupNamesRes.right().value()); } // add groups to resource Map<String, GroupDefinition> groups; @@ -1378,7 +1391,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { groups); if (createGroupsOnResource.isRight()) { rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts); - throw new ComponentException(createGroupsOnResource.right().value()); + throw new ByResponseFormatComponentException(createGroupsOnResource.right().value()); } resource = createGroupsOnResource.left().value(); log.trace("************* Finished to add groups from yaml {}", yamlName); @@ -1392,7 +1405,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { csarInfo, resource, nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock); if (createArtifactsEither.isRight()) { rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts); - throw new ComponentException(createArtifactsEither.right().value()); + throw new ByResponseFormatComponentException(createArtifactsEither.right().value()); } resource = getResourceWithGroups(createArtifactsEither.left().value().getUniqueId()); @@ -1524,7 +1537,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either<Resource, StorageOperationStatus> updatedResource = toscaOperationFacade .getToscaElement(resource.getUniqueId()); if (updatedResource.isRight()) { - throw new ComponentException(componentsUtils.getResponseFormatByResource( + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource( componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource)); } return updatedResource.left().value(); @@ -1601,7 +1614,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either<List<InputDefinition>, ResponseFormat> createInputs = inputsBusinessLogic.createInputsInGraph(inputs, resource); if (createInputs.isRight()) { - throw new ComponentException(createInputs.right().value()); + throw new ByResponseFormatComponentException(createInputs.right().value()); } } else { return resource; @@ -1609,7 +1622,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either<Resource, StorageOperationStatus> updatedResource = toscaOperationFacade .getToscaElement(resource.getUniqueId()); if (updatedResource.isRight()) { - throw new ComponentException(componentsUtils.getResponseFormatByResource( + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource( componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource)); } return updatedResource.left().value(); @@ -1623,7 +1636,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (groups != null) { Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies = validateCyclicGroupsDependencies(groups); if (validateCyclicGroupsDependencies.isRight()) { - throw new ComponentException(validateCyclicGroupsDependencies.right().value()); + throw new ByResponseFormatComponentException(validateCyclicGroupsDependencies.right().value()); } for (Entry<String, GroupDefinition> entry : groups.entrySet()) { String groupName = entry.getKey(); @@ -1647,7 +1660,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { String membersAstString = compInstancesNames.stream().collect(joining(",")); log.debug("The members: {}, in group: {}, cannot be found in component {}. There are no component instances.", membersAstString, groupName, component.getNormalizedName()); - throw new ComponentException(componentsUtils.getResponseFormat( + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat( ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString, groupName, component.getNormalizedName(), getComponentTypeForResponse(component))); } @@ -1669,7 +1682,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { String membersAstString = compInstancesNames.stream().collect(joining(",")); log.debug("The members: {}, in group: {}, cannot be found in component: {}", membersAstString, groupName, component.getNormalizedName()); - throw new ComponentException(componentsUtils.getResponseFormat( + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat( ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString, groupName, component.getNormalizedName(), getComponentTypeForResponse(component))); } @@ -1836,9 +1849,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } createResourcesFromYamlNodeTypesList(yamlName, resource, mappedToscaTemplate, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo); - } catch(ComponentException e){ - ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() - : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + } catch(ByActionStatusComponentException e){ + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE); + throw e; + } catch(ByResponseFormatComponentException e){ + ResponseFormat responseFormat = e.getResponseFormat(); componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE); throw e; } catch (StorageException e){ @@ -2152,7 +2168,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { resource.getResourceType() != ResourceTypeEnum.PNF)) { // PNF can have no resource instances log.debug("#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ", resource.getUniqueId(), yamlName); BeEcompErrorManager.getInstance().logInternalDataError("createResourceInstancesRelations", "No instances found in a resource or nn yaml template. ", ErrorSeverity.ERROR); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName)); } Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>(); @@ -2170,7 +2186,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { TitanOperationStatus status = allDataTypes.right().value(); BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance", "Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR); - throw new ComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse( + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse( DaoStatusConverter.convertTitanStatusToStorageStatus(status)), yamlName)); } @@ -2197,7 +2213,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(resource.getUniqueId()); log.debug("************* in create relations, getResource end"); if (eitherGetResource.isRight()) { - throw new ComponentException(componentsUtils.getResponseFormatByResource( + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource( componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource)); } return eitherGetResource.left().value(); @@ -2220,7 +2236,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) { log.debug("failed to associate instances of resource {} status is {}", resource.getUniqueId(), addArtToInst); - throw new ComponentException(componentsUtils + throw new ByResponseFormatComponentException(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName)); } } @@ -2243,7 +2259,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) { log.debug("failed to associate attributes of resource {} status is {}", resource.getUniqueId(), addArtToInst); - throw new ComponentException(componentsUtils + throw new ByResponseFormatComponentException(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName)); } } @@ -2255,7 +2271,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) { log.debug("failed to associate cap and req of resource {} status is {}", resource.getUniqueId(), addArtToInst); - throw new ComponentException(componentsUtils + throw new ByResponseFormatComponentException(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName)); } } @@ -2266,7 +2282,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { addArtToInst = toscaOperationFacade.associateArtifactsToInstances(instArtifacts, resource.getUniqueId()); if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) { log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst); - throw new ComponentException(componentsUtils + throw new ByResponseFormatComponentException(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName)); } } @@ -2276,7 +2292,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { .associateDeploymentArtifactsToInstances(instDeploymentArtifacts, resource.getUniqueId(), user); if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) { log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst); - throw new ComponentException(componentsUtils + throw new ByResponseFormatComponentException(componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName)); } } @@ -2288,7 +2304,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (addInputToInst.isRight()) { log.debug("failed to associate inputs value of resource {} status is {}", resource.getUniqueId(), addInputToInst.right().value()); - throw new ComponentException(componentsUtils.getResponseFormat( + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat( componentsUtils.convertFromStorageResponse(addInputToInst.right().value()), yamlName)); } } @@ -2300,7 +2316,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (addPropToInst.isRight()) { log.debug("failed to associate properties of resource {} status is {}", resource.getUniqueId(), addPropToInst.right().value()); - throw new ComponentException(componentsUtils.getResponseFormat( + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat( componentsUtils.convertFromStorageResponse(addPropToInst.right().value()), yamlName)); } } @@ -2311,14 +2327,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (getResourceRes.isRight()) { ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource( componentsUtils.convertFromStorageResponse(getResourceRes.right().value()), resource); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } getResourceRes = updateCalculatedCapReqWithSubstitutionMappings(getResourceRes.left().value(), uploadResInstancesMap); if (getResourceRes.isRight()) { ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource( componentsUtils.convertFromStorageResponse(getResourceRes.right().value()), resource); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } } } @@ -2343,12 +2359,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { resource.getUniqueId(), ErrorSeverity.ERROR); ResponseFormat responseFormat = componentsUtils .getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } ResponseFormat addRelationToRiRes = addRelationToRI(yamlName, resource, entry.getValue(), relations); if (addRelationToRiRes.getStatus() != 200) { - throw new ComponentException(addRelationToRiRes); + throw new ByResponseFormatComponentException(addRelationToRiRes); } } } @@ -2365,7 +2381,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { resource.getUniqueId(), ErrorSeverity.ERROR); ResponseFormat responseFormat = componentsUtils .getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } ComponentInstance currentCompInstance = currentCompInstanceOpt.get(); String resourceInstanceId = currentCompInstance.getUniqueId(); @@ -2390,7 +2406,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, instProperties, allDataTypes.left().value()); if (addPropertiesValueToRiRes.getStatus() != 200) { - throw new ComponentException(addPropertiesValueToRiRes); + throw new ByResponseFormatComponentException(addPropertiesValueToRiRes); } } else { addInputsValuesToRi(uploadComponentInstanceInfo, resource, @@ -2409,7 +2425,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { getOriginResourceRes); ResponseFormat responseFormat = componentsUtils.getResponseFormat( componentsUtils.convertFromStorageResponse(getOriginResourceRes.right().value()), yamlName); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } originResource = getOriginResourceRes.left().value(); originCompMap.put(originResource.getUniqueId(), originResource); @@ -2692,7 +2708,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (CollectionUtils.isEmpty( originResource.getInputs())) { log.debug("failed to find properties "); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND)); } originResource.getInputs().forEach(p->addInput(currPropertiesMap, p)); for (List<UploadPropInfo> propertyList : propMap.values()) { @@ -2708,7 +2724,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { String propName = propertyInfo.getName(); if (!currPropertiesMap.containsKey(propName)) { log.debug("failed to find property {} ", propName); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, propName)); } InputDefinition curPropertyDef = currPropertiesMap.get(propName); @@ -2742,7 +2758,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (CollectionUtils.isEmpty(inputs)) { log.debug("Failed to add property {} to resource instance {}. Inputs list is empty ", property, currentCompInstance.getUniqueId()); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)); } Optional<InputDefinition> optional = inputs.stream() @@ -2750,7 +2766,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (!optional.isPresent()) { log.debug("Failed to find input {} ", getInput.getInputName()); // @@TODO error message - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)); } InputDefinition input = optional.get(); getInput.setInputId(input.getUniqueId()); @@ -2774,7 +2790,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (!optional.isPresent()) { log.debug("Failed to find input {} ", getInputIndex.getInputName()); // @@TODO error message - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT)); } InputDefinition inputIndex = optional.get(); getInputIndex.setInputId(inputIndex.getUniqueId()); @@ -3029,7 +3045,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName); if (isEmpty(uploadResInstancesMap) && resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } Map<String, Resource> existingNodeTypeMap = new HashMap<>(); if (MapUtils.isNotEmpty(nodeNamespaceMap)) { @@ -3048,7 +3064,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat responseFormat = componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(status)); eitherResource = Either.right(responseFormat); - throw new ComponentException(eitherResource.right().value()); + throw new ByResponseFormatComponentException(eitherResource.right().value()); } } log.debug("*************Going to get resource {}", resource.getUniqueId()); @@ -3058,14 +3074,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (eitherGetResource.isRight()) { ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource( componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } if (CollectionUtils.isEmpty(eitherGetResource.left().value().getComponentInstances()) && resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances log.debug("Error when create resource instance from csar. ComponentInstances list empty"); BeEcompErrorManager.getInstance().logBeDaoSystemError( "Error when create resource instance from csar. ComponentInstances list empty"); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE)); } return eitherGetResource.left().value(); } @@ -3114,7 +3130,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType()); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType()); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } Resource origResource = existingnodeTypeMap.get(uploadComponentInstanceInfo.getType()); componentInstance.setName(uploadComponentInstanceInfo.getName()); @@ -3170,7 +3186,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType()); ResponseFormat responseFormat = componentsUtils.getResponseFormat( componentsUtils.convertFromStorageResponse(findResourceEither.right().value())); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } refResource = findResourceEither.left().value(); nodeNamespaceMap.put(refResource.getToscaResourceName(), refResource); @@ -3182,14 +3198,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { refResource.getName(), componentState); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ILLEGAL_COMPONENT_STATE, refResource.getComponentType().getValue(), refResource.getName(), componentState); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } if (!ModelConverter.isAtomicComponent(refResource) && refResource.getResourceType() != ResourceTypeEnum.CVFC) { log.debug("validateResourceInstanceBeforeCreate - ref resource type is ", refResource.getResourceType()); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE, yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType()); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } return refResource; } @@ -3484,7 +3500,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { .state(oldResource.getLifecycleState().name()) .version(oldResource.getVersion()) .build()); - throw new ComponentException(response); + throw new ByResponseFormatComponentException(response); } public Resource validateResourceBeforeCreate(Resource resource, User user, AuditingActionEnum actionEnum, boolean inTransaction, CsarInfo csarInfo) { @@ -3691,7 +3707,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (lockResult.isRight()) { ResponseFormat responseFormat = lockResult.right().value(); componentsUtils.auditResource(responseFormat, user, resource, actionEnum); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult); @@ -3705,8 +3721,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { componentsUtils.auditResource(componentsUtils.getResponseFormat(ActionStatus.CREATED), user, createdResource, actionEnum); ASDCKpiApi.countCreatedResourcesKPI(); - } catch(ComponentException e) { - ResponseFormat responseFormat = e.getResponseFormat() == null ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat(); + } catch(ByActionStatusComponentException e) { + ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + componentsUtils.auditResource(responseFormat, user, resource, actionEnum); + throw e; + } catch(ByResponseFormatComponentException e) { + ResponseFormat responseFormat = e.getResponseFormat(); componentsUtils.auditResource(responseFormat, user, resource, actionEnum); throw e; } catch (StorageException e){ @@ -3734,13 +3754,13 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { eitherValidation.right().value()); ResponseFormat errorResponse = componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(eitherValidation.right().value())); - throw new ComponentException(errorResponse); + throw new ByResponseFormatComponentException(errorResponse); } if (eitherValidation.left().value()) { log.debug("resource with name: {}, already exists", resource.getName()); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resource.getName()); - throw new ComponentException(errorResponse); + throw new ByResponseFormatComponentException(errorResponse); } log.debug("send resource {} to dao for create", resource.getName()); @@ -3764,7 +3784,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { private Resource throwComponentExceptionByResource(StorageOperationStatus status, Resource resource) { ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource( componentsUtils.convertFromStorageResponse(status), resource); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } private void createArtifactsPlaceHolderData(Resource resource, User user) { @@ -4019,7 +4039,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either<Resource, StorageOperationStatus> storageStatus = toscaOperationFacade .getToscaElement(resourceIdToUpdate); if (storageStatus.isRight()) { - throw new ComponentException(componentsUtils.getResponseFormatByResource( + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource( componentsUtils.convertFromStorageResponse(storageStatus.right().value()), "")); } @@ -4028,7 +4048,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { // verify that resource is checked-out and the user is the last // updater if (!ComponentValidationUtils.canWorkOnResource(currentResource, user.getUserId())) { - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)); } // lock resource @@ -4040,7 +4060,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.debug("Failed to lock resource: {}, error - {}", resourceIdToUpdate, lockResult); ResponseFormat responseFormat = componentsUtils .getResponseFormat(componentsUtils.convertFromStorageResponse(lockResult)); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } needToUnlock = true; @@ -4064,7 +4084,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (dataModelResponse.isRight()) { log.debug("failed to update resource metadata!!!"); rollbackNeeded = true; - throw new ComponentException(dataModelResponse.right().value()); + throw new ByResponseFormatComponentException(dataModelResponse.right().value()); } log.debug("Resource metadata updated successfully!!!"); @@ -4368,7 +4388,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } else { log.info("Resource name: {}, cannot be updated once the resource has been certified once.", resourceNameUpdated); - throw new ComponentException(ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED); + throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED); } } } @@ -4381,7 +4401,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { validateIcon(null, updateInfoResource, null); } else { log.info("Icon {} cannot be updated once the resource has been certified once.", iconUpdated); - throw new ComponentException(ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED); + throw new ByActionStatusComponentException(ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED); } } } @@ -4497,12 +4517,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { .getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus), resource); log.trace("audit before sending response"); componentsUtils.auditResource(responseFormat, user, resource, actionEnum); - throw new ComponentException(componentsUtils.convertFromStorageResponse(storageStatus)); + throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(storageStatus)); } else if (!dataModelResponse.left().value()) { log.info("resource template with name: {}, does not exists", templateName); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PARENT_RESOURCE_NOT_FOUND); componentsUtils.auditResource(responseFormat, user, resource, actionEnum); - throw new ComponentException(ActionStatus.PARENT_RESOURCE_NOT_FOUND); + throw new ByActionStatusComponentException(ActionStatus.PARENT_RESOURCE_NOT_FOUND); } } @@ -4547,7 +4567,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { .getResponseFormat(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); componentsUtils.auditResource(responseFormat, user, resource, actionEnum); - throw new ComponentException(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); + throw new ByActionStatusComponentException(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); } } @@ -4558,7 +4578,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { resource.getComponentType()); if (resourceOperationResponse.isLeft() && resourceOperationResponse.left().value()) { log.debug("resource with name: {}, already exists", resource.getName()); - throw new ComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resource.getName()); } else if(resourceOperationResponse.isRight()){ log.debug("error while validateResourceNameExists for resource: {}", resource.getName()); @@ -4576,22 +4596,22 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); componentsUtils.auditResource(responseFormat, user, resource, actionEnum); - throw new ComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); } if (categories.size() > 1) { log.debug("Must be only one category for resource"); - throw new ComponentException(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.RESOURCE.getValue()); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.RESOURCE.getValue()); } CategoryDefinition category = categories.get(0); List<SubCategoryDefinition> subcategories = category.getSubcategories(); if (CollectionUtils.isEmpty(subcategories)) { log.debug("Missinig subcategory for resource"); - throw new ComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY); } if (subcategories.size() > 1) { log.debug("Must be only one sub category for resource"); - throw new ComponentException(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES); + throw new ByActionStatusComponentException(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES); } SubCategoryDefinition subcategory = subcategories.get(0); @@ -4601,7 +4621,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); componentsUtils.auditResource(responseFormat, user, resource, actionEnum); - throw new ComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); } if (!ValidationUtils.validateStringNotEmpty(subcategory.getName())) { @@ -4609,7 +4629,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat responseFormat = componentsUtils.getResponseFormat( ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue()); componentsUtils.auditResource(responseFormat, user, resource, actionEnum); - throw new ComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue()); + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue()); } validateCategoryListed(category, subcategory, user, resource, actionEnum, inTransaction); @@ -4626,7 +4646,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.debug("failed to retrieve resource categories from Titan"); responseFormat = componentsUtils.getResponseFormat(categories.right().value()); componentsUtils.auditResource(responseFormat, user, resource, actionEnum); - throw new ComponentException(categories.right().value()); + throw new ByActionStatusComponentException(categories.right().value()); } List<CategoryDefinition> categoryList = categories.left().value(); Optional<CategoryDefinition> foundCategory = categoryList.stream() @@ -4655,7 +4675,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); componentsUtils.auditResource(responseFormat, user, resource, actionEnum); - throw new ComponentException(ActionStatus.COMPONENT_INVALID_CATEGORY, + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); } @@ -4666,7 +4686,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.info("vendor relese name is missing."); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_RELEASE); componentsUtils.auditResource(errorResponse, user, resource, actionEnum); - throw new ComponentException(ActionStatus.MISSING_VENDOR_RELEASE); + throw new ByActionStatusComponentException(ActionStatus.MISSING_VENDOR_RELEASE); } validateVendorReleaseName(vendorRelease, user, resource, actionEnum); @@ -4679,14 +4699,14 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat errorResponse = componentsUtils.getResponseFormat( ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH); componentsUtils.auditResource(errorResponse, user, resource, actionEnum); - throw new ComponentException(ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH); + throw new ByActionStatusComponentException(ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH); } if (!ValidationUtils.validateVendorRelease(vendorRelease)) { log.info("vendor release is not valid."); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_VENDOR_RELEASE); componentsUtils.auditResource(errorResponse, user, resource, actionEnum); - throw new ComponentException(ActionStatus.INVALID_VENDOR_RELEASE); + throw new ByActionStatusComponentException(ActionStatus.INVALID_VENDOR_RELEASE); } } } @@ -4698,7 +4718,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.info("vendor name is missing."); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_NAME); componentsUtils.auditResource(errorResponse, user, resource, actionEnum); - throw new ComponentException(ActionStatus.MISSING_VENDOR_NAME); + throw new ByActionStatusComponentException(ActionStatus.MISSING_VENDOR_NAME); } validateVendorName(vendorName, user, resource, actionEnum); } @@ -4711,7 +4731,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH); componentsUtils.auditResource(errorResponse, user, resource, actionEnum); - throw new ComponentException(ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT, + throw new ByActionStatusComponentException(ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH); } @@ -4719,7 +4739,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.info("vendor name is not valid."); ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_VENDOR_NAME); componentsUtils.auditResource(errorResponse, user, resource, actionEnum); - throw new ComponentException(ActionStatus.INVALID_VENDOR_NAME); + throw new ByActionStatusComponentException(ActionStatus.INVALID_VENDOR_NAME); } } } @@ -4733,7 +4753,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT, "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH); componentsUtils.auditResource(errorResponse, user, resource, actionEnum); - throw new ComponentException(ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT, + throw new ByActionStatusComponentException(ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT, "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH); } // resource vendor model number is currently validated as vendor @@ -4743,7 +4763,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { ResponseFormat errorResponse = componentsUtils .getResponseFormat(ActionStatus.INVALID_RESOURCE_VENDOR_MODEL_NUMBER); componentsUtils.auditResource(errorResponse, user, resource, actionEnum); - throw new ComponentException(ActionStatus.INVALID_RESOURCE_VENDOR_MODEL_NUMBER); + throw new ByActionStatusComponentException(ActionStatus.INVALID_RESOURCE_VENDOR_MODEL_NUMBER); } } } @@ -4754,7 +4774,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (cost != null) { if (!ValidationUtils.validateCost(cost)) { log.debug("resource cost is invalid."); - throw new ComponentException(ActionStatus.INVALID_CONTENT); + throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT); } } } @@ -4773,7 +4793,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { // In update case, no audit is required componentsUtils.auditResource(responseFormat, user, resource, actionEnum); } - throw new ComponentException(ActionStatus.INVALID_CONTENT); + throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT); } } } @@ -5001,7 +5021,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { validCapabilityList.add(defaultCapability); validCapabilitiesMap.put(key, validCapabilityList); } else { - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, capabilityType)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, capabilityType)); } } @@ -5013,7 +5033,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { log.debug( "Failed to update capability property values. Property list of fetched capability {} is empty. ", defaultCapability.getName()); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, resourceId)); + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, resourceId)); } else if (isNotEmpty(capabilities.get(0).getProperties())) { validateUniquenessUpdateUploadedComponentInstanceCapability(defaultCapability, capabilities.get(0)); } @@ -5029,7 +5049,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (getFullComponentRes.isRight()) { log.debug("Failed to get full component {}. Status is {}. ", resourceId, getFullComponentRes.right().value()); - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND, + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND, resourceId)); } defaultCapability = getFullComponentRes.left().value().getCapabilities().get(capabilityType).get(0); @@ -5048,7 +5068,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { String propertyType = property.getType(); ComponentInstanceProperty validProperty; if (defaultProperties.containsKey(propertyName) && propertTypeEqualsTo(defaultProperties, propertyName, propertyType)) { - throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS, + throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS, propertyName)); } validProperty = new ComponentInstanceProperty(); @@ -5197,7 +5217,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } catch (Exception e) { ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_TOSCA_TEMPLATE); log.debug("Exception occured when buildNestedToscaResourceName, error is:{}", e.getMessage(), e); - throw new ComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE, vfResourceName); + throw new ByActionStatusComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE, vfResourceName); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java index 4d72f87289..cd9be0fe72 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceImportManager.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -264,9 +266,8 @@ public class ResourceImportManager { } catch (ComponentException e) { - ResponseFormat responseFormat = e.getResponseFormat() != null? - e.getResponseFormat() : getResponseFormatManager().getResponseFormat(e.getActionStatus(), e.getParams()); - response = Either.right(handleImportResourceException(resourceMetaData, creator, false, e, responseFormat)); + response = Either.right(handleImportResourceException(resourceMetaData, creator, false, e, + e.getResponseFormat())); } catch (RuntimeException e) { response = Either.right(handleImportResourceException(resourceMetaData, creator, false, e, null)); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index cad9a92ab3..6c41985c9a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -61,6 +63,8 @@ import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine; import org.openecomp.sdc.be.components.distribution.engine.INotificationData; import org.openecomp.sdc.be.components.distribution.engine.VfModuleArtifactPayload; import org.openecomp.sdc.be.components.health.HealthCheckBusinessLogic; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; @@ -963,7 +967,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, service, actionEnum); if (serviceNameUniquenessValidation.isRight()) { - throw new ComponentException(serviceNameUniquenessValidation.right().value()); + throw new ByResponseFormatComponentException(serviceNameUniquenessValidation.right().value()); } Either<Boolean, ResponseFormat> categoryValidation = validateServiceCategory(user, service, actionEnum); if (categoryValidation.isRight()) { @@ -1462,7 +1466,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { String serviceType = ((Service)component).getServiceType(); if (serviceType == null) { log.info("service type is not valid."); - throw new ComponentException(ActionStatus.INVALID_SERVICE_TYPE); + throw new ByActionStatusComponentException(ActionStatus.INVALID_SERVICE_TYPE); } serviceType = cleanUpText(serviceType); validateServiceType(serviceType); @@ -1475,11 +1479,11 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { } if (!ValidationUtils.validateServiceTypeLength(serviceType)) { log.info("service type exceeds limit."); - throw new ComponentException(ActionStatus.SERVICE_TYPE_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_TYPE_MAX_LENGTH); + throw new ByActionStatusComponentException(ActionStatus.SERVICE_TYPE_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_TYPE_MAX_LENGTH); } if (!ValidationUtils.validateIsEnglish(serviceType)) { log.info("service type is not valid."); - throw new ComponentException(ActionStatus.INVALID_SERVICE_TYPE); + throw new ByActionStatusComponentException(ActionStatus.INVALID_SERVICE_TYPE); } } @@ -2378,7 +2382,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { log.debug("validateRoleForDeploy method - user is not listed. userId= {}", user.getUserId()); ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, user.getUserId()); auditDeployError(did, user, auditAction, service, ActionStatus.USER_NOT_FOUND); - throw new ComponentException(ActionStatus.USER_NOT_FOUND, user.getUserId()); + throw new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND, user.getUserId()); } user = eitherCreator.left().value(); log.debug("validate user role"); @@ -2387,7 +2391,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { roles.add(Role.OPS); try{ validateUserRole(user, service, roles, auditAction, null); - } catch (ComponentException e){ + } catch (ByActionStatusComponentException e){ log.info("role {} is not allowed to perform this action", user.getRole()); auditDeployError(did, user, auditAction, service, e.getActionStatus()); throw e; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByActionStatusComponentException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByActionStatusComponentException.java new file mode 100644 index 0000000000..4a19fdaf06 --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByActionStatusComponentException.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia 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.be.components.impl.exceptions; + +import java.util.Arrays; +import org.openecomp.sdc.be.components.impl.ResponseFormatManager; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.exception.ResponseFormat; + +public class ByActionStatusComponentException extends ComponentException { + + private final ActionStatus actionStatus; + private final String[] params; + + public ByActionStatusComponentException(ActionStatus actionStatus, String... params) { + this.actionStatus = actionStatus; + this.params = params.clone(); + } + + public ActionStatus getActionStatus() { + return actionStatus; + } + + public String[] getParams() { + return params.clone(); + } + + @Override + public ResponseFormat getResponseFormat() { + return ResponseFormatManager.getInstance().getResponseFormat(getActionStatus(), getParams()); + } + + @Override + public String toString() { + return "ComponentException{" + + "actionStatus=" + actionStatus + + ", params=" + Arrays.toString(params) + + '}'; + } + +} diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByResponseFormatComponentException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByResponseFormatComponentException.java new file mode 100644 index 0000000000..0737c45d49 --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ByResponseFormatComponentException.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia 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.be.components.impl.exceptions; + +import org.openecomp.sdc.exception.ResponseFormat; + +public class ByResponseFormatComponentException extends ComponentException { + + private final transient ResponseFormat responseFormat; + + public ByResponseFormatComponentException(ResponseFormat responseFormat) { + this.responseFormat = responseFormat; + } + + @Override + public ResponseFormat getResponseFormat() { + return responseFormat; + } + + @Override + public String toString() { + return "ComponentException{" + + "responseFormat=" + responseFormat + + '}'; + } + +} diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentException.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentException.java index 72d54873d2..bedb299163 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentException.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentException.java @@ -1,61 +1,37 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl.exceptions; -import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.exception.ResponseFormat; -import java.util.Arrays; +/** + * This class will be initialized either by action status and params or by ResponseFormat + */ +public abstract class ComponentException extends RuntimeException { -public class ComponentException extends RuntimeException { - - /** - * This class will be initialized either by action status and params or by ResponseFormat - */ - - private final transient ResponseFormat responseFormat; - private final ActionStatus actionStatus; - private final String[] params; - - public ComponentException(ResponseFormat responseFormat) { - this(responseFormat, ActionStatus.OK); - } - - public ComponentException(ActionStatus actionStatus, String... params) { - this(null, actionStatus, params); - } - - private ComponentException(ResponseFormat responseFormat, ActionStatus actionStatus, String... params) { - this.actionStatus = actionStatus; - this.params = params.clone(); - this.responseFormat = responseFormat; - } - - public ResponseFormat getResponseFormat() { - return responseFormat; - } - - public ActionStatus getActionStatus() { - return actionStatus; - } - - public String[] getParams() { - return params.clone(); - } + public abstract ResponseFormat getResponseFormat(); @Override public String getMessage() { return this.toString(); } - - @Override - public String toString() { - return "ComponentException{" + - "responseFormat=" + responseFormat + - ", actionStatus=" + actionStatus + - ", params=" + Arrays.toString(params) + - '}'; - } - - - - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/ExceptionUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/ExceptionUtils.java index e48d21cb77..2d6f354139 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/ExceptionUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/utils/ExceptionUtils.java @@ -1,6 +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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl.utils; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; @@ -20,12 +42,12 @@ public class ExceptionUtils { public <T> T rollBackAndThrow(ActionStatus actionStatus, String ... params) { titanDao.rollback(); - throw new ComponentException(actionStatus, params); + throw new ByActionStatusComponentException(actionStatus, params); } public <T> T rollBackAndThrow(ResponseFormat responseFormat) { titanDao.rollback(); - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } public <T> T rollBackAndThrow(StorageOperationStatus status, String ... params) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java index b0247a26e2..981f0bdff2 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.lifecycle; @@ -24,7 +26,7 @@ import fj.data.Either; import org.apache.commons.lang3.StringUtils; import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder; import org.openecomp.sdc.be.components.impl.*; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; @@ -314,7 +316,7 @@ public class LifecycleBusinessLogic { lastName = fullName[1]; } } - throw new ComponentException(ActionStatus.COMPONENT_ALREADY_CERTIFIED, + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ALREADY_CERTIFIED, component.getName(), component.getComponentType().name().toLowerCase(), firstName, diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBL.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBL.java index e9c4364181..68a8333e31 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBL.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/merge/instance/ExternalRefsMergeBL.java @@ -1,7 +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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.merge.instance; import fj.data.Either; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; @@ -36,7 +57,7 @@ public class ExternalRefsMergeBL implements ComponentInstanceMergeInterface { public Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) { Optional<ComponentInstance> componentInstance = updatedContainerComponent.getComponentInstanceById(newInstanceId); if (!componentInstance.isPresent()) { - throw new ComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, + throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, newInstanceId); } Map<String, List<String>> savedExternalRefs = dataHolder.getOrigCompInstExternalRefs(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java index d5a94c038a..9dbf012653 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/ComponentValidations.java @@ -16,12 +16,14 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.validation; import org.apache.commons.collections.CollectionUtils; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; @@ -108,7 +110,7 @@ public class ComponentValidations { void validateComponentIsCheckedOutByUser(Component component, String userId) { if (!ComponentValidationUtils.canWorkOnComponent(component, userId)) { - throw new ComponentException(ActionStatus.ILLEGAL_COMPONENT_STATE, component.getComponentType().name(), component.getName(), component.getLifecycleState().name()); + throw new ByActionStatusComponentException(ActionStatus.ILLEGAL_COMPONENT_STATE, component.getComponentType().name(), component.getName(), component.getLifecycleState().name()); } } Component validateComponentIsCheckedOutByUser(String componentId, ComponentTypeEnum componentTypeEnum, String userId) { @@ -129,7 +131,7 @@ public class ComponentValidations { private void validateComponentType(Component component, ComponentTypeEnum componentType) { if (componentType!=component.getComponentType()) { - throw new ComponentException(ActionStatus.INVALID_RESOURCE_TYPE); + throw new ByActionStatusComponentException(ActionStatus.INVALID_RESOURCE_TYPE); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java index 18fe51d3d4..dd65627738 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java @@ -1,8 +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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.validation; import fj.data.Either; import org.apache.commons.lang3.StringUtils; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.impl.ComponentsUtils; @@ -38,7 +59,7 @@ public class UserValidations { } log.debug("User is not listed. userId {}", userId); BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId); - throw new ComponentException(status); + throw new ByActionStatusComponentException(status); } return eitherCreator.left().value(); } @@ -48,7 +69,7 @@ public class UserValidations { if (roles != null) { if (!roles.contains(userRole)) { log.debug("user is not in appropriate role to perform action"); - throw new ComponentException(ActionStatus.RESTRICTED_OPERATION); + throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION); } } } @@ -74,7 +95,7 @@ public class UserValidations { if (StringUtils.isEmpty(userId)) { log.debug("User header is missing "); BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, user.getUserId()); - throw new ComponentException(ActionStatus.MISSING_INFORMATION); + throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION); } return user; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java index 9f6fb9fe89..0d9e21a66a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.impl; @@ -41,6 +43,8 @@ import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAdminEventFactory; import org.openecomp.sdc.be.components.impl.ImportUtils; import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum; import org.openecomp.sdc.be.components.impl.ResponseFormatManager; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -1516,15 +1520,21 @@ public class ComponentsUtils { } return result; } - - + public ResponseFormat getResponseFormat(ComponentException exception) { - ResponseFormat responseFormat = exception.getResponseFormat(); - if (responseFormat != null) { - return responseFormat; - } + return exception instanceof ByResponseFormatComponentException ? + getResponseFormat((ByResponseFormatComponentException) exception): + getResponseFormat((ByActionStatusComponentException) exception); + } + + public ResponseFormat getResponseFormat(ByResponseFormatComponentException exception) { + return exception.getResponseFormat(); + } + + public ResponseFormat getResponseFormat(ByActionStatusComponentException exception) { return getResponseFormat(exception.getActionStatus(), exception.getParams()); } + public ActionStatus convertFromStorageResponseForRelationshipType( StorageOperationStatus storageResponse) { ActionStatus responseEnum; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java index 3d7dd8c622..54c6c9cd59 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.servlets; @@ -49,7 +51,7 @@ import org.openecomp.sdc.be.components.impl.ImportUtils; import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum; import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum; import org.openecomp.sdc.be.components.impl.ResourceImportManager; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -649,7 +651,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { Either<Map<String, byte[]>, ResponseFormat> csarUIPayloadRes = getCsarFromPayload(resourceInfoObject); if (csarUIPayloadRes.isRight()) { - throw new ComponentException(csarUIPayloadRes.right().value()); + throw new ByResponseFormatComponentException(csarUIPayloadRes.right().value()); } Map<String, byte[]> csarUIPayload = csarUIPayloadRes.left().value(); @@ -666,7 +668,7 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { } private Resource throwComponentException(ResponseFormat responseFormat) { - throw new ComponentException(responseFormat); + throw new ByResponseFormatComponentException(responseFormat); } private void getAndValidateCsarYaml(Map<String, byte[]> csarUIPayload, Resource resource, User user, String csarUUID) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ComponentExceptionMapper.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ComponentExceptionMapper.java index 4ec1915014..19ef727b57 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ComponentExceptionMapper.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/exception/ComponentExceptionMapper.java @@ -1,7 +1,30 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.servlets.exception; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.common.log.wrappers.Logger; @@ -29,10 +52,6 @@ public class ComponentExceptionMapper implements ExceptionMapper<ComponentExcept // TODO log this? BeEcompErrorManager.getInstance().logBeRestApiGeneralError(requestURI); log.debug("#toResponse - An error occurred: ", exception); ResponseFormat responseFormat = exception.getResponseFormat(); - if (exception.getResponseFormat()==null) { - responseFormat = componentsUtils.getResponseFormat(exception.getActionStatus(), exception.getParams()); - } - return Response.status(responseFormat.getStatus()) .entity(gson.toJson(responseFormat.getRequestError())) .build(); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java index 32a2334669..50bb276c97 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogicTest.java @@ -43,7 +43,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; @@ -318,11 +318,11 @@ public class ComponentInstanceBusinessLogicTest { private void getServiceRelationByIdUserValidationFailure(Component component) { when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false))) - .thenThrow(new ComponentException(ActionStatus.USER_NOT_FOUND)); + .thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND)); try { componentInstanceBusinessLogic .getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType()); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertSame(e.getActionStatus(), ActionStatus.USER_NOT_FOUND); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java index 36f7084755..6d30003810 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ElementBusinessLogicTest.java @@ -1,3 +1,24 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import java.util.ArrayList; @@ -14,6 +35,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -189,7 +211,7 @@ public class ElementBusinessLogicTest { @Test(expected = ComponentException.class) public void testGetAllCategories_givenValidationOfUserFails_thenReturnsError() { - doThrow(new ComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()), + doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()), anyString(), anyBoolean()); elementBusinessLogic.getAllCategories(null, user.getUserId()); } @@ -268,7 +290,7 @@ public class ElementBusinessLogicTest { @Test(expected = ComponentException.class) public void testCreateSubCategory_givenUserValidationFails_thenReturnsException() { SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition(); - doThrow(new ComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()), + doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()), anyString(), anyBoolean()); elementBusinessLogic.createSubCategory(subCategoryDefinition, "resources", "cat1", user.getUserId()); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java index 955330d88e..ffeb80ec00 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogicTest.java @@ -568,7 +568,7 @@ public class InputsBusinessLogicTest { //ComponentInstListInput createListInputParams = setUpCreateListInputParams(); when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat()); + when(componentsUtilsMock.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat()); Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, LISTINPUT_NAME); assertEquals(true, result.isRight()); @@ -587,7 +587,7 @@ public class InputsBusinessLogicTest { when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))) .thenReturn(Either.left(service)); - when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat()); + when(componentsUtilsMock.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat()); Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, NONEXIST_INPUT_NAME); assertEquals(true, result.isRight()); @@ -625,7 +625,7 @@ public class InputsBusinessLogicTest { .thenReturn(Either.left(service)); when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK); when(toscaOperationFacadeMock.deleteInputOfResource(service, listInput.getName())).thenReturn(StorageOperationStatus.BAD_REQUEST); - when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat()); + when(componentsUtilsMock.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat()); Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, inputId); assertEquals(true, result.isRight()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java index 19f4caf8c1..e55578c989 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java @@ -43,7 +43,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator; import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder; import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder; @@ -178,12 +178,12 @@ public class PolicyBusinessLogicTest { @Test public void createPolicyUserFailureTest(){ - ComponentException userNotFoundException = new ComponentException(ActionStatus.USER_NOT_FOUND); + ByActionStatusComponentException userNotFoundException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND); when(userValidations.validateUserExists(eq(USER_ID), eq(CREATE_POLICY), eq(false))).thenThrow(userNotFoundException); stubRollback(); try{ businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertEquals(e.getActionStatus(), userNotFoundException.getActionStatus()); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java index 928a576f98..04f0a58ebf 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyPropertiesBusinessLogicTest.java @@ -1,3 +1,24 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import static org.assertj.core.api.Assertions.assertThat; @@ -17,6 +38,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.utils.PolicyDefinitionBuilder; import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder; @@ -105,11 +127,11 @@ public class PolicyPropertiesBusinessLogicTest { @Test public void getPolicyProperties_userIdIsNull() { String userId = null; - ComponentException forbiddenException = new ComponentException(ActionStatus.AUTH_FAILED); + ComponentException forbiddenException = new ByActionStatusComponentException(ActionStatus.AUTH_FAILED); when(userValidations.validateUserExists(eq(userId), anyString(), eq(false))).thenThrow(forbiddenException); try{ testInstance.getPolicyProperties(ComponentTypeEnum.RESOURCE, RESOURCE_ID, POLICY_ID, null); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertThat(e.getActionStatus()).isEqualTo(ActionStatus.AUTH_FAILED); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java index 811d0b900c..db74b2d2ed 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java @@ -1,3 +1,24 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import com.google.common.collect.ImmutableMap; @@ -9,7 +30,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.openecomp.sdc.be.DummyConfigurationManager; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.utils.PolicyTypeBuilder; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.config.ConfigurationManager; @@ -64,10 +85,10 @@ public class PolicyTypeBusinessLogicTest { @Test public void getAllPolicyTypes_userNotExist() { ResponseFormat userNotExistResponse = new ResponseFormat(); - when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(true))).thenThrow(new ComponentException(userNotExistResponse)); + when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(true))).thenThrow(new ByResponseFormatComponentException(userNotExistResponse)); try{ testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE); - }catch(ComponentException e){ + }catch(ByResponseFormatComponentException e){ assertThat(e.getResponseFormat()).isSameAs(userNotExistResponse); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogicTest.java index faaddd7565..e8d7300733 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ProductBusinessLogicTest.java @@ -1,3 +1,24 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl; import java.util.ArrayList; @@ -9,6 +30,8 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.components.validation.ValidationUtils; @@ -134,13 +157,13 @@ public class ProductBusinessLogicTest { @Test(expected = ComponentException.class) public void testCreateProduct_givenEmptyUserId_thenReturnsException() { when(userValidations.validateUserNotEmpty(Mockito.any(User.class), Mockito.anyString())) - .thenThrow(new ComponentException(new ResponseFormat())); + .thenThrow(new ByResponseFormatComponentException(new ResponseFormat())); productBusinessLogic.createProduct(product, user); } @Test(expected = ComponentException.class) public void testCreateProduct_givenUnknownUser_thenReturnsException() { - ComponentException componentException = new ComponentException(ActionStatus.USER_NOT_FOUND); + ComponentException componentException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND); when(userValidations.validateUserNotEmpty(any(User.class), anyString())) .thenReturn(user); when(userValidations.validateUserExists(anyString(), anyString(), anyBoolean())) @@ -151,7 +174,7 @@ public class ProductBusinessLogicTest { @Test(expected = ComponentException.class) public void testCreateProduct_givenInvalidUserRole_thenReturnsException() { user.setRole("CREATOR"); - doThrow(new ComponentException(new ResponseFormat())).when(userValidations).validateUserRole(any(), anyList()); + doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserRole(any(), anyList()); assertTrue(productBusinessLogic.createProduct(product, user).isRight()); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java index 8e35981722..9b5387c7b9 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -30,12 +32,13 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.ElementOperationMock; import org.openecomp.sdc.be.auditing.impl.AuditingManager; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.components.csar.CsarBusinessLogic; import org.openecomp.sdc.be.components.csar.CsarInfo; import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction; @@ -358,7 +361,7 @@ public class ResourceBusinessLogicTest { try{ createdResource= bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null); assertThat(createResourceObject(true)).isEqualTo(createdResource); - } catch(ComponentException e){ + } catch(ByResponseFormatComponentException e){ assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus()); } } @@ -380,7 +383,7 @@ public class ResourceBusinessLogicTest { try{ createdResource= bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId()); assertThat(resource.getUniqueId()).isEqualTo(createdResource.getUniqueId()); - } catch(ComponentException e){ + } catch(ByResponseFormatComponentException e){ assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus()); } } @@ -434,7 +437,7 @@ public class ResourceBusinessLogicTest { validateUserRoles(Role.ADMIN, Role.DESIGNER); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByResponseFormatComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName); } } @@ -445,7 +448,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -458,7 +461,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH); } } @@ -471,7 +474,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -493,7 +496,7 @@ public class ResourceBusinessLogicTest { resourceExccedsDescLimit.setDescription(tooLongResourceDesc); try { bl.createResource(resourceExccedsDescLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH); } } @@ -506,7 +509,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(notEnglish, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -517,7 +520,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -528,7 +531,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -541,7 +544,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -552,7 +555,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -562,7 +565,7 @@ public class ResourceBusinessLogicTest { resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf"); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH); } } @@ -574,7 +577,7 @@ public class ResourceBusinessLogicTest { resourceExist.setTags(null); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS); } } @@ -584,7 +587,7 @@ public class ResourceBusinessLogicTest { resourceExist.setTags(new ArrayList<>()); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS); } } @@ -640,7 +643,7 @@ public class ResourceBusinessLogicTest { resourceExccedsNameLimit.setTags(tagsList); try { bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH); } } @@ -656,7 +659,7 @@ public class ResourceBusinessLogicTest { resourceExccedsNameLimit.setTags(tagsList); try { bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH); } } @@ -669,7 +672,7 @@ public class ResourceBusinessLogicTest { serviceExccedsNameLimit.setTags(tagsList); try { bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME); } } @@ -682,7 +685,7 @@ public class ResourceBusinessLogicTest { serviceExccedsNameLimit.setTags(tagsList); try { bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, new String[]{"Resource", "tag"}); } } @@ -698,7 +701,7 @@ public class ResourceBusinessLogicTest { try { bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -710,7 +713,7 @@ public class ResourceBusinessLogicTest { resourceContactId.setContactId(contactIdFormatWrong); try { bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -720,7 +723,7 @@ public class ResourceBusinessLogicTest { resourceExist.setContactId(""); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -730,7 +733,7 @@ public class ResourceBusinessLogicTest { resourceExist.setContactId(null); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -741,7 +744,7 @@ public class ResourceBusinessLogicTest { resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName); try { bl.createResource(resourceExccedsVendorNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH); } } @@ -752,7 +755,7 @@ public class ResourceBusinessLogicTest { resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber); try { bl.createResource(resourceExccedsVendorModelNumberLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT, "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH); } } @@ -764,7 +767,7 @@ public class ResourceBusinessLogicTest { resource.setVendorName(nameWrongFormat); try { bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME); } } @@ -776,7 +779,7 @@ public class ResourceBusinessLogicTest { resource.setVendorRelease(nameWrongFormat); try { bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_VENDOR_RELEASE); } } @@ -787,7 +790,7 @@ public class ResourceBusinessLogicTest { resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease); try { bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH); } } @@ -797,7 +800,7 @@ public class ResourceBusinessLogicTest { resourceExist.setVendorName(null); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_VENDOR_NAME); } } @@ -807,7 +810,7 @@ public class ResourceBusinessLogicTest { resourceExist.setVendorRelease(null); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_VENDOR_RELEASE); } } @@ -819,7 +822,7 @@ public class ResourceBusinessLogicTest { resourceExist.setCategories(null); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -831,7 +834,7 @@ public class ResourceBusinessLogicTest { resourceExist.addCategory("koko", "koko"); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -855,7 +858,7 @@ public class ResourceBusinessLogicTest { createResourceObjectAfterCreate.setCost(cost); createResourceObjectAfterCreate.setLicenseType(licenseType); assertThat(createResourceObjectAfterCreate).isEqualTo(createdResource); - }catch(ComponentException e){ + }catch(ByResponseFormatComponentException e){ assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus()); } } @@ -867,7 +870,7 @@ public class ResourceBusinessLogicTest { resourceCost.setCost(cost); try { bl.createResource(resourceCost, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_CONTENT); } } @@ -881,7 +884,7 @@ public class ResourceBusinessLogicTest { resourceLicenseType.setLicenseType(licenseType); try { bl.createResource(resourceLicenseType, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_CONTENT); } } @@ -894,7 +897,7 @@ public class ResourceBusinessLogicTest { resourceExist.setDerivedFrom(list); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); } } @@ -904,7 +907,7 @@ public class ResourceBusinessLogicTest { resourceExist.setDerivedFrom(new ArrayList<>()); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); } } @@ -916,14 +919,20 @@ public class ResourceBusinessLogicTest { resourceExist.setDerivedFrom(derivedFrom); try { bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null); - } catch (ComponentException e) { + } catch (ByResponseFormatComponentException e) { + assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND); + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND); } } // Derived from stop - private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) { - ResponseFormat actualResponse = e.getResponseFormat() != null ? - e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + private void assertComponentException(ByResponseFormatComponentException e, ActionStatus expectedStatus, String... variables) { + ResponseFormat actualResponse = e.getResponseFormat(); + assertResponse(actualResponse, expectedStatus, variables); + } + + private void assertComponentException(ByActionStatusComponentException e, ActionStatus expectedStatus, String... variables) { + ResponseFormat actualResponse = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); assertResponse(actualResponse, expectedStatus, variables); } @@ -955,7 +964,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -978,7 +987,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED); } } @@ -998,7 +1007,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName); } } @@ -1028,7 +1037,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH); } } @@ -1049,7 +1058,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -1073,7 +1082,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED); } } @@ -1138,7 +1147,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH); } } @@ -1159,7 +1168,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME); } } @@ -1182,7 +1191,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME); } } @@ -1202,7 +1211,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH); } } @@ -1224,7 +1233,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue()); } } @@ -1247,7 +1256,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED); } } @@ -1269,7 +1278,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); } } @@ -1289,7 +1298,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE); } } @@ -1311,7 +1320,7 @@ public class ResourceBusinessLogicTest { when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse); try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND); } } @@ -1369,7 +1378,7 @@ public class ResourceBusinessLogicTest { try { bl.updateResourceMetadata(resourceId, updatedResource, null, user, false); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java index bd7056ef89..5c539477d5 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogicTest.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.components.impl; @@ -27,6 +29,8 @@ import org.junit.Test; import org.mockito.Mockito; import org.openecomp.sdc.ElementOperationMock; import org.openecomp.sdc.be.auditing.impl.AuditingManager; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic; import org.openecomp.sdc.be.components.validation.UserValidations; @@ -233,9 +237,13 @@ public class ServiceBusinessLogicTest { assertResponse(createResponse.right().value(), expectedStatus, variables); } - private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) { - ResponseFormat actualResponse = e.getResponseFormat() != null ? - e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + private void assertComponentException(ByActionStatusComponentException e, ActionStatus expectedStatus, String... variables) { + ResponseFormat actualResponse = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + assertResponse(actualResponse, expectedStatus, variables); + } + + private void assertComponentException(ByResponseFormatComponentException e, ActionStatus expectedStatus, String... variables) { + ResponseFormat actualResponse = e.getResponseFormat(); assertResponse(actualResponse, expectedStatus, variables); } @@ -295,7 +303,7 @@ public class ServiceBusinessLogicTest { serviceExccedsNameLimit.setName(null); try{ bl.createService(serviceExccedsNameLimit, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue()); } } @@ -307,7 +315,7 @@ public class ServiceBusinessLogicTest { service.setName(nameWrongFormat); try{ bl.createService(service, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue()); } } @@ -317,7 +325,7 @@ public class ServiceBusinessLogicTest { serviceExist.setDescription(""); try{ bl.createService(serviceExist, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue()); } } @@ -327,7 +335,7 @@ public class ServiceBusinessLogicTest { serviceExist.setDescription(null); try{ bl.createService(serviceExist, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue()); } } @@ -347,7 +355,7 @@ public class ServiceBusinessLogicTest { serviceExccedsDescLimit.setDescription(tooLongServiceDesc); try{ bl.createService(serviceExccedsDescLimit, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.SERVICE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH); } } @@ -359,7 +367,7 @@ public class ServiceBusinessLogicTest { notEnglish.setDescription(tooLongServiceDesc); try{ bl.createService(notEnglish, user); - } catch(ComponentException e){ + } catch(ByActionStatusComponentException e){ assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue()); } } @@ -371,7 +379,7 @@ public class ServiceBusinessLogicTest { serviceExist.setIcon(""); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.SERVICE.getValue()); } } @@ -381,7 +389,7 @@ public class ServiceBusinessLogicTest { serviceExist.setIcon(null); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.SERVICE.getValue()); } } @@ -391,7 +399,7 @@ public class ServiceBusinessLogicTest { resourceExist.setIcon("kjk3453^&"); try{ bl.createService(resourceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.SERVICE.getValue()); } } @@ -401,7 +409,7 @@ public class ServiceBusinessLogicTest { resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf"); try{ bl.createService(resourceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, "Service", "25"); } } @@ -414,7 +422,7 @@ public class ServiceBusinessLogicTest { serviceExccedsNameLimit.setTags(tagsList); try{ bl.createService(serviceExccedsNameLimit, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME); } } @@ -427,7 +435,7 @@ public class ServiceBusinessLogicTest { serviceExccedsNameLimit.setTags(tagsList); try{ bl.createService(serviceExccedsNameLimit, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, "Service", "tag"); } } @@ -437,7 +445,7 @@ public class ServiceBusinessLogicTest { serviceExist.setTags(null); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS); } } @@ -447,7 +455,7 @@ public class ServiceBusinessLogicTest { serviceExist.setTags(new ArrayList<>()); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS); } } @@ -461,7 +469,7 @@ public class ServiceBusinessLogicTest { serviceContactId.setContactId(contactIdTooLong); try{ bl.createService(serviceContactId, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue()); } } @@ -473,7 +481,7 @@ public class ServiceBusinessLogicTest { serviceContactId.setContactId(contactIdTooLong); try{ bl.createService(serviceContactId, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue()); } } @@ -483,7 +491,7 @@ public class ServiceBusinessLogicTest { resourceExist.setContactId(null); try{ bl.createService(resourceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.SERVICE.getValue()); } } @@ -495,7 +503,7 @@ public class ServiceBusinessLogicTest { serviceExist.setCategories(null); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue()); } } @@ -573,7 +581,7 @@ public class ServiceBusinessLogicTest { serviceExist.setCategories(categories); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.SERVICE.getValue()); } } @@ -620,7 +628,7 @@ public class ServiceBusinessLogicTest { serviceExist.setProjectCode(null); try{ bl.createService(serviceExist, user); - } catch(ComponentException e) { + } catch(ByActionStatusComponentException e) { assertComponentException(e, ActionStatus.MISSING_PROJECT_CODE); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentExceptionTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentExceptionTest.java index c2ad653353..f41e689bf6 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentExceptionTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/exceptions/ComponentExceptionTest.java @@ -1,47 +1,52 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ + package org.openecomp.sdc.be.components.impl.exceptions; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + import org.junit.Test; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.exception.ResponseFormat; public class ComponentExceptionTest { - private ComponentException createTestSubject() { - return new ComponentException(new ResponseFormat()); - } + private static final String[] PARAMS = {"param1", "param2"}; @Test - public void testConstructor() throws Exception { - new ComponentException(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, "mock", "moc"); + public void hasValidGettersForActionStatus() { + ByActionStatusComponentException componentException = new ByActionStatusComponentException( + ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, PARAMS); + assertEquals(componentException.getActionStatus(), ActionStatus.AAI_ARTIFACT_GENERATION_FAILED); + assertArrayEquals(componentException.getParams(), PARAMS); } - - @Test - public void testGetResponseFormat() throws Exception { - ComponentException testSubject; - ResponseFormat result; - // default test - testSubject = createTestSubject(); - result = testSubject.getResponseFormat(); - } @Test - public void testGetActionStatus() throws Exception { - ComponentException testSubject; - ActionStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getActionStatus(); + public void hasValidGettersForResponseFormat() { + ResponseFormat responseFormat = new ResponseFormat(); + ByResponseFormatComponentException componentException = new ByResponseFormatComponentException(responseFormat); + assertEquals(componentException.getResponseFormat(), responseFormat); } - @Test - public void testGetParams() throws Exception { - ComponentException testSubject; - String[] result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getParams(); - } }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/lock/ComponentLockAspectTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/lock/ComponentLockAspectTest.java new file mode 100644 index 0000000000..e965364057 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/lock/ComponentLockAspectTest.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 Nokia 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.be.components.impl.lock; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.Signature; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InOrder; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.be.components.impl.ComponentLocker; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; + +@RunWith(MockitoJUnitRunner.class) +public class ComponentLockAspectTest { + + private static final String COMPONENT_ID = "componentID"; + + @Mock + private ComponentLocker componentLocker; + @Mock + private ProceedingJoinPoint proceedingJoinPoint; + + @Mock + private Signature signature; + + @Test + public void shouldLockProceedAndUnlockComponent() throws Throwable { + ComponentLockAspect componentLockAspect = new ComponentLockAspect(componentLocker); + Mockito.when(proceedingJoinPoint.getSignature()).thenReturn(signature); + componentLockAspect.lock(proceedingJoinPoint, COMPONENT_ID, ComponentTypeEnum.RESOURCE); + InOrder orderVerifier = Mockito.inOrder(componentLocker, proceedingJoinPoint); + orderVerifier.verify(proceedingJoinPoint).getSignature(); + orderVerifier.verify(componentLocker).lock(COMPONENT_ID, ComponentTypeEnum.RESOURCE.getNodeType()); + orderVerifier.verify(proceedingJoinPoint).proceed(); + orderVerifier.verify(componentLocker).unlock(COMPONENT_ID, ComponentTypeEnum.RESOURCE.getNodeType()); + } +}
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdateHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdateHandlerTest.java index 40dc3dbeb1..82bf7612df 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdateHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/policy/PolicyTargetsUpdateHandlerTest.java @@ -1,3 +1,24 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.impl.policy; import org.junit.Before; @@ -7,7 +28,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.components.utils.PolicyDefinitionBuilder; import org.openecomp.sdc.be.components.utils.ResourceBuilder; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -93,7 +114,7 @@ public class PolicyTargetsUpdateHandlerTest { when(toscaOperationFacade.updatePoliciesOfComponent(eq(CONTAINER_ID), anyList())).thenReturn(StorageOperationStatus.GENERAL_ERROR); try { testInstance.removePoliciesTargets(container, "group2", PolicyTargetType.GROUPS); - } catch (ComponentException e) { + } catch (ByActionStatusComponentException e) { assertThat(e.getActionStatus()).isEqualTo(ActionStatus.GENERAL_ERROR); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidationTest.java index 50f66f6825..dfc1b18837 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidationTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/ServiceDistributionValidationTest.java @@ -1,3 +1,24 @@ +/*- + * ============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========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ package org.openecomp.sdc.be.components.validation; import fj.data.Either; @@ -8,7 +29,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine; import org.openecomp.sdc.be.components.impl.ActivationRequestInformation; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -73,10 +94,10 @@ public class ServiceDistributionValidationTest { @Test public void validateActivateServiceRequest_userNotExist() { - when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(false))).thenThrow(new ComponentException(errResponse)); + when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(false))).thenThrow(new ByResponseFormatComponentException(errResponse)); try { testInstance.validateActivateServiceRequest(SERVICE_ID, ENV_ID, user, new ServiceDistributionReqInfo("distributionData")); - } catch(ComponentException e){ + } catch(ByResponseFormatComponentException e){ assertEquals(errResponse, e.getResponseFormat()); } verifyZeroInteractions(toscaOperationFacade, operationalEnvironmentDao, componentsUtils); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java index 7d949a1959..5a2b598ed8 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/ExternalRefServletTest.java @@ -16,11 +16,12 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.externalapi.servlet; -import com.google.common.collect.ImmutableListMultimap; import fj.data.Either; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; @@ -30,7 +31,7 @@ import org.junit.Test; import org.mockito.Mockito; import org.openecomp.sdc.be.components.impl.ComponentLocker; import org.openecomp.sdc.be.components.impl.ExternalRefsBusinessLogic; -import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.path.utils.GraphTestUtils; import org.openecomp.sdc.be.components.validation.AccessValidations; import org.openecomp.sdc.be.config.ConfigurationManager; @@ -40,10 +41,6 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.impl.HealingPipelineDao; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.HealingTitanDao; -import org.openecomp.sdc.be.dao.jsongraph.TitanDao; -import org.openecomp.sdc.be.dao.jsongraph.heal.Heal; -import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersionBuilder; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.titan.HealingTitanGenericDao; import org.openecomp.sdc.be.dao.titan.TitanGenericDao; import org.openecomp.sdc.be.dao.titan.TitanGraphClient; @@ -70,7 +67,6 @@ import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.common.impl.ExternalConfiguration; import org.openecomp.sdc.common.impl.FSConfigurationSource; import org.openecomp.sdc.exception.ResponseFormat; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -325,9 +321,8 @@ public class ExternalRefServletTest extends JerseyTest { when(componentUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)).thenReturn(responseFormat); when(responseFormat.getStatus()).thenReturn(HttpStatus.UNAUTHORIZED.value()); - ComponentException ce = Mockito.mock(ComponentException.class); + ByResponseFormatComponentException ce = Mockito.mock(ByResponseFormatComponentException.class); String[] params = {otherDesignerUser.getUserId()}; - when(ce.getParams()).thenReturn(params); when(ce.getResponseFormat()).thenReturn(responseFormat); doThrow(ce).when(accessValidationsMock) .validateUserCanWorkOnComponent(any(), eq(otherDesignerUser.getUserId()), any()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java index aea9908650..f315ddf9d0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ArchiveEndpointTest.java @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ */ package org.openecomp.sdc.be.servlets; @@ -45,6 +47,7 @@ import org.glassfish.jersey.test.JerseyTest; import org.junit.BeforeClass; import org.junit.Test; import org.openecomp.sdc.be.components.impl.ArchiveBusinessLogic; +import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.path.utils.GraphTestUtils; import org.openecomp.sdc.be.components.validation.AccessValidations; @@ -299,7 +302,7 @@ public class ArchiveEndpointTest extends JerseyTest { when(componentUtils.getResponseFormat(eq(ActionStatus.INVALID_SERVICE_STATE), any())).thenReturn(invalidServiceStateResponseFormat); when(responseFormat.getStatus()).thenReturn(HttpStatus.UNAUTHORIZED.value()); - ComponentException ce = new ComponentException(responseFormat); + ComponentException ce = new ByResponseFormatComponentException(responseFormat); doThrow(ce).when(accessValidationsMock).userIsAdminOrDesigner(eq(otherUser.getUserId()), any()); //Needed for error configuration |