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.CAPABILITY_NOT_FOUND;
807 responseEnum = ActionStatus.GENERAL_ERROR;
810 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
814 public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
815 ActionStatus responseEnum;
816 switch (storageResponse) {
818 responseEnum = ActionStatus.OK;
820 case CONNECTION_FAILURE:
822 responseEnum = ActionStatus.GENERAL_ERROR;
825 responseEnum = ActionStatus.INVALID_CONTENT;
827 case ENTITY_ALREADY_EXISTS:
828 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
830 case SCHEMA_VIOLATION:
831 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
834 responseEnum = ActionStatus.GENERAL_ERROR;
837 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
841 public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
842 ActionStatus responseEnum;
843 switch (storageResponse) {
845 responseEnum = ActionStatus.OK;
848 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
850 case INVALID_PROPERTY:
851 responseEnum = ActionStatus.INVALID_PROPERTY;
854 responseEnum = ActionStatus.GENERAL_ERROR;
857 responseEnum = ActionStatus.INVALID_CONTENT;
859 case MATCH_NOT_FOUND:
860 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
862 case SCHEMA_VIOLATION:
863 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
867 responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
869 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
873 responseEnum = ActionStatus.GENERAL_ERROR;
876 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
880 public ResponseFormat getResponseFormatForResourceInstance(ActionStatus actionStatus, String serviceName, String resourceInstanceName) {
881 ResponseFormat responseFormat;
882 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
883 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
885 responseFormat = getResponseFormat(actionStatus, serviceName);
887 return responseFormat;
890 public ResponseFormat getResponseFormatForResourceInstanceProperty(ActionStatus actionStatus, String resourceInstanceName) {
891 ResponseFormat responseFormat;
892 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
893 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
895 responseFormat = getResponseFormat(actionStatus);
897 return responseFormat;
900 public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
901 ActionStatus responseEnum;
902 switch (storageResponse) {
904 responseEnum = ActionStatus.OK;
907 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
910 responseEnum = ActionStatus.GENERAL_ERROR;
913 responseEnum = ActionStatus.INVALID_CONTENT;
915 case MATCH_NOT_FOUND:
916 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
918 case SCHEMA_VIOLATION:
919 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
922 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
925 responseEnum = ActionStatus.GENERAL_ERROR;
928 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
932 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
933 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, String comment) {
934 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, comment, null, null);
937 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
938 ComponentTypeEnum typeEnum) {
939 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
940 ResourceVersionInfo.newBuilder().build());
943 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
944 ComponentTypeEnum typeEnum, String comment) {
945 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
946 ResourceVersionInfo.newBuilder().build(), null, comment, null, null);
949 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
950 ComponentTypeEnum typeEnum, ResourceVersionInfo prevComponent) {
951 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), prevComponent);
954 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
955 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent) {
956 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, null, null, null);
959 public void auditComponent(ResponseFormat responseFormat, User modifier, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo,
961 auditComponent(responseFormat, modifier, null, actionEnum, resourceCommonInfo, ResourceVersionInfo.newBuilder().build(), null, comment, null,
965 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
966 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent) {
967 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, currComponent, null, null, null);
970 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
971 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent,
972 String comment, ArtifactDefinition artifactDefinition, String did) {
973 if (actionEnum != null) {
975 String currState = null;
976 String invariantUUID = null;
977 String currArtifactUid = null;
978 String currVersion = null;
979 String dcurrStatus = null;
980 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
981 String message = getMessageString(responseFormat);
982 int status = responseFormat.getStatus();
983 String artifactData = buildAuditingArtifactData(artifactDefinition);
984 if (component != null) {
985 // fields that are filled during creation and might still be empty
986 if (component.getLifecycleState() != null) {
987 currState = component.getLifecycleState().name();
989 uuid = component.getUUID();
990 invariantUUID = component.getInvariantUUID();
991 currVersion = component.getVersion();
992 if (StringUtils.isEmpty(resourceCommonInfo.getResourceName())) {
993 resourceCommonInfo.setResourceName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
996 if (currComponent != null) {
997 currArtifactUid = currComponent.getArtifactUuid();
998 dcurrStatus = currComponent.getDistributionStatus();
999 if (currState == null) { //probably it was not set
1000 currState = currComponent.getState();
1002 if (currVersion == null) { //probably it was not set
1003 currVersion = currComponent.getVersion();
1006 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(actionEnum,
1007 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(uuid)
1008 .build(), resourceCommonInfo, prevComponent,
1009 ResourceVersionInfo.newBuilder().artifactUuid(currArtifactUid).state(currState).version(currVersion).distributionStatus(dcurrStatus)
1010 .build(), invariantUUID, modifier, artifactData, comment, did, null);
1011 getAuditingManager().auditEvent(factory);
1015 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData,
1017 auditDistributionEngine(action, environmentName, distributionTopicData, null, null, status);
1020 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role,
1021 String apiKey, String status) {
1022 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1023 .createDistributionEngineEventFactory(action, environmentName, distributionTopicData, role, apiKey, status);
1024 getAuditingManager().auditEvent(factory);
1027 public void auditEnvironmentEngine(AuditingActionEnum actionEnum, String environmentID, String environmentType, String action,
1028 String environmentName, String tenantContext) {
1029 AuditEventFactory factory = new AuditEcompOpEnvEventFactory(actionEnum, environmentID, environmentName, environmentType, action,
1031 audit.startAuditFetchLog(PARTNER_NAME, DmaapConsumer.class.getName());
1032 audit.logEntry(LogLevel.INFO, Severity.OK, null, MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), environmentID);
1033 getAuditingManager().auditEvent(factory, audit);
1036 public void auditDistributionNotification(String serviceUUID, String resourceName, String resourceType, String currVersion, User modifier,
1037 String environmentName, String currState, String topicName, String distributionId, String description,
1038 String status, String workloadContext, String tenant) {
1039 AuditEventFactory factory = new AuditDistributionNotificationEventFactory(
1040 CommonAuditData.newBuilder().serviceInstanceId(serviceUUID).status(status).description(description)
1041 .requestId(ThreadLocalsHolder.getUuid()).build(), new ResourceCommonInfo(resourceName, resourceType),
1042 ResourceVersionInfo.newBuilder().state(currState).version(currVersion).build(), distributionId, modifier, topicName,
1043 new OperationalEnvAuditData(environmentName, workloadContext, tenant));
1044 getAuditingManager().auditEvent(factory);
1047 public void auditAuthEvent(String url, String user, String authStatus, String realm) {
1048 AuditEventFactory factory = new AuditAuthRequestEventFactory(CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).build(),
1049 user, url, realm, authStatus);
1050 getAuditingManager().auditEvent(factory);
1053 public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName, String resourceUrl, String statusTime,
1054 String status, String errorReason, LoggerSdcAudit audit) {
1055 AuditEventFactory factory = new AuditDistributionStatusEventFactory(
1056 CommonAuditData.newBuilder().description(errorReason).status(status).requestId(distributionId).build(),
1057 new DistributionData(consumerId, resourceUrl), distributionId, topicName, statusTime);
1058 getAuditingManager().auditEvent(factory, audit);
1061 public void auditGetUebCluster(String consumerId, String status, String description) {
1062 AuditEventFactory factory = new AuditGetUebClusterEventFactory(
1063 CommonAuditData.newBuilder().description(description).status(status).requestId(ThreadLocalsHolder.getUuid()).build(), consumerId);
1064 getAuditingManager().auditEvent(factory);
1067 public void auditMissingInstanceIdAsDistributionEngineEvent(AuditingActionEnum actionEnum, String status) {
1068 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1069 .createDistributionEngineEventFactory(actionEnum, "", DistributionTopicData.newBuilder().build(), null, null, status);
1070 getAuditingManager().auditEvent(factory);
1073 public void auditRegisterOrUnRegisterEvent(AuditingActionEnum action, String consumerId, String apiPublicKey, String envName, String status,
1074 String distributionStatus, String notifTopicName, String statusTopicName) {
1075 String appliedStatus = !StringUtils.isEmpty(status) ? status : distributionStatus;
1076 AuditEventFactory factory = new AuditRegUnregDistributionEngineEventFactory(action,
1077 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).status(appliedStatus).build(),
1078 DistributionTopicData.newBuilder().statusTopic(statusTopicName).notificationTopic(notifTopicName).build(), consumerId, apiPublicKey,
1080 getAuditingManager().auditEvent(factory);
1083 public void auditServiceDistributionDeployed(String serviceName, String serviceVersion, String serviceUUID, String distributionId, String status,
1084 String desc, User modifier) {
1085 AuditEventFactory factory = new AuditDistributionDeployEventFactory(
1086 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(serviceUUID).status(status).description(desc)
1087 .build(), new ResourceCommonInfo(serviceName, "Service"), distributionId, modifier, serviceVersion);
1088 getAuditingManager().auditEvent(factory);
1091 public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat,
1093 AuditEventFactory factory = new AuditConsumerEventFactory(actionEnum,
1094 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1095 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, consumer);
1096 getAuditingManager().auditEvent(factory);
1099 public void auditGetUsersList(User user, String details, ResponseFormat responseFormat) {
1100 AuditEventFactory factory = new AuditGetUsersListEventFactory(
1101 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1102 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1103 getAuditingManager().auditEvent(factory);
1106 public void auditAdminUserActionAndThrowException(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter,
1107 ActionStatus status, String... params) {
1108 ResponseFormat responseFormat = getResponseFormat(status, params);
1109 auditAdminUserAction(actionEnum, modifier, userBefore, userAfter, responseFormat);
1110 throw new ByResponseFormatComponentException(responseFormat);
1113 public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
1114 AuditEventFactory factory = new AuditUserAdminEventFactory(actionEnum,
1115 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1116 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, userBefore, userAfter);
1117 getAuditingManager().auditEvent(factory);
1120 public void auditUserAccess(User user, ActionStatus status, String... params) {
1121 auditUserAccess(user, getResponseFormat(status, params));
1124 public void auditUserAccess(User user, ResponseFormat responseFormat) {
1125 AuditEventFactory factory = new AuditUserAccessEventFactory(
1126 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1127 .requestId(ThreadLocalsHolder.getUuid()).build(), user);
1128 getAuditingManager().auditEvent(factory);
1131 public void auditGetCategoryHierarchy(User user, String details, ResponseFormat responseFormat) {
1132 AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(
1133 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1134 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1135 getAuditingManager().auditEvent(factory);
1138 public ResponseFormat getResponseFormatByComponent(ActionStatus actionStatus, Component component, ComponentTypeEnum type) {
1139 if (component == null) {
1140 return getResponseFormat(actionStatus);
1142 ResponseFormat responseFormat;
1143 switch (actionStatus) {
1144 case COMPONENT_VERSION_ALREADY_EXIST:
1145 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, type.getValue(), component.getVersion());
1147 case RESOURCE_NOT_FOUND:
1148 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND,
1149 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1151 case COMPONENT_NAME_ALREADY_EXIST:
1152 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(),
1153 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1155 case COMPONENT_IN_USE:
1156 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, type.name().toLowerCase(), component.getUniqueId());
1158 case SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND:
1159 responseFormat = getResponseFormat(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND,
1160 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1163 responseFormat = getResponseFormat(actionStatus);
1166 return responseFormat;
1169 public boolean validateStringNotEmpty(String value) {
1170 return value != null && !value.trim().isEmpty();
1173 public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
1174 ActionStatus responseEnum;
1175 switch (storageResponse) {
1177 responseEnum = ActionStatus.OK;
1179 case ENTITY_ALREADY_EXISTS:
1180 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
1183 responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
1186 responseEnum = ActionStatus.GENERAL_ERROR;
1189 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1190 return responseEnum;
1193 public ActionStatus convertFromResultStatusEnum(ResultStatusEnum resultStatus, JsonPresentationFields elementType) {
1194 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1195 switch (resultStatus) {
1197 responseEnum = ActionStatus.OK;
1199 case ELEMENT_NOT_FOUND:
1200 if (elementType == JsonPresentationFields.PROPERTY) {
1201 responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
1204 case INVALID_PROPERTY_DEFAULT_VALUE:
1205 case INVALID_PROPERTY_TYPE:
1206 case INVALID_PROPERTY_VALUE:
1207 case INVALID_PROPERTY_NAME:
1208 case MISSING_ENTRY_SCHEMA_TYPE:
1209 responseEnum = ActionStatus.INVALID_PROPERTY;
1211 case INVALID_ATTRIBUTE_NAME:
1212 responseEnum = ActionStatus.INVALID_ATTRIBUTE;
1217 return responseEnum;
1220 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus, AdditionalInfoParameterInfo additionalInfoParameterInfo,
1221 NodeTypeEnum nodeType, AdditionalInformationEnum labelOrValue) {
1222 if (additionalInfoParameterInfo == null) {
1223 additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
1225 if (labelOrValue == null) {
1226 labelOrValue = AdditionalInformationEnum.None;
1228 switch (actionStatus) {
1229 case COMPONENT_NAME_ALREADY_EXIST:
1230 return getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey());
1231 case ADDITIONAL_INFORMATION_EXCEEDS_LIMIT:
1232 return getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(),
1233 ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString());
1234 case ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED:
1235 return getResponseFormat(actionStatus, nodeType.name().toLowerCase());
1236 case ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED:
1237 return getResponseFormat(actionStatus);
1238 case ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS:
1239 return getResponseFormat(actionStatus);
1240 case ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS:
1241 return getResponseFormat(actionStatus);
1242 case ADDITIONAL_INFORMATION_NOT_FOUND:
1243 return getResponseFormat(actionStatus);
1245 return getResponseFormat(actionStatus);
1249 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus) {
1250 return getResponseFormatAdditionalProperty(actionStatus, null, null, null);
1253 public ActionStatus convertFromStorageResponseForConsumer(StorageOperationStatus storageResponse) {
1254 ActionStatus responseEnum;
1255 switch (storageResponse) {
1257 responseEnum = ActionStatus.OK;
1259 case CONNECTION_FAILURE:
1261 responseEnum = ActionStatus.GENERAL_ERROR;
1264 responseEnum = ActionStatus.INVALID_CONTENT;
1266 case ENTITY_ALREADY_EXISTS:
1267 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1269 case SCHEMA_VIOLATION:
1270 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1273 responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
1276 responseEnum = ActionStatus.GENERAL_ERROR;
1279 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1280 return responseEnum;
1283 public ActionStatus convertFromStorageResponseForGroupType(StorageOperationStatus storageResponse) {
1284 ActionStatus responseEnum;
1285 switch (storageResponse) {
1287 responseEnum = ActionStatus.OK;
1289 case CONNECTION_FAILURE:
1291 responseEnum = ActionStatus.GENERAL_ERROR;
1294 responseEnum = ActionStatus.INVALID_CONTENT;
1296 case ENTITY_ALREADY_EXISTS:
1297 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1299 case SCHEMA_VIOLATION:
1300 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1303 responseEnum = ActionStatus.GENERAL_ERROR;
1306 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1307 return responseEnum;
1310 public ActionStatus convertFromStorageResponseForPolicyType(StorageOperationStatus storageResponse) {
1311 ActionStatus responseEnum;
1312 switch (storageResponse) {
1314 responseEnum = ActionStatus.OK;
1316 case CONNECTION_FAILURE:
1318 responseEnum = ActionStatus.GENERAL_ERROR;
1321 responseEnum = ActionStatus.INVALID_CONTENT;
1323 case ENTITY_ALREADY_EXISTS:
1324 responseEnum = ActionStatus.POLICY_TYPE_ALREADY_EXIST;
1326 case SCHEMA_VIOLATION:
1327 responseEnum = ActionStatus.POLICY_TYPE_ALREADY_EXIST;
1330 responseEnum = ActionStatus.GENERAL_ERROR;
1333 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1334 return responseEnum;
1337 public ActionStatus convertFromStorageResponseForDataType(StorageOperationStatus storageResponse) {
1338 ActionStatus responseEnum;
1339 switch (storageResponse) {
1341 responseEnum = ActionStatus.OK;
1343 case CONNECTION_FAILURE:
1345 responseEnum = ActionStatus.GENERAL_ERROR;
1348 responseEnum = ActionStatus.INVALID_CONTENT;
1350 case ENTITY_ALREADY_EXISTS:
1351 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1353 case SCHEMA_VIOLATION:
1354 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1356 case CANNOT_UPDATE_EXISTING_ENTITY:
1357 responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
1360 responseEnum = ActionStatus.GENERAL_ERROR;
1363 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1364 return responseEnum;
1367 public ResponseFormat getResponseFormatByGroupType(ActionStatus actionStatus, GroupTypeDefinition groupType) {
1368 if (groupType == null) {
1369 return getResponseFormat(actionStatus);
1371 ResponseFormat responseFormat;
1372 switch (actionStatus) {
1373 case GROUP_MEMBER_EMPTY:
1374 case GROUP_TYPE_ALREADY_EXIST:
1375 responseFormat = getResponseFormat(actionStatus, groupType.getType());
1378 responseFormat = getResponseFormat(actionStatus);
1381 return responseFormat;
1384 public ResponseFormat getResponseFormatByPolicyType(ActionStatus actionStatus, PolicyTypeDefinition policyType) {
1385 if (policyType == null) {
1386 return getResponseFormat(actionStatus);
1388 ResponseFormat responseFormat;
1389 if (actionStatus == ActionStatus.POLICY_TYPE_ALREADY_EXIST) {
1390 responseFormat = getResponseFormat(actionStatus, policyType.getType());
1392 responseFormat = getResponseFormat(actionStatus);
1394 return responseFormat;
1397 public ResponseFormat getResponseFormatByDataType(ActionStatus actionStatus, DataTypeDefinition dataType, List<String> properties) {
1398 if (dataType == null) {
1399 return getResponseFormat(actionStatus);
1401 ResponseFormat responseFormat;
1402 switch (actionStatus) {
1403 case DATA_TYPE_ALREADY_EXIST:
1404 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1406 case DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM:
1407 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1409 case DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY:
1410 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1412 case DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR:
1413 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1415 case DATA_TYPE_DERIVED_IS_MISSING:
1416 responseFormat = getResponseFormat(actionStatus, dataType.getDerivedFromName());
1418 case DATA_TYPE_DUPLICATE_PROPERTY:
1419 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1421 case DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE:
1422 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1424 case DATA_TYPE_CANNOT_HAVE_PROPERTIES:
1425 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1427 case DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST:
1428 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1431 responseFormat = getResponseFormat(actionStatus);
1434 return responseFormat;
1437 public StorageOperationStatus convertToStorageOperationStatus(CassandraOperationStatus cassandraStatus) {
1438 StorageOperationStatus result;
1439 switch (cassandraStatus) {
1441 result = StorageOperationStatus.OK;
1444 result = StorageOperationStatus.NOT_FOUND;
1446 case CLUSTER_NOT_CONNECTED:
1447 case KEYSPACE_NOT_CONNECTED:
1448 result = StorageOperationStatus.CONNECTION_FAILURE;
1451 result = StorageOperationStatus.GENERAL_ERROR;
1457 public ResponseFormat getResponseFormat(ComponentException exception) {
1458 return exception instanceof ByResponseFormatComponentException ? getResponseFormat((ByResponseFormatComponentException) exception)
1459 : getResponseFormat((ByActionStatusComponentException) exception);
1462 public ResponseFormat getResponseFormat(ByResponseFormatComponentException exception) {
1463 return exception.getResponseFormat();
1466 public ResponseFormat getResponseFormat(ByActionStatusComponentException exception) {
1467 return getResponseFormat(exception.getActionStatus(), exception.getParams());
1470 public ActionStatus convertFromStorageResponseForRelationshipType(StorageOperationStatus storageResponse) {
1471 ActionStatus responseEnum;
1472 switch (storageResponse) {
1474 responseEnum = ActionStatus.OK;
1476 case CONNECTION_FAILURE:
1478 responseEnum = ActionStatus.GENERAL_ERROR;
1481 responseEnum = ActionStatus.INVALID_CONTENT;
1483 case ENTITY_ALREADY_EXISTS:
1484 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1486 case SCHEMA_VIOLATION:
1487 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1490 responseEnum = ActionStatus.GENERAL_ERROR;
1493 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1494 return responseEnum;
1497 public ResponseFormat getResponseFormat(StorageException exception) {
1498 ActionStatus status = convertFromStorageResponse(exception.getStorageOperationStatus());
1499 return getResponseFormat(status, exception.getParams());
1502 public List<UiLeftPaletteComponent> convertComponentToUiLeftPaletteComponentObject(List<Component> components) {
1503 List<UiLeftPaletteComponent> uiLeftPaletteComponents = new ArrayList<>();
1504 components.forEach(c -> uiLeftPaletteComponents.add(new UiLeftPaletteComponent(c)));
1505 return uiLeftPaletteComponents;
1508 public F<StorageOperationStatus, ResponseFormat> toResponseFormat() {
1509 return sos -> getResponseFormat(convertFromStorageResponse(sos));
1512 public Optional<UIConstraint> parseToConstraint(final String componentJson, final User user, final ComponentTypeEnum componentTypeEnum) {
1513 final Either<UIConstraint, ResponseFormat> uiConstraintResponseFormatEither = convertJsonToObjectUsingObjectMapper(componentJson, user,
1514 UIConstraint.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
1515 if (uiConstraintResponseFormatEither.isRight()) {
1516 return Optional.empty();
1518 return Optional.of(uiConstraintResponseFormatEither.left().value());
1521 private Either<List, ResponseFormat> parseToConstraints(final String componentJson, final User user, final ComponentTypeEnum componentTypeEnum) {
1522 return convertJsonToObjectUsingObjectMapper(componentJson, user, List.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
1525 public List<UIConstraint> validateAndParseConstraint(final ComponentTypeEnum componentTypeEnum, final String constraintData,
1526 final User userModifier) {
1527 final String FAILED_TO_PARSE_CONSTRAINT_DATA = "Failed to Parse Constraint Data {}";
1528 final Either<List, ResponseFormat> convertResponse = parseToConstraints(constraintData, userModifier, componentTypeEnum);
1529 if (convertResponse.isRight()) {
1530 log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData, convertResponse.right().value());
1531 return Collections.emptyList();
1533 final List<Map<String, String>> uiConstraintsMaps = (List<Map<String, String>>) convertResponse.left().value();
1534 if (uiConstraintsMaps == null) {
1535 log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData);
1536 return Collections.emptyList();
1538 return uiConstraintsMaps.stream().map(dataMap -> new ObjectMapper().convertValue(dataMap, UIConstraint.class))
1539 .collect(Collectors.toList());
1542 public Map<String, DataTypeDefinition> getAllDataTypes(final ApplicationDataTypeCache applicationDataTypeCache, final String model) {
1543 final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll(model);
1544 if (allDataTypes.isRight()) {
1545 final var operationStatus = allDataTypes.right().value();
1546 if (operationStatus == JanusGraphOperationStatus.NOT_FOUND) {
1547 BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", ErrorSeverity.ERROR);
1548 throw new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model);
1550 BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", ErrorSeverity.ERROR);
1551 throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
1554 return allDataTypes.left().value();
1557 public ActionStatus convertFromStorageResponseForArtifactType(final StorageOperationStatus storageResponse) {
1558 ActionStatus responseEnum;
1559 switch (storageResponse) {
1561 responseEnum = ActionStatus.OK;
1563 case CONNECTION_FAILURE:
1565 responseEnum = ActionStatus.GENERAL_ERROR;
1568 responseEnum = ActionStatus.INVALID_CONTENT;
1570 case ENTITY_ALREADY_EXISTS:
1571 responseEnum = ActionStatus.ARTIFACT_TYPE_ALREADY_EXIST;
1573 case SCHEMA_VIOLATION:
1574 responseEnum = ActionStatus.ARTIFACT_TYPE_ALREADY_EXIST;
1577 responseEnum = ActionStatus.GENERAL_ERROR;
1580 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1581 return responseEnum;