From 335d13c0e57ae61148b7a0871c5c9e46f768cd93 Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Sun, 13 Aug 2017 16:51:44 +0300 Subject: [SDC-235] rebase code Change-Id: Iea503188e521fa3846f580ced7c1c4fce303abe5 Signed-off-by: Michael Lando --- .../be/components/impl/ElementBusinessLogic.java | 8 ++++---- .../be/components/impl/ResourceBusinessLogic.java | 2 +- .../lifecycle/LifecycleBusinessLogic.java | 21 ++++++++++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) (limited to 'catalog-be/src/main/java') 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 7214d011e0..2c051b2b94 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 @@ -1196,7 +1196,7 @@ public class ElementBusinessLogic extends BaseBusinessLogic { if(subcategories != null){ return fetchByMainCategory(subcategories.left().value(), inTransaction, resourceType); } - return fetchByResourceType(filters.get(FilterKeyEnum.RESOURCE_TYPE), inTransaction); + return fetchComponentMetaDataByResourceType(filters.get(FilterKeyEnum.RESOURCE_TYPE), inTransaction); } private Either>, StorageOperationStatus> getAllSubCategories(String categoryName) { @@ -1320,14 +1320,14 @@ public class ElementBusinessLogic extends BaseBusinessLogic { return Either.left(components); } - private Either, StorageOperationStatus> fetchByResourceType(String resourceType, boolean inTransaction) { + private Either, StorageOperationStatus> fetchComponentMetaDataByResourceType(String resourceType, boolean inTransaction) { List components = null; StorageOperationStatus status; Wrapper statusWrapper = new Wrapper<>(); Either, StorageOperationStatus> result; try { - - Either, StorageOperationStatus> getResources = toscaOperationFacade.fetchByResourceType(resourceType); //titanGenericDao.getByCriteria(nodeType, props, clazz); + ComponentParametersView fetchUsersAndCategoriesFilter = new ComponentParametersView(Arrays.asList(ComponentFieldsEnum.USERS.getValue(), ComponentFieldsEnum.CATEGORIES.getValue())); + Either, StorageOperationStatus> getResources = toscaOperationFacade.fetchMetaDataByResourceType(resourceType, fetchUsersAndCategoriesFilter); if (getResources.isRight()) { status = getResources.right().value(); if(status != StorageOperationStatus.NOT_FOUND){ 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 82382f961d..8fd28e1224 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 @@ -4858,7 +4858,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Either result = null; try { - if(resource.getLifecycleState() != LifecycleStateEnum.CERTIFIED && forceCertificationAllowed){ + if(resource.getLifecycleState() != LifecycleStateEnum.CERTIFIED && forceCertificationAllowed && lifecycleBusinessLogic.isFirstCertification(resource.getVersion())){ result = nodeForceCertification(resource, user, lifecycleChangeInfo, inTransaction, needLock); if(result.isRight()){ return result; 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 dfe04f919d..f0b369072e 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 @@ -464,7 +464,18 @@ public class LifecycleBusinessLogic { return Either.left(latestComponent); } - +/** + * Performs Force certification. + * Note that a Force certification is allowed for the first certification only, + * as only a state and a version is promoted due a Force certification, + * skipping other actions required if a previous certified version exists. + * @param resource + * @param user + * @param lifecycleChangeInfo + * @param inTransaction + * @param needLock + * @return + */ public Either forceResourceCertification(Resource resource, User user, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) { Either result = null; Either certifyResourceRes = null; @@ -472,6 +483,10 @@ public class LifecycleBusinessLogic { log.debug("Force certification is not allowed for the action {}. ", lifecycleChangeInfo.getAction().name()); result = Either.right(componentUtils.getResponseFormat(ActionStatus.NOT_ALLOWED)); } + if(!isFirstCertification(resource.getVersion())){ + log.debug("Failed to perform a force certification of resource{}. Force certification is allowed for the first certification only. ", resource.getName()); + result = Either.right(componentUtils.getResponseFormat(ActionStatus.NOT_ALLOWED)); + } // lock resource if(result == null && !inTransaction && needLock){ log.info("lock component {}", resource.getUniqueId()); @@ -512,4 +527,8 @@ public class LifecycleBusinessLogic { return result; } + public boolean isFirstCertification(String previousVersion) { + return previousVersion.split("\\.")[0].equals("0"); + } + } -- cgit 1.2.3-korg