1c8114c2e84a1fac747d852fd75a6e35c652f754
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdcrests.vsp.rest.services;
18
19 import static javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION;
20 import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_USER;
21 import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME;
22 import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.VALIDATION_VSP_NAME;
23 import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_ID;
24 import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.ITEM_NAME;
25 import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.SUBMIT_DESCRIPTION;
26 import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_ID;
27 import static org.openecomp.sdc.versioning.VersioningNotificationConstansts.VERSION_NAME;
28
29 import java.io.File;
30 import java.io.IOException;
31 import java.util.Collection;
32 import java.util.Comparator;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Objects;
37 import java.util.Optional;
38 import java.util.function.Predicate;
39 import javax.inject.Named;
40 import javax.ws.rs.core.Response;
41 import org.apache.commons.collections4.MapUtils;
42 import org.openecomp.core.dao.UniqueValueDaoFactory;
43 import org.openecomp.core.util.UniqueValueUtil;
44 import org.openecomp.sdc.activitylog.ActivityLogManager;
45 import org.openecomp.sdc.activitylog.ActivityLogManagerFactory;
46 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
47 import org.openecomp.sdc.activitylog.dao.type.ActivityType;
48 import org.openecomp.sdc.common.errors.CoreException;
49 import org.openecomp.sdc.common.errors.ErrorCode;
50 import org.openecomp.sdc.common.errors.Messages;
51 import org.openecomp.sdc.datatypes.error.ErrorMessage;
52 import org.openecomp.sdc.datatypes.model.ItemType;
53 import org.openecomp.sdc.healing.factory.HealingManagerFactory;
54 import org.openecomp.sdc.itempermissions.ItemPermissionsManager;
55 import org.openecomp.sdc.itempermissions.ItemPermissionsManagerFactory;
56 import org.openecomp.sdc.itempermissions.impl.types.PermissionTypes;
57 import org.openecomp.sdc.logging.api.Logger;
58 import org.openecomp.sdc.logging.api.LoggerFactory;
59 import org.openecomp.sdc.notification.dtos.Event;
60 import org.openecomp.sdc.notification.factories.NotificationPropagationManagerFactory;
61 import org.openecomp.sdc.notification.services.NotificationPropagationManager;
62 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManagerFactory;
63 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
64 import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
65 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity;
66 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OnboardingMethod;
67 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
68 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity;
69 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
70 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
71 import org.openecomp.sdc.vendorsoftwareproduct.errors.CreatePackageForNonFinalVendorSoftwareProductErrorBuilder;
72 import org.openecomp.sdc.vendorsoftwareproduct.errors.OnboardingMethodErrorBuilder;
73 import org.openecomp.sdc.vendorsoftwareproduct.errors.PackageNotFoundErrorBuilder;
74 import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
75 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
76 import org.openecomp.sdc.versioning.AsdcItemManager;
77 import org.openecomp.sdc.versioning.AsdcItemManagerFactory;
78 import org.openecomp.sdc.versioning.VersioningManager;
79 import org.openecomp.sdc.versioning.VersioningManagerFactory;
80 import org.openecomp.sdc.versioning.dao.types.Version;
81 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
82 import org.openecomp.sdc.versioning.errors.RequestedVersionInvalidErrorBuilder;
83 import org.openecomp.sdc.versioning.types.Item;
84 import org.openecomp.sdc.versioning.types.NotificationEventTypes;
85 import org.openecomp.sdcrests.item.rest.mapping.MapVersionToDto;
86 import org.openecomp.sdcrests.item.types.ItemCreationDto;
87 import org.openecomp.sdcrests.item.types.VersionDto;
88 import org.openecomp.sdcrests.vendorsoftwareproducts.types.PackageInfoDto;
89 import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto;
90 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ValidationResponseDto;
91 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VendorSoftwareProductAction;
92 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VersionSoftwareProductActionRequestDto;
93 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspComputeDto;
94 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDescriptionDto;
95 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDetailsDto;
96 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspRequestDto;
97 import org.openecomp.sdcrests.vsp.rest.VendorSoftwareProducts;
98 import org.openecomp.sdcrests.vsp.rest.mapping.MapComputeEntityToVspComputeDto;
99 import org.openecomp.sdcrests.vsp.rest.mapping.MapItemToVspDetailsDto;
100 import org.openecomp.sdcrests.vsp.rest.mapping.MapPackageInfoToPackageInfoDto;
101 import org.openecomp.sdcrests.vsp.rest.mapping.MapQuestionnaireResponseToQuestionnaireResponseDto;
102 import org.openecomp.sdcrests.vsp.rest.mapping.MapValidationResponseToDto;
103 import org.openecomp.sdcrests.vsp.rest.mapping.MapVspDescriptionDtoToItem;
104 import org.openecomp.sdcrests.vsp.rest.mapping.MapVspDescriptionDtoToVspDetails;
105 import org.openecomp.sdcrests.vsp.rest.mapping.MapVspDetailsToDto;
106 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
107 import org.springframework.context.annotation.Scope;
108 import org.springframework.stereotype.Service;
109
110 @Named
111 @Service("vendorSoftwareProducts")
112 @Scope(value = "prototype")
113 public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
114
115   private static final String SUBMIT_ITEM_ACTION = "Submit_Item";
116   private static final String ATTACHMENT_FILENAME = "attachment; filename=";
117   private static final String SUBMIT_HEALED_VERSION_ERROR =
118       "VSP Id %s: Error while submitting version %s created based on Certified version %s for healing purpose.";
119   private static final Logger LOGGER = LoggerFactory.getLogger(VendorSoftwareProductsImpl.class);
120
121   private static ItemCreationDto validationVsp;
122
123   private final AsdcItemManager asdcItemManager = AsdcItemManagerFactory.getInstance()
124       .createInterface();
125   private final ItemPermissionsManager permissionsManager =
126       ItemPermissionsManagerFactory.getInstance().createInterface();
127   private final VersioningManager versioningManager =
128       VersioningManagerFactory.getInstance().createInterface();
129   private final VendorSoftwareProductManager vendorSoftwareProductManager =
130       VspManagerFactory.getInstance().createInterface();
131   private final ActivityLogManager activityLogManager =
132       ActivityLogManagerFactory.getInstance().createInterface();
133   private final NotificationPropagationManager notifier =
134       NotificationPropagationManagerFactory.getInstance().createInterface();
135   private final UniqueValueUtil uniqueValueUtil = new UniqueValueUtil(UniqueValueDaoFactory
136       .getInstance().createInterface());
137
138   @Override
139   public Response createVsp(VspRequestDto vspRequestDto, String user) {
140
141     OnboardingMethod onboardingMethod = null;
142     try {
143       onboardingMethod = OnboardingMethod.valueOf(vspRequestDto.getOnboardingMethod());
144     } catch (IllegalArgumentException e) {
145       LOGGER.error("Error while creating VSP. Message: " + e.getMessage());
146       throwUnknownOnboardingMethodException(e);
147     }
148     ItemCreationDto itemCreationDto = null;
149     if (onboardingMethod == OnboardingMethod.NetworkPackage
150         || onboardingMethod == OnboardingMethod.Manual) {
151       itemCreationDto = getItemCreationDto(vspRequestDto, user, onboardingMethod);
152
153     } else {
154       throwUnknownOnboardingMethodException(new IllegalArgumentException("Wrong parameter Onboarding Method"));
155     }
156
157     return Response.ok(itemCreationDto).build();
158   }
159
160   private ItemCreationDto getItemCreationDto(VspRequestDto vspRequestDto,
161                                              String user,
162                                              OnboardingMethod onboardingMethod) {
163
164     Item item = new MapVspDescriptionDtoToItem().applyMapping(vspRequestDto, Item.class);
165     item.setType(ItemType.vsp.name());
166     item.setOwner(user);
167     item.addProperty(VspItemProperty.ONBOARDING_METHOD, onboardingMethod.name());
168
169     uniqueValueUtil.validateUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName());
170     item = asdcItemManager.create(item);
171     uniqueValueUtil.createUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName());
172
173     Version version = versioningManager.create(item.getId(), new Version(), null);
174
175     VspDetails vspDetails =
176         new MapVspDescriptionDtoToVspDetails().applyMapping(vspRequestDto, VspDetails.class);
177     vspDetails.setId(item.getId());
178     vspDetails.setVersion(version);
179     vspDetails.setOnboardingMethod(vspRequestDto.getOnboardingMethod());
180
181     vendorSoftwareProductManager.createVsp(vspDetails);
182     versioningManager.publish(item.getId(), version, "Initial vsp:" + vspDetails.getName());
183     ItemCreationDto itemCreationDto = new ItemCreationDto();
184     itemCreationDto.setItemId(item.getId());
185     itemCreationDto.setVersion(new MapVersionToDto().applyMapping(version, VersionDto.class));
186
187     activityLogManager.logActivity(new ActivityLogEntity(vspDetails.getId(), version,
188         ActivityType.Create, user, true, "", ""));
189     return itemCreationDto;
190   }
191
192   private void throwUnknownOnboardingMethodException(IllegalArgumentException e) {
193     ErrorCode onboardingMethodUpdateErrorCode = OnboardingMethodErrorBuilder
194         .getInvalidOnboardingMethodErrorBuilder();
195     throw new CoreException(onboardingMethodUpdateErrorCode,e);
196   }
197
198   @Override
199   public Response listVsps(String versionStatus, String user) {
200     Predicate<Item> itemPredicate;
201     if (VersionStatus.Certified.name().equals(versionStatus)) {
202       itemPredicate = item -> ItemType.vsp.name().equals(item.getType())
203           && item.getVersionStatusCounters().containsKey(VersionStatus.Certified);
204
205     } else if (VersionStatus.Draft.name().equals(versionStatus)) {
206       itemPredicate = item -> ItemType.vsp.name().equals(item.getType())
207           && item.getVersionStatusCounters().containsKey(VersionStatus.Draft)
208           && userHasPermission(item.getId(), user);
209
210     } else {
211       itemPredicate = item -> ItemType.vsp.name().equals(item.getType());
212     }
213
214     GenericCollectionWrapper<VspDetailsDto> results = new GenericCollectionWrapper<>();
215     MapItemToVspDetailsDto mapper = new MapItemToVspDetailsDto();
216     asdcItemManager.list(itemPredicate).stream()
217         .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime()))
218         .forEach(vspItem -> results.add(mapper.applyMapping(vspItem, VspDetailsDto.class)));
219
220     return Response.ok(results).build();
221   }
222
223   @Override
224   public Response getVsp(String vspId, String versionId, String user) {
225     Version version = versioningManager.get(vspId, new Version(versionId));
226     VspDetails vspDetails = vendorSoftwareProductManager.getVsp(vspId, version);
227     vspDetails.setWritetimeMicroSeconds(version.getModificationTime().getTime());
228
229     try {
230       Optional<Version> healedVersion = HealingManagerFactory.getInstance().createInterface()
231           .healItemVersion(vspId, version, ItemType.vsp, false);
232
233       healedVersion.ifPresent(version1 -> {
234         vspDetails.setVersion(version1);
235         if (version.getStatus() == VersionStatus.Certified) {
236           submitHealedVersion(vspId, version1, versionId, user);
237         }
238       });
239     } catch (Exception e) {
240       LOGGER.error(
241           String.format("Error while auto healing VSP with Id %s and version %s", vspId, versionId),
242           e);
243     }
244
245     VspDetailsDto vspDetailsDto =
246         new MapVspDetailsToDto().applyMapping(vspDetails, VspDetailsDto.class);
247     addNetworkPackageInfo(vspId, version, vspDetailsDto);
248
249     return Response.ok(vspDetailsDto).build();
250   }
251
252   private void submitHealedVersion(String vspId, Version healedVersion, String baseVersionId,
253                                    String user) {
254     try {
255       Optional<ValidationResponse>
256           validationResponse = submit(vspId, healedVersion, "Submit healed Vsp", user);
257       // TODO: 8/9/2017 before collaboration checkout was done at this scenario (equivalent
258       // to new version in collaboration). need to decide what should be done now.
259       validationResponse.ifPresent(validationResponse1 -> {
260         throw new IllegalStateException("Certified vsp after healing failed on validation");
261       });
262       vendorSoftwareProductManager.createPackage(vspId, healedVersion);
263     } catch (Exception ex) {
264       LOGGER.error(
265           String.format(SUBMIT_HEALED_VERSION_ERROR, vspId, healedVersion.getId(), baseVersionId),
266           ex);
267     }
268   }
269
270   @Override
271   public Response updateVsp(String vspId, String versionId, VspDescriptionDto vspDescriptionDto,
272                             String user) {
273     VspDetails vspDetails =
274         new MapVspDescriptionDtoToVspDetails().applyMapping(vspDescriptionDto, VspDetails.class);
275     vspDetails.setId(vspId);
276     vspDetails.setVersion(new Version(versionId));
277
278     vendorSoftwareProductManager.updateVsp(vspDetails);
279
280     return Response.ok().build();
281   }
282
283   @Override
284   public Response deleteVsp(String vspId, String user) {
285     Item vsp = asdcItemManager.get(vspId);
286
287     if(!vsp.getType().equals(ItemType.vsp.name())){
288       throw new CoreException((new ErrorCode.ErrorCodeBuilder()
289               .withMessage(String.format("Vsp with id %s does not exist.",
290                       vspId)).build()));
291     }
292
293     Integer certifiedVersionsCounter = vsp.getVersionStatusCounters().get(VersionStatus.Certified);
294     if (Objects.isNull(certifiedVersionsCounter) || certifiedVersionsCounter == 0) {
295       asdcItemManager.delete(vsp);
296       permissionsManager.deleteItemPermissions(vspId);
297       uniqueValueUtil.deleteUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, vsp.getName());
298       notifyUsers(vspId, vsp.getName(), null, "VSP was deleted", user,
299           NotificationEventTypes.DELETE);
300
301       return Response.ok().build();
302     } else {
303       return Response.status(Response.Status.FORBIDDEN)
304           .entity(new Exception(Messages.DELETE_VSP_ERROR.getErrorMessage())).build();
305     }
306   }
307
308   @Override
309   public Response actOnVendorSoftwareProduct(VersionSoftwareProductActionRequestDto request,
310                                              String vspId, String versionId,
311                                              String user) throws IOException {
312     Version version = new Version(versionId);
313
314     if (request.getAction() == VendorSoftwareProductAction.Submit) {
315       if (!permissionsManager.isAllowed(vspId, user, SUBMIT_ITEM_ACTION)) {
316         return Response.status(Response.Status.FORBIDDEN)
317             .entity(new Exception(Messages.PERMISSIONS_ERROR.getErrorMessage())).build();
318       }
319       String message = request.getSubmitRequest() == null ? "Submit"
320           : request.getSubmitRequest().getMessage();
321       Optional<ValidationResponse> validationResponse = submit(vspId, version, message, user);
322
323       if (validationResponse.isPresent()) {
324         ValidationResponseDto validationResponseDto = new MapValidationResponseToDto()
325             .applyMapping(validationResponse.get(), ValidationResponseDto.class);
326         return Response.status(Response.Status.EXPECTATION_FAILED).entity(validationResponseDto)
327             .build();
328       }
329
330       notifyUsers(vspId, null, version, message, user, NotificationEventTypes.SUBMIT);
331
332     } else if (request.getAction() == VendorSoftwareProductAction.Create_Package) {
333       return createPackage(vspId, version);
334     }
335
336     return Response.ok().build();
337   }
338
339   @Override
340   public Response getValidationVsp(String user) {
341     if (validationVsp != null) {
342       return Response.ok(validationVsp).build();
343     }
344
345     VspRequestDto validationVspRequest = new VspRequestDto();
346     validationVspRequest.setOnboardingMethod("HEAT");
347     validationVspRequest.setName(VALIDATION_VSP_NAME);
348
349     try {
350       validationVsp = (ItemCreationDto) createVsp(validationVspRequest, user).getEntity();
351       return Response.ok(validationVsp).build();
352
353     } catch (CoreException validationVspAlreadyExistException) {
354       // find validationVsp
355       String validationVspId = asdcItemManager.list(item ->
356           ItemType.vsp.name().equals(item.getType()) && VALIDATION_VSP_NAME.equals(item.getName()))
357           .stream().findFirst().orElseThrow(() -> new IllegalStateException("Vsp with name %s "
358               + "does not exist even though the name exists according to unique value util"))
359           .getId();
360       Version validationVspVersion = versioningManager.list(validationVspId).iterator().next();
361
362       validationVsp = new ItemCreationDto();
363       validationVsp.setItemId(validationVspId);
364       validationVsp
365           .setVersion(new MapVersionToDto().applyMapping(validationVspVersion, VersionDto.class));
366
367       return Response.ok(validationVsp).build();
368     }
369   }
370
371   @Override
372   public Response getOrchestrationTemplate(String vspId, String versionId, String user) {
373     byte[] orchestrationTemplateFile =
374         vendorSoftwareProductManager.getOrchestrationTemplateFile(vspId, new Version(versionId));
375
376     if (orchestrationTemplateFile == null) {
377       return Response.status(Response.Status.NOT_FOUND).build();
378     }
379     Response.ResponseBuilder response = Response.ok(orchestrationTemplateFile);
380     response.header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + "LatestHeatPackage.zip");
381     return response.build();
382   }
383
384   @Override
385   public Response listPackages(String category, String subCategory, String user) {
386     List<PackageInfo> packageInfoList =
387         vendorSoftwareProductManager.listPackages(category, subCategory);
388
389     GenericCollectionWrapper<PackageInfoDto> results = new GenericCollectionWrapper<>();
390     MapPackageInfoToPackageInfoDto mapper = new MapPackageInfoToPackageInfoDto();
391
392     if (packageInfoList != null) {
393       for (PackageInfo packageInfo : packageInfoList) {
394         results.add(mapper.applyMapping(packageInfo, PackageInfoDto.class));
395       }
396     }
397     return Response.ok(results).build();
398   }
399
400   @Override
401   public Response getTranslatedFile(String vspId, String versionName, String user) {
402     List<Version> versions = versioningManager.list(vspId);
403     Version version;
404     if (versionName == null) {
405       version = versions.stream().filter(ver -> VersionStatus.Certified == ver.getStatus())
406           .max(Comparator.comparingDouble(o -> Double.parseDouble(o.getName())))
407           .orElseThrow(() -> new CoreException(new PackageNotFoundErrorBuilder(vspId).build()));
408     } else {
409       version = versions.stream().filter(ver -> versionName.equals(ver.getName()))
410           .findFirst()
411           .orElseThrow(() -> new CoreException(new PackageNotFoundErrorBuilder(vspId).build()));
412
413       if (version.getStatus() != VersionStatus.Certified) {
414         throw new CoreException(new RequestedVersionInvalidErrorBuilder().build());
415       }
416     }
417
418     File zipFile = vendorSoftwareProductManager.getTranslatedFile(vspId, version);
419
420     Response.ResponseBuilder response = Response.ok(zipFile);
421     if (zipFile == null) {
422       return Response.status(Response.Status.NOT_FOUND).build();
423     }
424     response.header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + zipFile.getName());
425
426     return response.build();
427   }
428
429   @Override
430   public Response getQuestionnaire(String vspId, String versionId, String user) {
431     QuestionnaireResponse questionnaireResponse =
432         vendorSoftwareProductManager.getVspQuestionnaire(vspId, new Version(versionId));
433
434     if (questionnaireResponse.getErrorMessage() != null) {
435       return Response.status(Response.Status.EXPECTATION_FAILED).entity(
436           new MapQuestionnaireResponseToQuestionnaireResponseDto()
437               .applyMapping(questionnaireResponse, QuestionnaireResponseDto.class)).build();
438     }
439
440     QuestionnaireResponseDto result = new MapQuestionnaireResponseToQuestionnaireResponseDto()
441         .applyMapping(questionnaireResponse, QuestionnaireResponseDto.class);
442     return Response.ok(result).build();
443   }
444
445   @Override
446   public Response updateQuestionnaire(String questionnaireData, String vspId, String
447       versionId, String user) {
448     vendorSoftwareProductManager
449         .updateVspQuestionnaire(vspId, new Version(versionId), questionnaireData);
450     return Response.ok().build();
451   }
452
453   @Override
454   public Response heal(String vspId, String versionId, String user) {
455     HealingManagerFactory.getInstance().createInterface()
456         .healItemVersion(vspId, new Version(versionId), ItemType.vsp, true);
457     return Response.ok().build();
458   }
459
460   @Override
461   public Response getVspInformationArtifact(String vspId, String versionId, String user) {
462     File textInformationArtifact =
463         vendorSoftwareProductManager.getInformationArtifact(vspId, new Version(versionId));
464
465     Response.ResponseBuilder response = Response.ok(textInformationArtifact);
466     if (textInformationArtifact == null) {
467       return Response.status(Response.Status.NOT_FOUND).build();
468     }
469     response
470         .header(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + textInformationArtifact.getName());
471     return response.build();
472   }
473
474   @Override
475   public Response listComputes(String vspId, String version, String user) {
476
477     Collection<ComputeEntity> computes =
478         vendorSoftwareProductManager.getComputeByVsp(vspId, new Version(version));
479
480     MapComputeEntityToVspComputeDto mapper = new MapComputeEntityToVspComputeDto();
481     GenericCollectionWrapper<VspComputeDto> results = new GenericCollectionWrapper<>();
482     for (ComputeEntity compute : computes) {
483       results.add(mapper.applyMapping(compute, VspComputeDto.class));
484     }
485
486     return Response.ok(results).build();
487   }
488
489   private Optional<ValidationResponse> submit(String vspId, Version version, String message,
490                                               String user) throws IOException {
491
492     ValidationResponse validationResponse = vendorSoftwareProductManager.validate(vspId, version);
493     Map<String, List<ErrorMessage>> compilationErrors =
494         vendorSoftwareProductManager.compile(vspId, version);
495     if (!validationResponse.isValid() || MapUtils.isNotEmpty(compilationErrors)) {
496
497       activityLogManager.logActivity(
498           new ActivityLogEntity(vspId, version, ActivityType.Submit, user, false,
499               "Failed on validation before submit", ""));
500       return Optional.of(validationResponse);
501     }
502
503     versioningManager.submit(vspId, version, message);
504
505     activityLogManager.logActivity(
506         new ActivityLogEntity(vspId, version, ActivityType.Submit, user, true, "", message));
507     return Optional.empty();
508   }
509
510   private void notifyUsers(String itemId, String itemName, Version version, String message,
511                            String userName, NotificationEventTypes eventType) {
512     Map<String, Object> eventProperties = new HashMap<>();
513     eventProperties.put(ITEM_NAME, itemName == null ? asdcItemManager.get(itemId).getName() : itemName);
514     eventProperties.put(ITEM_ID, itemId);
515
516     if (version != null) {
517       eventProperties.put(VERSION_NAME, version.getName() == null
518           ? versioningManager.get(itemId, version).getName()
519           : version.getName());
520       eventProperties.put(VERSION_ID, version.getId());
521     }
522
523     eventProperties.put(SUBMIT_DESCRIPTION, message);
524     eventProperties.put(PERMISSION_USER, userName);
525
526     Event syncEvent = new SyncEvent(eventType.getEventName(), itemId, eventProperties, itemId);
527     try {
528       notifier.notifySubscribers(syncEvent, userName);
529     } catch (Exception e) {
530       LOGGER.error("Failed to send sync notification to users subscribed o item '" + itemId);
531     }
532   }
533
534   private class SyncEvent implements Event {
535
536     private final String eventType;
537     private final String originatorId;
538     private final Map<String, Object> attributes;
539     private final String entityId;
540
541     SyncEvent(String eventType, String originatorId,
542               Map<String, Object> attributes, String entityId) {
543       this.eventType = eventType;
544       this.originatorId = originatorId;
545       this.attributes = attributes;
546       this.entityId = entityId;
547     }
548
549     @Override
550     public String getEventType() {
551       return eventType;
552     }
553
554     @Override
555     public String getOriginatorId() {
556       return originatorId;
557     }
558
559     @Override
560     public Map<String, Object> getAttributes() {
561       return attributes;
562     }
563
564     @Override
565     public String getEntityId() {
566       return entityId;
567     }
568   }
569
570   private Response createPackage(String vspId, Version version) throws IOException {
571     Version retrievedVersion = versioningManager.get(vspId, version);
572     if (retrievedVersion.getStatus() != VersionStatus.Certified) {
573       throw new CoreException(
574           new CreatePackageForNonFinalVendorSoftwareProductErrorBuilder(vspId, version)
575               .build());
576     }
577     PackageInfo packageInfo =
578         vendorSoftwareProductManager.createPackage(vspId, retrievedVersion);
579     return Response.ok(packageInfo == null
580         ? null
581         : new MapPackageInfoToPackageInfoDto().applyMapping(packageInfo, PackageInfoDto.class))
582         .build();
583   }
584
585   private void addNetworkPackageInfo(String vspId, Version version, VspDetailsDto vspDetailsDto) {
586     OrchestrationTemplateCandidateData candidateInfo =
587         OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface()
588             .getInfo(vspId, version);
589     if (Objects.nonNull(candidateInfo) && Objects.nonNull(candidateInfo.getFileSuffix())) {
590       vspDetailsDto.setValidationData(candidateInfo.getValidationDataStructure());
591       vspDetailsDto.setNetworkPackageName(candidateInfo.getFileName());
592       vspDetailsDto.setCandidateOnboardingOrigin(candidateInfo.getFileSuffix());
593     } else {
594       OrchestrationTemplateEntity orchestrationTemplateInfo =
595           vendorSoftwareProductManager.getOrchestrationTemplateInfo(vspId, version);
596       if (Objects.nonNull(orchestrationTemplateInfo)) {
597         vspDetailsDto.setValidationData(orchestrationTemplateInfo.getValidationDataStructure());
598         vspDetailsDto.setNetworkPackageName(orchestrationTemplateInfo.getFileName());
599         vspDetailsDto.setOnboardingOrigin(orchestrationTemplateInfo.getFileSuffix());
600       }
601     }
602   }
603
604   private boolean userHasPermission(String itemId, String userId) {
605     String permission = permissionsManager.getUserItemPermiission(itemId, userId);
606     return permission != null && permission
607         .matches(PermissionTypes.Contributor.name() + "|" + PermissionTypes.Owner.name());
608   }
609 }