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 DECLARED_INPUT_USED_BY_OPERATION:
768 responseEnum = ActionStatus.DECLARED_INPUT_USED_BY_OPERATION;
771 responseEnum = ActionStatus.GENERAL_ERROR;
774 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
778 public ActionStatus convertFromToscaError(ToscaError toscaError) {
779 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
780 if (toscaError == null) {
783 switch (toscaError) {// TODO match errors
784 case NODE_TYPE_CAPABILITY_ERROR:
785 case NOT_SUPPORTED_TOSCA_TYPE:
786 case NODE_TYPE_REQUIREMENT_ERROR:
787 responseEnum = ActionStatus.INVALID_CONTENT;
790 responseEnum = ActionStatus.GENERAL_ERROR;
796 public ActionStatus convertFromStorageResponseForCapabilityType(StorageOperationStatus storageResponse) {
797 ActionStatus responseEnum;
798 switch (storageResponse) {
800 responseEnum = ActionStatus.OK;
802 case CONNECTION_FAILURE:
804 responseEnum = ActionStatus.GENERAL_ERROR;
807 responseEnum = ActionStatus.INVALID_CONTENT;
809 case ENTITY_ALREADY_EXISTS:
810 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
812 case SCHEMA_VIOLATION:
813 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
816 responseEnum = ActionStatus.GENERAL_ERROR;
819 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
823 public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
824 ActionStatus responseEnum;
825 switch (storageResponse) {
827 responseEnum = ActionStatus.OK;
829 case CONNECTION_FAILURE:
831 responseEnum = ActionStatus.GENERAL_ERROR;
834 responseEnum = ActionStatus.INVALID_CONTENT;
836 case ENTITY_ALREADY_EXISTS:
837 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
839 case SCHEMA_VIOLATION:
840 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
843 responseEnum = ActionStatus.GENERAL_ERROR;
846 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
850 public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
851 ActionStatus responseEnum;
852 switch (storageResponse) {
854 responseEnum = ActionStatus.OK;
857 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
859 case INVALID_PROPERTY:
860 responseEnum = ActionStatus.INVALID_PROPERTY;
863 responseEnum = ActionStatus.GENERAL_ERROR;
866 responseEnum = ActionStatus.INVALID_CONTENT;
868 case MATCH_NOT_FOUND:
869 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
871 case SCHEMA_VIOLATION:
872 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
876 responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
878 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
882 responseEnum = ActionStatus.GENERAL_ERROR;
885 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
889 public ResponseFormat getResponseFormatForResourceInstance(ActionStatus actionStatus, String serviceName, String resourceInstanceName) {
890 ResponseFormat responseFormat;
891 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
892 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
894 responseFormat = getResponseFormat(actionStatus, serviceName);
896 return responseFormat;
899 public ResponseFormat getResponseFormatForResourceInstanceProperty(ActionStatus actionStatus, String resourceInstanceName) {
900 ResponseFormat responseFormat;
901 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
902 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
904 responseFormat = getResponseFormat(actionStatus);
906 return responseFormat;
909 public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
910 ActionStatus responseEnum;
911 switch (storageResponse) {
913 responseEnum = ActionStatus.OK;
916 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
919 responseEnum = ActionStatus.GENERAL_ERROR;
922 responseEnum = ActionStatus.INVALID_CONTENT;
924 case MATCH_NOT_FOUND:
925 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
927 case SCHEMA_VIOLATION:
928 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
931 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
934 responseEnum = ActionStatus.GENERAL_ERROR;
937 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
941 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
942 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, String comment) {
943 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, comment, null, null);
946 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
947 ComponentTypeEnum typeEnum) {
948 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
949 ResourceVersionInfo.newBuilder().build());
952 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
953 ComponentTypeEnum typeEnum, String comment) {
954 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
955 ResourceVersionInfo.newBuilder().build(), null, comment, null, null);
958 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
959 ComponentTypeEnum typeEnum, ResourceVersionInfo prevComponent) {
960 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), prevComponent);
963 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
964 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent) {
965 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, null, null, null);
968 public void auditComponent(ResponseFormat responseFormat, User modifier, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo,
970 auditComponent(responseFormat, modifier, null, actionEnum, resourceCommonInfo, ResourceVersionInfo.newBuilder().build(), null, comment, null,
974 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
975 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent) {
976 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, currComponent, null, null, null);
979 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
980 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent,
981 String comment, ArtifactDefinition artifactDefinition, String did) {
982 if (actionEnum != null) {
984 String currState = null;
985 String invariantUUID = null;
986 String currArtifactUid = null;
987 String currVersion = null;
988 String dcurrStatus = null;
989 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
990 String message = getMessageString(responseFormat);
991 int status = responseFormat.getStatus();
992 String artifactData = buildAuditingArtifactData(artifactDefinition);
993 if (component != null) {
994 // fields that are filled during creation and might still be empty
995 if (component.getLifecycleState() != null) {
996 currState = component.getLifecycleState().name();
998 uuid = component.getUUID();
999 invariantUUID = component.getInvariantUUID();
1000 currVersion = component.getVersion();
1001 if (StringUtils.isEmpty(resourceCommonInfo.getResourceName())) {
1002 resourceCommonInfo.setResourceName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1005 if (currComponent != null) {
1006 currArtifactUid = currComponent.getArtifactUuid();
1007 dcurrStatus = currComponent.getDistributionStatus();
1008 if (currState == null) { //probably it was not set
1009 currState = currComponent.getState();
1011 if (currVersion == null) { //probably it was not set
1012 currVersion = currComponent.getVersion();
1015 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(actionEnum,
1016 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(uuid)
1017 .build(), resourceCommonInfo, prevComponent,
1018 ResourceVersionInfo.newBuilder().artifactUuid(currArtifactUid).state(currState).version(currVersion).distributionStatus(dcurrStatus)
1019 .build(), invariantUUID, modifier, artifactData, comment, did, null);
1020 getAuditingManager().auditEvent(factory);
1024 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData,
1026 auditDistributionEngine(action, environmentName, distributionTopicData, null, null, status);
1029 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role,
1030 String apiKey, String status) {
1031 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1032 .createDistributionEngineEventFactory(action, environmentName, distributionTopicData, role, apiKey, status);
1033 getAuditingManager().auditEvent(factory);
1036 public void auditEnvironmentEngine(AuditingActionEnum actionEnum, String environmentID, String environmentType, String action,
1037 String environmentName, String tenantContext) {
1038 AuditEventFactory factory = new AuditEcompOpEnvEventFactory(actionEnum, environmentID, environmentName, environmentType, action,
1040 audit.startAuditFetchLog(PARTNER_NAME, DmaapConsumer.class.getName());
1041 audit.logEntry(LogLevel.INFO, Severity.OK, null, MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), environmentID);
1042 getAuditingManager().auditEvent(factory, audit);
1045 public void auditDistributionNotification(String serviceUUID, String resourceName, String resourceType, String currVersion, User modifier,
1046 String environmentName, String currState, String topicName, String distributionId, String description,
1047 String status, String workloadContext, String tenant) {
1048 AuditEventFactory factory = new AuditDistributionNotificationEventFactory(
1049 CommonAuditData.newBuilder().serviceInstanceId(serviceUUID).status(status).description(description)
1050 .requestId(ThreadLocalsHolder.getUuid()).build(), new ResourceCommonInfo(resourceName, resourceType),
1051 ResourceVersionInfo.newBuilder().state(currState).version(currVersion).build(), distributionId, modifier, topicName,
1052 new OperationalEnvAuditData(environmentName, workloadContext, tenant));
1053 getAuditingManager().auditEvent(factory);
1056 public void auditAuthEvent(String url, String user, String authStatus, String realm) {
1057 AuditEventFactory factory = new AuditAuthRequestEventFactory(CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).build(),
1058 user, url, realm, authStatus);
1059 getAuditingManager().auditEvent(factory);
1062 public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName, String resourceUrl, String statusTime,
1063 String status, String errorReason, LoggerSdcAudit audit) {
1064 AuditEventFactory factory = new AuditDistributionStatusEventFactory(
1065 CommonAuditData.newBuilder().description(errorReason).status(status).requestId(distributionId).build(),
1066 new DistributionData(consumerId, resourceUrl), distributionId, topicName, statusTime);
1067 getAuditingManager().auditEvent(factory, audit);
1070 public void auditGetUebCluster(String consumerId, String status, String description) {
1071 AuditEventFactory factory = new AuditGetUebClusterEventFactory(
1072 CommonAuditData.newBuilder().description(description).status(status).requestId(ThreadLocalsHolder.getUuid()).build(), consumerId);
1073 getAuditingManager().auditEvent(factory);
1076 public void auditMissingInstanceIdAsDistributionEngineEvent(AuditingActionEnum actionEnum, String status) {
1077 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1078 .createDistributionEngineEventFactory(actionEnum, "", DistributionTopicData.newBuilder().build(), null, null, status);
1079 getAuditingManager().auditEvent(factory);
1082 public void auditRegisterOrUnRegisterEvent(AuditingActionEnum action, String consumerId, String apiPublicKey, String envName, String status,
1083 String distributionStatus, String notifTopicName, String statusTopicName) {
1084 String appliedStatus = !StringUtils.isEmpty(status) ? status : distributionStatus;
1085 AuditEventFactory factory = new AuditRegUnregDistributionEngineEventFactory(action,
1086 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).status(appliedStatus).build(),
1087 DistributionTopicData.newBuilder().statusTopic(statusTopicName).notificationTopic(notifTopicName).build(), consumerId, apiPublicKey,
1089 getAuditingManager().auditEvent(factory);
1092 public void auditServiceDistributionDeployed(String serviceName, String serviceVersion, String serviceUUID, String distributionId, String status,
1093 String desc, User modifier) {
1094 AuditEventFactory factory = new AuditDistributionDeployEventFactory(
1095 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(serviceUUID).status(status).description(desc)
1096 .build(), new ResourceCommonInfo(serviceName, "Service"), distributionId, modifier, serviceVersion);
1097 getAuditingManager().auditEvent(factory);
1100 public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat,
1102 AuditEventFactory factory = new AuditConsumerEventFactory(actionEnum,
1103 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1104 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, consumer);
1105 getAuditingManager().auditEvent(factory);
1108 public void auditGetUsersList(User user, String details, ResponseFormat responseFormat) {
1109 AuditEventFactory factory = new AuditGetUsersListEventFactory(
1110 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1111 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1112 getAuditingManager().auditEvent(factory);
1115 public void auditAdminUserActionAndThrowException(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter,
1116 ActionStatus status, String... params) {
1117 ResponseFormat responseFormat = getResponseFormat(status, params);
1118 auditAdminUserAction(actionEnum, modifier, userBefore, userAfter, responseFormat);
1119 throw new ByResponseFormatComponentException(responseFormat);
1122 public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
1123 AuditEventFactory factory = new AuditUserAdminEventFactory(actionEnum,
1124 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1125 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, userBefore, userAfter);
1126 getAuditingManager().auditEvent(factory);
1129 public void auditUserAccess(User user, ActionStatus status, String... params) {
1130 auditUserAccess(user, getResponseFormat(status, params));
1133 public void auditUserAccess(User user, ResponseFormat responseFormat) {
1134 AuditEventFactory factory = new AuditUserAccessEventFactory(
1135 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1136 .requestId(ThreadLocalsHolder.getUuid()).build(), user);
1137 getAuditingManager().auditEvent(factory);
1140 public void auditGetCategoryHierarchy(User user, String details, ResponseFormat responseFormat) {
1141 AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(
1142 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1143 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1144 getAuditingManager().auditEvent(factory);
1147 public ResponseFormat getResponseFormatByComponent(ActionStatus actionStatus, Component component, ComponentTypeEnum type) {
1148 if (component == null) {
1149 return getResponseFormat(actionStatus);
1151 ResponseFormat responseFormat;
1152 switch (actionStatus) {
1153 case COMPONENT_VERSION_ALREADY_EXIST:
1154 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, type.getValue(), component.getVersion());
1156 case RESOURCE_NOT_FOUND:
1157 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND,
1158 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1160 case COMPONENT_NAME_ALREADY_EXIST:
1161 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(),
1162 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1164 case COMPONENT_IN_USE:
1165 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, type.name().toLowerCase(), component.getUniqueId());
1167 case SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND:
1168 responseFormat = getResponseFormat(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND,
1169 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1172 responseFormat = getResponseFormat(actionStatus);
1175 return responseFormat;
1178 public boolean validateStringNotEmpty(String value) {
1179 return value != null && !value.trim().isEmpty();
1182 public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
1183 ActionStatus responseEnum;
1184 switch (storageResponse) {
1186 responseEnum = ActionStatus.OK;
1188 case ENTITY_ALREADY_EXISTS:
1189 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
1192 responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
1195 responseEnum = ActionStatus.GENERAL_ERROR;
1198 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1199 return responseEnum;
1202 public ActionStatus convertFromResultStatusEnum(ResultStatusEnum resultStatus, JsonPresentationFields elementType) {
1203 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1204 switch (resultStatus) {
1206 responseEnum = ActionStatus.OK;
1208 case ELEMENT_NOT_FOUND:
1209 if (elementType != null && elementType == JsonPresentationFields.PROPERTY) {
1210 responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
1213 case INVALID_PROPERTY_DEFAULT_VALUE:
1214 case INVALID_PROPERTY_TYPE:
1215 case INVALID_PROPERTY_VALUE:
1216 case INVALID_PROPERTY_NAME:
1217 case MISSING_ENTRY_SCHEMA_TYPE:
1218 responseEnum = ActionStatus.INVALID_PROPERTY;
1220 case INVALID_ATTRIBUTE_NAME:
1221 responseEnum = ActionStatus.INVALID_ATTRIBUTE;
1224 responseEnum = ActionStatus.GENERAL_ERROR;
1227 return responseEnum;
1230 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus, AdditionalInfoParameterInfo additionalInfoParameterInfo,
1231 NodeTypeEnum nodeType, AdditionalInformationEnum labelOrValue) {
1232 if (additionalInfoParameterInfo == null) {
1233 additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
1235 if (labelOrValue == null) {
1236 labelOrValue = AdditionalInformationEnum.None;
1238 switch (actionStatus) {
1239 case COMPONENT_NAME_ALREADY_EXIST:
1240 return getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey());
1241 case ADDITIONAL_INFORMATION_EXCEEDS_LIMIT:
1242 return getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(),
1243 ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString());
1244 case ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED:
1245 return getResponseFormat(actionStatus, nodeType.name().toLowerCase());
1246 case ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED:
1247 return getResponseFormat(actionStatus);
1248 case ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS:
1249 return getResponseFormat(actionStatus);
1250 case ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS:
1251 return getResponseFormat(actionStatus);
1252 case ADDITIONAL_INFORMATION_NOT_FOUND:
1253 return getResponseFormat(actionStatus);
1255 return getResponseFormat(actionStatus);
1259 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus) {
1260 return getResponseFormatAdditionalProperty(actionStatus, null, null, null);
1263 public ActionStatus convertFromStorageResponseForConsumer(StorageOperationStatus storageResponse) {
1264 ActionStatus responseEnum;
1265 switch (storageResponse) {
1267 responseEnum = ActionStatus.OK;
1269 case CONNECTION_FAILURE:
1271 responseEnum = ActionStatus.GENERAL_ERROR;
1274 responseEnum = ActionStatus.INVALID_CONTENT;
1276 case ENTITY_ALREADY_EXISTS:
1277 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1279 case SCHEMA_VIOLATION:
1280 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1283 responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
1286 responseEnum = ActionStatus.GENERAL_ERROR;
1289 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1290 return responseEnum;
1293 public ActionStatus convertFromStorageResponseForGroupType(StorageOperationStatus storageResponse) {
1294 ActionStatus responseEnum;
1295 switch (storageResponse) {
1297 responseEnum = ActionStatus.OK;
1299 case CONNECTION_FAILURE:
1301 responseEnum = ActionStatus.GENERAL_ERROR;
1304 responseEnum = ActionStatus.INVALID_CONTENT;
1306 case ENTITY_ALREADY_EXISTS:
1307 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1309 case SCHEMA_VIOLATION:
1310 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1313 responseEnum = ActionStatus.GENERAL_ERROR;
1316 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1317 return responseEnum;
1320 public ActionStatus convertFromStorageResponseForPolicyType(StorageOperationStatus storageResponse) {
1321 ActionStatus responseEnum;
1322 switch (storageResponse) {
1324 responseEnum = ActionStatus.OK;
1326 case CONNECTION_FAILURE:
1328 responseEnum = ActionStatus.GENERAL_ERROR;
1331 responseEnum = ActionStatus.INVALID_CONTENT;
1333 case ENTITY_ALREADY_EXISTS:
1334 responseEnum = ActionStatus.POLICY_TYPE_ALREADY_EXIST;
1336 case SCHEMA_VIOLATION:
1337 responseEnum = ActionStatus.POLICY_TYPE_ALREADY_EXIST;
1340 responseEnum = ActionStatus.GENERAL_ERROR;
1343 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1344 return responseEnum;
1347 public ActionStatus convertFromStorageResponseForDataType(StorageOperationStatus storageResponse) {
1348 ActionStatus responseEnum;
1349 switch (storageResponse) {
1351 responseEnum = ActionStatus.OK;
1353 case CONNECTION_FAILURE:
1355 responseEnum = ActionStatus.GENERAL_ERROR;
1358 responseEnum = ActionStatus.INVALID_CONTENT;
1360 case ENTITY_ALREADY_EXISTS:
1361 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1363 case SCHEMA_VIOLATION:
1364 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1366 case CANNOT_UPDATE_EXISTING_ENTITY:
1367 responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
1370 responseEnum = ActionStatus.GENERAL_ERROR;
1373 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1374 return responseEnum;
1377 public ResponseFormat getResponseFormatByGroupType(ActionStatus actionStatus, GroupTypeDefinition groupType) {
1378 if (groupType == null) {
1379 return getResponseFormat(actionStatus);
1381 ResponseFormat responseFormat;
1382 switch (actionStatus) {
1383 case GROUP_MEMBER_EMPTY:
1384 case GROUP_TYPE_ALREADY_EXIST:
1385 responseFormat = getResponseFormat(actionStatus, groupType.getType());
1388 responseFormat = getResponseFormat(actionStatus);
1391 return responseFormat;
1394 public ResponseFormat getResponseFormatByPolicyType(ActionStatus actionStatus, PolicyTypeDefinition policyType) {
1395 if (policyType == null) {
1396 return getResponseFormat(actionStatus);
1398 ResponseFormat responseFormat;
1399 if (actionStatus == ActionStatus.POLICY_TYPE_ALREADY_EXIST) {
1400 responseFormat = getResponseFormat(actionStatus, policyType.getType());
1402 responseFormat = getResponseFormat(actionStatus);
1404 return responseFormat;
1407 public ResponseFormat getResponseFormatByDataType(ActionStatus actionStatus, DataTypeDefinition dataType, List<String> properties) {
1408 if (dataType == null) {
1409 return getResponseFormat(actionStatus);
1411 ResponseFormat responseFormat;
1412 switch (actionStatus) {
1413 case DATA_TYPE_ALREADY_EXIST:
1414 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1416 case DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM:
1417 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1419 case DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY:
1420 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1422 case DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR:
1423 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1425 case DATA_TYPE_DERIVED_IS_MISSING:
1426 responseFormat = getResponseFormat(actionStatus, dataType.getDerivedFromName());
1428 case DATA_TYPE_DUPLICATE_PROPERTY:
1429 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1431 case DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE:
1432 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1434 case DATA_TYPE_CANNOT_HAVE_PROPERTIES:
1435 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1437 case DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST:
1438 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1441 responseFormat = getResponseFormat(actionStatus);
1444 return responseFormat;
1447 public StorageOperationStatus convertToStorageOperationStatus(CassandraOperationStatus cassandraStatus) {
1448 StorageOperationStatus result;
1449 switch (cassandraStatus) {
1451 result = StorageOperationStatus.OK;
1454 result = StorageOperationStatus.NOT_FOUND;
1456 case CLUSTER_NOT_CONNECTED:
1457 case KEYSPACE_NOT_CONNECTED:
1458 result = StorageOperationStatus.CONNECTION_FAILURE;
1461 result = StorageOperationStatus.GENERAL_ERROR;
1467 public ResponseFormat getResponseFormat(ComponentException exception) {
1468 return exception instanceof ByResponseFormatComponentException ? getResponseFormat((ByResponseFormatComponentException) exception)
1469 : getResponseFormat((ByActionStatusComponentException) exception);
1472 public ResponseFormat getResponseFormat(ByResponseFormatComponentException exception) {
1473 return exception.getResponseFormat();
1476 public ResponseFormat getResponseFormat(ByActionStatusComponentException exception) {
1477 return getResponseFormat(exception.getActionStatus(), exception.getParams());
1480 public ActionStatus convertFromStorageResponseForRelationshipType(StorageOperationStatus storageResponse) {
1481 ActionStatus responseEnum;
1482 switch (storageResponse) {
1484 responseEnum = ActionStatus.OK;
1486 case CONNECTION_FAILURE:
1488 responseEnum = ActionStatus.GENERAL_ERROR;
1491 responseEnum = ActionStatus.INVALID_CONTENT;
1493 case ENTITY_ALREADY_EXISTS:
1494 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1496 case SCHEMA_VIOLATION:
1497 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1500 responseEnum = ActionStatus.GENERAL_ERROR;
1503 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1504 return responseEnum;
1507 public ResponseFormat getResponseFormat(StorageException exception) {
1508 ActionStatus status = convertFromStorageResponse(exception.getStorageOperationStatus());
1509 return getResponseFormat(status, exception.getParams());
1512 public List<UiLeftPaletteComponent> convertComponentToUiLeftPaletteComponentObject(List<Component> components) {
1513 List<UiLeftPaletteComponent> uiLeftPaletteComponents = new ArrayList<>();
1514 components.forEach(c -> uiLeftPaletteComponents.add(new UiLeftPaletteComponent(c)));
1515 return uiLeftPaletteComponents;
1518 public F<StorageOperationStatus, ResponseFormat> toResponseFormat() {
1519 return sos -> getResponseFormat(convertFromStorageResponse(sos));
1522 public Optional<UIConstraint> parseToConstraint(final String componentJson, final User user, final ComponentTypeEnum componentTypeEnum) {
1523 final Either<UIConstraint, ResponseFormat> uiConstraintResponseFormatEither = convertJsonToObjectUsingObjectMapper(componentJson, user,
1524 UIConstraint.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
1525 if (uiConstraintResponseFormatEither.isRight()) {
1526 return Optional.empty();
1528 return Optional.of(uiConstraintResponseFormatEither.left().value());
1531 private Either<List, ResponseFormat> parseToConstraints(final String componentJson, final User user, final ComponentTypeEnum componentTypeEnum) {
1532 return convertJsonToObjectUsingObjectMapper(componentJson, user, List.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
1535 public List<UIConstraint> validateAndParseConstraint(final ComponentTypeEnum componentTypeEnum, final String constraintData,
1536 final User userModifier) {
1537 final String FAILED_TO_PARSE_CONSTRAINT_DATA = "Failed to Parse Constraint Data {}";
1538 final Either<List, ResponseFormat> convertResponse = parseToConstraints(constraintData, userModifier, componentTypeEnum);
1539 if (convertResponse.isRight()) {
1540 log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData, convertResponse.right().value());
1541 return Collections.emptyList();
1543 final List<Map<String, String>> uiConstraintsMaps = (List<Map<String, String>>) convertResponse.left().value();
1544 if (uiConstraintsMaps == null) {
1545 log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData);
1546 return Collections.emptyList();
1548 return uiConstraintsMaps.stream().map(dataMap -> new com.fasterxml.jackson.databind.ObjectMapper().convertValue(dataMap, UIConstraint.class))
1549 .collect(Collectors.toList());
1552 public Map<String, DataTypeDefinition> getAllDataTypes(final ApplicationDataTypeCache applicationDataTypeCache, final String model) {
1553 final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll(model);
1554 if (allDataTypes.isRight()) {
1555 final var operationStatus = allDataTypes.right().value();
1556 if (operationStatus == JanusGraphOperationStatus.NOT_FOUND) {
1557 BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", ErrorSeverity.ERROR);
1558 throw new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model);
1560 BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", ErrorSeverity.ERROR);
1561 throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
1564 return allDataTypes.left().value();
1567 public ActionStatus convertFromStorageResponseForArtifactType(final StorageOperationStatus storageResponse) {
1568 ActionStatus responseEnum;
1569 switch (storageResponse) {
1571 responseEnum = ActionStatus.OK;
1573 case CONNECTION_FAILURE:
1575 responseEnum = ActionStatus.GENERAL_ERROR;
1578 responseEnum = ActionStatus.INVALID_CONTENT;
1580 case ENTITY_ALREADY_EXISTS:
1581 responseEnum = ActionStatus.ARTIFACT_TYPE_ALREADY_EXIST;
1583 case SCHEMA_VIOLATION:
1584 responseEnum = ActionStatus.ARTIFACT_TYPE_ALREADY_EXIST;
1587 responseEnum = ActionStatus.GENERAL_ERROR;
1590 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1591 return responseEnum;