aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/services
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/services')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiService.java63
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java435
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/CategoryParameterService.java18
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/CategoryParameterServiceImpl.java144
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementService.java32
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java303
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/CsvService.java15
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java250
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java164
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/RoleGeneratorService.java5
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/VidService.java17
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java79
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/WorkflowService.java9
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/WorkflowServiceImpl.java40
14 files changed, 1574 insertions, 0 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java
new file mode 100644
index 000000000..4e86281c6
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java
@@ -0,0 +1,63 @@
+package org.onap.vid.services;
+
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.onap.vid.aai.AaiResponse;
+import org.onap.vid.aai.SubscriberFilteredResults;
+import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
+import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
+import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
+import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
+import org.onap.vid.asdc.beans.Service;
+import org.onap.vid.model.ServiceInstanceSearchResult;
+import org.onap.vid.model.SubscriberList;
+import org.onap.vid.roles.RoleValidator;
+
+import javax.ws.rs.core.Response;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by Oren on 7/4/17.
+ */
+public interface AaiService {
+
+
+ SubscriberFilteredResults getFullSubscriberList(RoleValidator roleValidator);
+
+ AaiResponse getSubscriberData(String subscriberId, RoleValidator roleValidator);
+
+ AaiResponse getServiceInstanceSearchResults(String subscriberId, String instanceIdentifier, RoleValidator roleProvider, List<String> owningEntities, List<String> projects);
+
+ AaiResponse<SubscriberList> getFullSubscriberList();
+
+ AaiResponse getServices(RoleValidator roleValidator);
+
+ AaiResponse getAaiZones();
+
+ AaiResponse<OperationalEnvironmentList> getOperationalEnvironments(String operationalEnvironmentType, String operationalEnvironmentStatus);
+
+ AaiResponse getAicZoneForPnf(String globalCustomerId , String serviceType , String serviceId);
+
+ Response getVNFData(String globalSubscriberId, String serviceType);
+
+ AaiResponse<GetTenantsResponse[]> getTenants(String globalCustomerId, String serviceType, RoleValidator roleValidator);
+
+ AaiResponse getVNFData(String globalSubscriberId, String serviceType, String serviceInstanceId);
+
+ AaiResponse getNodeTemplateInstances(String globalCustomerId, String serviceType, String modelVersionId, String modelInvariantId, String cloudRegion);
+
+ Response getVersionByInvariantId(List<String> modelInvariantId);
+
+ Collection<Service> getServicesByDistributionStatus();
+
+ AaiResponse<Pnf> getSpecificPnf(String pnfId);
+
+ List<String> getServiceInstanceAssociatedPnfs(String globalCustomerId, String serviceType, String serviceInstanceId);
+
+ AaiResponse getPNFData(String globalCustomerId, String serviceType, String modelVersionId, String modelInvariantId, String cloudRegion, String equipVendor, String equipModel);
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
new file mode 100644
index 000000000..ffb43803c
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
@@ -0,0 +1,435 @@
+package org.onap.vid.services;
+
+import org.apache.http.HttpStatus;
+import org.onap.vid.aai.model.AaiGetAicZone.AicZones;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.vid.aai.*;
+import org.onap.vid.aai.ServiceInstance;
+import org.onap.vid.aai.ServiceSubscription;
+import org.onap.vid.aai.Services;
+import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
+import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
+import org.onap.vid.aai.model.AaiGetServicesRequestModel.GetServicesAAIRespone;
+import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
+import org.onap.vid.aai.model.*;
+import org.onap.vid.asdc.beans.Service;
+import org.onap.vid.model.ServiceInstanceSearchResult;
+import org.onap.vid.model.SubscriberList;
+import org.onap.vid.roles.RoleValidator;
+import org.onap.vid.utils.Intersection;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.ws.rs.core.Response;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Created by Oren on 7/4/17.
+ */
+public class AaiServiceImpl implements AaiService {
+ private String serviceInstanceId = "service-instance.service-instance-id";
+ private String serviceType = "service-subscription.service-type";
+ private String customerId = "customer.global-customer-id";
+ private String serviceInstanceName = "service-instance.service-instance-name";
+ private int indexOfSubscriberName = 6;
+
+ @Autowired
+ private AaiClientInterface aaiClient;
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AaiServiceImpl.class);
+
+ private List<Service> convertModelToService(Model model) {
+ List<Service> services = new ArrayList<>();
+ String category = "";
+
+ if(validateModel(model)){
+ if(model.getModelType() != null)
+ category = model.getModelType();
+
+ for (ModelVer modelVer: model.getModelVers().getModelVer()) {
+ Service service = new Service();
+ if (modelVer.getModelVersionId() != null)
+ service.setUuid(modelVer.getModelVersionId());
+ if(model.getModelInvariantId() != null)
+ service.setInvariantUUID(model.getModelInvariantId());
+ if(modelVer.getModelVersion() != null)
+ service.setVersion(modelVer.getModelVersion());
+ if(modelVer.getModelName() != null)
+ service.setName(modelVer.getModelName());
+ if(modelVer.getDistributionStatus() != null)
+ service.setDistributionStatus(Service.DistributionStatus.valueOf(modelVer.getDistributionStatus()));
+ service.setCategory(category);
+
+ services.add(service);
+ }
+ } else {
+ return null;
+ }
+
+ return services;
+ }
+
+ private boolean validateModel(Model model){
+ if(model != null){
+ if(model.getModelVers() != null && model.getModelVers().getModelVer() != null && model.getModelVers().getModelVer().get(0).getModelVersionId() != null){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private List<ServiceInstanceSearchResult> getServicesByOwningEntityId(List<String> owningEntities, RoleValidator roleValidator) {
+ AaiResponse<OwningEntityResponse> owningEntityResponse = aaiClient.getServicesByOwningEntityId(owningEntities);
+ List<ServiceInstanceSearchResult> serviceInstanceSearchResultList = new ArrayList<>();
+ if (owningEntityResponse.getT() != null) {
+ for (OwningEntity owningEntity : owningEntityResponse.getT().getOwningEntity()) {
+ if (owningEntity.getRelationshipList() != null) {
+ serviceInstanceSearchResultList = convertRelationshipToSearchResult(owningEntity, serviceInstanceSearchResultList, roleValidator);
+ }
+ }
+ }
+ return serviceInstanceSearchResultList;
+ }
+
+ private List<ServiceInstanceSearchResult> getServicesByProjectNames(List<String> projectNames, RoleValidator roleValidator) {
+ AaiResponse<ProjectResponse> projectByIdResponse = aaiClient.getServicesByProjectNames(projectNames);
+ List<ServiceInstanceSearchResult> serviceInstanceSearchResultList = new ArrayList<>();
+ if (projectByIdResponse.getT() != null) {
+ for (Project project : projectByIdResponse.getT().getProject()) {
+ if (project.getRelationshipList() != null)
+ serviceInstanceSearchResultList = convertRelationshipToSearchResult(project, serviceInstanceSearchResultList, roleValidator);
+ }
+ }
+ return serviceInstanceSearchResultList;
+ }
+
+ private List<ServiceInstanceSearchResult> convertRelationshipToSearchResult(AaiRelationResponse owningEntityResponse, List<ServiceInstanceSearchResult> serviceInstanceSearchResultList, RoleValidator roleValidator) {
+ if (owningEntityResponse.getRelationshipList().getRelationship() != null) {
+ List<Relationship> relationshipList = owningEntityResponse.getRelationshipList().getRelationship();
+ for (Relationship relationship : relationshipList) {
+ ServiceInstanceSearchResult serviceInstanceSearchResult = new ServiceInstanceSearchResult();
+ extractRelationshipData(relationship, serviceInstanceSearchResult, roleValidator);
+ extractRelatedToProperty(relationship, serviceInstanceSearchResult);
+ serviceInstanceSearchResultList.add(serviceInstanceSearchResult);
+ }
+ }
+ return serviceInstanceSearchResultList;
+ }
+
+ private void extractRelationshipData(Relationship relationship, ServiceInstanceSearchResult serviceInstanceSearchResult, RoleValidator roleValidator) {
+ List<RelationshipData> relationshipDataList = relationship.getRelationDataList();
+ if (relationshipDataList != null) {
+ setSubscriberName(relationship, serviceInstanceSearchResult);
+ for (RelationshipData relationshipData : relationshipDataList) {
+ String key = relationshipData.getRelationshipKey();
+ if (key.equals(serviceInstanceId)) {
+ serviceInstanceSearchResult.setServiceInstanceId(relationshipData.getRelationshipValue());
+ } else if (key.equals(serviceType)) {
+ serviceInstanceSearchResult.setServiceType(relationshipData.getRelationshipValue());
+ } else if (key.equals(customerId)) {
+ serviceInstanceSearchResult.setGlobalCustomerId(relationshipData.getRelationshipValue());
+ }
+ }
+
+ boolean isPermitted = roleValidator.isServicePermitted(serviceInstanceSearchResult.getSubscriberName(), serviceInstanceSearchResult.getServiceType());
+ serviceInstanceSearchResult.setIsPermitted(isPermitted);
+ }
+ }
+
+ private void setSubscriberName(Relationship relationship, ServiceInstanceSearchResult serviceInstanceSearchResult) {
+ String relatedLink = relationship.getRelatedLink();
+ String[] subsciber = relatedLink.split("/");
+ serviceInstanceSearchResult.setSubscriberName(subsciber[indexOfSubscriberName]);
+ }
+
+ private void extractRelatedToProperty(Relationship relationship, ServiceInstanceSearchResult serviceInstanceSearchResult) {
+ List<RelatedToProperty> relatedToPropertyList = relationship.getRelatedToPropertyList();
+ if (relatedToPropertyList != null) {
+ for (RelatedToProperty relatedToProperty : relatedToPropertyList) {
+ if (relatedToProperty.getPropertyKey().equals(serviceInstanceName)) {
+ serviceInstanceSearchResult.setServiceInstanceName(relatedToProperty.getPropertyValue());
+ }
+ }
+ }
+ }
+
+ @Override
+ public SubscriberFilteredResults getFullSubscriberList(RoleValidator roleValidator) {
+ AaiResponse<SubscriberList> subscriberResponse = aaiClient.getAllSubscribers();
+ SubscriberFilteredResults subscriberFilteredResults =
+ new SubscriberFilteredResults(roleValidator, subscriberResponse.getT(),
+ subscriberResponse.getErrorMessage(),
+ subscriberResponse.getHttpCode());
+
+ return subscriberFilteredResults;
+ }
+
+ @Override
+ public AaiResponse<OperationalEnvironmentList> getOperationalEnvironments(String operationalEnvironmentType, String operationalEnvironmentStatus) {
+ AaiResponse<OperationalEnvironmentList> subscriberResponse = aaiClient.getOperationalEnvironments(operationalEnvironmentType, operationalEnvironmentStatus);
+ return subscriberResponse;
+ }
+
+ @Override
+ public AaiResponse<SubscriberList> getFullSubscriberList() {
+ AaiResponse<SubscriberList> subscriberResponse = aaiClient.getAllSubscribers();
+ return subscriberResponse;
+ }
+
+ @Override
+ public AaiResponse getSubscriberData(String subscriberId, RoleValidator roleValidator) {
+ AaiResponse<Services> subscriberResponse = aaiClient.getSubscriberData(subscriberId);
+ String subscriberGlobalId = subscriberResponse.getT().globalCustomerId;
+ for (ServiceSubscription serviceSubscription : subscriberResponse.getT().serviceSubscriptions.serviceSubscription) {
+ String serviceType = serviceSubscription.serviceType;
+ serviceSubscription.isPermitted = roleValidator.isServicePermitted(subscriberGlobalId, serviceType);
+ }
+ return subscriberResponse;
+
+ }
+
+ @Override
+ public AaiResponse getServiceInstanceSearchResults(String subscriberId, String instanceIdentifier, RoleValidator roleValidator, List<String> owningEntities, List<String> projects) {
+ List<List<ServiceInstanceSearchResult>> resultList = new ArrayList<>();
+ ServiceInstancesSearchResults serviceInstancesSearchResults = new ServiceInstancesSearchResults();
+
+ if (subscriberId != null || instanceIdentifier != null) {
+ resultList.add(getServicesBySubscriber(subscriberId, instanceIdentifier, roleValidator));
+ }
+ if (owningEntities != null) {
+ resultList.add(getServicesByOwningEntityId(owningEntities, roleValidator));
+ }
+ if (projects != null) {
+ resultList.add(getServicesByProjectNames(projects, roleValidator));
+ }
+ if (resultList.size() > 0) {
+ Intersection<ServiceInstanceSearchResult> intersection = new Intersection<>();
+ serviceInstancesSearchResults.serviceInstances = intersection.intersectMultipileArray(resultList);
+ }
+
+ return new AaiResponse<>(serviceInstancesSearchResults, null, HttpStatus.SC_OK);
+ }
+
+
+ private List<ServiceInstanceSearchResult> getServicesBySubscriber(String subscriberId, String instanceIdentifier, RoleValidator roleValidator) {
+ AaiResponse<Services> subscriberResponse = aaiClient.getSubscriberData(subscriberId);
+ String subscriberGlobalId = subscriberResponse.getT().globalCustomerId;
+ String subscriberName = subscriberResponse.getT().subscriberName;
+ ServiceSubscriptions serviceSubscriptions = subscriberResponse.getT().serviceSubscriptions;
+
+ return getSearchResultsForSubscriptions(serviceSubscriptions, subscriberId, instanceIdentifier, roleValidator, subscriberGlobalId, subscriberName);
+
+ }
+
+
+ private ArrayList<ServiceInstanceSearchResult> getSearchResultsForSubscriptions(ServiceSubscriptions serviceSubscriptions, String subscriberId, String instanceIdentifier, RoleValidator roleValidator, String subscriberGlobalId, String subscriberName) {
+ ArrayList<ServiceInstanceSearchResult> results = new ArrayList<>();
+
+ if (serviceSubscriptions != null) {
+ for (ServiceSubscription serviceSubscription : serviceSubscriptions.serviceSubscription) {
+ String serviceType = serviceSubscription.serviceType;
+ serviceSubscription.isPermitted = roleValidator.isServicePermitted(subscriberGlobalId, serviceType);
+ ArrayList<ServiceInstanceSearchResult> resultsForSubscription = getSearchResultsForSingleSubscription(serviceSubscription, subscriberId, instanceIdentifier, subscriberName, serviceType);
+ results.addAll(resultsForSubscription);
+ }
+ }
+
+ return results;
+ }
+
+ private ArrayList<ServiceInstanceSearchResult> getSearchResultsForSingleSubscription(ServiceSubscription serviceSubscription, String subscriberId, String instanceIdentifier, String subscriberName, String serviceType) {
+ ArrayList<ServiceInstanceSearchResult> results = new ArrayList<>();
+
+ if (serviceSubscription.serviceInstances != null) {
+ for (ServiceInstance serviceInstance : serviceSubscription.serviceInstances.serviceInstance) {
+ ServiceInstanceSearchResult serviceInstanceSearchResult =
+ new ServiceInstanceSearchResult(serviceInstance.serviceInstanceId, subscriberId, serviceType, serviceInstance.serviceInstanceName,
+ subscriberName, serviceInstance.modelInvariantId, serviceInstance.modelVersionId, serviceSubscription.isPermitted);
+
+ if (instanceIdentifier == null) {
+ results.add(serviceInstanceSearchResult);
+ } else if (serviceInstanceMatchesIdentifier(instanceIdentifier, serviceInstance)) {
+ results.add(serviceInstanceSearchResult);
+ }
+ }
+ }
+
+ return results;
+ }
+
+ private boolean serviceInstanceMatchesIdentifier(String instanceIdentifier, ServiceInstance serviceInstance) {
+ return instanceIdentifier.equals(serviceInstance.serviceInstanceId) || instanceIdentifier.equals(serviceInstance.serviceInstanceName);
+ }
+
+ @Override
+ public Response getVersionByInvariantId(List<String> modelInvariantId) {
+ try {
+ return aaiClient.getVersionByInvariantId(modelInvariantId);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ @Override
+ public AaiResponse<Pnf> getSpecificPnf(String pnfId) {
+ return aaiClient.getSpecificPnf(pnfId);
+ }
+
+ @Override
+ public AaiResponse getPNFData(String globalCustomerId, String serviceType, String modelVersionId, String modelInvariantId, String cloudRegion, String equipVendor, String equipModel) {
+ return aaiClient.getPNFData(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion, equipVendor, equipModel);
+ }
+
+
+
+ @Override
+ public AaiResponse getServices(RoleValidator roleValidator) {
+ AaiResponse<GetServicesAAIRespone> subscriberResponse = aaiClient.getServices();
+ if (subscriberResponse.getT() != null)
+ for (org.onap.vid.aai.model.AaiGetServicesRequestModel.Service service : subscriberResponse.getT().service) {
+ service.isPermitted = true;
+ }
+ return subscriberResponse;
+ }
+
+ @Override
+ public AaiResponse<GetTenantsResponse[]> getTenants(String globalCustomerId, String serviceType, RoleValidator roleValidator) {
+ AaiResponse<GetTenantsResponse[]> aaiGetTenantsResponse = aaiClient.getTenants(globalCustomerId, serviceType);
+ GetTenantsResponse[] tenants = aaiGetTenantsResponse.getT();
+ if (tenants != null) {
+ for (int i = 0; i < tenants.length; i++) {
+ tenants[i].isPermitted = roleValidator.isTenantPermitted(globalCustomerId, serviceType, tenants[i].tenantName);
+ }
+ }
+ return aaiGetTenantsResponse;
+
+
+ }
+
+ @Override
+ public AaiResponse getVNFData(String globalSubscriberId, String serviceType, String serviceInstanceId) {
+ return aaiClient.getVNFData(globalSubscriberId, serviceType, serviceInstanceId);
+ }
+
+ @Override
+ public Response getVNFData(String globalSubscriberId, String serviceType) {
+ return aaiClient.getVNFData(globalSubscriberId, serviceType);
+ }
+
+ @Override
+ public AaiResponse getAaiZones() {
+ AaiResponse<AicZones> response = aaiClient.getAllAicZones();
+ return response;
+ }
+
+ @Override
+ public AaiResponse getAicZoneForPnf(String globalCustomerId, String serviceType, String serviceId) {
+ String aicZone = "";
+
+ AaiResponse<ServiceRelationships> serviceInstanceResp = aaiClient.getServiceInstance(globalCustomerId, serviceType, serviceId);
+ if (serviceInstanceResp.getT() != null) {
+ List<String> aicZoneList = getRelationshipDataByType(serviceInstanceResp.getT().getRelationshipList(), "zone", "zone.zone-id");
+ if (aicZoneList.size() > 0) {
+ aicZone = aicZoneList.get(0);
+ } else {
+ logger.warn("aic zone not found for service instance " + serviceId);
+ }
+ } else {
+ if (serviceInstanceResp.getErrorMessage() != null) {
+ logger.error("get service instance " + serviceId + " return error", serviceInstanceResp.getErrorMessage());
+ return new AaiResponse(aicZone , serviceInstanceResp.getErrorMessage() ,serviceInstanceResp.getHttpCode());
+ } else {
+ logger.warn("get service instance " + serviceId + " return empty body");
+ return new AaiResponse(aicZone , "get service instance " + serviceId + " return empty body" ,serviceInstanceResp.getHttpCode());
+ }
+ }
+
+ return new AaiResponse(aicZone , null ,HttpStatus.SC_OK);
+ }
+
+ @Override
+ public AaiResponse getNodeTemplateInstances(String globalCustomerId, String serviceType, String modelVersionId, String modelInvariantId, String cloudRegion) {
+ return aaiClient.getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion);
+ }
+
+ @Override
+ public Collection<Service> getServicesByDistributionStatus() {
+ AaiResponse<GetServiceModelsByDistributionStatusResponse> serviceModelsByDistributionStatusResponse = aaiClient.getServiceModelsByDistributionStatus();
+ Collection<Service> services = new ArrayList<>();
+ if (serviceModelsByDistributionStatusResponse.getT() != null) {
+ List<Result> results = serviceModelsByDistributionStatusResponse.getT().getResults();
+ for (Result result : results) {
+ if(result.getModel() != null) {
+ List<Service> service = convertModelToService(result.getModel());
+ if (service != null) {
+ services.addAll(service);
+ }
+ }
+ }
+ }
+ return services;
+ }
+
+ @Override
+ public List<String> getServiceInstanceAssociatedPnfs(String globalCustomerId, String serviceType, String serviceInstanceId) {
+ List<String> pnfs = new ArrayList<>();
+
+ AaiResponse<ServiceRelationships> serviceInstanceResp = aaiClient.getServiceInstance(globalCustomerId, serviceType, serviceInstanceId);
+ if (serviceInstanceResp.getT() != null) {
+ List<String> logicalLinks = getRelationshipDataByType(serviceInstanceResp.getT().getRelationshipList(), "logical-link", "logical-link.link-name");
+ for (String logicalLink : logicalLinks) {
+ String link = "";
+ try {
+ link = URLEncoder.encode(logicalLink, "UTF-8");
+ AaiResponse<LogicalLinkResponse> logicalLinkResp = aaiClient.getLogicalLink(link);
+ if (logicalLinkResp.getT() != null) {
+ //lag-interface is the key for pnf - approved by Bracha
+ List<String> linkPnfs = getRelationshipDataByType(logicalLinkResp.getT().getRelationshipList(), "lag-interface", "pnf.pnf-name");
+ if (linkPnfs.size() > 0) {
+ pnfs.addAll(linkPnfs);
+ } else {
+ logger.warn("no pnf found for logical link " + logicalLink);
+ }
+ } else {
+ if (logicalLinkResp.getErrorMessage() != null) {
+ logger.error("get logical link " + logicalLink + " return error", logicalLinkResp.getErrorMessage());
+ } else {
+ logger.warn("get logical link " + logicalLink + " return empty body");
+ }
+ }
+ } catch (UnsupportedEncodingException e) {
+ logger.error("Failed to encode logical link: " + logicalLink, e.getMessage());
+ }
+ }
+ } else {
+ if (serviceInstanceResp.getErrorMessage() != null) {
+ logger.error("get service instance " + serviceInstanceId + " return error", serviceInstanceResp.getErrorMessage());
+ } else {
+ logger.warn("get service instance " + serviceInstanceId + " return empty body");
+ }
+ }
+
+ return pnfs.stream().distinct().collect(Collectors.toList());
+ }
+
+ private List<String> getRelationshipDataByType(RelationshipList relationshipList, String relationshipType, String relationshipDataKey) {
+ List<String> relationshipValues = new ArrayList<>();
+ for (Relationship relationship : relationshipList.getRelationship()) {
+ if (relationship.getRelatedTo().equals(relationshipType)) {
+ relationshipValues.addAll( relationship.getRelationDataList().stream()
+ .filter(rel -> rel.getRelationshipKey().equals(relationshipDataKey))
+ .map(RelationshipData::getRelationshipValue)
+ .collect(Collectors.toList())
+ );
+ }
+ }
+
+
+ return relationshipValues;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/CategoryParameterService.java b/vid-app-common/src/main/java/org/onap/vid/services/CategoryParameterService.java
new file mode 100644
index 000000000..a140007b0
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/CategoryParameterService.java
@@ -0,0 +1,18 @@
+package org.onap.vid.services;
+
+import java.io.IOException;
+
+import org.onap.vid.category.AddCategoryOptionResponse;
+import org.onap.vid.category.CategoryParameterOptionRep;
+import org.onap.vid.category.CategoryParametersResponse;
+import org.onap.vid.category.AddCategoryOptionsRequest;
+import org.onap.vid.model.CategoryParameterOption;
+import org.onap.vid.model.CategoryParameter.Family;
+
+public interface CategoryParameterService {
+
+ CategoryParametersResponse getCategoryParameters(Family familyName) throws IOException;
+ AddCategoryOptionResponse createCategoryParameterOptions(String categoryName, AddCategoryOptionsRequest option) throws IOException;
+ AddCategoryOptionResponse updateCategoryParameterOption(String categoryName, CategoryParameterOptionRep option);
+ void deleteCategoryOption(String categoryName, CategoryParameterOption option) throws IOException;
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/CategoryParameterServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/CategoryParameterServiceImpl.java
new file mode 100644
index 000000000..02d3521dc
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/CategoryParameterServiceImpl.java
@@ -0,0 +1,144 @@
+package org.onap.vid.services;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.service.DataAccessService;
+import org.onap.vid.category.AddCategoryOptionResponse;
+import org.onap.vid.category.CategoryParameterOptionRep;
+import org.onap.vid.model.CategoryParameter;
+import org.onap.vid.model.CategoryParameterOption;
+import org.onap.vid.category.AddCategoryOptionsRequest;
+import org.onap.vid.category.CategoryParametersResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.onap.vid.model.CategoryParameter.Family;
+
+import javax.ws.rs.ForbiddenException;
+
+
+@Service
+public class CategoryParameterServiceImpl implements CategoryParameterService {
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(CategoryParameterServiceImpl.class);
+
+ public static class UnfoundedCategoryException extends RuntimeException {
+
+ public UnfoundedCategoryException(String message) {
+ super(message);
+ }
+ }
+
+ public static class UnfoundedCategoryOptionException extends RuntimeException {
+
+ public UnfoundedCategoryOptionException(String message) {
+ super(message);
+ }
+ }
+
+ public static class AlreadyExistOptionNameException extends RuntimeException {
+
+ public AlreadyExistOptionNameException(String message) {
+ super(message);
+ }
+ }
+
+ @Override
+ public CategoryParametersResponse getCategoryParameters(Family familyName) throws IOException {
+ List<CategoryParameter> categoryParameters = dataAccessService.getList(CategoryParameter.class, String.format(" where family = '%s' ",familyName), null, null);
+ return convertToCategoryParametersResponse(categoryParameters);
+ }
+
+ private CategoryParametersResponse convertToCategoryParametersResponse(List<CategoryParameter> categoryParameters) {
+ Comparator<CategoryParameterOptionRep> comparator = Comparator.comparing(CategoryParameterOptionRep::getName, String.CASE_INSENSITIVE_ORDER);
+ Map<String, List<CategoryParameterOptionRep>> categoryParametersMap = categoryParameters.stream().collect(Collectors.toMap(
+ CategoryParameter::getName,
+ x -> x.getOptions().stream().map(opt -> new CategoryParameterOptionRep(opt.getAppId(), opt.getName())).sorted(comparator).collect(Collectors.toList())));
+ return new CategoryParametersResponse(categoryParametersMap);
+ }
+
+ @Override
+ public AddCategoryOptionResponse createCategoryParameterOptions(String categoryName, AddCategoryOptionsRequest optionsRequest) throws IOException, UnfoundedCategoryException {
+
+ AddCategoryOptionResponse response = new AddCategoryOptionResponse(new ArrayList<>());
+ CategoryParameter categoryParameter = getCategoryParameter(categoryName);
+ Set<String> categoryOptions = categoryParameter.getOptions().stream().map(CategoryParameterOption::getName).collect(Collectors.toSet());
+ for (String optionName : optionsRequest.options) {
+ if (categoryOptions.contains(optionName)) {
+ response.getErrors().add(String.format("Option %s already exist for category %s", optionName, categoryName));
+ continue;
+ }
+ String appId = categoryParameter.isIdSupported() ? UUID.randomUUID().toString() : optionName;
+ CategoryParameterOption categoryParameterOption = new CategoryParameterOption(appId, optionName, categoryParameter);
+ dataAccessService.saveDomainObject(categoryParameterOption, null);
+ }
+
+ return response;
+ }
+
+ private CategoryParameter getCategoryParameter( String categoryName) {
+ List<CategoryParameter> categoryParameters = dataAccessService.getList(CategoryParameter.class, String.format(" where name = '%s' ", categoryName), null, null);
+ if (categoryParameters.size() != 1) {
+ String msg = "There is no category parameter with name " + categoryName;
+ LOG.debug(msg);
+ throw new UnfoundedCategoryException(msg);
+ }
+
+
+ return categoryParameters.get(0);
+ }
+
+ @Override
+ public AddCategoryOptionResponse updateCategoryParameterOption(String categoryName, CategoryParameterOptionRep option) {
+ AddCategoryOptionResponse response = new AddCategoryOptionResponse(new ArrayList<>());
+ CategoryParameter categoryParameter = getCategoryParameter(categoryName);
+ if (!categoryParameter.isIdSupported()) {
+ String msg = "Updating option name for category: " + categoryName + ", is not allowed";
+ LOG.debug(msg);
+ throw new ForbiddenException(msg);
+ }
+ Optional<CategoryParameterOption> categoryParameterOptionOptional = categoryParameter.getOptions().stream().filter(x->x.getAppId().equals(option.getId())).findFirst();
+ if (!categoryParameterOptionOptional.isPresent()) {
+ String msg = "There is no option with id "+option.getId() + " for category " + categoryName;
+ LOG.debug(msg);
+ throw new UnfoundedCategoryOptionException(msg);
+ }
+ CategoryParameterOption categoryParameterOption = categoryParameterOptionOptional.get();
+ Optional<CategoryParameterOption> alreadyExistOptionWithName = categoryParameter.getOptions().stream().filter(x->x.getName().equals(option.getName())).findFirst();
+ if (alreadyExistOptionWithName.isPresent() && !alreadyExistOptionWithName.get().getAppId().equals(categoryParameterOption.getAppId())) {
+ String msg = "Option with name "+option.getName() + " already exist for category " + categoryName;
+ LOG.debug(msg);
+ throw new AlreadyExistOptionNameException(msg);
+ }
+
+ categoryParameterOption.setName(option.getName());
+ dataAccessService.saveDomainObject(categoryParameterOption, null);
+
+ return response;
+ }
+
+ @Override
+ public void deleteCategoryOption(String categoryName, CategoryParameterOption option) throws IOException {
+ List<CategoryParameter> categoryParameters = dataAccessService.getList(CategoryParameter.class, String.format(" where name = '%s'", categoryName), null, null);
+ if (categoryParameters.size() != 1) {
+ String msg = "There is no category parameter with name " + categoryName;
+ LOG.debug(msg);
+ throw new UnfoundedCategoryException(msg);
+ }
+ CategoryParameter categoryParameter = categoryParameters.get(0);
+ Set<CategoryParameterOption> categoryOptions = categoryParameter.getOptions();
+ for (CategoryParameterOption categoryOption: categoryOptions) {
+ if(categoryOption.getName().equals(option.getName()))
+ {
+ dataAccessService.deleteDomainObject(categoryOption, null);
+ }
+ }
+ }
+
+}
+
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementService.java b/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementService.java
new file mode 100644
index 000000000..bf0833182
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementService.java
@@ -0,0 +1,32 @@
+package org.onap.vid.services;
+
+import fj.data.Either;
+import org.apache.commons.lang3.tuple.Pair;
+import org.json.JSONObject;
+import org.onap.vid.changeManagement.*;
+import org.json.simple.JSONArray;
+import org.onap.vid.mso.rest.Request;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.Collection;
+import java.util.List;
+
+public interface ChangeManagementService {
+ Collection<Request> getMSOChangeManagements() throws Exception;
+ ResponseEntity<String> doChangeManagement(ChangeManagementRequest request, String vnfName) throws Exception;
+ JSONArray getSchedulerChangeManagements();
+
+ /**
+ * Deleting a scheduled flow.
+ * @param scheduleId - the ID of the schedule.
+ * @return - a pair, left - String representation of the response, right - response code.
+ */
+ Pair<String, Integer> deleteSchedule(String scheduleId);
+ VnfWorkflowRelationResponse addVnfWorkflowRelation(VnfWorkflowRelationRequest vnfWorkflowRelationRequest);
+ List<String> getWorkflowsForVnf(GetVnfWorkflowRelationRequest getVnfWorkflowRelationRequest);
+ VnfWorkflowRelationResponse deleteVnfWorkflowRelation(VnfWorkflowRelationRequest vnfWorkflowRelationRequest);
+ VnfWorkflowRelationAllResponse getAllVnfWorkflowRelations();
+ String uploadConfigUpdateFile(MultipartFile file) throws Exception;
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java
new file mode 100644
index 000000000..078f44945
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java
@@ -0,0 +1,303 @@
+package org.onap.vid.services;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.hibernate.NonUniqueObjectException;
+import org.json.JSONObject;
+import org.json.simple.JSONArray;
+import org.json.simple.parser.JSONParser;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.service.DataAccessService;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.onap.vid.changeManagement.*;
+import org.onap.vid.exceptions.NotFoundException;
+import org.onap.vid.model.VNFDao;
+import org.onap.vid.model.VidWorkflow;
+import org.onap.vid.mso.MsoBusinessLogic;
+import org.onap.vid.mso.MsoResponseWrapperInterface;
+import org.onap.vid.mso.rest.Request;
+import org.onap.vid.scheduler.SchedulerProperties;
+import org.onap.vid.scheduler.SchedulerRestInterfaceFactory;
+import org.onap.vid.scheduler.SchedulerRestInterfaceIfc;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.ws.rs.BadRequestException;
+import java.util.*;
+import java.util.stream.Collectors;
+
+
+@Service
+public class ChangeManagementServiceImpl implements ChangeManagementService {
+
+ private final static String primaryKey = "payload";
+ private final static Set<String> requiredKeys = new HashSet<>(Arrays.asList("request-parameters", "configuration-parameters"));
+ private final DataAccessService dataAccessService;
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ChangeManagementServiceImpl.class);
+ private MsoBusinessLogic msoBusinessLogic;
+ @Autowired
+ private CsvService csvService;
+
+ @Autowired
+ public ChangeManagementServiceImpl(DataAccessService dataAccessService, MsoBusinessLogic msoBusinessLogic) {
+ this.dataAccessService = dataAccessService;
+ this.msoBusinessLogic = msoBusinessLogic;
+ }
+
+ @Override
+ public Collection<Request> getMSOChangeManagements() throws Exception {
+ Collection<Request> result = null;
+ return msoBusinessLogic.getOrchestrationRequestsForDashboard();
+ }
+
+ private RequestDetails findRequestByVnfName(List<RequestDetails> requests, String vnfName) {
+
+ if (requests == null)
+ return null;
+
+ for (RequestDetails requestDetails : requests) {
+ if (requestDetails.getVnfName().equals(vnfName)) {
+ return requestDetails;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public ResponseEntity<String> doChangeManagement(ChangeManagementRequest request, String vnfName) throws Exception {
+ if (request == null)
+ return null;
+ ResponseEntity<String> response;
+ RequestDetails currentRequestDetails = findRequestByVnfName(request.getRequestDetails(), vnfName);
+ MsoResponseWrapperInterface msoResponseWrapperObject = null;
+ if (currentRequestDetails != null) {
+
+ String serviceInstanceId = extractServiceInstanceId(currentRequestDetails, request.getRequestType());
+ String vnfInstanceId = extractVnfInstanceId(currentRequestDetails, request.getRequestType());
+ String requestType = request.getRequestType();
+ try {
+ switch (requestType.toLowerCase()) {
+ case ChangeManagementRequest.UPDATE: {
+ msoResponseWrapperObject = msoBusinessLogic.updateVnf(currentRequestDetails, serviceInstanceId, vnfInstanceId);
+ break;
+ }
+ case ChangeManagementRequest.REPLACE: {
+ msoResponseWrapperObject = msoBusinessLogic.replaceVnf(currentRequestDetails, serviceInstanceId, vnfInstanceId);
+ break;
+ }
+ case ChangeManagementRequest.VNF_IN_PLACE_SOFTWARE_UPDATE: {
+ msoResponseWrapperObject = msoBusinessLogic.updateVnfSoftware(currentRequestDetails, serviceInstanceId, vnfInstanceId);
+ break;
+ }
+ case ChangeManagementRequest.CONFIG_UPDATE: {
+ msoResponseWrapperObject = msoBusinessLogic.updateVnfConfig(currentRequestDetails, serviceInstanceId, vnfInstanceId);
+ break;
+ }
+ }
+ response = new ResponseEntity<String>(msoResponseWrapperObject.getResponse(), HttpStatus.OK);
+ return response;
+ } catch (Exception e) {
+ logger.error("Failure during doChangeManagement with request " + request.toString(), e);
+ throw e;
+ }
+
+ }
+
+ // AH:TODO: return ChangeManagementResponse
+ return null;
+ }
+
+ private String extractVnfInstanceId(RequestDetails currentRequestDetails, String requestType) {
+ if (currentRequestDetails.getVnfInstanceId() == null) {
+ logger.error("Failed to extract vnfInstanceId");
+ throw new BadRequestException("No vnfInstanceId in request " + requestType);
+ }
+ return currentRequestDetails.getVnfInstanceId();
+ }
+
+ private String extractServiceInstanceId(RequestDetails currentRequestDetails, String requestType) {
+ try {
+ String serviceInstanceId = currentRequestDetails.getRelatedInstList().get(0).getRelatedInstance().getInstanceId();
+ serviceInstanceId.toString(); //throw exception in case that serviceInstanceId is null...
+ return serviceInstanceId;
+ } catch (Exception e) {
+ logger.error("Failed to extract serviceInstanceId");
+ throw new BadRequestException("No instanceId in request " + requestType);
+ }
+ }
+
+ @Override
+ public JSONArray getSchedulerChangeManagements() {
+ JSONArray result = null;
+ try {
+ String path = SystemProperties.getProperty(SchedulerProperties.SCHEDULER_GET_SCHEDULES);
+ org.onap.vid.scheduler.RestObject<String> restObject = new org.onap.vid.scheduler.RestObject<>();
+ SchedulerRestInterfaceIfc restClient = SchedulerRestInterfaceFactory.getInstance();
+
+ String str = new String();
+ restObject.set(str);
+ restClient.Get(str, "", path, restObject);
+ String restCallResult = restObject.get();
+ JSONParser parser = new JSONParser();
+ Object parserResult = parser.parse(restCallResult);
+ result = (JSONArray) parserResult;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+
+ @Override
+ public Pair<String, Integer> deleteSchedule(String scheduleId) {
+ try {
+ String path = String.format(SystemProperties.getProperty(SchedulerProperties.SCHEDULER_DELETE_SCHEDULE), scheduleId);
+ org.onap.vid.scheduler.RestObject<String> restObject = new org.onap.vid.scheduler.RestObject<>();
+ SchedulerRestInterfaceIfc restClient = SchedulerRestInterfaceFactory.getInstance();
+ String str = new String();
+ restObject.set(str);
+ restClient.Delete(str, "", path, restObject);
+ String restCallResult = restObject.get();
+ return new ImmutablePair<>(restCallResult, restObject.getStatusCode());
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ return new ImmutablePair<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.value());
+ }
+ }
+
+ @Override
+ public VnfWorkflowRelationResponse addVnfWorkflowRelation(VnfWorkflowRelationRequest vnfWorkflowRelationRequest) {
+ VnfWorkflowRelationResponse vnfWorkflowRelationResponse = new VnfWorkflowRelationResponse();
+ for (WorkflowsDetail workflowsDetail : vnfWorkflowRelationRequest.getWorkflowsDetails()) {
+ if (StringUtils.isEmpty(workflowsDetail.getVnfDetails().getUUID()) ||
+ StringUtils.isEmpty(workflowsDetail.getVnfDetails().getInvariantUUID())) {
+ vnfWorkflowRelationResponse.getErrors().add("Using empty UUID or invariantUUID is not allowed. Relation details: " + workflowsDetail.toString());
+ continue;
+ }
+ @SuppressWarnings("unchecked") List<VNFDao> vnfList = dataAccessService.getList(VNFDao.class, getVnfQueryString(workflowsDetail.getVnfDetails().getUUID(), workflowsDetail.getVnfDetails().getInvariantUUID()), null, null);
+ if (vnfList.size() == 0) {
+ vnfList.add(saveNewVnf(workflowsDetail));
+ }
+ @SuppressWarnings("unchecked") List<VidWorkflow> workflowList = dataAccessService.getList(VidWorkflow.class, String.format(" where wokflowName = '%s'", workflowsDetail.getWorkflowName()), null, null);
+ if (workflowList.size() == 0) {
+ vnfWorkflowRelationResponse.getErrors().add("Not Found instance of workflow " + workflowsDetail.getWorkflowName() + " for vnf with UUID " + workflowsDetail.getVnfDetails().getUUID() + " and with invariantUUID " + workflowsDetail.getVnfDetails().getInvariantUUID());
+ continue;
+ }
+ vnfList.get(0).getWorkflows().add(workflowList.get(0));
+ try {
+ dataAccessService.saveDomainObject(vnfList.get(0), null);
+ } catch (NonUniqueObjectException e) {
+ //In case the relation already exists, we continue running on the list
+ }
+ }
+ return vnfWorkflowRelationResponse;
+ }
+
+ @Override
+ public VnfWorkflowRelationResponse deleteVnfWorkflowRelation(VnfWorkflowRelationRequest vnfWorkflowRelationRequest) {
+ VnfWorkflowRelationResponse vnfWorkflowRelationResponse = new VnfWorkflowRelationResponse();
+ for (WorkflowsDetail workflowsDetail : vnfWorkflowRelationRequest.getWorkflowsDetails()) {
+ @SuppressWarnings("unchecked") List<VNFDao> vnfList = dataAccessService.getList(VNFDao.class, getVnfQueryString(workflowsDetail.getVnfDetails().getUUID(), workflowsDetail.getVnfDetails().getInvariantUUID()), null, null);
+ if (vnfList.size() != 1) {
+ vnfWorkflowRelationResponse.getErrors().add("Found " + vnfList.size() + " instances of vnf with UUID " + workflowsDetail.getVnfDetails().getUUID() + " and vnfInvariantUUID " + workflowsDetail.getVnfDetails().getInvariantUUID());
+ continue;
+ }
+ VidWorkflow vidWorkflow = getWorkflowOfVnf(vnfList.get(0), workflowsDetail.getWorkflowName());
+ if (vidWorkflow == null) {
+ vnfWorkflowRelationResponse.getErrors().add("Not Found instance of workflow " + workflowsDetail.getWorkflowName() + " for vnf with UUID " + workflowsDetail.getVnfDetails().getUUID() + " and with invariantUUID " + workflowsDetail.getVnfDetails().getInvariantUUID());
+ continue;
+ }
+ vnfList.get(0).getWorkflows().remove(vidWorkflow);
+ dataAccessService.saveDomainObject(vnfList.get(0), null);
+ }
+ return vnfWorkflowRelationResponse;
+
+ }
+
+ @Override
+ public List<String> getWorkflowsForVnf(GetVnfWorkflowRelationRequest getVnfWorkflowRelationRequest) {
+ List<VNFDao> vnfDaoList = new ArrayList<>();
+ List<Set<String>> workflowsList = new ArrayList<>();
+ getVnfDaoList(vnfDaoList, getVnfWorkflowRelationRequest);
+ getWorkflowsList(workflowsList, vnfDaoList);
+ return intersectWorkflows(workflowsList);
+ }
+
+ private void getVnfDaoList(List<VNFDao> vnfDaoList, GetVnfWorkflowRelationRequest getVnfWorkflowRelationRequest) {
+ for (VnfDetails vnfDetails : getVnfWorkflowRelationRequest.getVnfDetails()) {
+ @SuppressWarnings("unchecked") List<VNFDao> vnfList = dataAccessService.getList(VNFDao.class, getVnfQueryString(vnfDetails.getUUID(), vnfDetails.getInvariantUUID()), null, null);
+ if (vnfList.size() != 1) {
+ throw new NotFoundException("Found" + vnfList.size() + " instances of vnf with UUID" + vnfDetails.getUUID() + " and vnfInvariantUUID" + vnfDetails.getInvariantUUID());
+ }
+ vnfDaoList.add(vnfList.get(0));
+ }
+ }
+
+ private void getWorkflowsList(List<Set<String>> workflowsList, List<VNFDao> vnfDaoList) {
+ for (VNFDao vnfDao : vnfDaoList) {
+ Set<String> tempWorkflows = vnfDao.getWorkflows().stream().map(VidWorkflow::getWokflowName).collect(Collectors.toSet());
+ workflowsList.add(tempWorkflows);
+ }
+ }
+
+ private List<String> intersectWorkflows(List<Set<String>> workflowsList) {
+ Set<String> workflows = workflowsList.get(0);
+ for (Set<String> workflow : workflowsList) {
+ workflows.retainAll(workflow);
+ }
+ return new ArrayList<>(workflows);
+ }
+
+ private String getVnfQueryString(String UUID, String invariantUUID) {
+ return " where vnfInvariantUUID = '" + invariantUUID + "' and vnfUUID = '" + UUID + "'";
+ }
+
+ private VidWorkflow getWorkflowOfVnf(VNFDao vnfDao, String workflowName) {
+ VidWorkflow vidWorkflowRes = null;
+ for (VidWorkflow vidWorkflow : vnfDao.getWorkflows()) {
+ if (vidWorkflow.getWokflowName().equals(workflowName)) {
+ vidWorkflowRes = vidWorkflow;
+ }
+ }
+ return vidWorkflowRes;
+ }
+
+ private VNFDao saveNewVnf(WorkflowsDetail workflowsDetail) {
+ VNFDao vnfDao = new VNFDao();
+ vnfDao.setVnfUUID(workflowsDetail.getVnfDetails().getUUID());
+ vnfDao.setVnfInvariantUUID(workflowsDetail.getVnfDetails().getInvariantUUID());
+ dataAccessService.saveDomainObject(vnfDao, null);
+ return vnfDao;
+ }
+
+ @Override
+ public VnfWorkflowRelationAllResponse getAllVnfWorkflowRelations() {
+ @SuppressWarnings("unchecked") List<VNFDao> vnfList = dataAccessService.getList(VNFDao.class, null);
+ return new VnfWorkflowRelationAllResponse(
+ vnfList.stream()
+ .map(VnfDetailsWithWorkflows::new)
+ .collect(Collectors.toList()));
+ }
+
+ @Override
+ public String uploadConfigUpdateFile(MultipartFile file)
+ throws Exception {
+ JSONObject json = csvService.convertCsvToJson(csvService.readCsv(file));
+ if (!validateJsonOutput(json))
+ throw new BadRequestException("Invalid csv file");
+ json = json.getJSONObject(primaryKey);
+ json = new JSONObject().put(primaryKey, json.toString());
+ return json.toString();
+ }
+
+ private boolean validateJsonOutput(org.json.JSONObject json) {
+ if (!json.has(primaryKey) || !json.getJSONObject(primaryKey).keySet().containsAll(requiredKeys))
+ return false;
+ return true;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/CsvService.java b/vid-app-common/src/main/java/org/onap/vid/services/CsvService.java
new file mode 100644
index 000000000..248068fba
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/CsvService.java
@@ -0,0 +1,15 @@
+package org.onap.vid.services;
+
+import org.json.JSONObject;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.List;
+
+public interface CsvService {
+ List<String[]> readCsv(String filePath) throws IOException;
+ JSONObject convertCsvToJson (List<String[]> myEntries) throws InstantiationException, IllegalAccessException;
+ List<String[]> readCsv(MultipartFile file) throws IOException;
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java
new file mode 100644
index 000000000..8152dae04
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/CsvServiceImpl.java
@@ -0,0 +1,250 @@
+//package org.onap.vid.services;
+//
+////import com.opencsv.CSVReader;
+//import org.json.JSONArray;
+//import org.json.JSONObject;
+//import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+//import org.springframework.stereotype.Service;
+//import org.springframework.web.multipart.MultipartFile;
+//
+//import javax.ws.rs.BadRequestException;
+//import java.io.FileNotFoundException;
+//import java.io.FileReader;
+//import java.io.IOException;
+//import java.io.InputStreamReader;
+//import java.util.ArrayList;
+//import java.util.Arrays;
+//import java.util.List;
+//
+//import static org.onap.vid.utils.Logging.getMethodName;
+//
+//@Service
+//public class CsvServiceImpl implements CsvService{
+//
+//
+// /** The logger. */
+// static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CsvServiceImpl.class);
+//
+// private static final String arrayRegex = "\\[(.*?)\\]";
+//
+//
+// /**
+// * In UTF-8 the first line starts with "\uFEFF" so need to remove it
+// * @param line is first line contains BOM
+// * @return line after change
+// */
+// private String [] removeBOMFromCsv(String [] line){
+// if (line.length>0)
+// line[0] = line[0].replaceFirst("\uFEFF","").replaceFirst("","");
+// return line;
+// }
+//
+// /**
+// * read a csv file and puts its content in list of string arrays (without the empty lines)
+// * @param filePath - the path of file to read
+// * @return the content of file
+// * @throws IOException
+// */
+// /*@Override
+// public List<String[]> readCsv(String filePath) throws IOException {
+// CSVReader reader = new CSVReader(new FileReader(filePath));
+// return readCsv(reader);
+// }
+//
+// @Override
+// public List<String[]> readCsv(MultipartFile file) throws IOException {
+// CSVReader reader = new CSVReader(new InputStreamReader(file.getInputStream()));
+// return readCsv(reader);
+// }
+//
+// private List<String[]> addLineWithoutSpaces(List<String[]> myEntries, String [] line){
+// line = Arrays.stream(line).filter(x -> !"".equals(x)).toArray(String[]::new);
+// if(line.length > 0)
+// myEntries.add(line);
+// return myEntries;
+// }
+//
+//
+// private List<String[]> readCsv(CSVReader reader) throws IOException {
+// try {
+// List<String[]> myEntries = new ArrayList<>() ;
+// String [] line;
+// Boolean firstLine = true;
+// while ((line = reader.readNext())!= null) {
+// if (firstLine) {
+// line = removeBOMFromCsv(line);
+// firstLine = false;
+// }
+// myEntries = addLineWithoutSpaces(myEntries, line);
+// }
+// return myEntries;
+// }
+// catch (Exception e){
+// logger.error("error during reading CSV file. exception:" + e.getMessage());
+// throw e;
+// }
+//
+// }*/
+//
+// /**
+// * main function that call to the recursive function with initial parameters
+// * @param myEntries - the matrix with file content
+// * @return the json
+// * @throws IOException
+// * @throws InstantiationException
+// * @throws IllegalAccessException
+// */
+// @Override
+// public JSONObject convertCsvToJson (List<String[]> myEntries) throws InstantiationException, IllegalAccessException {
+// try {
+// return buildJSON(myEntries, 0, 0, myEntries.size(), JSONObject.class);
+// }
+// catch (Exception e){
+// logger.error("error during parsing CSV file. exception:" + e.getMessage());
+// throw e;
+// }
+//
+// }
+//
+// /**
+// * it goes over the matrix column while the values are the same and returns the index of changed value
+// * @param myEntries the matrix
+// * @param i row index refer to the whole matrix
+// * @param j column index
+// * @param numLines the length of the current inner matrix
+// * @param startLine row index of inner matrix
+// * @return the index of changed line
+// */
+// private int findIndexOfChangedLine(List<String[]> myEntries, final int i, final int j, final int numLines, final int startLine) {
+// int k;
+// for(k = 0; k + i - startLine < numLines && myEntries.get(i)[j].equals(myEntries.get(k + i)[j]) ; k++);
+// return k;
+// }
+//
+// /**
+// * check in array if its first element or if the key already exist in the previous item
+// * @param jsonArray - the array to search in
+// * @param key - the key to check
+// * @return if exists or first element return true, otherwise- false
+// */
+// private Boolean keyExistsOrFirstElement( JSONArray jsonArray,String key){
+// Boolean exists = false;
+// Boolean first = false;
+// JSONObject lastItem = lastItemInArray(jsonArray);
+// if (lastItem == null) {
+// first = true;
+// }
+// else {
+// if (lastItem.has(key)) {
+// exists = true;
+// }
+// }
+// return exists||first;
+// }
+//
+// /**
+// * return last json in json array
+// * @param jsonArray
+// * @return last item or null if the array is empty
+// */
+// private JSONObject lastItemInArray(JSONArray jsonArray){
+// JSONObject lastItem = null;
+// if(jsonArray.length()>0) {
+// lastItem = (JSONObject) jsonArray.get(jsonArray.length() - 1);
+// }
+// return lastItem;
+// }
+//
+// /**
+// * append current json to the main json
+// * @param json - the main json to append to it
+// * @param key - key to append
+// * @param values - value(s) to append
+// * @param <T> can be JSONObject or JSONArray
+// * @param <E> string or jsonObject or jsonArray
+// * @return json after put
+// * @throws IllegalAccessException
+// * @throws InstantiationException
+// */
+// private <T, E> T putJson(T json, String key, E values) throws IllegalAccessException, InstantiationException {
+// if (json instanceof JSONArray){
+// JSONArray currentJson= ((JSONArray)json);
+// if (values == null) //array of strings (for last item)
+// {
+// currentJson.put(key);
+// }
+// else {
+// if (keyExistsOrFirstElement(currentJson, key)) {
+// currentJson.put(new JSONObject().put(key, values));
+// } else {
+// JSONObject lastItem = lastItemInArray(currentJson);
+// lastItem.put(key, values);
+// }
+// }
+// }
+// if (json instanceof JSONObject){
+// if (values == null)
+// throw new BadRequestException("Invalid csv file");
+// ((JSONObject)json).put(key,values);
+// }
+// return json;
+// }
+//
+//
+// /**
+// * recursive function to build JSON. Each time it counts the same values in left and send the smaller matrix
+// * (until the changed value) to the next time.
+// *
+// * @param myEntries - the whole matrix
+// * @param i- row index of the whole matrix
+// * @param j - column index
+// * @param numLines - number of lines of inner matrix (num of same values in the left column)
+// * @param clazz JSONArray or JSONObject
+// * @param <T> JSONArray or JSONObject
+// * @return the json object
+// * @throws IllegalAccessException
+// * @throws InstantiationException
+// */
+// private <T> T buildJSON(List<String[]> myEntries, int i, final int j, final int numLines, Class<T> clazz) throws IllegalAccessException, InstantiationException {
+// logger.debug(EELFLoggerDelegate.debugLogger, "start {}({}, {}, {})", getMethodName(), i, j, numLines);
+// T json = clazz.newInstance();
+// int startLine = i;
+// while(i < numLines + startLine){
+// String[] currentRow = myEntries.get(i);
+// int length = currentRow.length;
+// int currentDuplicateRows = findIndexOfChangedLine(myEntries,i,j,numLines, startLine);
+// String key = currentRow[j];
+// if (j == length-1) {
+// json = putJson(json,currentRow[j],null);
+//
+// }
+// else
+// {
+// if (key.matches(arrayRegex)){
+// JSONArray arrayObjects = buildJSON(myEntries, i, j + 1, currentDuplicateRows, JSONArray.class);
+// json = putJson(json,key.replaceAll("\\[","").replaceAll("]",""),arrayObjects);
+// }
+// else {
+// if (j < length - 2) {
+// json = putJson(json, currentRow[j], buildJSON(myEntries, i, j + 1, currentDuplicateRows, JSONObject.class));
+// }
+// else
+// {
+// if (j == length - 2)//last object
+// {
+// if(currentDuplicateRows > 1) {
+// throw new BadRequestException("Invalid csv file");
+// }
+// json = putJson(json, currentRow[j], currentRow[j + 1]);
+// }
+// }
+// }
+// }
+// i += currentDuplicateRows;
+// }
+// logger.debug(EELFLoggerDelegate.debugLogger, "end {} json = {}", getMethodName(), json);
+// return json;
+// }
+//
+//}
+//
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java
new file mode 100644
index 000000000..ea2cea57b
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/RoleGenaratorServiceImpl.java
@@ -0,0 +1,164 @@
+package org.onap.vid.services;
+
+import jline.internal.Log;
+import org.junit.Test;
+import org.onap.vid.aai.*;
+import org.onap.vid.model.ModelConstants;
+import org.onap.vid.model.Subscriber;
+import org.onap.vid.model.SubscriberList;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+
+@Service
+public class RoleGenaratorServiceImpl implements RoleGeneratorService {
+
+ @Autowired
+ AaiClientInterface client;
+
+ public static final String dbName = "vid_portal";
+ public static final String tblName = "fn_role";
+ public static final String tempDelimiter ="***";
+ public static final String oldDelimiter = "_";
+
+ @Override
+ public String generateRoleScript(Boolean firstRun) {
+ String query = "USE " + dbName + ";\r\n" +
+ "SET SQL_SAFE_UPDATES = 0;\r\n";
+ try {
+ AaiResponse<SubscriberList> subscribers = client.getAllSubscribers();
+ if (firstRun) {
+ query += replaceRolesToTempDelimiter("subscriber",buildSubscribersValuesForMappingsTable(subscribers.getT()));
+ }
+ query += addAvailableRolesCombination(firstRun, subscribers);
+
+ }
+ catch (Exception e) {
+ Log.error("There was an error in updating roles "+e.getMessage());
+ }
+ return query;
+ }
+
+ private String addAvailableRolesCombination(Boolean firstRun, AaiResponse<SubscriberList> subscribers) {
+ String query, availableRoles="";
+ HashMap<String,String> servicesNames = new HashMap<String,String>();
+ for (Subscriber subscriber: subscribers.getT().customer) {
+ AaiResponse<Services> subscriberResponse = client.getSubscriberData(subscriber.globalCustomerId);
+ for(ServiceSubscription service: subscriberResponse.getT().serviceSubscriptions.serviceSubscription) {
+ servicesNames.put(service.serviceType,"");
+ String roleName = "'" + subscriber.subscriberName + ModelConstants.ROLE_DELIMITER + service.serviceType + "'";
+ availableRoles += "("+roleName+"),";
+
+
+ }
+ }
+ availableRoles = availableRoles.substring(0,availableRoles.length()-1);
+ query = createTemporaryTableAvailableRoles(availableRoles);
+ if (firstRun){
+ query += replaceRolesToTempDelimiter("service",buildServicesValuesForMappingsTable(servicesNames));
+ query += replaceToNewDelimiter();
+ query += deleteWrongRecords();
+
+ }
+ query += insertAvailableRolesToFnRole();
+ query += dropTemporaryTable("available_roles");
+ return query;
+ }
+
+ private String buildSubscribersValuesForMappingsTable(SubscriberList subscribers){
+ String query="";
+ for (Subscriber subscriber : subscribers.customer) {
+ String subscriberName = subscriber.subscriberName.contains(oldDelimiter) ? subscriber.subscriberName.replace(oldDelimiter, tempDelimiter) : subscriber.subscriberName;
+ query = query + "('" + subscriber.globalCustomerId + "','" + subscriberName + "') ,";
+ }
+ if(query.length() > 0)
+ query = query.substring(0, query.length()-1) + ";\r\n";
+ return query;
+ }
+
+ private String buildServicesValuesForMappingsTable(HashMap<String,String> servicesNames){
+ final String[] query = {""};
+ servicesNames.forEach((k,v)->{
+ if (k.contains(oldDelimiter)) {
+ query[0] += "('" + k + "' ,'" + k.replace(oldDelimiter, tempDelimiter) +"'),";
+ }
+ });
+ if(query[0].length() > 0)
+ query[0] = query[0].substring(0, query[0].length()-1) + ";\r\n";
+ return query[0];
+ }
+
+ private String replaceRolesToTempDelimiter(String entityName, String valuesForMappingsTable ) {
+
+ AaiResponse<Services> services = client.getServices();
+ String query = "";
+ if (valuesForMappingsTable.length() > 0) {
+ query = "CREATE TEMPORARY TABLE IF NOT EXISTS " + entityName + "Mappings(mapKey VARCHAR(255),mapValue VARCHAR(255));\r\n" +
+ "INSERT INTO " + entityName + "Mappings VALUES ";
+ query += valuesForMappingsTable;
+ query += "UPDATE " + tblName + "\r\n" +
+ "INNER JOIN " + entityName + "Mappings ON role_name LIKE concat('%',mapKey, '%')\r\n" +
+ "SET ROLE_NAME = REPLACE(ROLE_NAME, mapKey, mapValue) ; \r\n" +
+ dropTemporaryTable(entityName + "Mappings");
+ }
+ return query;
+ }
+
+ private String replaceToNewDelimiter(){
+ String query = "UPDATE " + tblName + "\r\n" +
+ "SET ROLE_NAME = REPLACE(ROLE_NAME, '" + oldDelimiter + "', '" + ModelConstants.ROLE_DELIMITER + "');\r\n" ;
+ query += "UPDATE fn_role\r\n" +
+ "SET ROLE_NAME = REPLACE(ROLE_NAME, '" + tempDelimiter + "', '" + oldDelimiter + "');\r\n" ;
+ return query;
+ }
+
+ private String insertAvailableRolesToFnRole(){
+ String query="INSERT INTO fn_role (ROLE_NAME, ACTIVE_YN, PRIORITY)\r\n" +
+ "SELECT RNAME, 'Y', 5\r\n" +
+ "FROM available_roles\r\n" +
+ "WHERE NOT EXISTS (SELECT ROLE_NAME\r\n" +
+ "FROM fn_role \r\n" +
+ "where RNAME = ROLE_NAME);\r\n";
+ return query;
+ }
+
+
+
+ private String createTemporaryTableAvailableRoles(String availableRoles) {
+ String query = "CREATE TEMPORARY TABLE IF NOT EXISTS available_roles(rname VARCHAR(255));\r\n";
+ query += "INSERT INTO available_roles VALUES "+availableRoles+";\r\n";
+ return query;
+ }
+
+ private String deleteWrongRecords(){
+ String query ="CREATE TEMPORARY TABLE IF NOT EXISTS wrong_roles(roleID INT);\r\n" +
+ "INSERT INTO wrong_roles (roleID)\r\n" +
+ "SELECT ROLE_ID FROM fn_role LEFT JOIN available_roles ON role_name LIKE concat(rname, '%')\r\n" +
+ "WHERE available_roles.rname IS NULL AND ROLE_ID NOT IN (1,16);\r\n";
+ query += deleteCascade();
+ query += dropTemporaryTable("wrong_roles");
+ return query;
+ }
+
+ private String deleteCascade() {
+ String query = deleteFromTableByRoles("fn_role_composite", "PARENT_ROLE_ID");
+ query = query.substring(0, query.length()-1);
+ query += " OR wrong_roles.ROLEID = fn_role_composite.CHILD_ROLE_ID;\r\n";
+ query += deleteFromTableByRoles("fn_role_function", "ROLE_ID")+ "\r\n";
+ query += deleteFromTableByRoles("fn_user_role", "ROLE_ID")+ "\r\n";
+ query += deleteFromTableByRoles("fn_role", "ROLE_ID")+ "\r\n";
+ return query;
+ }
+
+ private String deleteFromTableByRoles(String table, String column) {
+ String query = "DELETE FROM " + table + "\r\n";
+ query += "using " + table + " inner join wrong_roles\r\n" +
+ "where wrong_roles.ROLEID = " + table + "." + column + ";";
+ return query;
+ }
+
+ private String dropTemporaryTable(String table) {
+ return "DROP TEMPORARY TABLE IF EXISTS " + table + ";\r\n";
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/RoleGeneratorService.java b/vid-app-common/src/main/java/org/onap/vid/services/RoleGeneratorService.java
new file mode 100644
index 000000000..2bc96a5b2
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/RoleGeneratorService.java
@@ -0,0 +1,5 @@
+package org.onap.vid.services;
+
+public interface RoleGeneratorService {
+ String generateRoleScript(Boolean firstRun);
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/VidService.java b/vid-app-common/src/main/java/org/onap/vid/services/VidService.java
new file mode 100644
index 000000000..328fad019
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/VidService.java
@@ -0,0 +1,17 @@
+package org.onap.vid.services;
+
+import org.onap.vid.asdc.AsdcCatalogException;
+import org.onap.vid.asdc.beans.Service;
+import org.onap.vid.model.ServiceModel;
+
+import java.util.Collection;
+import java.util.Map;
+
+public interface VidService {
+
+ Collection<Service> getServices(Map<String, String[]> requestParams)
+ throws AsdcCatalogException;
+
+ ServiceModel getService(String uuid) throws AsdcCatalogException;
+
+} \ No newline at end of file
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java
new file mode 100644
index 000000000..81966439e
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/VidServiceImpl.java
@@ -0,0 +1,79 @@
+package org.onap.vid.services;
+
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.onap.vid.asdc.AsdcCatalogException;
+import org.onap.vid.asdc.AsdcClient;
+import org.onap.vid.asdc.beans.Service;
+import org.onap.vid.asdc.parser.ToscaParser;
+import org.onap.vid.asdc.parser.ToscaParserImpl;
+import org.onap.vid.asdc.parser.ToscaParserImpl2;
+import org.onap.vid.model.ServiceModel;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * The Class VidController.
+ */
+
+public class VidServiceImpl implements VidService {
+ /**
+ * The Constant LOG.
+ */
+ private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VidServiceImpl.class);
+ /**
+ * The Constant dateFormat.
+ */
+ protected final AsdcClient asdcClient;
+ @Autowired
+ private ToscaParserImpl2 toscaParser;
+
+ public VidServiceImpl(AsdcClient asdcClient) {
+ this.asdcClient = asdcClient;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.vid.controller.VidService#getServices(java.util.Map)
+ */
+ @Override
+ public Collection<Service> getServices(Map<String, String[]> requestParams)
+ throws AsdcCatalogException {
+ return asdcClient.getServices(requestParams);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.openecomp.vid.controller.VidService#getService(java.lang.String)
+ */
+ @Override
+ public ServiceModel getService(String uuid) throws AsdcCatalogException {
+ final Path serviceCsar = asdcClient.getServiceToscaModel(UUID.fromString(uuid));
+ ToscaParser tosca = new ToscaParserImpl();
+ serviceCsar.toFile().getAbsolutePath();
+ ServiceModel serviceModel = null;
+ try {
+ final Service asdcServiceMetadata = asdcClient.getService(UUID.fromString(uuid));
+ return getServiceModel(uuid, serviceCsar, tosca, asdcServiceMetadata);
+ } catch (Exception e) {
+ LOG.error("Failed to download and proccess service from ASDC", e);
+ }
+ return serviceModel;
+ }
+
+ private ServiceModel getServiceModel(String uuid, Path serviceCsar, ToscaParser tosca, Service asdcServiceMetadata) throws Exception {
+ try {
+ return toscaParser.makeServiceModel(serviceCsar, asdcServiceMetadata);
+ } catch (SdcToscaParserException e) {
+ return tosca.makeServiceModel(uuid, serviceCsar, asdcServiceMetadata);
+ }
+ }
+
+
+} \ No newline at end of file
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/WorkflowService.java b/vid-app-common/src/main/java/org/onap/vid/services/WorkflowService.java
new file mode 100644
index 000000000..ea139080f
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/WorkflowService.java
@@ -0,0 +1,9 @@
+package org.onap.vid.services;
+
+import org.onap.vid.model.Workflow;
+import java.util.Collection;
+
+public interface WorkflowService {
+ Collection<String> getWorkflowsForVNFs(Collection<String> vnfNames);
+ Collection<String> getAllWorkflows();
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/WorkflowServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/WorkflowServiceImpl.java
new file mode 100644
index 000000000..037c49c17
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/WorkflowServiceImpl.java
@@ -0,0 +1,40 @@
+package org.onap.vid.services;
+
+import org.onap.vid.model.Workflow;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+@Service
+public class WorkflowServiceImpl implements WorkflowService {
+ //TODO: Add the list of workflows hard coded or from DB.
+ private ArrayList<Workflow> workflows = new ArrayList<>(Arrays.asList(
+ new Workflow(0, "Upgrade", new ArrayList<>(Arrays.asList("VNF1", "VNF2", "VNF3", "VNF4"))),
+ new Workflow(1, "Clean", new ArrayList<>(Arrays.asList("VNF1", "VNF2", "VNF3"))),
+ new Workflow(2, "Reinstall", new ArrayList<>(Arrays.asList("VNF1", "VNF2", "VNF4"))),
+ new Workflow(3, "Dump", new ArrayList<>(Arrays.asList("VNF1", "VNF3", "VNF4"))),
+ new Workflow(4, "Flush", new ArrayList<>(Arrays.asList("VNF2", "VNF3", "VNF4")))
+ ));
+
+ @Override
+ public Collection<String> getWorkflowsForVNFs(Collection<String> vnfNames) {
+ Collection<String> result = workflows.stream()
+ .filter(workflow -> workflow.getVnfNames().containsAll(vnfNames))
+ .map(workflow -> workflow.getWorkflowName())
+ .distinct()
+ .collect(Collectors.toList());
+
+ return result;
+ }
+
+ @Override
+ public Collection<String> getAllWorkflows() {
+ return workflows.stream()
+ .map(workflow -> workflow.getWorkflowName())
+ .distinct()
+ .collect(Collectors.toList());
+ }
+}