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.impl;
24 import com.fasterxml.jackson.databind.DeserializationFeature;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.fasterxml.jackson.databind.module.SimpleModule;
27 import com.google.gson.Gson;
28 import com.google.gson.GsonBuilder;
29 import com.google.gson.reflect.TypeToken;
31 import fj.data.Either;
32 import java.lang.reflect.Type;
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
37 import java.util.Optional;
39 import java.util.stream.Collectors;
40 import javax.servlet.http.HttpServletRequest;
41 import org.apache.commons.collections.CollectionUtils;
42 import org.apache.commons.lang3.StringUtils;
43 import org.onap.logging.ref.slf4j.ONAPLogConstants;
44 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
45 import org.openecomp.sdc.be.auditing.impl.AuditAuthRequestEventFactory;
46 import org.openecomp.sdc.be.auditing.impl.AuditConsumerEventFactory;
47 import org.openecomp.sdc.be.auditing.impl.AuditEcompOpEnvEventFactory;
48 import org.openecomp.sdc.be.auditing.impl.AuditGetUebClusterEventFactory;
49 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
50 import org.openecomp.sdc.be.auditing.impl.category.AuditCategoryEventFactory;
51 import org.openecomp.sdc.be.auditing.impl.category.AuditGetCategoryHierarchyEventFactory;
52 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDeployEventFactory;
53 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDownloadEventFactory;
54 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionEngineEventFactoryManager;
55 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionNotificationEventFactory;
56 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionStatusEventFactory;
57 import org.openecomp.sdc.be.auditing.impl.distribution.AuditRegUnregDistributionEngineEventFactory;
58 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditActivateServiceExternalApiEventFactory;
59 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetExternalApiEventFactory;
60 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetListExternalApiEventFactory;
61 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditChangeLifecycleExternalApiEventFactory;
62 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateResourceExternalApiEventFactory;
63 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateServiceExternalApiEventFactory;
64 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCrudExternalApiArtifactEventFactory;
65 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditDownloadArtifactExternalApiEventFactory;
66 import org.openecomp.sdc.be.auditing.impl.resourceadmin.AuditResourceEventFactoryManager;
67 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditGetUsersListEventFactory;
68 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAccessEventFactory;
69 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAdminEventFactory;
70 import org.openecomp.sdc.be.components.distribution.engine.DmaapConsumer;
71 import org.openecomp.sdc.be.components.impl.ImportUtils;
72 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
73 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
74 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
75 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
76 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
77 import org.openecomp.sdc.be.config.BeEcompErrorManager;
78 import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
79 import org.openecomp.sdc.be.dao.api.ActionStatus;
80 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
81 import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
82 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
83 import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
84 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
85 import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
86 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
87 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
88 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
89 import org.openecomp.sdc.be.model.ArtifactDefinition;
90 import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
91 import org.openecomp.sdc.be.model.Component;
92 import org.openecomp.sdc.be.model.ComponentInstance;
93 import org.openecomp.sdc.be.model.ConsumerDefinition;
94 import org.openecomp.sdc.be.model.DataTypeDefinition;
95 import org.openecomp.sdc.be.model.GroupTypeDefinition;
96 import org.openecomp.sdc.be.model.LifecycleStateEnum;
97 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
98 import org.openecomp.sdc.be.model.PropertyConstraint;
99 import org.openecomp.sdc.be.model.RequirementDefinition;
100 import org.openecomp.sdc.be.model.Resource;
101 import org.openecomp.sdc.be.model.User;
102 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
103 import org.openecomp.sdc.be.model.operations.StorageException;
104 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
105 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
106 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserializer;
107 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
108 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
109 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
110 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
111 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
112 import org.openecomp.sdc.be.resources.data.auditing.model.OperationalEnvAuditData;
113 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
114 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
115 import org.openecomp.sdc.be.tosca.ToscaError;
116 import org.openecomp.sdc.be.ui.model.UIConstraint;
117 import org.openecomp.sdc.be.ui.model.UiLeftPaletteComponent;
118 import org.openecomp.sdc.common.api.Constants;
119 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
120 import org.openecomp.sdc.common.log.enums.LogLevel;
121 import org.openecomp.sdc.common.log.enums.Severity;
122 import org.openecomp.sdc.common.log.wrappers.Logger;
123 import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
124 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
125 import org.openecomp.sdc.common.util.ValidationUtils;
126 import org.openecomp.sdc.exception.ResponseFormat;
127 import org.slf4j.MarkerFactory;
128 import org.springframework.beans.factory.annotation.Autowired;
130 @org.springframework.stereotype.Component("componentUtils")
131 public class ComponentsUtils {
133 private static final String CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE = "convert storage response {} to action response {}";
134 private static final String INSIDE_AUDITING_FOR_AUDIT_ACTION = "Inside auditing for audit action {}";
135 private static final String AUDIT_BEFORE_SENDING_RESPONSE = "audit before sending response";
136 private static final String CONVERT_JSON_TO_OBJECT = "convertJsonToObject";
137 private static final Logger log = Logger.getLogger(ComponentsUtils.class);
138 private static final String PARTNER_NAME = "UNKNOWN";
139 private static LoggerSdcAudit audit = new LoggerSdcAudit(DmaapConsumer.class);
140 private final AuditingManager auditingManager;
141 private final ResponseFormatManager responseFormatManager;
144 public ComponentsUtils(AuditingManager auditingManager) {
145 this.auditingManager = auditingManager;
146 this.responseFormatManager = ResponseFormatManager.getInstance();
149 public static <T> T parseJsonToObject(String data, Class<T> clazz) {
150 Type constraintType = new TypeToken<PropertyConstraint>() {
152 Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
153 log.trace("convert json to object. json=\n{}", data);
154 return gson.fromJson(data, clazz);
157 private static Set<String> getNodesFiltersToBeDeleted(final Component component, final String componentInstanceName) {
158 return component.getComponentInstances().stream().filter(ci -> isNodeFilterUsingChangedCi(ci, componentInstanceName))
159 .map(ComponentInstance::getName).collect(Collectors.toSet());
162 public static Set<String> getNodesFiltersToBeDeleted(final Component component, final ComponentInstance componentInstance) {
163 return getNodesFiltersToBeDeleted(component, componentInstance.getName());
166 private static boolean isNodeFilterUsingChangedCi(final ComponentInstance componentInstance, final String componentInstanceName) {
167 if (CollectionUtils.isEmpty(componentInstance.getDirectives())) {
170 if (componentInstance.getNodeFilter() == null || componentInstance.getNodeFilter().getProperties() == null
171 || componentInstance.getNodeFilter().getProperties().getListToscaDataDefinition() == null) {
174 return componentInstance.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
175 .anyMatch(property -> isPropertyConstraintChangedByCi(property, componentInstanceName));
178 private static boolean isPropertyConstraintChangedByCi(
179 final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition, final String componentInstanceName) {
180 final List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
181 if (constraints == null) {
184 return constraints.stream().anyMatch(constraint -> isConstraintChangedByCi(constraint, componentInstanceName));
187 private static boolean isConstraintChangedByCi(final String constraint, final String componentInstanceName) {
188 final UIConstraint uiConstraint = new ConstraintConvertor().convert(constraint);
189 if (uiConstraint == null || uiConstraint.getSourceType() == null) {
192 if (!uiConstraint.getSourceType().equals(ConstraintConvertor.PROPERTY_CONSTRAINT)) {
195 return uiConstraint.getSourceName().equals(componentInstanceName);
198 public AuditingManager getAuditingManager() {
199 return auditingManager;
202 public <T> Either<T, ResponseFormat> convertJsonToObject(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum) {
204 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
205 log.debug("object is null after converting from json");
206 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
207 return Either.right(responseFormat);
210 T obj = parseJsonToObject(data, clazz);
211 return Either.left(obj);
212 } catch (Exception e) {
214 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
215 log.debug("failed to convert from json {}", data, e);
216 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
217 return Either.right(responseFormat);
221 public <T> Either<T, ResponseFormat> convertJsonToObjectUsingObjectMapper(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum,
222 ComponentTypeEnum typeEnum) {
224 ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
225 mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
226 mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
228 log.trace("convert json to object. json=\n{}", data);
229 SimpleModule module = new SimpleModule("customDeserializationModule");
230 module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
231 mapper.registerModule(module);
232 component = mapper.readValue(data, clazz);
233 if (component == null) {
234 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
235 log.debug("object is null after converting from json");
236 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
237 return Either.right(responseFormat);
239 } catch (Exception e) {
240 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
241 log.debug("failed to convert from json {}", data, e);
242 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
243 return Either.right(responseFormat);
245 return Either.left(component);
248 public ResponseFormat getResponseFormat(ActionStatus actionStatus, String... params) {
249 return responseFormatManager.getResponseFormat(actionStatus, params);
252 public ResponseFormat getResponseFormat(StorageOperationStatus storageStatus, String... params) {
253 return responseFormatManager.getResponseFormat(this.convertFromStorageResponse(storageStatus), params);
256 public <T> Either<List<T>, ResponseFormat> convertToResponseFormatOrNotFoundErrorToEmptyList(StorageOperationStatus storageOperationStatus) {
257 return storageOperationStatus.equals(StorageOperationStatus.NOT_FOUND) ? Either.left(Collections.emptyList())
258 : Either.right(getResponseFormat(storageOperationStatus));
262 * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus
263 * is anonymously converted from storage operation, and the caller doesn't know what actionStatus he received. It's caller's Responsibility to
264 * fill the resource object passed to this function with needed fields.
266 * Note that RESOURCE_IN_USE case passes hardcoded "resource" string to the error parameter. This means that if Resource object will also be used
267 * for Service, this code needs to be refactored and we should tell Resource from Service.
269 * @param actionStatus
273 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, Component resource) {
274 if (resource == null) {
275 return getResponseFormat(actionStatus);
277 ResponseFormat responseFormat;
278 switch (actionStatus) {
279 case COMPONENT_VERSION_ALREADY_EXIST:
280 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
281 resource.getVersion());
283 case RESOURCE_NOT_FOUND:
284 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resource.getName());
286 case COMPONENT_NAME_ALREADY_EXIST:
287 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
290 case COMPONENT_IN_USE:
291 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, ComponentTypeEnum.RESOURCE.name().toLowerCase(),
292 resource.getUniqueId());
295 responseFormat = getResponseFormat(actionStatus);
298 return responseFormat;
301 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, String resourceName) {
302 if (resourceName == null) {
303 return getResponseFormat(actionStatus);
305 ResponseFormat responseFormat;
306 if (actionStatus == ActionStatus.RESOURCE_NOT_FOUND) {
307 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceName);
309 responseFormat = getResponseFormat(actionStatus);
311 return responseFormat;
314 public ResponseFormat getResponseFormatByCapabilityType(ActionStatus actionStatus, CapabilityTypeDefinition capabilityType) {
315 if (capabilityType == null) {
316 return getResponseFormat(actionStatus);
318 ResponseFormat responseFormat;
319 if (actionStatus == ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST) {
320 responseFormat = getResponseFormat(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, capabilityType.getType());
322 responseFormat = getResponseFormat(actionStatus);
324 return responseFormat;
327 public <T> ResponseFormat getResponseFormatByElement(ActionStatus actionStatus, T obj) {
329 return getResponseFormat(actionStatus);
331 ResponseFormat responseFormat = null;
332 if (actionStatus == ActionStatus.MISSING_CAPABILITY_TYPE) {
333 if (obj instanceof List && org.apache.commons.collections.CollectionUtils.isNotEmpty((List) obj)) {
334 List list = (List) obj;
335 if (list.get(0) instanceof RequirementDefinition) {
336 responseFormat = getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, ((RequirementDefinition) list
337 .get(0)).getName()); //Arbitray index, all we need is single object
338 return responseFormat;
341 log.debug("UNKNOWN TYPE : expecting obj as a non empty List<RequirmentsDefinitions>");
343 responseFormat = getResponseFormat(actionStatus);
345 return responseFormat;
349 * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus
350 * is anynomously converted from storage operation, and the caller doesn't know what actionStatus he received. It's caller's responisibility to
351 * fill the passed resource object with needed fields.
353 * @param actionStatus
357 ResponseFormat getResponseFormatByUser(ActionStatus actionStatus, User user) {
359 return getResponseFormat(actionStatus);
361 ResponseFormat requestErrorWrapper;
362 switch (actionStatus) {
363 case INVALID_USER_ID:
364 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
366 case INVALID_EMAIL_ADDRESS:
367 requestErrorWrapper = getResponseFormat(actionStatus, user.getEmail());
370 requestErrorWrapper = getResponseFormat(actionStatus, user.getRole());
373 case USER_ALREADY_EXIST:
375 case USER_HAS_ACTIVE_ELEMENTS:
376 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
379 requestErrorWrapper = getResponseFormat(actionStatus);
382 return requestErrorWrapper;
385 public ResponseFormat getResponseFormatByUserId(ActionStatus actionStatus, String userId) {
386 User user = new User();
387 user.setUserId(userId);
388 return getResponseFormatByUser(actionStatus, user);
391 public ResponseFormat getResponseFormatByDE(ActionStatus actionStatus, String envName) {
392 ResponseFormat responseFormat;
393 switch (actionStatus) {
394 case DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE:
395 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE, envName);
397 case DISTRIBUTION_ENVIRONMENT_NOT_FOUND:
398 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND, envName);
401 responseFormat = getResponseFormat(actionStatus);
404 return responseFormat;
407 public ResponseFormat getResponseFormatByArtifactId(ActionStatus actionStatus, String... params) {
408 ResponseFormat responseFormat;
409 switch (actionStatus) {
410 case RESOURCE_NOT_FOUND:
411 case ARTIFACT_NOT_FOUND:
412 responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, params);
414 case ARTIFACT_NAME_INVALID:
415 responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NAME_INVALID, params);
418 responseFormat = getResponseFormat(actionStatus);
421 return responseFormat;
424 public ResponseFormat getInvalidContentErrorAndAudit(User user, AuditingActionEnum actionEnum) {
425 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
426 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
427 auditAdminUserAction(actionEnum, user, null, null, responseFormat);
428 return responseFormat;
431 public ResponseFormat getInvalidContentErrorAndAudit(User user, String resourceName, AuditingActionEnum actionEnum) {
432 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
433 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
434 auditResource(responseFormat, user, resourceName, actionEnum);
435 return responseFormat;
438 public ResponseFormat getInvalidContentErrorForConsumerAndAudit(User user, ConsumerDefinition consumer, AuditingActionEnum actionEnum) {
439 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
440 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
441 auditConsumerCredentialsEvent(actionEnum, consumer, responseFormat, user);
442 return responseFormat;
445 private ResponseFormat getInvalidContentErrorAndAuditComponent(User user, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
446 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
447 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
448 auditComponentAdmin(responseFormat, user, null, actionEnum, typeEnum);
449 return responseFormat;
452 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum,
453 ResourceVersionInfo prevResFields) {
454 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum, prevResFields, null, null);
457 public void auditResource(ResponseFormat responseFormat, User modifier, String resourceName, AuditingActionEnum actionEnum) {
458 auditResource(responseFormat, modifier, null, resourceName, actionEnum);
461 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum) {
462 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum);
465 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum) {
466 auditResource(responseFormat, modifier, resource, resourceName, actionEnum, ResourceVersionInfo.newBuilder().build(), null, null);
469 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum,
470 ResourceVersionInfo prevResFields, String currentArtifactUuid, ArtifactDefinition artifactDefinition) {
471 if (actionEnum != null) {
472 int status = responseFormat.getStatus();
474 String resourceCurrVersion = null;
475 String resourceCurrState = null;
476 String invariantUUID = null;
477 String resourceType = ComponentTypeEnum.RESOURCE.getValue();
478 String toscaNodeType = null;
479 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
480 String message = getMessageString(responseFormat);
481 String artifactData = buildAuditingArtifactData(artifactDefinition);
482 if (resource != null) {
483 resourceName = resource.getName();
484 resourceCurrVersion = resource.getVersion();
485 if (resource.getLifecycleState() != null) {
486 resourceCurrState = resource.getLifecycleState().name();
488 if (resource.getResourceType() != null) {
489 resourceType = resource.getResourceType().name();
491 invariantUUID = resource.getInvariantUUID();
492 uuid = resource.getUUID();
493 toscaNodeType = resource.getToscaResourceName();
495 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(actionEnum,
496 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(uuid)
497 .build(), new ResourceCommonInfo(resourceName, resourceType), prevResFields,
498 ResourceVersionInfo.newBuilder().artifactUuid(currentArtifactUuid).state(resourceCurrState).version(resourceCurrVersion).build(),
499 invariantUUID, modifier, artifactData, null, null, toscaNodeType);
500 getAuditingManager().auditEvent(factory);
504 private String getMessageString(ResponseFormat responseFormat) {
506 if (responseFormat.getMessageId() != null) {
507 message = responseFormat.getMessageId() + ": ";
509 message += responseFormat.getFormattedMessage();
513 public void auditDistributionDownload(ResponseFormat responseFormat, DistributionData distributionData) {
514 log.trace("Inside auditing");
515 int status = responseFormat.getStatus();
516 String message = getMessageString(responseFormat);
517 AuditDistributionDownloadEventFactory factory = new AuditDistributionDownloadEventFactory(
518 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).build(), distributionData);
519 getAuditingManager().auditEvent(factory);
522 public void auditExternalGetAsset(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
523 ResourceCommonInfo resourceCommonInfo, String requestId, String serviceInstanceId) {
524 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
525 AuditEventFactory factory = new AuditAssetExternalApiEventFactory(actionEnum,
526 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
527 .serviceInstanceId(serviceInstanceId).build(), resourceCommonInfo, distributionData);
528 getAuditingManager().auditEvent(factory);
531 public void auditExternalGetAssetList(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
533 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
534 AuditEventFactory factory = new AuditAssetListExternalApiEventFactory(actionEnum,
535 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
536 .build(), distributionData);
537 getAuditingManager().auditEvent(factory);
540 public void auditChangeLifecycleAction(ResponseFormat responseFormat, ComponentTypeEnum componentType, String requestId, Component component,
541 Component responseObject, DistributionData distributionData, User modifier) {
542 String invariantUuid = "";
543 String serviceInstanceId = "";
544 ResourceVersionInfo currResourceVersionInfo = null;
545 ResourceVersionInfo prevResourceVersionInfo = null;
546 ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
547 if (component != null) {
548 prevResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
549 resourceCommonInfo.setResourceName(component.getName());
551 if (responseObject != null) {
552 currResourceVersionInfo = buildResourceVersionInfoFromComponent(responseObject);
553 invariantUuid = responseObject.getInvariantUUID();
554 serviceInstanceId = responseObject.getUUID();
555 } else if (component != null) {
556 currResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
557 invariantUuid = component.getInvariantUUID();
558 serviceInstanceId = component.getUUID();
560 if (prevResourceVersionInfo == null) {
561 prevResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
563 if (currResourceVersionInfo == null) {
564 currResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
566 AuditEventFactory factory = new AuditChangeLifecycleExternalApiEventFactory(
567 CommonAuditData.newBuilder().serviceInstanceId(serviceInstanceId).requestId(requestId).description(getMessageString(responseFormat))
568 .status(responseFormat.getStatus()).build(), resourceCommonInfo, distributionData, prevResourceVersionInfo, currResourceVersionInfo,
569 invariantUuid, modifier);
570 getAuditingManager().auditEvent(factory);
573 private ResourceVersionInfo buildResourceVersionInfoFromComponent(Component component) {
574 return ResourceVersionInfo.newBuilder().version(component.getVersion()).state(component.getLifecycleState().name()).build();
577 public void auditExternalCrudApi(ResponseFormat responseFormat, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo,
578 HttpServletRequest request, ArtifactDefinition artifactDefinition, String artifactUuid) {
579 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
580 ResourceVersionInfo currResourceVersionInfo;
581 User modifier = new User();
582 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
583 String artifactData = "";
584 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
585 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
586 if (artifactDefinition == null) {
587 currResourceVersionInfo = ResourceVersionInfo.newBuilder().artifactUuid(artifactUuid).build();
589 currResourceVersionInfo = ResourceVersionInfo.newBuilder().artifactUuid(artifactDefinition.getArtifactUUID())
590 .version(artifactDefinition.getArtifactVersion()).build();
591 artifactData = buildAuditingArtifactData(artifactDefinition);
592 modifier.setUserId(artifactDefinition.getUserIdLastUpdater());
594 AuditEventFactory factory = new AuditCrudExternalApiArtifactEventFactory(actionEnum,
595 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
596 .build(), resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().build(), currResourceVersionInfo, null, modifier,
598 getAuditingManager().auditEvent(factory);
601 public boolean isExternalApiEvent(AuditingActionEnum auditingActionEnum) {
602 return auditingActionEnum != null && auditingActionEnum.getAuditingEsType().equals(AuditingTypesConstants.EXTERNAL_API_EVENT_TYPE);
605 public void auditCreateResourceExternalApi(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo, HttpServletRequest request,
607 String invariantUuid = null;
608 String serviceInstanceId = null;
609 User modifier = new User();
610 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
611 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
612 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
613 ResourceVersionInfo currResourceVersionInfo;
614 if (resource != null) {
615 currResourceVersionInfo = ResourceVersionInfo.newBuilder().state(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())
616 .version(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION).build();
617 resourceCommonInfo.setResourceName(resource.getName());
618 invariantUuid = resource.getInvariantUUID();
619 serviceInstanceId = resource.getUUID();
621 currResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
623 AuditEventFactory factory = new AuditCreateResourceExternalApiEventFactory(
624 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
625 .serviceInstanceId(serviceInstanceId).build(), resourceCommonInfo, distributionData, currResourceVersionInfo, invariantUuid,
627 getAuditingManager().auditEvent(factory);
630 public void auditCreateServiceExternalApi(ResponseFormat responseFormat, HttpServletRequest request, Component service) {
631 String invariantUuid = null;
632 String serviceInstanceId = null;
633 User modifier = new User();
634 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
635 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
636 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
637 if (null != service) {
638 invariantUuid = service.getInvariantUUID();
639 serviceInstanceId = service.getUUID();
641 AuditEventFactory factory = new AuditCreateServiceExternalApiEventFactory(
642 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
643 .serviceInstanceId(serviceInstanceId).build(), new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()), distributionData,
644 invariantUuid, modifier);
645 getAuditingManager().auditEvent(factory);
648 public void auditExternalActivateService(ResponseFormat responseFormat, DistributionData distributionData, String requestId,
649 String serviceInstanceUuid, User modifier) {
650 AuditEventFactory factory = new AuditActivateServiceExternalApiEventFactory(
651 CommonAuditData.newBuilder().serviceInstanceId(serviceInstanceUuid).description(getMessageString(responseFormat))
652 .status(responseFormat.getStatus()).requestId(requestId).build(), new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()),
653 distributionData, "", modifier);
654 getAuditingManager().auditEvent(factory);
657 public void auditExternalDownloadArtifact(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo, DistributionData distributionData,
658 String requestId, String currArtifactUuid, String userId) {
659 User modifier = new User();
660 modifier.setUserId(userId);
661 AuditEventFactory factory = new AuditDownloadArtifactExternalApiEventFactory(
662 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus()).requestId(requestId)
663 .build(), resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().artifactUuid(currArtifactUuid).build(), modifier);
664 getAuditingManager().auditEvent(factory);
667 private String buildAuditingArtifactData(ArtifactDefinition artifactDefinition) {
668 StringBuilder sb = new StringBuilder();
669 if (artifactDefinition != null) {
670 sb.append(artifactDefinition.getArtifactGroupType().getType()).append(",").append("'").append(artifactDefinition.getArtifactLabel())
671 .append("'").append(",").append(artifactDefinition.getArtifactType()).append(",").append(artifactDefinition.getArtifactName())
672 .append(",").append(artifactDefinition.getTimeout()).append(",").append(artifactDefinition.getEsId());
674 sb.append(artifactDefinition.getArtifactVersion() != null ? artifactDefinition.getArtifactVersion() : " ");
676 sb.append(artifactDefinition.getArtifactUUID() != null ? artifactDefinition.getArtifactUUID() : " ");
678 return sb.toString();
681 public void auditCategory(ResponseFormat responseFormat, User modifier, String categoryName, String subCategoryName, String groupingName,
682 AuditingActionEnum actionEnum, String componentType) {
683 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
684 AuditEventFactory factory = new AuditCategoryEventFactory(actionEnum,
685 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
686 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, categoryName, subCategoryName, groupingName, componentType);
687 getAuditingManager().auditEvent(factory);
690 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse) {
691 return convertFromStorageResponse(storageResponse, ComponentTypeEnum.RESOURCE);
694 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse, ComponentTypeEnum type) {
695 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
696 if (storageResponse == null) {
699 switch (storageResponse) {
701 responseEnum = ActionStatus.OK;
703 case CONNECTION_FAILURE:
705 responseEnum = ActionStatus.GENERAL_ERROR;
708 responseEnum = ActionStatus.INVALID_CONTENT;
710 case ENTITY_ALREADY_EXISTS:
711 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
713 case PARENT_RESOURCE_NOT_FOUND:
714 responseEnum = ActionStatus.PARENT_RESOURCE_NOT_FOUND;
716 case MULTIPLE_PARENT_RESOURCE_FOUND:
717 responseEnum = ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND;
720 if (ComponentTypeEnum.RESOURCE == type) {
721 responseEnum = ActionStatus.RESOURCE_NOT_FOUND;
722 } else if (ComponentTypeEnum.PRODUCT == type) {
723 responseEnum = ActionStatus.PRODUCT_NOT_FOUND;
725 responseEnum = ActionStatus.SERVICE_NOT_FOUND;
728 case FAILED_TO_LOCK_ELEMENT:
729 responseEnum = ActionStatus.COMPONENT_IN_USE;
731 case ARTIFACT_NOT_FOUND:
732 responseEnum = ActionStatus.ARTIFACT_NOT_FOUND;
734 case DISTR_ENVIRONMENT_NOT_AVAILABLE:
735 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE;
737 case DISTR_ENVIRONMENT_NOT_FOUND:
738 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND;
740 case DISTR_ENVIRONMENT_SENT_IS_INVALID:
741 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID;
744 responseEnum = ActionStatus.INVALID_CONTENT;
747 responseEnum = ActionStatus.INVALID_CONTENT;
750 responseEnum = ActionStatus.CSAR_NOT_FOUND;
752 case PROPERTY_NAME_ALREADY_EXISTS:
753 responseEnum = ActionStatus.PROPERTY_NAME_ALREADY_EXISTS;
755 case MATCH_NOT_FOUND:
756 responseEnum = ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY;
758 case CATEGORY_NOT_FOUND:
759 responseEnum = ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;
761 case INVALID_PROPERTY:
762 responseEnum = ActionStatus.INVALID_PROPERTY;
764 case COMPONENT_IS_ARCHIVED:
765 responseEnum = ActionStatus.COMPONENT_IS_ARCHIVED;
767 case COMPONENT_NOT_ARCHIVED:
768 responseEnum = ActionStatus.COMPONENT_NOT_ARCHIVED;
770 case COMPONENT_IS_IN_USE:
771 responseEnum = ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT;
773 case DECLARED_INPUT_USED_BY_OPERATION:
774 responseEnum = ActionStatus.DECLARED_INPUT_USED_BY_OPERATION;
777 responseEnum = ActionStatus.GENERAL_ERROR;
780 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
784 public ActionStatus convertFromToscaError(ToscaError toscaError) {
785 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
786 if (toscaError == null) {
789 switch (toscaError) {// TODO match errors
790 case NODE_TYPE_CAPABILITY_ERROR:
791 case NOT_SUPPORTED_TOSCA_TYPE:
792 case NODE_TYPE_REQUIREMENT_ERROR:
793 responseEnum = ActionStatus.INVALID_CONTENT;
796 responseEnum = ActionStatus.GENERAL_ERROR;
802 public ActionStatus convertFromStorageResponseForCapabilityType(StorageOperationStatus storageResponse) {
803 ActionStatus responseEnum;
804 switch (storageResponse) {
806 responseEnum = ActionStatus.OK;
808 case CONNECTION_FAILURE:
810 responseEnum = ActionStatus.GENERAL_ERROR;
813 responseEnum = ActionStatus.INVALID_CONTENT;
815 case ENTITY_ALREADY_EXISTS:
816 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
818 case SCHEMA_VIOLATION:
819 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
822 responseEnum = ActionStatus.GENERAL_ERROR;
825 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
829 public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
830 ActionStatus responseEnum;
831 switch (storageResponse) {
833 responseEnum = ActionStatus.OK;
835 case CONNECTION_FAILURE:
837 responseEnum = ActionStatus.GENERAL_ERROR;
840 responseEnum = ActionStatus.INVALID_CONTENT;
842 case ENTITY_ALREADY_EXISTS:
843 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
845 case SCHEMA_VIOLATION:
846 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
849 responseEnum = ActionStatus.GENERAL_ERROR;
852 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
856 public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
857 ActionStatus responseEnum;
858 switch (storageResponse) {
860 responseEnum = ActionStatus.OK;
863 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
865 case INVALID_PROPERTY:
866 responseEnum = ActionStatus.INVALID_PROPERTY;
869 responseEnum = ActionStatus.GENERAL_ERROR;
872 responseEnum = ActionStatus.INVALID_CONTENT;
874 case MATCH_NOT_FOUND:
875 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
877 case SCHEMA_VIOLATION:
878 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
882 responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
884 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
888 responseEnum = ActionStatus.GENERAL_ERROR;
891 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
895 public ResponseFormat getResponseFormatForResourceInstance(ActionStatus actionStatus, String serviceName, String resourceInstanceName) {
896 ResponseFormat responseFormat;
897 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
898 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
900 responseFormat = getResponseFormat(actionStatus, serviceName);
902 return responseFormat;
905 public ResponseFormat getResponseFormatForResourceInstanceProperty(ActionStatus actionStatus, String resourceInstanceName) {
906 ResponseFormat responseFormat;
907 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
908 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
910 responseFormat = getResponseFormat(actionStatus);
912 return responseFormat;
915 public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
916 ActionStatus responseEnum;
917 switch (storageResponse) {
919 responseEnum = ActionStatus.OK;
922 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
925 responseEnum = ActionStatus.GENERAL_ERROR;
928 responseEnum = ActionStatus.INVALID_CONTENT;
930 case MATCH_NOT_FOUND:
931 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
933 case SCHEMA_VIOLATION:
934 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
937 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
940 responseEnum = ActionStatus.GENERAL_ERROR;
943 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
947 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
948 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, String comment) {
949 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, comment, null, null);
952 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
953 ComponentTypeEnum typeEnum) {
954 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
955 ResourceVersionInfo.newBuilder().build());
958 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
959 ComponentTypeEnum typeEnum, String comment) {
960 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
961 ResourceVersionInfo.newBuilder().build(), null, comment, null, null);
964 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
965 ComponentTypeEnum typeEnum, ResourceVersionInfo prevComponent) {
966 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), prevComponent);
969 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
970 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent) {
971 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, null, null, null);
974 public void auditComponent(ResponseFormat responseFormat, User modifier, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo,
976 auditComponent(responseFormat, modifier, null, actionEnum, resourceCommonInfo, ResourceVersionInfo.newBuilder().build(), null, comment, null,
980 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
981 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent) {
982 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, currComponent, null, null, null);
985 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
986 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent,
987 String comment, ArtifactDefinition artifactDefinition, String did) {
988 if (actionEnum != null) {
990 String currState = null;
991 String invariantUUID = null;
992 String currArtifactUid = null;
993 String currVersion = null;
994 String dcurrStatus = null;
995 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
996 String message = getMessageString(responseFormat);
997 int status = responseFormat.getStatus();
998 String artifactData = buildAuditingArtifactData(artifactDefinition);
999 if (component != null) {
1000 // fields that are filled during creation and might still be empty
1001 if (component.getLifecycleState() != null) {
1002 currState = component.getLifecycleState().name();
1004 uuid = component.getUUID();
1005 invariantUUID = component.getInvariantUUID();
1006 currVersion = component.getVersion();
1007 if (StringUtils.isEmpty(resourceCommonInfo.getResourceName())) {
1008 resourceCommonInfo.setResourceName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1011 if (currComponent != null) {
1012 currArtifactUid = currComponent.getArtifactUuid();
1013 dcurrStatus = currComponent.getDistributionStatus();
1014 if (currState == null) { //probably it was not set
1015 currState = currComponent.getState();
1017 if (currVersion == null) { //probably it was not set
1018 currVersion = currComponent.getVersion();
1021 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(actionEnum,
1022 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(uuid)
1023 .build(), resourceCommonInfo, prevComponent,
1024 ResourceVersionInfo.newBuilder().artifactUuid(currArtifactUid).state(currState).version(currVersion).distributionStatus(dcurrStatus)
1025 .build(), invariantUUID, modifier, artifactData, comment, did, null);
1026 getAuditingManager().auditEvent(factory);
1030 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData,
1032 auditDistributionEngine(action, environmentName, distributionTopicData, null, null, status);
1035 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role,
1036 String apiKey, String status) {
1037 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1038 .createDistributionEngineEventFactory(action, environmentName, distributionTopicData, role, apiKey, status);
1039 getAuditingManager().auditEvent(factory);
1042 public void auditEnvironmentEngine(AuditingActionEnum actionEnum, String environmentID, String environmentType, String action,
1043 String environmentName, String tenantContext) {
1044 AuditEventFactory factory = new AuditEcompOpEnvEventFactory(actionEnum, environmentID, environmentName, environmentType, action,
1046 audit.startAuditFetchLog(PARTNER_NAME, DmaapConsumer.class.getName());
1047 audit.logEntry(LogLevel.INFO, Severity.OK, null, MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), environmentID);
1048 getAuditingManager().auditEvent(factory, audit);
1051 public void auditDistributionNotification(String serviceUUID, String resourceName, String resourceType, String currVersion, User modifier,
1052 String environmentName, String currState, String topicName, String distributionId, String description,
1053 String status, String workloadContext, String tenant) {
1054 AuditEventFactory factory = new AuditDistributionNotificationEventFactory(
1055 CommonAuditData.newBuilder().serviceInstanceId(serviceUUID).status(status).description(description)
1056 .requestId(ThreadLocalsHolder.getUuid()).build(), new ResourceCommonInfo(resourceName, resourceType),
1057 ResourceVersionInfo.newBuilder().state(currState).version(currVersion).build(), distributionId, modifier, topicName,
1058 new OperationalEnvAuditData(environmentName, workloadContext, tenant));
1059 getAuditingManager().auditEvent(factory);
1062 public void auditAuthEvent(String url, String user, String authStatus, String realm) {
1063 AuditEventFactory factory = new AuditAuthRequestEventFactory(CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).build(),
1064 user, url, realm, authStatus);
1065 getAuditingManager().auditEvent(factory);
1068 public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName, String resourceUrl, String statusTime,
1069 String status, String errorReason, LoggerSdcAudit audit) {
1070 AuditEventFactory factory = new AuditDistributionStatusEventFactory(
1071 CommonAuditData.newBuilder().description(errorReason).status(status).requestId(distributionId).build(),
1072 new DistributionData(consumerId, resourceUrl), distributionId, topicName, statusTime);
1073 getAuditingManager().auditEvent(factory, audit);
1076 public void auditGetUebCluster(String consumerId, String status, String description) {
1077 AuditEventFactory factory = new AuditGetUebClusterEventFactory(
1078 CommonAuditData.newBuilder().description(description).status(status).requestId(ThreadLocalsHolder.getUuid()).build(), consumerId);
1079 getAuditingManager().auditEvent(factory);
1082 public void auditMissingInstanceIdAsDistributionEngineEvent(AuditingActionEnum actionEnum, String status) {
1083 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1084 .createDistributionEngineEventFactory(actionEnum, "", DistributionTopicData.newBuilder().build(), null, null, status);
1085 getAuditingManager().auditEvent(factory);
1088 public void auditRegisterOrUnRegisterEvent(AuditingActionEnum action, String consumerId, String apiPublicKey, String envName, String status,
1089 String distributionStatus, String notifTopicName, String statusTopicName) {
1090 String appliedStatus = !StringUtils.isEmpty(status) ? status : distributionStatus;
1091 AuditEventFactory factory = new AuditRegUnregDistributionEngineEventFactory(action,
1092 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).status(appliedStatus).build(),
1093 DistributionTopicData.newBuilder().statusTopic(statusTopicName).notificationTopic(notifTopicName).build(), consumerId, apiPublicKey,
1095 getAuditingManager().auditEvent(factory);
1098 public void auditServiceDistributionDeployed(String serviceName, String serviceVersion, String serviceUUID, String distributionId, String status,
1099 String desc, User modifier) {
1100 AuditEventFactory factory = new AuditDistributionDeployEventFactory(
1101 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(serviceUUID).status(status).description(desc)
1102 .build(), new ResourceCommonInfo(serviceName, "Service"), distributionId, modifier, serviceVersion);
1103 getAuditingManager().auditEvent(factory);
1106 public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat,
1108 AuditEventFactory factory = new AuditConsumerEventFactory(actionEnum,
1109 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1110 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, consumer);
1111 getAuditingManager().auditEvent(factory);
1114 public void auditGetUsersList(User user, String details, ResponseFormat responseFormat) {
1115 AuditEventFactory factory = new AuditGetUsersListEventFactory(
1116 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1117 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1118 getAuditingManager().auditEvent(factory);
1121 public void auditAdminUserActionAndThrowException(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter,
1122 ActionStatus status, String... params) {
1123 ResponseFormat responseFormat = getResponseFormat(status, params);
1124 auditAdminUserAction(actionEnum, modifier, userBefore, userAfter, responseFormat);
1125 throw new ByResponseFormatComponentException(responseFormat);
1128 public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
1129 AuditEventFactory factory = new AuditUserAdminEventFactory(actionEnum,
1130 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1131 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, userBefore, userAfter);
1132 getAuditingManager().auditEvent(factory);
1135 public void auditUserAccess(User user, ActionStatus status, String... params) {
1136 auditUserAccess(user, getResponseFormat(status, params));
1139 public void auditUserAccess(User user, ResponseFormat responseFormat) {
1140 AuditEventFactory factory = new AuditUserAccessEventFactory(
1141 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1142 .requestId(ThreadLocalsHolder.getUuid()).build(), user);
1143 getAuditingManager().auditEvent(factory);
1146 public void auditGetCategoryHierarchy(User user, String details, ResponseFormat responseFormat) {
1147 AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(
1148 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1149 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1150 getAuditingManager().auditEvent(factory);
1153 public ResponseFormat getResponseFormatByComponent(ActionStatus actionStatus, Component component, ComponentTypeEnum type) {
1154 if (component == null) {
1155 return getResponseFormat(actionStatus);
1157 ResponseFormat responseFormat;
1158 switch (actionStatus) {
1159 case COMPONENT_VERSION_ALREADY_EXIST:
1160 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, type.getValue(), component.getVersion());
1162 case RESOURCE_NOT_FOUND:
1163 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND,
1164 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1166 case COMPONENT_NAME_ALREADY_EXIST:
1167 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(),
1168 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1170 case COMPONENT_IN_USE:
1171 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, type.name().toLowerCase(), component.getUniqueId());
1173 case SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND:
1174 responseFormat = getResponseFormat(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND,
1175 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1178 responseFormat = getResponseFormat(actionStatus);
1181 return responseFormat;
1184 public boolean validateStringNotEmpty(String value) {
1185 return value != null && !value.trim().isEmpty();
1188 public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
1189 ActionStatus responseEnum;
1190 switch (storageResponse) {
1192 responseEnum = ActionStatus.OK;
1194 case ENTITY_ALREADY_EXISTS:
1195 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
1198 responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
1201 responseEnum = ActionStatus.GENERAL_ERROR;
1204 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1205 return responseEnum;
1208 public ActionStatus convertFromResultStatusEnum(ResultStatusEnum resultStatus, JsonPresentationFields elementType) {
1209 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1210 switch (resultStatus) {
1212 responseEnum = ActionStatus.OK;
1214 case ELEMENT_NOT_FOUND:
1215 if (elementType != null && elementType == JsonPresentationFields.PROPERTY) {
1216 responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
1219 case INVALID_PROPERTY_DEFAULT_VALUE:
1220 case INVALID_PROPERTY_TYPE:
1221 case INVALID_PROPERTY_VALUE:
1222 case INVALID_PROPERTY_NAME:
1223 case MISSING_ENTRY_SCHEMA_TYPE:
1224 responseEnum = ActionStatus.INVALID_PROPERTY;
1226 case INVALID_ATTRIBUTE_NAME:
1227 responseEnum = ActionStatus.INVALID_ATTRIBUTE;
1230 responseEnum = ActionStatus.GENERAL_ERROR;
1233 return responseEnum;
1236 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus, AdditionalInfoParameterInfo additionalInfoParameterInfo,
1237 NodeTypeEnum nodeType, AdditionalInformationEnum labelOrValue) {
1238 if (additionalInfoParameterInfo == null) {
1239 additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
1241 if (labelOrValue == null) {
1242 labelOrValue = AdditionalInformationEnum.None;
1244 switch (actionStatus) {
1245 case COMPONENT_NAME_ALREADY_EXIST:
1246 return getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey());
1247 case ADDITIONAL_INFORMATION_EXCEEDS_LIMIT:
1248 return getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(),
1249 ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString());
1250 case ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED:
1251 return getResponseFormat(actionStatus, nodeType.name().toLowerCase());
1252 case ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED:
1253 return getResponseFormat(actionStatus);
1254 case ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS:
1255 return getResponseFormat(actionStatus);
1256 case ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS:
1257 return getResponseFormat(actionStatus);
1258 case ADDITIONAL_INFORMATION_NOT_FOUND:
1259 return getResponseFormat(actionStatus);
1261 return getResponseFormat(actionStatus);
1265 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus) {
1266 return getResponseFormatAdditionalProperty(actionStatus, null, null, null);
1269 public ActionStatus convertFromStorageResponseForConsumer(StorageOperationStatus storageResponse) {
1270 ActionStatus responseEnum;
1271 switch (storageResponse) {
1273 responseEnum = ActionStatus.OK;
1275 case CONNECTION_FAILURE:
1277 responseEnum = ActionStatus.GENERAL_ERROR;
1280 responseEnum = ActionStatus.INVALID_CONTENT;
1282 case ENTITY_ALREADY_EXISTS:
1283 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1285 case SCHEMA_VIOLATION:
1286 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1289 responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
1292 responseEnum = ActionStatus.GENERAL_ERROR;
1295 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1296 return responseEnum;
1299 public ActionStatus convertFromStorageResponseForGroupType(StorageOperationStatus storageResponse) {
1300 ActionStatus responseEnum;
1301 switch (storageResponse) {
1303 responseEnum = ActionStatus.OK;
1305 case CONNECTION_FAILURE:
1307 responseEnum = ActionStatus.GENERAL_ERROR;
1310 responseEnum = ActionStatus.INVALID_CONTENT;
1312 case ENTITY_ALREADY_EXISTS:
1313 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1315 case SCHEMA_VIOLATION:
1316 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1319 responseEnum = ActionStatus.GENERAL_ERROR;
1322 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1323 return responseEnum;
1326 public ActionStatus convertFromStorageResponseForPolicyType(StorageOperationStatus storageResponse) {
1327 ActionStatus responseEnum;
1328 switch (storageResponse) {
1330 responseEnum = ActionStatus.OK;
1332 case CONNECTION_FAILURE:
1334 responseEnum = ActionStatus.GENERAL_ERROR;
1337 responseEnum = ActionStatus.INVALID_CONTENT;
1339 case ENTITY_ALREADY_EXISTS:
1340 responseEnum = ActionStatus.POLICY_TYPE_ALREADY_EXIST;
1342 case SCHEMA_VIOLATION:
1343 responseEnum = ActionStatus.POLICY_TYPE_ALREADY_EXIST;
1346 responseEnum = ActionStatus.GENERAL_ERROR;
1349 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1350 return responseEnum;
1353 public ActionStatus convertFromStorageResponseForDataType(StorageOperationStatus storageResponse) {
1354 ActionStatus responseEnum;
1355 switch (storageResponse) {
1357 responseEnum = ActionStatus.OK;
1359 case CONNECTION_FAILURE:
1361 responseEnum = ActionStatus.GENERAL_ERROR;
1364 responseEnum = ActionStatus.INVALID_CONTENT;
1366 case ENTITY_ALREADY_EXISTS:
1367 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1369 case SCHEMA_VIOLATION:
1370 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1372 case CANNOT_UPDATE_EXISTING_ENTITY:
1373 responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
1376 responseEnum = ActionStatus.GENERAL_ERROR;
1379 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1380 return responseEnum;
1383 public ResponseFormat getResponseFormatByGroupType(ActionStatus actionStatus, GroupTypeDefinition groupType) {
1384 if (groupType == null) {
1385 return getResponseFormat(actionStatus);
1387 ResponseFormat responseFormat;
1388 switch (actionStatus) {
1389 case GROUP_MEMBER_EMPTY:
1390 case GROUP_TYPE_ALREADY_EXIST:
1391 responseFormat = getResponseFormat(actionStatus, groupType.getType());
1394 responseFormat = getResponseFormat(actionStatus);
1397 return responseFormat;
1400 public ResponseFormat getResponseFormatByPolicyType(ActionStatus actionStatus, PolicyTypeDefinition policyType) {
1401 if (policyType == null) {
1402 return getResponseFormat(actionStatus);
1404 ResponseFormat responseFormat;
1405 if (actionStatus == ActionStatus.POLICY_TYPE_ALREADY_EXIST) {
1406 responseFormat = getResponseFormat(actionStatus, policyType.getType());
1408 responseFormat = getResponseFormat(actionStatus);
1410 return responseFormat;
1413 public ResponseFormat getResponseFormatByDataType(ActionStatus actionStatus, DataTypeDefinition dataType, List<String> properties) {
1414 if (dataType == null) {
1415 return getResponseFormat(actionStatus);
1417 ResponseFormat responseFormat;
1418 switch (actionStatus) {
1419 case DATA_TYPE_ALREADY_EXIST:
1420 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1422 case DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM:
1423 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1425 case DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY:
1426 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1428 case DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR:
1429 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1431 case DATA_TYPE_DERIVED_IS_MISSING:
1432 responseFormat = getResponseFormat(actionStatus, dataType.getDerivedFromName());
1434 case DATA_TYPE_DUPLICATE_PROPERTY:
1435 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1437 case DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE:
1438 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1440 case DATA_TYPE_CANNOT_HAVE_PROPERTIES:
1441 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1443 case DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST:
1444 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1447 responseFormat = getResponseFormat(actionStatus);
1450 return responseFormat;
1453 public StorageOperationStatus convertToStorageOperationStatus(CassandraOperationStatus cassandraStatus) {
1454 StorageOperationStatus result;
1455 switch (cassandraStatus) {
1457 result = StorageOperationStatus.OK;
1460 result = StorageOperationStatus.NOT_FOUND;
1462 case CLUSTER_NOT_CONNECTED:
1463 case KEYSPACE_NOT_CONNECTED:
1464 result = StorageOperationStatus.CONNECTION_FAILURE;
1467 result = StorageOperationStatus.GENERAL_ERROR;
1473 public ResponseFormat getResponseFormat(ComponentException exception) {
1474 return exception instanceof ByResponseFormatComponentException ? getResponseFormat((ByResponseFormatComponentException) exception)
1475 : getResponseFormat((ByActionStatusComponentException) exception);
1478 public ResponseFormat getResponseFormat(ByResponseFormatComponentException exception) {
1479 return exception.getResponseFormat();
1482 public ResponseFormat getResponseFormat(ByActionStatusComponentException exception) {
1483 return getResponseFormat(exception.getActionStatus(), exception.getParams());
1486 public ActionStatus convertFromStorageResponseForRelationshipType(StorageOperationStatus storageResponse) {
1487 ActionStatus responseEnum;
1488 switch (storageResponse) {
1490 responseEnum = ActionStatus.OK;
1492 case CONNECTION_FAILURE:
1494 responseEnum = ActionStatus.GENERAL_ERROR;
1497 responseEnum = ActionStatus.INVALID_CONTENT;
1499 case ENTITY_ALREADY_EXISTS:
1500 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1502 case SCHEMA_VIOLATION:
1503 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1506 responseEnum = ActionStatus.GENERAL_ERROR;
1509 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1510 return responseEnum;
1513 public ResponseFormat getResponseFormat(StorageException exception) {
1514 ActionStatus status = convertFromStorageResponse(exception.getStorageOperationStatus());
1515 return getResponseFormat(status, exception.getParams());
1518 public List<UiLeftPaletteComponent> convertComponentToUiLeftPaletteComponentObject(List<Component> components) {
1519 List<UiLeftPaletteComponent> uiLeftPaletteComponents = new ArrayList<>();
1520 components.forEach(c -> uiLeftPaletteComponents.add(new UiLeftPaletteComponent(c)));
1521 return uiLeftPaletteComponents;
1524 public F<StorageOperationStatus, ResponseFormat> toResponseFormat() {
1525 return sos -> getResponseFormat(convertFromStorageResponse(sos));
1528 public Optional<UIConstraint> parseToConstraint(final String componentJson, final User user, final ComponentTypeEnum componentTypeEnum) {
1529 final Either<UIConstraint, ResponseFormat> uiConstraintResponseFormatEither = convertJsonToObjectUsingObjectMapper(componentJson, user,
1530 UIConstraint.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
1531 if (uiConstraintResponseFormatEither.isRight()) {
1532 return Optional.empty();
1534 return Optional.of(uiConstraintResponseFormatEither.left().value());
1537 private Either<List, ResponseFormat> parseToConstraints(final String componentJson, final User user, final ComponentTypeEnum componentTypeEnum) {
1538 return convertJsonToObjectUsingObjectMapper(componentJson, user, List.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
1541 public List<UIConstraint> validateAndParseConstraint(final ComponentTypeEnum componentTypeEnum, final String constraintData,
1542 final User userModifier) {
1543 final String FAILED_TO_PARSE_CONSTRAINT_DATA = "Failed to Parse Constraint Data {}";
1544 final Either<List, ResponseFormat> convertResponse = parseToConstraints(constraintData, userModifier, componentTypeEnum);
1545 if (convertResponse.isRight()) {
1546 log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData, convertResponse.right().value());
1547 return Collections.emptyList();
1549 final List<Map<String, String>> uiConstraintsMaps = (List<Map<String, String>>) convertResponse.left().value();
1550 if (uiConstraintsMaps == null) {
1551 log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData);
1552 return Collections.emptyList();
1554 return uiConstraintsMaps.stream().map(dataMap -> new com.fasterxml.jackson.databind.ObjectMapper().convertValue(dataMap, UIConstraint.class))
1555 .collect(Collectors.toList());
1558 public Map<String, DataTypeDefinition> getAllDataTypes(final ApplicationDataTypeCache applicationDataTypeCache, final String model) {
1559 final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll(model);
1560 if (allDataTypes.isRight()) {
1561 final var operationStatus = allDataTypes.right().value();
1562 if (operationStatus == JanusGraphOperationStatus.NOT_FOUND) {
1563 BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", ErrorSeverity.ERROR);
1564 throw new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model);
1566 BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", ErrorSeverity.ERROR);
1567 throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
1570 return allDataTypes.left().value();
1573 public ActionStatus convertFromStorageResponseForArtifactType(final StorageOperationStatus storageResponse) {
1574 ActionStatus responseEnum;
1575 switch (storageResponse) {
1577 responseEnum = ActionStatus.OK;
1579 case CONNECTION_FAILURE:
1581 responseEnum = ActionStatus.GENERAL_ERROR;
1584 responseEnum = ActionStatus.INVALID_CONTENT;
1586 case ENTITY_ALREADY_EXISTS:
1587 responseEnum = ActionStatus.ARTIFACT_TYPE_ALREADY_EXIST;
1589 case SCHEMA_VIOLATION:
1590 responseEnum = ActionStatus.ARTIFACT_TYPE_ALREADY_EXIST;
1593 responseEnum = ActionStatus.GENERAL_ERROR;
1596 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1597 return responseEnum;