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.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 java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Predicate;
-import javax.inject.Named;
-import javax.ws.rs.core.Response;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.dao.UniqueValueDaoFactory;
import org.openecomp.core.util.UniqueValueUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Predicate;
+
+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.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;
+
@Named
@Service("vendorSoftwareProducts")
@Scope(value = "prototype")
private static ItemCreationDto validationVsp;
- private final AsdcItemManager asdcItemManager = AsdcItemManagerFactory.getInstance()
+ private final AsdcItemManager itemManager = AsdcItemManagerFactory.getInstance()
.createInterface();
private final ItemPermissionsManager permissionsManager =
ItemPermissionsManagerFactory.getInstance().createInterface();
itemCreationDto = getItemCreationDto(vspRequestDto, user, onboardingMethod);
} else {
- throwUnknownOnboardingMethodException(new IllegalArgumentException("Wrong parameter Onboarding Method"));
+ throwUnknownOnboardingMethodException(
+ new IllegalArgumentException("Wrong parameter Onboarding Method"));
}
return Response.ok(itemCreationDto).build();
item.addProperty(VspItemProperty.ONBOARDING_METHOD, onboardingMethod.name());
uniqueValueUtil.validateUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName());
- item = asdcItemManager.create(item);
+ item = itemManager.create(item);
uniqueValueUtil.createUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName());
Version version = versioningManager.create(item.getId(), new Version(), null);
private void throwUnknownOnboardingMethodException(IllegalArgumentException e) {
ErrorCode onboardingMethodUpdateErrorCode = OnboardingMethodErrorBuilder
.getInvalidOnboardingMethodErrorBuilder();
- throw new CoreException(onboardingMethodUpdateErrorCode,e);
+ throw new CoreException(onboardingMethodUpdateErrorCode, e);
}
@Override
GenericCollectionWrapper<VspDetailsDto> results = new GenericCollectionWrapper<>();
MapItemToVspDetailsDto mapper = new MapItemToVspDetailsDto();
- asdcItemManager.list(itemPredicate).stream()
+ itemManager.list(itemPredicate).stream()
.sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime()))
.forEach(vspItem -> results.add(mapper.applyMapping(vspItem, VspDetailsDto.class)));
@Override
public Response deleteVsp(String vspId, String user) {
- Item vsp = asdcItemManager.get(vspId);
+ Item vsp = itemManager.get(vspId);
- if(!vsp.getType().equals(ItemType.vsp.name())){
+ 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()));
+ .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) {
- asdcItemManager.delete(vsp);
+ 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, "VSP was deleted", user,
} catch (CoreException validationVspAlreadyExistException) {
// find validationVsp
- String validationVspId = asdcItemManager.list(item ->
+ 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"))
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 ? asdcItemManager.get(itemId).getName() : itemName);
+ eventProperties
+ .put(ITEM_NAME, itemName == null ? itemManager.get(itemId).getName() : itemName);
eventProperties.put(ITEM_ID, itemId);
if (version != null) {
VspDetails getVsp(String vspId, Version version);
- void deleteVsp(String vspIdToDelete);
+ void deleteVsp(String vspId, Version version);
ValidationResponse validate(String vspId, Version version) throws IOException;
import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.VspMergeDao;
import org.openecomp.sdc.vendorsoftwareproduct.dao.errors.VendorSoftwareProductNotFoundErrorBuilder;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager {
+ private final VspMergeDao vspMergeDao;
private final OrchestrationTemplateDao orchestrationTemplateDao;
private final OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager;
private final VendorSoftwareProductInfoDao vspInfoDao;
private final UniqueValueUtil uniqueValueUtil;
public VendorSoftwareProductManagerImpl(
+ VspMergeDao vspMergeDao,
OrchestrationTemplateDao orchestrationTemplateDataDao,
OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager,
VendorSoftwareProductInfoDao vspInfoDao,
ImageDao imageDao,
ManualVspToscaManager manualVspToscaManager,
UniqueValueDao uniqueValueDao) {
+ this.vspMergeDao = vspMergeDao;
this.orchestrationTemplateDao = orchestrationTemplateDataDao;
this.orchestrationTemplateCandidateManager = orchestrationTemplateCandidateManager;
this.vspInfoDao = vspInfoDao;
orchestrationTemplateDao.get(vspId, version);
ToscaServiceModel serviceModel =
serviceModelDao.getServiceModel(vspId, vspDetails.getVersion());
- if (!isOrchestrationTemplateExist(orchestrationTemplate)
- || !isServiceModelExist(serviceModel)) {
+ if (isOrchestrationTemplateMissing(orchestrationTemplate)
+ || isServiceModelMissing(serviceModel)) {
vspErrors.add(VendorSoftwareProductInvalidErrorBuilder
.vendorSoftwareProductMissingServiceModelErrorBuilder(vspDetails.getId(),
vspDetails.getVersion()));
.generateToscaModel(manualVspToscaManager.gatherVspInformation(vspId, version))
: serviceModelDao.getServiceModel(vspId, version);
- return compile(vspId, version, serviceModel);
+ return compile(vspId, version, serviceModel);
}
private boolean validateComponentDependencies(
if (!CollectionUtils.isEmpty(deploymentFlavors)) {
deploymentFlavors.forEach(deploymentFlavor -> {
DeploymentFlavorEntity deployment = deploymentFlavorDao.get(deploymentFlavor);
- DeploymentFlavor deploymentlocalFlavor = deployment.getDeploymentFlavorCompositionData();
- if (deploymentlocalFlavor != null) {
- if (deploymentlocalFlavor.getFeatureGroupId() == null) {
+ DeploymentFlavor deploymentLocalFlavor = deployment.getDeploymentFlavorCompositionData();
+ if (deploymentLocalFlavor != null) {
+ if (deploymentLocalFlavor.getFeatureGroupId() == null) {
ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder.
- getFeatureGroupMandatoryErrorBuilder(deploymentlocalFlavor.getModel());
+ getFeatureGroupMandatoryErrorBuilder(deploymentLocalFlavor.getModel());
errorCodeList.add(deploymentFlavorErrorBuilder);
}
- validateComponetComputeAssociations(errorCodeList, deploymentFlavor,
- deployment, deploymentlocalFlavor);
+ validateComponentComputeAssociations(errorCodeList, deploymentFlavor,
+ deployment, deploymentLocalFlavor);
}
});
}
return errorCodeList;
}
- private void validateComponetComputeAssociations(Collection<ErrorCode> errorCodeList,
- DeploymentFlavorEntity deploymentFlavor,
- DeploymentFlavorEntity deployment,
- DeploymentFlavor deploymentlocalFlavor) {
- List<ComponentComputeAssociation> componetComputeAssociations =
+ private void validateComponentComputeAssociations(Collection<ErrorCode> errorCodeList,
+ DeploymentFlavorEntity deploymentFlavor,
+ DeploymentFlavorEntity deployment,
+ DeploymentFlavor deploymentlocalFlavor) {
+ List<ComponentComputeAssociation> componentComputeAssociations =
deploymentlocalFlavor.getComponentComputeAssociations();
- if (CollectionUtils.isEmpty(componetComputeAssociations)) {
+ if (CollectionUtils.isEmpty(componentComputeAssociations)) {
CompositionEntityValidationData compositionEntityValidationData = new
CompositionEntityValidationData(CompositionEntityType.deployment, deploymentFlavor
.getId());
errorCodeList.add(deploymentFlavorErrorBuilder);
} else {
- componetComputeAssociations.forEach(componetComputeAssociation -> {
- if (componetComputeAssociation == null
- || !(componetComputeAssociation.getComponentId() != null
- && componetComputeAssociation.getComputeFlavorId() != null)) {
+ componentComputeAssociations.forEach(componentComputeAssociation -> {
+ if (componentComputeAssociation == null
+ || !(componentComputeAssociation.getComponentId() != null
+ && componentComputeAssociation.getComputeFlavorId() != null)) {
CompositionEntityValidationData compositionEntityValidationData = new
CompositionEntityValidationData(CompositionEntityType.deployment,
deploymentFlavor.getId());
private Map<String, List<ErrorMessage>> compile(String vendorSoftwareProductId, Version version,
ToscaServiceModel serviceModel) {
- if (!isServiceModelExist(serviceModel)) {
+ if (isServiceModelMissing(serviceModel)) {
return null;
}
VspDetails retrieved = vspInfoDao.get(vspDetails);
if (retrieved == null) {
throw new CoreException((new ErrorCode.ErrorCodeBuilder()
- .withMessage(String.format("Vsp with id %s and version %s does not exist.",
- vspDetails.getId(), vspDetails.getVersion().getId()))).build());
+ .withMessage(String.format("Vsp with id %s and version %s does not exist.",
+ vspDetails.getId(), vspDetails.getVersion().getId()))).build());
}
vspDetails.setOnboardingMethod(retrieved.getOnboardingMethod());
@Override
public VspDetails getVsp(String vspId, Version version) {
- return getValidatedVsp(vspId, version);
+ return getValidatedVsp(vspId, version);
}
private VspDetails getValidatedVsp(String vspId, Version version) {
}
@Override
- public void deleteVsp(String vspId) {
- throw new UnsupportedOperationException(
- VendorSoftwareProductConstants.UNSUPPORTED_OPERATION_ERROR);
+ public void deleteVsp(String vspId, Version version) {
+ vspMergeDao.deleteHint(vspId, version);
}
@Override
}
@Override
-
public byte[] getOrchestrationTemplateFile(String vspId, Version version) {
OrchestrationTemplateEntity uploadData = orchestrationTemplateDao.get(vspId, version);
ByteBuffer contentData = uploadData.getContentData();
private Map<String, List<ErrorMessage>> validateOrchestrationTemplate(
OrchestrationTemplateEntity orchestrationTemplate) throws IOException {
- if (!isOrchestrationTemplateExist(orchestrationTemplate)) {
+ if (isOrchestrationTemplateMissing(orchestrationTemplate)) {
return null;
}
Map<String, List<ErrorMessage>> validationErrors = new HashMap<>();
return computeDao.listByVsp(vspId, version);
}
- private boolean isOrchestrationTemplateExist(OrchestrationTemplateEntity orchestrationTemplate) {
- return orchestrationTemplate != null
- && orchestrationTemplate.getContentData() != null
- && orchestrationTemplate.getFileSuffix() != null
- && orchestrationTemplate.getFileName() != null;
+ private boolean isOrchestrationTemplateMissing(OrchestrationTemplateEntity orchestrationTemplate) {
+ return orchestrationTemplate == null
+ || orchestrationTemplate.getContentData() == null
+ || orchestrationTemplate.getFileSuffix() == null
+ || orchestrationTemplate.getFileName() == null;
}
- private boolean isServiceModelExist(ToscaServiceModel serviceModel) {
- return serviceModel != null && serviceModel.getEntryDefinitionServiceTemplate() != null;
+ private boolean isServiceModelMissing(ToscaServiceModel serviceModel) {
+ return serviceModel == null || serviceModel.getEntryDefinitionServiceTemplate() == null;
}
}
import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory;
import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDaoFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.ComputeDaoFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDaoFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDaoFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory;
+import org.openecomp.sdc.vendorsoftwareproduct.dao.*;
import org.openecomp.sdc.vendorsoftwareproduct.factory.InformationArtifactGeneratorFactory;
public class VspManagerFactoryImpl extends VspManagerFactory {
private static final VendorSoftwareProductManager INSTANCE =
new VendorSoftwareProductManagerImpl(
+ VspMergeDaoFactory.getInstance().createInterface(),
OrchestrationTemplateDaoFactory.getInstance().createInterface(),
OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface(),
VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(),
orchestrationTemplateDataDao.update(vspDetails.getId(), vspDetails.getVersion(), uploadData);
VspMergeDaoFactory.getInstance().createInterface()
- .updateVspModelId(vspDetails.getId(), vspDetails.getVersion());
+ .updateHint(vspDetails.getId(), vspDetails.getVersion());
}
public void saveServiceModel(String vspId, Version version,
import org.openecomp.sdc.vendorsoftwareproduct.dao.VspMergeDao;
import org.openecomp.sdc.versioning.dao.types.Version;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
.of(OrchestrationTemplateCandidateContent, OrchestrationTemplateValidationData)
.collect(Collectors.toSet());
private static final Map<ElementType, Set<ElementType>> ELEMENT_TYPE_TO_CONFLICT_DEPENDANT_TYPES =
- new HashMap<>();
+ new EnumMap<>(ElementType.class);
static {
ELEMENT_TYPE_TO_CONFLICT_DEPENDANT_TYPES.put(OrchestrationTemplateCandidate,
@Override
public boolean isConflicted(String itemId, Version version) {
- return vspMergeDao.isVspModelConflicted(itemId, version);
+ return vspMergeDao.isConflicted(itemId, version);
}
@Override
public void finalizeMerge(String itemId, Version version) {
if (!conflictsDao.isConflicted(itemId, version)) {
- vspMergeDao.applyVspModelConflictResolution(itemId, version);
+ vspMergeDao.applyConflictResolution(itemId, version);
}
}
}
}
- if (!vspModelConflicted && vspMergeDao.isVspModelConflicted(itemId, version)) {
+ if (!vspModelConflicted && vspMergeDao.isConflicted(itemId, version)) {
elementConflicts
.add(new ConflictInfo(VSP_MODEL_CONFLICT_ID, NetworkPackage, NetworkPackage.name()));
}
public boolean resolveConflict(String itemId, Version version, String conflictId,
ConflictResolution resolution) {
if (VSP_MODEL_CONFLICT_ID.equals(conflictId)) {
- vspMergeDao.updateVspModelConflictResolution(itemId, version,
+ vspMergeDao.updateConflictResolution(itemId, version,
com.amdocs.zusammen.datatypes.item.Resolution.valueOf(resolution.getResolution().name()));
return true;
}
throw getConflictNotExistException(itemId, version, conflictId);
}
if (conflict.getType() == VspModel) {
- vspMergeDao.updateVspModelConflictResolution(itemId, version,
+ vspMergeDao.updateConflictResolution(itemId, version,
com.amdocs.zusammen.datatypes.item.Resolution.valueOf(resolution.getResolution().name()));
conflictsDao.resolveConflict(itemId, version, conflictId, new ConflictResolution(
public interface VspMergeDao {
- boolean isVspModelConflicted(String vspId, Version version);
+ boolean isConflicted(String vspId, Version version);
- void updateVspModelId(String vspId, Version version);
+ void updateHint(String vspId, Version version);
+
+ void deleteHint(String vspId, Version version);
// TODO: 11/7/2017 change to sdc Resolution
- void updateVspModelConflictResolution(String vspId, Version version, Resolution resolution);
+ void updateConflictResolution(String vspId, Version version, Resolution resolution);
- void applyVspModelConflictResolution(String vspId, Version version);
+ void applyConflictResolution(String vspId, Version version);
}
}
@Override
- public boolean isVspModelConflicted(String vspId, Version version) {
+ public boolean isConflicted(String vspId, Version version) {
SessionContext context = createSessionContext();
ElementContext elementContext = new ElementContext(new Id(vspId), new Id(version.getId()));
}
@Override
- public void updateVspModelId(String vspId, Version version) {
+ public void updateHint(String vspId, Version version) {
SessionContext context = createSessionContext();
ElementContext elementContext = new ElementContext(new Id(vspId), new Id(version.getId()));
}
@Override
- public void updateVspModelConflictResolution(String vspId, Version version,
- Resolution resolution) {
+ public void deleteHint(String vspId, Version version) {
+ accessor.delete(getUser(),vspId,version.getId());
+ }
+
+ @Override
+ public void updateConflictResolution(String vspId, Version version,
+ Resolution resolution) {
accessor.updateModelResolution(resolution, getUser(), vspId, version.getId());
}
@Override
- public void applyVspModelConflictResolution(String vspId, Version version) {
+ public void applyConflictResolution(String vspId, Version version) {
//called only when no conflicts
SessionContext context = createSessionContext();
}
String user = getUser();
- Row row = accessor.getModelMergeHint(user, vspId, version.getId()).one();
+ Row row = accessor.get(user, vspId, version.getId()).one();
if (row == null) {
throw new IllegalStateException(
"Vsp model id must exists if its conflict is being resolved");
String chosenModelId =
keepOnlyChosenVspModel(context, elementContext, vspModels, resolution, localModelId);
- accessor.updateModelMergeHint(chosenModelId, null, user, vspId, version.getId());
+ accessor.update(chosenModelId, null, user, vspId, version.getId());
}
private String keepOnlyChosenVspModel(SessionContext context, ElementContext elementContext,
}
private void updateVspModelId(String vspId, Version version, String vspModelId) {
- accessor.updateModelMergeHint(vspModelId, null, getUser(), vspId, version.getId());
+ accessor.update(vspModelId, null, getUser(), vspId, version.getId());
}
private String getUser() {
@Accessor
interface VspMergeHintAccessor {
+ @Query("SELECT model_id, model_resolution FROM vsp_merge_hint " +
+ "WHERE space=? AND item_id=? AND version_id=?")
+ ResultSet get(String space, String itemId, String versionId);
+
@Query("UPDATE vsp_merge_hint SET model_id=?, model_resolution=? " +
"WHERE space=? AND item_id=? AND version_id=?")
- void updateModelMergeHint(String vspModelId, Resolution modelResolution, String space,
- String itemId, String versionId);
+ void update(String vspModelId, Resolution modelResolution, String space,
+ String itemId, String versionId);
@Query(
"UPDATE vsp_merge_hint SET model_resolution=? WHERE space=? AND item_id=? AND version_id=?")
void updateModelResolution(Resolution modelResolution, String space, String itemId,
String versionId);
- @Query("SELECT model_id, model_resolution FROM vsp_merge_hint " +
- "WHERE space=? AND item_id=? AND version_id=?")
- ResultSet getModelMergeHint(String space, String itemId, String versionId);
+ @Query("DELETE from vsp_merge_hint WHERE space=? AND item_id=? AND version_id=?")
+ void delete(String space, String itemId, String versionId);
}
}