2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
22 package org.openecomp.sdc.be.components.impl;
24 import fj.data.Either;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
29 import java.util.Map.Entry;
30 import java.util.Optional;
31 import java.util.function.BiFunction;
32 import java.util.function.BooleanSupplier;
33 import java.util.stream.Collectors;
34 import org.apache.commons.collections.CollectionUtils;
35 import org.apache.commons.lang3.StringUtils;
36 import org.apache.commons.lang3.tuple.ImmutablePair;
37 import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
38 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
39 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
40 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
41 import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
42 import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
43 import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator;
44 import org.openecomp.sdc.be.components.validation.component.ComponentIconValidator;
45 import org.openecomp.sdc.be.components.validation.component.ComponentNameValidator;
46 import org.openecomp.sdc.be.components.validation.component.ComponentProjectCodeValidator;
47 import org.openecomp.sdc.be.components.validation.component.ComponentTagsValidator;
48 import org.openecomp.sdc.be.components.validation.component.ComponentValidator;
49 import org.openecomp.sdc.be.config.BeEcompErrorManager;
50 import org.openecomp.sdc.be.config.ConfigurationManager;
51 import org.openecomp.sdc.be.dao.api.ActionStatus;
52 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
53 import org.openecomp.sdc.be.dao.utils.MapUtil;
54 import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
55 import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
57 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
58 import org.openecomp.sdc.be.datatypes.enums.FilterKeyEnum;
59 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
60 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
61 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
62 import org.openecomp.sdc.be.facade.operations.CatalogOperation;
63 import org.openecomp.sdc.be.impl.ComponentsUtils;
64 import org.openecomp.sdc.be.model.ArtifactDefinition;
65 import org.openecomp.sdc.be.model.AttributeDefinition;
66 import org.openecomp.sdc.be.model.CapReqDef;
67 import org.openecomp.sdc.be.model.Component;
68 import org.openecomp.sdc.be.model.ComponentInstance;
69 import org.openecomp.sdc.be.model.ComponentInstanceInput;
70 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
71 import org.openecomp.sdc.be.model.ComponentParametersView;
72 import org.openecomp.sdc.be.model.DataTypeDefinition;
73 import org.openecomp.sdc.be.model.GroupDefinition;
74 import org.openecomp.sdc.be.model.IComponentInstanceConnectedElement;
75 import org.openecomp.sdc.be.model.InputDefinition;
76 import org.openecomp.sdc.be.model.LifecycleStateEnum;
77 import org.openecomp.sdc.be.model.Operation;
78 import org.openecomp.sdc.be.model.PropertyDefinition;
79 import org.openecomp.sdc.be.model.Resource;
80 import org.openecomp.sdc.be.model.User;
81 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
82 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
83 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
84 import org.openecomp.sdc.be.model.operations.api.IGroupInstanceOperation;
85 import org.openecomp.sdc.be.model.operations.api.IGroupOperation;
86 import org.openecomp.sdc.be.model.operations.api.IGroupTypeOperation;
87 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
88 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
89 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
90 import org.openecomp.sdc.be.resources.data.ComponentMetadataData;
91 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
92 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
93 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
94 import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
95 import org.openecomp.sdc.be.user.Role;
96 import org.openecomp.sdc.be.utils.CommonBeUtils;
97 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
98 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
99 import org.openecomp.sdc.common.log.wrappers.Logger;
100 import org.openecomp.sdc.common.util.ValidationUtils;
101 import org.openecomp.sdc.exception.ResponseFormat;
102 import org.springframework.beans.factory.annotation.Autowired;
104 public abstract class ComponentBusinessLogic extends BaseBusinessLogic {
106 private static final Logger log = Logger.getLogger(ComponentBusinessLogic.class.getName());
108 protected final GroupBusinessLogic groupBusinessLogic;
109 protected ArtifactsBusinessLogic artifactsBusinessLogic;
110 protected GenericTypeBusinessLogic genericTypeBusinessLogic;
111 protected ComponentDescriptionValidator componentDescriptionValidator;
112 protected ComponentProjectCodeValidator componentProjectCodeValidator;
113 protected CatalogOperation catalogOperations;
114 protected ComponentIconValidator componentIconValidator;
115 protected ComponentTagsValidator componentTagsValidator;
116 protected ComponentNameValidator componentNameValidator;
117 protected ComponentContactIdValidator componentContactIdValidator;
119 public ComponentBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
120 IGroupTypeOperation groupTypeOperation, GroupBusinessLogic groupBusinessLogic,
121 InterfaceOperation interfaceOperation, InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
122 ArtifactsBusinessLogic artifactsBusinessLogic, ArtifactsOperations artifactToscaOperation,
123 ComponentContactIdValidator componentContactIdValidator, ComponentNameValidator componentNameValidator,
124 ComponentTagsValidator componentTagsValidator, ComponentValidator componentValidator,
125 ComponentIconValidator componentIconValidator, ComponentProjectCodeValidator componentProjectCodeValidator,
126 ComponentDescriptionValidator componentDescriptionValidator) {
127 super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
128 artifactToscaOperation);
129 this.artifactsBusinessLogic = artifactsBusinessLogic;
130 this.groupBusinessLogic = groupBusinessLogic;
131 this.componentContactIdValidator = componentContactIdValidator;
132 this.componentNameValidator = componentNameValidator;
133 this.componentTagsValidator = componentTagsValidator;
134 this.componentIconValidator = componentIconValidator;
135 this.componentProjectCodeValidator = componentProjectCodeValidator;
136 this.componentDescriptionValidator = componentDescriptionValidator;
139 private static Either<ArtifactDefinition, Operation> saveToscaArtifactAndPopulateToscaArtifactsWithResult(Component component,
140 final ComponentsUtils componentsUtils,
141 final ArtifactTypeEnum artifactEnum,
142 final BiFunction<Component, ArtifactDefinition, Either<ArtifactDefinition, Operation>> saveToscaArtifactPayloadFunction) {
143 ArtifactDefinition artifactDefinition = getToscaArtifactByTypeOrThrowException(component, artifactEnum, componentsUtils);
144 Either<ArtifactDefinition, Operation> result = saveToscaArtifactPayloadFunction.apply(component, artifactDefinition);
145 if (result.isLeft()) {
146 ArtifactDefinition def = result.left().value();
147 component.getToscaArtifacts().put(def.getArtifactLabel(), def);
152 private static Optional<ArtifactDefinition> getToscaArtifactByType(final Map<String, ArtifactDefinition> toscaArtifacts,
153 final ArtifactTypeEnum typeEnum) {
154 return toscaArtifacts.values().stream().filter(p -> p.getArtifactType().equals(typeEnum.getType())).findAny();
157 private static ArtifactDefinition getToscaArtifactByTypeOrThrowException(final Component component, final ArtifactTypeEnum typeEnum,
158 final ComponentsUtils componentsUtils) {
159 return Optional.ofNullable(component.getToscaArtifacts()).flatMap(toscaArtifacts -> getToscaArtifactByType(toscaArtifacts, typeEnum))
161 log.debug("Impossible to find a ToscaArtifact with type '{}' for {}", typeEnum.getType(), component);
162 return new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, typeEnum.name()));
166 public void setComponentDescriptionValidator(ComponentDescriptionValidator componentDescriptionValidator) {
167 this.componentDescriptionValidator = componentDescriptionValidator;
170 public void setComponentProjectCodeValidator(ComponentProjectCodeValidator componentProjectCodeValidator) {
171 this.componentProjectCodeValidator = componentProjectCodeValidator;
174 public void setComponentIconValidator(ComponentIconValidator componentIconValidator) {
175 this.componentIconValidator = componentIconValidator;
178 public void setComponentContactIdValidator(ComponentContactIdValidator componentContactIdValidator) {
179 this.componentContactIdValidator = componentContactIdValidator;
182 public void setComponentTagsValidator(ComponentTagsValidator componentTagsValidator) {
183 this.componentTagsValidator = componentTagsValidator;
186 public void setComponentNameValidator(ComponentNameValidator componentNameValidator) {
187 this.componentNameValidator = componentNameValidator;
191 public void setGenericTypeBusinessLogic(GenericTypeBusinessLogic genericTypeBusinessLogic) {
192 this.genericTypeBusinessLogic = genericTypeBusinessLogic;
195 public abstract Either<List<String>, ResponseFormat> deleteMarkedComponents();
197 public abstract ComponentInstanceBusinessLogic getComponentInstanceBL();
199 public abstract Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId,
204 * @param dataParamsToReturn
207 public abstract Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String componentId,
208 List<String> dataParamsToReturn);
210 public Either<ComponentMetadataData, StorageOperationStatus> getComponentMetadata(final String componentId) {
211 return toscaOperationFacade.getComponentMetadata(componentId);
214 User validateUser(User user, String ecompErrorContext, Component component, AuditingActionEnum auditAction, boolean inTransaction) {
216 ResponseFormat responseFormat;
218 validateUserNotEmpty(user, ecompErrorContext);
219 validatedUser = validateUserExists(user);
220 } catch (ByActionStatusComponentException e) {
221 if (e.getActionStatus() == ActionStatus.MISSING_INFORMATION) {
222 user.setUserId("UNKNOWN");
224 responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
225 componentsUtils.auditComponentAdmin(responseFormat, user, component, auditAction, component.getComponentType());
227 } catch (ByResponseFormatComponentException e) {
228 responseFormat = e.getResponseFormat();
229 componentsUtils.auditComponentAdmin(responseFormat, user, component, auditAction, component.getComponentType());
232 return validatedUser;
235 protected void validateUserRole(User user, Component component, List<Role> roles, AuditingActionEnum auditAction, String comment) {
236 if (roles != null && roles.isEmpty()) {
237 roles.add(Role.ADMIN);
238 roles.add(Role.DESIGNER);
241 validateUserRole(user, roles);
242 } catch (ByActionStatusComponentException e) {
243 ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
244 handleComponentException(component, comment, responseFormat, user, auditAction);
246 } catch (ByResponseFormatComponentException e) {
247 ResponseFormat responseFormat = e.getResponseFormat();
248 handleComponentException(component, comment, responseFormat, user, auditAction);
253 private void handleComponentException(Component component, String comment, ResponseFormat responseFormat, User user,
254 AuditingActionEnum auditAction) {
255 String commentStr = null;
256 String distrStatus = null;
257 ComponentTypeEnum componentType = component.getComponentType();
258 if (componentType == ComponentTypeEnum.SERVICE) {
259 distrStatus = ((ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition())
260 .getDistributionStatus();
261 commentStr = comment;
263 componentsUtils.auditComponent(responseFormat, user, component, auditAction, new ResourceCommonInfo(componentType.getValue()),
264 ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(),
265 ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(), commentStr, null, null);
268 public Either<Boolean, ResponseFormat> validateConformanceLevel(String componentUuid, ComponentTypeEnum componentTypeEnum, String userId) {
269 log.trace("validate conformance level");
270 if (componentTypeEnum != ComponentTypeEnum.SERVICE) {
271 log.error("conformance level validation for non service component, id {}", componentUuid);
272 ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
273 return Either.right(errorResponse);
275 validateUserExists(userId);
276 Either<ComponentMetadataData, StorageOperationStatus> eitherComponent = toscaOperationFacade
277 .getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, null);
278 if (eitherComponent.isRight()) {
279 log.error("can't validate conformance level, component not found, uuid {}", componentUuid);
280 BeEcompErrorManager.getInstance().logBeComponentMissingError("validateConformanceLevel", componentTypeEnum.getValue(), componentUuid);
281 StorageOperationStatus status = eitherComponent.right().value();
282 ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(status, componentTypeEnum);
283 ResponseFormat responseFormat = componentsUtils.getResponseFormat(actionStatus);
284 return Either.right(responseFormat);
286 String componentConformanceLevel = eitherComponent.left().value().getMetadataDataDefinition().getConformanceLevel();
287 if (StringUtils.isBlank(componentConformanceLevel)) {
288 log.error("component conformance level property is null or empty, uuid {}", componentUuid);
289 ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
290 return Either.right(errorResponse);
292 String configConformanceLevel = ConfigurationManager.getConfigurationManager().getConfiguration().getMinToscaConformanceLevel();
293 Boolean result = true;
294 if (CommonBeUtils.conformanceLevelCompare(componentConformanceLevel, configConformanceLevel) < 0) {
295 log.error("invalid asset conformance level, uuid {}, asset conformanceLevel {}, config conformanceLevel {}", componentUuid,
296 componentConformanceLevel, configConformanceLevel);
299 log.trace("conformance level validation finished");
300 return Either.left(result);
303 protected void validateIcon(User user, Component component, AuditingActionEnum actionEnum) {
304 log.debug("validate Icon");
305 ComponentTypeEnum type = component.getComponentType();
306 String icon = component.getIcon();
307 if (!ValidationUtils.validateStringNotEmpty(icon)) {
308 log.info("icon is missing.");
309 ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_ICON, type.getValue());
310 componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
311 throw new ComponentException(ActionStatus.COMPONENT_MISSING_ICON, type.getValue());
314 validateIcon(icon, type);
315 } catch (ComponentException e) {
316 ResponseFormat responseFormat =
317 e.getResponseFormat() != null ? e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
318 componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
323 private void validateIcon(String icon, ComponentTypeEnum type) {
325 if (!ValidationUtils.validateIconLength(icon)) {
326 log.debug("icon exceeds max length");
327 throw new ComponentException(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
329 if (!ValidationUtils.validateIcon(icon)) {
330 log.info("icon is invalid.");
331 throw new ComponentException(ActionStatus.COMPONENT_INVALID_ICON, type.getValue());
336 protected void checkComponentFieldsForOverrideAttempt(Component component) {
337 if (component.getLifecycleState() != null) {
338 log.info("LifecycleState cannot be defined by user. This field will be overridden by the application");
340 if (component.getVersion() != null) {
341 log.info("Version cannot be defined by user. This field will be overridden by the application");
343 if (component.getCreatorUserId() != null || component.getCreatorFullName() != null) {
344 log.info("Creator cannot be defined by user. This field will be overridden by the application");
346 if (component.getLastUpdaterUserId() != null || component.getLastUpdaterFullName() != null) {
347 log.info("Last Updater cannot be defined by user. This field will be overridden by the application");
349 if (component.getCreationDate() != null) {
350 log.info("Creation Date cannot be defined by user. This field will be overridden by the application");
352 if (component.isHighestVersion() != null) {
353 log.info("Is Highest Version cannot be defined by user. This field will be overridden by the application");
355 if (component.getUUID() != null) {
356 log.info("UUID cannot be defined by user. This field will be overridden by the application");
358 if (component.getLastUpdateDate() != null) {
359 log.info("Last Update Date cannot be defined by user. This field will be overridden by the application");
361 if (component.getUniqueId() != null) {
362 log.info("uid cannot be defined by user. This field will be overridden by the application.");
363 component.setUniqueId(null);
365 if (component.getInvariantUUID() != null) {
366 log.info("Invariant UUID cannot be defined by user. This field will be overridden by the application.");
370 protected void validateComponentFieldsBeforeCreate(User user, Component component, AuditingActionEnum actionEnum) {
371 // validate component name uniqueness
372 log.debug("validate component name ");
373 componentNameValidator.validateAndCorrectField(user, component, actionEnum);
374 // validate description
375 log.debug("validate description");
376 componentDescriptionValidator.validateAndCorrectField(user, component, actionEnum);
378 log.debug("validate tags");
379 componentTagsValidator.validateAndCorrectField(user, component, actionEnum);
380 // validate contact info
381 log.debug("validate contact info");
382 componentContactIdValidator.validateAndCorrectField(user, component, actionEnum);
384 log.debug("validate icon");
385 validateIcon(user, component, actionEnum);
388 public CapReqDef getRequirementsAndCapabilities(String componentId, ComponentTypeEnum componentTypeEnum, String userId) {
389 validateUserExists(userId);
390 ComponentParametersView filter = new ComponentParametersView(true);
391 filter.setIgnoreCapabilities(false);
392 filter.setIgnoreRequirements(false);
393 filter.setIgnoreComponentInstances(false);
395 Component component = validateComponentExists(componentId, componentTypeEnum, filter);
396 return new CapReqDef(component.getRequirements(), component.getCapabilities());
397 } catch (ComponentException e) {
398 BeEcompErrorManager.getInstance().logBeComponentMissingError("getRequirementsAndCapabilities", componentTypeEnum.getValue(), componentId);
399 throwComponentException(e.getResponseFormat());
404 public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponents(boolean isAbstractAbstract,
405 ComponentTypeEnum componentTypeEnum,
406 String internalComponentType, List<String> componentUids,
409 validateUserExists(userId);
410 List<Component> result = new ArrayList<>();
411 List<String> componentsUidToFetch = new ArrayList<>();
412 componentsUidToFetch.addAll(componentUids);
413 if (!componentsUidToFetch.isEmpty()) {
414 log.debug("Number of Components to fetch from graph is {}", componentsUidToFetch.size());
415 Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = toscaOperationFacade
416 .getLatestVersionNotAbstractComponents(isAbstractAbstract, componentTypeEnum, internalComponentType, componentsUidToFetch);
417 if (nonCheckoutCompResponse.isLeft()) {
418 log.debug("Retrived Resource successfully.");
419 result.addAll(nonCheckoutCompResponse.left().value());
422 componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value())));
425 return Either.left(result);
427 janusGraphDao.commit();
431 public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(final boolean isAbstractAbstract,
432 final HighestFilterEnum highestFilter,
433 final ComponentTypeEnum componentTypeEnum,
434 final String internalComponentType, String userId,
435 final String modelName,
436 final boolean includeNormativeExtensionModels) {
437 Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = null;
439 validateUserExists(userId);
440 nonCheckoutCompResponse = toscaOperationFacade
441 .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType, modelName,
442 includeNormativeExtensionModels);
443 if (nonCheckoutCompResponse.isLeft()) {
444 log.debug("Retrieved Resource successfully.");
445 return Either.left(nonCheckoutCompResponse.left().value());
448 .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value())));
450 if (nonCheckoutCompResponse != null && nonCheckoutCompResponse.isLeft()) {
451 janusGraphDao.commit();
456 public void setDeploymentArtifactsPlaceHolder(Component component, User user) {
459 @SuppressWarnings("unchecked")
460 public void setToscaArtifactsPlaceHolders(Component component, User user) {
461 Map<String, ArtifactDefinition> artifactMap = component.getToscaArtifacts();
462 if (artifactMap == null) {
463 artifactMap = new HashMap<>();
465 String componentUniqueId = component.getUniqueId();
466 String componentSystemName = component.getSystemName();
467 String componentType = component.getComponentType().getValue().toLowerCase();
468 Map<String, Object> toscaArtifacts = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts();
469 if (toscaArtifacts != null) {
470 for (Entry<String, Object> artifactInfoMap : toscaArtifacts.entrySet()) {
471 Map<String, Object> artifactInfo = (Map<String, Object>) artifactInfoMap.getValue();
472 ArtifactDefinition artifactDefinition = artifactsBusinessLogic
473 .createArtifactPlaceHolderInfo(componentUniqueId, artifactInfoMap.getKey(), artifactInfo, user, ArtifactGroupTypeEnum.TOSCA);
475 .setArtifactName(ValidationUtils.normalizeFileName(componentType + "-" + componentSystemName + artifactInfo.get("artifactName")));
476 artifactMap.put(artifactDefinition.getArtifactLabel(), artifactDefinition);
479 component.setToscaArtifacts(artifactMap);
482 public Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest,
483 boolean inTransaction, boolean shouldLock) {
484 return populateToscaArtifacts(component, user, isInCertificationRequest, inTransaction, shouldLock, true, true);
487 public Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest,
488 boolean inTransaction, boolean shouldLock, boolean retrieveResource) {
489 return populateToscaArtifacts(component, user, isInCertificationRequest, inTransaction, shouldLock, true, retrieveResource);
492 private Either<ArtifactDefinition, Operation> populateToscaArtifacts(Component component, User user, boolean isInCertificationRequest,
493 boolean inTransaction, boolean shouldLock, boolean fetchTemplatesFromDB,
494 boolean retrieveResource) {
495 if (retrieveResource) {
496 Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaFullElement(component.getUniqueId());
497 if (toscaElement.isRight()) {
498 throw new ByActionStatusComponentException(
499 componentsUtils.convertFromStorageResponse(toscaElement.right().value(), component.getComponentType()));
501 component = toscaElement.left().value();
503 Either<ArtifactDefinition, Operation> generateToscaRes = saveToscaArtifactAndPopulateToscaArtifactsWithResult(component, componentsUtils,
504 ArtifactTypeEnum.TOSCA_TEMPLATE,
505 (comp, toscaArtifact) -> saveToscaArtifactPayload(toscaArtifact, comp, user, isInCertificationRequest, shouldLock, inTransaction,
506 fetchTemplatesFromDB));
507 if (!isAbstractResource(component)) {
508 generateToscaRes = saveToscaArtifactAndPopulateToscaArtifactsWithResult(component, componentsUtils, ArtifactTypeEnum.TOSCA_CSAR,
509 (comp, toscaArtifactArg) -> saveToscaArtifactPayload(toscaArtifactArg, comp, user, isInCertificationRequest, shouldLock,
510 inTransaction, true));
512 return generateToscaRes;
515 private boolean isAbstractResource(Component component) {
516 return component.getComponentType() == ComponentTypeEnum.RESOURCE && ((Resource) component).isAbstract();
519 private Either<ArtifactDefinition, Operation> saveToscaArtifactPayload(ArtifactDefinition artifactDefinition,
520 org.openecomp.sdc.be.model.Component component, User user,
521 boolean isInCertificationRequest, boolean shouldLock,
522 boolean inTransaction, boolean fetchTemplatesFromDB) {
523 return artifactsBusinessLogic
524 .generateAndSaveToscaArtifact(artifactDefinition, component, user, isInCertificationRequest, shouldLock, inTransaction,
525 fetchTemplatesFromDB);
528 public ImmutablePair<String, byte[]> getToscaModelByComponentUuid(ComponentTypeEnum componentType, String uuid,
529 ResourceCommonInfo resourceCommonInfo) {
530 Either<List<Component>, StorageOperationStatus> latestVersionEither = toscaOperationFacade.getComponentListByUuid(uuid, null);
531 if (latestVersionEither.isRight()) {
532 throw new ByActionStatusComponentException(
533 componentsUtils.convertFromStorageResponse(latestVersionEither.right().value(), componentType));
535 List<Component> components = latestVersionEither.left().value();
536 Component component = components.stream().filter(Component::isHighestVersion).findFirst().orElse(null);
537 if (component == null) {
538 component = components.stream().filter(c -> c.getLifecycleState() == LifecycleStateEnum.CERTIFIED).findFirst().orElse(null);
540 if (component == null) {
541 throw new ByResponseFormatComponentException(
542 componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, componentType)));
544 resourceCommonInfo.setResourceName(component.getName());
545 // TODO remove after migration - handle artifact not found(no
548 if (null == component.getToscaArtifacts() || component.getToscaArtifacts().isEmpty()) {
549 throw new ByResponseFormatComponentException(
550 componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
553 final ArtifactDefinition csarArtifact = component.getToscaArtifacts().values().stream()
554 .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny().orElseThrow(() -> {
555 throw new ByResponseFormatComponentException(
556 componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
558 return artifactsBusinessLogic.handleDownloadToscaModelRequest(component, csarArtifact);
561 protected StorageOperationStatus markComponentToDelete(Component component) {
562 ComponentTypeEnum componentType = component.getComponentType();
563 String uniqueId = component.getUniqueId();
564 if (Boolean.TRUE.equals(component.getIsDeleted())) {
565 log.info("component {} already marked as deleted. id= {}, type={}", component.getName(), uniqueId, componentType);
566 return StorageOperationStatus.NOT_FOUND;
568 StorageOperationStatus markResourceToDelete = toscaOperationFacade.markComponentToDelete(component);
569 if (StorageOperationStatus.OK != markResourceToDelete) {
570 log.debug("failed to mark component {} of type {} for delete. error = {}", uniqueId, componentType, markResourceToDelete);
571 return markResourceToDelete;
573 log.debug("Component {} of type {} was marked as deleted", uniqueId, componentType);
574 updateCatalog(component, ChangeTypeEnum.DELETE);
575 return StorageOperationStatus.OK;
579 public Either<Boolean, ResponseFormat> validateAndUpdateDescription(User user, Component currentComponent, Component updatedComponent,
580 AuditingActionEnum auditingAction) {
581 String descriptionUpdated = updatedComponent.getDescription();
582 String descriptionCurrent = currentComponent.getDescription();
583 if (descriptionUpdated != null && !descriptionCurrent.equals(descriptionUpdated)) {
584 componentDescriptionValidator.validateAndCorrectField(user, updatedComponent, auditingAction);
585 currentComponent.setDescription(updatedComponent.getDescription());
587 return Either.left(true);
590 public Either<Boolean, ResponseFormat> validateAndUpdateProjectCode(User user, Component currentComponent, Component updatedComponent) {
591 String projectCodeUpdated = updatedComponent.getProjectCode();
592 String projectCodeCurrent = currentComponent.getProjectCode();
593 if (projectCodeUpdated != null && !projectCodeCurrent.equals(projectCodeUpdated)) {
595 componentProjectCodeValidator.validateAndCorrectField(user, updatedComponent, null);
596 } catch (ComponentException exp) {
597 ResponseFormat errorRespons = exp.getResponseFormat();
598 return Either.right(errorRespons);
600 currentComponent.setProjectCode(updatedComponent.getProjectCode());
602 return Either.left(true);
605 public Either<Boolean, ResponseFormat> validateAndUpdateIcon(User user, Component currentComponent, Component updatedComponent,
606 boolean hasBeenCertified) {
607 String iconUpdated = updatedComponent.getIcon();
608 String iconCurrent = currentComponent.getIcon();
609 if (iconUpdated != null && !iconCurrent.equals(iconUpdated)) {
610 if (!hasBeenCertified) {
611 componentIconValidator.validateAndCorrectField(user, updatedComponent, null);
612 currentComponent.setIcon(updatedComponent.getIcon());
614 log.info("icon {} cannot be updated once the component has been certified once.", iconUpdated);
615 ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_PARAMETER_CANNOT_BE_CHANGED, "Icon",
616 currentComponent.getComponentType().name().toLowerCase());
617 return Either.right(errorResponse);
620 return Either.left(true);
623 protected Either<List<String>, ResponseFormat> deleteMarkedComponents(ComponentTypeEnum componentType) {
624 log.trace("start deleteMarkedComponents");
625 Either<List<String>, StorageOperationStatus> deleteMarkedElements = toscaOperationFacade.deleteMarkedElements(componentType);
626 if (deleteMarkedElements.isRight()) {
627 janusGraphDao.rollback();
628 ResponseFormat responseFormat = componentsUtils
629 .getResponseFormat(componentsUtils.convertFromStorageResponse(deleteMarkedElements.right().value(), componentType));
630 return Either.right(responseFormat);
632 log.trace("end deleteMarkedComponents");
633 janusGraphDao.commit();
634 return Either.left(deleteMarkedElements.left().value());
637 public Either<List<ArtifactDefinition>, StorageOperationStatus> getComponentArtifactsForDelete(String parentId, NodeTypeEnum parentType) {
638 List<ArtifactDefinition> artifacts = new ArrayList<>();
639 Either<Map<String, ArtifactDefinition>, StorageOperationStatus> artifactsResponse = artifactToscaOperation.getArtifacts(parentId);
640 if (artifactsResponse.isRight()) {
641 if (artifactsResponse.right().value() != StorageOperationStatus.NOT_FOUND) {
642 log.debug("failed to retrieve artifacts for {} {}", parentType, parentId);
643 return Either.right(artifactsResponse.right().value());
646 artifacts.addAll(artifactsResponse.left().value().values());
648 return Either.left(artifacts);
654 * @param dataParamsToReturn - ui list of params to return
657 public Either<UiComponentDataTransfer, ResponseFormat> getComponentDataFilteredByParams(String componentId, User user,
658 List<String> dataParamsToReturn) {
660 validateUserExists(user);
662 UiComponentDataTransfer result = new UiComponentDataTransfer();
663 if (dataParamsToReturn == null || dataParamsToReturn.isEmpty()) {
666 Either<UiComponentDataTransfer, ResponseFormat> uiDataTransferEither = getUiComponentDataTransferByComponentId(componentId,
668 if (uiDataTransferEither.isRight()) {
669 return Either.right(uiDataTransferEither.right().value());
671 result = uiDataTransferEither.left().value();
673 return Either.left(result);
676 protected <T extends Component> void generateAndAddInputsFromGenericTypeProperties(T component, Resource genericType) {
677 List<InputDefinition> genericAndComponentInputs = new ArrayList<>();
678 List<InputDefinition> genericInputs = genericTypeBusinessLogic.generateInputsFromGenericTypeProperties(genericType);
679 genericAndComponentInputs.addAll(genericInputs);
680 if (null != component.getInputs()) {
681 List<InputDefinition> nonGenericInputsFromComponent = getAllNonGenericInputsFromComponent(genericInputs, component.getInputs());
682 genericAndComponentInputs.addAll(nonGenericInputsFromComponent);
684 component.setInputs(genericAndComponentInputs);
687 private List<InputDefinition> getAllNonGenericInputsFromComponent(List<InputDefinition> genericInputs, List<InputDefinition> componentInputs) {
688 if (genericInputs == null) {
689 return componentInputs;
691 Map<String, InputDefinition> inputByNameMap = MapUtil.toMap(genericInputs, InputDefinition::getName);
692 List<InputDefinition> componentNonGenericInputs = new ArrayList<>();
693 componentInputs.stream().forEach(input -> {
694 if (!inputByNameMap.containsKey(input.getName())) {
695 componentNonGenericInputs.add(input);
698 return componentNonGenericInputs;
701 protected void generatePropertiesFromGenericType(final Component component, final Resource genericType) {
702 if (CollectionUtils.isEmpty(genericType.getProperties())) {
705 final List<PropertyDefinition> genericTypePropertyList = genericType.getProperties().stream().map(PropertyDefinition::new)
706 .peek(propertyDefinition -> propertyDefinition.setUniqueId(null)).collect(Collectors.toList());
707 if (component.getProperties() == null) {
708 component.setProperties(new ArrayList<>(genericTypePropertyList));
710 List<PropertyDefinition> servicePropertyList = component.getProperties();
711 genericTypePropertyList.stream()
712 .filter(property -> servicePropertyList.stream().noneMatch(property1 -> property1.getName().equals(property.getName())))
713 .forEach(servicePropertyList::add);
715 component.getProperties().forEach(propertyDefinition -> propertyDefinition.setUniqueId(null));
718 protected <T extends Component> Resource fetchAndSetDerivedFromGenericType(final T component) {
719 return fetchAndSetDerivedFromGenericType(component, null);
722 protected <T extends Component> Resource fetchAndSetDerivedFromGenericType(final T component, final String toscaType) {
723 final Either<Resource, ResponseFormat> genericTypeEither = this.genericTypeBusinessLogic.fetchDerivedFromGenericType(component, toscaType);
724 if (genericTypeEither.isRight()) {
725 log.debug("Failed to fetch latest generic type for component {} of type", component.getName(), component.assetType());
726 throw new ByActionStatusComponentException(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType());
728 final Resource genericTypeResource = genericTypeEither.left().value();
729 component.setDerivedFromGenericInfo(genericTypeResource);
730 return genericTypeResource;
733 public Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> getFilteredComponentInstanceProperties(String componentId,
734 Map<FilterKeyEnum, List<String>> filters,
736 Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> response = null;
737 Either<Component, StorageOperationStatus> getResourceRes = null;
739 if (!filters.containsKey(FilterKeyEnum.NAME_FRAGMENT) && StringUtils.isEmpty(filters.get(FilterKeyEnum.NAME_FRAGMENT).get(0))) {
740 response = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
742 if (userId != null && response == null) {
743 validateUserExists(userId);
745 if (response == null) {
746 getResourceRes = toscaOperationFacade.getToscaElement(componentId);
747 if (getResourceRes.isRight()) {
749 .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getResourceRes.right().value())));
752 if (response == null) {
753 response = getFilteredComponentInstancesProperties(getResourceRes.left().value(), filters);
755 } catch (Exception e) {
756 log.debug("The exception {} occured during filtered instance properties fetching. the containing component is {}. ", e, componentId);
757 response = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
759 if (response != null && response.isLeft()) {
760 toscaOperationFacade.commit();
762 toscaOperationFacade.rollback();
768 private Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> getFilteredComponentInstancesProperties(Component component,
769 Map<FilterKeyEnum, List<String>> filters) {
770 Map<String, List<IComponentInstanceConnectedElement>> filteredProperties = new HashMap<>();
771 Either<Map<String, List<IComponentInstanceConnectedElement>>, ResponseFormat> result = Either.left(filteredProperties);
772 List<ComponentInstance> filteredInstances = getFilteredInstances(component, filters.get(FilterKeyEnum.RESOURCE_TYPE));
773 String propertyNameFragment = filters.get(FilterKeyEnum.NAME_FRAGMENT).get(0);
774 boolean searchByFragment = propertyNameFragment.length() > 3;
775 if (CollectionUtils.isNotEmpty(filteredInstances)) {
776 for (ComponentInstance instance : filteredInstances) {
777 if (component.getComponentInstancesProperties() != null && component.getComponentInstancesProperties()
778 .containsKey(instance.getUniqueId())) {
779 List<IComponentInstanceConnectedElement> currProperties = getFilteredComponentInstanceProperties(
780 component.getComponentInstancesProperties().get(instance.getUniqueId()), propertyNameFragment, searchByFragment);
781 setFilteredProperties(filteredProperties, instance, currProperties);
783 if (component.getComponentInstancesInputs() != null && component.getComponentInstancesInputs().containsKey(instance.getUniqueId())) {
784 List<IComponentInstanceConnectedElement> currInputs = getFilteredComponentInstanceInputs(
785 component.getComponentInstancesInputs().get(instance.getUniqueId()), propertyNameFragment, searchByFragment);
786 if (CollectionUtils.isNotEmpty(currInputs)) {
787 checkFilteredProperties(filteredProperties, instance, currInputs);
795 private void setFilteredProperties(Map<String, List<IComponentInstanceConnectedElement>> filteredProperties, ComponentInstance instance,
796 List<IComponentInstanceConnectedElement> currProperties) {
797 if (CollectionUtils.isNotEmpty(currProperties)) {
798 filteredProperties.put(instance.getUniqueId(), currProperties);
802 private void checkFilteredProperties(Map<String, List<IComponentInstanceConnectedElement>> filteredProperties, ComponentInstance instance,
803 List<IComponentInstanceConnectedElement> currInputs) {
804 if (filteredProperties.get(instance.getUniqueId()) != null) {
805 filteredProperties.get(instance.getUniqueId()).addAll(currInputs);
807 filteredProperties.put(instance.getUniqueId(), currInputs);
811 private List<IComponentInstanceConnectedElement> getFilteredComponentInstanceInputs(List<ComponentInstanceInput> inputs,
812 String propertyNameFragment, boolean searchByFragment) {
813 return inputs.stream().filter(i -> isMatchingInput(i, propertyNameFragment, searchByFragment)).collect(Collectors.toList());
816 private List<IComponentInstanceConnectedElement> getFilteredComponentInstanceProperties(List<ComponentInstanceProperty> instanceProperties,
817 String propertyNameFragment, boolean searchByFragment) {
818 return instanceProperties.stream().filter(p -> isMatchingProperty(p, propertyNameFragment, searchByFragment)).collect(Collectors.toList());
821 private boolean isMatchingInput(ComponentInstanceInput input, String propertyNameFragment, boolean searchByFragment) {
822 boolean isMatching = false;
823 if (searchByFragment && input.getName().toLowerCase().contains(propertyNameFragment)) {
826 if (!searchByFragment && input.getName().equalsIgnoreCase(propertyNameFragment)) {
832 private boolean isMatchingProperty(ComponentInstanceProperty property, String propertyNameFragment, boolean searchByFragment) {
833 boolean isMatching = false;
834 if (searchByFragment && property.getName().toLowerCase().contains(propertyNameFragment)) {
837 if (!searchByFragment && property.getName().equalsIgnoreCase(propertyNameFragment)) {
840 if (!isMatching && !ToscaPropertyType.isPrimitiveType(property.getType())) {
841 isMatching = isMatchingComplexPropertyByRecursively(property, propertyNameFragment, searchByFragment);
846 private boolean isMatchingComplexPropertyByRecursively(PropertyDataDefinition property, String propertyNameFragment, boolean searchByFragment) {
848 List<PropertyDefinition> dataTypeProperties;
849 DataTypeDefinition currentProperty;
850 if (searchByFragment && property.getName().toLowerCase().contains(propertyNameFragment.toLowerCase())) {
853 if (!searchByFragment && property.getName().equalsIgnoreCase(propertyNameFragment)) {
856 propertyType = isEmptyInnerType(property) ? property.getType() : property.getSchema().getProperty().getType();
857 if (ToscaPropertyType.isScalarType(propertyType)) {
860 Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByNameRes = propertyOperation.getDataTypeByName(propertyType, null);
861 if (getDataTypeByNameRes.isRight()) {
864 currentProperty = getDataTypeByNameRes.left().value();
865 dataTypeProperties = currentProperty.getProperties();
866 boolean dataPropertiesNotNull = CollectionUtils.isNotEmpty(dataTypeProperties);
867 BooleanSupplier dataMatchesComplexProperty = () -> isMatchingComplexProperty(propertyNameFragment, searchByFragment, dataTypeProperties);
868 BooleanSupplier parentPropertiesNotNull = () -> CollectionUtils.isNotEmpty(currentProperty.getDerivedFrom().getProperties());
869 BooleanSupplier parentDataMatchesComplexProperty = () -> isMatchingComplexProperty(propertyNameFragment, searchByFragment,
870 currentProperty.getDerivedFrom().getProperties());
871 return ((dataPropertiesNotNull && dataMatchesComplexProperty.getAsBoolean()) || (parentPropertiesNotNull.getAsBoolean()
872 && parentDataMatchesComplexProperty.getAsBoolean()));
875 private boolean isMatchingComplexProperty(String propertyNameFragment, boolean searchByFragment, List<PropertyDefinition> dataTypeProperties) {
876 for (PropertyDefinition prop : dataTypeProperties) {
877 if (isMatchingComplexPropertyByRecursively(prop, propertyNameFragment, searchByFragment)) {
884 private boolean isEmptyInnerType(PropertyDataDefinition property) {
885 return property == null || property.getSchema() == null || property.getSchema().getProperty() == null
886 || property.getSchema().getProperty().getType() == null;
889 public Either<Boolean, ResponseFormat> shouldUpgradeToLatestGeneric(Component clonedComponent) {
890 if (!clonedComponent.deriveFromGeneric() || StringUtils.isNotEmpty(clonedComponent.getModel())) {
891 return Either.left(false);
893 Boolean shouldUpgrade = false;
894 String currentGenericType = clonedComponent.getDerivedFromGenericType();
895 String currentGenericVersion = clonedComponent.getDerivedFromGenericVersion();
896 Resource genericTypeResource = fetchAndSetDerivedFromGenericType(clonedComponent);
897 if (null == currentGenericType || !currentGenericType.equals(genericTypeResource.getToscaResourceName()) || !currentGenericVersion
898 .equals(genericTypeResource.getVersion())) {
899 shouldUpgrade = upgradeToLatestGeneric(clonedComponent, genericTypeResource);
900 if (!shouldUpgrade) {
901 reverntUpdateOfGenericVersion(clonedComponent, currentGenericType, currentGenericVersion);
904 return Either.left(shouldUpgrade);
907 private void reverntUpdateOfGenericVersion(Component clonedComponent, String currentGenericType, String currentGenericVersion) {
908 clonedComponent.setDerivedFromGenericType(currentGenericType);
909 clonedComponent.setDerivedFromGenericVersion(currentGenericVersion);
912 private <T extends ToscaDataDefinition> Either<Map<String, T>, String> validateNoConflictingProperties(List<T> currentList,
913 List<T> upgradedList) {
914 Map<String, T> currentMap = ToscaDataDefinition.listToMapByName(currentList);
915 Map<String, T> upgradedMap = ToscaDataDefinition.listToMapByName(upgradedList);
916 return ToscaDataDefinition.mergeDataMaps(upgradedMap, currentMap, true);
919 private boolean shouldUpgradeNodeType(Component componentToCheckOut, Resource latestGeneric) {
920 List<PropertyDefinition> genericTypeProps = latestGeneric.getProperties();
921 Either<Map<String, PropertyDefinition>, String> validPropertiesMerge = validateNoConflictingProperties(genericTypeProps,
922 ((Resource) componentToCheckOut).getProperties());
923 if (validPropertiesMerge.isRight()) {
924 if (log.isDebugEnabled()) {
925 log.debug("property {} cannot be overriden, check out performed without upgrading to latest generic",
926 validPropertiesMerge.right().value());
930 List<AttributeDefinition> genericTypeAttributes = latestGeneric.getAttributes();
931 final Either<Map<String, AttributeDefinition>, String> validAttributesMerge = validateNoConflictingProperties(genericTypeAttributes,
932 ((Resource) componentToCheckOut).getAttributes());
933 if (validAttributesMerge.isRight()) {
934 if (log.isDebugEnabled()) {
935 log.debug("attribute {} cannot be overriden, check out performed without upgrading to latest generic",
936 validAttributesMerge.right().value());
943 private boolean upgradeToLatestGeneric(Component componentToCheckOut, Resource latestGeneric) {
944 if (!componentToCheckOut.shouldGenerateInputs()) {
945 //node type - validate properties and attributes
946 return shouldUpgradeNodeType(componentToCheckOut, latestGeneric);
948 List<PropertyDefinition> genericTypeProps = latestGeneric.getProperties();
949 List<InputDefinition> genericTypeInputs = null == genericTypeProps ? null
950 : genericTypeBusinessLogic.convertGenericTypePropertiesToInputsDefintion(genericTypeProps, latestGeneric.getUniqueId());
951 List<InputDefinition> currentList = new ArrayList<>();
952 // nullify existing ownerId from existing list and merge into updated list
953 if (null != componentToCheckOut.getInputs()) {
954 for (InputDefinition input : componentToCheckOut.getInputs()) {
955 InputDefinition copy = new InputDefinition(input);
956 copy.setOwnerId(null);
957 currentList.add(copy);
960 if (null == genericTypeInputs) {
961 componentToCheckOut.setInputs(currentList);
964 Either<Map<String, InputDefinition>, String> eitherMerged = validateNoConflictingProperties(genericTypeInputs, currentList);
965 if (eitherMerged.isRight()) {
966 if (log.isDebugEnabled()) {
967 log.debug("input {} cannot be overriden, check out performed without upgrading to latest generic", eitherMerged.right().value());
971 componentToCheckOut.setInputs(new ArrayList<>(eitherMerged.left().value().values()));
975 private List<ComponentInstance> getFilteredInstances(Component component, List<String> resourceTypes) {
976 List<ComponentInstance> filteredInstances = null;
977 if (CollectionUtils.isEmpty(resourceTypes)) {
978 filteredInstances = component.getComponentInstances();
979 } else if (CollectionUtils.isNotEmpty(component.getComponentInstances())) {
980 filteredInstances = component.getComponentInstances().stream().filter(i -> isMatchingType(i.getOriginType(), resourceTypes))
981 .collect(Collectors.toList());
983 if (filteredInstances == null) {
984 filteredInstances = new ArrayList<>();
986 return filteredInstances;
989 private boolean isMatchingType(OriginTypeEnum originType, List<String> resourceTypes) {
990 boolean isMatchingType = false;
991 for (String resourceType : resourceTypes) {
992 if (originType == OriginTypeEnum.findByValue(resourceType.toUpperCase())) {
993 isMatchingType = true;
997 return isMatchingType;
1000 public Either<Component, ActionStatus> shouldUpgradeToLatestDerived(Component clonedComponent) {
1001 //general implementation. Must be error for service, VF . In ResourceBuisnessLogic exist override
1002 return Either.right(ActionStatus.GENERAL_ERROR);
1005 protected Either<Component, ResponseFormat> updateCatalog(Component component, ChangeTypeEnum changeStatus) {
1006 if (log.isDebugEnabled()) {
1007 log.debug("update Catalog start with Component Type {} And Componet Name {} with change status {}",
1008 component.getComponentType().name(), component.getName(), changeStatus.name());
1010 ActionStatus status = catalogOperations.updateCatalog(changeStatus, component);
1011 if (status != ActionStatus.OK) {
1012 return Either.right(componentsUtils.getResponseFormat(status));
1014 return Either.left(component);
1017 public CatalogOperation getCatalogOperations() {
1018 return catalogOperations;
1022 public void setCatalogOperations(CatalogOperation catalogOperations) {
1023 this.catalogOperations = catalogOperations;
1026 public List<GroupDefinition> throwComponentException(ResponseFormat responseFormat) {
1027 throw new ByResponseFormatComponentException(responseFormat);