2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
22 package org.openecomp.sdc.be.impl;
24 import com.fasterxml.jackson.databind.DeserializationFeature;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import com.fasterxml.jackson.databind.module.SimpleModule;
27 import com.google.gson.Gson;
28 import com.google.gson.GsonBuilder;
29 import com.google.gson.reflect.TypeToken;
31 import fj.data.Either;
32 import java.lang.reflect.Type;
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
37 import java.util.Optional;
39 import java.util.stream.Collectors;
40 import javax.servlet.http.HttpServletRequest;
41 import org.apache.commons.collections.CollectionUtils;
42 import org.apache.commons.lang3.StringUtils;
43 import org.onap.logging.ref.slf4j.ONAPLogConstants;
44 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
45 import org.openecomp.sdc.be.auditing.impl.AuditAuthRequestEventFactory;
46 import org.openecomp.sdc.be.auditing.impl.AuditConsumerEventFactory;
47 import org.openecomp.sdc.be.auditing.impl.AuditEcompOpEnvEventFactory;
48 import org.openecomp.sdc.be.auditing.impl.AuditGetUebClusterEventFactory;
49 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
50 import org.openecomp.sdc.be.auditing.impl.category.AuditCategoryEventFactory;
51 import org.openecomp.sdc.be.auditing.impl.category.AuditGetCategoryHierarchyEventFactory;
52 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDeployEventFactory;
53 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDownloadEventFactory;
54 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionEngineEventFactoryManager;
55 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionNotificationEventFactory;
56 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionStatusEventFactory;
57 import org.openecomp.sdc.be.auditing.impl.distribution.AuditRegUnregDistributionEngineEventFactory;
58 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditActivateServiceExternalApiEventFactory;
59 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetExternalApiEventFactory;
60 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetListExternalApiEventFactory;
61 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditChangeLifecycleExternalApiEventFactory;
62 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateResourceExternalApiEventFactory;
63 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateServiceExternalApiEventFactory;
64 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCrudExternalApiArtifactEventFactory;
65 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditDownloadArtifactExternalApiEventFactory;
66 import org.openecomp.sdc.be.auditing.impl.resourceadmin.AuditResourceEventFactoryManager;
67 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditGetUsersListEventFactory;
68 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAccessEventFactory;
69 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAdminEventFactory;
70 import org.openecomp.sdc.be.components.distribution.engine.DmaapConsumer;
71 import org.openecomp.sdc.be.components.impl.ImportUtils;
72 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
73 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
74 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
75 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
76 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
77 import org.openecomp.sdc.be.config.BeEcompErrorManager;
78 import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
79 import org.openecomp.sdc.be.dao.api.ActionStatus;
80 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
81 import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
82 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
83 import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
84 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
85 import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
86 import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
87 import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionJsonDeserializer;
88 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
89 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
90 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
91 import org.openecomp.sdc.be.model.ArtifactDefinition;
92 import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
93 import org.openecomp.sdc.be.model.Component;
94 import org.openecomp.sdc.be.model.ComponentInstance;
95 import org.openecomp.sdc.be.model.ConsumerDefinition;
96 import org.openecomp.sdc.be.model.DataTypeDefinition;
97 import org.openecomp.sdc.be.model.GroupTypeDefinition;
98 import org.openecomp.sdc.be.model.LifecycleStateEnum;
99 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
100 import org.openecomp.sdc.be.model.PropertyConstraint;
101 import org.openecomp.sdc.be.model.RequirementDefinition;
102 import org.openecomp.sdc.be.model.Resource;
103 import org.openecomp.sdc.be.model.User;
104 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
105 import org.openecomp.sdc.be.model.operations.StorageException;
106 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
107 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
108 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserializer;
109 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
110 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
111 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
112 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
113 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
114 import org.openecomp.sdc.be.resources.data.auditing.model.OperationalEnvAuditData;
115 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
116 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
117 import org.openecomp.sdc.be.tosca.ToscaError;
118 import org.openecomp.sdc.be.ui.model.UIConstraint;
119 import org.openecomp.sdc.be.ui.model.UiLeftPaletteComponent;
120 import org.openecomp.sdc.common.api.Constants;
121 import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
122 import org.openecomp.sdc.common.log.enums.LogLevel;
123 import org.openecomp.sdc.common.log.enums.Severity;
124 import org.openecomp.sdc.common.log.wrappers.Logger;
125 import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
126 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
127 import org.openecomp.sdc.common.util.ValidationUtils;
128 import org.openecomp.sdc.exception.ResponseFormat;
129 import org.slf4j.MarkerFactory;
130 import org.springframework.beans.factory.annotation.Autowired;
132 @org.springframework.stereotype.Component("componentUtils")
133 public class ComponentsUtils {
135 private static final String CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE = "convert storage response {} to action response {}";
136 private static final String INSIDE_AUDITING_FOR_AUDIT_ACTION = "Inside auditing for audit action {}";
137 private static final String AUDIT_BEFORE_SENDING_RESPONSE = "audit before sending response";
138 private static final String CONVERT_JSON_TO_OBJECT = "convertJsonToObject";
139 private static final Logger log = Logger.getLogger(ComponentsUtils.class);
140 private static final String PARTNER_NAME = "UNKNOWN";
141 private static LoggerSdcAudit audit = new LoggerSdcAudit(DmaapConsumer.class);
142 private final AuditingManager auditingManager;
143 private final ResponseFormatManager responseFormatManager;
146 public ComponentsUtils(AuditingManager auditingManager) {
147 this.auditingManager = auditingManager;
148 this.responseFormatManager = ResponseFormatManager.getInstance();
151 public static <T> T parseJsonToObject(String data, Class<T> clazz) {
152 Type constraintType = new TypeToken<PropertyConstraint>() {
154 Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
155 log.trace("convert json to object. json=\n{}", data);
156 return gson.fromJson(data, clazz);
159 private static Set<String> getNodesFiltersToBeDeleted(final Component component, final String componentInstanceName) {
160 return component.getComponentInstances().stream().filter(ci -> isNodeFilterUsingChangedCi(ci, componentInstanceName))
161 .map(ComponentInstance::getName).collect(Collectors.toSet());
164 public static Set<String> getNodesFiltersToBeDeleted(final Component component, final ComponentInstance componentInstance) {
165 return getNodesFiltersToBeDeleted(component, componentInstance.getName());
168 private static boolean isNodeFilterUsingChangedCi(final ComponentInstance componentInstance, final String componentInstanceName) {
169 if (CollectionUtils.isEmpty(componentInstance.getDirectives())) {
172 if (componentInstance.getNodeFilter() == null || componentInstance.getNodeFilter().getProperties() == null
173 || componentInstance.getNodeFilter().getProperties().getListToscaDataDefinition() == null) {
176 return componentInstance.getNodeFilter().getProperties().getListToscaDataDefinition().stream()
177 .anyMatch(property -> isPropertyConstraintChangedByCi(property, componentInstanceName));
180 private static boolean isPropertyConstraintChangedByCi(
181 final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition, final String componentInstanceName) {
182 final List<String> constraints = requirementNodeFilterPropertyDataDefinition.getConstraints();
183 if (constraints == null) {
186 return constraints.stream().anyMatch(constraint -> isConstraintChangedByCi(constraint, componentInstanceName));
189 private static boolean isConstraintChangedByCi(final String constraint, final String componentInstanceName) {
190 final UIConstraint uiConstraint = new ConstraintConvertor().convert(constraint);
191 if (uiConstraint == null || uiConstraint.getSourceType() == null) {
194 if (!uiConstraint.getSourceType().equals(ConstraintConvertor.PROPERTY_CONSTRAINT)) {
197 return uiConstraint.getSourceName().equals(componentInstanceName);
200 public AuditingManager getAuditingManager() {
201 return auditingManager;
204 public <T> Either<T, ResponseFormat> convertJsonToObject(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum) {
206 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
207 log.debug("object is null after converting from json");
208 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
209 return Either.right(responseFormat);
212 T obj = parseJsonToObject(data, clazz);
213 return Either.left(obj);
214 } catch (Exception e) {
216 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
217 log.debug("failed to convert from json {}", data, e);
218 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
219 return Either.right(responseFormat);
223 public <T> Either<T, ResponseFormat> convertJsonToObjectUsingObjectMapper(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum,
224 ComponentTypeEnum typeEnum) {
226 ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
227 mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
228 mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
230 log.trace("convert json to object. json=\n{}", data);
231 SimpleModule module = new SimpleModule("customDeserializationModule");
232 module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
233 module.addDeserializer(ToscaFunction.class, new ToscaFunctionJsonDeserializer());
234 mapper.registerModule(module);
235 component = mapper.readValue(data, clazz);
236 if (component == null) {
237 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
238 log.debug("object is null after converting from json");
239 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
240 return Either.right(responseFormat);
242 } catch (Exception e) {
243 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
244 log.debug("failed to convert from json {}", data, e);
245 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
246 return Either.right(responseFormat);
248 return Either.left(component);
251 public ResponseFormat getResponseFormat(ActionStatus actionStatus, String... params) {
252 return responseFormatManager.getResponseFormat(actionStatus, params);
255 public ResponseFormat getResponseFormat(StorageOperationStatus storageStatus, String... params) {
256 return responseFormatManager.getResponseFormat(this.convertFromStorageResponse(storageStatus), params);
259 public <T> Either<List<T>, ResponseFormat> convertToResponseFormatOrNotFoundErrorToEmptyList(StorageOperationStatus storageOperationStatus) {
260 return storageOperationStatus.equals(StorageOperationStatus.NOT_FOUND) ? Either.left(Collections.emptyList())
261 : Either.right(getResponseFormat(storageOperationStatus));
265 * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus
266 * is anonymously converted from storage operation, and the caller doesn't know what actionStatus he received. It's caller's Responsibility to
267 * fill the resource object passed to this function with needed fields.
269 * Note that RESOURCE_IN_USE case passes hardcoded "resource" string to the error parameter. This means that if Resource object will also be used
270 * for Service, this code needs to be refactored and we should tell Resource from Service.
272 * @param actionStatus
276 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, Component resource) {
277 if (resource == null) {
278 return getResponseFormat(actionStatus);
280 ResponseFormat responseFormat;
281 switch (actionStatus) {
282 case COMPONENT_VERSION_ALREADY_EXIST:
283 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
284 resource.getVersion());
286 case RESOURCE_NOT_FOUND:
287 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resource.getName());
289 case COMPONENT_NAME_ALREADY_EXIST:
290 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
293 case COMPONENT_IN_USE:
294 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, ComponentTypeEnum.RESOURCE.name().toLowerCase(),
295 resource.getUniqueId());
298 responseFormat = getResponseFormat(actionStatus);
301 return responseFormat;
304 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, String resourceName) {
305 if (resourceName == null) {
306 return getResponseFormat(actionStatus);
308 ResponseFormat responseFormat;
309 if (actionStatus == ActionStatus.RESOURCE_NOT_FOUND) {
310 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceName);
312 responseFormat = getResponseFormat(actionStatus);
314 return responseFormat;
317 public ResponseFormat getResponseFormatByCapabilityType(ActionStatus actionStatus, CapabilityTypeDefinition capabilityType) {
318 if (capabilityType == null) {
319 return getResponseFormat(actionStatus);
321 ResponseFormat responseFormat;
322 if (actionStatus == ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST) {
323 responseFormat = getResponseFormat(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, capabilityType.getType());
325 responseFormat = getResponseFormat(actionStatus);
327 return responseFormat;
330 public <T> ResponseFormat getResponseFormatByElement(ActionStatus actionStatus, T obj) {
332 return getResponseFormat(actionStatus);
334 ResponseFormat responseFormat = null;
335 if (actionStatus == ActionStatus.MISSING_CAPABILITY_TYPE) {
336 if (obj instanceof List && org.apache.commons.collections.CollectionUtils.isNotEmpty((List) obj)) {
337 List list = (List) obj;
338 if (list.get(0) instanceof RequirementDefinition) {
339 responseFormat = getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, ((RequirementDefinition) list
340 .get(0)).getName()); //Arbitray index, all we need is single object
341 return responseFormat;
344 log.debug("UNKNOWN TYPE : expecting obj as a non empty List<RequirmentsDefinitions>");
346 responseFormat = getResponseFormat(actionStatus);
348 return responseFormat;
352 * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus
353 * is anynomously converted from storage operation, and the caller doesn't know what actionStatus he received. It's caller's responisibility to
354 * fill the passed resource object with needed fields.
356 * @param actionStatus
360 ResponseFormat getResponseFormatByUser(ActionStatus actionStatus, User user) {
362 return getResponseFormat(actionStatus);
364 ResponseFormat requestErrorWrapper;
365 switch (actionStatus) {
366 case INVALID_USER_ID:
367 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
369 case INVALID_EMAIL_ADDRESS:
370 requestErrorWrapper = getResponseFormat(actionStatus, user.getEmail());
373 requestErrorWrapper = getResponseFormat(actionStatus, user.getRole());
376 case USER_ALREADY_EXIST:
378 case USER_HAS_ACTIVE_ELEMENTS:
379 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
382 requestErrorWrapper = getResponseFormat(actionStatus);
385 return requestErrorWrapper;
388 public ResponseFormat getResponseFormatByUserId(ActionStatus actionStatus, String userId) {
389 User user = new User();
390 user.setUserId(userId);
391 return getResponseFormatByUser(actionStatus, user);
394 public ResponseFormat getResponseFormatByDE(ActionStatus actionStatus, String envName) {
395 ResponseFormat responseFormat;
396 switch (actionStatus) {
397 case DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE:
398 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE, envName);
400 case DISTRIBUTION_ENVIRONMENT_NOT_FOUND:
401 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND, envName);
404 responseFormat = getResponseFormat(actionStatus);
407 return responseFormat;
410 public ResponseFormat getResponseFormatByArtifactId(ActionStatus actionStatus, String... params) {
411 ResponseFormat responseFormat;
412 switch (actionStatus) {
413 case RESOURCE_NOT_FOUND:
414 case ARTIFACT_NOT_FOUND:
415 responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, params);
417 case ARTIFACT_NAME_INVALID:
418 responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NAME_INVALID, params);
421 responseFormat = getResponseFormat(actionStatus);
424 return responseFormat;
427 public ResponseFormat getInvalidContentErrorAndAudit(User user, AuditingActionEnum actionEnum) {
428 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
429 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
430 auditAdminUserAction(actionEnum, user, null, null, responseFormat);
431 return responseFormat;
434 public ResponseFormat getInvalidContentErrorAndAudit(User user, String resourceName, AuditingActionEnum actionEnum) {
435 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
436 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
437 auditResource(responseFormat, user, resourceName, actionEnum);
438 return responseFormat;
441 public ResponseFormat getInvalidContentErrorForConsumerAndAudit(User user, ConsumerDefinition consumer, AuditingActionEnum actionEnum) {
442 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
443 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
444 auditConsumerCredentialsEvent(actionEnum, consumer, responseFormat, user);
445 return responseFormat;
448 private ResponseFormat getInvalidContentErrorAndAuditComponent(User user, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
449 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
450 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
451 auditComponentAdmin(responseFormat, user, null, actionEnum, typeEnum);
452 return responseFormat;
455 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum,
456 ResourceVersionInfo prevResFields) {
457 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum, prevResFields, null, null);
460 public void auditResource(ResponseFormat responseFormat, User modifier, String resourceName, AuditingActionEnum actionEnum) {
461 auditResource(responseFormat, modifier, null, resourceName, actionEnum);
464 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum) {
465 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum);
468 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum) {
469 auditResource(responseFormat, modifier, resource, resourceName, actionEnum, ResourceVersionInfo.newBuilder().build(), null, null);
472 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum,
473 ResourceVersionInfo prevResFields, String currentArtifactUuid, ArtifactDefinition artifactDefinition) {
474 if (actionEnum != null) {
475 int status = responseFormat.getStatus();
477 String resourceCurrVersion = null;
478 String resourceCurrState = null;
479 String invariantUUID = null;
480 String resourceType = ComponentTypeEnum.RESOURCE.getValue();
481 String toscaNodeType = null;
482 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
483 String message = getMessageString(responseFormat);
484 String artifactData = buildAuditingArtifactData(artifactDefinition);
485 if (resource != null) {
486 resourceName = resource.getName();
487 resourceCurrVersion = resource.getVersion();
488 if (resource.getLifecycleState() != null) {
489 resourceCurrState = resource.getLifecycleState().name();
491 if (resource.getResourceType() != null) {
492 resourceType = resource.getResourceType().name();
494 invariantUUID = resource.getInvariantUUID();
495 uuid = resource.getUUID();
496 toscaNodeType = resource.getToscaResourceName();
498 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(actionEnum,
499 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(uuid)
500 .build(), new ResourceCommonInfo(resourceName, resourceType), prevResFields,
501 ResourceVersionInfo.newBuilder().artifactUuid(currentArtifactUuid).state(resourceCurrState).version(resourceCurrVersion).build(),
502 invariantUUID, modifier, artifactData, null, null, toscaNodeType);
503 getAuditingManager().auditEvent(factory);
507 private String getMessageString(ResponseFormat responseFormat) {
509 if (responseFormat.getMessageId() != null) {
510 message = responseFormat.getMessageId() + ": ";
512 message += responseFormat.getFormattedMessage();
516 public void auditDistributionDownload(ResponseFormat responseFormat, DistributionData distributionData) {
517 log.trace("Inside auditing");
518 int status = responseFormat.getStatus();
519 String message = getMessageString(responseFormat);
520 AuditDistributionDownloadEventFactory factory = new AuditDistributionDownloadEventFactory(
521 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).build(), distributionData);
522 getAuditingManager().auditEvent(factory);
525 public void auditExternalGetAsset(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
526 ResourceCommonInfo resourceCommonInfo, String requestId, String serviceInstanceId) {
527 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
528 AuditEventFactory factory = new AuditAssetExternalApiEventFactory(actionEnum,
529 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
530 .serviceInstanceId(serviceInstanceId).build(), resourceCommonInfo, distributionData);
531 getAuditingManager().auditEvent(factory);
534 public void auditExternalGetAssetList(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
536 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
537 AuditEventFactory factory = new AuditAssetListExternalApiEventFactory(actionEnum,
538 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
539 .build(), distributionData);
540 getAuditingManager().auditEvent(factory);
543 public void auditChangeLifecycleAction(ResponseFormat responseFormat, ComponentTypeEnum componentType, String requestId, Component component,
544 Component responseObject, DistributionData distributionData, User modifier) {
545 String invariantUuid = "";
546 String serviceInstanceId = "";
547 ResourceVersionInfo currResourceVersionInfo = null;
548 ResourceVersionInfo prevResourceVersionInfo = null;
549 ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
550 if (component != null) {
551 prevResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
552 resourceCommonInfo.setResourceName(component.getName());
554 if (responseObject != null) {
555 currResourceVersionInfo = buildResourceVersionInfoFromComponent(responseObject);
556 invariantUuid = responseObject.getInvariantUUID();
557 serviceInstanceId = responseObject.getUUID();
558 } else if (component != null) {
559 currResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
560 invariantUuid = component.getInvariantUUID();
561 serviceInstanceId = component.getUUID();
563 if (prevResourceVersionInfo == null) {
564 prevResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
566 if (currResourceVersionInfo == null) {
567 currResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
569 AuditEventFactory factory = new AuditChangeLifecycleExternalApiEventFactory(
570 CommonAuditData.newBuilder().serviceInstanceId(serviceInstanceId).requestId(requestId).description(getMessageString(responseFormat))
571 .status(responseFormat.getStatus()).build(), resourceCommonInfo, distributionData, prevResourceVersionInfo, currResourceVersionInfo,
572 invariantUuid, modifier);
573 getAuditingManager().auditEvent(factory);
576 private ResourceVersionInfo buildResourceVersionInfoFromComponent(Component component) {
577 return ResourceVersionInfo.newBuilder().version(component.getVersion()).state(component.getLifecycleState().name()).build();
580 public void auditExternalCrudApi(ResponseFormat responseFormat, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo,
581 HttpServletRequest request, ArtifactDefinition artifactDefinition, String artifactUuid) {
582 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
583 ResourceVersionInfo currResourceVersionInfo;
584 User modifier = new User();
585 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
586 String artifactData = "";
587 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
588 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
589 if (artifactDefinition == null) {
590 currResourceVersionInfo = ResourceVersionInfo.newBuilder().artifactUuid(artifactUuid).build();
592 currResourceVersionInfo = ResourceVersionInfo.newBuilder().artifactUuid(artifactDefinition.getArtifactUUID())
593 .version(artifactDefinition.getArtifactVersion()).build();
594 artifactData = buildAuditingArtifactData(artifactDefinition);
595 modifier.setUserId(artifactDefinition.getUserIdLastUpdater());
597 AuditEventFactory factory = new AuditCrudExternalApiArtifactEventFactory(actionEnum,
598 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
599 .build(), resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().build(), currResourceVersionInfo, null, modifier,
601 getAuditingManager().auditEvent(factory);
604 public boolean isExternalApiEvent(AuditingActionEnum auditingActionEnum) {
605 return auditingActionEnum != null && auditingActionEnum.getAuditingEsType().equals(AuditingTypesConstants.EXTERNAL_API_EVENT_TYPE);
608 public void auditCreateResourceExternalApi(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo, HttpServletRequest request,
610 String invariantUuid = null;
611 String serviceInstanceId = null;
612 User modifier = new User();
613 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
614 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
615 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
616 ResourceVersionInfo currResourceVersionInfo;
617 if (resource != null) {
618 currResourceVersionInfo = ResourceVersionInfo.newBuilder().state(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())
619 .version(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION).build();
620 resourceCommonInfo.setResourceName(resource.getName());
621 invariantUuid = resource.getInvariantUUID();
622 serviceInstanceId = resource.getUUID();
624 currResourceVersionInfo = ResourceVersionInfo.newBuilder().build();
626 AuditEventFactory factory = new AuditCreateResourceExternalApiEventFactory(
627 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
628 .serviceInstanceId(serviceInstanceId).build(), resourceCommonInfo, distributionData, currResourceVersionInfo, invariantUuid,
630 getAuditingManager().auditEvent(factory);
633 public void auditCreateServiceExternalApi(ResponseFormat responseFormat, HttpServletRequest request, Component service) {
634 String invariantUuid = null;
635 String serviceInstanceId = null;
636 User modifier = new User();
637 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
638 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
639 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
640 if (null != service) {
641 invariantUuid = service.getInvariantUUID();
642 serviceInstanceId = service.getUUID();
644 AuditEventFactory factory = new AuditCreateServiceExternalApiEventFactory(
645 CommonAuditData.newBuilder().status(responseFormat.getStatus()).description(getMessageString(responseFormat)).requestId(requestId)
646 .serviceInstanceId(serviceInstanceId).build(), new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()), distributionData,
647 invariantUuid, modifier);
648 getAuditingManager().auditEvent(factory);
651 public void auditExternalActivateService(ResponseFormat responseFormat, DistributionData distributionData, String requestId,
652 String serviceInstanceUuid, User modifier) {
653 AuditEventFactory factory = new AuditActivateServiceExternalApiEventFactory(
654 CommonAuditData.newBuilder().serviceInstanceId(serviceInstanceUuid).description(getMessageString(responseFormat))
655 .status(responseFormat.getStatus()).requestId(requestId).build(), new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()),
656 distributionData, "", modifier);
657 getAuditingManager().auditEvent(factory);
660 public void auditExternalDownloadArtifact(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo, DistributionData distributionData,
661 String requestId, String currArtifactUuid, String userId) {
662 User modifier = new User();
663 modifier.setUserId(userId);
664 AuditEventFactory factory = new AuditDownloadArtifactExternalApiEventFactory(
665 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus()).requestId(requestId)
666 .build(), resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().artifactUuid(currArtifactUuid).build(), modifier);
667 getAuditingManager().auditEvent(factory);
670 private String buildAuditingArtifactData(ArtifactDefinition artifactDefinition) {
671 StringBuilder sb = new StringBuilder();
672 if (artifactDefinition != null) {
673 sb.append(artifactDefinition.getArtifactGroupType().getType()).append(",").append("'").append(artifactDefinition.getArtifactLabel())
674 .append("'").append(",").append(artifactDefinition.getArtifactType()).append(",").append(artifactDefinition.getArtifactName())
675 .append(",").append(artifactDefinition.getTimeout()).append(",").append(artifactDefinition.getEsId());
677 sb.append(artifactDefinition.getArtifactVersion() != null ? artifactDefinition.getArtifactVersion() : " ");
679 sb.append(artifactDefinition.getArtifactUUID() != null ? artifactDefinition.getArtifactUUID() : " ");
681 return sb.toString();
684 public void auditCategory(ResponseFormat responseFormat, User modifier, String categoryName, String subCategoryName, String groupingName,
685 AuditingActionEnum actionEnum, String componentType) {
686 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
687 AuditEventFactory factory = new AuditCategoryEventFactory(actionEnum,
688 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
689 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, categoryName, subCategoryName, groupingName, componentType);
690 getAuditingManager().auditEvent(factory);
693 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse) {
694 return convertFromStorageResponse(storageResponse, ComponentTypeEnum.RESOURCE);
697 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse, ComponentTypeEnum type) {
698 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
699 if (storageResponse == null) {
702 switch (storageResponse) {
704 responseEnum = ActionStatus.OK;
706 case CONNECTION_FAILURE:
708 responseEnum = ActionStatus.GENERAL_ERROR;
711 responseEnum = ActionStatus.INVALID_CONTENT;
713 case ENTITY_ALREADY_EXISTS:
714 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
716 case PARENT_RESOURCE_NOT_FOUND:
717 responseEnum = ActionStatus.PARENT_RESOURCE_NOT_FOUND;
719 case MULTIPLE_PARENT_RESOURCE_FOUND:
720 responseEnum = ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND;
723 if (ComponentTypeEnum.RESOURCE == type) {
724 responseEnum = ActionStatus.RESOURCE_NOT_FOUND;
725 } else if (ComponentTypeEnum.PRODUCT == type) {
726 responseEnum = ActionStatus.PRODUCT_NOT_FOUND;
728 responseEnum = ActionStatus.SERVICE_NOT_FOUND;
731 case FAILED_TO_LOCK_ELEMENT:
732 responseEnum = ActionStatus.COMPONENT_IN_USE;
734 case ARTIFACT_NOT_FOUND:
735 responseEnum = ActionStatus.ARTIFACT_NOT_FOUND;
737 case DISTR_ENVIRONMENT_NOT_AVAILABLE:
738 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE;
740 case DISTR_ENVIRONMENT_NOT_FOUND:
741 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND;
743 case DISTR_ENVIRONMENT_SENT_IS_INVALID:
744 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID;
747 responseEnum = ActionStatus.INVALID_CONTENT;
750 responseEnum = ActionStatus.INVALID_CONTENT;
753 responseEnum = ActionStatus.CSAR_NOT_FOUND;
755 case PROPERTY_NAME_ALREADY_EXISTS:
756 responseEnum = ActionStatus.PROPERTY_NAME_ALREADY_EXISTS;
758 case MATCH_NOT_FOUND:
759 responseEnum = ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY;
761 case CATEGORY_NOT_FOUND:
762 responseEnum = ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;
764 case INVALID_PROPERTY:
765 responseEnum = ActionStatus.INVALID_PROPERTY;
767 case COMPONENT_IS_ARCHIVED:
768 responseEnum = ActionStatus.COMPONENT_IS_ARCHIVED;
770 case COMPONENT_NOT_ARCHIVED:
771 responseEnum = ActionStatus.COMPONENT_NOT_ARCHIVED;
773 case COMPONENT_IS_IN_USE:
774 responseEnum = ActionStatus.COMPONENT_IN_USE_BY_ANOTHER_COMPONENT;
776 case DECLARED_INPUT_USED_BY_OPERATION:
777 responseEnum = ActionStatus.DECLARED_INPUT_USED_BY_OPERATION;
780 responseEnum = ActionStatus.GENERAL_ERROR;
783 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
787 public ActionStatus convertFromToscaError(ToscaError toscaError) {
788 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
789 if (toscaError == null) {
792 switch (toscaError) {// TODO match errors
793 case NODE_TYPE_CAPABILITY_ERROR:
794 case NOT_SUPPORTED_TOSCA_TYPE:
795 case NODE_TYPE_REQUIREMENT_ERROR:
796 responseEnum = ActionStatus.INVALID_CONTENT;
799 responseEnum = ActionStatus.GENERAL_ERROR;
805 public ActionStatus convertFromStorageResponseForCapabilityType(StorageOperationStatus storageResponse) {
806 ActionStatus responseEnum;
807 switch (storageResponse) {
809 responseEnum = ActionStatus.OK;
811 case CONNECTION_FAILURE:
813 responseEnum = ActionStatus.GENERAL_ERROR;
816 responseEnum = ActionStatus.INVALID_CONTENT;
818 case ENTITY_ALREADY_EXISTS:
819 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
821 case SCHEMA_VIOLATION:
822 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
825 responseEnum = ActionStatus.GENERAL_ERROR;
828 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
832 public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
833 ActionStatus responseEnum;
834 switch (storageResponse) {
836 responseEnum = ActionStatus.OK;
838 case CONNECTION_FAILURE:
840 responseEnum = ActionStatus.GENERAL_ERROR;
843 responseEnum = ActionStatus.INVALID_CONTENT;
845 case ENTITY_ALREADY_EXISTS:
846 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
848 case SCHEMA_VIOLATION:
849 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
852 responseEnum = ActionStatus.GENERAL_ERROR;
855 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
859 public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
860 ActionStatus responseEnum;
861 switch (storageResponse) {
863 responseEnum = ActionStatus.OK;
866 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
868 case INVALID_PROPERTY:
869 responseEnum = ActionStatus.INVALID_PROPERTY;
872 responseEnum = ActionStatus.GENERAL_ERROR;
875 responseEnum = ActionStatus.INVALID_CONTENT;
877 case MATCH_NOT_FOUND:
878 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
880 case SCHEMA_VIOLATION:
881 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
885 responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
887 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
891 responseEnum = ActionStatus.GENERAL_ERROR;
894 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
898 public ResponseFormat getResponseFormatForResourceInstance(ActionStatus actionStatus, String serviceName, String resourceInstanceName) {
899 ResponseFormat responseFormat;
900 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
901 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
903 responseFormat = getResponseFormat(actionStatus, serviceName);
905 return responseFormat;
908 public ResponseFormat getResponseFormatForResourceInstanceProperty(ActionStatus actionStatus, String resourceInstanceName) {
909 ResponseFormat responseFormat;
910 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
911 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
913 responseFormat = getResponseFormat(actionStatus);
915 return responseFormat;
918 public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
919 ActionStatus responseEnum;
920 switch (storageResponse) {
922 responseEnum = ActionStatus.OK;
925 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
928 responseEnum = ActionStatus.GENERAL_ERROR;
931 responseEnum = ActionStatus.INVALID_CONTENT;
933 case MATCH_NOT_FOUND:
934 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
936 case SCHEMA_VIOLATION:
937 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
940 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
943 responseEnum = ActionStatus.GENERAL_ERROR;
946 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
950 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
951 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, String comment) {
952 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, comment, null, null);
955 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
956 ComponentTypeEnum typeEnum) {
957 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
958 ResourceVersionInfo.newBuilder().build());
961 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
962 ComponentTypeEnum typeEnum, String comment) {
963 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()),
964 ResourceVersionInfo.newBuilder().build(), null, comment, null, null);
967 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
968 ComponentTypeEnum typeEnum, ResourceVersionInfo prevComponent) {
969 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), prevComponent);
972 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
973 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent) {
974 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, null, null, null);
977 public void auditComponent(ResponseFormat responseFormat, User modifier, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo,
979 auditComponent(responseFormat, modifier, null, actionEnum, resourceCommonInfo, ResourceVersionInfo.newBuilder().build(), null, comment, null,
983 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
984 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent) {
985 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, currComponent, null, null, null);
988 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum,
989 ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent,
990 String comment, ArtifactDefinition artifactDefinition, String did) {
991 if (actionEnum != null) {
993 String currState = null;
994 String invariantUUID = null;
995 String currArtifactUid = null;
996 String currVersion = null;
997 String dcurrStatus = null;
998 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
999 String message = getMessageString(responseFormat);
1000 int status = responseFormat.getStatus();
1001 String artifactData = buildAuditingArtifactData(artifactDefinition);
1002 if (component != null) {
1003 // fields that are filled during creation and might still be empty
1004 if (component.getLifecycleState() != null) {
1005 currState = component.getLifecycleState().name();
1007 uuid = component.getUUID();
1008 invariantUUID = component.getInvariantUUID();
1009 currVersion = component.getVersion();
1010 if (StringUtils.isEmpty(resourceCommonInfo.getResourceName())) {
1011 resourceCommonInfo.setResourceName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1014 if (currComponent != null) {
1015 currArtifactUid = currComponent.getArtifactUuid();
1016 dcurrStatus = currComponent.getDistributionStatus();
1017 if (currState == null) { //probably it was not set
1018 currState = currComponent.getState();
1020 if (currVersion == null) { //probably it was not set
1021 currVersion = currComponent.getVersion();
1024 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(actionEnum,
1025 CommonAuditData.newBuilder().status(status).description(message).requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(uuid)
1026 .build(), resourceCommonInfo, prevComponent,
1027 ResourceVersionInfo.newBuilder().artifactUuid(currArtifactUid).state(currState).version(currVersion).distributionStatus(dcurrStatus)
1028 .build(), invariantUUID, modifier, artifactData, comment, did, null);
1029 getAuditingManager().auditEvent(factory);
1033 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData,
1035 auditDistributionEngine(action, environmentName, distributionTopicData, null, null, status);
1038 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role,
1039 String apiKey, String status) {
1040 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1041 .createDistributionEngineEventFactory(action, environmentName, distributionTopicData, role, apiKey, status);
1042 getAuditingManager().auditEvent(factory);
1045 public void auditEnvironmentEngine(AuditingActionEnum actionEnum, String environmentID, String environmentType, String action,
1046 String environmentName, String tenantContext) {
1047 AuditEventFactory factory = new AuditEcompOpEnvEventFactory(actionEnum, environmentID, environmentName, environmentType, action,
1049 audit.startAuditFetchLog(PARTNER_NAME, DmaapConsumer.class.getName());
1050 audit.logEntry(LogLevel.INFO, Severity.OK, null, MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), environmentID);
1051 getAuditingManager().auditEvent(factory, audit);
1054 public void auditDistributionNotification(String serviceUUID, String resourceName, String resourceType, String currVersion, User modifier,
1055 String environmentName, String currState, String topicName, String distributionId, String description,
1056 String status, String workloadContext, String tenant) {
1057 AuditEventFactory factory = new AuditDistributionNotificationEventFactory(
1058 CommonAuditData.newBuilder().serviceInstanceId(serviceUUID).status(status).description(description)
1059 .requestId(ThreadLocalsHolder.getUuid()).build(), new ResourceCommonInfo(resourceName, resourceType),
1060 ResourceVersionInfo.newBuilder().state(currState).version(currVersion).build(), distributionId, modifier, topicName,
1061 new OperationalEnvAuditData(environmentName, workloadContext, tenant));
1062 getAuditingManager().auditEvent(factory);
1065 public void auditAuthEvent(String url, String user, String authStatus, String realm) {
1066 AuditEventFactory factory = new AuditAuthRequestEventFactory(CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).build(),
1067 user, url, realm, authStatus);
1068 getAuditingManager().auditEvent(factory);
1071 public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName, String resourceUrl, String statusTime,
1072 String status, String errorReason, LoggerSdcAudit audit) {
1073 AuditEventFactory factory = new AuditDistributionStatusEventFactory(
1074 CommonAuditData.newBuilder().description(errorReason).status(status).requestId(distributionId).build(),
1075 new DistributionData(consumerId, resourceUrl), distributionId, topicName, statusTime);
1076 getAuditingManager().auditEvent(factory, audit);
1079 public void auditGetUebCluster(String consumerId, String status, String description) {
1080 AuditEventFactory factory = new AuditGetUebClusterEventFactory(
1081 CommonAuditData.newBuilder().description(description).status(status).requestId(ThreadLocalsHolder.getUuid()).build(), consumerId);
1082 getAuditingManager().auditEvent(factory);
1085 public void auditMissingInstanceIdAsDistributionEngineEvent(AuditingActionEnum actionEnum, String status) {
1086 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager
1087 .createDistributionEngineEventFactory(actionEnum, "", DistributionTopicData.newBuilder().build(), null, null, status);
1088 getAuditingManager().auditEvent(factory);
1091 public void auditRegisterOrUnRegisterEvent(AuditingActionEnum action, String consumerId, String apiPublicKey, String envName, String status,
1092 String distributionStatus, String notifTopicName, String statusTopicName) {
1093 String appliedStatus = !StringUtils.isEmpty(status) ? status : distributionStatus;
1094 AuditEventFactory factory = new AuditRegUnregDistributionEngineEventFactory(action,
1095 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).status(appliedStatus).build(),
1096 DistributionTopicData.newBuilder().statusTopic(statusTopicName).notificationTopic(notifTopicName).build(), consumerId, apiPublicKey,
1098 getAuditingManager().auditEvent(factory);
1101 public void auditServiceDistributionDeployed(String serviceName, String serviceVersion, String serviceUUID, String distributionId, String status,
1102 String desc, User modifier) {
1103 AuditEventFactory factory = new AuditDistributionDeployEventFactory(
1104 CommonAuditData.newBuilder().requestId(ThreadLocalsHolder.getUuid()).serviceInstanceId(serviceUUID).status(status).description(desc)
1105 .build(), new ResourceCommonInfo(serviceName, "Service"), distributionId, modifier, serviceVersion);
1106 getAuditingManager().auditEvent(factory);
1109 public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat,
1111 AuditEventFactory factory = new AuditConsumerEventFactory(actionEnum,
1112 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1113 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, consumer);
1114 getAuditingManager().auditEvent(factory);
1117 public void auditGetUsersList(User user, String details, ResponseFormat responseFormat) {
1118 AuditEventFactory factory = new AuditGetUsersListEventFactory(
1119 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1120 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1121 getAuditingManager().auditEvent(factory);
1124 public void auditAdminUserActionAndThrowException(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter,
1125 ActionStatus status, String... params) {
1126 ResponseFormat responseFormat = getResponseFormat(status, params);
1127 auditAdminUserAction(actionEnum, modifier, userBefore, userAfter, responseFormat);
1128 throw new ByResponseFormatComponentException(responseFormat);
1131 public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
1132 AuditEventFactory factory = new AuditUserAdminEventFactory(actionEnum,
1133 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1134 .requestId(ThreadLocalsHolder.getUuid()).build(), modifier, userBefore, userAfter);
1135 getAuditingManager().auditEvent(factory);
1138 public void auditUserAccess(User user, ActionStatus status, String... params) {
1139 auditUserAccess(user, getResponseFormat(status, params));
1142 public void auditUserAccess(User user, ResponseFormat responseFormat) {
1143 AuditEventFactory factory = new AuditUserAccessEventFactory(
1144 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1145 .requestId(ThreadLocalsHolder.getUuid()).build(), user);
1146 getAuditingManager().auditEvent(factory);
1149 public void auditGetCategoryHierarchy(User user, String details, ResponseFormat responseFormat) {
1150 AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(
1151 CommonAuditData.newBuilder().description(getMessageString(responseFormat)).status(responseFormat.getStatus())
1152 .requestId(ThreadLocalsHolder.getUuid()).build(), user, details);
1153 getAuditingManager().auditEvent(factory);
1156 public ResponseFormat getResponseFormatByComponent(ActionStatus actionStatus, Component component, ComponentTypeEnum type) {
1157 if (component == null) {
1158 return getResponseFormat(actionStatus);
1160 ResponseFormat responseFormat;
1161 switch (actionStatus) {
1162 case COMPONENT_VERSION_ALREADY_EXIST:
1163 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, type.getValue(), component.getVersion());
1165 case RESOURCE_NOT_FOUND:
1166 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND,
1167 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1169 case COMPONENT_NAME_ALREADY_EXIST:
1170 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(),
1171 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1173 case COMPONENT_IN_USE:
1174 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, type.name().toLowerCase(), component.getUniqueId());
1176 case SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND:
1177 responseFormat = getResponseFormat(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND,
1178 component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1181 responseFormat = getResponseFormat(actionStatus);
1184 return responseFormat;
1187 public boolean validateStringNotEmpty(String value) {
1188 return value != null && !value.trim().isEmpty();
1191 public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
1192 ActionStatus responseEnum;
1193 switch (storageResponse) {
1195 responseEnum = ActionStatus.OK;
1197 case ENTITY_ALREADY_EXISTS:
1198 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
1201 responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
1204 responseEnum = ActionStatus.GENERAL_ERROR;
1207 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1208 return responseEnum;
1211 public ActionStatus convertFromResultStatusEnum(ResultStatusEnum resultStatus, JsonPresentationFields elementType) {
1212 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1213 switch (resultStatus) {
1215 responseEnum = ActionStatus.OK;
1217 case ELEMENT_NOT_FOUND:
1218 if (elementType != null && elementType == JsonPresentationFields.PROPERTY) {
1219 responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
1222 case INVALID_PROPERTY_DEFAULT_VALUE:
1223 case INVALID_PROPERTY_TYPE:
1224 case INVALID_PROPERTY_VALUE:
1225 case INVALID_PROPERTY_NAME:
1226 case MISSING_ENTRY_SCHEMA_TYPE:
1227 responseEnum = ActionStatus.INVALID_PROPERTY;
1229 case INVALID_ATTRIBUTE_NAME:
1230 responseEnum = ActionStatus.INVALID_ATTRIBUTE;
1233 responseEnum = ActionStatus.GENERAL_ERROR;
1236 return responseEnum;
1239 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus, AdditionalInfoParameterInfo additionalInfoParameterInfo,
1240 NodeTypeEnum nodeType, AdditionalInformationEnum labelOrValue) {
1241 if (additionalInfoParameterInfo == null) {
1242 additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
1244 if (labelOrValue == null) {
1245 labelOrValue = AdditionalInformationEnum.None;
1247 switch (actionStatus) {
1248 case COMPONENT_NAME_ALREADY_EXIST:
1249 return getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey());
1250 case ADDITIONAL_INFORMATION_EXCEEDS_LIMIT:
1251 return getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(),
1252 ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString());
1253 case ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED:
1254 return getResponseFormat(actionStatus, nodeType.name().toLowerCase());
1255 case ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED:
1256 return getResponseFormat(actionStatus);
1257 case ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS:
1258 return getResponseFormat(actionStatus);
1259 case ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS:
1260 return getResponseFormat(actionStatus);
1261 case ADDITIONAL_INFORMATION_NOT_FOUND:
1262 return getResponseFormat(actionStatus);
1264 return getResponseFormat(actionStatus);
1268 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus) {
1269 return getResponseFormatAdditionalProperty(actionStatus, null, null, null);
1272 public ActionStatus convertFromStorageResponseForConsumer(StorageOperationStatus storageResponse) {
1273 ActionStatus responseEnum;
1274 switch (storageResponse) {
1276 responseEnum = ActionStatus.OK;
1278 case CONNECTION_FAILURE:
1280 responseEnum = ActionStatus.GENERAL_ERROR;
1283 responseEnum = ActionStatus.INVALID_CONTENT;
1285 case ENTITY_ALREADY_EXISTS:
1286 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1288 case SCHEMA_VIOLATION:
1289 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1292 responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
1295 responseEnum = ActionStatus.GENERAL_ERROR;
1298 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1299 return responseEnum;
1302 public ActionStatus convertFromStorageResponseForGroupType(StorageOperationStatus storageResponse) {
1303 ActionStatus responseEnum;
1304 switch (storageResponse) {
1306 responseEnum = ActionStatus.OK;
1308 case CONNECTION_FAILURE:
1310 responseEnum = ActionStatus.GENERAL_ERROR;
1313 responseEnum = ActionStatus.INVALID_CONTENT;
1315 case ENTITY_ALREADY_EXISTS:
1316 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1318 case SCHEMA_VIOLATION:
1319 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1322 responseEnum = ActionStatus.GENERAL_ERROR;
1325 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1326 return responseEnum;
1329 public ActionStatus convertFromStorageResponseForPolicyType(StorageOperationStatus storageResponse) {
1330 ActionStatus responseEnum;
1331 switch (storageResponse) {
1333 responseEnum = ActionStatus.OK;
1335 case CONNECTION_FAILURE:
1337 responseEnum = ActionStatus.GENERAL_ERROR;
1340 responseEnum = ActionStatus.INVALID_CONTENT;
1342 case ENTITY_ALREADY_EXISTS:
1343 responseEnum = ActionStatus.POLICY_TYPE_ALREADY_EXIST;
1345 case SCHEMA_VIOLATION:
1346 responseEnum = ActionStatus.POLICY_TYPE_ALREADY_EXIST;
1349 responseEnum = ActionStatus.GENERAL_ERROR;
1352 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1353 return responseEnum;
1356 public ActionStatus convertFromStorageResponseForDataType(StorageOperationStatus storageResponse) {
1357 ActionStatus responseEnum;
1358 switch (storageResponse) {
1360 responseEnum = ActionStatus.OK;
1362 case CONNECTION_FAILURE:
1364 responseEnum = ActionStatus.GENERAL_ERROR;
1367 responseEnum = ActionStatus.INVALID_CONTENT;
1369 case ENTITY_ALREADY_EXISTS:
1370 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1372 case SCHEMA_VIOLATION:
1373 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1375 case CANNOT_UPDATE_EXISTING_ENTITY:
1376 responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
1379 responseEnum = ActionStatus.GENERAL_ERROR;
1382 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1383 return responseEnum;
1386 public ResponseFormat getResponseFormatByGroupType(ActionStatus actionStatus, GroupTypeDefinition groupType) {
1387 if (groupType == null) {
1388 return getResponseFormat(actionStatus);
1390 ResponseFormat responseFormat;
1391 switch (actionStatus) {
1392 case GROUP_MEMBER_EMPTY:
1393 case GROUP_TYPE_ALREADY_EXIST:
1394 responseFormat = getResponseFormat(actionStatus, groupType.getType());
1397 responseFormat = getResponseFormat(actionStatus);
1400 return responseFormat;
1403 public ResponseFormat getResponseFormatByPolicyType(ActionStatus actionStatus, PolicyTypeDefinition policyType) {
1404 if (policyType == null) {
1405 return getResponseFormat(actionStatus);
1407 ResponseFormat responseFormat;
1408 if (actionStatus == ActionStatus.POLICY_TYPE_ALREADY_EXIST) {
1409 responseFormat = getResponseFormat(actionStatus, policyType.getType());
1411 responseFormat = getResponseFormat(actionStatus);
1413 return responseFormat;
1416 public ResponseFormat getResponseFormatByDataType(ActionStatus actionStatus, DataTypeDefinition dataType, List<String> properties) {
1417 if (dataType == null) {
1418 return getResponseFormat(actionStatus);
1420 ResponseFormat responseFormat;
1421 switch (actionStatus) {
1422 case DATA_TYPE_ALREADY_EXIST:
1423 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1425 case DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM:
1426 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1428 case DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY:
1429 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1431 case DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR:
1432 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1434 case DATA_TYPE_DERIVED_IS_MISSING:
1435 responseFormat = getResponseFormat(actionStatus, dataType.getDerivedFromName());
1437 case DATA_TYPE_DUPLICATE_PROPERTY:
1438 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1440 case DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE:
1441 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1443 case DATA_TYPE_CANNOT_HAVE_PROPERTIES:
1444 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1446 case DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST:
1447 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1450 responseFormat = getResponseFormat(actionStatus);
1453 return responseFormat;
1456 public StorageOperationStatus convertToStorageOperationStatus(CassandraOperationStatus cassandraStatus) {
1457 StorageOperationStatus result;
1458 switch (cassandraStatus) {
1460 result = StorageOperationStatus.OK;
1463 result = StorageOperationStatus.NOT_FOUND;
1465 case CLUSTER_NOT_CONNECTED:
1466 case KEYSPACE_NOT_CONNECTED:
1467 result = StorageOperationStatus.CONNECTION_FAILURE;
1470 result = StorageOperationStatus.GENERAL_ERROR;
1476 public ResponseFormat getResponseFormat(ComponentException exception) {
1477 return exception instanceof ByResponseFormatComponentException ? getResponseFormat((ByResponseFormatComponentException) exception)
1478 : getResponseFormat((ByActionStatusComponentException) exception);
1481 public ResponseFormat getResponseFormat(ByResponseFormatComponentException exception) {
1482 return exception.getResponseFormat();
1485 public ResponseFormat getResponseFormat(ByActionStatusComponentException exception) {
1486 return getResponseFormat(exception.getActionStatus(), exception.getParams());
1489 public ActionStatus convertFromStorageResponseForRelationshipType(StorageOperationStatus storageResponse) {
1490 ActionStatus responseEnum;
1491 switch (storageResponse) {
1493 responseEnum = ActionStatus.OK;
1495 case CONNECTION_FAILURE:
1497 responseEnum = ActionStatus.GENERAL_ERROR;
1500 responseEnum = ActionStatus.INVALID_CONTENT;
1502 case ENTITY_ALREADY_EXISTS:
1503 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1505 case SCHEMA_VIOLATION:
1506 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1509 responseEnum = ActionStatus.GENERAL_ERROR;
1512 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1513 return responseEnum;
1516 public ResponseFormat getResponseFormat(StorageException exception) {
1517 ActionStatus status = convertFromStorageResponse(exception.getStorageOperationStatus());
1518 return getResponseFormat(status, exception.getParams());
1521 public List<UiLeftPaletteComponent> convertComponentToUiLeftPaletteComponentObject(List<Component> components) {
1522 List<UiLeftPaletteComponent> uiLeftPaletteComponents = new ArrayList<>();
1523 components.forEach(c -> uiLeftPaletteComponents.add(new UiLeftPaletteComponent(c)));
1524 return uiLeftPaletteComponents;
1527 public F<StorageOperationStatus, ResponseFormat> toResponseFormat() {
1528 return sos -> getResponseFormat(convertFromStorageResponse(sos));
1531 public Optional<UIConstraint> parseToConstraint(final String componentJson, final User user, final ComponentTypeEnum componentTypeEnum) {
1532 final Either<UIConstraint, ResponseFormat> uiConstraintResponseFormatEither = convertJsonToObjectUsingObjectMapper(componentJson, user,
1533 UIConstraint.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
1534 if (uiConstraintResponseFormatEither.isRight()) {
1535 return Optional.empty();
1537 return Optional.of(uiConstraintResponseFormatEither.left().value());
1540 private Either<List, ResponseFormat> parseToConstraints(final String componentJson, final User user, final ComponentTypeEnum componentTypeEnum) {
1541 return convertJsonToObjectUsingObjectMapper(componentJson, user, List.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
1544 public List<UIConstraint> validateAndParseConstraint(final ComponentTypeEnum componentTypeEnum, final String constraintData,
1545 final User userModifier) {
1546 final String FAILED_TO_PARSE_CONSTRAINT_DATA = "Failed to Parse Constraint Data {}";
1547 final Either<List, ResponseFormat> convertResponse = parseToConstraints(constraintData, userModifier, componentTypeEnum);
1548 if (convertResponse.isRight()) {
1549 log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData, convertResponse.right().value());
1550 return Collections.emptyList();
1552 final List<Map<String, String>> uiConstraintsMaps = (List<Map<String, String>>) convertResponse.left().value();
1553 if (uiConstraintsMaps == null) {
1554 log.error(EcompLoggerErrorCode.DATA_ERROR, FAILED_TO_PARSE_CONSTRAINT_DATA, constraintData);
1555 return Collections.emptyList();
1557 return uiConstraintsMaps.stream().map(dataMap -> new com.fasterxml.jackson.databind.ObjectMapper().convertValue(dataMap, UIConstraint.class))
1558 .collect(Collectors.toList());
1561 public Map<String, DataTypeDefinition> getAllDataTypes(final ApplicationDataTypeCache applicationDataTypeCache, final String model) {
1562 final Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = applicationDataTypeCache.getAll(model);
1563 if (allDataTypes.isRight()) {
1564 final var operationStatus = allDataTypes.right().value();
1565 if (operationStatus == JanusGraphOperationStatus.NOT_FOUND) {
1566 BeEcompErrorManager.getInstance().logInternalDataError("FetchDataTypes", "Data types are not loaded", ErrorSeverity.ERROR);
1567 throw new ByActionStatusComponentException(ActionStatus.DATA_TYPES_NOT_LOADED, model);
1569 BeEcompErrorManager.getInstance().logInternalFlowError("FetchDataTypes", "Failed to fetch data types", ErrorSeverity.ERROR);
1570 throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
1573 return allDataTypes.left().value();
1576 public ActionStatus convertFromStorageResponseForArtifactType(final StorageOperationStatus storageResponse) {
1577 ActionStatus responseEnum;
1578 switch (storageResponse) {
1580 responseEnum = ActionStatus.OK;
1582 case CONNECTION_FAILURE:
1584 responseEnum = ActionStatus.GENERAL_ERROR;
1587 responseEnum = ActionStatus.INVALID_CONTENT;
1589 case ENTITY_ALREADY_EXISTS:
1590 responseEnum = ActionStatus.ARTIFACT_TYPE_ALREADY_EXIST;
1592 case SCHEMA_VIOLATION:
1593 responseEnum = ActionStatus.ARTIFACT_TYPE_ALREADY_EXIST;
1596 responseEnum = ActionStatus.GENERAL_ERROR;
1599 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1600 return responseEnum;