From 38b4e81eab76202bcafdec7e0b6374679090ce7e Mon Sep 17 00:00:00 2001 From: sheetalm Date: Mon, 19 Feb 2018 11:05:17 +0530 Subject: Onboarding foundation changes - UniqueValueUtil Refactored UniqueValueUtil Change-Id: I7523ad501de9a49c5fbbb59f33c07a40c55eda2f Issue-ID: SDC-1047 Signed-off-by: sheetalm --- .../rest/services/VendorLicenseModelsImpl.java | 9 ++-- .../rest/services/VendorSoftwareProductsImpl.java | 9 ++-- .../sdc/action/impl/ActionManagerImpl.java | 11 +++-- .../impl/VendorLicenseManagerFactoryImpl.java | 4 +- .../impl/VendorLicenseManagerImpl.java | 25 ++++++----- .../org/openecomp/sdc/vendorlicense/LimitTest.java | 35 ++++++++-------- .../vendorlicense/impl/EntitlementPoolTest.java | 49 ++++++++++++---------- .../sdc/vendorlicense/impl/FeatureGroupTest.java | 33 ++++++++------- .../vendorlicense/impl/LicenseAgreementTest.java | 43 +++++++++---------- .../vendorlicense/impl/LicenseKeyGroupTest.java | 45 ++++++++++---------- .../vendorlicense/impl/VendorLicenseModelTest.java | 16 ++++--- .../impl/ComputeManagerImpl.java | 19 ++++++--- .../impl/ProcessManagerFactoryImpl.java | 4 +- .../impl/ProcessManagerImpl.java | 15 ++++--- .../impl/VendorSoftwareProductManagerImpl.java | 8 +++- .../impl/VspManagerFactoryImpl.java | 4 +- .../impl/orchestration/OrchestrationUtil.java | 5 ++- .../org/openecomp/core/util/UniqueValueUtil.java | 38 ++++++++--------- .../facade/impl/VendorLicenseFacadeImpl.java | 19 +++++---- .../impl/VersionableEntityDaoCassandraImpl.java | 11 ++++- .../dao/impl/VersionableEntityDaoFactoryImpl.java | 4 +- 21 files changed, 238 insertions(+), 168 deletions(-) diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java index 812e3d94f0..b9c2ea3bb8 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java @@ -17,6 +17,7 @@ package org.openecomp.sdcrests.vendorlicense.rest.services; +import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.sdc.activitylog.ActivityLogManager; import org.openecomp.sdc.activitylog.ActivityLogManagerFactory; @@ -101,6 +102,8 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { VendorLicenseManagerFactory.getInstance().createInterface(); private ActivityLogManager activityLogManager = ActivityLogManagerFactory.getInstance().createInterface(); + private UniqueValueUtil uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory.getInstance() + .createInterface()); @Override public Response listLicenseModels(String versionStatus, String user) { @@ -135,10 +138,10 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { item.setName(request.getVendorName()); item.setDescription(request.getDescription()); - UniqueValueUtil + uniqueValueUtil .validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName()); item = asdcItemManager.create(item); - UniqueValueUtil + uniqueValueUtil .createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName()); Version version = versioningManager.create(item.getId(), new Version(), null); @@ -214,7 +217,7 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { if (Objects.isNull(certifiedVersionsCounter) || certifiedVersionsCounter == 0) { asdcItemManager.delete(vlm); permissionsManager.deleteItemPermissions(vlmId); - UniqueValueUtil + uniqueValueUtil .deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, vlm.getName()); notifyUsers(vlmId, vlm.getName(), null, "VLM was deleted", user, NotificationEventTypes.DELETE); diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java index 185bb93983..480b83bf8f 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java @@ -18,6 +18,7 @@ package org.openecomp.sdcrests.vsp.rest.services; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.sdc.activitylog.ActivityLogManager; import org.openecomp.sdc.activitylog.ActivityLogManagerFactory; @@ -136,6 +137,8 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { ActivityLogManagerFactory.getInstance().createInterface(); private final NotificationPropagationManager notifier = NotificationPropagationManagerFactory.getInstance().createInterface(); + private final UniqueValueUtil uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory + .getInstance().createInterface()); @Override public Response createVsp(VspRequestDto vspRequestDto, String user) { @@ -168,9 +171,9 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { item.setOwner(user); item.addProperty(VspItemProperty.ONBOARDING_METHOD, onboardingMethod.name()); - UniqueValueUtil.validateUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName()); + uniqueValueUtil.validateUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName()); item = asdcItemManager.create(item); - UniqueValueUtil.createUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName()); + uniqueValueUtil.createUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName()); Version version = versioningManager.create(item.getId(), new Version(), null); @@ -296,7 +299,7 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts { if (Objects.isNull(certifiedVersionsCounter) || certifiedVersionsCounter == 0) { asdcItemManager.delete(vsp); permissionsManager.deleteItemPermissions(vspId); - UniqueValueUtil.deleteUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, vsp.getName()); + uniqueValueUtil.deleteUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, vsp.getName()); notifyUsers(vspId, vsp.getName(), null, "VSP was deleted", user, NotificationEventTypes.DELETE); diff --git a/openecomp-be/backend/openecomp-sdc-action-manager/src/main/java/org/openecomp/sdc/action/impl/ActionManagerImpl.java b/openecomp-be/backend/openecomp-sdc-action-manager/src/main/java/org/openecomp/sdc/action/impl/ActionManagerImpl.java index 1189a9c00a..696c63e498 100644 --- a/openecomp-be/backend/openecomp-sdc-action-manager/src/main/java/org/openecomp/sdc/action/impl/ActionManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-action-manager/src/main/java/org/openecomp/sdc/action/impl/ActionManagerImpl.java @@ -74,6 +74,7 @@ import java.util.Map; import java.util.UUID; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; +import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.core.utilities.json.JsonUtil; @@ -282,9 +283,11 @@ public class ActionManagerImpl implements ActionManager { */ @Override public Action createAction(Action action, String user) throws ActionException { + UniqueValueUtil uniqueValueUtil = + new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); try { actionLogPreProcessor(ActionSubOperation.VALIDATE_ACTION_UNIQUE_NAME, TARGET_ENTITY_API); - UniqueValueUtil + uniqueValueUtil .validateUniqueValue(ActionConstants.UniqueValues.ACTION_NAME, action.getName()); actionLogPostProcessor(StatusCode.COMPLETE); } catch (CoreException exception) { @@ -314,7 +317,7 @@ public class ActionManagerImpl implements ActionManager { action = actionDao.createAction(action); actionLogPreProcessor(ActionSubOperation.CREATE_ACTION_UNIQUE_VALUE, TARGET_ENTITY_API); - UniqueValueUtil.createUniqueValue(ActionConstants.UniqueValues.ACTION_NAME, action.getName()); + uniqueValueUtil.createUniqueValue(ActionConstants.UniqueValues.ACTION_NAME, action.getName()); actionLogPostProcessor(StatusCode.COMPLETE); log.metrics(""); @@ -456,7 +459,9 @@ public class ActionManagerImpl implements ActionManager { if (version.equals(new Version(0, 0))) { actionLogPreProcessor(ActionSubOperation.DELETE_UNIQUEVALUE, TARGET_ENTITY_API); - UniqueValueUtil + UniqueValueUtil uniqueValueUtil = + new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); + uniqueValueUtil .deleteUniqueValue(ActionConstants.UniqueValues.ACTION_NAME, action.getName()); actionLogPostProcessor(StatusCode.COMPLETE); log.metrics(""); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerFactoryImpl.java index 472473fdb0..4a07aee7c6 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerFactoryImpl.java @@ -1,5 +1,6 @@ package org.openecomp.sdc.vendorlicense.impl; +import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.sdc.vendorlicense.VendorLicenseManager; import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory; import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory; @@ -22,7 +23,8 @@ public class VendorLicenseManagerFactoryImpl extends VendorLicenseManagerFactory FeatureGroupDaoFactory.getInstance().createInterface(), EntitlementPoolDaoFactory.getInstance().createInterface(), LicenseKeyGroupDaoFactory.getInstance().createInterface(), - LimitDaoFactory.getInstance().createInterface()); + LimitDaoFactory.getInstance().createInterface(), + UniqueValueDaoFactory.getInstance().createInterface()); @Override public VendorLicenseManager createInterface() { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java index 8135efa89a..50425c82c4 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java @@ -17,6 +17,7 @@ package org.openecomp.sdc.vendorlicense.impl; import org.apache.commons.collections.CollectionUtils; +import org.openecomp.core.dao.UniqueValueDao; import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.sdc.common.errors.CoreException; @@ -52,13 +53,15 @@ import java.util.Optional; import java.util.Set; public class VendorLicenseManagerImpl implements VendorLicenseManager { - private VendorLicenseFacade vendorLicenseFacade; - private VendorLicenseModelDao vendorLicenseModelDao; - private LicenseAgreementDao licenseAgreementDao; - private FeatureGroupDao featureGroupDao; - private EntitlementPoolDao entitlementPoolDao; - private LicenseKeyGroupDao licenseKeyGroupDao; - private LimitDao limitDao; + private final UniqueValueUtil uniqueValueUtil; + private final VendorLicenseFacade vendorLicenseFacade; + private final VendorLicenseModelDao vendorLicenseModelDao; + private final LicenseAgreementDao licenseAgreementDao; + private final FeatureGroupDao featureGroupDao; + private final EntitlementPoolDao entitlementPoolDao; + private final LicenseKeyGroupDao licenseKeyGroupDao; + private final LimitDao limitDao; + private static final String EP_POOL_START_TIME = "T00:00:00Z"; private static final String EP_POOL_EXPIRY_TIME = "T23:59:59Z"; private static final DateTimeFormatter FORMATTER @@ -69,7 +72,8 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { FeatureGroupDao featureGroupDao, EntitlementPoolDao entitlementPoolDao, LicenseKeyGroupDao licenseKeyGroupDao, - LimitDao limitDao) { + LimitDao limitDao, + UniqueValueDao uniqueValueDao) { this.vendorLicenseFacade = vendorLicenseFacade; this.vendorLicenseModelDao = vendorLicenseModelDao; this.licenseAgreementDao = licenseAgreementDao; @@ -77,6 +81,7 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { this.entitlementPoolDao = entitlementPoolDao; this.licenseKeyGroupDao = licenseKeyGroupDao; this.limitDao = limitDao; + this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao); } @@ -690,11 +695,11 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { protected void updateUniqueName(String uniqueValueType, String oldName, String newName, String... context) { - UniqueValueUtil + uniqueValueUtil .updateUniqueValue(uniqueValueType, oldName, newName, context); } protected void deleteUniqueName(String uniqueValueType, String... uniqueCombination) { - UniqueValueUtil.deleteUniqueValue(uniqueValueType, uniqueCombination); + uniqueValueUtil.deleteUniqueValue(uniqueValueType, uniqueCombination); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LimitTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LimitTest.java index 0197dd9d28..e86f71e903 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LimitTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/LimitTest.java @@ -1,25 +1,29 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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 + * 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.vendorlicense; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -36,18 +40,10 @@ import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; import org.openecomp.sdc.versioning.types.VersionInfo; import org.testng.Assert; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - public class LimitTest { private final String USER1 = "limitTestUser1"; @@ -90,6 +86,11 @@ public class LimitTest { MockitoAnnotations.initMocks(this); } + @AfterMethod + public void tearDown(){ + vendorLicenseManagerImpl = null; + } + @Test public void testUpdateLimit() { Version version = new Version(); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/EntitlementPoolTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/EntitlementPoolTest.java index 57d22544ad..38f0ebff86 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/EntitlementPoolTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/EntitlementPoolTest.java @@ -1,26 +1,34 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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 - * + * + * 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.vendorlicense.impl; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -39,22 +47,10 @@ import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - public class EntitlementPoolTest { //JUnit Test Cases using Mockito @@ -110,6 +106,12 @@ public class EntitlementPoolTest { MockitoAnnotations.initMocks(this); } + + @AfterMethod + public void tearDown(){ + vendorLicenseManagerImpl = null; + } + @Test public void createTest() { Set opScopeChoices; @@ -131,6 +133,7 @@ public class EntitlementPoolTest { } + @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Vendor " + "license model with id vlm1_id has invalid date range.") public void createWithInvalidStartExpiryDateTest() { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java index d71bec6055..f9e8570d30 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/FeatureGroupTest.java @@ -1,11 +1,11 @@ /* - * Copyright © 2016-2017 European Support Limited + * Copyright © 2016-2018 European Support Limited * * 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 + * 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, @@ -16,6 +16,16 @@ package org.openecomp.sdc.vendorlicense.impl; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -34,21 +44,10 @@ import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - public class FeatureGroupTest { //JUnit Test Cases using Mockito private static final Version VERSION01 = new Version(0, 1); @@ -94,6 +93,12 @@ public class FeatureGroupTest { @Spy private VendorLicenseManagerImpl vendorLicenseManagerImpl; + + @AfterMethod + public void tearDown(){ + vendorLicenseManagerImpl = null; + } + public FeatureGroupEntity updateFeatureGroup(String vlmId, Version version, String id, String name, String desc, String partNumber, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseAgreementTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseAgreementTest.java index 91435e85fd..0584ac5e99 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseAgreementTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseAgreementTest.java @@ -1,25 +1,31 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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 - * + * + * 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.vendorlicense.impl; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; @@ -42,20 +48,10 @@ import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - public class LicenseAgreementTest { private static final String USER1 = "TestUser1"; @@ -102,6 +98,11 @@ public class LicenseAgreementTest { MockitoAnnotations.initMocks(this); } + @AfterMethod + public void tearDown(){ + vendorLicenseManager = null; + } + public static LicenseAgreementEntity createLicenseAgreement(String vlmId, Version version, String id, String name, String desc, String requirementsAndConstrains, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseKeyGroupTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseKeyGroupTest.java index dc376ee5b6..89d836e976 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseKeyGroupTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/LicenseKeyGroupTest.java @@ -1,26 +1,33 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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 - * + * + * 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.vendorlicense.impl; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -36,21 +43,10 @@ import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - public class LicenseKeyGroupTest { //JUnit Test Cases using Mockito @@ -83,6 +79,11 @@ public class LicenseKeyGroupTest { MockitoAnnotations.initMocks(this); } + @AfterMethod + public void tearDown(){ + vendorLicenseManagerImpl = null; + } + private LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyType type, Set operationalScopeChoices, String operationalScopeOther) { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java index d1df147a60..8ef9c5aec6 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/test/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseModelTest.java @@ -1,5 +1,10 @@ package org.openecomp.sdc.vendorlicense.impl; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; @@ -18,14 +23,10 @@ import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; +import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - /** * Created by ayalaben on 7/19/2017 @@ -75,6 +76,11 @@ public class VendorLicenseModelTest { MockitoAnnotations.initMocks(this); } + @AfterMethod + public void tearDown(){ + vendorLicenseManager = null; + } + @Test public void testValidate() { // TODO: 8/13/2017 diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java index a074557d13..6e462dc370 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ComputeManagerImpl.java @@ -18,6 +18,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.core.utilities.json.JsonSchemaDataGenerator; import org.openecomp.sdc.common.errors.CoreException; @@ -300,30 +301,38 @@ public class ComputeManagerImpl implements ComputeManager { protected void validateUniqueName(String vspId, Version version, String componentId, String name) { - UniqueValueUtil.validateUniqueValue(VendorSoftwareProductConstants.UniqueValues.COMPUTE_NAME, + UniqueValueUtil uniqueValueUtil = + new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); + uniqueValueUtil.validateUniqueValue(VendorSoftwareProductConstants.UniqueValues.COMPUTE_NAME, vspId, version.getId(), componentId, name); } protected void createUniqueName(String vspId, Version version, String componentId, String name) { - UniqueValueUtil + UniqueValueUtil uniqueValueUtil = + new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); + uniqueValueUtil .createUniqueValue(VendorSoftwareProductConstants.UniqueValues.COMPUTE_NAME, vspId, version.getId(), componentId, name); } protected void updateUniqueName(String vspId, Version version, String componentId, String oldName, String newName) { - UniqueValueUtil + UniqueValueUtil uniqueValueUtil = + new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); + uniqueValueUtil .updateUniqueValue(VendorSoftwareProductConstants.UniqueValues.COMPUTE_NAME, oldName, newName, vspId, version.getId(), componentId); } protected void deleteUniqueValue(String vspId, Version version, String componentId, String name) { + UniqueValueUtil uniqueValueUtil = + new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); if (componentId == null) { - UniqueValueUtil + uniqueValueUtil .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.COMPUTE_NAME, vspId, version.getId(), name); } - UniqueValueUtil + uniqueValueUtil .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.COMPUTE_NAME, vspId, version.getId(), componentId, name); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerFactoryImpl.java index 7a4e4876d2..b1b8ff4d42 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerFactoryImpl.java @@ -20,13 +20,15 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.sdc.vendorsoftwareproduct.ProcessManager; import org.openecomp.sdc.vendorsoftwareproduct.ProcessManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory; public class ProcessManagerFactoryImpl extends ProcessManagerFactory { private static final ProcessManager INSTANCE = - new ProcessManagerImpl(ProcessDaoFactory.getInstance().createInterface()); + new ProcessManagerImpl(ProcessDaoFactory.getInstance().createInterface(), + UniqueValueDaoFactory.getInstance().createInterface()); @Override public ProcessManager createInterface() { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImpl.java index 1bdb9b2a28..855007dfd9 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ProcessManagerImpl.java @@ -16,6 +16,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.openecomp.core.dao.UniqueValueDao; import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.common.errors.CoreException; @@ -42,9 +43,11 @@ public class ProcessManagerImpl implements ProcessManager { private static final String PROCESS_ARTIFACT_NOT_EXIST_MSG = "Process artifact for process with Id %s does not exist for %s with Id %s and version %s"; private final ProcessDao processDao; + private final UniqueValueUtil uniqueValueUtil; - public ProcessManagerImpl(ProcessDao processDao) { + public ProcessManagerImpl(ProcessDao processDao, UniqueValueDao uniqueValueDao) { this.processDao = processDao; + this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao); } @Override @@ -186,20 +189,20 @@ public class ProcessManagerImpl implements ProcessManager { protected void validateUniqueName(String vspId, Version version, String componentId, String processName) { - UniqueValueUtil.validateUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME, + uniqueValueUtil.validateUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME, vspId, version.getId(), componentId, processName); } protected void createUniqueName(String vspId, Version version, String componentId, String processName) { - UniqueValueUtil + uniqueValueUtil .createUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME, vspId, version.getId(), componentId, processName); } protected void updateUniqueName(String vspId, Version version, String componentId, String oldProcessName, String newProcessName) { - UniqueValueUtil + uniqueValueUtil .updateUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME, oldProcessName, newProcessName, vspId, version.getId(), componentId); } @@ -207,11 +210,11 @@ public class ProcessManagerImpl implements ProcessManager { protected void deleteUniqueValue(String vspId, Version version, String componentId, String processName) { if (componentId == null) { - UniqueValueUtil + uniqueValueUtil .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME, vspId, version.getId(), processName); } - UniqueValueUtil + uniqueValueUtil .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME, vspId, version.getId(), componentId, processName); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java index 8961df70ea..ad5717af25 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java @@ -18,6 +18,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.dao.UniqueValueDao; import org.openecomp.core.enrichment.api.EnrichmentManager; import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory; import org.openecomp.core.model.dao.EnrichedServiceModelDao; @@ -140,6 +141,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private final ComputeDao computeDao; private final ImageDao imageDao; private final ManualVspToscaManager manualVspToscaManager; + private final UniqueValueUtil uniqueValueUtil; public VendorSoftwareProductManagerImpl( OrchestrationTemplateDao orchestrationTemplateDataDao, @@ -157,7 +159,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa NicDao nicDao, ComputeDao computeDao, ImageDao imageDao, - ManualVspToscaManager manualVspToscaManager) { + ManualVspToscaManager manualVspToscaManager, + UniqueValueDao uniqueValueDao) { this.orchestrationTemplateDao = orchestrationTemplateDataDao; this.orchestrationTemplateCandidateManager = orchestrationTemplateCandidateManager; this.vspInfoDao = vspInfoDao; @@ -174,6 +177,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa this.computeDao = computeDao; this.imageDao = imageDao; this.manualVspToscaManager = manualVspToscaManager; + this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao); registerToVersioning(); } @@ -812,7 +816,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } void updateUniqueName(String oldVspName, String newVspName) { - UniqueValueUtil.updateUniqueValue( + uniqueValueUtil.updateUniqueValue( VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, oldVspName, newVspName); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java index 4749e7f2dd..177af3a8bc 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VspManagerFactoryImpl.java @@ -16,6 +16,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory; import org.openecomp.core.model.dao.ServiceModelDaoFactory; import org.openecomp.sdc.vendorlicense.VendorLicenseArtifactServiceFactory; @@ -52,7 +53,8 @@ public class VspManagerFactoryImpl extends VspManagerFactory { NicDaoFactory.getInstance().createInterface(), ComputeDaoFactory.getInstance().createInterface(), ImageDaoFactory.getInstance().createInterface(), - new ManualVspToscaManagerImpl()); + new ManualVspToscaManagerImpl(), + UniqueValueDaoFactory.getInstance().createInterface()); @Override public VendorSoftwareProductManager createInterface() { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java index fae8f8b697..71890bb9e8 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java @@ -20,6 +20,7 @@ import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConst import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.dao.ServiceModelDaoFactory; import org.openecomp.core.util.UniqueValueUtil; @@ -282,7 +283,9 @@ public class OrchestrationUtil { Collection processList = processes.get(componentName); processList.forEach(process -> { process.setComponentId(componentId); - UniqueValueUtil.createUniqueValue(PROCESS_NAME, vspId, version.getId(), componentId, + UniqueValueUtil uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory.getInstance() + .createInterface()); + uniqueValueUtil.createUniqueValue(PROCESS_NAME, vspId, version.getId(), componentId, process.getName()); processDao.create(process); if (processArtifact.containsKey(process.getId())) { diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java index 4341899d8a..36b76a0772 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java @@ -1,27 +1,22 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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 - * + * + * 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.core.util; import org.openecomp.core.dao.UniqueValueDao; -import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.dao.types.UniqueValueEntity; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.sdc.common.errors.CoreException; @@ -34,15 +29,20 @@ public class UniqueValueUtil { private static final String UNIQUE_VALUE_VIOLATION = "UNIQUE_VALUE_VIOLATION"; private static final String UNIQUE_VALUE_VIOLATION_MSG = "%s with the value '%s' already exists."; - private static final UniqueValueDao uniqueValueDao = - UniqueValueDaoFactory.getInstance().createInterface(); + private final UniqueValueDao uniqueValueDao; + + + public UniqueValueUtil(UniqueValueDao uniqueValueDao) { + this.uniqueValueDao = uniqueValueDao; + } + /** * Create unique value. * * @param type the type * @param uniqueCombination the unique combination */ - public static void createUniqueValue(String type, String... uniqueCombination) { + public void createUniqueValue(String type, String... uniqueCombination) { Optional value = formatValue(uniqueCombination); if (!value.isPresent()) { return; @@ -57,7 +57,7 @@ public class UniqueValueUtil { * @param type the type * @param uniqueCombination the unique combination */ - public static void deleteUniqueValue(String type, String... uniqueCombination) { + public void deleteUniqueValue(String type, String... uniqueCombination) { Optional value = formatValue(uniqueCombination); if (!value.isPresent()) { return; @@ -73,8 +73,8 @@ public class UniqueValueUtil { * @param newValue the new value * @param uniqueContext the unique context */ - public static void updateUniqueValue(String type, String oldValue, String newValue, - String... uniqueContext) { + public void updateUniqueValue(String type, String oldValue, String newValue, + String... uniqueContext) { if (newValue == null || oldValue == null || !newValue.equalsIgnoreCase(oldValue)) { createUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{newValue})); deleteUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{oldValue})); @@ -87,7 +87,7 @@ public class UniqueValueUtil { * @param type the type * @param uniqueCombination the unique combination */ - public static void validateUniqueValue(String type, String... uniqueCombination) { + public void validateUniqueValue(String type, String... uniqueCombination) { Optional value = formatValue(uniqueCombination); if (!value.isPresent()) { return; @@ -95,7 +95,7 @@ public class UniqueValueUtil { validateUniqueValue(type, value.get(), uniqueCombination); } - private static void validateUniqueValue(String type, String value, String... uniqueCombination) { + private void validateUniqueValue(String type, String value, String... uniqueCombination) { if (uniqueValueDao.get(new UniqueValueEntity(type, value)) != null) { throw new CoreException(new ErrorCode.ErrorCodeBuilder() .withCategory(ErrorCategory.APPLICATION) diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java index b02f6a527e..633de716b7 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/facade/impl/VendorLicenseFacadeImpl.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.vendorlicense.facade.impl; import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.sdc.common.errors.CoreException; @@ -75,6 +76,8 @@ public class VendorLicenseFacadeImpl implements VendorLicenseFacade { private static final LicenseKeyGroupDao licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface(); private static final LimitDao limitDao = LimitDaoFactory.getInstance().createInterface(); + private static final UniqueValueUtil uniqueValueUtil = new UniqueValueUtil + (UniqueValueDaoFactory.getInstance().createInterface()); /** * Instantiates a new Vendor license facade. */ @@ -139,7 +142,7 @@ public class VendorLicenseFacadeImpl implements VendorLicenseFacade { @Override public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) { entitlementPool.setVersionUuId(CommonMethods.nextUuId()); - UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME, + uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME, entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId(), entitlementPool.getName()); entitlementPoolDao.create(entitlementPool); @@ -154,7 +157,7 @@ public class VendorLicenseFacadeImpl implements VendorLicenseFacade { if (retrieved.equals(entitlementPool)) { return; } - UniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME, + uniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME, retrieved.getName(), entitlementPool.getName(), entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().getId()); entitlementPool.setVersionUuId(CommonMethods.nextUuId()); @@ -180,7 +183,7 @@ public class VendorLicenseFacadeImpl implements VendorLicenseFacade { licenseKeyGroup.setVersionUuId((CommonMethods.nextUuId())); VersioningUtil .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE); - UniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, + uniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, retrieved.getName(), licenseKeyGroup.getName(), licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId()); licenseKeyGroupDao.update(licenseKeyGroup); @@ -189,7 +192,7 @@ public class VendorLicenseFacadeImpl implements VendorLicenseFacade { @Override public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) { licenseKeyGroup.setVersionUuId(CommonMethods.nextUuId()); - UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, + uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().getId(), licenseKeyGroup.getName()); licenseKeyGroupDao.create(licenseKeyGroup); @@ -214,12 +217,12 @@ public class VendorLicenseFacadeImpl implements VendorLicenseFacade { null), featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE); - UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, + uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId(), licenseAgreement.getName()); licenseAgreementDao.create(licenseAgreement); - UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, + uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().getId(), licenseAgreement.getName()); if (licenseAgreement.getFeatureGroupIds() != null) { @@ -243,12 +246,12 @@ public class VendorLicenseFacadeImpl implements VendorLicenseFacade { new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(), null), entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE); - UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, + uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId(), featureGroup.getName()); featureGroupDao.create(featureGroup); - UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, + uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().getId(), featureGroup.getName()); diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java index 0845beaa2f..0a14c7ae19 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java @@ -24,6 +24,7 @@ import com.datastax.driver.core.ColumnDefinitions; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; import com.datastax.driver.mapping.UDTMapper; +import org.openecomp.core.dao.UniqueValueDao; import org.openecomp.core.nosqldb.api.NoSqlDb; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.core.util.UniqueValueUtil; @@ -44,12 +45,18 @@ import java.util.stream.Collectors; class VersionableEntityDaoCassandraImpl implements VersionableEntityDao { + private final UniqueValueUtil uniqueValueUtil; private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); private static Logger Logger = (Logger) LoggerFactory.getLogger(VersionableEntityDaoCassandraImpl.class); private static UDTMapper versionMapper = noSqlDb.getMappingManager().udtMapper(Version.class); + public VersionableEntityDaoCassandraImpl( + UniqueValueDao uniqueValueDao) { + this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao); + } + private static String commaSeparatedQuestionMarks(int size) { StringBuilder sb = new StringBuilder(size * 2 - 1); for (int i = 0; i < size; i++) { @@ -128,7 +135,7 @@ class VersionableEntityDaoCassandraImpl implements VersionableEntityDao { for (UniqueValueMetadata uniqueMetadata : metadata) { List uniqueValueCombination = uniqueMetadata.getUniqueConstraintIdentifiers().stream() .map(colName -> (String) columnNameToValue.get(colName)).collect(Collectors.toList()); - UniqueValueUtil.createUniqueValue(uniqueMetadata.getType(), + uniqueValueUtil.createUniqueValue(uniqueMetadata.getType(), uniqueValueCombination.toArray(new String[uniqueValueCombination.size()])); } } @@ -138,7 +145,7 @@ class VersionableEntityDaoCassandraImpl implements VersionableEntityDao { for (UniqueValueMetadata uniqueMetadata : metadata) { List uniqueValueCombination = uniqueMetadata.getUniqueConstraintIdentifiers().stream() .map(colName -> (String) columnNameToValue.get(colName)).collect(Collectors.toList()); - UniqueValueUtil.deleteUniqueValue(uniqueMetadata.getType(), + uniqueValueUtil.deleteUniqueValue(uniqueMetadata.getType(), uniqueValueCombination.toArray(new String[uniqueValueCombination.size()])); } } diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoFactoryImpl.java index 3ab6560c71..d9300a007b 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoFactoryImpl.java @@ -20,13 +20,15 @@ package org.openecomp.sdc.versioning.dao.impl; +import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory; import org.openecomp.sdc.versioning.dao.VersionableEntityDao; import org.openecomp.sdc.versioning.dao.VersionableEntityDaoFactory; import org.openecomp.sdc.versioning.types.VersionableEntityStoreType; public class VersionableEntityDaoFactoryImpl extends VersionableEntityDaoFactory { - private static VersionableEntityDao CASSANDRA_INSTANCE = new VersionableEntityDaoCassandraImpl(); + private static VersionableEntityDao CASSANDRA_INSTANCE = new VersionableEntityDaoCassandraImpl( + UniqueValueDaoFactory.getInstance().createInterface()); private static VersionableEntityDao ZUSAMMEN_INSTANCE = new VersionableEntityDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()); -- cgit 1.2.3-korg