From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- .../rest/services/EntitlementPoolLimitsImpl.java | 196 +++++++++------------ .../rest/services/EntitlementPoolsImpl.java | 187 +++++++++----------- .../rest/services/FeatureGroupsImpl.java | 71 +++----- .../rest/services/LicenseAgreementsImpl.java | 71 +++----- .../rest/services/LicenseKeyGroupLimitsImpl.java | 195 +++++++++----------- .../rest/services/LicenseKeyGroupsImpl.java | 193 +++++++++----------- .../rest/services/VendorLicenseModelsImpl.java | 164 ++++++----------- .../rest/services/VlmUniqueTypeProvider.java | 16 +- 8 files changed, 437 insertions(+), 656 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services') 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/EntitlementPoolLimitsImpl.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/EntitlementPoolLimitsImpl.java index 544c1d7331..38e0a78154 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/EntitlementPoolLimitsImpl.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/EntitlementPoolLimitsImpl.java @@ -7,9 +7,9 @@ * 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. @@ -17,10 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.vendorlicense.rest.services; - +import java.util.Collection; +import javax.inject.Named; +import javax.ws.rs.core.Response; import org.openecomp.sdc.vendorlicense.VendorLicenseManager; import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory; import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity; @@ -37,126 +38,89 @@ import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; -import javax.inject.Named; -import javax.ws.rs.core.Response; -import java.util.Collection; - @Named @Service("entitlementPoolLimits") @Scope(value = "prototype") public class EntitlementPoolLimitsImpl implements EntitlementPoolLimits { - private VendorLicenseManager vendorLicenseManager = - VendorLicenseManagerFactory.getInstance().createInterface(); - - private static final String PARENT = "EntitlementPool"; - - @Override - public Response createLimit(LimitRequestDto request, - String vlmId, - String versionId, - String entitlementPoolId, - String user) { - Version version = new Version(versionId); - vendorLicenseManager - .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId)); - - LimitEntity limitEntity = - new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class); - limitEntity.setVendorLicenseModelId(vlmId); - limitEntity.setVersion(version); - limitEntity.setEpLkgId(entitlementPoolId); - limitEntity.setParent(PARENT); - LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity); - MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto(); - LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto.class); - - return Response.ok(createdLimitDto != null ? createdLimitDto : null).build(); - } - - @Override - public Response listLimits(String vlmId, String versionId, String entitlementPoolId, String - user) { - Version version = new Version(versionId); - vendorLicenseManager - .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId)); - - Collection limits = - vendorLicenseManager.listLimits(vlmId, version, entitlementPoolId); - - GenericCollectionWrapper result = new GenericCollectionWrapper<>(); - MapLimitEntityToLimitDto outputMapper = - new MapLimitEntityToLimitDto(); - for (LimitEntity limit : limits) { - result.add(outputMapper.applyMapping(limit, LimitEntityDto.class)); + private static final String PARENT = "EntitlementPool"; + private VendorLicenseManager vendorLicenseManager = VendorLicenseManagerFactory.getInstance().createInterface(); + + @Override + public Response createLimit(LimitRequestDto request, String vlmId, String versionId, String entitlementPoolId, String user) { + Version version = new Version(versionId); + vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId)); + LimitEntity limitEntity = new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class); + limitEntity.setVendorLicenseModelId(vlmId); + limitEntity.setVersion(version); + limitEntity.setEpLkgId(entitlementPoolId); + limitEntity.setParent(PARENT); + LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity); + MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto(); + LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto.class); + return Response.ok(createdLimitDto != null ? createdLimitDto : null).build(); } - return Response.ok(result).build(); - } - - @Override - public Response getLimit(String vlmId, String versionId, String entitlementPoolId, - String limitId, String user) { - Version version = new Version(versionId); - vendorLicenseManager - .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId)); - LimitEntity limitInput = new LimitEntity(); - limitInput.setVendorLicenseModelId(vlmId); - limitInput.setVersion(version); - limitInput.setEpLkgId(entitlementPoolId); - limitInput.setId(limitId); - LimitEntity limit = vendorLicenseManager.getLimit(limitInput); - - LimitEntityDto entitlementPoolEntityDto = limit == null ? null : - new MapLimitEntityToLimitDto().applyMapping(limit, LimitEntityDto.class); - return Response.ok(entitlementPoolEntityDto).build(); - } - @Override - public Response updateLimit(LimitRequestDto request, - String vlmId, - String versionId, - String entitlementPoolId, - String limitId, - String user) { - Version version = new Version(versionId); - vendorLicenseManager - .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId)); - - LimitEntity limitEntity = - new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class); - limitEntity.setVendorLicenseModelId(vlmId); - limitEntity.setVersion(version); - limitEntity.setEpLkgId(entitlementPoolId); - limitEntity.setId(limitId); - limitEntity.setParent(PARENT); - - vendorLicenseManager.updateLimit(limitEntity); - return Response.ok().build(); - } + @Override + public Response listLimits(String vlmId, String versionId, String entitlementPoolId, String user) { + Version version = new Version(versionId); + vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId)); + Collection limits = vendorLicenseManager.listLimits(vlmId, version, entitlementPoolId); + GenericCollectionWrapper result = new GenericCollectionWrapper<>(); + MapLimitEntityToLimitDto outputMapper = new MapLimitEntityToLimitDto(); + for (LimitEntity limit : limits) { + result.add(outputMapper.applyMapping(limit, LimitEntityDto.class)); + } + return Response.ok(result).build(); + } - /** - * Delete entitlement pool. - * - * @param vlmId the vlm id - * @param entitlementPoolId the entitlement pool id - * @param limitId the limitId - * @param user the user - * @return the response - */ - public Response deleteLimit(String vlmId, String versionId, String entitlementPoolId, - String limitId, String user) { - Version version = new Version(versionId); - vendorLicenseManager.getEntitlementPool( - new EntitlementPoolEntity(vlmId, version, entitlementPoolId)); + @Override + public Response getLimit(String vlmId, String versionId, String entitlementPoolId, String limitId, String user) { + Version version = new Version(versionId); + vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId)); + LimitEntity limitInput = new LimitEntity(); + limitInput.setVendorLicenseModelId(vlmId); + limitInput.setVersion(version); + limitInput.setEpLkgId(entitlementPoolId); + limitInput.setId(limitId); + LimitEntity limit = vendorLicenseManager.getLimit(limitInput); + LimitEntityDto entitlementPoolEntityDto = limit == null ? null : new MapLimitEntityToLimitDto().applyMapping(limit, LimitEntityDto.class); + return Response.ok(entitlementPoolEntityDto).build(); + } - LimitEntity limitInput = new LimitEntity(); - limitInput.setVendorLicenseModelId(vlmId); - limitInput.setVersion(version); - limitInput.setEpLkgId(entitlementPoolId); - limitInput.setId(limitId); - limitInput.setParent(PARENT); + @Override + public Response updateLimit(LimitRequestDto request, String vlmId, String versionId, String entitlementPoolId, String limitId, String user) { + Version version = new Version(versionId); + vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId)); + LimitEntity limitEntity = new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class); + limitEntity.setVendorLicenseModelId(vlmId); + limitEntity.setVersion(version); + limitEntity.setEpLkgId(entitlementPoolId); + limitEntity.setId(limitId); + limitEntity.setParent(PARENT); + vendorLicenseManager.updateLimit(limitEntity); + return Response.ok().build(); + } - vendorLicenseManager.deleteLimit(limitInput); - return Response.ok().build(); - } + /** + * Delete entitlement pool. + * + * @param vlmId the vlm id + * @param entitlementPoolId the entitlement pool id + * @param limitId the limitId + * @param user the user + * @return the response + */ + public Response deleteLimit(String vlmId, String versionId, String entitlementPoolId, String limitId, String user) { + Version version = new Version(versionId); + vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId)); + LimitEntity limitInput = new LimitEntity(); + limitInput.setVendorLicenseModelId(vlmId); + limitInput.setVersion(version); + limitInput.setEpLkgId(entitlementPoolId); + limitInput.setId(limitId); + limitInput.setParent(PARENT); + vendorLicenseManager.deleteLimit(limitInput); + return Response.ok().build(); + } } 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/EntitlementPoolsImpl.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/EntitlementPoolsImpl.java index 83519198b7..bff8c7a449 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/EntitlementPoolsImpl.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/EntitlementPoolsImpl.java @@ -7,9 +7,9 @@ * 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. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.vendorlicense.rest.services; import java.util.Comparator; @@ -42,115 +41,97 @@ import org.springframework.stereotype.Service; @Service("entitlementPools") @Scope(value = "prototype") public class EntitlementPoolsImpl implements EntitlementPools { - private VendorLicenseManager vendorLicenseManager = - VendorLicenseManagerFactory.getInstance().createInterface(); - - /** - * List entitlement pools response. - * - * @param vlmId the vlm id - * @param versionId the version - * @param user the user - * @return the response - */ - public Response listEntitlementPools(String vlmId, String versionId, String user) { - MapEntitlementPoolEntityToEntitlementPoolEntityDto outputMapper = - new MapEntitlementPoolEntityToEntitlementPoolEntityDto(); + private VendorLicenseManager vendorLicenseManager = VendorLicenseManagerFactory.getInstance().createInterface(); + /** + * List entitlement pools response. + * + * @param vlmId the vlm id + * @param versionId the version + * @param user the user + * @return the response + */ + public Response listEntitlementPools(String vlmId, String versionId, String user) { + MapEntitlementPoolEntityToEntitlementPoolEntityDto outputMapper = new MapEntitlementPoolEntityToEntitlementPoolEntityDto(); GenericCollectionWrapper result = new GenericCollectionWrapper<>( - vendorLicenseManager.listEntitlementPools(vlmId, new Version(versionId)).stream() - .sorted(Comparator.comparing(EntitlementPoolEntity::getName)) - .map(item -> outputMapper.applyMapping(item, EntitlementPoolEntityDto.class)) - .collect(Collectors.toList())); - + vendorLicenseManager.listEntitlementPools(vlmId, new Version(versionId)).stream() + .sorted(Comparator.comparing(EntitlementPoolEntity::getName)) + .map(item -> outputMapper.applyMapping(item, EntitlementPoolEntityDto.class)).collect(Collectors.toList())); return Response.ok(result).build(); } - /** - * Create entitlement pool response. - * - * @param request the request - * @param vlmId the vlm id - * @param user the user - * @return the response - */ - public Response createEntitlementPool(EntitlementPoolRequestDto request, String vlmId, - String versionId, String user) { - EntitlementPoolEntity entitlementPoolEntity = - new MapEntitlementPoolRequestDtoToEntitlementPoolEntity() + /** + * Create entitlement pool response. + * + * @param request the request + * @param vlmId the vlm id + * @param user the user + * @return the response + */ + public Response createEntitlementPool(EntitlementPoolRequestDto request, String vlmId, String versionId, String user) { + EntitlementPoolEntity entitlementPoolEntity = new MapEntitlementPoolRequestDtoToEntitlementPoolEntity() .applyMapping(request, EntitlementPoolEntity.class); - entitlementPoolEntity.setVendorLicenseModelId(vlmId); - entitlementPoolEntity.setVersion(new Version(versionId)); - - EntitlementPoolEntity createdEntitlementPool = - vendorLicenseManager.createEntitlementPool(entitlementPoolEntity); - StringWrapperResponse result = - createdEntitlementPool != null ? new StringWrapperResponse(createdEntitlementPool.getId()) - : null; - return Response.ok(result).build(); - } + entitlementPoolEntity.setVendorLicenseModelId(vlmId); + entitlementPoolEntity.setVersion(new Version(versionId)); + EntitlementPoolEntity createdEntitlementPool = vendorLicenseManager.createEntitlementPool(entitlementPoolEntity); + StringWrapperResponse result = createdEntitlementPool != null ? new StringWrapperResponse(createdEntitlementPool.getId()) : null; + return Response.ok(result).build(); + } - /** - * Update entitlement pool response. - * - * @param request the request - * @param vlmId the vlm id - * @param entitlementPoolId the entitlement pool id - * @param user the user - * @return the response - */ - public Response updateEntitlementPool(EntitlementPoolRequestDto request, String vlmId, - String versionId, String entitlementPoolId, String user) { - EntitlementPoolEntity entitlementPoolEntity = - new MapEntitlementPoolRequestDtoToEntitlementPoolEntity() + /** + * Update entitlement pool response. + * + * @param request the request + * @param vlmId the vlm id + * @param entitlementPoolId the entitlement pool id + * @param user the user + * @return the response + */ + public Response updateEntitlementPool(EntitlementPoolRequestDto request, String vlmId, String versionId, String entitlementPoolId, String user) { + EntitlementPoolEntity entitlementPoolEntity = new MapEntitlementPoolRequestDtoToEntitlementPoolEntity() .applyMapping(request, EntitlementPoolEntity.class); - entitlementPoolEntity.setVendorLicenseModelId(vlmId); - entitlementPoolEntity.setVersion(new Version(versionId)); - entitlementPoolEntity.setId(entitlementPoolId); - - vendorLicenseManager.updateEntitlementPool(entitlementPoolEntity); - return Response.ok().build(); - } - - /** - * Gets entitlement pool. - * - * @param vlmId the vlm id - * @param versionId the version id - * @param entitlementPoolId the entitlement pool id - * @param user the user - * @return the entitlement pool - */ - public Response getEntitlementPool(String vlmId, String versionId, String entitlementPoolId, - String user) { - EntitlementPoolEntity epInput = new EntitlementPoolEntity(); - epInput.setVendorLicenseModelId(vlmId); - epInput.setVersion(new Version(versionId)); - epInput.setId(entitlementPoolId); - EntitlementPoolEntity entitlementPool = vendorLicenseManager.getEntitlementPool(epInput); + entitlementPoolEntity.setVendorLicenseModelId(vlmId); + entitlementPoolEntity.setVersion(new Version(versionId)); + entitlementPoolEntity.setId(entitlementPoolId); + vendorLicenseManager.updateEntitlementPool(entitlementPoolEntity); + return Response.ok().build(); + } - EntitlementPoolEntityDto entitlementPoolEntityDto = entitlementPool == null ? null : - new MapEntitlementPoolEntityToEntitlementPoolEntityDto() - .applyMapping(entitlementPool, EntitlementPoolEntityDto.class); - return Response.ok(entitlementPoolEntityDto).build(); - } + /** + * Gets entitlement pool. + * + * @param vlmId the vlm id + * @param versionId the version id + * @param entitlementPoolId the entitlement pool id + * @param user the user + * @return the entitlement pool + */ + public Response getEntitlementPool(String vlmId, String versionId, String entitlementPoolId, String user) { + EntitlementPoolEntity epInput = new EntitlementPoolEntity(); + epInput.setVendorLicenseModelId(vlmId); + epInput.setVersion(new Version(versionId)); + epInput.setId(entitlementPoolId); + EntitlementPoolEntity entitlementPool = vendorLicenseManager.getEntitlementPool(epInput); + EntitlementPoolEntityDto entitlementPoolEntityDto = entitlementPool == null ? null + : new MapEntitlementPoolEntityToEntitlementPoolEntityDto().applyMapping(entitlementPool, EntitlementPoolEntityDto.class); + return Response.ok(entitlementPoolEntityDto).build(); + } - /** - * Delete entitlement pool response. - * - * @param vlmId the vlm id - * @param entitlementPoolId the entitlement pool id - * @param user the user - * @return the response - */ - public Response deleteEntitlementPool(String vlmId, String versionId, String entitlementPoolId, - String user) { - EntitlementPoolEntity epInput = new EntitlementPoolEntity(); - epInput.setVendorLicenseModelId(vlmId); - epInput.setId(entitlementPoolId); - epInput.setVersion(new Version(versionId)); - vendorLicenseManager.deleteEntitlementPool(epInput); - return Response.ok().build(); - } + /** + * Delete entitlement pool response. + * + * @param vlmId the vlm id + * @param entitlementPoolId the entitlement pool id + * @param user the user + * @return the response + */ + public Response deleteEntitlementPool(String vlmId, String versionId, String entitlementPoolId, String user) { + EntitlementPoolEntity epInput = new EntitlementPoolEntity(); + epInput.setVendorLicenseModelId(vlmId); + epInput.setId(entitlementPoolId); + epInput.setVersion(new Version(versionId)); + vendorLicenseManager.deleteEntitlementPool(epInput); + return Response.ok().build(); + } } 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/FeatureGroupsImpl.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/FeatureGroupsImpl.java index 4ea35d321d..a945784213 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/FeatureGroupsImpl.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/FeatureGroupsImpl.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.vendorlicense.rest.services; import java.util.Comparator; @@ -54,104 +53,75 @@ import org.springframework.stereotype.Service; @Scope(value = "prototype") public class FeatureGroupsImpl implements FeatureGroups { - private VendorLicenseManager vendorLicenseManager = - VendorLicenseManagerFactory.getInstance().createInterface(); + private VendorLicenseManager vendorLicenseManager = VendorLicenseManagerFactory.getInstance().createInterface(); @Override public Response listFeatureGroups(String vlmId, String versionId, String user) { - - MapFeatureGroupEntityToFeatureGroupDescriptorDto outputMapper = - new MapFeatureGroupEntityToFeatureGroupDescriptorDto(); - + MapFeatureGroupEntityToFeatureGroupDescriptorDto outputMapper = new MapFeatureGroupEntityToFeatureGroupDescriptorDto(); GenericCollectionWrapper results = new GenericCollectionWrapper<>( - vendorLicenseManager.listFeatureGroups(vlmId, new Version(versionId)).stream() - .sorted(Comparator.comparing(FeatureGroupEntity::getName)) - .map(fg -> getFeatureGroupEntityDto(outputMapper,fg)).collect(Collectors.toList())); - + vendorLicenseManager.listFeatureGroups(vlmId, new Version(versionId)).stream().sorted(Comparator.comparing(FeatureGroupEntity::getName)) + .map(fg -> getFeatureGroupEntityDto(outputMapper, fg)).collect(Collectors.toList())); return Response.ok(results).build(); } @Override - public Response createFeatureGroup(FeatureGroupRequestDto request, String vlmId, String versionId, - String user) { + public Response createFeatureGroup(FeatureGroupRequestDto request, String vlmId, String versionId, String user) { FeatureGroupEntity featureGroupEntity = new MapFeatureGroupDescriptorDtoToFeatureGroupEntity() - .applyMapping(request, FeatureGroupEntity.class); + .applyMapping(request, FeatureGroupEntity.class); featureGroupEntity.setVendorLicenseModelId(vlmId); featureGroupEntity.setVersion(new Version(versionId)); featureGroupEntity.setLicenseKeyGroupIds(request.getAddedLicenseKeyGroupsIds()); featureGroupEntity.setEntitlementPoolIds(request.getAddedEntitlementPoolsIds()); - - FeatureGroupEntity createdFeatureGroup = - vendorLicenseManager.createFeatureGroup(featureGroupEntity); - - StringWrapperResponse result = - createdFeatureGroup != null ? new StringWrapperResponse(createdFeatureGroup.getId()) : null; + FeatureGroupEntity createdFeatureGroup = vendorLicenseManager.createFeatureGroup(featureGroupEntity); + StringWrapperResponse result = createdFeatureGroup != null ? new StringWrapperResponse(createdFeatureGroup.getId()) : null; return Response.ok(result).build(); } @Override - public Response updateFeatureGroup(FeatureGroupUpdateRequestDto request, String vlmId, - String versionId, String featureGroupId, String user) { + public Response updateFeatureGroup(FeatureGroupUpdateRequestDto request, String vlmId, String versionId, String featureGroupId, String user) { FeatureGroupEntity featureGroupEntity = new MapFeatureGroupDescriptorDtoToFeatureGroupEntity() - .applyMapping(request, FeatureGroupEntity.class); + .applyMapping(request, FeatureGroupEntity.class); featureGroupEntity.setVendorLicenseModelId(vlmId); featureGroupEntity.setVersion(new Version(versionId)); featureGroupEntity.setId(featureGroupId); - - vendorLicenseManager - .updateFeatureGroup(featureGroupEntity, request.getAddedLicenseKeyGroupsIds(), - request.getRemovedLicenseKeyGroupsIds(), request.getAddedEntitlementPoolsIds(), - request.getRemovedEntitlementPoolsIds()); + vendorLicenseManager.updateFeatureGroup(featureGroupEntity, request.getAddedLicenseKeyGroupsIds(), request.getRemovedLicenseKeyGroupsIds(), + request.getAddedEntitlementPoolsIds(), request.getRemovedEntitlementPoolsIds()); return Response.ok().build(); } @Override - public Response getFeatureGroup(String vlmId, String versionId, String featureGroupId, - String user) { + public Response getFeatureGroup(String vlmId, String versionId, String featureGroupId, String user) { FeatureGroupEntity fgInput = new FeatureGroupEntity(); fgInput.setVendorLicenseModelId(vlmId); fgInput.setVersion(new Version(versionId)); fgInput.setId(featureGroupId); FeatureGroupModel featureGroupModel = vendorLicenseManager.getFeatureGroupModel(fgInput); - if (featureGroupModel == null) { return Response.ok().build(); } - FeatureGroupModelDto fgmDto = new FeatureGroupModelDto(); fgmDto.setId(featureGroupModel.getFeatureGroup().getId()); - fgmDto.setReferencingLicenseAgreements( - featureGroupModel.getFeatureGroup().getReferencingLicenseAgreements()); - new MapFeatureGroupEntityToFeatureGroupDescriptorDto() - .doMapping(featureGroupModel.getFeatureGroup(), fgmDto); - + fgmDto.setReferencingLicenseAgreements(featureGroupModel.getFeatureGroup().getReferencingLicenseAgreements()); + new MapFeatureGroupEntityToFeatureGroupDescriptorDto().doMapping(featureGroupModel.getFeatureGroup(), fgmDto); if (!CollectionUtils.isEmpty(featureGroupModel.getLicenseKeyGroups())) { fgmDto.setLicenseKeyGroups(new HashSet<>()); - - MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto lkgMapper = - new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto(); + MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto lkgMapper = new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto(); for (LicenseKeyGroupEntity lkg : featureGroupModel.getLicenseKeyGroups()) { - fgmDto.getLicenseKeyGroups() - .add(lkgMapper.applyMapping(lkg, LicenseKeyGroupEntityDto.class)); + fgmDto.getLicenseKeyGroups().add(lkgMapper.applyMapping(lkg, LicenseKeyGroupEntityDto.class)); } } - if (!CollectionUtils.isEmpty(featureGroupModel.getEntitlementPools())) { fgmDto.setEntitlementPools(new HashSet<>()); - - MapEntitlementPoolEntityToEntitlementPoolEntityDto epMapper = - new MapEntitlementPoolEntityToEntitlementPoolEntityDto(); + MapEntitlementPoolEntityToEntitlementPoolEntityDto epMapper = new MapEntitlementPoolEntityToEntitlementPoolEntityDto(); for (EntitlementPoolEntity ep : featureGroupModel.getEntitlementPools()) { fgmDto.getEntitlementPools().add(epMapper.applyMapping(ep, EntitlementPoolEntityDto.class)); - } } return Response.ok(fgmDto).build(); } @Override - public Response deleteFeatureGroup(String vlmId, String versionId, String featureGroupId, - String user) { + public Response deleteFeatureGroup(String vlmId, String versionId, String featureGroupId, String user) { FeatureGroupEntity fgInput = new FeatureGroupEntity(); fgInput.setVendorLicenseModelId(vlmId); fgInput.setVersion(new Version(versionId)); @@ -160,7 +130,7 @@ public class FeatureGroupsImpl implements FeatureGroups { return Response.ok().build(); } - private FeatureGroupEntityDto getFeatureGroupEntityDto(MapFeatureGroupEntityToFeatureGroupDescriptorDto mapper,FeatureGroupEntity fg) { + private FeatureGroupEntityDto getFeatureGroupEntityDto(MapFeatureGroupEntityToFeatureGroupDescriptorDto mapper, FeatureGroupEntity fg) { FeatureGroupEntityDto fgDto = new FeatureGroupEntityDto(); fgDto.setId(fg.getId()); fgDto.setLicenseKeyGroupsIds(fg.getLicenseKeyGroupIds()); @@ -169,5 +139,4 @@ public class FeatureGroupsImpl implements FeatureGroups { mapper.doMapping(fg, fgDto); return fgDto; } - } 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/LicenseAgreementsImpl.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/LicenseAgreementsImpl.java index 7c0539931b..fb67b237f0 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/LicenseAgreementsImpl.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/LicenseAgreementsImpl.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.vendorlicense.rest.services; import java.util.Comparator; @@ -51,8 +50,7 @@ import org.springframework.stereotype.Service; @Scope(value = "prototype") public class LicenseAgreementsImpl implements LicenseAgreements { - private VendorLicenseManager vendorLicenseManager = - VendorLicenseManagerFactory.getInstance().createInterface(); + private VendorLicenseManager vendorLicenseManager = VendorLicenseManagerFactory.getInstance().createInterface(); /** * List license agreements response. @@ -63,20 +61,14 @@ public class LicenseAgreementsImpl implements LicenseAgreements { * @return the response */ public Response listLicenseAgreements(String vlmId, String versionId, String user) { - - MapLicenseAgreementEntityToLicenseAgreementDescriptorDto outputMapper = - new MapLicenseAgreementEntityToLicenseAgreementDescriptorDto(); - + MapLicenseAgreementEntityToLicenseAgreementDescriptorDto outputMapper = new MapLicenseAgreementEntityToLicenseAgreementDescriptorDto(); GenericCollectionWrapper results = new GenericCollectionWrapper<>( - vendorLicenseManager.listLicenseAgreements(vlmId, new Version(versionId)).stream() - .sorted(Comparator.comparing(LicenseAgreementEntity::getName)) - .map(lae -> getLicenseAgreementEntityDto(outputMapper, lae)) - .collect(Collectors.toList())); - + vendorLicenseManager.listLicenseAgreements(vlmId, new Version(versionId)).stream() + .sorted(Comparator.comparing(LicenseAgreementEntity::getName)).map(lae -> getLicenseAgreementEntityDto(outputMapper, lae)) + .collect(Collectors.toList())); return Response.ok(results).build(); } - /** * Create license agreement response. * @@ -85,20 +77,14 @@ public class LicenseAgreementsImpl implements LicenseAgreements { * @param user the user * @return the response */ - public Response createLicenseAgreement(LicenseAgreementRequestDto request, String vlmId, - String versionId, String user) { - LicenseAgreementEntity licenseAgreementEntity = - new MapLicenseAgreementDescriptorDtoToLicenseAgreementEntity() - .applyMapping(request, LicenseAgreementEntity.class); + public Response createLicenseAgreement(LicenseAgreementRequestDto request, String vlmId, String versionId, String user) { + LicenseAgreementEntity licenseAgreementEntity = new MapLicenseAgreementDescriptorDtoToLicenseAgreementEntity() + .applyMapping(request, LicenseAgreementEntity.class); licenseAgreementEntity.setVendorLicenseModelId(vlmId); licenseAgreementEntity.setVersion(new Version(versionId)); licenseAgreementEntity.setFeatureGroupIds(request.getAddedFeatureGroupsIds()); - - LicenseAgreementEntity createdLicenseAgreement = - vendorLicenseManager.createLicenseAgreement(licenseAgreementEntity); - StringWrapperResponse result = - createdLicenseAgreement != null ? new StringWrapperResponse(createdLicenseAgreement.getId()) - : null; + LicenseAgreementEntity createdLicenseAgreement = vendorLicenseManager.createLicenseAgreement(licenseAgreementEntity); + StringWrapperResponse result = createdLicenseAgreement != null ? new StringWrapperResponse(createdLicenseAgreement.getId()) : null; return Response.ok(result).build(); } @@ -111,18 +97,14 @@ public class LicenseAgreementsImpl implements LicenseAgreements { * @param user the user * @return the response */ - public Response updateLicenseAgreement(LicenseAgreementUpdateRequestDto request, String vlmId, - String versionId, String licenseAgreementId, String user) { - LicenseAgreementEntity licenseAgreementEntity = - new MapLicenseAgreementDescriptorDtoToLicenseAgreementEntity() - .applyMapping(request, LicenseAgreementEntity.class); + public Response updateLicenseAgreement(LicenseAgreementUpdateRequestDto request, String vlmId, String versionId, String licenseAgreementId, + String user) { + LicenseAgreementEntity licenseAgreementEntity = new MapLicenseAgreementDescriptorDtoToLicenseAgreementEntity() + .applyMapping(request, LicenseAgreementEntity.class); licenseAgreementEntity.setVendorLicenseModelId(vlmId); licenseAgreementEntity.setVersion(new Version(versionId)); licenseAgreementEntity.setId(licenseAgreementId); - - vendorLicenseManager - .updateLicenseAgreement(licenseAgreementEntity, request.getAddedFeatureGroupsIds(), - request.getRemovedFeatureGroupsIds()); + vendorLicenseManager.updateLicenseAgreement(licenseAgreementEntity, request.getAddedFeatureGroupsIds(), request.getRemovedFeatureGroupsIds()); return Response.ok().build(); } @@ -135,32 +117,24 @@ public class LicenseAgreementsImpl implements LicenseAgreements { * @param user the user * @return the license agreement */ - public Response getLicenseAgreement(String vlmId, String versionId, String licenseAgreementId, - String user) { + public Response getLicenseAgreement(String vlmId, String versionId, String licenseAgreementId, String user) { LicenseAgreementModel licenseAgreementModel = vendorLicenseManager - .getLicenseAgreementModel(vlmId, new Version(versionId), licenseAgreementId); - + .getLicenseAgreementModel(vlmId, new Version(versionId), licenseAgreementId); if (licenseAgreementModel == null) { return Response.ok().build(); } - LicenseAgreementModelDto lamDto = new LicenseAgreementModelDto(); lamDto.setId(licenseAgreementModel.getLicenseAgreement().getId()); - new MapLicenseAgreementEntityToLicenseAgreementDescriptorDto() - .doMapping(licenseAgreementModel.getLicenseAgreement(), lamDto); - + new MapLicenseAgreementEntityToLicenseAgreementDescriptorDto().doMapping(licenseAgreementModel.getLicenseAgreement(), lamDto); if (!CollectionUtils.isEmpty(licenseAgreementModel.getFeatureGroups())) { lamDto.setFeatureGroups(new HashSet<>()); - - MapFeatureGroupEntityToFeatureGroupDescriptorDto fgMapper = - new MapFeatureGroupEntityToFeatureGroupDescriptorDto(); + MapFeatureGroupEntityToFeatureGroupDescriptorDto fgMapper = new MapFeatureGroupEntityToFeatureGroupDescriptorDto(); for (FeatureGroupEntity fg : licenseAgreementModel.getFeatureGroups()) { FeatureGroupEntityDto fgeDto = new FeatureGroupEntityDto(); fgeDto.setId(fg.getId()); fgeDto.setEntitlementPoolsIds(fg.getEntitlementPoolIds()); fgeDto.setLicenseKeyGroupsIds(fg.getLicenseKeyGroupIds()); fgMapper.doMapping(fg, fgeDto); - lamDto.getFeatureGroups().add(fgeDto); } } @@ -176,14 +150,13 @@ public class LicenseAgreementsImpl implements LicenseAgreements { * @param user the user * @return the response */ - public Response deleteLicenseAgreement(String vlmId, String versionId, String licenseAgreementId, - String user) { + public Response deleteLicenseAgreement(String vlmId, String versionId, String licenseAgreementId, String user) { vendorLicenseManager.deleteLicenseAgreement(vlmId, new Version(versionId), licenseAgreementId); return Response.ok().build(); } - private LicenseAgreementEntityDto getLicenseAgreementEntityDto( - MapLicenseAgreementEntityToLicenseAgreementDescriptorDto mapper, LicenseAgreementEntity lae) { + private LicenseAgreementEntityDto getLicenseAgreementEntityDto(MapLicenseAgreementEntityToLicenseAgreementDescriptorDto mapper, + LicenseAgreementEntity lae) { LicenseAgreementEntityDto laeDto = new LicenseAgreementEntityDto(); laeDto.setId(lae.getId()); laeDto.setFeatureGroupsIds(lae.getFeatureGroupIds()); 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/LicenseKeyGroupLimitsImpl.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/LicenseKeyGroupLimitsImpl.java index 14491b0e6a..7d4f1f7679 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/LicenseKeyGroupLimitsImpl.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/LicenseKeyGroupLimitsImpl.java @@ -7,9 +7,9 @@ * 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. @@ -17,9 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.vendorlicense.rest.services; +import java.util.Collection; +import javax.inject.Named; +import javax.ws.rs.core.Response; import org.openecomp.sdc.vendorlicense.VendorLicenseManager; import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory; import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity; @@ -36,126 +38,89 @@ import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; -import javax.inject.Named; -import javax.ws.rs.core.Response; -import java.util.Collection; - @Named @Service("licenseKeyGroupLimits") @Scope(value = "prototype") public class LicenseKeyGroupLimitsImpl implements LicenseKeyGroupLimits { - private VendorLicenseManager vendorLicenseManager = - VendorLicenseManagerFactory.getInstance().createInterface(); - - private static final String PARENT = "LicenseKeyGroup"; - - - @Override - public Response createLimit(LimitRequestDto request, - String vlmId, - String versionId, - String licenseKeyGroupId, - String user) { - Version version = new Version(versionId); - vendorLicenseManager.getLicenseKeyGroup( - new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId)); - - LimitEntity limitEntity = - new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class); - limitEntity.setVendorLicenseModelId(vlmId); - limitEntity.setVersion(version); - limitEntity.setEpLkgId(licenseKeyGroupId); - limitEntity.setParent(PARENT); - LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity); - MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto(); - LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto.class); - return Response.ok(createdLimitDto != null ? createdLimitDto : null).build(); - } - - @Override - public Response listLimits(String vlmId, String versionId, String licenseKeyGroupId, - String user) { - Version version = new Version(versionId); - vendorLicenseManager - .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId)); - - Collection limits = - vendorLicenseManager.listLimits(vlmId, version, licenseKeyGroupId); - - GenericCollectionWrapper result = new GenericCollectionWrapper<>(); - MapLimitEntityToLimitDto outputMapper = - new MapLimitEntityToLimitDto(); - for (LimitEntity limit : limits) { - result.add(outputMapper.applyMapping(limit, LimitEntityDto.class)); + private static final String PARENT = "LicenseKeyGroup"; + private VendorLicenseManager vendorLicenseManager = VendorLicenseManagerFactory.getInstance().createInterface(); + + @Override + public Response createLimit(LimitRequestDto request, String vlmId, String versionId, String licenseKeyGroupId, String user) { + Version version = new Version(versionId); + vendorLicenseManager.getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId)); + LimitEntity limitEntity = new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class); + limitEntity.setVendorLicenseModelId(vlmId); + limitEntity.setVersion(version); + limitEntity.setEpLkgId(licenseKeyGroupId); + limitEntity.setParent(PARENT); + LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity); + MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto(); + LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto.class); + return Response.ok(createdLimitDto != null ? createdLimitDto : null).build(); } - return Response.ok(result).build(); - } - - @Override - public Response updateLimit(LimitRequestDto request, - String vlmId, - String versionId, - String licenseKeyGroupId, - String limitId, - String user) { - Version version = new Version(versionId); - vendorLicenseManager - .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId)); - - LimitEntity limitEntity = - new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class); - limitEntity.setVendorLicenseModelId(vlmId); - limitEntity.setVersion(version); - limitEntity.setEpLkgId(licenseKeyGroupId); - limitEntity.setId(limitId); - limitEntity.setParent(PARENT); - - vendorLicenseManager.updateLimit(limitEntity); - return Response.ok().build(); - } - /** - * Delete License Key Group. - * - * @param vlmId the vlm id - * @param licenseKeyGroupId the license Key Group id - * @param limitId the limitId - * @param user the user - * @return the response - */ - public Response deleteLimit(String vlmId, String versionId, String licenseKeyGroupId, - String limitId, String user) { - Version version = new Version(versionId); - vendorLicenseManager - .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId)); - - LimitEntity limitInput = new LimitEntity(); - limitInput.setVendorLicenseModelId(vlmId); - limitInput.setVersion(version); - limitInput.setEpLkgId(licenseKeyGroupId); - limitInput.setId(limitId); - limitInput.setParent(PARENT); + @Override + public Response listLimits(String vlmId, String versionId, String licenseKeyGroupId, String user) { + Version version = new Version(versionId); + vendorLicenseManager.getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId)); + Collection limits = vendorLicenseManager.listLimits(vlmId, version, licenseKeyGroupId); + GenericCollectionWrapper result = new GenericCollectionWrapper<>(); + MapLimitEntityToLimitDto outputMapper = new MapLimitEntityToLimitDto(); + for (LimitEntity limit : limits) { + result.add(outputMapper.applyMapping(limit, LimitEntityDto.class)); + } + return Response.ok(result).build(); + } - vendorLicenseManager.deleteLimit(limitInput); - return Response.ok().build(); - } + @Override + public Response updateLimit(LimitRequestDto request, String vlmId, String versionId, String licenseKeyGroupId, String limitId, String user) { + Version version = new Version(versionId); + vendorLicenseManager.getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId)); + LimitEntity limitEntity = new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class); + limitEntity.setVendorLicenseModelId(vlmId); + limitEntity.setVersion(version); + limitEntity.setEpLkgId(licenseKeyGroupId); + limitEntity.setId(limitId); + limitEntity.setParent(PARENT); + vendorLicenseManager.updateLimit(limitEntity); + return Response.ok().build(); + } - @Override - public Response getLimit(String vlmId, String versionId, String licenseKeyGroupId, - String limitId, String user) { - Version version = new Version(versionId); - vendorLicenseManager - .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId)); - LimitEntity limitInput = new LimitEntity(); - limitInput.setVendorLicenseModelId(vlmId); - limitInput.setVersion(version); - limitInput.setEpLkgId(licenseKeyGroupId); - limitInput.setId(limitId); - LimitEntity limit = vendorLicenseManager.getLimit(limitInput); + /** + * Delete License Key Group. + * + * @param vlmId the vlm id + * @param licenseKeyGroupId the license Key Group id + * @param limitId the limitId + * @param user the user + * @return the response + */ + public Response deleteLimit(String vlmId, String versionId, String licenseKeyGroupId, String limitId, String user) { + Version version = new Version(versionId); + vendorLicenseManager.getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId)); + LimitEntity limitInput = new LimitEntity(); + limitInput.setVendorLicenseModelId(vlmId); + limitInput.setVersion(version); + limitInput.setEpLkgId(licenseKeyGroupId); + limitInput.setId(limitId); + limitInput.setParent(PARENT); + vendorLicenseManager.deleteLimit(limitInput); + return Response.ok().build(); + } - LimitEntityDto entitlementPoolEntityDto = limit == null ? null - : new MapLimitEntityToLimitDto().applyMapping(limit, LimitEntityDto.class); - return Response.ok(entitlementPoolEntityDto).build(); - } + @Override + public Response getLimit(String vlmId, String versionId, String licenseKeyGroupId, String limitId, String user) { + Version version = new Version(versionId); + vendorLicenseManager.getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId)); + LimitEntity limitInput = new LimitEntity(); + limitInput.setVendorLicenseModelId(vlmId); + limitInput.setVersion(version); + limitInput.setEpLkgId(licenseKeyGroupId); + limitInput.setId(limitId); + LimitEntity limit = vendorLicenseManager.getLimit(limitInput); + LimitEntityDto entitlementPoolEntityDto = limit == null ? null : new MapLimitEntityToLimitDto().applyMapping(limit, LimitEntityDto.class); + return Response.ok(entitlementPoolEntityDto).build(); + } } 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/LicenseKeyGroupsImpl.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/LicenseKeyGroupsImpl.java index 3edee02080..f7ddc25eba 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/LicenseKeyGroupsImpl.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/LicenseKeyGroupsImpl.java @@ -7,9 +7,9 @@ * 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. @@ -17,12 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdcrests.vendorlicense.rest.services; import java.util.Comparator; import java.util.stream.Collectors; -import java.util.stream.Stream; import javax.inject.Named; import javax.ws.rs.core.Response; import org.openecomp.sdc.vendorlicense.VendorLicenseManager; @@ -45,116 +43,97 @@ import org.springframework.validation.annotation.Validated; @Scope(value = "prototype") @Validated public class LicenseKeyGroupsImpl implements LicenseKeyGroups { - private VendorLicenseManager vendorLicenseManager = - VendorLicenseManagerFactory.getInstance().createInterface(); - - /** - * List license key groups response. - * - * @param vlmId the vlm id - * @param versionId the version - * @param user the user - * @return the response - */ - public Response listLicenseKeyGroups(String vlmId, String versionId, String user) { - MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto outputMapper = - new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto(); + private VendorLicenseManager vendorLicenseManager = VendorLicenseManagerFactory.getInstance().createInterface(); - GenericCollectionWrapper result = new GenericCollectionWrapper<>( + /** + * List license key groups response. + * + * @param vlmId the vlm id + * @param versionId the version + * @param user the user + * @return the response + */ + public Response listLicenseKeyGroups(String vlmId, String versionId, String user) { + MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto outputMapper = new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto(); + GenericCollectionWrapper result = new GenericCollectionWrapper<>( vendorLicenseManager.listLicenseKeyGroups(vlmId, new Version(versionId)).stream() - .sorted(Comparator.comparing(LicenseKeyGroupEntity::getName)) - .map(item -> outputMapper.applyMapping(item, LicenseKeyGroupEntityDto.class)) - .collect(Collectors.toList())); - - return Response.ok(result).build(); - } + .sorted(Comparator.comparing(LicenseKeyGroupEntity::getName)) + .map(item -> outputMapper.applyMapping(item, LicenseKeyGroupEntityDto.class)).collect(Collectors.toList())); + return Response.ok(result).build(); + } - /** - * Create license key group response. - * - * @param request the request - * @param vlmId the vlm id - * @param user the user - * @return the response - */ - public Response createLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId, - String versionId, String user) { - LicenseKeyGroupEntity licenseKeyGroupEntity = - new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity() + /** + * Create license key group response. + * + * @param request the request + * @param vlmId the vlm id + * @param user the user + * @return the response + */ + public Response createLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId, String versionId, String user) { + LicenseKeyGroupEntity licenseKeyGroupEntity = new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity() .applyMapping(request, LicenseKeyGroupEntity.class); - licenseKeyGroupEntity.setVendorLicenseModelId(vlmId); - licenseKeyGroupEntity.setVersion(new Version(versionId)); + licenseKeyGroupEntity.setVendorLicenseModelId(vlmId); + licenseKeyGroupEntity.setVersion(new Version(versionId)); + LicenseKeyGroupEntity createdLicenseKeyGroup = vendorLicenseManager.createLicenseKeyGroup(licenseKeyGroupEntity); + StringWrapperResponse result = createdLicenseKeyGroup != null ? new StringWrapperResponse(createdLicenseKeyGroup.getId()) : null; + return Response.ok(result).build(); + } - LicenseKeyGroupEntity createdLicenseKeyGroup = - vendorLicenseManager.createLicenseKeyGroup(licenseKeyGroupEntity); - StringWrapperResponse result = - createdLicenseKeyGroup != null ? new StringWrapperResponse(createdLicenseKeyGroup.getId()) - : null; - return Response.ok(result).build(); - } - - /** - * Update license key group response. - * - * @param request the request - * @param vlmId the vlm id - * @param licenseKeyGroupId the license key group id - * @param user the user - * @return the response - */ - public Response updateLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId, - String versionId, - String licenseKeyGroupId, String user) { - LicenseKeyGroupEntity licenseKeyGroupEntity = - new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity() + /** + * Update license key group response. + * + * @param request the request + * @param vlmId the vlm id + * @param licenseKeyGroupId the license key group id + * @param user the user + * @return the response + */ + public Response updateLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId, String versionId, String licenseKeyGroupId, String user) { + LicenseKeyGroupEntity licenseKeyGroupEntity = new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity() .applyMapping(request, LicenseKeyGroupEntity.class); - licenseKeyGroupEntity.setVendorLicenseModelId(vlmId); - licenseKeyGroupEntity.setVersion(new Version(versionId)); - licenseKeyGroupEntity.setId(licenseKeyGroupId); - - vendorLicenseManager.updateLicenseKeyGroup(licenseKeyGroupEntity); - return Response.ok().build(); - } - - /** - * Gets license key group. - * - * @param vlmId the vlm id - * @param versionId the version - * @param licenseKeyGroupId the license key group id - * @param user the user - * @return the license key group - */ - public Response getLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId, - String user) { - LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity(); - lkgInput.setVendorLicenseModelId(vlmId); - lkgInput.setVersion(new Version(versionId)); - lkgInput.setId(licenseKeyGroupId); - LicenseKeyGroupEntity licenseKeyGroup = vendorLicenseManager.getLicenseKeyGroup(lkgInput); + licenseKeyGroupEntity.setVendorLicenseModelId(vlmId); + licenseKeyGroupEntity.setVersion(new Version(versionId)); + licenseKeyGroupEntity.setId(licenseKeyGroupId); + vendorLicenseManager.updateLicenseKeyGroup(licenseKeyGroupEntity); + return Response.ok().build(); + } - LicenseKeyGroupEntityDto licenseKeyGroupEntityDto = licenseKeyGroup == null ? null : - new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto() - .applyMapping(licenseKeyGroup, LicenseKeyGroupEntityDto.class); - return Response.ok(licenseKeyGroupEntityDto).build(); - } + /** + * Gets license key group. + * + * @param vlmId the vlm id + * @param versionId the version + * @param licenseKeyGroupId the license key group id + * @param user the user + * @return the license key group + */ + public Response getLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId, String user) { + LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity(); + lkgInput.setVendorLicenseModelId(vlmId); + lkgInput.setVersion(new Version(versionId)); + lkgInput.setId(licenseKeyGroupId); + LicenseKeyGroupEntity licenseKeyGroup = vendorLicenseManager.getLicenseKeyGroup(lkgInput); + LicenseKeyGroupEntityDto licenseKeyGroupEntityDto = licenseKeyGroup == null ? null + : new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto().applyMapping(licenseKeyGroup, LicenseKeyGroupEntityDto.class); + return Response.ok(licenseKeyGroupEntityDto).build(); + } - /** - * Delete license key group response. - * - * @param vlmId the vlm id - * @param licenseKeyGroupId the license key group id - * @param user the user - * @return the response - */ - public Response deleteLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId, - String user) { - LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity(); - lkgInput.setVendorLicenseModelId(vlmId); - lkgInput.setVersion(new Version(versionId)); - lkgInput.setId(licenseKeyGroupId); - vendorLicenseManager.deleteLicenseKeyGroup(lkgInput); - return Response.ok().build(); - } + /** + * Delete license key group response. + * + * @param vlmId the vlm id + * @param licenseKeyGroupId the license key group id + * @param user the user + * @return the response + */ + public Response deleteLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId, String user) { + LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity(); + lkgInput.setVendorLicenseModelId(vlmId); + lkgInput.setVersion(new Version(versionId)); + lkgInput.setId(licenseKeyGroupId); + vendorLicenseManager.deleteLicenseKeyGroup(lkgInput); + return Response.ok().build(); + } } 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 df6363c883..0255b14753 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 @@ -13,10 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - package org.openecomp.sdcrests.vendorlicense.rest.services; +import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_ID; +import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_NAME; +import static org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActionRequestDto.VendorLicenseModelAction.Submit; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.function.Predicate; +import javax.inject.Named; +import javax.ws.rs.core.Response; import org.openecomp.core.dao.UniqueValueDaoFactory; import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.sdc.activitylog.ActivityLogManager; @@ -65,17 +77,6 @@ import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import javax.inject.Named; -import javax.ws.rs.core.Response; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.function.Predicate; - -import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER; -import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.*; -import static org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActionRequestDto.VendorLicenseModelAction.Submit; - @Named @Service("vendorLicenseModels") @Scope(value = "prototype") @@ -83,75 +84,57 @@ import static org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActio public class VendorLicenseModelsImpl implements VendorLicenseModels { private static final String SUBMIT_ITEM_ACTION = "Submit_Item"; - private static final String SUBMIT_HEALED_VERSION_ERROR = - "VLM Id %s: Error while submitting version %s created based on Certified version %s for healing purpose."; + private static final String SUBMIT_HEALED_VERSION_ERROR = "VLM Id %s: Error while submitting version %s created based on Certified version %s for healing purpose."; private static final Logger LOGGER = LoggerFactory.getLogger(VendorLicenseModelsImpl.class); private PermissionsManager permissionsManager = PermissionsManagerFactory.getInstance().createInterface(); - private NotificationPropagationManager notifier = - NotificationPropagationManagerFactory.getInstance().createInterface(); - + private NotificationPropagationManager notifier = NotificationPropagationManagerFactory.getInstance().createInterface(); private AsdcItemManager asdcItemManager = AsdcItemManagerFactory.getInstance().createInterface(); private VersioningManager versioningManager = VersioningManagerFactory.getInstance().createInterface(); private VendorLicenseManager vendorLicenseManager = VendorLicenseManagerFactory.getInstance().createInterface(); private ActivityLogManager activityLogManager = ActivityLogManagerFactory.getInstance().createInterface(); - private UniqueValueUtil uniqueValueUtil = - new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); + private UniqueValueUtil uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory.getInstance().createInterface()); @Override public Response listLicenseModels(String versionStatus, String itemStatus, String user) { Predicate itemPredicate = createItemPredicate(versionStatus, itemStatus, user); - GenericCollectionWrapper results = new GenericCollectionWrapper<>(); MapItemToDto mapper = new MapItemToDto(); - asdcItemManager.list(itemPredicate).stream() - .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())) - .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class))); - + asdcItemManager.list(itemPredicate).stream().sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())) + .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class))); return Response.ok(results).build(); } @Override public Response createLicenseModel(VendorLicenseModelRequestDto request, String user) { - Item item = new Item(); item.setType(ItemType.vlm.name()); item.setOwner(user); item.setStatus(ItemStatus.ACTIVE); item.setName(request.getVendorName()); item.setDescription(request.getDescription()); - uniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName()); item = asdcItemManager.create(item); uniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, item.getName()); - Version version = versioningManager.create(item.getId(), new Version(), null); - VendorLicenseModelEntity vlm = new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity() - .applyMapping(request, VendorLicenseModelEntity.class); + .applyMapping(request, VendorLicenseModelEntity.class); vlm.setId(item.getId()); vlm.setVersion(version); - vendorLicenseManager.createVendorLicenseModel(vlm); versioningManager.publish(item.getId(), version, "Initial vlm:" + vlm.getVendorName()); - ItemCreationDto itemCreationDto = new ItemCreationDto(); itemCreationDto.setItemId(item.getId()); itemCreationDto.setVersion(new MapVersionToDto().applyMapping(version, VersionDto.class)); - - activityLogManager - .logActivity(new ActivityLogEntity(vlm.getId(), version, ActivityType.Create, user, true, "", "")); - + activityLogManager.logActivity(new ActivityLogEntity(vlm.getId(), version, ActivityType.Create, user, true, "", "")); return Response.ok(itemCreationDto).build(); } @Override - public Response updateLicenseModel(VendorLicenseModelRequestDto request, String vlmId, String versionId, - String user) { + public Response updateLicenseModel(VendorLicenseModelRequestDto request, String vlmId, String versionId, String user) { VendorLicenseModelEntity vlm = new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity() - .applyMapping(request, VendorLicenseModelEntity.class); + .applyMapping(request, VendorLicenseModelEntity.class); vlm.setId(vlmId); vlm.setVersion(new Version(versionId)); - vendorLicenseManager.updateVendorLicenseModel(vlm); return Response.ok().build(); } @@ -160,74 +143,56 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { public Response getLicenseModel(String vlmId, String versionId, String user) { Version version = versioningManager.get(vlmId, new Version(versionId)); VendorLicenseModelEntity vlm = vendorLicenseManager.getVendorLicenseModel(vlmId, version); - try { - HealingManagerFactory.getInstance().createInterface() - .healItemVersion(vlmId, version, ItemType.vlm, false) - .ifPresent(healedVersion -> { - vlm.setVersion(healedVersion); - if (version.getStatus() == VersionStatus.Certified) { - submitHealedVersion(vlmId, healedVersion, versionId, user); - } - }); + HealingManagerFactory.getInstance().createInterface().healItemVersion(vlmId, version, ItemType.vlm, false).ifPresent(healedVersion -> { + vlm.setVersion(healedVersion); + if (version.getStatus() == VersionStatus.Certified) { + submitHealedVersion(vlmId, healedVersion, versionId, user); + } + }); } catch (Exception e) { LOGGER.error(String.format("Error while auto healing VLM with Id %s and version %s", vlmId, versionId), e); } - - VendorLicenseModelEntityDto vlmDto = - new MapVendorLicenseModelEntityToDto().applyMapping(vlm, VendorLicenseModelEntityDto.class); + VendorLicenseModelEntityDto vlmDto = new MapVendorLicenseModelEntityToDto().applyMapping(vlm, VendorLicenseModelEntityDto.class); return Response.ok(vlmDto).build(); } @Override public Response deleteLicenseModel(String vlmId, String user) { Item vlm = asdcItemManager.get(vlmId); - if (!vlm.getType().equals(ItemType.vlm.name())) { - throw new CoreException((new ErrorCode.ErrorCodeBuilder() - .withMessage(String.format("Vlm with id %s does not exist.", vlmId)) - .build())); + throw new CoreException((new ErrorCode.ErrorCodeBuilder().withMessage(String.format("Vlm with id %s does not exist.", vlmId)).build())); } - Integer certifiedVersionsCounter = vlm.getVersionStatusCounters().get(VersionStatus.Certified); if (Objects.isNull(certifiedVersionsCounter) || certifiedVersionsCounter == 0) { asdcItemManager.delete(vlm); permissionsManager.deleteItemPermissions(vlmId); uniqueValueUtil.deleteUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME, vlm.getName()); notifyUsers(vlmId, vlm.getName(), null, null, user, NotificationEventTypes.DELETE); - return Response.ok().build(); } else { - return Response.status(Response.Status.FORBIDDEN) - .entity(new Exception(Messages.DELETE_VLM_ERROR.getErrorMessage())).build(); + return Response.status(Response.Status.FORBIDDEN).entity(new Exception(Messages.DELETE_VLM_ERROR.getErrorMessage())).build(); } } @Override - public Response actOnLicenseModel(VendorLicenseModelActionRequestDto request, String vlmId, String versionId, - String user) { + public Response actOnLicenseModel(VendorLicenseModelActionRequestDto request, String vlmId, String versionId, String user) { Version version = new Version(versionId); - if (request.getAction() == Submit) { if (!permissionsManager.isAllowed(vlmId, user, SUBMIT_ITEM_ACTION)) { - return Response.status(Response.Status.FORBIDDEN) - .entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build(); + return Response.status(Response.Status.FORBIDDEN).entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build(); } String message = request.getSubmitRequest() == null ? "Submit" : request.getSubmitRequest().getMessage(); submit(vlmId, version, message, user); - notifyUsers(vlmId, null, version, message, user, NotificationEventTypes.SUBMIT); - } return Response.ok().build(); } private void submit(String vlmId, Version version, String message, String user) { - vendorLicenseManager.validate(vlmId, version); versioningManager.submit(vlmId, version, message); - activityLogManager - .logActivity(new ActivityLogEntity(vlmId, version, ActivityType.Submit, user, true, "", message)); + activityLogManager.logActivity(new ActivityLogEntity(vlmId, version, ActivityType.Submit, user, true, "", message)); } private void submitHealedVersion(String vlmId, Version healedVersion, String baseVersionId, String user) { @@ -238,21 +203,16 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { } } - private void notifyUsers(String itemId, String itemName, Version version, String message, String userName, - NotificationEventTypes eventType) { + private void notifyUsers(String itemId, String itemName, Version version, String message, String userName, NotificationEventTypes eventType) { Map eventProperties = new HashMap<>(); eventProperties.put(ITEM_NAME, itemName == null ? asdcItemManager.get(itemId).getName() : itemName); eventProperties.put(ITEM_ID, itemId); - if (version != null) { - eventProperties.put(VERSION_NAME, - version.getName() == null ? versioningManager.get(itemId, version).getName() : version.getName()); + eventProperties.put(VERSION_NAME, version.getName() == null ? versioningManager.get(itemId, version).getName() : version.getName()); eventProperties.put(VERSION_ID, version.getId()); } - eventProperties.put(SUBMIT_DESCRIPTION, message); eventProperties.put(PERMISSION_USER, userName); - Event syncEvent = new SyncEvent(eventType.getEventName(), itemId, eventProperties, itemId); try { notifier.notifySubscribers(syncEvent, userName); @@ -261,6 +221,27 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { } } + private boolean userHasPermission(String itemId, String userId) { + return permissionsManager.getUserItemPermission(itemId, userId) + .map(permission -> permission.matches(PermissionTypes.Contributor.name() + "|" + PermissionTypes.Owner.name())).orElse(false); + } + + private Predicate createItemPredicate(String versionStatus, String itemStatus, String user) { + Predicate itemPredicate = item -> ItemType.vlm.name().equals(item.getType()); + if (ItemStatus.ARCHIVED.name().equals(itemStatus)) { + itemPredicate = itemPredicate.and(item -> ItemStatus.ARCHIVED.equals(item.getStatus())); + } else { + itemPredicate = itemPredicate.and(item -> ItemStatus.ACTIVE.equals(item.getStatus())); + if (VersionStatus.Certified.name().equals(versionStatus)) { + itemPredicate = itemPredicate.and(item -> item.getVersionStatusCounters().containsKey(VersionStatus.Certified)); + } else if (VersionStatus.Draft.name().equals(versionStatus)) { + itemPredicate = itemPredicate + .and(item -> item.getVersionStatusCounters().containsKey(VersionStatus.Draft) && userHasPermission(item.getId(), user)); + } + } + return itemPredicate; + } + private class SyncEvent implements Event { private String eventType; @@ -295,33 +276,4 @@ public class VendorLicenseModelsImpl implements VendorLicenseModels { return entityId; } } - - private boolean userHasPermission(String itemId, String userId) { - return permissionsManager.getUserItemPermission(itemId, userId) - .map(permission -> permission - .matches(PermissionTypes.Contributor.name() + "|" + PermissionTypes.Owner.name())) - .orElse(false); - } - - private Predicate createItemPredicate(String versionStatus, String itemStatus, String user) { - Predicate itemPredicate = item -> ItemType.vlm.name().equals(item.getType()); - - if (ItemStatus.ARCHIVED.name().equals(itemStatus)) { - itemPredicate = itemPredicate.and(item -> ItemStatus.ARCHIVED.equals(item.getStatus())); - } else { - itemPredicate = itemPredicate.and(item -> ItemStatus.ACTIVE.equals(item.getStatus())); - - if (VersionStatus.Certified.name().equals(versionStatus)) { - itemPredicate = - itemPredicate.and(item -> item.getVersionStatusCounters().containsKey(VersionStatus.Certified)); - - } else if (VersionStatus.Draft.name().equals(versionStatus)) { - itemPredicate = itemPredicate - .and(item -> item.getVersionStatusCounters().containsKey(VersionStatus.Draft) - && userHasPermission(item.getId(), user)); - } - } - return itemPredicate; - } - } 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/VlmUniqueTypeProvider.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/VlmUniqueTypeProvider.java index 5beeec242f..91e1ac5593 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/VlmUniqueTypeProvider.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/VlmUniqueTypeProvider.java @@ -15,20 +15,18 @@ */ package org.openecomp.sdcrests.vendorlicense.rest.services; -import org.openecomp.sdcrests.uniquevalue.types.UniqueTypesProvider; +import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.UniqueValues.VENDOR_NAME; import java.util.Collections; import java.util.Map; - -import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.UniqueValues.VENDOR_NAME; +import org.openecomp.sdcrests.uniquevalue.types.UniqueTypesProvider; public class VlmUniqueTypeProvider implements UniqueTypesProvider { - private static final Map uniqueTypes = - Collections.singletonMap("VlmName", VENDOR_NAME); + private static final Map uniqueTypes = Collections.singletonMap("VlmName", VENDOR_NAME); - @Override - public Map listUniqueTypes() { - return uniqueTypes; - } + @Override + public Map listUniqueTypes() { + return uniqueTypes; + } } -- cgit 1.2.3-korg