2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
22 package org.openecomp.sdc.be.impl;
24 import com.fasterxml.jackson.databind.DeserializationFeature;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.fasterxml.jackson.databind.module.SimpleModule;
27 import com.google.gson.Gson;
28 import com.google.gson.GsonBuilder;
29 import com.google.gson.reflect.TypeToken;
31 import fj.data.Either;
32 import java.lang.reflect.Type;
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
37 import java.util.Optional;
39 import java.util.stream.Collectors;
40 import javax.servlet.http.HttpServletRequest;
41 import org.apache.commons.collections.CollectionUtils;
42 import org.apache.commons.lang3.StringUtils;
43 import org.onap.logging.ref.slf4j.ONAPLogConstants;
44 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
45 import org.openecomp.sdc.be.auditing.impl.AuditAuthRequestEventFactory;
46 import org.openecomp.sdc.be.auditing.impl.AuditConsumerEventFactory;
47 import org.openecomp.sdc.be.auditing.impl.AuditEcompOpEnvEventFactory;
48 import org.openecomp.sdc.be.auditing.impl.AuditGetUebClusterEventFactory;
49 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
50 import org.openecomp.sdc.be.auditing.impl.category.AuditCategoryEventFactory;
51 import org.openecomp.sdc.be.auditing.impl.category.AuditGetCategoryHierarchyEventFactory;
52 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDeployEventFactory;
53 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDownloadEventFactory;
54 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionEngineEventFactoryManager;
55 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionNotificationEventFactory;
56 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionStatusEventFactory;
57 import org.openecomp.sdc.be.auditing.impl.distribution.AuditRegUnregDistributionEngineEventFactory;
58 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditActivateServiceExternalApiEventFactory;
59 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetExternalApiEventFactory;
60 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetListExternalApiEventFactory;
61 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditChangeLifecycleExternalApiEventFactory;
62 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateResourceExternalApiEventFactory;
63 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateServiceExternalApiEventFactory;
64 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCrudExternalApiArtifactEventFactory;
65 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditDownloadArtifactExternalApiEventFactory;
66 import org.openecomp.sdc.be.auditing.impl.resourceadmin.AuditResourceEventFactoryManager;
67 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditGetUsersListEventFactory;
68 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAccessEventFactory;
69 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAdminEventFactory;
70 import org.openecomp.sdc.be.components.distribution.engine.DmaapConsumer;
71 import org.openecomp.sdc.be.components.impl.ImportUtils;
72 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
73 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
74 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
75 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
76 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
77 import org.openecomp.sdc.be.config.BeEcompErrorManager;
78 import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
79 import org.openecomp.sdc.be.dao.api.ActionStatus;
80 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
81 import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
82 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
83 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
84 import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
85 import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionJsonDeserializer;
86 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
87 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
88 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
89 import org.openecomp.sdc.be.model.ArtifactDefinition;
90 import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
91 import org.openecomp.sdc.be.model.Component;
92 import org.openecomp.sdc.be.model.ComponentInstance;
93 import org.openecomp.sdc.be.model.ConsumerDefinition;
94 import org.openecomp.sdc.be.model.DataTypeDefinition;
95 import org.openecomp.sdc.be.model.GroupTypeDefinition;
96 import org.openecomp.sdc.be.model.LifecycleStateEnum;
97 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
98 import org.openecomp.sdc.be.model.PropertyConstraint;
99 import org.openecomp.sdc.be.model.RequirementDefinition;
100 import org.openecomp.sdc.be.model.Resource;
101 import org.openecomp.sdc.be.model.User;
102 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
103 import org.openecomp.sdc.be.model.operations.StorageException;
104 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
105 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
106 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserializer;
107 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
108 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
109 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
110 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
111 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
112 import org.openecomp.sdc.be.resources.data.auditing.model.OperationalEnvAuditData;
113 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
114 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
115 import org.openecomp.sdc.be.tosca.ToscaError;
116 import org.openecomp.sdc.be.ui.model.UIConstraint;
117 import org.openecomp.sdc.be.ui.model.UiLeftPaletteComponent;
118 import org.openecomp.sdc.common.api.Constants;
119 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
120 import org.openecomp.sdc.common.log.enums.LogLevel;
121 import org.openecomp.sdc.common.log.enums.Severity;
122 import org.openecomp.sdc.common.log.wrappers.Logger;
123 import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
124 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
125 import org.openecomp.sdc.common.util.ValidationUtils;
126 import org.openecomp.sdc.exception.ResponseFormat;
127 import org.slf4j.MarkerFactory;
128 import org.springframework.beans.factory.annotation.Autowired;
130 @org.springframework.stereotype.Component("componentUtils")
131 public class ComponentsUtils {
133 private static final String CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE = "convert storage response {} to action response {}";
134 private static final String INSIDE_AUDITING_FOR_AUDIT_ACTION = "Inside auditing for audit action {}";
135 private static final String AUDIT_BEFORE_SENDING_RESPONSE = "audit before sending response";
136 private static final String CONVERT_JSON_TO_OBJECT = "convertJsonToObject";
137 private static final Logger log = Logger.getLogger(ComponentsUtils.class);
138 private static final String PARTNER_NAME = "UNKNOWN";
139 private static final LoggerSdcAudit audit = new LoggerSdcAudit(DmaapConsumer.class);
140 private final AuditingManager auditingManager;
141 private final ResponseFormatManager responseFormatManager;
144 public ComponentsUtils(AuditingManager auditingManager) {
145 this.auditingManager = auditingManager;
146 this.responseFormatManager = ResponseFormatManager.getInstance();
149 public static <T> T parseJsonToObject(String data, Class<T> clazz) {
150 Type constraintType = new TypeToken<PropertyConstraint>() {
152 Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
153 log.trace("convert json to object. json=\n{}", data);
154 return gson.fromJson(data, clazz);
157 private static Set<String> getNodesFiltersToBeDeleted(final Component component, final String componentInstanceName) {
158 return component.getComponentInstances().stream().filter(ci -> isNodeFilterUsingChangedCi(ci, componentInstanceName))
159 .map(ComponentInstance::getName).collect(Collectors.toSet());
162 public static Set<String> getNodesFiltersToBeDeleted(final Component component, final ComponentInstance componentInstance) {
163 return getNodesFiltersToBeDeleted(component, componentInstance.getName());
166 private static boolean isNodeFilterUsingChangedCi(final ComponentInstance componentInstance, final String componentInstanceName) {
167 if (CollectionUtils.isEmpty(componentInstance.getDirectives())) {
170 if (componentInstance.getNodeFilter() == null || componentInstance.getNodeFilter().getProperties() == null
171 || componentInstance.getNodeFilter().getProperties().getListToscaDataDefinition() == null) {
174 return componentInstance.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
175 .anyMatch(property -> ServiceFilterUtils.isPropertyConstraintChangedByCi(property, componentInstanceName));
178 public AuditingManager getAuditingManager() {
179 return auditingManager;
182 public <T> Either<T, ResponseFormat> convertJsonToObject(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum) {
184 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
185 log.debug("object is null after converting from json");
186 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
187 return Either.right(responseFormat);
190 T obj = parseJsonToObject(data, clazz);
191 return Either.left(obj);
192 } catch (Exception e) {
194 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
195 log.debug("failed to convert from json {}", data, e);
196 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
197 return Either.right(responseFormat);
201 public <T> Either<T, ResponseFormat> convertJsonToObjectUsingObjectMapper(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum,
202 ComponentTypeEnum typeEnum) {
204 ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
205 mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
206 mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
208 log.trace("convert json to object. json=\n{}", data);
209 SimpleModule module = new SimpleModule("customDeserializationModule");
210 module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
211 module.addDeserializer(ToscaFunction.class, new ToscaFunctionJsonDeserializer());
212 mapper.registerModule(module);
213 component = mapper.readValue(data, clazz);
214 if (component == null) {
215 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
216 log.debug("object is null after converting from json");
217 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
218 return Either.right(responseFormat);
220 } catch (Exception e) {
221 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
222 log.debug("failed to convert from json {}", data, e);
223 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
224 return Either.right(responseFormat);
226 return Either.left(component);
229 public ResponseFormat getResponseFormat(ActionStatus actionStatus, String... params) {
230 return responseFormatManager.getResponseFormat(actionStatus, params);
233 public ResponseFormat getResponseFormat(StorageOperationStatus storageStatus, String... params) {
234 return responseFormatManager.getResponseFormat(this.convertFromStorageResponse(storageStatus), params);
237 public <T> Either<List<T>, ResponseFormat> convertToResponseFormatOrNotFoundErrorToEmptyList(StorageOperationStatus storageOperationStatus) {
238 return storageOperationStatus.equals(StorageOperationStatus.NOT_FOUND) ? Either.left(Collections.emptyList())
239 : Either.right(getResponseFormat(storageOperationStatus));
243 * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus
244 * is anonymously converted from storage operation, and the caller doesn't know what actionStatus he received. It's caller's Responsibility to
245 * fill the resource object passed to this function with needed fields.
247 * Note that RESOURCE_IN_USE case passes hardcoded "resource" string to the error parameter. This means that if Resource object will also be used
248 * for Service, this code needs to be refactored and we should tell Resource from Service.
250 * @param actionStatus
254 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, Component resource) {
255 if (resource == null) {
256 return getResponseFormat(actionStatus);
258 ResponseFormat responseFormat;
259 switch (actionStatus) {
260 case COMPONENT_VERSION_ALREADY_EXIST:
261 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
262 resource.getVersion());
264 case RESOURCE_NOT_FOUND:
265 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resource.getName());
267 case COMPONENT_NAME_ALREADY_EXIST:
268 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
271 case COMPONENT_IN_USE:
272 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, ComponentTypeEnum.RESOURCE.name().toLowerCase(),
273 resource.getUniqueId());
276 responseFormat = getResponseFormat(actionStatus);
279 return responseFormat;
282 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, String resourceName) {
283 if (resourceName == null) {
284 return getResponseFormat(actionStatus);
286 ResponseFormat responseFormat;
287 if (actionStatus == ActionStatus.RESOURCE_NOT_FOUND) {
288 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceName);
290 responseFormat = getResponseFormat(actionStatus);
292 return responseFormat;
295 public ResponseFormat getResponseFormatByCapabilityType(ActionStatus actionStatus, CapabilityTypeDefinition capabilityType) {
296 if (capabilityType == null) {
297 return getResponseFormat(actionStatus);
299 ResponseFormat responseFormat;
300 if (actionStatus == ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST) {
301 responseFormat = getResponseFormat(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, capabilityType.getType());
303 responseFormat = getResponseFormat(actionStatus);
305 return responseFormat;
308 public <T> ResponseFormat getResponseFormatByElement(ActionStatus actionStatus, T obj) {
310 return getResponseFormat(actionStatus);
312 ResponseFormat responseFormat = null;
313 if (actionStatus == ActionStatus.MISSING_CAPABILITY_TYPE) {
314 if (obj instanceof List && org.apache.commons.collections.CollectionUtils.isNotEmpty((List) obj)) {
315 List list = (List) obj;
316 if (list.get(0) instanceof RequirementDefinition) {
317 responseFormat = getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, ((RequirementDefinition) list
318 .get(0)).getName()); //Arbitray index, all we need is single object
319 return responseFormat;
322 log.debug("UNKNOWN TYPE : expecting obj as a non empty List<RequirmentsDefinitions>");
324 responseFormat = getResponseFormat(actionStatus);
326 return responseFormat;
330 * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus
331 * is anynomously converted from storage operation, and the caller doesn't know what actionStatus he received. It's caller's responisibility to
332 * fill the passed resource object with needed fields.
334 * @param actionStatus
338 ResponseFormat getResponseFormatByUser(ActionStatus actionStatus, User user) {
340 return getResponseFormat(actionStatus);
342 ResponseFormat requestErrorWrapper;
343 switch (actionStatus) {
344 case INVALID_USER_ID:
345 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
347 case INVALID_EMAIL_ADDRESS:
348 requestErrorWrapper = getResponseFormat(actionStatus, user.getEmail());
351 requestErrorWrapper = getResponseFormat(actionStatus, user.getRole());
354 case USER_ALREADY_EXIST:
356 case USER_HAS_ACTIVE_ELEMENTS:
357 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
360 requestErrorWrapper = getResponseFormat(actionStatus);
363 return requestErrorWrapper;
366 public ResponseFormat getResponseFormatByUserId(ActionStatus actionStatus, String userId) {
367 User user = new User();
368 user.setUserId(userId);
369 return getResponseFormatByUser(actionStatus, user);
372 public ResponseFormat getResponseFormatByDE(ActionStatus actionStatus, String envName) {
373 ResponseFormat responseFormat;
374 switch (actionStatus) {
375 case DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE:
376 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE, envName);
378 case DISTRIBUTION_ENVIRONMENT_NOT_FOUND:
379 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND, envName);
382 responseFormat = getResponseFormat(actionStatus);
385 return responseFormat;
388 public ResponseFormat getResponseFormatByArtifactId(ActionStatus actionStatus, String... params) {
389 ResponseFormat responseFormat;
390 switch (actionStatus) {
391 case RESOURCE_NOT_FOUND:
392 case ARTIFACT_NOT_FOUND:
393 responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, params);
395 case ARTIFACT_NAME_INVALID:
396 responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NAME_INVALID, params);
399 responseFormat = getResponseFormat(actionStatus);
402 return responseFormat;
405 public ResponseFormat getInvalidContentErrorAndAudit(User user, AuditingActionEnum actionEnum) {
406 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
407 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
408 auditAdminUserAction(actionEnum, user, null, null, responseFormat);
409 return responseFormat;
412 public ResponseFormat getInvalidContentErrorAndAudit(User user, String resourceName, AuditingActionEnum actionEnum) {
413 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
414 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
415 auditResource(responseFormat, user, resourceName, actionEnum);
416 return responseFormat;
419 public ResponseFormat getInvalidContentErrorForConsumerAndAudit(User user, ConsumerDefinition consumer, AuditingActionEnum actionEnum) {
420 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
421 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
422 auditConsumerCredentialsEvent(actionEnum, consumer, responseFormat, user);
423 return responseFormat;
426 private ResponseFormat getInvalidContentErrorAndAuditComponent(User user, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
427 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
428 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
429 auditComponentAdmin(responseFormat, user, null, actionEnum, typeEnum);
430 return responseFormat;
433 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum,
434 ResourceVersionInfo prevResFields) {
435 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum, prevResFields, null, null);
438 public void auditResource(ResponseFormat responseFormat, User modifier, String resourceName, AuditingActionEnum actionEnum) {
439 auditResource(responseFormat, modifier, null, resourceName, actionEnum);
442 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum) {
443 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum);
446 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum) {
447 auditResource(responseFormat, modifier, resource, resourceName, actionEnum, ResourceVersionInfo.newBuilder().build(), null, null);
450 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum,
451 ResourceVersionInfo prevResFields, String currentArtifactUuid, ArtifactDefinition artifactDefinition) {
452 if (actionEnum != null) {
453 int status = responseFormat.getStatus();
455 String resourceCurrVersion = null;
456 String resourceCurrState = null;
457 String invariantUUID = null;
458 String resourceType = ComponentTypeEnum.RESOURCE.getValue();
459 String toscaNodeType = null;
460 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
461 String message = getMessageString(responseFormat);
462 String artifactData = buildAuditingArtifactData(artifactDefinition);
463 if (resource != null) {
464 resourceName = resource.getName();
465 resourceCurrVersion = resource.getVersion();
466 if (resource.getLifecycleState() != null) {
467 resourceCurrState = resource.getLifecycleState().name();
469 if (resource.getResourceType() != null) {
470 resourceType = resource.getResourceType().name();
472 invariantUUID = resource.getInvariantUUID();
473 uuid = resource.getUUID();
474 toscaNodeType = resource.getToscaResourceName();
476 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(actionEnum,
477 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(uuid)
478 .build(), new ResourceCommonInfo(resourceName, resourceType), prevResFields,
479 ResourceVersionInfo.newBuilder().artifactUuid(currentArtifactUuid).state(resourceCurrState).version(resourceCurrVersion).build(),
480 invariantUUID, modifier, artifactData, null, null, toscaNodeType);
481 getAuditingManager().auditEvent(factory);
485 private String getMessageString(ResponseFormat responseFormat) {
487 if (responseFormat.getMessageId() != null) {
488 message = responseFormat.getMessageId() + ": ";
490 message += responseFormat.getFormattedMessage();
494 public void auditDistributionDownload(ResponseFormat responseFormat, DistributionData distributionData) {
495 log.trace("Inside auditing");
496 int status = responseFormat.getStatus();
497 String message = getMessageString(responseFormat);
498 AuditDistributionDownloadEventFactory factory = new AuditDistributionDownloadEventFactory(
499 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).build(), distributionData);
500 getAuditingManager().auditEvent(factory);
503 public void auditExternalGetAsset(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
504 ResourceCommonInfo resourceCommonInfo, String requestId, String serviceInstanceId) {
505 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
506 AuditEventFactory factory = new AuditAssetExternalApiEventFactory(actionEnum,
507 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
508 .serviceInstanceId(serviceInstanceId).build(), resourceCommonInfo, distributionData);
509 getAuditingManager().auditEvent(factory);
512 public void auditExternalGetAssetList(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
514 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
515 AuditEventFactory factory = new AuditAssetListExternalApiEventFactory(actionEnum,
516 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
517 .build(), distributionData);
518 getAuditingManager().auditEvent(factory);
521 public void auditChangeLifecycleAction(ResponseFormat responseFormat, ComponentTypeEnum componentType, String requestId, Component component,
522 Component responseObject, DistributionData distributionData, User modifier) {
523 String invariantUuid = "";
524 String serviceInstanceId = "";
525 ResourceVersionInfo currResourceVersionInfo = null;
526 ResourceVersionInfo prevResourceVersionInfo = null;
527 ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
528 if (component != null) {
529 prevResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
530 resourceCommonInfo.setResourceName(component.getName());
532 if (responseObject != null) {
533 currResourceVersionInfo = buildResourceVersionInfoFromComponent(responseObject);
534 invariantUuid = responseObject.getInvariantUUID();
535 serviceInstanceId = responseObject.getUUID();
536 } else if (component != null) {
537 currResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
538 invariantUuid = component.getInvariantUUID();
539 serviceInstanceId = component.getUUID();
541 if (prevResourceVersionInfo == null) {
542 prevResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
544 if (currResourceVersionInfo == null) {
545 currResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
547 AuditEventFactory factory = new AuditChangeLifecycleExternalApiEventFactory(
548 CommonAuditData.newBuilder().serviceInstanceId(serviceInstanceId).requestId(requestId).description(getMessageString(responseFormat))
549 .status(responseFormat.getStatus()).build(), resourceCommonInfo, distributionData, prevResourceVersionInfo, currResourceVersionInfo,
550 invariantUuid, modifier);
551 getAuditingManager().auditEvent(factory);
554 private ResourceVersionInfo buildResourceVersionInfoFromComponent(Component component) {
555 return ResourceVersionInfo.newBuilder().version(component.getVersion()).state(component.getLifecycleState().name()).build();
558 public void auditExternalCrudApi(ResponseFormat responseFormat, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo,
559 HttpServletRequest request, ArtifactDefinition artifactDefinition, String artifactUuid) {
560 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
561 ResourceVersionInfo currResourceVersionInfo;
562 User modifier = new User();
563 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
564 String artifactData = "";
565 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
566 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
567 if (artifactDefinition == null) {
568 currResourceVersionInfo = ResourceVersionInfo.newBuilder().artifactUuid(artifactUuid).build();
570 currResourceVersionInfo = ResourceVersionInfo.newBuilder().artifactUuid(artifactDefinition.getArtifactUUID())
571 .version(artifactDefinition.getArtifactVersion()).build();
572 artifactData = buildAuditingArtifactData(artifactDefinition);
573 modifier.setUserId(artifactDefinition.getUserIdLastUpdater());
575 AuditEventFactory factory = new AuditCrudExternalApiArtifactEventFactory(actionEnum,
576 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
577 .build(), resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().build(), currResourceVersionInfo, null, modifier,
579 getAuditingManager().auditEvent(factory);
582 public boolean isExternalApiEvent(AuditingActionEnum auditingActionEnum) {
583 return auditingActionEnum != null && auditingActionEnum.getAuditingEsType().equals(AuditingTypesConstants.EXTERNAL_API_EVENT_TYPE);
586 public void auditCreateResourceExternalApi(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo, HttpServletRequest request,
588 String invariantUuid = null;
589 String serviceInstanceId = null;
590 User modifier = new User();
591 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
592 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
593 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
594 ResourceVersionInfo currResourceVersionInfo;
595 if (resource != null) {
596 currResourceVersionInfo = ResourceVersionInfo.newBuilder().state(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())
597 .version(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION).build();
598 resourceCommonInfo.setResourceName(resource.getName());
599 invariantUuid = resource.getInvariantUUID();
600 serviceInstanceId = resource.getUUID();
602 currResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
604 AuditEventFactory factory = new AuditCreateResourceExternalApiEventFactory(
605 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
606 .serviceInstanceId(serviceInstanceId).build(), resourceCommonInfo, distributionData, currResourceVersionInfo, invariantUuid,
608 getAuditingManager().auditEvent(factory);
611 public void auditCreateServiceExternalApi(ResponseFormat responseFormat, HttpServletRequest request, Component service) {
612 String invariantUuid = null;
613 String serviceInstanceId = null;
614 User modifier = new User();
615 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
616 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
617 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
618 if (null != service) {
619 invariantUuid = service.getInvariantUUID();
620 serviceInstanceId = service.getUUID();
622 AuditEventFactory factory = new AuditCreateServiceExternalApiEventFactory(
623 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
624 .serviceInstanceId(serviceInstanceId).build(), new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()), distributionData,
625 invariantUuid, modifier);
626 getAuditingManager().auditEvent(factory);
629 public void auditExternalActivateService(ResponseFormat responseFormat, DistributionData distributionData, String requestId,
630 String serviceInstanceUuid, User modifier) {
631 AuditEventFactory factory = new AuditActivateServiceExternalApiEventFactory(
632 CommonAuditData.newBuilder().serviceInstanceId(serviceInstanceUuid).description(getMessageString(responseFormat))
633 .status(responseFormat.getStatus()).requestId(requestId).build(), new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()),
634 distributionData, "", modifier);
635 getAuditingManager().auditEvent(factory);
638 public void auditExternalDownloadArtifact(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo, DistributionData distributionData,
639 String requestId, String currArtifactUuid, String userId) {
640 User modifier = new User();
641 modifier.setUserId(userId);
642 AuditEventFactory factory = new AuditDownloadArtifactExternalApiEventFactory(
643 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus()).requestId(requestId)
644 .build(), resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().artifactUuid(currArtifactUuid).build(), modifier);
645 getAuditingManager().auditEvent(factory);
648 private String buildAuditingArtifactData(ArtifactDefinition artifactDefinition) {
649 StringBuilder sb = new StringBuilder();
650 if (artifactDefinition != null) {
651 sb.append(artifactDefinition.getArtifactGroupType().getType()).append(",").append("'").append(artifactDefinition.getArtifactLabel())
652 .append("'").append(",").append(artifactDefinition.getArtifactType()).append(",").append(artifactDefinition.getArtifactName())
653 .append(",").append(artifactDefinition.getTimeout()).append(",").append(artifactDefinition.getEsId());
655 sb.append(artifactDefinition.getArtifactVersion() != null ? artifactDefinition.getArtifactVersion() : " ");
657 sb.append(artifactDefinition.getArtifactUUID() != null ? artifactDefinition.getArtifactUUID() : " ");
659 return sb.toString();
662 public void auditCategory(ResponseFormat responseFormat, User modifier, String categoryName, String subCategoryName, String groupingName,
663 AuditingActionEnum actionEnum, String componentType) {
664 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
665 AuditEventFactory factory = new AuditCategoryEventFactory(actionEnum,
666 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
667 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, categoryName, subCategoryName, groupingName, componentType);
668 getAuditingManager().auditEvent(factory);
671 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse) {
672 return convertFromStorageResponse(storageResponse, ComponentTypeEnum.RESOURCE);
675 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse, ComponentTypeEnum type) {
676 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
677 if (storageResponse == null) {
680 switch (storageResponse) {
682 responseEnum = ActionStatus.OK;
684 case CONNECTION_FAILURE:
686 responseEnum = ActionStatus.GENERAL_ERROR;
689 responseEnum = ActionStatus.INVALID_CONTENT;
691 case ENTITY_ALREADY_EXISTS:
692 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
694 case PARENT_RESOURCE_NOT_FOUND:
695 responseEnum = ActionStatus.PARENT_RESOURCE_NOT_FOUND;
697 case MULTIPLE_PARENT_RESOURCE_FOUND:
698 responseEnum = ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND;
701 if (ComponentTypeEnum.RESOURCE == type) {
702 responseEnum = ActionStatus.RESOURCE_NOT_FOUND;
703 } else if (ComponentTypeEnum.PRODUCT == type) {
704 responseEnum = ActionStatus.PRODUCT_NOT_FOUND;
706 responseEnum = ActionStatus.SERVICE_NOT_FOUND;
709 case FAILED_TO_LOCK_ELEMENT:
710 responseEnum = ActionStatus.COMPONENT_IN_USE;
712 case ARTIFACT_NOT_FOUND:
713 responseEnum = ActionStatus.ARTIFACT_NOT_FOUND;
715 case DISTR_ENVIRONMENT_NOT_AVAILABLE:
716 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE;
718 case DISTR_ENVIRONMENT_NOT_FOUND:
719 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND;
721 case DISTR_ENVIRONMENT_SENT_IS_INVALID:
722 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID;
725 responseEnum = ActionStatus.INVALID_CONTENT;
728 responseEnum = ActionStatus.INVALID_CONTENT;
731 responseEnum = ActionStatus.CSAR_NOT_FOUND;
733 case PROPERTY_NAME_ALREADY_EXISTS:
734 responseEnum = ActionStatus.PROPERTY_NAME_ALREADY_EXISTS;
736 case MATCH_NOT_FOUND:
737 responseEnum = ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY;
739 case CATEGORY_NOT_FOUND:
740 responseEnum = ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;
742 case INVALID_PROPERTY:
743 responseEnum = ActionStatus.INVALID_PROPERTY;
745 case COMPONENT_IS_ARCHIVED:
746 responseEnum = ActionStatus.COMPONENT_IS_ARCHIVED;
748 case COMPONENT_NOT_ARCHIVED:
749 responseEnum = ActionStatus.COMPONENT_NOT_ARCHIVED;
751 case COMPONENT_IS_IN_USE:
752 responseEnum = ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT;
754 case DECLARED_INPUT_USED_BY_OPERATION:
755 responseEnum = ActionStatus.DECLARED_INPUT_USED_BY_OPERATION;
758 responseEnum = ActionStatus.GENERAL_ERROR;
761 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
765 public ActionStatus convertFromToscaError(ToscaError toscaError) {
766 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
767 if (toscaError == null) {
770 switch (toscaError) {// TODO match errors
771 case NODE_TYPE_CAPABILITY_ERROR:
772 case NOT_SUPPORTED_TOSCA_TYPE:
773 case NODE_TYPE_REQUIREMENT_ERROR:
774 responseEnum = ActionStatus.INVALID_CONTENT;
777 responseEnum = ActionStatus.GENERAL_ERROR;
783 public ActionStatus convertFromStorageResponseForCapabilityType(StorageOperationStatus storageResponse) {
784 ActionStatus responseEnum;
785 switch (storageResponse) {
787 responseEnum = ActionStatus.OK;
789 case CONNECTION_FAILURE:
791 responseEnum = ActionStatus.GENERAL_ERROR;
794 responseEnum = ActionStatus.INVALID_CONTENT;
796 case ENTITY_ALREADY_EXISTS:
797 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
799 case SCHEMA_VIOLATION:
800 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
803 responseEnum = ActionStatus.GENERAL_ERROR;
806 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
810 public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
811 ActionStatus responseEnum;
812 switch (storageResponse) {
814 responseEnum = ActionStatus.OK;
816 case CONNECTION_FAILURE:
818 responseEnum = ActionStatus.GENERAL_ERROR;
821 responseEnum = ActionStatus.INVALID_CONTENT;
823 case ENTITY_ALREADY_EXISTS:
824 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
826 case SCHEMA_VIOLATION:
827 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
830 responseEnum = ActionStatus.GENERAL_ERROR;
833 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
837 public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
838 ActionStatus responseEnum;
839 switch (storageResponse) {
841 responseEnum = ActionStatus.OK;
844 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
846 case INVALID_PROPERTY:
847 responseEnum = ActionStatus.INVALID_PROPERTY;
850 responseEnum = ActionStatus.GENERAL_ERROR;
853 responseEnum = ActionStatus.INVALID_CONTENT;
855 case MATCH_NOT_FOUND:
856 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
858 case SCHEMA_VIOLATION:
859 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
863 responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
865 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
869 responseEnum = ActionStatus.GENERAL_ERROR;
872 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
876 public ResponseFormat getResponseFormatForResourceInstance(ActionStatus actionStatus, String serviceName, String resourceInstanceName) {
877 ResponseFormat responseFormat;
878 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
879 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
881 responseFormat = getResponseFormat(actionStatus, serviceName);
883 return responseFormat;
886 public ResponseFormat getResponseFormatForResourceInstanceProperty(ActionStatus actionStatus, String resourceInstanceName) {
887 ResponseFormat responseFormat;
888 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
889 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
891 responseFormat = getResponseFormat(actionStatus);
893 return responseFormat;
896 public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
897 ActionStatus responseEnum;
898 switch (storageResponse) {
900 responseEnum = ActionStatus.OK;
903 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
906 responseEnum = ActionStatus.GENERAL_ERROR;
909 responseEnum = ActionStatus.INVALID_CONTENT;
911 case MATCH_NOT_FOUND:
912 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
914 case SCHEMA_VIOLATION:
915 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
918 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
921 responseEnum = ActionStatus.GENERAL_ERROR;
924 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
928 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
929 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, String comment) {
930 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, comment, null, null);
933 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
934 ComponentTypeEnum typeEnum) {
935 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
936 ResourceVersionInfo.newBuilder().build());
939 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
940 ComponentTypeEnum typeEnum, String comment) {
941 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
942 ResourceVersionInfo.newBuilder().build(), null, comment, null, null);
945 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
946 ComponentTypeEnum typeEnum, ResourceVersionInfo prevComponent) {
947 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), prevComponent);
950 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
951 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent) {
952 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, null, null, null);
955 public void auditComponent(ResponseFormat responseFormat, User modifier, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo,
957 auditComponent(responseFormat, modifier, null, actionEnum, resourceCommonInfo, ResourceVersionInfo.newBuilder().build(), null, comment, null,
961 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
962 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent) {
963 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, currComponent, null, null, null);
966 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
967 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent,
968 String comment, ArtifactDefinition artifactDefinition, String did) {
969 if (actionEnum != null) {
971 String currState = null;
972 String invariantUUID = null;
973 String currArtifactUid = null;
974 String currVersion = null;
975 String dcurrStatus = null;
976 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
977 String message = getMessageString(responseFormat);
978 int status = responseFormat.getStatus();
979 String artifactData = buildAuditingArtifactData(artifactDefinition);
980 if (component != null) {
981 // fields that are filled during creation and might still be empty
982 if (component.getLifecycleState() != null) {
983 currState = component.getLifecycleState().name();
985 uuid = component.getUUID();
986 invariantUUID = component.getInvariantUUID();
987 currVersion = component.getVersion();
988 if (StringUtils.isEmpty(resourceCommonInfo.getResourceName())) {
989 resourceCommonInfo.setResourceName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
992 if (currComponent != null) {
993 currArtifactUid = currComponent.getArtifactUuid();
994 dcurrStatus = currComponent.getDistributionStatus();
995 if (currState == null) { //probably it was not set
996 currState = currComponent.getState();
998 if (currVersion == null) { //probably it was not set
999 currVersion = currComponent.getVersion();
1002 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(actionEnum,
1003 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(uuid)
1004 .build(), resourceCommonInfo, prevComponent,
1005 ResourceVersionInfo.newBuilder().artifactUuid(currArtifactUid).state(currState).version(currVersion).distributionStatus(dcurrStatus)
1006 .build(), invariantUUID, modifier, artifactData, comment, did, null);
1007 getAuditingManager().auditEvent(factory);
1011 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData,
1013 auditDistributionEngine(action, environmentName, distributionTopicData, null, null, status);
1016 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role,
1017 String apiKey, String status) {
1018 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1019 .createDistributionEngineEventFactory(action, environmentName, distributionTopicData, role, apiKey, status);
1020 getAuditingManager().auditEvent(factory);
1023 public void auditEnvironmentEngine(AuditingActionEnum actionEnum, String environmentID, String environmentType, String action,
1024 String environmentName, String tenantContext) {
1025 AuditEventFactory factory = new AuditEcompOpEnvEventFactory(actionEnum, environmentID, environmentName, environmentType, action,
1027 audit.startAuditFetchLog(PARTNER_NAME, DmaapConsumer.class.getName());
1028 audit.logEntry(LogLevel.INFO, Severity.OK, null, MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), environmentID);
1029 getAuditingManager().auditEvent(factory, audit);
1032 public void auditDistributionNotification(String serviceUUID, String resourceName, String resourceType, String currVersion, User modifier,
1033 String environmentName, String currState, String topicName, String distributionId, String description,
1034 String status, String workloadContext, String tenant) {
1035 AuditEventFactory factory = new AuditDistributionNotificationEventFactory(
1036 CommonAuditData.newBuilder().serviceInstanceId(serviceUUID).status(status).description(description)
1037 .requestId(ThreadLocalsHolder.getUuid()).build(), new ResourceCommonInfo(resourceName, resourceType),
1038 ResourceVersionInfo.newBuilder().state(currState).version(currVersion).build(), distributionId, modifier, topicName,
1039 new OperationalEnvAuditData(environmentName, workloadContext, tenant));
1040 getAuditingManager().auditEvent(factory);
1043 public void auditAuthEvent(String url, String user, String authStatus, String realm) {
1044 AuditEventFactory factory = new AuditAuthRequestEventFactory(CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).build(),
1045 user, url, realm, authStatus);
1046 getAuditingManager().auditEvent(factory);
1049 public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName, String resourceUrl, String statusTime,
1050 String status, String errorReason, LoggerSdcAudit audit) {
1051 AuditEventFactory factory = new AuditDistributionStatusEventFactory(
1052 CommonAuditData.newBuilder().description(errorReason).status(status).requestId(distributionId).build(),
1053 new DistributionData(consumerId, resourceUrl), distributionId, topicName, statusTime);
1054 getAuditingManager().auditEvent(factory, audit);
1057 public void auditGetUebCluster(String consumerId, String status, String description) {
1058 AuditEventFactory factory = new AuditGetUebClusterEventFactory(
1059 CommonAuditData.newBuilder().description(description).status(status).requestId(ThreadLocalsHolder.getUuid()).build(), consumerId);
1060 getAuditingManager().auditEvent(factory);
1063 public void auditMissingInstanceIdAsDistributionEngineEvent(AuditingActionEnum actionEnum, String status) {
1064 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1065 .createDistributionEngineEventFactory(actionEnum, "", DistributionTopicData.newBuilder().build(), null, null, status);
1066 getAuditingManager().auditEvent(factory);
1069 public void auditRegisterOrUnRegisterEvent(AuditingActionEnum action, String consumerId, String apiPublicKey, String envName, String status,
1070 String distributionStatus, String notifTopicName, String statusTopicName) {
1071 String appliedStatus = !StringUtils.isEmpty(status) ? status : distributionStatus;
1072 AuditEventFactory factory = new AuditRegUnregDistributionEngineEventFactory(action,
1073 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).status(appliedStatus).build(),
1074 DistributionTopicData.newBuilder().statusTopic(statusTopicName).notificationTopic(notifTopicName).build(), consumerId, apiPublicKey,
1076 getAuditingManager().auditEvent(factory);
1079 public void auditServiceDistributionDeployed(String serviceName, String serviceVersion, String serviceUUID, String distributionId, String status,
1080 String desc, User modifier) {
1081 AuditEventFactory factory = new AuditDistributionDeployEventFactory(
1082 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(serviceUUID).status(status).description(desc)
1083 .build(), new ResourceCommonInfo(serviceName, "Service"), distributionId, modifier, serviceVersion);
1084 getAuditingManager().auditEvent(factory);
1087 public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat,
1089 AuditEventFactory factory = new AuditConsumerEventFactory(actionEnum,
1090 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1091 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, consumer);
1092 getAuditingManager().auditEvent(factory);
1095 public void auditGetUsersList(User user, String details, ResponseFormat responseFormat) {
1096 AuditEventFactory factory = new AuditGetUsersListEventFactory(
1097 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1098 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1099 getAuditingManager().auditEvent(factory);
1102 public void auditAdminUserActionAndThrowException(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter,
1103 ActionStatus status, String... params) {
1104 ResponseFormat responseFormat = getResponseFormat(status, params);
1105 auditAdminUserAction(actionEnum, modifier, userBefore, userAfter, responseFormat);
1106 throw new ByResponseFormatComponentException(responseFormat);
1109 public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
1110 AuditEventFactory factory = new AuditUserAdminEventFactory(actionEnum,
1111 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1112 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, userBefore, userAfter);
1113 getAuditingManager().auditEvent(factory);
1116 public void auditUserAccess(User user, ActionStatus status, String... params) {
1117 auditUserAccess(user, getResponseFormat(status, params));
1120 public void auditUserAccess(User user, ResponseFormat responseFormat) {
1121 AuditEventFactory factory = new AuditUserAccessEventFactory(
1122 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1123 .requestId(ThreadLocalsHolder.getUuid()).build(), user);
1124 getAuditingManager().auditEvent(factory);
1127 public void auditGetCategoryHierarchy(User user, String details, ResponseFormat responseFormat) {
1128 AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(
1129 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1130 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1131 getAuditingManager().auditEvent(factory);
1134 public ResponseFormat getResponseFormatByComponent(ActionStatus actionStatus, Component component, ComponentTypeEnum type) {
1135 if (component == null) {
1136 return getResponseFormat(actionStatus);
1138 ResponseFormat responseFormat;
1139 switch (actionStatus) {
1140 case COMPONENT_VERSION_ALREADY_EXIST:
1141 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, type.getValue(), component.getVersion());
1143 case RESOURCE_NOT_FOUND:
1144 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND,
1145 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1147 case COMPONENT_NAME_ALREADY_EXIST:
1148 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(),
1149 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1151 case COMPONENT_IN_USE:
1152 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, type.name().toLowerCase(), component.getUniqueId());
1154 case SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND:
1155 responseFormat = getResponseFormat(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND,
1156 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1159 responseFormat = getResponseFormat(actionStatus);
1162 return responseFormat;
1165 public boolean validateStringNotEmpty(String value) {
1166 return value != null && !value.trim().isEmpty();
1169 public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
1170 ActionStatus responseEnum;
1171 switch (storageResponse) {
1173 responseEnum = ActionStatus.OK;
1175 case ENTITY_ALREADY_EXISTS:
1176 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
1179 responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
1182 responseEnum = ActionStatus.GENERAL_ERROR;
1185 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1186 return responseEnum;
1189 public ActionStatus convertFromResultStatusEnum(ResultStatusEnum resultStatus, JsonPresentationFields elementType) {
1190 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1191 switch (resultStatus) {
1193 responseEnum = ActionStatus.OK;
1195 case ELEMENT_NOT_FOUND:
1196 if (elementType != null && elementType == JsonPresentationFields.PROPERTY) {
1197 responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
1200 case INVALID_PROPERTY_DEFAULT_VALUE:
1201 case INVALID_PROPERTY_TYPE:
1202 case INVALID_PROPERTY_VALUE:
1203 case INVALID_PROPERTY_NAME:
1204 case MISSING_ENTRY_SCHEMA_TYPE:
1205 responseEnum = ActionStatus.INVALID_PROPERTY;
1207 case INVALID_ATTRIBUTE_NAME:
1208 responseEnum = ActionStatus.INVALID_ATTRIBUTE;
1211 responseEnum = ActionStatus.GENERAL_ERROR;
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;