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 * ================================================================================
23 package org.openecomp.sdc.be.impl;
25 import com.fasterxml.jackson.databind.DeserializationFeature;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.fasterxml.jackson.databind.module.SimpleModule;
28 import com.google.gson.Gson;
29 import com.google.gson.GsonBuilder;
30 import com.google.gson.reflect.TypeToken;
31 import fj.data.Either;
32 import org.apache.commons.lang3.StringUtils;
33 import org.onap.logging.ref.slf4j.ONAPLogConstants;
34 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
35 import org.openecomp.sdc.be.auditing.impl.AuditAuthRequestEventFactory;
36 import org.openecomp.sdc.be.auditing.impl.AuditConsumerEventFactory;
37 import org.openecomp.sdc.be.auditing.impl.AuditEcompOpEnvEventFactory;
38 import org.openecomp.sdc.be.auditing.impl.AuditGetUebClusterEventFactory;
39 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
40 import org.openecomp.sdc.be.auditing.impl.category.AuditCategoryEventFactory;
41 import org.openecomp.sdc.be.auditing.impl.category.AuditGetCategoryHierarchyEventFactory;
42 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDeployEventFactory;
43 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionDownloadEventFactory;
44 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionEngineEventFactoryManager;
45 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionNotificationEventFactory;
46 import org.openecomp.sdc.be.auditing.impl.distribution.AuditDistributionStatusEventFactory;
47 import org.openecomp.sdc.be.auditing.impl.distribution.AuditRegUnregDistributionEngineEventFactory;
48 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditActivateServiceExternalApiEventFactory;
49 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetExternalApiEventFactory;
50 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditAssetListExternalApiEventFactory;
51 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditChangeLifecycleExternalApiEventFactory;
52 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateResourceExternalApiEventFactory;
53 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCreateServiceExternalApiEventFactory;
54 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditCrudExternalApiArtifactEventFactory;
55 import org.openecomp.sdc.be.auditing.impl.externalapi.AuditDownloadArtifactExternalApiEventFactory;
56 import org.openecomp.sdc.be.auditing.impl.resourceadmin.AuditResourceEventFactoryManager;
57 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditGetUsersListEventFactory;
58 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAccessEventFactory;
59 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAdminEventFactory;
60 import org.openecomp.sdc.be.components.distribution.engine.DmaapConsumer;
61 import org.openecomp.sdc.be.components.impl.ImportUtils;
62 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
63 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
64 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
65 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
66 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
67 import org.openecomp.sdc.be.config.BeEcompErrorManager;
68 import org.openecomp.sdc.be.dao.api.ActionStatus;
69 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
70 import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
71 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
72 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
73 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
74 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
75 import org.openecomp.sdc.be.model.ArtifactDefinition;
76 import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
77 import org.openecomp.sdc.be.model.Component;
78 import org.openecomp.sdc.be.model.ConsumerDefinition;
79 import org.openecomp.sdc.be.model.DataTypeDefinition;
80 import org.openecomp.sdc.be.model.GroupTypeDefinition;
81 import org.openecomp.sdc.be.model.LifecycleStateEnum;
82 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
83 import org.openecomp.sdc.be.model.PropertyConstraint;
84 import org.openecomp.sdc.be.model.RequirementDefinition;
85 import org.openecomp.sdc.be.model.Resource;
86 import org.openecomp.sdc.be.model.User;
87 import org.openecomp.sdc.be.model.operations.StorageException;
88 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
89 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
90 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserializer;
91 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
92 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
93 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
94 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
95 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
96 import org.openecomp.sdc.be.resources.data.auditing.model.OperationalEnvAuditData;
97 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
98 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
99 import org.openecomp.sdc.be.tosca.ToscaError;
100 import org.openecomp.sdc.be.ui.model.UiLeftPaletteComponent;
101 import org.openecomp.sdc.common.api.Constants;
102 import org.openecomp.sdc.common.log.enums.LogLevel;
103 import org.openecomp.sdc.common.log.enums.Severity;
104 import org.openecomp.sdc.common.log.wrappers.Logger;
105 import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit;
106 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
107 import org.openecomp.sdc.common.util.ValidationUtils;
108 import org.openecomp.sdc.exception.ResponseFormat;
109 import org.slf4j.MarkerFactory;
110 import org.springframework.beans.factory.annotation.Autowired;
112 import javax.servlet.http.HttpServletRequest;
113 import java.lang.reflect.Type;
114 import java.util.ArrayList;
115 import java.util.Collections;
116 import java.util.List;
118 @org.springframework.stereotype.Component("componentUtils")
119 public class ComponentsUtils {
121 private static final String CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE = "convert storage response {} to action response {}";
122 private static final String INSIDE_AUDITING_FOR_AUDIT_ACTION = "Inside auditing for audit action {}";
123 private static final String AUDIT_BEFORE_SENDING_RESPONSE = "audit before sending response";
124 private static final String CONVERT_JSON_TO_OBJECT = "convertJsonToObject";
125 private static final Logger log = Logger.getLogger(ComponentsUtils.class);
126 private static final String PARTNER_NAME = "UNKNOWN";
127 private final AuditingManager auditingManager;
128 private final ResponseFormatManager responseFormatManager;
129 private static LoggerSdcAudit audit = new LoggerSdcAudit(DmaapConsumer.class);
132 public ComponentsUtils(AuditingManager auditingManager) {
133 this.auditingManager = auditingManager;
134 this.responseFormatManager = ResponseFormatManager.getInstance();
137 public AuditingManager getAuditingManager() {
138 return auditingManager;
141 public <T> Either<T, ResponseFormat> convertJsonToObject(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum) {
143 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
144 log.debug("object is null after converting from json");
145 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
146 return Either.right(responseFormat);
149 T obj = parseJsonToObject(data, clazz);
150 return Either.left(obj);
151 } catch (Exception e) {
153 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
154 log.debug("failed to convert from json {}", data, e);
155 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
156 return Either.right(responseFormat);
160 public static <T> T parseJsonToObject(String data, Class<T> clazz) {
161 Type constraintType = new TypeToken<PropertyConstraint>() {}.getType();
162 Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
163 log.trace("convert json to object. json=\n{}", data);
164 return gson.fromJson(data, clazz);
167 public <T> Either<T, ResponseFormat> convertJsonToObjectUsingObjectMapper(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
169 ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
170 mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
171 mapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
174 log.trace("convert json to object. json=\n{}", data);
176 SimpleModule module = new SimpleModule("customDeserializationModule");
177 module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
178 mapper.registerModule(module);
180 component = mapper.readValue(data, clazz);
181 if (component == null) {
182 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
183 log.debug("object is null after converting from json");
184 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
185 return Either.right(responseFormat);
187 } catch (Exception e) {
188 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
189 log.debug("failed to convert from json {}", data, e);
190 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
191 return Either.right(responseFormat);
193 return Either.left(component);
196 public ResponseFormat getResponseFormat(ActionStatus actionStatus, String... params) {
197 return responseFormatManager.getResponseFormat(actionStatus, params);
200 public ResponseFormat getResponseFormat(StorageOperationStatus storageStatus, String... params) {
201 return responseFormatManager.getResponseFormat(this.convertFromStorageResponse(storageStatus), params);
204 public <T> Either<List<T>, ResponseFormat> convertToResponseFormatOrNotFoundErrorToEmptyList(StorageOperationStatus storageOperationStatus) {
205 return storageOperationStatus.equals(StorageOperationStatus.NOT_FOUND) ? Either.left(Collections.emptyList()) :
206 Either.right(getResponseFormat(storageOperationStatus));
210 * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus is anonymously converted from storage operation, and the caller doesn't know what actionStatus he
211 * received. It's caller's Responsibility to fill the resource object passed to this function with needed fields.
213 * Note that RESOURCE_IN_USE case passes hardcoded "resource" string to the error parameter. This means that if Resource object will also be used for Service, this code needs to be refactored and we should tell Resource from Service.
215 * @param actionStatus
219 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, Resource resource) {
220 if (resource == null) {
221 return getResponseFormat(actionStatus);
223 ResponseFormat responseFormat;
225 switch (actionStatus) {
226 case COMPONENT_VERSION_ALREADY_EXIST:
227 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resource.getVersion());
229 case RESOURCE_NOT_FOUND:
230 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resource.getName());
232 case COMPONENT_NAME_ALREADY_EXIST:
233 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
235 case COMPONENT_IN_USE:
236 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, ComponentTypeEnum.RESOURCE.name().toLowerCase(), resource.getUniqueId());
239 responseFormat = getResponseFormat(actionStatus);
242 return responseFormat;
245 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, String resourceName) {
246 if (resourceName == null) {
247 return getResponseFormat(actionStatus);
250 ResponseFormat responseFormat;
251 if (actionStatus == ActionStatus.RESOURCE_NOT_FOUND) {
252 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceName);
255 responseFormat = getResponseFormat(actionStatus);
257 return responseFormat;
260 public ResponseFormat getResponseFormatByCapabilityType(ActionStatus actionStatus, CapabilityTypeDefinition capabilityType) {
261 if (capabilityType == null) {
262 return getResponseFormat(actionStatus);
265 ResponseFormat responseFormat;
266 if (actionStatus == ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST) {
267 responseFormat = getResponseFormat(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, capabilityType.getType());
270 responseFormat = getResponseFormat(actionStatus);
272 return responseFormat;
275 public <T> ResponseFormat getResponseFormatByElement(ActionStatus actionStatus, T obj) {
277 return getResponseFormat(actionStatus);
280 ResponseFormat responseFormat = null;
281 if (actionStatus == ActionStatus.MISSING_CAPABILITY_TYPE) {
282 if (obj instanceof List && org.apache.commons.collections.CollectionUtils.isNotEmpty((List) obj)) {
283 List list = (List) obj;
284 if (list.get(0) instanceof RequirementDefinition) {
285 responseFormat = getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, ((RequirementDefinition) list
286 .get(0)).getName()); //Arbitray index, all we need is single object
287 return responseFormat;
290 log.debug("UNKNOWN TYPE : expecting obj as a non empty List<RequirmentsDefinitions>");
293 responseFormat = getResponseFormat(actionStatus);
295 return responseFormat;
299 * Returns the response format of resource error with respective variables according to actionStatus. This is needed for cases where actionStatus is anynomously converted from storage operation, and the caller doesn't know what actionStatus he
300 * received. It's caller's responisibility to fill the passed resource object with needed fields.
302 * @param actionStatus
306 ResponseFormat getResponseFormatByUser(ActionStatus actionStatus, User user) {
308 return getResponseFormat(actionStatus);
310 ResponseFormat requestErrorWrapper;
311 switch (actionStatus) {
312 case INVALID_USER_ID:
313 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
315 case INVALID_EMAIL_ADDRESS:
316 requestErrorWrapper = getResponseFormat(actionStatus, user.getEmail());
319 requestErrorWrapper = getResponseFormat(actionStatus, user.getRole());
322 case USER_ALREADY_EXIST:
324 case USER_HAS_ACTIVE_ELEMENTS:
325 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
328 requestErrorWrapper = getResponseFormat(actionStatus);
331 return requestErrorWrapper;
334 public ResponseFormat getResponseFormatByUserId(ActionStatus actionStatus, String userId) {
335 User user = new User();
336 user.setUserId(userId);
337 return getResponseFormatByUser(actionStatus, user);
340 public ResponseFormat getResponseFormatByDE(ActionStatus actionStatus, String envName) {
341 ResponseFormat responseFormat;
343 switch (actionStatus) {
344 case DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE:
345 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE, envName);
347 case DISTRIBUTION_ENVIRONMENT_NOT_FOUND:
348 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND, envName);
351 responseFormat = getResponseFormat(actionStatus);
354 return responseFormat;
357 public ResponseFormat getResponseFormatByArtifactId(ActionStatus actionStatus, String artifactId) {
358 ResponseFormat responseFormat;
360 switch (actionStatus) {
361 case RESOURCE_NOT_FOUND:
362 case ARTIFACT_NOT_FOUND:
363 responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactId);
366 responseFormat = getResponseFormat(actionStatus);
369 return responseFormat;
372 public ResponseFormat getInvalidContentErrorAndAudit(User user, AuditingActionEnum actionEnum) {
373 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
374 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
375 auditAdminUserAction(actionEnum, user, null, null, responseFormat);
376 return responseFormat;
379 public ResponseFormat getInvalidContentErrorAndAudit(User user, String resourceName, AuditingActionEnum actionEnum) {
380 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
381 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
382 auditResource(responseFormat, user, resourceName, actionEnum);
383 return responseFormat;
388 public ResponseFormat getInvalidContentErrorForConsumerAndAudit(User user, ConsumerDefinition consumer, AuditingActionEnum actionEnum) {
389 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
390 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
391 auditConsumerCredentialsEvent(actionEnum, consumer, responseFormat, user);
392 return responseFormat;
395 private ResponseFormat getInvalidContentErrorAndAuditComponent(User user, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
396 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
397 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
398 auditComponentAdmin(responseFormat, user, null, actionEnum, typeEnum);
399 return responseFormat;
402 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum, ResourceVersionInfo prevResFields) {
403 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum, prevResFields, null, null);
406 public void auditResource(ResponseFormat responseFormat, User modifier, String resourceName, AuditingActionEnum actionEnum) {
407 auditResource(responseFormat, modifier, null, resourceName, actionEnum);
410 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum) {
411 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum);
414 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum) {
415 auditResource(responseFormat, modifier, resource, resourceName, actionEnum, ResourceVersionInfo.newBuilder().build(), null, null);
418 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum,
419 ResourceVersionInfo prevResFields, String currentArtifactUuid, ArtifactDefinition artifactDefinition) {
420 if (actionEnum != null) {
421 int status = responseFormat.getStatus();
424 String resourceCurrVersion = null;
425 String resourceCurrState = null;
426 String invariantUUID = null;
427 String resourceType = ComponentTypeEnum.RESOURCE.getValue();
428 String toscaNodeType = null;
430 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
432 String message = getMessageString(responseFormat);
434 String artifactData = buildAuditingArtifactData(artifactDefinition);
436 if (resource != null) {
437 resourceName = resource.getName();
438 resourceCurrVersion = resource.getVersion();
439 if (resource.getLifecycleState() != null) {
440 resourceCurrState = resource.getLifecycleState().name();
442 if (resource.getResourceType() != null) {
443 resourceType = resource.getResourceType().name();
445 invariantUUID = resource.getInvariantUUID();
446 uuid = resource.getUUID();
447 toscaNodeType = resource.getToscaResourceName();
450 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(
452 CommonAuditData.newBuilder()
454 .description(message)
455 .requestId(ThreadLocalsHolder.getUuid())
456 .serviceInstanceId(uuid)
458 new ResourceCommonInfo(resourceName, resourceType),
460 ResourceVersionInfo.newBuilder()
461 .artifactUuid(currentArtifactUuid)
462 .state(resourceCurrState)
463 .version(resourceCurrVersion)
467 artifactData, null, null, toscaNodeType);
469 getAuditingManager().auditEvent(factory);
473 private String getMessageString(ResponseFormat responseFormat) {
475 if (responseFormat.getMessageId() != null) {
476 message = responseFormat.getMessageId() + ": ";
478 message += responseFormat.getFormattedMessage();
482 public void auditDistributionDownload(ResponseFormat responseFormat, DistributionData distributionData) {
483 log.trace("Inside auditing");
484 int status = responseFormat.getStatus();
486 String message = getMessageString(responseFormat);
488 AuditDistributionDownloadEventFactory factory = new AuditDistributionDownloadEventFactory(
489 CommonAuditData.newBuilder()
491 .description(message)
492 .requestId(ThreadLocalsHolder.getUuid())
495 getAuditingManager().auditEvent(factory);
498 public void auditExternalGetAsset(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
499 ResourceCommonInfo resourceCommonInfo, String requestId, String serviceInstanceId) {
500 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
502 AuditEventFactory factory = new AuditAssetExternalApiEventFactory(actionEnum,
503 CommonAuditData.newBuilder()
504 .status(responseFormat.getStatus())
505 .description(getMessageString(responseFormat))
506 .requestId(requestId)
507 .serviceInstanceId(serviceInstanceId)
509 resourceCommonInfo, distributionData);
511 getAuditingManager().auditEvent(factory);
514 public void auditExternalGetAssetList(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData, String requestId) {
515 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
517 AuditEventFactory factory = new AuditAssetListExternalApiEventFactory(actionEnum,
518 CommonAuditData.newBuilder()
519 .status(responseFormat.getStatus())
520 .description(getMessageString(responseFormat))
521 .requestId(requestId)
525 getAuditingManager().auditEvent(factory);
528 public void auditChangeLifecycleAction(ResponseFormat responseFormat, ComponentTypeEnum componentType, String requestId,
529 Component component, Component responseObject, DistributionData distributionData, User modifier) {
531 String invariantUuid = "";
532 String serviceInstanceId = "";
533 ResourceVersionInfo currResourceVersionInfo = null;
534 ResourceVersionInfo prevResourceVersionInfo = null;
535 ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
537 if (component != null) {
538 prevResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
539 resourceCommonInfo.setResourceName(component.getName());
542 if (responseObject != null){
543 currResourceVersionInfo = buildResourceVersionInfoFromComponent(responseObject);
544 invariantUuid = responseObject.getInvariantUUID();
545 serviceInstanceId = responseObject.getUUID();
547 else if (component != null){
548 currResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
549 invariantUuid = component.getInvariantUUID();
550 serviceInstanceId = component.getUUID();
553 if (prevResourceVersionInfo == null) {
554 prevResourceVersionInfo = ResourceVersionInfo.newBuilder()
557 if (currResourceVersionInfo == null) {
558 currResourceVersionInfo = ResourceVersionInfo.newBuilder()
561 AuditEventFactory factory = new AuditChangeLifecycleExternalApiEventFactory(
562 CommonAuditData.newBuilder()
563 .serviceInstanceId(serviceInstanceId)
564 .requestId(requestId)
565 .description(getMessageString(responseFormat))
566 .status(responseFormat.getStatus())
568 resourceCommonInfo, distributionData,
569 prevResourceVersionInfo, currResourceVersionInfo,
570 invariantUuid, modifier);
572 getAuditingManager().auditEvent(factory);
575 private ResourceVersionInfo buildResourceVersionInfoFromComponent(Component component) {
576 return ResourceVersionInfo.newBuilder()
577 .version(component.getVersion())
578 .state(component.getLifecycleState().name())
582 public void auditExternalCrudApi(ResponseFormat responseFormat, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, HttpServletRequest request,
583 ArtifactDefinition artifactDefinition, String artifactUuid) {
584 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
586 ResourceVersionInfo currResourceVersionInfo;
587 User modifier = new User();
588 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
589 String artifactData = "";
590 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
591 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
594 if (artifactDefinition == null) {
595 currResourceVersionInfo = ResourceVersionInfo.newBuilder()
596 .artifactUuid(artifactUuid)
600 currResourceVersionInfo = ResourceVersionInfo.newBuilder()
601 .artifactUuid(artifactDefinition.getArtifactUUID())
602 .version(artifactDefinition.getArtifactVersion())
604 artifactData = buildAuditingArtifactData(artifactDefinition);
605 modifier.setUserId(artifactDefinition.getUserIdLastUpdater());
607 AuditEventFactory factory = new AuditCrudExternalApiArtifactEventFactory(actionEnum,
608 CommonAuditData.newBuilder()
609 .status(responseFormat.getStatus())
610 .description(getMessageString(responseFormat))
611 .requestId(requestId)
613 resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().build(), currResourceVersionInfo,
614 null, modifier, artifactData);
616 getAuditingManager().auditEvent(factory);
619 public boolean isExternalApiEvent(AuditingActionEnum auditingActionEnum){
620 return auditingActionEnum != null && auditingActionEnum.getAuditingEsType().equals(AuditingTypesConstants.EXTERNAL_API_EVENT_TYPE);
623 public void auditCreateResourceExternalApi(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo, HttpServletRequest request,
626 String invariantUuid = null;
627 String serviceInstanceId = null;
629 User modifier = new User();
630 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
631 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
632 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
634 ResourceVersionInfo currResourceVersionInfo;
636 if( resource != null ){
637 currResourceVersionInfo = ResourceVersionInfo.newBuilder()
638 .state(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())
639 .version(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION)
641 resourceCommonInfo.setResourceName(resource.getName());
642 invariantUuid = resource.getInvariantUUID();
643 serviceInstanceId = resource.getUUID();
646 currResourceVersionInfo = ResourceVersionInfo.newBuilder()
650 AuditEventFactory factory = new AuditCreateResourceExternalApiEventFactory(
651 CommonAuditData.newBuilder()
652 .status(responseFormat.getStatus())
653 .description(getMessageString(responseFormat))
654 .requestId(requestId)
655 .serviceInstanceId(serviceInstanceId)
657 resourceCommonInfo, distributionData,
658 currResourceVersionInfo, invariantUuid, modifier);
660 getAuditingManager().auditEvent(factory);
663 public void auditCreateServiceExternalApi(ResponseFormat responseFormat, HttpServletRequest request, Component service) {
665 String invariantUuid = null;
666 String serviceInstanceId = null;
668 User modifier = new User();
669 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
670 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
671 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
673 if(null != service) {
674 invariantUuid = service.getInvariantUUID();
675 serviceInstanceId = service.getUUID();
678 AuditEventFactory factory = new AuditCreateServiceExternalApiEventFactory(
679 CommonAuditData.newBuilder()
680 .status(responseFormat.getStatus())
681 .description(getMessageString(responseFormat))
682 .requestId(requestId)
683 .serviceInstanceId(serviceInstanceId)
685 new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()), distributionData, invariantUuid, modifier);
687 getAuditingManager().auditEvent(factory);
691 public void auditExternalActivateService(ResponseFormat responseFormat, DistributionData distributionData, String requestId, String serviceInstanceUuid, User modifier) {
692 AuditEventFactory factory = new AuditActivateServiceExternalApiEventFactory(
693 CommonAuditData.newBuilder()
694 .serviceInstanceId(serviceInstanceUuid)
695 .description(getMessageString(responseFormat))
696 .status(responseFormat.getStatus())
697 .requestId(requestId)
699 new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()), distributionData, "", modifier);
700 getAuditingManager().auditEvent(factory);
703 public void auditExternalDownloadArtifact(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo,
704 DistributionData distributionData, String requestId, String currArtifactUuid, String userId) {
705 User modifier = new User();
706 modifier.setUserId(userId);
708 AuditEventFactory factory = new AuditDownloadArtifactExternalApiEventFactory(
709 CommonAuditData.newBuilder()
710 .description(getMessageString(responseFormat))
711 .status(responseFormat.getStatus())
712 .requestId(requestId)
714 resourceCommonInfo, distributionData,
715 ResourceVersionInfo.newBuilder()
716 .artifactUuid(currArtifactUuid)
719 getAuditingManager().auditEvent(factory);
722 private String buildAuditingArtifactData(ArtifactDefinition artifactDefinition) {
723 StringBuilder sb = new StringBuilder();
724 if (artifactDefinition != null) {
725 sb.append(artifactDefinition.getArtifactGroupType().getType())
728 .append(artifactDefinition.getArtifactLabel())
731 .append(artifactDefinition.getArtifactType())
733 .append(artifactDefinition.getArtifactName())
735 .append(artifactDefinition.getTimeout())
737 .append(artifactDefinition.getEsId());
740 sb.append(artifactDefinition.getArtifactVersion() != null ? artifactDefinition.getArtifactVersion() : " ");
742 sb.append(artifactDefinition.getArtifactUUID() != null ? artifactDefinition.getArtifactUUID() : " ");
744 return sb.toString();
747 public void auditCategory(ResponseFormat responseFormat, User modifier, String categoryName, String subCategoryName, String groupingName, AuditingActionEnum actionEnum, String componentType) {
748 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
750 AuditEventFactory factory = new AuditCategoryEventFactory(actionEnum,
751 CommonAuditData.newBuilder()
752 .description(getMessageString(responseFormat))
753 .status(responseFormat.getStatus())
754 .requestId(ThreadLocalsHolder.getUuid())
756 modifier, categoryName, subCategoryName, groupingName, componentType);
758 getAuditingManager().auditEvent(factory);
761 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse) {
763 return convertFromStorageResponse(storageResponse, ComponentTypeEnum.RESOURCE);
766 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse, ComponentTypeEnum type) {
768 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
769 if (storageResponse == null) {
772 switch (storageResponse) {
774 responseEnum = ActionStatus.OK;
776 case CONNECTION_FAILURE:
778 responseEnum = ActionStatus.GENERAL_ERROR;
781 responseEnum = ActionStatus.INVALID_CONTENT;
783 case ENTITY_ALREADY_EXISTS:
784 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
786 case PARENT_RESOURCE_NOT_FOUND:
787 responseEnum = ActionStatus.PARENT_RESOURCE_NOT_FOUND;
789 case MULTIPLE_PARENT_RESOURCE_FOUND:
790 responseEnum = ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND;
793 if (ComponentTypeEnum.RESOURCE == type) {
794 responseEnum = ActionStatus.RESOURCE_NOT_FOUND;
795 } else if (ComponentTypeEnum.PRODUCT == type) {
796 responseEnum = ActionStatus.PRODUCT_NOT_FOUND;
798 responseEnum = ActionStatus.SERVICE_NOT_FOUND;
801 case FAILED_TO_LOCK_ELEMENT:
802 responseEnum = ActionStatus.COMPONENT_IN_USE;
804 case ARTIFACT_NOT_FOUND:
805 responseEnum = ActionStatus.ARTIFACT_NOT_FOUND;
807 case DISTR_ENVIRONMENT_NOT_AVAILABLE:
808 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE;
810 case DISTR_ENVIRONMENT_NOT_FOUND:
811 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND;
813 case DISTR_ENVIRONMENT_SENT_IS_INVALID:
814 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID;
817 responseEnum = ActionStatus.INVALID_CONTENT;
820 responseEnum = ActionStatus.INVALID_CONTENT;
823 responseEnum = ActionStatus.CSAR_NOT_FOUND;
825 case PROPERTY_NAME_ALREADY_EXISTS:
826 responseEnum = ActionStatus.PROPERTY_NAME_ALREADY_EXISTS;
828 case MATCH_NOT_FOUND:
829 responseEnum = ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY;
831 case CATEGORY_NOT_FOUND:
832 responseEnum = ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;
834 case INVALID_PROPERTY:
835 responseEnum = ActionStatus.INVALID_PROPERTY;
837 case COMPONENT_IS_ARCHIVED:
838 responseEnum = ActionStatus.COMPONENT_IS_ARCHIVED;
840 case DECLARED_INPUT_USED_BY_OPERATION:
841 responseEnum = ActionStatus.DECLARED_INPUT_USED_BY_OPERATION;
844 responseEnum = ActionStatus.GENERAL_ERROR;
847 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
851 public ActionStatus convertFromToscaError(ToscaError toscaError) {
852 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
853 if (toscaError == null) {
856 switch (toscaError) {// TODO match errors
857 case NODE_TYPE_CAPABILITY_ERROR:
858 case NOT_SUPPORTED_TOSCA_TYPE:
859 case NODE_TYPE_REQUIREMENT_ERROR:
860 responseEnum = ActionStatus.INVALID_CONTENT;
863 responseEnum = ActionStatus.GENERAL_ERROR;
869 public ActionStatus convertFromStorageResponseForCapabilityType(StorageOperationStatus storageResponse) {
870 ActionStatus responseEnum;
872 switch (storageResponse) {
874 responseEnum = ActionStatus.OK;
876 case CONNECTION_FAILURE:
878 responseEnum = ActionStatus.GENERAL_ERROR;
881 responseEnum = ActionStatus.INVALID_CONTENT;
883 case ENTITY_ALREADY_EXISTS:
884 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
886 case SCHEMA_VIOLATION:
887 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
890 responseEnum = ActionStatus.GENERAL_ERROR;
893 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
897 public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
898 ActionStatus responseEnum;
900 switch (storageResponse) {
902 responseEnum = ActionStatus.OK;
904 case CONNECTION_FAILURE:
906 responseEnum = ActionStatus.GENERAL_ERROR;
909 responseEnum = ActionStatus.INVALID_CONTENT;
911 case ENTITY_ALREADY_EXISTS:
912 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
914 case SCHEMA_VIOLATION:
915 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
918 responseEnum = ActionStatus.GENERAL_ERROR;
921 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
925 public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
926 ActionStatus responseEnum;
928 switch (storageResponse) {
930 responseEnum = ActionStatus.OK;
933 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
935 case INVALID_PROPERTY:
936 responseEnum = ActionStatus.INVALID_PROPERTY;
939 responseEnum = ActionStatus.GENERAL_ERROR;
942 responseEnum = ActionStatus.INVALID_CONTENT;
944 case MATCH_NOT_FOUND:
945 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
947 case SCHEMA_VIOLATION:
948 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
952 responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
954 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
958 responseEnum = ActionStatus.GENERAL_ERROR;
961 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
965 public ResponseFormat getResponseFormatForResourceInstance(ActionStatus actionStatus, String serviceName, String resourceInstanceName) {
966 ResponseFormat responseFormat;
968 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
969 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
972 responseFormat = getResponseFormat(actionStatus, serviceName);
974 return responseFormat;
977 public ResponseFormat getResponseFormatForResourceInstanceProperty(ActionStatus actionStatus, String resourceInstanceName) {
978 ResponseFormat responseFormat;
979 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
980 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
983 responseFormat = getResponseFormat(actionStatus);
985 return responseFormat;
988 public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
989 ActionStatus responseEnum;
991 switch (storageResponse) {
993 responseEnum = ActionStatus.OK;
996 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
999 responseEnum = ActionStatus.GENERAL_ERROR;
1002 responseEnum = ActionStatus.INVALID_CONTENT;
1004 case MATCH_NOT_FOUND:
1005 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
1007 case SCHEMA_VIOLATION:
1008 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
1011 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
1014 responseEnum = ActionStatus.GENERAL_ERROR;
1017 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1018 return responseEnum;
1021 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, String comment) {
1022 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, comment, null, null);
1025 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
1026 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), ResourceVersionInfo.newBuilder().build());
1029 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum, String comment) {
1030 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), ResourceVersionInfo.newBuilder().build(), null,
1031 comment, null, null);
1034 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum, ResourceVersionInfo prevComponent) {
1035 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), prevComponent);
1038 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent) {
1039 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, null, null, null);
1042 public void auditComponent(ResponseFormat responseFormat, User modifier, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, String comment) {
1043 auditComponent(responseFormat, modifier, null, actionEnum, resourceCommonInfo, ResourceVersionInfo.newBuilder().build(), null, comment, null, null);
1046 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent) {
1047 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, currComponent, null, null, null);
1050 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent,
1051 String comment, ArtifactDefinition artifactDefinition, String did) {
1052 if (actionEnum != null) {
1054 String currState = null;
1055 String invariantUUID = null;
1056 String currArtifactUid = null;
1057 String currVersion = null;
1058 String dcurrStatus = null;
1060 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
1062 String message = getMessageString(responseFormat);
1063 int status = responseFormat.getStatus();
1064 String artifactData = buildAuditingArtifactData(artifactDefinition);
1066 if (component != null) {
1067 // fields that are filled during creation and might still be empty
1068 if (component.getLifecycleState() != null) {
1069 currState = component.getLifecycleState().name();
1071 uuid = component.getUUID();
1072 invariantUUID = component.getInvariantUUID();
1073 currVersion = component.getVersion();
1074 if (StringUtils.isEmpty(resourceCommonInfo.getResourceName())) {
1075 resourceCommonInfo.setResourceName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1078 if (currComponent != null) {
1079 currArtifactUid = currComponent.getArtifactUuid();
1080 dcurrStatus = currComponent.getDistributionStatus();
1081 if (currState == null) { //probably it was not set
1082 currState = currComponent.getState();
1084 if (currVersion == null) { //probably it was not set
1085 currVersion = currComponent.getVersion();
1088 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(
1090 CommonAuditData.newBuilder()
1092 .description(message)
1093 .requestId(ThreadLocalsHolder.getUuid())
1094 .serviceInstanceId(uuid)
1096 resourceCommonInfo, prevComponent,
1097 ResourceVersionInfo.newBuilder()
1098 .artifactUuid(currArtifactUid)
1100 .version(currVersion)
1101 .distributionStatus(dcurrStatus)
1104 modifier, artifactData, comment, did, null);
1106 getAuditingManager().auditEvent(factory);
1110 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String status) {
1111 auditDistributionEngine(action, environmentName, distributionTopicData, null, null, status);
1115 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role, String apiKey, String status) {
1116 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager.createDistributionEngineEventFactory(action,
1117 environmentName, distributionTopicData, role, apiKey, status);
1118 getAuditingManager().auditEvent(factory);
1122 public void auditEnvironmentEngine(AuditingActionEnum actionEnum, String environmentID,
1123 String environmentType, String action, String environmentName, String tenantContext) {
1124 AuditEventFactory factory = new AuditEcompOpEnvEventFactory(actionEnum, environmentID, environmentName,
1125 environmentType, action, tenantContext);
1126 audit.startAuditFetchLog(PARTNER_NAME, DmaapConsumer.class.getName());
1127 audit.logEntry(LogLevel.INFO, Severity.OK, null,
1128 MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName()), environmentID);
1129 getAuditingManager().auditEvent(factory, audit);
1132 public void auditDistributionNotification(String serviceUUID, String resourceName, String resourceType, String currVersion, User modifier, String environmentName, String currState,
1133 String topicName, String distributionId, String description, String status, String workloadContext, String tenant) {
1135 AuditEventFactory factory = new AuditDistributionNotificationEventFactory(
1136 CommonAuditData.newBuilder()
1137 .serviceInstanceId(serviceUUID)
1139 .description(description)
1140 .requestId(ThreadLocalsHolder.getUuid())
1142 new ResourceCommonInfo(resourceName, resourceType),
1143 ResourceVersionInfo.newBuilder()
1145 .version(currVersion)
1147 distributionId, modifier, topicName,
1148 new OperationalEnvAuditData(environmentName, workloadContext, tenant));
1150 getAuditingManager().auditEvent(factory);
1153 public void auditAuthEvent(String url, String user, String authStatus, String realm) {
1154 AuditEventFactory factory = new AuditAuthRequestEventFactory(
1155 CommonAuditData.newBuilder()
1156 .requestId(ThreadLocalsHolder.getUuid())
1158 user, url, realm, authStatus);
1159 getAuditingManager().auditEvent(factory);
1162 public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName,
1163 String resourceUrl, String statusTime, String status,
1164 String errorReason, LoggerSdcAudit audit) {
1165 AuditEventFactory factory = new AuditDistributionStatusEventFactory(
1166 CommonAuditData.newBuilder()
1167 .description(errorReason)
1169 .requestId(distributionId)
1171 new DistributionData(consumerId, resourceUrl),
1172 distributionId, topicName, statusTime);
1174 getAuditingManager().auditEvent(factory, audit);
1177 public void auditGetUebCluster(String consumerId, String status, String description) {
1178 AuditEventFactory factory = new AuditGetUebClusterEventFactory(
1179 CommonAuditData.newBuilder()
1180 .description(description)
1182 .requestId(ThreadLocalsHolder.getUuid())
1186 getAuditingManager().auditEvent(factory);
1189 public void auditMissingInstanceIdAsDistributionEngineEvent(AuditingActionEnum actionEnum, String status) {
1190 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager.createDistributionEngineEventFactory(
1192 DistributionTopicData.newBuilder()
1193 .build(), null, null, status);
1194 getAuditingManager().auditEvent(factory);
1198 public void auditRegisterOrUnRegisterEvent(AuditingActionEnum action, String consumerId, String apiPublicKey, String envName, String status, String distributionStatus, String notifTopicName, String statusTopicName) {
1199 String appliedStatus = !StringUtils.isEmpty(status) ? status : distributionStatus;
1201 AuditEventFactory factory = new AuditRegUnregDistributionEngineEventFactory(action,
1202 CommonAuditData.newBuilder()
1203 .requestId(ThreadLocalsHolder.getUuid())
1204 .status(appliedStatus)
1206 DistributionTopicData.newBuilder()
1207 .statusTopic(statusTopicName)
1208 .notificationTopic(notifTopicName)
1210 consumerId, apiPublicKey, envName);
1212 getAuditingManager().auditEvent(factory);
1215 public void auditServiceDistributionDeployed(String serviceName, String serviceVersion, String serviceUUID, String distributionId, String status, String desc, User modifier) {
1217 AuditEventFactory factory = new AuditDistributionDeployEventFactory(
1218 CommonAuditData.newBuilder()
1219 .requestId(ThreadLocalsHolder.getUuid())
1220 .serviceInstanceId(serviceUUID)
1224 new ResourceCommonInfo(serviceName, "Service"),
1229 getAuditingManager().auditEvent(factory);
1233 public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat, User modifier) {
1234 AuditEventFactory factory = new AuditConsumerEventFactory(actionEnum,
1235 CommonAuditData.newBuilder()
1236 .description(getMessageString(responseFormat))
1237 .status(responseFormat.getStatus())
1238 .requestId(ThreadLocalsHolder.getUuid())
1240 modifier, consumer);
1242 getAuditingManager().auditEvent(factory);
1245 public void auditGetUsersList(User user, String details, ResponseFormat responseFormat) {
1247 AuditEventFactory factory = new AuditGetUsersListEventFactory(
1248 CommonAuditData.newBuilder()
1249 .description(getMessageString(responseFormat))
1250 .status(responseFormat.getStatus())
1251 .requestId(ThreadLocalsHolder.getUuid())
1254 getAuditingManager().auditEvent(factory);
1257 public void auditAdminUserActionAndThrowException(AuditingActionEnum actionEnum, User modifier, User userBefore,
1258 User userAfter, ActionStatus status, String... params) {
1259 ResponseFormat responseFormat = getResponseFormat(status, params);
1260 auditAdminUserAction(actionEnum, modifier, userBefore, userAfter, responseFormat);
1261 throw new ByResponseFormatComponentException(responseFormat);
1264 public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
1266 AuditEventFactory factory = new AuditUserAdminEventFactory(actionEnum,
1267 CommonAuditData.newBuilder()
1268 .description(getMessageString(responseFormat))
1269 .status(responseFormat.getStatus())
1270 .requestId(ThreadLocalsHolder.getUuid())
1272 modifier, userBefore, userAfter);
1274 getAuditingManager().auditEvent(factory);
1277 public void auditUserAccess(User user, ActionStatus status, String... params) {
1278 auditUserAccess(user, getResponseFormat(status, params));
1281 public void auditUserAccess(User user, ResponseFormat responseFormat) {
1283 AuditEventFactory factory = new AuditUserAccessEventFactory(CommonAuditData.newBuilder()
1284 .description(getMessageString(responseFormat))
1285 .status(responseFormat.getStatus())
1286 .requestId(ThreadLocalsHolder.getUuid())
1290 getAuditingManager().auditEvent(factory);
1293 public void auditGetCategoryHierarchy(User user, String details, ResponseFormat responseFormat) {
1295 AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(CommonAuditData.newBuilder()
1296 .description(getMessageString(responseFormat))
1297 .status(responseFormat.getStatus())
1298 .requestId(ThreadLocalsHolder.getUuid())
1302 getAuditingManager().auditEvent(factory);
1305 public ResponseFormat getResponseFormatByComponent(ActionStatus actionStatus, Component component, ComponentTypeEnum type) {
1306 if (component == null) {
1307 return getResponseFormat(actionStatus);
1309 ResponseFormat responseFormat;
1311 switch (actionStatus) {
1312 case COMPONENT_VERSION_ALREADY_EXIST:
1313 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, type.getValue(), component.getVersion());
1315 case RESOURCE_NOT_FOUND:
1316 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1318 case COMPONENT_NAME_ALREADY_EXIST:
1319 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(), component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1321 case COMPONENT_IN_USE:
1322 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, type.name().toLowerCase(), component.getUniqueId());
1324 case SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND:
1325 responseFormat = getResponseFormat(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1328 responseFormat = getResponseFormat(actionStatus);
1331 return responseFormat;
1334 public boolean validateStringNotEmpty(String value) {
1335 return value != null && !value.trim().isEmpty();
1338 public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
1339 ActionStatus responseEnum;
1341 switch (storageResponse) {
1343 responseEnum = ActionStatus.OK;
1345 case ENTITY_ALREADY_EXISTS:
1346 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
1349 responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
1352 responseEnum = ActionStatus.GENERAL_ERROR;
1355 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1356 return responseEnum;
1359 public ActionStatus convertFromResultStatusEnum(ResultStatusEnum resultStatus, JsonPresentationFields elementType) {
1360 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1361 switch (resultStatus) {
1363 responseEnum = ActionStatus.OK;
1365 case ELEMENT_NOT_FOUND:
1366 if(elementType!= null && elementType == JsonPresentationFields.PROPERTY){
1367 responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
1370 case INVALID_PROPERTY_DEFAULT_VALUE:
1371 case INVALID_PROPERTY_TYPE:
1372 case INVALID_PROPERTY_VALUE:
1373 case INVALID_PROPERTY_NAME:
1374 case MISSING_ENTRY_SCHEMA_TYPE:
1375 responseEnum = ActionStatus.INVALID_PROPERTY;
1378 responseEnum = ActionStatus.GENERAL_ERROR;
1381 return responseEnum;
1384 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus, AdditionalInfoParameterInfo additionalInfoParameterInfo, NodeTypeEnum nodeType, AdditionalInformationEnum labelOrValue) {
1386 if (additionalInfoParameterInfo == null) {
1387 additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
1389 if (labelOrValue == null) {
1390 labelOrValue = AdditionalInformationEnum.None;
1393 ResponseFormat responseFormat = null;
1394 switch (actionStatus) {
1395 case COMPONENT_NAME_ALREADY_EXIST:
1396 responseFormat = getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey());
1398 case ADDITIONAL_INFORMATION_EXCEEDS_LIMIT:
1399 responseFormat = getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(), ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString());
1401 case ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED:
1402 responseFormat = getResponseFormat(actionStatus, nodeType.name().toLowerCase());
1404 case ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED:
1405 responseFormat = getResponseFormat(actionStatus);
1407 case ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS:
1408 responseFormat = getResponseFormat(actionStatus);
1410 case ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS:
1411 responseFormat = getResponseFormat(actionStatus);
1413 case ADDITIONAL_INFORMATION_NOT_FOUND:
1414 responseFormat = getResponseFormat(actionStatus);
1417 responseFormat = getResponseFormat(actionStatus);
1421 return responseFormat;
1424 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus) {
1425 return getResponseFormatAdditionalProperty(actionStatus, null, null, null);
1428 public ActionStatus convertFromStorageResponseForConsumer(StorageOperationStatus storageResponse) {
1429 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1431 switch (storageResponse) {
1433 responseEnum = ActionStatus.OK;
1435 case CONNECTION_FAILURE:
1437 responseEnum = ActionStatus.GENERAL_ERROR;
1440 responseEnum = ActionStatus.INVALID_CONTENT;
1442 case ENTITY_ALREADY_EXISTS:
1443 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1445 case SCHEMA_VIOLATION:
1446 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1449 responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
1452 responseEnum = ActionStatus.GENERAL_ERROR;
1455 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1456 return responseEnum;
1459 public ActionStatus convertFromStorageResponseForGroupType(StorageOperationStatus storageResponse) {
1460 ActionStatus responseEnum;
1462 switch (storageResponse) {
1464 responseEnum = ActionStatus.OK;
1466 case CONNECTION_FAILURE:
1468 responseEnum = ActionStatus.GENERAL_ERROR;
1471 responseEnum = ActionStatus.INVALID_CONTENT;
1473 case ENTITY_ALREADY_EXISTS:
1474 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1476 case SCHEMA_VIOLATION:
1477 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1480 responseEnum = ActionStatus.GENERAL_ERROR;
1483 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1484 return responseEnum;
1487 public ActionStatus convertFromStorageResponseForDataType(StorageOperationStatus storageResponse) {
1488 ActionStatus responseEnum;
1490 switch (storageResponse) {
1492 responseEnum = ActionStatus.OK;
1494 case CONNECTION_FAILURE:
1496 responseEnum = ActionStatus.GENERAL_ERROR;
1499 responseEnum = ActionStatus.INVALID_CONTENT;
1501 case ENTITY_ALREADY_EXISTS:
1502 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1504 case SCHEMA_VIOLATION:
1505 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1507 case CANNOT_UPDATE_EXISTING_ENTITY:
1508 responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
1511 responseEnum = ActionStatus.GENERAL_ERROR;
1514 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1515 return responseEnum;
1518 public ResponseFormat getResponseFormatByGroupType(ActionStatus actionStatus, GroupTypeDefinition groupType) {
1519 if (groupType == null) {
1520 return getResponseFormat(actionStatus);
1522 ResponseFormat responseFormat;
1524 switch (actionStatus) {
1525 case GROUP_MEMBER_EMPTY:
1526 case GROUP_TYPE_ALREADY_EXIST:
1527 responseFormat = getResponseFormat(actionStatus, groupType.getType());
1530 responseFormat = getResponseFormat(actionStatus);
1533 return responseFormat;
1537 public ResponseFormat getResponseFormatByPolicyType(ActionStatus actionStatus, PolicyTypeDefinition policyType) {
1538 if (policyType == null) {
1539 return getResponseFormat(actionStatus);
1542 ResponseFormat responseFormat;
1543 if (actionStatus == ActionStatus.POLICY_TYPE_ALREADY_EXIST) {
1544 responseFormat = getResponseFormat(actionStatus, policyType.getType());
1547 responseFormat = getResponseFormat(actionStatus);
1549 return responseFormat;
1553 public ResponseFormat getResponseFormatByDataType(ActionStatus actionStatus, DataTypeDefinition dataType, List<String> properties) {
1554 if (dataType == null) {
1555 return getResponseFormat(actionStatus);
1557 ResponseFormat responseFormat;
1559 switch (actionStatus) {
1560 case DATA_TYPE_ALREADY_EXIST:
1561 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1563 case DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM:
1564 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1566 case DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY:
1567 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1569 case DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR:
1570 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1572 case DATA_TYPE_DERIVED_IS_MISSING:
1573 responseFormat = getResponseFormat(actionStatus, dataType.getDerivedFromName());
1575 case DATA_TYPE_DUPLICATE_PROPERTY:
1576 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1578 case DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE:
1579 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1581 case DATA_TYPE_CANNOT_HAVE_PROPERTIES:
1582 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1584 case DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST:
1585 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1589 responseFormat = getResponseFormat(actionStatus);
1592 return responseFormat;
1595 public StorageOperationStatus convertToStorageOperationStatus(CassandraOperationStatus cassandraStatus) {
1596 StorageOperationStatus result;
1597 switch (cassandraStatus) {
1599 result = StorageOperationStatus.OK;
1602 result = StorageOperationStatus.NOT_FOUND;
1604 case CLUSTER_NOT_CONNECTED:
1605 case KEYSPACE_NOT_CONNECTED:
1606 result = StorageOperationStatus.CONNECTION_FAILURE;
1609 result = StorageOperationStatus.GENERAL_ERROR;
1615 public ResponseFormat getResponseFormat(ComponentException exception) {
1616 return exception instanceof ByResponseFormatComponentException ?
1617 getResponseFormat((ByResponseFormatComponentException) exception):
1618 getResponseFormat((ByActionStatusComponentException) exception);
1621 public ResponseFormat getResponseFormat(ByResponseFormatComponentException exception) {
1622 return exception.getResponseFormat();
1625 public ResponseFormat getResponseFormat(ByActionStatusComponentException exception) {
1626 return getResponseFormat(exception.getActionStatus(), exception.getParams());
1629 public ActionStatus convertFromStorageResponseForRelationshipType(
1630 StorageOperationStatus storageResponse) {
1631 ActionStatus responseEnum;
1633 switch (storageResponse) {
1635 responseEnum = ActionStatus.OK;
1637 case CONNECTION_FAILURE:
1639 responseEnum = ActionStatus.GENERAL_ERROR;
1642 responseEnum = ActionStatus.INVALID_CONTENT;
1644 case ENTITY_ALREADY_EXISTS:
1645 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1647 case SCHEMA_VIOLATION:
1648 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1651 responseEnum = ActionStatus.GENERAL_ERROR;
1654 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1655 return responseEnum;
1658 public ResponseFormat getResponseFormat(StorageException exception) {
1659 ActionStatus status = convertFromStorageResponse(exception.getStorageOperationStatus());
1660 return getResponseFormat(status, exception.getParams());
1664 public List<UiLeftPaletteComponent> convertComponentToUiLeftPaletteComponentObject(List<Component> components) {
1665 List<UiLeftPaletteComponent> uiLeftPaletteComponents = new ArrayList<>();
1666 components.forEach(c-> uiLeftPaletteComponents.add(new UiLeftPaletteComponent(c)));
1667 return uiLeftPaletteComponents;