aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp
diff options
context:
space:
mode:
authoravigaffa <avi.gaffa@amdocs.com>2018-04-10 17:06:11 +0300
committerOren Kleks <orenkle@amdocs.com>2018-04-12 09:19:15 +0000
commitccf1c53e30c0021e055941f801597cc7919f8461 (patch)
tree3e7d98a5a864232a808487b78bbdc77e823eba8c /openecomp-be/api/openecomp-sdc-rest-webapp
parent26855ad25011c8582d45f809688dff4838950d8b (diff)
ValidationVsp Cannot support multiple sessions
Change-Id: I6b927fc12d89b33a722335eb8f6c7dd2e4c5fad9 Issue-ID: SDC-1192 Signed-off-by: avigaffa <avi.gaffa@amdocs.com> Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp')
-rw-r--r--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.java908
1 files changed, 464 insertions, 444 deletions
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 80532b5c29..3baf95cbd9 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
@@ -19,7 +19,7 @@ package org.openecomp.sdcrests.vsp.rest.services;
import static javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION;
import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME;
-import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.VALIDATION_VSP_NAME;
+import static org.openecomp.sdc.vendorsoftwareproduct.dao.type.OnboardingMethod.NetworkPackage;
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;
@@ -82,10 +82,10 @@ import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.errors.RequestedVersionInvalidErrorBuilder;
import org.openecomp.sdc.versioning.types.Item;
+import org.openecomp.sdc.versioning.types.ItemStatus;
import org.openecomp.sdc.versioning.types.NotificationEventTypes;
import org.openecomp.sdcrests.item.rest.mapping.MapVersionToDto;
import org.openecomp.sdcrests.item.types.ItemCreationDto;
-import org.openecomp.sdc.versioning.types.ItemStatus;
import org.openecomp.sdcrests.item.types.VersionDto;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.PackageInfoDto;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto;
@@ -114,534 +114,554 @@ import org.springframework.stereotype.Service;
@Scope(value = "prototype")
public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
- private static final String SUBMIT_ITEM_ACTION = "Submit_Item";
- private static final String ATTACHMENT_FILENAME = "attachment; filename=";
- private static final String SUBMIT_HEALED_VERSION_ERROR =
- "VSP Id %s: Error while submitting version %s created based on Certified version %s for healing purpose.";
- private static final Logger LOGGER = LoggerFactory.getLogger(VendorSoftwareProductsImpl.class);
+ private static final String VALIDATION_VSP_NAME = "validationOnlyVspName";
+ private static final String VALIDATION_VSP_USER = "validationOnlyVspUser";
+ private static final String SUBMIT_ITEM_ACTION = "Submit_Item";
+ private static final String ATTACHMENT_FILENAME = "attachment; filename=";
+ private static final String SUBMIT_HEALED_VERSION_ERROR =
+ "VSP Id %s: Error while submitting version %s created based on Certified version %s for healing purpose.";
+ private static final Logger LOGGER = LoggerFactory.getLogger(VendorSoftwareProductsImpl.class);
+ private static final Object VALIDATION_VSP_CACHE_LOCK = new Object();
- private static ItemCreationDto validationVsp;
+ private static ItemCreationDto cachedValidationVsp;
- private final AsdcItemManager itemManager = AsdcItemManagerFactory.getInstance()
- .createInterface();
+ private final AsdcItemManager itemManager = AsdcItemManagerFactory.getInstance()
+ .createInterface();
private final PermissionsManager permissionsManager =
PermissionsManagerFactory.getInstance().createInterface();
- private final VersioningManager versioningManager =
- VersioningManagerFactory.getInstance().createInterface();
- private final VendorSoftwareProductManager vendorSoftwareProductManager =
- VspManagerFactory.getInstance().createInterface();
- private final ActivityLogManager activityLogManager =
- 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) {
-
- OnboardingMethod onboardingMethod = null;
- try {
- onboardingMethod = OnboardingMethod.valueOf(vspRequestDto.getOnboardingMethod());
- } catch (IllegalArgumentException e) {
- LOGGER.error("Error while creating VSP. Message: " + e.getMessage());
- throwUnknownOnboardingMethodException(e);
- }
- ItemCreationDto itemCreationDto = null;
- if (onboardingMethod == OnboardingMethod.NetworkPackage
- || onboardingMethod == OnboardingMethod.Manual) {
- itemCreationDto = getItemCreationDto(vspRequestDto, user, onboardingMethod);
-
- } else {
- throwUnknownOnboardingMethodException(
- new IllegalArgumentException("Wrong parameter Onboarding Method"));
+ private final VersioningManager versioningManager =
+ VersioningManagerFactory.getInstance().createInterface();
+ private final VendorSoftwareProductManager vendorSoftwareProductManager =
+ VspManagerFactory.getInstance().createInterface();
+ private final ActivityLogManager activityLogManager =
+ 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) {
+ ItemCreationDto vspCreationDto = createVspItem(vspRequestDto, user);
+ return Response.ok(vspCreationDto).build();
}
- return Response.ok(itemCreationDto).build();
- }
+ private ItemCreationDto createVspItem(VspRequestDto vspRequestDto, String user) {
- private ItemCreationDto getItemCreationDto(VspRequestDto vspRequestDto,
- String user,
- OnboardingMethod onboardingMethod) {
+ OnboardingMethod onboardingMethod = null;
- Item item = new MapVspDescriptionDtoToItem().applyMapping(vspRequestDto, Item.class);
- item.setType(ItemType.vsp.name());
- item.setOwner(user);
- item.setStatus(ItemStatus.ACTIVE);
- item.addProperty(VspItemProperty.ONBOARDING_METHOD, onboardingMethod.name());
+ try {
+ onboardingMethod = OnboardingMethod.valueOf(vspRequestDto.getOnboardingMethod());
+ } catch (IllegalArgumentException e) {
+ LOGGER.error("Error while creating VSP. Message: " + e.getMessage());
+ throwUnknownOnboardingMethodException(e);
+ }
+
+ ItemCreationDto itemCreationDto = null;
+ if (onboardingMethod == NetworkPackage
+ || onboardingMethod == OnboardingMethod.Manual) {
+ itemCreationDto = createItem(vspRequestDto, user, onboardingMethod);
+
+ } else {
+ throwUnknownOnboardingMethodException(
+ new IllegalArgumentException("Wrong parameter Onboarding Method"));
+ }
+
+ return itemCreationDto;
+ }
- uniqueValueUtil.validateUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName());
- item = itemManager.create(item);
- uniqueValueUtil.createUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName());
+ private ItemCreationDto createItem(VspRequestDto vspRequestDto, String user, OnboardingMethod onboardingMethod) {
- Version version = versioningManager.create(item.getId(), new Version(), null);
+ Item item = new MapVspDescriptionDtoToItem().applyMapping(vspRequestDto, Item.class);
+ item.setType(ItemType.vsp.name());
+ item.setOwner(user);
+ item.setStatus(ItemStatus.ACTIVE);
+ item.addProperty(VspItemProperty.ONBOARDING_METHOD, onboardingMethod.name());
- VspDetails vspDetails =
- new MapVspDescriptionDtoToVspDetails().applyMapping(vspRequestDto, VspDetails.class);
- vspDetails.setId(item.getId());
- vspDetails.setVersion(version);
- vspDetails.setOnboardingMethod(vspRequestDto.getOnboardingMethod());
+ uniqueValueUtil.validateUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName());
+ item = itemManager.create(item);
+ uniqueValueUtil.createUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName());
- vendorSoftwareProductManager.createVsp(vspDetails);
- versioningManager.publish(item.getId(), version, "Initial vsp:" + vspDetails.getName());
- ItemCreationDto itemCreationDto = new ItemCreationDto();
- itemCreationDto.setItemId(item.getId());
- itemCreationDto.setVersion(new MapVersionToDto().applyMapping(version, VersionDto.class));
+ Version version = versioningManager.create(item.getId(), new Version(), null);
- activityLogManager.logActivity(new ActivityLogEntity(vspDetails.getId(), version,
- ActivityType.Create, user, true, "", ""));
- return itemCreationDto;
- }
+ VspDetails vspDetails =
+ new MapVspDescriptionDtoToVspDetails().applyMapping(vspRequestDto, VspDetails.class);
+ vspDetails.setId(item.getId());
+ vspDetails.setVersion(version);
+ vspDetails.setOnboardingMethod(vspRequestDto.getOnboardingMethod());
- private void throwUnknownOnboardingMethodException(IllegalArgumentException e) {
- ErrorCode onboardingMethodUpdateErrorCode = OnboardingMethodErrorBuilder
- .getInvalidOnboardingMethodErrorBuilder();
- throw new CoreException(onboardingMethodUpdateErrorCode, e);
- }
+ vendorSoftwareProductManager.createVsp(vspDetails);
+ versioningManager.publish(item.getId(), version, "Initial vsp:" + vspDetails.getName());
+ ItemCreationDto itemCreationDto = new ItemCreationDto();
+ itemCreationDto.setItemId(item.getId());
+ itemCreationDto.setVersion(new MapVersionToDto().applyMapping(version, VersionDto.class));
+
+ activityLogManager.logActivity(new ActivityLogEntity(vspDetails.getId(), version,
+ ActivityType.Create, user, true, "", ""));
+ return itemCreationDto;
+ }
+
+ private void throwUnknownOnboardingMethodException(IllegalArgumentException e) {
+ ErrorCode onboardingMethodUpdateErrorCode = OnboardingMethodErrorBuilder
+ .getInvalidOnboardingMethodErrorBuilder();
+ throw new CoreException(onboardingMethodUpdateErrorCode, e);
+ }
@Override
public Response listVsps(String versionStatus, String itemStatus, String user) {
- GenericCollectionWrapper<VspDetailsDto> results = new GenericCollectionWrapper<>();
- MapItemToVspDetailsDto mapper = new MapItemToVspDetailsDto();
+ GenericCollectionWrapper<VspDetailsDto> results = new GenericCollectionWrapper<>();
+ MapItemToVspDetailsDto mapper = new MapItemToVspDetailsDto();
- getVspList(versionStatus,itemStatus,user)
- .forEach(vspItem -> results.add(mapper.applyMapping(vspItem, VspDetailsDto.class)));
+ getVspList(versionStatus, itemStatus, user)
+ .forEach(vspItem -> results.add(mapper.applyMapping(vspItem, VspDetailsDto.class)));
- return Response.ok(results).build();
- }
+ return Response.ok(results).build();
+ }
- @Override
- public Response getVsp(String vspId, String versionId, String user) {
- Version version = versioningManager.get(vspId, new Version(versionId));
- VspDetails vspDetails = vendorSoftwareProductManager.getVsp(vspId, version);
- vspDetails.setWritetimeMicroSeconds(version.getModificationTime().getTime());
+ @Override
+ public Response getVsp(String vspId, String versionId, String user) {
+ Version version = versioningManager.get(vspId, new Version(versionId));
+ VspDetails vspDetails = vendorSoftwareProductManager.getVsp(vspId, version);
+ vspDetails.setWritetimeMicroSeconds(version.getModificationTime().getTime());
+
+ try {
+ Optional<Version> healedVersion = HealingManagerFactory.getInstance().createInterface()
+ .healItemVersion(vspId, version, ItemType.vsp, false);
+
+ healedVersion.ifPresent(version1 -> {
+ vspDetails.setVersion(version1);
+ if (version.getStatus() == VersionStatus.Certified) {
+ submitHealedVersion(vspId, version1, versionId, user);
+ }
+ });
+ } catch (Exception e) {
+ LOGGER.error(
+ String.format("Error while auto healing VSP with Id %s and version %s", vspId, versionId),
+ e);
+ }
- try {
- Optional<Version> healedVersion = HealingManagerFactory.getInstance().createInterface()
- .healItemVersion(vspId, version, ItemType.vsp, false);
+ VspDetailsDto vspDetailsDto =
+ new MapVspDetailsToDto().applyMapping(vspDetails, VspDetailsDto.class);
+ addNetworkPackageInfo(vspId, vspDetails.getVersion(), vspDetailsDto);
- healedVersion.ifPresent(version1 -> {
- vspDetails.setVersion(version1);
- if (version.getStatus() == VersionStatus.Certified) {
- submitHealedVersion(vspId, version1, versionId, user);
- }
- });
- } catch (Exception e) {
- LOGGER.error(
- String.format("Error while auto healing VSP with Id %s and version %s", vspId, versionId),
- e);
+ return Response.ok(vspDetailsDto).build();
}
- VspDetailsDto vspDetailsDto =
- new MapVspDetailsToDto().applyMapping(vspDetails, VspDetailsDto.class);
- addNetworkPackageInfo(vspId, vspDetails.getVersion(), vspDetailsDto);
-
- return Response.ok(vspDetailsDto).build();
- }
-
- private void submitHealedVersion(String vspId, Version healedVersion, String baseVersionId,
- String user) {
- try {
- Optional<ValidationResponse>
- validationResponse = submit(vspId, healedVersion, "Submit healed Vsp", user);
- // TODO: 8/9/2017 before collaboration checkout was done at this scenario (equivalent
- // to new version in collaboration). need to decide what should be done now.
- validationResponse.ifPresent(validationResponse1 -> {
- throw new IllegalStateException("Certified vsp after healing failed on validation");
- });
- vendorSoftwareProductManager.createPackage(vspId, healedVersion);
- } catch (Exception ex) {
- LOGGER.error(
- String.format(SUBMIT_HEALED_VERSION_ERROR, vspId, healedVersion.getId(), baseVersionId),
- ex);
+ private void submitHealedVersion(String vspId, Version healedVersion, String baseVersionId,
+ String user) {
+ try {
+ Optional<ValidationResponse>
+ validationResponse = submit(vspId, healedVersion, "Submit healed Vsp", user);
+ // TODO: 8/9/2017 before collaboration checkout was done at this scenario (equivalent
+ // to new version in collaboration). need to decide what should be done now.
+ validationResponse.ifPresent(validationResponse1 -> {
+ throw new IllegalStateException("Certified vsp after healing failed on validation");
+ });
+ vendorSoftwareProductManager.createPackage(vspId, healedVersion);
+ } catch (Exception ex) {
+ LOGGER.error(
+ String.format(SUBMIT_HEALED_VERSION_ERROR, vspId, healedVersion.getId(), baseVersionId),
+ ex);
+ }
}
- }
- @Override
- public Response updateVsp(String vspId, String versionId, VspDescriptionDto vspDescriptionDto,
- String user) {
- VspDetails vspDetails =
- new MapVspDescriptionDtoToVspDetails().applyMapping(vspDescriptionDto, VspDetails.class);
- vspDetails.setId(vspId);
- vspDetails.setVersion(new Version(versionId));
+ @Override
+ public Response updateVsp(String vspId, String versionId, VspDescriptionDto vspDescriptionDto,
+ String user) {
+ VspDetails vspDetails =
+ new MapVspDescriptionDtoToVspDetails().applyMapping(vspDescriptionDto, VspDetails.class);
+ vspDetails.setId(vspId);
+ vspDetails.setVersion(new Version(versionId));
- vendorSoftwareProductManager.updateVsp(vspDetails);
+ vendorSoftwareProductManager.updateVsp(vspDetails);
- return Response.ok().build();
- }
+ return Response.ok().build();
+ }
- @Override
- public Response deleteVsp(String vspId, String user) {
- Item vsp = itemManager.get(vspId);
+ @Override
+ public Response deleteVsp(String vspId, String user) {
+ Item vsp = itemManager.get(vspId);
- if (!vsp.getType().equals(ItemType.vsp.name())) {
- throw new CoreException((new ErrorCode.ErrorCodeBuilder()
- .withMessage(String.format("Vsp with id %s does not exist.",
- vspId)).build()));
- }
+ if (!vsp.getType().equals(ItemType.vsp.name())) {
+ throw new CoreException((new ErrorCode.ErrorCodeBuilder()
+ .withMessage(String.format("Vsp with id %s does not exist.",
+ vspId)).build()));
+ }
- Integer certifiedVersionsCounter = vsp.getVersionStatusCounters().get(VersionStatus.Certified);
- if (Objects.isNull(certifiedVersionsCounter) || certifiedVersionsCounter == 0) {
- versioningManager.list(vspId)
- .forEach(version -> vendorSoftwareProductManager.deleteVsp(vspId, version));
- itemManager.delete(vsp);
- permissionsManager.deleteItemPermissions(vspId);
- uniqueValueUtil.deleteUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, vsp.getName());
- notifyUsers(vspId, vsp.getName(), null, null, user,
- NotificationEventTypes.DELETE);
-
- return Response.ok().build();
- } else {
- return Response.status(Response.Status.FORBIDDEN)
- .entity(new Exception(Messages.DELETE_VSP_ERROR.getErrorMessage())).build();
- }
- }
-
- @Override
- public Response actOnVendorSoftwareProduct(VersionSoftwareProductActionRequestDto request,
- String vspId, String versionId,
- String user) throws IOException {
- Version version = new Version(versionId);
-
- if (request.getAction() == VendorSoftwareProductAction.Submit) {
- if (!permissionsManager.isAllowed(vspId, user, SUBMIT_ITEM_ACTION)) {
- return Response.status(Response.Status.FORBIDDEN)
- .entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build();
- }
- String message = request.getSubmitRequest() == null ? "Submit"
- : request.getSubmitRequest().getMessage();
- Optional<ValidationResponse> validationResponse = submit(vspId, version, message, user);
-
- if (validationResponse.isPresent()) {
- ValidationResponseDto validationResponseDto = new MapValidationResponseToDto()
- .applyMapping(validationResponse.get(), ValidationResponseDto.class);
- return Response.status(Response.Status.EXPECTATION_FAILED).entity(validationResponseDto)
- .build();
- }
-
- notifyUsers(vspId, null, version, message, user, NotificationEventTypes.SUBMIT);
-
- } else if (request.getAction() == VendorSoftwareProductAction.Create_Package) {
- return createPackage(vspId, version);
+ Integer certifiedVersionsCounter = vsp.getVersionStatusCounters().get(VersionStatus.Certified);
+ if (Objects.isNull(certifiedVersionsCounter) || certifiedVersionsCounter == 0) {
+ versioningManager.list(vspId)
+ .forEach(version -> vendorSoftwareProductManager.deleteVsp(vspId, version));
+ itemManager.delete(vsp);
+ permissionsManager.deleteItemPermissions(vspId);
+ uniqueValueUtil.deleteUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, vsp.getName());
+ notifyUsers(vspId, vsp.getName(), null, null, user,
+ NotificationEventTypes.DELETE);
+
+ return Response.ok().build();
+ } else {
+ return Response.status(Response.Status.FORBIDDEN)
+ .entity(new Exception(Messages.DELETE_VSP_ERROR.getErrorMessage())).build();
+ }
}
- return Response.ok().build();
- }
+ @Override
+ public Response actOnVendorSoftwareProduct(VersionSoftwareProductActionRequestDto request,
+ String vspId, String versionId,
+ String user) throws IOException {
+ Version version = new Version(versionId);
+
+ if (request.getAction() == VendorSoftwareProductAction.Submit) {
+ if (!permissionsManager.isAllowed(vspId, user, SUBMIT_ITEM_ACTION)) {
+ return Response.status(Response.Status.FORBIDDEN)
+ .entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build();
+ }
+ String message = request.getSubmitRequest() == null ? "Submit"
+ : request.getSubmitRequest().getMessage();
+ Optional<ValidationResponse> validationResponse = submit(vspId, version, message, user);
+
+ if (validationResponse.isPresent()) {
+ ValidationResponseDto validationResponseDto = new MapValidationResponseToDto()
+ .applyMapping(validationResponse.get(), ValidationResponseDto.class);
+ return Response.status(Response.Status.EXPECTATION_FAILED).entity(validationResponseDto)
+ .build();
+ }
+
+ notifyUsers(vspId, null, version, message, user, NotificationEventTypes.SUBMIT);
+
+ } else if (request.getAction() == VendorSoftwareProductAction.Create_Package) {
+ return createPackage(vspId, version);
+ }
- @Override
- public Response getValidationVsp(String user) {
- if (validationVsp != null) {
- return Response.ok(validationVsp).build();
+ return Response.ok().build();
}
- VspRequestDto validationVspRequest = new VspRequestDto();
- validationVspRequest.setOnboardingMethod("HEAT");
- validationVspRequest.setName(VALIDATION_VSP_NAME);
-
- try {
- validationVsp = (ItemCreationDto) createVsp(validationVspRequest, user).getEntity();
- return Response.ok(validationVsp).build();
-
- } catch (CoreException validationVspAlreadyExistException) {
- // find validationVsp
- String validationVspId = itemManager.list(item ->
- ItemType.vsp.name().equals(item.getType()) && VALIDATION_VSP_NAME.equals(item.getName()))
- .stream().findFirst().orElseThrow(() -> new IllegalStateException("Vsp with name %s "
- + "does not exist even though the name exists according to unique value util"))
- .getId();
- Version validationVspVersion = versioningManager.list(validationVspId).iterator().next();
-
- validationVsp = new ItemCreationDto();
- validationVsp.setItemId(validationVspId);
- validationVsp
- .setVersion(new MapVersionToDto().applyMapping(validationVspVersion, VersionDto.class));
-
- return Response.ok(validationVsp).build();
+ @Override
+ public Response getValidationVsp(String user) {
+ ItemCreationDto validationVsp = retrieveValidationVsp();
+ return Response.ok(validationVsp).build();
}
- }
- @Override
- public Response getOrchestrationTemplate(String vspId, String versionId, String user) {
- byte[] orchestrationTemplateFile =
- vendorSoftwareProductManager.getOrchestrationTemplateFile(vspId, new Version(versionId));
+ private ItemCreationDto retrieveValidationVsp() {
- if (orchestrationTemplateFile == null) {
- return Response.status(Response.Status.NOT_FOUND).build();
- }
- Response.ResponseBuilder response = Response.ok(orchestrationTemplateFile);
- response.header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + "LatestHeatPackage.zip");
- return response.build();
- }
+ synchronized (VALIDATION_VSP_CACHE_LOCK) {
- @Override
- public Response listPackages(String status, String category, String subCategory, String user) {
+ if (cachedValidationVsp != null) {
+ return cachedValidationVsp;
+ }
- List<String> VspsIds =
- getVspList(null, status != null ? ItemStatus.valueOf(status).name(): null, user)
- .stream().map(Item::getId).collect(Collectors.toList());
+ VspRequestDto validationVspRequest = new VspRequestDto();
+ validationVspRequest.setOnboardingMethod(NetworkPackage.toString());
+ validationVspRequest.setName(VALIDATION_VSP_NAME);
- List<PackageInfo> packageInfoList =
- vendorSoftwareProductManager.listPackages(category, subCategory);
+ try {
- packageInfoList = packageInfoList.stream().
- filter(packageInfo -> VspsIds.contains(packageInfo.getVspId()))
- .collect(Collectors.toList());
+ cachedValidationVsp = createVspItem(validationVspRequest, VALIDATION_VSP_USER);
+ return cachedValidationVsp;
- GenericCollectionWrapper<PackageInfoDto> results = new GenericCollectionWrapper<>();
- MapPackageInfoToPackageInfoDto mapper = new MapPackageInfoToPackageInfoDto();
+ } catch (CoreException vspCreateException) {
+ LOGGER.debug("Failed to create validation VSP", vspCreateException);
+ Predicate<Item> validationVspFilter = item -> ItemType.vsp.name().equals(item.getType())
+ && VALIDATION_VSP_NAME.equals(item.getName());
+ String validationVspId = itemManager.list(validationVspFilter).stream().findFirst()
+ .orElseThrow(() -> new IllegalStateException(
+ "Vsp with name " + VALIDATION_VSP_NAME +
+ " does not exist even though the name exists according to " +
+ "unique value util"))
+ .getId();
- if (packageInfoList != null) {
- for (PackageInfo packageInfo : packageInfoList) {
- results.add(mapper.applyMapping(packageInfo, PackageInfoDto.class));
- }
- }
- return Response.ok(results).build();
- }
-
- @Override
- public Response getTranslatedFile(String vspId, String versionName, String user) {
- List<Version> versions = versioningManager.list(vspId);
- Version version;
- if (versionName == null) {
- version = versions.stream().filter(ver -> VersionStatus.Certified == ver.getStatus())
- .max(Comparator.comparingDouble(o -> Double.parseDouble(o.getName())))
- .orElseThrow(() -> new CoreException(new PackageNotFoundErrorBuilder(vspId).build()));
- } else {
- version = versions.stream().filter(ver -> versionName.equals(ver.getName()))
- .findFirst()
- .orElseThrow(() -> new CoreException(new PackageNotFoundErrorBuilder(vspId).build()));
-
- if (version.getStatus() != VersionStatus.Certified) {
- throw new CoreException(new RequestedVersionInvalidErrorBuilder().build());
- }
+ Version validationVspVersion = versioningManager.list(validationVspId).iterator().next();
+
+ cachedValidationVsp = new ItemCreationDto();
+ cachedValidationVsp.setItemId(validationVspId);
+ cachedValidationVsp.setVersion(new MapVersionToDto().applyMapping(validationVspVersion, VersionDto.class));
+ return cachedValidationVsp;
+ }
+ }
}
- File zipFile = vendorSoftwareProductManager.getTranslatedFile(vspId, version);
+ @Override
+ public Response getOrchestrationTemplate(String vspId, String versionId, String user) {
+ byte[] orchestrationTemplateFile =
+ vendorSoftwareProductManager.getOrchestrationTemplateFile(vspId, new Version(versionId));
- Response.ResponseBuilder response = Response.ok(zipFile);
- if (zipFile == null) {
- return Response.status(Response.Status.NOT_FOUND).build();
+ if (orchestrationTemplateFile == null) {
+ return Response.status(Response.Status.NOT_FOUND).build();
+ }
+ Response.ResponseBuilder response = Response.ok(orchestrationTemplateFile);
+ response.header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + "LatestHeatPackage.zip");
+ return response.build();
}
- response.header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + zipFile.getName());
- return response.build();
- }
+ @Override
+ public Response listPackages(String status, String category, String subCategory, String user) {
- @Override
- public Response getQuestionnaire(String vspId, String versionId, String user) {
- QuestionnaireResponse questionnaireResponse =
- vendorSoftwareProductManager.getVspQuestionnaire(vspId, new Version(versionId));
+ List<String> vspsIds =
+ getVspList(null, status != null ? ItemStatus.valueOf(status).name() : null, user)
+ .stream().map(Item::getId).collect(Collectors.toList());
- if (questionnaireResponse.getErrorMessage() != null) {
- return Response.status(Response.Status.EXPECTATION_FAILED).entity(
- new MapQuestionnaireResponseToQuestionnaireResponseDto()
- .applyMapping(questionnaireResponse, QuestionnaireResponseDto.class)).build();
- }
+ List<PackageInfo> packageInfoList =
+ vendorSoftwareProductManager.listPackages(category, subCategory);
+
+ packageInfoList = packageInfoList.stream().
+ filter(packageInfo -> vspsIds.contains(packageInfo.getVspId()))
+ .collect(Collectors.toList());
- QuestionnaireResponseDto result = new MapQuestionnaireResponseToQuestionnaireResponseDto()
- .applyMapping(questionnaireResponse, QuestionnaireResponseDto.class);
- return Response.ok(result).build();
- }
-
- @Override
- public Response updateQuestionnaire(String questionnaireData, String vspId, String
- versionId, String user) {
- vendorSoftwareProductManager
- .updateVspQuestionnaire(vspId, new Version(versionId), questionnaireData);
- return Response.ok().build();
- }
-
- @Override
- public Response heal(String vspId, String versionId, String user) {
- HealingManagerFactory.getInstance().createInterface()
- .healItemVersion(vspId, new Version(versionId), ItemType.vsp, true);
- return Response.ok().build();
- }
-
- @Override
- public Response getVspInformationArtifact(String vspId, String versionId, String user) {
- File textInformationArtifact =
- vendorSoftwareProductManager.getInformationArtifact(vspId, new Version(versionId));
-
- Response.ResponseBuilder response = Response.ok(textInformationArtifact);
- if (textInformationArtifact == null) {
- return Response.status(Response.Status.NOT_FOUND).build();
+ GenericCollectionWrapper<PackageInfoDto> results = new GenericCollectionWrapper<>();
+ MapPackageInfoToPackageInfoDto mapper = new MapPackageInfoToPackageInfoDto();
+
+ if (packageInfoList != null) {
+ for (PackageInfo packageInfo : packageInfoList) {
+ results.add(mapper.applyMapping(packageInfo, PackageInfoDto.class));
+ }
+ }
+ return Response.ok(results).build();
}
- response
- .header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + textInformationArtifact.getName());
- return response.build();
- }
- @Override
- public Response listComputes(String vspId, String version, String user) {
+ @Override
+ public Response getTranslatedFile(String vspId, String versionName, String user) {
+ List<Version> versions = versioningManager.list(vspId);
+ Version version;
+ if (versionName == null) {
+ version = versions.stream().filter(ver -> VersionStatus.Certified == ver.getStatus())
+ .max(Comparator.comparingDouble(o -> Double.parseDouble(o.getName())))
+ .orElseThrow(() -> new CoreException(new PackageNotFoundErrorBuilder(vspId).build()));
+ } else {
+ version = versions.stream().filter(ver -> versionName.equals(ver.getName()))
+ .findFirst()
+ .orElseThrow(() -> new CoreException(new PackageNotFoundErrorBuilder(vspId).build()));
+
+ if (version.getStatus() != VersionStatus.Certified) {
+ throw new CoreException(new RequestedVersionInvalidErrorBuilder().build());
+ }
+ }
- Collection<ComputeEntity> computes =
- vendorSoftwareProductManager.getComputeByVsp(vspId, new Version(version));
+ File zipFile = vendorSoftwareProductManager.getTranslatedFile(vspId, version);
- MapComputeEntityToVspComputeDto mapper = new MapComputeEntityToVspComputeDto();
- GenericCollectionWrapper<VspComputeDto> results = new GenericCollectionWrapper<>();
- for (ComputeEntity compute : computes) {
- results.add(mapper.applyMapping(compute, VspComputeDto.class));
- }
+ Response.ResponseBuilder response = Response.ok(zipFile);
+ if (zipFile == null) {
+ return Response.status(Response.Status.NOT_FOUND).build();
+ }
+ response.header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + zipFile.getName());
- return Response.ok(results).build();
- }
+ return response.build();
+ }
- private Optional<ValidationResponse> submit(String vspId, Version version, String message,
- String user) throws IOException {
+ @Override
+ public Response getQuestionnaire(String vspId, String versionId, String user) {
+ QuestionnaireResponse questionnaireResponse =
+ vendorSoftwareProductManager.getVspQuestionnaire(vspId, new Version(versionId));
+
+ if (questionnaireResponse.getErrorMessage() != null) {
+ return Response.status(Response.Status.EXPECTATION_FAILED).entity(
+ new MapQuestionnaireResponseToQuestionnaireResponseDto()
+ .applyMapping(questionnaireResponse, QuestionnaireResponseDto.class)).build();
+ }
- ValidationResponse validationResponse = vendorSoftwareProductManager.validate(vspId, version);
- Map<String, List<ErrorMessage>> compilationErrors =
- vendorSoftwareProductManager.compile(vspId, version);
- if (!validationResponse.isValid() || MapUtils.isNotEmpty(compilationErrors)) {
+ QuestionnaireResponseDto result = new MapQuestionnaireResponseToQuestionnaireResponseDto()
+ .applyMapping(questionnaireResponse, QuestionnaireResponseDto.class);
+ return Response.ok(result).build();
+ }
- activityLogManager.logActivity(
- new ActivityLogEntity(vspId, version, ActivityType.Submit, user, false,
- "Failed on validation before submit", ""));
- return Optional.of(validationResponse);
+ @Override
+ public Response updateQuestionnaire(String questionnaireData, String vspId, String
+ versionId, String user) {
+ vendorSoftwareProductManager
+ .updateVspQuestionnaire(vspId, new Version(versionId), questionnaireData);
+ return Response.ok().build();
}
- versioningManager.submit(vspId, version, message);
-
- activityLogManager.logActivity(
- new ActivityLogEntity(vspId, version, ActivityType.Submit, user, true, "", message));
- return Optional.empty();
- }
-
- private void notifyUsers(String itemId, String itemName, Version version, String message,
- String userName, NotificationEventTypes eventType) {
- Map<String, Object> eventProperties = new HashMap<>();
- eventProperties
- .put(ITEM_NAME, itemName == null ? itemManager.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_ID, version.getId());
+ @Override
+ public Response heal(String vspId, String versionId, String user) {
+ HealingManagerFactory.getInstance().createInterface()
+ .healItemVersion(vspId, new Version(versionId), ItemType.vsp, true);
+ return Response.ok().build();
}
- eventProperties.put(SUBMIT_DESCRIPTION, message);
- eventProperties.put(PERMISSION_USER, userName);
+ @Override
+ public Response getVspInformationArtifact(String vspId, String versionId, String user) {
+ File textInformationArtifact =
+ vendorSoftwareProductManager.getInformationArtifact(vspId, new Version(versionId));
- Event syncEvent = new SyncEvent(eventType.getEventName(), itemId, eventProperties, itemId);
- try {
- notifier.notifySubscribers(syncEvent, userName);
- } catch (Exception e) {
- LOGGER.error("Failed to send sync notification to users subscribed o item '" + itemId);
+ Response.ResponseBuilder response = Response.ok(textInformationArtifact);
+ if (textInformationArtifact == null) {
+ return Response.status(Response.Status.NOT_FOUND).build();
+ }
+ response
+ .header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + textInformationArtifact.getName());
+ return response.build();
}
- }
- private class SyncEvent implements Event {
+ @Override
+ public Response listComputes(String vspId, String version, String user) {
+
+ Collection<ComputeEntity> computes =
+ vendorSoftwareProductManager.getComputeByVsp(vspId, new Version(version));
- private final String eventType;
- private final String originatorId;
- private final Map<String, Object> attributes;
- private final String entityId;
+ MapComputeEntityToVspComputeDto mapper = new MapComputeEntityToVspComputeDto();
+ GenericCollectionWrapper<VspComputeDto> results = new GenericCollectionWrapper<>();
+ for (ComputeEntity compute : computes) {
+ results.add(mapper.applyMapping(compute, VspComputeDto.class));
+ }
- SyncEvent(String eventType, String originatorId,
- Map<String, Object> attributes, String entityId) {
- this.eventType = eventType;
- this.originatorId = originatorId;
- this.attributes = attributes;
- this.entityId = entityId;
+ return Response.ok(results).build();
}
- @Override
- public String getEventType() {
- return eventType;
+ private Optional<ValidationResponse> submit(String vspId, Version version, String message,
+ String user) throws IOException {
+
+ ValidationResponse validationResponse = vendorSoftwareProductManager.validate(vspId, version);
+ Map<String, List<ErrorMessage>> compilationErrors =
+ vendorSoftwareProductManager.compile(vspId, version);
+ if (!validationResponse.isValid() || MapUtils.isNotEmpty(compilationErrors)) {
+
+ activityLogManager.logActivity(
+ new ActivityLogEntity(vspId, version, ActivityType.Submit, user, false,
+ "Failed on validation before submit", ""));
+ return Optional.of(validationResponse);
+ }
+
+ versioningManager.submit(vspId, version, message);
+
+ activityLogManager.logActivity(
+ new ActivityLogEntity(vspId, version, ActivityType.Submit, user, true, "", message));
+ return Optional.empty();
}
- @Override
- public String getOriginatorId() {
- return originatorId;
+ private void notifyUsers(String itemId, String itemName, Version version, String message,
+ String userName, NotificationEventTypes eventType) {
+ Map<String, Object> eventProperties = new HashMap<>();
+ eventProperties
+ .put(ITEM_NAME, itemName == null ? itemManager.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_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);
+ } catch (Exception e) {
+ LOGGER.error("Failed to send sync notification to users subscribed o item '" + itemId, e);
+ }
}
- @Override
- public Map<String, Object> getAttributes() {
- return attributes;
+ private Response createPackage(String vspId, Version version) throws IOException {
+ Version retrievedVersion = versioningManager.get(vspId, version);
+ if (retrievedVersion.getStatus() != VersionStatus.Certified) {
+ throw new CoreException(
+ new CreatePackageForNonFinalVendorSoftwareProductErrorBuilder(vspId, version)
+ .build());
+ }
+ PackageInfo packageInfo =
+ vendorSoftwareProductManager.createPackage(vspId, retrievedVersion);
+ return Response.ok(packageInfo == null
+ ? null
+ : new MapPackageInfoToPackageInfoDto().applyMapping(packageInfo, PackageInfoDto.class))
+ .build();
}
- @Override
- public String getEntityId() {
- return entityId;
+ private void addNetworkPackageInfo(String vspId, Version version, VspDetailsDto vspDetailsDto) {
+ OrchestrationTemplateCandidateData candidateInfo =
+ OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface()
+ .getInfo(vspId, version);
+ if (Objects.nonNull(candidateInfo) && Objects.nonNull(candidateInfo.getFileSuffix())) {
+ vspDetailsDto.setValidationData(candidateInfo.getValidationDataStructure());
+ vspDetailsDto.setNetworkPackageName(candidateInfo.getFileName());
+ vspDetailsDto.setCandidateOnboardingOrigin(candidateInfo.getFileSuffix());
+ } else {
+ OrchestrationTemplateEntity orchestrationTemplateInfo =
+ vendorSoftwareProductManager.getOrchestrationTemplateInfo(vspId, version);
+ if (Objects.nonNull(orchestrationTemplateInfo) && Objects.nonNull(orchestrationTemplateInfo
+ .getFileSuffix())) {
+ vspDetailsDto.setValidationData(orchestrationTemplateInfo.getValidationDataStructure());
+ vspDetailsDto.setNetworkPackageName(orchestrationTemplateInfo.getFileName());
+ vspDetailsDto.setOnboardingOrigin(orchestrationTemplateInfo.getFileSuffix());
+ }
+ }
}
- }
-
- private Response createPackage(String vspId, Version version) throws IOException {
- Version retrievedVersion = versioningManager.get(vspId, version);
- if (retrievedVersion.getStatus() != VersionStatus.Certified) {
- throw new CoreException(
- new CreatePackageForNonFinalVendorSoftwareProductErrorBuilder(vspId, version)
- .build());
+
+ private boolean userHasPermission(String itemId, String userId) {
+ String permission = permissionsManager.getUserItemPermission(itemId, userId);
+ return permission != null && permission
+ .matches(PermissionTypes.Contributor.name() + "|" + PermissionTypes.Owner.name());
}
- PackageInfo packageInfo =
- vendorSoftwareProductManager.createPackage(vspId, retrievedVersion);
- return Response.ok(packageInfo == null
- ? null
- : new MapPackageInfoToPackageInfoDto().applyMapping(packageInfo, PackageInfoDto.class))
- .build();
- }
-
- private void addNetworkPackageInfo(String vspId, Version version, VspDetailsDto vspDetailsDto) {
- OrchestrationTemplateCandidateData candidateInfo =
- OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface()
- .getInfo(vspId, version);
- if (Objects.nonNull(candidateInfo) && Objects.nonNull(candidateInfo.getFileSuffix())) {
- vspDetailsDto.setValidationData(candidateInfo.getValidationDataStructure());
- vspDetailsDto.setNetworkPackageName(candidateInfo.getFileName());
- vspDetailsDto.setCandidateOnboardingOrigin(candidateInfo.getFileSuffix());
- } else {
- OrchestrationTemplateEntity orchestrationTemplateInfo =
- vendorSoftwareProductManager.getOrchestrationTemplateInfo(vspId, version);
- if (Objects.nonNull(orchestrationTemplateInfo) && Objects.nonNull(orchestrationTemplateInfo
- .getFileSuffix())) {
- vspDetailsDto.setValidationData(orchestrationTemplateInfo.getValidationDataStructure());
- vspDetailsDto.setNetworkPackageName(orchestrationTemplateInfo.getFileName());
- vspDetailsDto.setOnboardingOrigin(orchestrationTemplateInfo.getFileSuffix());
- }
+
+ private Predicate<Item> createItemPredicate(String versionStatus,
+ String itemStatus,
+ String user) {
+ Predicate<Item> itemPredicate = item -> ItemType.vsp.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 boolean userHasPermission(String itemId, String userId) {
- String permission = permissionsManager.getUserItemPermission(itemId, userId);
- return permission != null && permission
- .matches(PermissionTypes.Contributor.name() + "|" + PermissionTypes.Owner.name());
- }
-
-
- private Predicate<Item> createItemPredicate(String versionStatus,
- String itemStatus,
- String user) {
- Predicate<Item> itemPredicate = item -> ItemType.vsp.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));
- }
+ private List<Item> getVspList(String versionStatus, String itemStatus, String user) {
+
+ Predicate<Item> itemPredicate = createItemPredicate(versionStatus, itemStatus, user);
+
+ return itemManager.list(itemPredicate).stream()
+ .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())).
+ collect(Collectors.toList());
}
- return itemPredicate;
- }
- private List<Item> getVspList(String versionStatus, String itemStatus, String user) {
+ private class SyncEvent implements Event {
+
+ private final String eventType;
+
+ private final String originatorId;
+ private final Map<String, Object> attributes;
+ private final String entityId;
- Predicate<Item> itemPredicate = createItemPredicate(versionStatus, itemStatus, user);
+ SyncEvent(String eventType, String originatorId,
+ Map<String, Object> attributes, String entityId) {
+ this.eventType = eventType;
+ this.originatorId = originatorId;
+ this.attributes = attributes;
+ this.entityId = entityId;
+ }
- return itemManager.list(itemPredicate).stream()
- .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())).
- collect(Collectors.toList());
+ @Override
+ public String getEventType() {
+ return eventType;
+ }
- }
+ @Override
+ public String getOriginatorId() {
+ return originatorId;
+ }
+
+ @Override
+ public Map<String, Object> getAttributes() {
+ return attributes;
+ }
+
+ @Override
+ public String getEntityId() {
+ return entityId;
+ }
+ }
}