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.annotation.JsonInclude.Include;
25 import com.fasterxml.jackson.databind.DeserializationFeature;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.fasterxml.jackson.databind.module.SimpleModule;
28 import com.google.gson.Gson;
29 import com.google.gson.GsonBuilder;
30 import com.google.gson.reflect.TypeToken;
32 import fj.data.Either;
33 import java.lang.reflect.Type;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.List;
38 import java.util.Optional;
40 import java.util.stream.Collectors;
41 import javax.servlet.http.HttpServletRequest;
42 import org.apache.commons.collections.CollectionUtils;
43 import org.apache.commons.lang3.StringUtils;
44 import org.onap.logging.ref.slf4j.ONAPLogConstants;
45 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
46 import org.openecomp.sdc.be.auditing.impl.AuditAuthRequestEventFactory;
47 import org.openecomp.sdc.be.auditing.impl.AuditConsumerEventFactory;
48 import org.openecomp.sdc.be.auditing.impl.AuditEcompOpEnvEventFactory;
49 import org.openecomp.sdc.be.auditing.impl.AuditGetUebClusterEventFactory;
50 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
51 import org.openecomp.sdc.be.auditing.impl.category.AuditCategoryEventFactory;
52 import org.openecomp.sdc.be.auditing.impl.category.AuditGetCategoryHierarchyEventFactory;
53 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDeployEventFactory;
54 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDownloadEventFactory;
55 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionEngineEventFactoryManager;
56 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionNotificationEventFactory;
57 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionStatusEventFactory;
58 import org.openecomp.sdc.be.auditing.impl.distribution.AuditRegUnregDistributionEngineEventFactory;
59 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditActivateServiceExternalApiEventFactory;
60 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetExternalApiEventFactory;
61 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetListExternalApiEventFactory;
62 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditChangeLifecycleExternalApiEventFactory;
63 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateResourceExternalApiEventFactory;
64 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateServiceExternalApiEventFactory;
65 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCrudExternalApiArtifactEventFactory;
66 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditDownloadArtifactExternalApiEventFactory;
67 import org.openecomp.sdc.be.auditing.impl.resourceadmin.AuditResourceEventFactoryManager;
68 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditGetUsersListEventFactory;
69 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAccessEventFactory;
70 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAdminEventFactory;
71 import org.openecomp.sdc.be.components.distribution.engine.DmaapConsumer;
72 import org.openecomp.sdc.be.components.impl.ImportUtils;
73 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
74 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
75 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
76 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
77 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
78 import org.openecomp.sdc.be.config.BeEcompErrorManager;
79 import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
80 import org.openecomp.sdc.be.dao.api.ActionStatus;
81 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
82 import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
83 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
84 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
85 import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
86 import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionJsonDeserializer;
87 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
88 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
89 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
90 import org.openecomp.sdc.be.model.ArtifactDefinition;
91 import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
92 import org.openecomp.sdc.be.model.Component;
93 import org.openecomp.sdc.be.model.ComponentInstance;
94 import org.openecomp.sdc.be.model.ConsumerDefinition;
95 import org.openecomp.sdc.be.model.DataTypeDefinition;
96 import org.openecomp.sdc.be.model.GroupTypeDefinition;
97 import org.openecomp.sdc.be.model.LifecycleStateEnum;
98 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
99 import org.openecomp.sdc.be.model.PropertyConstraint;
100 import org.openecomp.sdc.be.model.RequirementDefinition;
101 import org.openecomp.sdc.be.model.Resource;
102 import org.openecomp.sdc.be.model.User;
103 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
104 import org.openecomp.sdc.be.model.operations.StorageException;
105 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
106 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
107 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserializer;
108 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
109 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
110 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
111 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
112 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
113 import org.openecomp.sdc.be.resources.data.auditing.model.OperationalEnvAuditData;
114 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
115 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
116 import org.openecomp.sdc.be.tosca.ToscaError;
117 import org.openecomp.sdc.be.ui.model.UIConstraint;
118 import org.openecomp.sdc.be.ui.model.UiLeftPaletteComponent;
119 import org.openecomp.sdc.common.api.Constants;
120 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
121 import org.openecomp.sdc.common.log.enums.LogLevel;
122 import org.openecomp.sdc.common.log.enums.Severity;
123 import org.openecomp.sdc.common.log.wrappers.Logger;
124 import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
125 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
126 import org.openecomp.sdc.common.util.ValidationUtils;
127 import org.openecomp.sdc.exception.ResponseFormat;
128 import org.slf4j.MarkerFactory;
129 import org.springframework.beans.factory.annotation.Autowired;
131 @org.springframework.stereotype.Component("componentUtils")
132 public class ComponentsUtils {
134 private static final String CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE = "convert storage response {} to action response {}";
135 private static final String INSIDE_AUDITING_FOR_AUDIT_ACTION = "Inside auditing for audit action {}";
136 private static final String AUDIT_BEFORE_SENDING_RESPONSE = "audit before sending response";
137 private static final String CONVERT_JSON_TO_OBJECT = "convertJsonToObject";
138 private static final Logger log = Logger.getLogger(ComponentsUtils.class);
139 private static final String PARTNER_NAME = "UNKNOWN";
140 private static final LoggerSdcAudit audit = new LoggerSdcAudit(DmaapConsumer.class);
141 private final AuditingManager auditingManager;
142 private final ResponseFormatManager responseFormatManager;
145 public ComponentsUtils(AuditingManager auditingManager) {
146 this.auditingManager = auditingManager;
147 this.responseFormatManager = ResponseFormatManager.getInstance();
150 public static <T> T parseJsonToObject(String data, Class<T> clazz) {
151 Type constraintType = new TypeToken<PropertyConstraint>() {
153 Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
154 log.trace("convert json to object. json=\n{}", data);
155 return gson.fromJson(data, clazz);
158 private static Set<String> getNodesFiltersToBeDeleted(final Component component, final String componentInstanceName) {
159 return component.getComponentInstances().stream().filter(ci -> isNodeFilterUsingChangedCi(ci, componentInstanceName))
160 .map(ComponentInstance::getName).collect(Collectors.toSet());
163 public static Set<String> getNodesFiltersToBeDeleted(final Component component, final ComponentInstance componentInstance) {
164 return getNodesFiltersToBeDeleted(component, componentInstance.getName());
167 private static boolean isNodeFilterUsingChangedCi(final ComponentInstance componentInstance, final String componentInstanceName) {
168 if (CollectionUtils.isEmpty(componentInstance.getDirectives())) {
171 if (componentInstance.getNodeFilter() == null || componentInstance.getNodeFilter().getProperties() == null
172 || componentInstance.getNodeFilter().getProperties().getListToscaDataDefinition() == null) {
175 return componentInstance.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
176 .anyMatch(property -> ServiceFilterUtils.isPropertyConstraintChangedByCi(property, componentInstanceName));
179 public AuditingManager getAuditingManager() {
180 return auditingManager;
183 public <T> Either<T, ResponseFormat> convertJsonToObject(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum) {
185 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
186 log.debug("object is null after converting from json");
187 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
188 return Either.right(responseFormat);
191 T obj = parseJsonToObject(data, clazz);
192 return Either.left(obj);
193 } catch (Exception e) {
195 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
196 log.debug("failed to convert from json {}", data, e);
197 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
198 return Either.right(responseFormat);
202 public <T> Either<T, ResponseFormat> convertJsonToObjectUsingObjectMapper(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum,
203 ComponentTypeEnum typeEnum) {
205 ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
206 mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
207 mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
209 log.trace("convert json to object. json=\n{}", data);
210 SimpleModule module = new SimpleModule("customDeserializationModule");
211 module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
212 module.addDeserializer(ToscaFunction.class, new ToscaFunctionJsonDeserializer());
213 mapper.registerModule(module);
214 mapper.setSerializationInclusion(Include.NON_NULL);
215 component = mapper.readValue(data, clazz);
216 if (component == null) {
217 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
218 log.debug("object is null after converting from json");
219 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
220 return Either.right(responseFormat);
222 } catch (Exception e) {
223 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
224 log.debug("failed to convert from json {}", data, e);
225 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
226 return Either.right(responseFormat);
228 return Either.left(component);
231 public ResponseFormat getResponseFormat(ActionStatus actionStatus, String... params) {
232 return responseFormatManager.getResponseFormat(actionStatus, params);
235 public ResponseFormat getResponseFormat(StorageOperationStatus storageStatus, String... params) {
236 return responseFormatManager.getResponseFormat(this.convertFromStorageResponse(storageStatus), params);
239 public <T> Either<List<T>, ResponseFormat> convertToResponseFormatOrNotFoundErrorToEmptyList(StorageOperationStatus storageOperationStatus) {
240 return storageOperationStatus.equals(StorageOperationStatus.NOT_FOUND) ? Either.left(Collections.emptyList())
241 : Either.right(getResponseFormat(storageOperationStatus));
245 * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus
246 * is anonymously converted from storage operation, and the caller doesn't know what actionStatus he received. It's caller's Responsibility to
247 * fill the resource object passed to this function with needed fields.
249 * Note that RESOURCE_IN_USE case passes hardcoded "resource" string to the error parameter. This means that if Resource object will also be used
250 * for Service, this code needs to be refactored and we should tell Resource from Service.
252 * @param actionStatus
256 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, Component resource) {
257 if (resource == null) {
258 return getResponseFormat(actionStatus);
260 ResponseFormat responseFormat;
261 switch (actionStatus) {
262 case COMPONENT_VERSION_ALREADY_EXIST:
263 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
264 resource.getVersion());
266 case RESOURCE_NOT_FOUND:
267 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resource.getName());
269 case COMPONENT_NAME_ALREADY_EXIST:
270 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
273 case COMPONENT_IN_USE:
274 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, ComponentTypeEnum.RESOURCE.name().toLowerCase(),
275 resource.getUniqueId());
278 responseFormat = getResponseFormat(actionStatus);
281 return responseFormat;
284 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, String resourceName) {
285 if (resourceName == null) {
286 return getResponseFormat(actionStatus);
288 ResponseFormat responseFormat;
289 if (actionStatus == ActionStatus.RESOURCE_NOT_FOUND) {
290 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceName);
292 responseFormat = getResponseFormat(actionStatus);
294 return responseFormat;
297 public ResponseFormat getResponseFormatByCapabilityType(ActionStatus actionStatus, CapabilityTypeDefinition capabilityType) {
298 if (capabilityType == null) {
299 return getResponseFormat(actionStatus);
301 ResponseFormat responseFormat;
302 if (actionStatus == ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST) {
303 responseFormat = getResponseFormat(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, capabilityType.getType());
305 responseFormat = getResponseFormat(actionStatus);
307 return responseFormat;
310 public <T> ResponseFormat getResponseFormatByElement(ActionStatus actionStatus, T obj) {
312 return getResponseFormat(actionStatus);
314 ResponseFormat responseFormat = null;
315 if (actionStatus == ActionStatus.MISSING_CAPABILITY_TYPE) {
316 if (obj instanceof List && org.apache.commons.collections.CollectionUtils.isNotEmpty((List) obj)) {
317 List list = (List) obj;
318 if (list.get(0) instanceof RequirementDefinition) {
319 responseFormat = getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, ((RequirementDefinition) list
320 .get(0)).getName()); //Arbitray index, all we need is single object
321 return responseFormat;
324 log.debug("UNKNOWN TYPE : expecting obj as a non empty List<RequirmentsDefinitions>");
326 responseFormat = getResponseFormat(actionStatus);
328 return responseFormat;
332 * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus
333 * is anynomously converted from storage operation, and the caller doesn't know what actionStatus he received. It's caller's responisibility to
334 * fill the passed resource object with needed fields.
336 * @param actionStatus
340 ResponseFormat getResponseFormatByUser(ActionStatus actionStatus, User user) {
342 return getResponseFormat(actionStatus);
344 ResponseFormat requestErrorWrapper;
345 switch (actionStatus) {
346 case INVALID_USER_ID:
347 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
349 case INVALID_EMAIL_ADDRESS:
350 requestErrorWrapper = getResponseFormat(actionStatus, user.getEmail());
353 requestErrorWrapper = getResponseFormat(actionStatus, user.getRole());
356 case USER_ALREADY_EXIST:
358 case USER_HAS_ACTIVE_ELEMENTS:
359 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
362 requestErrorWrapper = getResponseFormat(actionStatus);
365 return requestErrorWrapper;
368 public ResponseFormat getResponseFormatByUserId(ActionStatus actionStatus, String userId) {
369 User user = new User();
370 user.setUserId(userId);
371 return getResponseFormatByUser(actionStatus, user);
374 public ResponseFormat getResponseFormatByDE(ActionStatus actionStatus, String envName) {
375 ResponseFormat responseFormat;
376 switch (actionStatus) {
377 case DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE:
378 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE, envName);
380 case DISTRIBUTION_ENVIRONMENT_NOT_FOUND:
381 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND, envName);
384 responseFormat = getResponseFormat(actionStatus);
387 return responseFormat;
390 public ResponseFormat getResponseFormatByArtifactId(ActionStatus actionStatus, String... params) {
391 ResponseFormat responseFormat;
392 switch (actionStatus) {
393 case RESOURCE_NOT_FOUND:
394 case ARTIFACT_NOT_FOUND:
395 responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, params);
397 case ARTIFACT_NAME_INVALID:
398 responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NAME_INVALID, params);
401 responseFormat = getResponseFormat(actionStatus);
404 return responseFormat;
407 public ResponseFormat getInvalidContentErrorAndAudit(User user, AuditingActionEnum actionEnum) {
408 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
409 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
410 auditAdminUserAction(actionEnum, user, null, null, responseFormat);
411 return responseFormat;
414 public ResponseFormat getInvalidContentErrorAndAudit(User user, String resourceName, AuditingActionEnum actionEnum) {
415 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
416 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
417 auditResource(responseFormat, user, resourceName, actionEnum);
418 return responseFormat;
421 public ResponseFormat getInvalidContentErrorForConsumerAndAudit(User user, ConsumerDefinition consumer, AuditingActionEnum actionEnum) {
422 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
423 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
424 auditConsumerCredentialsEvent(actionEnum, consumer, responseFormat, user);
425 return responseFormat;
428 private ResponseFormat getInvalidContentErrorAndAuditComponent(User user, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
429 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
430 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
431 auditComponentAdmin(responseFormat, user, null, actionEnum, typeEnum);
432 return responseFormat;
435 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum,
436 ResourceVersionInfo prevResFields) {
437 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum, prevResFields, null, null);
440 public void auditResource(ResponseFormat responseFormat, User modifier, String resourceName, AuditingActionEnum actionEnum) {
441 auditResource(responseFormat, modifier, null, resourceName, actionEnum);
444 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum) {
445 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum);
448 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum) {
449 auditResource(responseFormat, modifier, resource, resourceName, actionEnum, ResourceVersionInfo.newBuilder().build(), null, null);
452 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum,
453 ResourceVersionInfo prevResFields, String currentArtifactUuid, ArtifactDefinition artifactDefinition) {
454 if (actionEnum != null) {
455 int status = responseFormat.getStatus();
457 String resourceCurrVersion = null;
458 String resourceCurrState = null;
459 String invariantUUID = null;
460 String resourceType = ComponentTypeEnum.RESOURCE.getValue();
461 String toscaNodeType = null;
462 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
463 String message = getMessageString(responseFormat);
464 String artifactData = buildAuditingArtifactData(artifactDefinition);
465 if (resource != null) {
466 resourceName = resource.getName();
467 resourceCurrVersion = resource.getVersion();
468 if (resource.getLifecycleState() != null) {
469 resourceCurrState = resource.getLifecycleState().name();
471 if (resource.getResourceType() != null) {
472 resourceType = resource.getResourceType().name();
474 invariantUUID = resource.getInvariantUUID();
475 uuid = resource.getUUID();
476 toscaNodeType = resource.getToscaResourceName();
478 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(actionEnum,
479 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(uuid)
480 .build(), new ResourceCommonInfo(resourceName, resourceType), prevResFields,
481 ResourceVersionInfo.newBuilder().artifactUuid(currentArtifactUuid).state(resourceCurrState).version(resourceCurrVersion).build(),
482 invariantUUID, modifier, artifactData, null, null, toscaNodeType);
483 getAuditingManager().auditEvent(factory);
487 private String getMessageString(ResponseFormat responseFormat) {
489 if (responseFormat.getMessageId() != null) {
490 message = responseFormat.getMessageId() + ": ";
492 message += responseFormat.getFormattedMessage();
496 public void auditDistributionDownload(ResponseFormat responseFormat, DistributionData distributionData) {
497 log.trace("Inside auditing");
498 int status = responseFormat.getStatus();
499 String message = getMessageString(responseFormat);
500 AuditDistributionDownloadEventFactory factory = new AuditDistributionDownloadEventFactory(
501 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).build(), distributionData);
502 getAuditingManager().auditEvent(factory);
505 public void auditExternalGetAsset(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
506 ResourceCommonInfo resourceCommonInfo, String requestId, String serviceInstanceId) {
507 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
508 AuditEventFactory factory = new AuditAssetExternalApiEventFactory(actionEnum,
509 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
510 .serviceInstanceId(serviceInstanceId).build(), resourceCommonInfo, distributionData);
511 getAuditingManager().auditEvent(factory);
514 public void auditExternalGetAssetList(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
516 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
517 AuditEventFactory factory = new AuditAssetListExternalApiEventFactory(actionEnum,
518 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
519 .build(), distributionData);
520 getAuditingManager().auditEvent(factory);
523 public void auditChangeLifecycleAction(ResponseFormat responseFormat, ComponentTypeEnum componentType, String requestId, Component component,
524 Component responseObject, DistributionData distributionData, User modifier) {
525 String invariantUuid = "";
526 String serviceInstanceId = "";
527 ResourceVersionInfo currResourceVersionInfo = null;
528 ResourceVersionInfo prevResourceVersionInfo = null;
529 ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
530 if (component != null) {
531 prevResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
532 resourceCommonInfo.setResourceName(component.getName());
534 if (responseObject != null) {
535 currResourceVersionInfo = buildResourceVersionInfoFromComponent(responseObject);
536 invariantUuid = responseObject.getInvariantUUID();
537 serviceInstanceId = responseObject.getUUID();
538 } else if (component != null) {
539 currResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
540 invariantUuid = component.getInvariantUUID();
541 serviceInstanceId = component.getUUID();
543 if (prevResourceVersionInfo == null) {
544 prevResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
546 if (currResourceVersionInfo == null) {
547 currResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
549 AuditEventFactory factory = new AuditChangeLifecycleExternalApiEventFactory(
550 CommonAuditData.newBuilder().serviceInstanceId(serviceInstanceId).requestId(requestId).description(getMessageString(responseFormat))
551 .status(responseFormat.getStatus()).build(), resourceCommonInfo, distributionData, prevResourceVersionInfo, currResourceVersionInfo,
552 invariantUuid, modifier);
553 getAuditingManager().auditEvent(factory);
556 private ResourceVersionInfo buildResourceVersionInfoFromComponent(Component component) {
557 return ResourceVersionInfo.newBuilder().version(component.getVersion()).state(component.getLifecycleState().name()).build();
560 public void auditExternalCrudApi(ResponseFormat responseFormat, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo,
561 HttpServletRequest request, ArtifactDefinition artifactDefinition, String artifactUuid) {
562 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
563 ResourceVersionInfo currResourceVersionInfo;
564 User modifier = new User();
565 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
566 String artifactData = "";
567 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
568 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
569 if (artifactDefinition == null) {
570 currResourceVersionInfo = ResourceVersionInfo.newBuilder().artifactUuid(artifactUuid).build();
572 currResourceVersionInfo = ResourceVersionInfo.newBuilder().artifactUuid(artifactDefinition.getArtifactUUID())
573 .version(artifactDefinition.getArtifactVersion()).build();
574 artifactData = buildAuditingArtifactData(artifactDefinition);
575 modifier.setUserId(artifactDefinition.getUserIdLastUpdater());
577 AuditEventFactory factory = new AuditCrudExternalApiArtifactEventFactory(actionEnum,
578 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
579 .build(), resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().build(), currResourceVersionInfo, null, modifier,
581 getAuditingManager().auditEvent(factory);
584 public boolean isExternalApiEvent(AuditingActionEnum auditingActionEnum) {
585 return auditingActionEnum != null && auditingActionEnum.getAuditingEsType().equals(AuditingTypesConstants.EXTERNAL_API_EVENT_TYPE);
588 public void auditCreateResourceExternalApi(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo, HttpServletRequest request,
590 String invariantUuid = null;
591 String serviceInstanceId = null;
592 User modifier = new User();
593 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
594 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
595 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
596 ResourceVersionInfo currResourceVersionInfo;
597 if (resource != null) {
598 currResourceVersionInfo = ResourceVersionInfo.newBuilder().state(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())
599 .version(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION).build();
600 resourceCommonInfo.setResourceName(resource.getName());
601 invariantUuid = resource.getInvariantUUID();
602 serviceInstanceId = resource.getUUID();
604 currResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
606 AuditEventFactory factory = new AuditCreateResourceExternalApiEventFactory(
607 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
608 .serviceInstanceId(serviceInstanceId).build(), resourceCommonInfo, distributionData, currResourceVersionInfo, invariantUuid,
610 getAuditingManager().auditEvent(factory);
613 public void auditCreateServiceExternalApi(ResponseFormat responseFormat, HttpServletRequest request, Component service) {
614 String invariantUuid = null;
615 String serviceInstanceId = null;
616 User modifier = new User();
617 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
618 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
619 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
620 if (null != service) {
621 invariantUuid = service.getInvariantUUID();
622 serviceInstanceId = service.getUUID();
624 AuditEventFactory factory = new AuditCreateServiceExternalApiEventFactory(
625 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
626 .serviceInstanceId(serviceInstanceId).build(), new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()), distributionData,
627 invariantUuid, modifier);
628 getAuditingManager().auditEvent(factory);
631 public void auditExternalActivateService(ResponseFormat responseFormat, DistributionData distributionData, String requestId,
632 String serviceInstanceUuid, User modifier) {
633 AuditEventFactory factory = new AuditActivateServiceExternalApiEventFactory(
634 CommonAuditData.newBuilder().serviceInstanceId(serviceInstanceUuid).description(getMessageString(responseFormat))
635 .status(responseFormat.getStatus()).requestId(requestId).build(), new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()),
636 distributionData, "", modifier);
637 getAuditingManager().auditEvent(factory);
640 public void auditExternalDownloadArtifact(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo, DistributionData distributionData,
641 String requestId, String currArtifactUuid, String userId) {
642 User modifier = new User();
643 modifier.setUserId(userId);
644 AuditEventFactory factory = new AuditDownloadArtifactExternalApiEventFactory(
645 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus()).requestId(requestId)
646 .build(), resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().artifactUuid(currArtifactUuid).build(), modifier);
647 getAuditingManager().auditEvent(factory);
650 private String buildAuditingArtifactData(ArtifactDefinition artifactDefinition) {
651 StringBuilder sb = new StringBuilder();
652 if (artifactDefinition != null) {
653 sb.append(artifactDefinition.getArtifactGroupType().getType()).append(",").append("'").append(artifactDefinition.getArtifactLabel())
654 .append("'").append(",").append(artifactDefinition.getArtifactType()).append(",").append(artifactDefinition.getArtifactName())
655 .append(",").append(artifactDefinition.getTimeout()).append(",").append(artifactDefinition.getEsId());
657 sb.append(artifactDefinition.getArtifactVersion() != null ? artifactDefinition.getArtifactVersion() : " ");
659 sb.append(artifactDefinition.getArtifactUUID() != null ? artifactDefinition.getArtifactUUID() : " ");
661 return sb.toString();
664 public void auditCategory(ResponseFormat responseFormat, User modifier, String categoryName, String subCategoryName, String groupingName,
665 AuditingActionEnum actionEnum, String componentType) {
666 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
667 AuditEventFactory factory = new AuditCategoryEventFactory(actionEnum,
668 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
669 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, categoryName, subCategoryName, groupingName, componentType);
670 getAuditingManager().auditEvent(factory);
673 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse) {
674 return convertFromStorageResponse(storageResponse, ComponentTypeEnum.RESOURCE);
677 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse, ComponentTypeEnum type) {
678 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
679 if (storageResponse == null) {
682 switch (storageResponse) {
684 responseEnum = ActionStatus.OK;
686 case CONNECTION_FAILURE:
688 responseEnum = ActionStatus.GENERAL_ERROR;
691 responseEnum = ActionStatus.INVALID_CONTENT;
693 case ENTITY_ALREADY_EXISTS:
694 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
696 case PARENT_RESOURCE_NOT_FOUND:
697 responseEnum = ActionStatus.PARENT_RESOURCE_NOT_FOUND;
699 case MULTIPLE_PARENT_RESOURCE_FOUND:
700 responseEnum = ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND;
703 if (ComponentTypeEnum.RESOURCE == type) {
704 responseEnum = ActionStatus.RESOURCE_NOT_FOUND;
705 } else if (ComponentTypeEnum.PRODUCT == type) {
706 responseEnum = ActionStatus.PRODUCT_NOT_FOUND;
708 responseEnum = ActionStatus.SERVICE_NOT_FOUND;
711 case FAILED_TO_LOCK_ELEMENT:
712 responseEnum = ActionStatus.COMPONENT_IN_USE;
714 case ARTIFACT_NOT_FOUND:
715 responseEnum = ActionStatus.ARTIFACT_NOT_FOUND;
717 case DISTR_ENVIRONMENT_NOT_AVAILABLE:
718 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE;
720 case DISTR_ENVIRONMENT_NOT_FOUND:
721 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND;
723 case DISTR_ENVIRONMENT_SENT_IS_INVALID:
724 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID;
727 responseEnum = ActionStatus.INVALID_CONTENT;
730 responseEnum = ActionStatus.INVALID_CONTENT;
733 responseEnum = ActionStatus.CSAR_NOT_FOUND;
735 case PROPERTY_NAME_ALREADY_EXISTS:
736 responseEnum = ActionStatus.PROPERTY_NAME_ALREADY_EXISTS;
738 case MATCH_NOT_FOUND:
739 responseEnum = ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY;
741 case CATEGORY_NOT_FOUND:
742 responseEnum = ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;
744 case INVALID_PROPERTY:
745 responseEnum = ActionStatus.INVALID_PROPERTY;
747 case COMPONENT_IS_ARCHIVED:
748 responseEnum = ActionStatus.COMPONENT_IS_ARCHIVED;
750 case COMPONENT_NOT_ARCHIVED:
751 responseEnum = ActionStatus.COMPONENT_NOT_ARCHIVED;
753 case COMPONENT_IS_IN_USE:
754 responseEnum = ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT;
756 case DECLARED_INPUT_USED_BY_OPERATION:
757 responseEnum = ActionStatus.DECLARED_INPUT_USED_BY_OPERATION;
760 responseEnum = ActionStatus.GENERAL_ERROR;
763 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
767 public ActionStatus convertFromToscaError(ToscaError toscaError) {
768 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
769 if (toscaError == null) {
772 switch (toscaError) {// TODO match errors
773 case NODE_TYPE_CAPABILITY_ERROR:
774 case NOT_SUPPORTED_TOSCA_TYPE:
775 case NODE_TYPE_REQUIREMENT_ERROR:
776 responseEnum = ActionStatus.INVALID_CONTENT;
784 public ActionStatus convertFromStorageResponseForCapabilityType(StorageOperationStatus storageResponse) {
785 ActionStatus responseEnum;
786 switch (storageResponse) {
788 responseEnum = ActionStatus.OK;
790 case CONNECTION_FAILURE:
792 responseEnum = ActionStatus.GENERAL_ERROR;
795 responseEnum = ActionStatus.INVALID_CONTENT;
797 case ENTITY_ALREADY_EXISTS:
798 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
800 case SCHEMA_VIOLATION:
801 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
804 responseEnum = ActionStatus.GENERAL_ERROR;
807 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
811 public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
812 ActionStatus responseEnum;
813 switch (storageResponse) {
815 responseEnum = ActionStatus.OK;
817 case CONNECTION_FAILURE:
819 responseEnum = ActionStatus.GENERAL_ERROR;
822 responseEnum = ActionStatus.INVALID_CONTENT;
824 case ENTITY_ALREADY_EXISTS:
825 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
827 case SCHEMA_VIOLATION:
828 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
831 responseEnum = ActionStatus.GENERAL_ERROR;
834 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
838 public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
839 ActionStatus responseEnum;
840 switch (storageResponse) {
842 responseEnum = ActionStatus.OK;
845 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
847 case INVALID_PROPERTY:
848 responseEnum = ActionStatus.INVALID_PROPERTY;
851 responseEnum = ActionStatus.GENERAL_ERROR;
854 responseEnum = ActionStatus.INVALID_CONTENT;
856 case MATCH_NOT_FOUND:
857 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
859 case SCHEMA_VIOLATION:
860 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
864 responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
866 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
870 responseEnum = ActionStatus.GENERAL_ERROR;
873 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
877 public ResponseFormat getResponseFormatForResourceInstance(ActionStatus actionStatus, String serviceName, String resourceInstanceName) {
878 ResponseFormat responseFormat;
879 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
880 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
882 responseFormat = getResponseFormat(actionStatus, serviceName);
884 return responseFormat;
887 public ResponseFormat getResponseFormatForResourceInstanceProperty(ActionStatus actionStatus, String resourceInstanceName) {
888 ResponseFormat responseFormat;
889 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
890 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
892 responseFormat = getResponseFormat(actionStatus);
894 return responseFormat;
897 public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
898 ActionStatus responseEnum;
899 switch (storageResponse) {
901 responseEnum = ActionStatus.OK;
904 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
907 responseEnum = ActionStatus.GENERAL_ERROR;
910 responseEnum = ActionStatus.INVALID_CONTENT;
912 case MATCH_NOT_FOUND:
913 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
915 case SCHEMA_VIOLATION:
916 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
919 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
922 responseEnum = ActionStatus.GENERAL_ERROR;
925 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
929 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
930 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, String comment) {
931 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, comment, null, null);
934 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
935 ComponentTypeEnum typeEnum) {
936 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
937 ResourceVersionInfo.newBuilder().build());
940 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
941 ComponentTypeEnum typeEnum, String comment) {
942 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
943 ResourceVersionInfo.newBuilder().build(), null, comment, null, null);
946 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
947 ComponentTypeEnum typeEnum, ResourceVersionInfo prevComponent) {
948 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), prevComponent);
951 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
952 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent) {
953 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, null, null, null);
956 public void auditComponent(ResponseFormat responseFormat, User modifier, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo,
958 auditComponent(responseFormat, modifier, null, actionEnum, resourceCommonInfo, ResourceVersionInfo.newBuilder().build(), null, comment, null,
962 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
963 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent) {
964 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, currComponent, null, null, null);
967 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
968 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent,
969 String comment, ArtifactDefinition artifactDefinition, String did) {
970 if (actionEnum != null) {
972 String currState = null;
973 String invariantUUID = null;
974 String currArtifactUid = null;
975 String currVersion = null;
976 String dcurrStatus = null;
977 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
978 String message = getMessageString(responseFormat);
979 int status = responseFormat.getStatus();
980 String artifactData = buildAuditingArtifactData(artifactDefinition);
981 if (component != null) {
982 // fields that are filled during creation and might still be empty
983 if (component.getLifecycleState() != null) {
984 currState = component.getLifecycleState().name();
986 uuid = component.getUUID();
987 invariantUUID = component.getInvariantUUID();
988 currVersion = component.getVersion();
989 if (StringUtils.isEmpty(resourceCommonInfo.getResourceName())) {
990 resourceCommonInfo.setResourceName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
993 if (currComponent != null) {
994 currArtifactUid = currComponent.getArtifactUuid();
995 dcurrStatus = currComponent.getDistributionStatus();
996 if (currState == null) { //probably it was not set
997 currState = currComponent.getState();
999 if (currVersion == null) { //probably it was not set
1000 currVersion = currComponent.getVersion();
1003 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(actionEnum,
1004 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(uuid)
1005 .build(), resourceCommonInfo, prevComponent,
1006 ResourceVersionInfo.newBuilder().artifactUuid(currArtifactUid).state(currState).version(currVersion).distributionStatus(dcurrStatus)
1007 .build(), invariantUUID, modifier, artifactData, comment, did, null);
1008 getAuditingManager().auditEvent(factory);
1012 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData,
1014 auditDistributionEngine(action, environmentName, distributionTopicData, null, null, status);
1017 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role,
1018 String apiKey, String status) {
1019 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1020 .createDistributionEngineEventFactory(action, environmentName, distributionTopicData, role, apiKey, status);
1021 getAuditingManager().auditEvent(factory);
1024 public void auditEnvironmentEngine(AuditingActionEnum actionEnum, String environmentID, String environmentType, String action,
1025 String environmentName, String tenantContext) {
1026 AuditEventFactory factory = new AuditEcompOpEnvEventFactory(actionEnum, environmentID, environmentName, environmentType, action,
1028 audit.startAuditFetchLog(PARTNER_NAME, DmaapConsumer.class.getName());
1029 audit.logEntry(LogLevel.INFO, Severity.OK, null, MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), environmentID);
1030 getAuditingManager().auditEvent(factory, audit);
1033 public void auditDistributionNotification(String serviceUUID, String resourceName, String resourceType, String currVersion, User modifier,
1034 String environmentName, String currState, String topicName, String distributionId, String description,
1035 String status, String workloadContext, String tenant) {
1036 AuditEventFactory factory = new AuditDistributionNotificationEventFactory(
1037 CommonAuditData.newBuilder().serviceInstanceId(serviceUUID).status(status).description(description)
1038 .requestId(ThreadLocalsHolder.getUuid()).build(), new ResourceCommonInfo(resourceName, resourceType),
1039 ResourceVersionInfo.newBuilder().state(currState).version(currVersion).build(), distributionId, modifier, topicName,
1040 new OperationalEnvAuditData(environmentName, workloadContext, tenant));
1041 getAuditingManager().auditEvent(factory);
1044 public void auditAuthEvent(String url, String user, String authStatus, String realm) {
1045 AuditEventFactory factory = new AuditAuthRequestEventFactory(CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).build(),
1046 user, url, realm, authStatus);
1047 getAuditingManager().auditEvent(factory);
1050 public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName, String resourceUrl, String statusTime,
1051 String status, String errorReason, LoggerSdcAudit audit) {
1052 AuditEventFactory factory = new AuditDistributionStatusEventFactory(
1053 CommonAuditData.newBuilder().description(errorReason).status(status).requestId(distributionId).build(),
1054 new DistributionData(consumerId, resourceUrl), distributionId, topicName, statusTime);
1055 getAuditingManager().auditEvent(factory, audit);
1058 public void auditGetUebCluster(String consumerId, String status, String description) {
1059 AuditEventFactory factory = new AuditGetUebClusterEventFactory(
1060 CommonAuditData.newBuilder().description(description).status(status).requestId(ThreadLocalsHolder.getUuid()).build(), consumerId);
1061 getAuditingManager().auditEvent(factory);
1064 public void auditMissingInstanceIdAsDistributionEngineEvent(AuditingActionEnum actionEnum, String status) {
1065 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1066 .createDistributionEngineEventFactory(actionEnum, "", DistributionTopicData.newBuilder().build(), null, null, status);
1067 getAuditingManager().auditEvent(factory);
1070 public void auditRegisterOrUnRegisterEvent(AuditingActionEnum action, String consumerId, String apiPublicKey, String envName, String status,
1071 String distributionStatus, String notifTopicName, String statusTopicName) {
1072 String appliedStatus = !StringUtils.isEmpty(status) ? status : distributionStatus;
1073 AuditEventFactory factory = new AuditRegUnregDistributionEngineEventFactory(action,
1074 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).status(appliedStatus).build(),
1075 DistributionTopicData.newBuilder().statusTopic(statusTopicName).notificationTopic(notifTopicName).build(), consumerId, apiPublicKey,
1077 getAuditingManager().auditEvent(factory);
1080 public void auditServiceDistributionDeployed(String serviceName, String serviceVersion, String serviceUUID, String distributionId, String status,
1081 String desc, User modifier) {
1082 AuditEventFactory factory = new AuditDistributionDeployEventFactory(
1083 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(serviceUUID).status(status).description(desc)
1084 .build(), new ResourceCommonInfo(serviceName, "Service"), distributionId, modifier, serviceVersion);
1085 getAuditingManager().auditEvent(factory);
1088 public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat,
1090 AuditEventFactory factory = new AuditConsumerEventFactory(actionEnum,
1091 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1092 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, consumer);
1093 getAuditingManager().auditEvent(factory);
1096 public void auditGetUsersList(User user, String details, ResponseFormat responseFormat) {
1097 AuditEventFactory factory = new AuditGetUsersListEventFactory(
1098 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1099 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1100 getAuditingManager().auditEvent(factory);
1103 public void auditAdminUserActionAndThrowException(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter,
1104 ActionStatus status, String... params) {
1105 ResponseFormat responseFormat = getResponseFormat(status, params);
1106 auditAdminUserAction(actionEnum, modifier, userBefore, userAfter, responseFormat);
1107 throw new ByResponseFormatComponentException(responseFormat);
1110 public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
1111 AuditEventFactory factory = new AuditUserAdminEventFactory(actionEnum,
1112 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1113 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, userBefore, userAfter);
1114 getAuditingManager().auditEvent(factory);
1117 public void auditUserAccess(User user, ActionStatus status, String... params) {
1118 auditUserAccess(user, getResponseFormat(status, params));
1121 public void auditUserAccess(User user, ResponseFormat responseFormat) {
1122 AuditEventFactory factory = new AuditUserAccessEventFactory(
1123 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1124 .requestId(ThreadLocalsHolder.getUuid()).build(), user);
1125 getAuditingManager().auditEvent(factory);
1128 public void auditGetCategoryHierarchy(User user, String details, ResponseFormat responseFormat) {
1129 AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(
1130 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1131 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1132 getAuditingManager().auditEvent(factory);
1135 public ResponseFormat getResponseFormatByComponent(ActionStatus actionStatus, Component component, ComponentTypeEnum type) {
1136 if (component == null) {
1137 return getResponseFormat(actionStatus);
1139 ResponseFormat responseFormat;
1140 switch (actionStatus) {
1141 case COMPONENT_VERSION_ALREADY_EXIST:
1142 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, type.getValue(), component.getVersion());
1144 case RESOURCE_NOT_FOUND:
1145 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND,
1146 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1148 case COMPONENT_NAME_ALREADY_EXIST:
1149 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(),
1150 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1152 case COMPONENT_IN_USE:
1153 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, type.name().toLowerCase(), component.getUniqueId());
1155 case SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND:
1156 responseFormat = getResponseFormat(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND,
1157 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1160 responseFormat = getResponseFormat(actionStatus);
1163 return responseFormat;
1166 public boolean validateStringNotEmpty(String value) {
1167 return value != null && !value.trim().isEmpty();
1170 public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
1171 ActionStatus responseEnum;
1172 switch (storageResponse) {
1174 responseEnum = ActionStatus.OK;
1176 case ENTITY_ALREADY_EXISTS:
1177 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
1180 responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
1183 responseEnum = ActionStatus.GENERAL_ERROR;
1186 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1187 return responseEnum;
1190 public ActionStatus convertFromResultStatusEnum(ResultStatusEnum resultStatus, JsonPresentationFields elementType) {
1191 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1192 switch (resultStatus) {
1194 responseEnum = ActionStatus.OK;
1196 case ELEMENT_NOT_FOUND:
1197 if (elementType == JsonPresentationFields.PROPERTY) {
1198 responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
1201 case INVALID_PROPERTY_DEFAULT_VALUE:
1202 case INVALID_PROPERTY_TYPE:
1203 case INVALID_PROPERTY_VALUE:
1204 case INVALID_PROPERTY_NAME:
1205 case MISSING_ENTRY_SCHEMA_TYPE:
1206 responseEnum = ActionStatus.INVALID_PROPERTY;
1208 case INVALID_ATTRIBUTE_NAME:
1209 responseEnum = ActionStatus.INVALID_ATTRIBUTE;
1214 return responseEnum;
1217 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus, AdditionalInfoParameterInfo additionalInfoParameterInfo,
1218 NodeTypeEnum nodeType, AdditionalInformationEnum labelOrValue) {
1219 if (additionalInfoParameterInfo == null) {
1220 additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
1222 if (labelOrValue == null) {
1223 labelOrValue = AdditionalInformationEnum.None;
1225 switch (actionStatus) {
1226 case COMPONENT_NAME_ALREADY_EXIST:
1227 return getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey());
1228 case ADDITIONAL_INFORMATION_EXCEEDS_LIMIT:
1229 return getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(),
1230 ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString());
1231 case ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED:
1232 return getResponseFormat(actionStatus, nodeType.name().toLowerCase());
1233 case ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED:
1234 return getResponseFormat(actionStatus);
1235 case ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS:
1236 return getResponseFormat(actionStatus);
1237 case ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS:
1238 return getResponseFormat(actionStatus);
1239 case ADDITIONAL_INFORMATION_NOT_FOUND:
1240 return getResponseFormat(actionStatus);
1242 return getResponseFormat(actionStatus);
1246 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus) {
1247 return getResponseFormatAdditionalProperty(actionStatus, null, null, null);
1250 public ActionStatus convertFromStorageResponseForConsumer(StorageOperationStatus storageResponse) {
1251 ActionStatus responseEnum;
1252 switch (storageResponse) {
1254 responseEnum = ActionStatus.OK;
1256 case CONNECTION_FAILURE:
1258 responseEnum = ActionStatus.GENERAL_ERROR;
1261 responseEnum = ActionStatus.INVALID_CONTENT;
1263 case ENTITY_ALREADY_EXISTS:
1264 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1266 case SCHEMA_VIOLATION:
1267 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1270 responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
1273 responseEnum = ActionStatus.GENERAL_ERROR;
1276 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1277 return responseEnum;
1280 public ActionStatus convertFromStorageResponseForGroupType(StorageOperationStatus storageResponse) {
1281 ActionStatus responseEnum;
1282 switch (storageResponse) {
1284 responseEnum = ActionStatus.OK;
1286 case CONNECTION_FAILURE:
1288 responseEnum = ActionStatus.GENERAL_ERROR;
1291 responseEnum = ActionStatus.INVALID_CONTENT;
1293 case ENTITY_ALREADY_EXISTS:
1294 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1296 case SCHEMA_VIOLATION:
1297 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1300 responseEnum = ActionStatus.GENERAL_ERROR;
1303 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1304 return responseEnum;
1307 public ActionStatus convertFromStorageResponseForPolicyType(StorageOperationStatus storageResponse) {
1308 ActionStatus responseEnum;
1309 switch (storageResponse) {
1311 responseEnum = ActionStatus.OK;
1313 case CONNECTION_FAILURE:
1315 responseEnum = ActionStatus.GENERAL_ERROR;
1318 responseEnum = ActionStatus.INVALID_CONTENT;
1320 case ENTITY_ALREADY_EXISTS:
1321 responseEnum = ActionStatus.POLICY_TYPE_ALREADY_EXIST;
1323 case SCHEMA_VIOLATION:
1324 responseEnum = ActionStatus.POLICY_TYPE_ALREADY_EXIST;
1327 responseEnum = ActionStatus.GENERAL_ERROR;
1330 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1331 return responseEnum;
1334 public ActionStatus convertFromStorageResponseForDataType(StorageOperationStatus storageResponse) {
1335 ActionStatus responseEnum;
1336 switch (storageResponse) {
1338 responseEnum = ActionStatus.OK;
1340 case CONNECTION_FAILURE:
1342 responseEnum = ActionStatus.GENERAL_ERROR;
1345 responseEnum = ActionStatus.INVALID_CONTENT;
1347 case ENTITY_ALREADY_EXISTS:
1348 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1350 case SCHEMA_VIOLATION:
1351 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1353 case CANNOT_UPDATE_EXISTING_ENTITY:
1354 responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
1357 responseEnum = ActionStatus.GENERAL_ERROR;
1360 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1361 return responseEnum;
1364 public ResponseFormat getResponseFormatByGroupType(ActionStatus actionStatus, GroupTypeDefinition groupType) {
1365 if (groupType == null) {
1366 return getResponseFormat(actionStatus);
1368 ResponseFormat responseFormat;
1369 switch (actionStatus) {
1370 case GROUP_MEMBER_EMPTY:
1371 case GROUP_TYPE_ALREADY_EXIST:
1372 responseFormat = getResponseFormat(actionStatus, groupType.getType());
1375 responseFormat = getResponseFormat(actionStatus);
1378 return responseFormat;
1381 public ResponseFormat getResponseFormatByPolicyType(ActionStatus actionStatus, PolicyTypeDefinition policyType) {
1382 if (policyType == null) {
1383 return getResponseFormat(actionStatus);
1385 ResponseFormat responseFormat;
1386 if (actionStatus == ActionStatus.POLICY_TYPE_ALREADY_EXIST) {
1387 responseFormat = getResponseFormat(actionStatus, policyType.getType());
1389 responseFormat = getResponseFormat(actionStatus);
1391 return responseFormat;
1394 public ResponseFormat getResponseFormatByDataType(ActionStatus actionStatus, DataTypeDefinition dataType, List<String> properties) {
1395 if (dataType == null) {
1396 return getResponseFormat(actionStatus);
1398 ResponseFormat responseFormat;
1399 switch (actionStatus) {
1400 case DATA_TYPE_ALREADY_EXIST:
1401 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1403 case DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM:
1404 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1406 case DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY:
1407 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1409 case DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR:
1410 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1412 case DATA_TYPE_DERIVED_IS_MISSING:
1413 responseFormat = getResponseFormat(actionStatus, dataType.getDerivedFromName());
1415 case DATA_TYPE_DUPLICATE_PROPERTY:
1416 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1418 case DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE:
1419 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1421 case DATA_TYPE_CANNOT_HAVE_PROPERTIES:
1422 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1424 case DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST:
1425 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1428 responseFormat = getResponseFormat(actionStatus);
1431 return responseFormat;
1434 public StorageOperationStatus convertToStorageOperationStatus(CassandraOperationStatus cassandraStatus) {
1435 StorageOperationStatus result;
1436 switch (cassandraStatus) {
1438 result = StorageOperationStatus.OK;
1441 result = StorageOperationStatus.NOT_FOUND;
1443 case CLUSTER_NOT_CONNECTED:
1444 case KEYSPACE_NOT_CONNECTED:
1445 result = StorageOperationStatus.CONNECTION_FAILURE;
1448 result = StorageOperationStatus.GENERAL_ERROR;
1454 public ResponseFormat getResponseFormat(ComponentException exception) {
1455 return exception instanceof ByResponseFormatComponentException ? getResponseFormat((ByResponseFormatComponentException) exception)
1456 : getResponseFormat((ByActionStatusComponentException) exception);
1459 public ResponseFormat getResponseFormat(ByResponseFormatComponentException exception) {
1460 return exception.getResponseFormat();
1463 public ResponseFormat getResponseFormat(ByActionStatusComponentException exception) {
1464 return getResponseFormat(exception.getActionStatus(), exception.getParams());
1467 public ActionStatus convertFromStorageResponseForRelationshipType(StorageOperationStatus storageResponse) {
1468 ActionStatus responseEnum;
1469 switch (storageResponse) {
1471 responseEnum = ActionStatus.OK;
1473 case CONNECTION_FAILURE:
1475 responseEnum = ActionStatus.GENERAL_ERROR;
1478 responseEnum = ActionStatus.INVALID_CONTENT;
1480 case ENTITY_ALREADY_EXISTS:
1481 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1483 case SCHEMA_VIOLATION:
1484 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1487 responseEnum = ActionStatus.GENERAL_ERROR;
1490 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1491 return responseEnum;
1494 public ResponseFormat getResponseFormat(StorageException exception) {
1495 ActionStatus status = convertFromStorageResponse(exception.getStorageOperationStatus());
1496 return getResponseFormat(status, exception.getParams());
1499 public List<UiLeftPaletteComponent> convertComponentToUiLeftPaletteComponentObject(List<Component> components) {
1500 List<UiLeftPaletteComponent> uiLeftPaletteComponents = new ArrayList<>();
1501 components.forEach(c -> uiLeftPaletteComponents.add(new UiLeftPaletteComponent(c)));
1502 return uiLeftPaletteComponents;
1505 public F<StorageOperationStatus, ResponseFormat> toResponseFormat() {
1506 return sos -> getResponseFormat(convertFromStorageResponse(sos));
1509 public Optional<UIConstraint> parseToConstraint(final String componentJson, final User user, final ComponentTypeEnum componentTypeEnum) {
1510 final Either<UIConstraint, ResponseFormat> uiConstraintResponseFormatEither = convertJsonToObjectUsingObjectMapper(componentJson, user,
1511 UIConstraint.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
1512 if (uiConstraintResponseFormatEither.isRight()) {
1513 return Optional.empty();
1515 return Optional.of(uiConstraintResponseFormatEither.left().value());
1518 private Either<List, ResponseFormat> parseToConstraints(final String componentJson, final User user, final ComponentTypeEnum componentTypeEnum) {
1519 return convertJsonToObjectUsingObjectMapper(componentJson, user, List.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
1522 public List<UIConstraint> validateAndParseConstraint(final ComponentTypeEnum componentTypeEnum, final String constraintData,
1523 final User userModifier) {
1524 final String FAILED_TO_PARSE_CONSTRAINT_DATA = "Failed to Parse Constraint Data {}";
1525 final Either<List, ResponseFormat> convertResponse = parseToConstraints(constraintData, userModifier, componentTypeEnum);
1526 if (convertResponse.isRight()) {
1527 log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData, convertResponse.right().value());
1528 return Collections.emptyList();
1530 final List<Map<String, String>> uiConstraintsMaps = (List<Map<String, String>>) convertResponse.left().value();
1531 if (uiConstraintsMaps == null) {
1532 log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData);
1533 return Collections.emptyList();
1535 return uiConstraintsMaps.stream().map(dataMap -> new ObjectMapper().convertValue(dataMap, UIConstraint.class))
1536 .collect(Collectors.toList());
1539 public Map<String, DataTypeDefinition> getAllDataTypes(final ApplicationDataTypeCache applicationDataTypeCache, final String model) {
1540 final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll(model);
1541 if (allDataTypes.isRight()) {
1542 final var operationStatus = allDataTypes.right().value();
1543 if (operationStatus == JanusGraphOperationStatus.NOT_FOUND) {
1544 BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", ErrorSeverity.ERROR);
1545 throw new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model);
1547 BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", ErrorSeverity.ERROR);
1548 throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
1551 return allDataTypes.left().value();
1554 public ActionStatus convertFromStorageResponseForArtifactType(final StorageOperationStatus storageResponse) {
1555 ActionStatus responseEnum;
1556 switch (storageResponse) {
1558 responseEnum = ActionStatus.OK;
1560 case CONNECTION_FAILURE:
1562 responseEnum = ActionStatus.GENERAL_ERROR;
1565 responseEnum = ActionStatus.INVALID_CONTENT;
1567 case ENTITY_ALREADY_EXISTS:
1568 responseEnum = ActionStatus.ARTIFACT_TYPE_ALREADY_EXIST;
1570 case SCHEMA_VIOLATION:
1571 responseEnum = ActionStatus.ARTIFACT_TYPE_ALREADY_EXIST;
1574 responseEnum = ActionStatus.GENERAL_ERROR;
1577 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1578 return responseEnum;