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=========================================================
21 package org.openecomp.sdc.be.impl;
23 import com.fasterxml.jackson.databind.DeserializationFeature;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import com.fasterxml.jackson.databind.module.SimpleModule;
26 import com.google.gson.Gson;
27 import com.google.gson.GsonBuilder;
28 import com.google.gson.reflect.TypeToken;
29 import fj.data.Either;
30 import org.apache.commons.lang3.StringUtils;
31 import org.openecomp.sdc.be.auditing.api.AuditEventFactory;
32 import org.openecomp.sdc.be.auditing.impl.*;
33 import org.openecomp.sdc.be.auditing.impl.category.AuditCategoryEventFactory;
34 import org.openecomp.sdc.be.auditing.impl.category.AuditGetCategoryHierarchyEventFactory;
35 import org.openecomp.sdc.be.auditing.impl.distribution.*;
36 import org.openecomp.sdc.be.auditing.impl.externalapi.*;
37 import org.openecomp.sdc.be.auditing.impl.resourceadmin.AuditResourceEventFactoryManager;
38 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditGetUsersListEventFactory;
39 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAccessEventFactory;
40 import org.openecomp.sdc.be.auditing.impl.usersadmin.AuditUserAdminEventFactory;
41 import org.openecomp.sdc.be.components.impl.ImportUtils;
42 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
43 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
44 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
45 import org.openecomp.sdc.be.config.BeEcompErrorManager;
46 import org.openecomp.sdc.be.dao.api.ActionStatus;
47 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
48 import org.openecomp.sdc.be.dao.graph.datatype.AdditionalInformationEnum;
49 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterInfo;
50 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
51 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
52 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
53 import org.openecomp.sdc.be.model.*;
54 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
55 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintDeserialiser;
56 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyConstraintJacksonDeserializer;
57 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
58 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
59 import org.openecomp.sdc.be.resources.data.auditing.model.*;
60 import org.openecomp.sdc.be.tosca.ToscaError;
61 import org.openecomp.sdc.common.api.Constants;
62 import org.openecomp.sdc.common.log.wrappers.Logger;
63 import org.openecomp.sdc.common.util.ThreadLocalsHolder;
64 import org.openecomp.sdc.common.util.ValidationUtils;
65 import org.openecomp.sdc.exception.ResponseFormat;
67 import javax.servlet.http.HttpServletRequest;
68 import java.lang.reflect.Type;
69 import java.util.Collections;
70 import java.util.List;
72 @org.springframework.stereotype.Component("componentUtils")
73 public class ComponentsUtils {
75 private static final String CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE = "convert storage response {} to action response {}";
76 private static final String INSIDE_AUDITING_FOR_AUDIT_ACTION = "Inside auditing for audit action {}";
77 private static final String AUDIT_BEFORE_SENDING_RESPONSE = "audit before sending response";
78 private static final String CONVERT_JSON_TO_OBJECT = "convertJsonToObject";
79 private static final Logger log = Logger.getLogger(ComponentsUtils.class);
80 private final AuditingManager auditingManager;
81 private final ResponseFormatManager responseFormatManager;
83 public ComponentsUtils(AuditingManager auditingManager) {
84 this.auditingManager = auditingManager;
85 this.responseFormatManager = ResponseFormatManager.getInstance();
88 public AuditingManager getAuditingManager() {
89 return auditingManager;
92 public <T> Either<T, ResponseFormat> convertJsonToObject(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum) {
94 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
95 log.debug("object is null after converting from json");
96 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
97 return Either.right(responseFormat);
100 T obj = parseJsonToObject(data, clazz);
101 return Either.left(obj);
102 } catch (Exception e) {
104 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
105 log.debug("failed to convert from json {}", data, e);
106 ResponseFormat responseFormat = getInvalidContentErrorAndAudit(user, actionEnum);
107 return Either.right(responseFormat);
111 public static <T> T parseJsonToObject(String data, Class<T> clazz) {
112 Type constraintType = new TypeToken<PropertyConstraint>() {}.getType();
113 Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
114 log.trace("convert json to object. json=\n{}", data);
115 return gson.fromJson(data, clazz);
118 public <T> Either<T, ResponseFormat> convertJsonToObjectUsingObjectMapper(String data, User user, Class<T> clazz, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
120 ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
121 mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
123 log.trace("convert json to object. json=\n{}", data);
125 SimpleModule module = new SimpleModule("customDeserializationModule");
126 module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
127 mapper.registerModule(module);
129 component = mapper.readValue(data, clazz);
130 if (component == null) {
131 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
132 log.debug("object is null after converting from json");
133 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
134 return Either.right(responseFormat);
136 } catch (Exception e) {
137 BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
138 log.debug("failed to convert from json {}", data, e);
139 ResponseFormat responseFormat = getInvalidContentErrorAndAuditComponent(user, actionEnum, typeEnum);
140 return Either.right(responseFormat);
142 return Either.left(component);
145 public ResponseFormat getResponseFormat(ActionStatus actionStatus, String... params) {
146 return responseFormatManager.getResponseFormat(actionStatus, params);
149 public ResponseFormat getResponseFormat(StorageOperationStatus storageStatus, String... params) {
150 return responseFormatManager.getResponseFormat(this.convertFromStorageResponse(storageStatus), params);
153 public <T> Either<List<T>, ResponseFormat> convertToResponseFormatOrNotFoundErrorToEmptyList(StorageOperationStatus storageOperationStatus) {
154 return storageOperationStatus.equals(StorageOperationStatus.NOT_FOUND) ? Either.left(Collections.emptyList()) :
155 Either.right(getResponseFormat(storageOperationStatus));
159 * 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
160 * received. It's caller's Responsibility to fill the resource object passed to this function with needed fields.
162 * 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.
164 * @param actionStatus
168 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, Resource resource) {
169 if (resource == null) {
170 return getResponseFormat(actionStatus);
172 ResponseFormat responseFormat;
174 switch (actionStatus) {
175 case COMPONENT_VERSION_ALREADY_EXIST:
176 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resource.getVersion());
178 case RESOURCE_NOT_FOUND:
179 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resource.getName());
181 case COMPONENT_NAME_ALREADY_EXIST:
182 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
184 case COMPONENT_IN_USE:
185 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, ComponentTypeEnum.RESOURCE.name().toLowerCase(), resource.getUniqueId());
188 responseFormat = getResponseFormat(actionStatus);
191 return responseFormat;
194 public ResponseFormat getResponseFormatByResource(ActionStatus actionStatus, String resourceName) {
195 if (resourceName == null) {
196 return getResponseFormat(actionStatus);
199 ResponseFormat responseFormat;
200 if (actionStatus == ActionStatus.RESOURCE_NOT_FOUND) {
201 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, resourceName);
204 responseFormat = getResponseFormat(actionStatus);
206 return responseFormat;
209 public ResponseFormat getResponseFormatByCapabilityType(ActionStatus actionStatus, CapabilityTypeDefinition capabilityType) {
210 if (capabilityType == null) {
211 return getResponseFormat(actionStatus);
214 ResponseFormat responseFormat;
215 if (actionStatus == ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST) {
216 responseFormat = getResponseFormat(ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST, capabilityType.getType());
219 responseFormat = getResponseFormat(actionStatus);
221 return responseFormat;
224 public <T> ResponseFormat getResponseFormatByElement(ActionStatus actionStatus, T obj) {
226 return getResponseFormat(actionStatus);
229 ResponseFormat responseFormat = null;
230 if (actionStatus == ActionStatus.MISSING_CAPABILITY_TYPE) {
231 if (obj instanceof List && org.apache.commons.collections.CollectionUtils.isNotEmpty((List) obj)) {
232 List list = (List) obj;
233 if (list.get(0) instanceof RequirementDefinition) {
234 responseFormat = getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, ((RequirementDefinition) list
235 .get(0)).getName()); //Arbitray index, all we need is single object
236 return responseFormat;
239 log.debug("UNKNOWN TYPE : expecting obj as a non empty List<RequirmentsDefinitions>");
242 responseFormat = getResponseFormat(actionStatus);
244 return responseFormat;
248 * 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
249 * received. It's caller's responisibility to fill the passed resource object with needed fields.
251 * @param actionStatus
255 public ResponseFormat getResponseFormatByUser(ActionStatus actionStatus, User user) {
257 return getResponseFormat(actionStatus);
259 ResponseFormat requestErrorWrapper;
260 switch (actionStatus) {
261 case INVALID_USER_ID:
262 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
264 case INVALID_EMAIL_ADDRESS:
265 requestErrorWrapper = getResponseFormat(actionStatus, user.getEmail());
268 requestErrorWrapper = getResponseFormat(actionStatus, user.getRole());
271 case USER_ALREADY_EXIST:
273 case USER_HAS_ACTIVE_ELEMENTS:
274 requestErrorWrapper = getResponseFormat(actionStatus, user.getUserId());
277 requestErrorWrapper = getResponseFormat(actionStatus);
280 return requestErrorWrapper;
283 public ResponseFormat getResponseFormatByUserId(ActionStatus actionStatus, String userId) {
284 User user = new User();
285 user.setUserId(userId);
286 return getResponseFormatByUser(actionStatus, user);
289 public ResponseFormat getResponseFormatByDE(ActionStatus actionStatus, String envName) {
290 ResponseFormat responseFormat;
292 switch (actionStatus) {
293 case DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE:
294 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE, envName);
296 case DISTRIBUTION_ENVIRONMENT_NOT_FOUND:
297 responseFormat = getResponseFormat(ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND, envName);
300 responseFormat = getResponseFormat(actionStatus);
303 return responseFormat;
306 public ResponseFormat getResponseFormatByArtifactId(ActionStatus actionStatus, String artifactId) {
307 ResponseFormat responseFormat;
309 switch (actionStatus) {
310 case RESOURCE_NOT_FOUND:
311 case ARTIFACT_NOT_FOUND:
312 responseFormat = getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, artifactId);
315 responseFormat = getResponseFormat(actionStatus);
318 return responseFormat;
321 public ResponseFormat getInvalidContentErrorAndAudit(User user, String resourceName, AuditingActionEnum actionEnum) {
322 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
323 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
324 auditResource(responseFormat, user, resourceName, actionEnum);
325 return responseFormat;
328 public ResponseFormat getInvalidContentErrorForConsumerAndAudit(User user, ConsumerDefinition consumer, AuditingActionEnum actionEnum) {
329 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
330 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
331 auditConsumerCredentialsEvent(actionEnum, consumer, responseFormat, user);
332 return responseFormat;
335 public ResponseFormat getInvalidContentErrorAndAudit(User user, AuditingActionEnum actionEnum) {
336 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
337 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
338 auditAdminUserAction(actionEnum, user, null, null, responseFormat);
339 return responseFormat;
342 public ResponseFormat getInvalidContentErrorAndAuditComponent(User user, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
343 ResponseFormat responseFormat = responseFormatManager.getResponseFormat(ActionStatus.INVALID_CONTENT);
344 log.debug(AUDIT_BEFORE_SENDING_RESPONSE);
345 auditComponentAdmin(responseFormat, user, null, actionEnum, typeEnum);
346 return responseFormat;
349 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum, ResourceVersionInfo prevResFields) {
350 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum, prevResFields, null, null);
353 public void auditResource(ResponseFormat responseFormat, User modifier, String resourceName, AuditingActionEnum actionEnum) {
354 auditResource(responseFormat, modifier, null, resourceName, actionEnum);
357 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, AuditingActionEnum actionEnum) {
358 auditResource(responseFormat, modifier, resource, resource.getName(), actionEnum);
361 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum) {
362 auditResource(responseFormat, modifier, resource, resourceName, actionEnum, ResourceVersionInfo.newBuilder().build(), null, null);
365 public void auditResource(ResponseFormat responseFormat, User modifier, Resource resource, String resourceName, AuditingActionEnum actionEnum,
366 ResourceVersionInfo prevResFields, String currentArtifactUuid, ArtifactDefinition artifactDefinition) {
367 if (actionEnum != null) {
368 int status = responseFormat.getStatus();
371 String resourceCurrVersion = null;
372 String resourceCurrState = null;
373 String invariantUUID = null;
374 String resourceType = ComponentTypeEnum.RESOURCE.getValue();
375 String toscaNodeType = null;
377 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
379 String message = getMessageString(responseFormat);
381 String artifactData = buildAuditingArtifactData(artifactDefinition);
383 if (resource != null) {
384 resourceName = resource.getName();
385 resourceCurrVersion = resource.getVersion();
386 if (resource.getLifecycleState() != null) {
387 resourceCurrState = resource.getLifecycleState().name();
389 if (resource.getResourceType() != null) {
390 resourceType = resource.getResourceType().name();
392 invariantUUID = resource.getInvariantUUID();
393 uuid = resource.getUUID();
394 toscaNodeType = resource.getToscaResourceName();
397 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(
399 CommonAuditData.newBuilder()
401 .description(message)
402 .requestId(ThreadLocalsHolder.getUuid())
403 .serviceInstanceId(uuid)
405 new ResourceCommonInfo(resourceName, resourceType),
407 ResourceVersionInfo.newBuilder()
408 .artifactUuid(currentArtifactUuid)
409 .state(resourceCurrState)
410 .version(resourceCurrVersion)
414 artifactData, null, null, toscaNodeType);
416 getAuditingManager().auditEvent(factory);
420 private String getMessageString(ResponseFormat responseFormat) {
422 if (responseFormat.getMessageId() != null) {
423 message = responseFormat.getMessageId() + ": ";
425 message += responseFormat.getFormattedMessage();
429 public void auditDistributionDownload(ResponseFormat responseFormat, DistributionData distributionData) {
430 log.trace("Inside auditing");
431 int status = responseFormat.getStatus();
433 String message = getMessageString(responseFormat);
435 AuditDistributionDownloadEventFactory factory = new AuditDistributionDownloadEventFactory(
436 CommonAuditData.newBuilder()
438 .description(message)
439 .requestId(ThreadLocalsHolder.getUuid())
442 getAuditingManager().auditEvent(factory);
445 public void auditExternalGetAsset(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData,
446 ResourceCommonInfo resourceCommonInfo, String requestId, String serviceInstanceId) {
447 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
449 AuditEventFactory factory = new AuditAssetExternalApiEventFactory(actionEnum,
450 CommonAuditData.newBuilder()
451 .status(responseFormat.getStatus())
452 .description(getMessageString(responseFormat))
453 .requestId(requestId)
454 .serviceInstanceId(serviceInstanceId)
456 resourceCommonInfo, distributionData);
458 getAuditingManager().auditEvent(factory);
461 public void auditExternalGetAssetList(ResponseFormat responseFormat, AuditingActionEnum actionEnum, DistributionData distributionData, String requestId) {
462 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
464 AuditEventFactory factory = new AuditAssetListExternalApiEventFactory(actionEnum,
465 CommonAuditData.newBuilder()
466 .status(responseFormat.getStatus())
467 .description(getMessageString(responseFormat))
468 .requestId(requestId)
472 getAuditingManager().auditEvent(factory);
475 public void auditChangeLifecycleAction(ResponseFormat responseFormat, ComponentTypeEnum componentType, String requestId,
476 Component component, Component responseObject, DistributionData distributionData, User modifier) {
478 String invariantUuid = "";
479 String serviceInstanceId = "";
480 ResourceVersionInfo currResourceVersionInfo = null;
481 ResourceVersionInfo prevResourceVersionInfo = null;
482 ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentType.getValue());
484 if (component != null) {
485 prevResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
486 resourceCommonInfo.setResourceName(component.getName());
489 if (responseObject != null){
490 currResourceVersionInfo = buildResourceVersionInfoFromComponent(responseObject);
491 invariantUuid = responseObject.getInvariantUUID();
492 serviceInstanceId = responseObject.getUUID();
494 else if (component != null){
495 currResourceVersionInfo = buildResourceVersionInfoFromComponent(component);
496 invariantUuid = component.getInvariantUUID();
497 serviceInstanceId = component.getUUID();
500 if (prevResourceVersionInfo == null) {
501 prevResourceVersionInfo = ResourceVersionInfo.newBuilder()
504 if (currResourceVersionInfo == null) {
505 currResourceVersionInfo = ResourceVersionInfo.newBuilder()
508 AuditEventFactory factory = new AuditChangeLifecycleExternalApiEventFactory(
509 CommonAuditData.newBuilder()
510 .serviceInstanceId(serviceInstanceId)
511 .requestId(requestId)
512 .description(getMessageString(responseFormat))
513 .status(responseFormat.getStatus())
515 resourceCommonInfo, distributionData,
516 prevResourceVersionInfo, currResourceVersionInfo,
517 invariantUuid, modifier);
519 getAuditingManager().auditEvent(factory);
522 private ResourceVersionInfo buildResourceVersionInfoFromComponent(Component component) {
523 return ResourceVersionInfo.newBuilder()
524 .version(component.getVersion())
525 .state(component.getLifecycleState().name())
529 public void auditExternalCrudApi(ResponseFormat responseFormat, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, HttpServletRequest request,
530 ArtifactDefinition artifactDefinition, String artifactUuid) {
531 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
533 ResourceVersionInfo currResourceVersionInfo;
534 User modifier = new User();
535 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
536 String artifactData = "";
537 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
538 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
541 if (artifactDefinition == null) {
542 currResourceVersionInfo = ResourceVersionInfo.newBuilder()
543 .artifactUuid(artifactUuid)
547 currResourceVersionInfo = ResourceVersionInfo.newBuilder()
548 .artifactUuid(artifactDefinition.getArtifactUUID())
549 .version(artifactDefinition.getArtifactVersion())
551 artifactData = buildAuditingArtifactData(artifactDefinition);
552 modifier.setUserId(artifactDefinition.getUserIdLastUpdater());
554 AuditEventFactory factory = new AuditCrudExternalApiArtifactEventFactory(actionEnum,
555 CommonAuditData.newBuilder()
556 .status(responseFormat.getStatus())
557 .description(getMessageString(responseFormat))
558 .requestId(requestId)
560 resourceCommonInfo, distributionData, ResourceVersionInfo.newBuilder().build(), currResourceVersionInfo,
561 null, modifier, artifactData);
563 getAuditingManager().auditEvent(factory);
566 public boolean isExternalApiEvent(AuditingActionEnum auditingActionEnum){
567 return auditingActionEnum != null && auditingActionEnum.getAuditingEsType().equals(AuditingTypesConstants.EXTERNAL_API_EVENT_TYPE);
570 public void auditCreateResourceExternalApi(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo, HttpServletRequest request,
573 String invariantUuid = null;
574 String serviceInstanceId = null;
576 User modifier = new User();
577 modifier.setUserId(request.getHeader(Constants.USER_ID_HEADER));
578 DistributionData distributionData = new DistributionData(request.getHeader(Constants.X_ECOMP_INSTANCE_ID_HEADER), request.getRequestURI());
579 String requestId = request.getHeader(Constants.X_ECOMP_REQUEST_ID_HEADER);
581 ResourceVersionInfo currResourceVersionInfo;
583 if( resource != null ){
584 currResourceVersionInfo = ResourceVersionInfo.newBuilder()
585 .state(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name())
586 .version(ImportUtils.Constants.FIRST_NON_CERTIFIED_VERSION)
588 resourceCommonInfo.setResourceName(resource.getName());
589 invariantUuid = resource.getInvariantUUID();
590 serviceInstanceId = resource.getUUID();
593 currResourceVersionInfo = ResourceVersionInfo.newBuilder()
597 AuditEventFactory factory = new AuditCreateResourceExternalApiEventFactory(
598 CommonAuditData.newBuilder()
599 .status(responseFormat.getStatus())
600 .description(getMessageString(responseFormat))
601 .requestId(requestId)
602 .serviceInstanceId(serviceInstanceId)
604 resourceCommonInfo, distributionData,
605 currResourceVersionInfo, invariantUuid, modifier);
607 getAuditingManager().auditEvent(factory);
610 public void auditExternalActivateService(ResponseFormat responseFormat, DistributionData distributionData, String requestId, String serviceInstanceUuid, User modifier) {
611 AuditEventFactory factory = new AuditActivateServiceExternalApiEventFactory(
612 CommonAuditData.newBuilder()
613 .serviceInstanceId(serviceInstanceUuid)
614 .description(getMessageString(responseFormat))
615 .status(responseFormat.getStatus())
616 .requestId(requestId)
618 new ResourceCommonInfo(ComponentTypeEnum.SERVICE.name()), distributionData, "", modifier);
619 getAuditingManager().auditEvent(factory);
622 public void auditExternalDownloadArtifact(ResponseFormat responseFormat, ResourceCommonInfo resourceCommonInfo,
623 DistributionData distributionData, String requestId, String currArtifactUuid, String userId) {
624 User modifier = new User();
625 modifier.setUserId(userId);
627 AuditEventFactory factory = new AuditDownloadArtifactExternalApiEventFactory(
628 CommonAuditData.newBuilder()
629 .description(getMessageString(responseFormat))
630 .status(responseFormat.getStatus())
631 .requestId(requestId)
633 resourceCommonInfo, distributionData,
634 ResourceVersionInfo.newBuilder()
635 .artifactUuid(currArtifactUuid)
638 getAuditingManager().auditEvent(factory);
641 private String buildAuditingArtifactData(ArtifactDefinition artifactDefinition) {
642 StringBuilder sb = new StringBuilder();
643 if (artifactDefinition != null) {
644 sb.append(artifactDefinition.getArtifactGroupType().getType())
647 .append(artifactDefinition.getArtifactLabel())
650 .append(artifactDefinition.getArtifactType())
652 .append(artifactDefinition.getArtifactName())
654 .append(artifactDefinition.getTimeout())
656 .append(artifactDefinition.getEsId());
659 sb.append(artifactDefinition.getArtifactVersion() != null ? artifactDefinition.getArtifactVersion() : " ");
661 sb.append(artifactDefinition.getArtifactUUID() != null ? artifactDefinition.getArtifactUUID() : " ");
663 return sb.toString();
666 public void auditCategory(ResponseFormat responseFormat, User modifier, String categoryName, String subCategoryName, String groupingName, AuditingActionEnum actionEnum, String componentType) {
667 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
669 AuditEventFactory factory = new AuditCategoryEventFactory(actionEnum,
670 CommonAuditData.newBuilder()
671 .description(getMessageString(responseFormat))
672 .status(responseFormat.getStatus())
673 .requestId(ThreadLocalsHolder.getUuid())
675 modifier, categoryName, subCategoryName, groupingName, componentType);
677 getAuditingManager().auditEvent(factory);
680 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse) {
682 return convertFromStorageResponse(storageResponse, ComponentTypeEnum.RESOURCE);
685 public ActionStatus convertFromStorageResponse(StorageOperationStatus storageResponse, ComponentTypeEnum type) {
687 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
688 if (storageResponse == null) {
691 switch (storageResponse) {
693 responseEnum = ActionStatus.OK;
695 case CONNECTION_FAILURE:
697 responseEnum = ActionStatus.GENERAL_ERROR;
700 responseEnum = ActionStatus.INVALID_CONTENT;
702 case ENTITY_ALREADY_EXISTS:
703 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
705 case PARENT_RESOURCE_NOT_FOUND:
706 responseEnum = ActionStatus.PARENT_RESOURCE_NOT_FOUND;
708 case MULTIPLE_PARENT_RESOURCE_FOUND:
709 responseEnum = ActionStatus.MULTIPLE_PARENT_RESOURCE_FOUND;
712 if (ComponentTypeEnum.RESOURCE == type) {
713 responseEnum = ActionStatus.RESOURCE_NOT_FOUND;
714 } else if (ComponentTypeEnum.PRODUCT == type) {
715 responseEnum = ActionStatus.PRODUCT_NOT_FOUND;
717 responseEnum = ActionStatus.SERVICE_NOT_FOUND;
720 case FAILED_TO_LOCK_ELEMENT:
721 responseEnum = ActionStatus.COMPONENT_IN_USE;
723 case ARTIFACT_NOT_FOUND:
724 responseEnum = ActionStatus.ARTIFACT_NOT_FOUND;
726 case DISTR_ENVIRONMENT_NOT_AVAILABLE:
727 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_AVAILABLE;
729 case DISTR_ENVIRONMENT_NOT_FOUND:
730 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_NOT_FOUND;
732 case DISTR_ENVIRONMENT_SENT_IS_INVALID:
733 responseEnum = ActionStatus.DISTRIBUTION_ENVIRONMENT_INVALID;
736 responseEnum = ActionStatus.INVALID_CONTENT;
739 responseEnum = ActionStatus.INVALID_CONTENT;
742 responseEnum = ActionStatus.CSAR_NOT_FOUND;
744 case PROPERTY_NAME_ALREADY_EXISTS:
745 responseEnum = ActionStatus.PROPERTY_NAME_ALREADY_EXISTS;
747 case MATCH_NOT_FOUND:
748 responseEnum = ActionStatus.COMPONENT_SUB_CATEGORY_NOT_FOUND_FOR_CATEGORY;
750 case CATEGORY_NOT_FOUND:
751 responseEnum = ActionStatus.COMPONENT_CATEGORY_NOT_FOUND;
753 case INVALID_PROPERTY:
754 responseEnum = ActionStatus.INVALID_PROPERTY;
756 case COMPONENT_IS_ARCHIVED:
757 responseEnum = ActionStatus.COMPONENT_IS_ARCHIVED;
760 responseEnum = ActionStatus.GENERAL_ERROR;
763 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
767 public ActionStatus convertFromToscaError(ToscaError toscaError) {
768 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
769 if (toscaError == null) {
772 switch (toscaError) {// TODO match errors
773 case NODE_TYPE_CAPABILITY_ERROR:
774 case NOT_SUPPORTED_TOSCA_TYPE:
775 case NODE_TYPE_REQUIREMENT_ERROR:
776 responseEnum = ActionStatus.INVALID_CONTENT;
779 responseEnum = ActionStatus.GENERAL_ERROR;
785 public ActionStatus convertFromStorageResponseForCapabilityType(StorageOperationStatus storageResponse) {
786 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
788 switch (storageResponse) {
790 responseEnum = ActionStatus.OK;
792 case CONNECTION_FAILURE:
794 responseEnum = ActionStatus.GENERAL_ERROR;
797 responseEnum = ActionStatus.INVALID_CONTENT;
799 case ENTITY_ALREADY_EXISTS:
800 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
802 case SCHEMA_VIOLATION:
803 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
806 responseEnum = ActionStatus.GENERAL_ERROR;
809 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
813 public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
814 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
816 switch (storageResponse) {
818 responseEnum = ActionStatus.OK;
820 case CONNECTION_FAILURE:
822 responseEnum = ActionStatus.GENERAL_ERROR;
825 responseEnum = ActionStatus.INVALID_CONTENT;
827 case ENTITY_ALREADY_EXISTS:
828 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
830 case SCHEMA_VIOLATION:
831 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
834 responseEnum = ActionStatus.GENERAL_ERROR;
837 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
841 public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
842 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
844 switch (storageResponse) {
846 responseEnum = ActionStatus.OK;
849 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
851 case INVALID_PROPERTY:
852 responseEnum = ActionStatus.INVALID_PROPERTY;
855 responseEnum = ActionStatus.GENERAL_ERROR;
858 responseEnum = ActionStatus.INVALID_CONTENT;
860 case MATCH_NOT_FOUND:
861 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
863 case SCHEMA_VIOLATION:
864 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
868 responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
870 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
874 responseEnum = ActionStatus.GENERAL_ERROR;
877 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
881 public ResponseFormat getResponseFormatForResourceInstance(ActionStatus actionStatus, String serviceName, String resourceInstanceName) {
882 ResponseFormat responseFormat;
884 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
885 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
888 responseFormat = getResponseFormat(actionStatus, serviceName);
890 return responseFormat;
893 public ResponseFormat getResponseFormatForResourceInstanceProperty(ActionStatus actionStatus, String resourceInstanceName) {
894 ResponseFormat responseFormat;
895 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
896 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
899 responseFormat = getResponseFormat(actionStatus);
901 return responseFormat;
904 public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
905 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
907 switch (storageResponse) {
909 responseEnum = ActionStatus.OK;
912 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
915 responseEnum = ActionStatus.GENERAL_ERROR;
918 responseEnum = ActionStatus.INVALID_CONTENT;
920 case MATCH_NOT_FOUND:
921 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
923 case SCHEMA_VIOLATION:
924 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
927 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
930 responseEnum = ActionStatus.GENERAL_ERROR;
933 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
937 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, String comment) {
938 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, comment, null, null);
941 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
942 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), ResourceVersionInfo.newBuilder().build());
945 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum, String comment) {
946 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), ResourceVersionInfo.newBuilder().build(), null,
947 comment, null, null);
950 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum, ResourceVersionInfo prevComponent) {
951 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), prevComponent);
954 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent) {
955 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, null, null, null);
958 public void auditComponent(ResponseFormat responseFormat, User modifier, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, String comment) {
959 auditComponent(responseFormat, modifier, null, actionEnum, resourceCommonInfo, ResourceVersionInfo.newBuilder().build(), null, comment, null, null);
962 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent) {
963 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, currComponent, null, null, null);
966 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent,
967 String comment, ArtifactDefinition artifactDefinition, String did) {
968 if (actionEnum != null) {
970 String currState = null;
971 String invariantUUID = null;
972 String currArtifactUid = null;
973 String currVersion = null;
974 String dcurrStatus = null;
976 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
978 String message = getMessageString(responseFormat);
979 int status = responseFormat.getStatus();
980 String artifactData = buildAuditingArtifactData(artifactDefinition);
982 if (component != null) {
983 // fields that are filled during creation and might still be empty
984 if (component.getLifecycleState() != null) {
985 currState = component.getLifecycleState().name();
987 uuid = component.getUUID();
988 invariantUUID = component.getInvariantUUID();
989 currVersion = component.getVersion();
990 if (StringUtils.isEmpty(resourceCommonInfo.getResourceName())) {
991 resourceCommonInfo.setResourceName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
994 if (currComponent != null) {
995 currArtifactUid = currComponent.getArtifactUuid();
996 dcurrStatus = currComponent.getDistributionStatus();
997 if (currState == null) { //probably it was not set
998 currState = currComponent.getState();
1000 if (currVersion == null) { //probably it was not set
1001 currVersion = currComponent.getVersion();
1004 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(
1006 CommonAuditData.newBuilder()
1008 .description(message)
1009 .requestId(ThreadLocalsHolder.getUuid())
1010 .serviceInstanceId(uuid)
1012 resourceCommonInfo, prevComponent,
1013 ResourceVersionInfo.newBuilder()
1014 .artifactUuid(currArtifactUid)
1016 .version(currVersion)
1017 .distributionStatus(dcurrStatus)
1020 modifier, artifactData, comment, did, null);
1022 getAuditingManager().auditEvent(factory);
1026 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String status) {
1027 auditDistributionEngine(action, environmentName, distributionTopicData, null, null, status);
1031 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role, String apiKey, String status) {
1032 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager.createDistributionEngineEventFactory(action,
1033 environmentName, distributionTopicData, role, apiKey, status);
1034 getAuditingManager().auditEvent(factory);
1038 public void auditEnvironmentEngine(AuditingActionEnum actionEnum, String environmentID,
1039 String environmentType, String action, String environmentName, String tenantContext) {
1040 AuditEventFactory factory = new AuditEcompOpEnvEventFactory(actionEnum, environmentID, environmentName,
1041 environmentType, action, tenantContext);
1042 getAuditingManager().auditEvent(factory);
1045 public void auditDistributionNotification(String serviceUUID, String resourceName, String resourceType, String currVersion, User modifier, String environmentName, String currState,
1046 String topicName, String distributionId, String description, String status, String workloadContext, String tenant) {
1048 AuditEventFactory factory = new AuditDistributionNotificationEventFactory(
1049 CommonAuditData.newBuilder()
1050 .serviceInstanceId(serviceUUID)
1052 .description(description)
1053 .requestId(ThreadLocalsHolder.getUuid())
1055 new ResourceCommonInfo(resourceName, resourceType),
1056 ResourceVersionInfo.newBuilder()
1058 .version(currVersion)
1060 distributionId, modifier, topicName,
1061 new OperationalEnvAuditData(environmentName, workloadContext, tenant));
1063 getAuditingManager().auditEvent(factory);
1066 public void auditAuthEvent(String url, String user, String authStatus, String realm) {
1067 AuditEventFactory factory = new AuditAuthRequestEventFactory(
1068 CommonAuditData.newBuilder()
1069 .requestId(ThreadLocalsHolder.getUuid())
1071 user, url, realm, authStatus);
1072 getAuditingManager().auditEvent(factory);
1075 public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName, String resourceUrl, String statusTime, String status, String errorReason) {
1076 ThreadLocalsHolder.setUuid(distributionId);
1078 AuditEventFactory factory = new AuditDistributionStatusEventFactory(
1079 CommonAuditData.newBuilder()
1080 .description(errorReason)
1082 .requestId(distributionId)
1084 new DistributionData(consumerId, resourceUrl),
1085 distributionId, topicName, statusTime);
1087 getAuditingManager().auditEvent(factory);
1090 public void auditGetUebCluster(String consumerId, String status, String description) {
1091 AuditEventFactory factory = new AuditGetUebClusterEventFactory(
1092 CommonAuditData.newBuilder()
1093 .description(description)
1095 .requestId(ThreadLocalsHolder.getUuid())
1099 getAuditingManager().auditEvent(factory);
1102 public void auditMissingInstanceIdAsDistributionEngineEvent(AuditingActionEnum actionEnum, String status) {
1103 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager.createDistributionEngineEventFactory(
1105 DistributionTopicData.newBuilder()
1106 .build(), null, null, status);
1107 getAuditingManager().auditEvent(factory);
1111 public void auditRegisterOrUnRegisterEvent(AuditingActionEnum action, String consumerId, String apiPublicKey, String envName, String status, String distributionStatus, String notifTopicName, String statusTopicName) {
1112 String appliedStatus = !StringUtils.isEmpty(status) ? status : distributionStatus;
1114 AuditEventFactory factory = new AuditRegUnregDistributionEngineEventFactory(action,
1115 CommonAuditData.newBuilder()
1116 .requestId(ThreadLocalsHolder.getUuid())
1117 .status(appliedStatus)
1119 DistributionTopicData.newBuilder()
1120 .statusTopic(statusTopicName)
1121 .notificationTopic(notifTopicName)
1123 consumerId, apiPublicKey, envName);
1125 getAuditingManager().auditEvent(factory);
1128 public void auditServiceDistributionDeployed(String serviceName, String serviceVersion, String serviceUUID, String distributionId, String status, String desc, User modifier) {
1130 AuditEventFactory factory = new AuditDistributionDeployEventFactory(
1131 CommonAuditData.newBuilder()
1132 .requestId(ThreadLocalsHolder.getUuid())
1133 .serviceInstanceId(serviceUUID)
1137 new ResourceCommonInfo(serviceName, "Service"),
1142 getAuditingManager().auditEvent(factory);
1146 public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat, User modifier) {
1147 AuditEventFactory factory = new AuditConsumerEventFactory(actionEnum,
1148 CommonAuditData.newBuilder()
1149 .description(getMessageString(responseFormat))
1150 .status(responseFormat.getStatus())
1151 .requestId(ThreadLocalsHolder.getUuid())
1153 modifier, consumer);
1155 getAuditingManager().auditEvent(factory);
1158 public void auditGetUsersList(User user, String details, ResponseFormat responseFormat) {
1160 AuditEventFactory factory = new AuditGetUsersListEventFactory(
1161 CommonAuditData.newBuilder()
1162 .description(getMessageString(responseFormat))
1163 .status(responseFormat.getStatus())
1164 .requestId(ThreadLocalsHolder.getUuid())
1167 getAuditingManager().auditEvent(factory);
1170 public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
1172 AuditEventFactory factory = new AuditUserAdminEventFactory(actionEnum,
1173 CommonAuditData.newBuilder()
1174 .description(getMessageString(responseFormat))
1175 .status(responseFormat.getStatus())
1176 .requestId(ThreadLocalsHolder.getUuid())
1178 modifier, userBefore, userAfter);
1180 getAuditingManager().auditEvent(factory);
1183 public void auditUserAccess(User user, ResponseFormat responseFormat) {
1185 AuditEventFactory factory = new AuditUserAccessEventFactory(CommonAuditData.newBuilder()
1186 .description(getMessageString(responseFormat))
1187 .status(responseFormat.getStatus())
1188 .requestId(ThreadLocalsHolder.getUuid())
1192 getAuditingManager().auditEvent(factory);
1195 public void auditGetCategoryHierarchy(User user, String details, ResponseFormat responseFormat) {
1197 AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(CommonAuditData.newBuilder()
1198 .description(getMessageString(responseFormat))
1199 .status(responseFormat.getStatus())
1200 .requestId(ThreadLocalsHolder.getUuid())
1204 getAuditingManager().auditEvent(factory);
1207 public ResponseFormat getResponseFormatByComponent(ActionStatus actionStatus, Component component, ComponentTypeEnum type) {
1208 if (component == null) {
1209 return getResponseFormat(actionStatus);
1211 ResponseFormat responseFormat;
1213 switch (actionStatus) {
1214 case COMPONENT_VERSION_ALREADY_EXIST:
1215 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, type.getValue(), component.getVersion());
1217 case RESOURCE_NOT_FOUND:
1218 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1220 case COMPONENT_NAME_ALREADY_EXIST:
1221 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(), component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1223 case COMPONENT_IN_USE:
1224 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, type.name().toLowerCase(), component.getUniqueId());
1226 case SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND:
1227 responseFormat = getResponseFormat(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1230 responseFormat = getResponseFormat(actionStatus);
1233 return responseFormat;
1236 public boolean validateStringNotEmpty(String value) {
1237 return value != null && !value.trim().isEmpty();
1240 public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
1241 ActionStatus responseEnum;
1243 switch (storageResponse) {
1245 responseEnum = ActionStatus.OK;
1247 case ENTITY_ALREADY_EXISTS:
1248 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
1251 responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
1254 responseEnum = ActionStatus.GENERAL_ERROR;
1257 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1258 return responseEnum;
1261 public ActionStatus convertFromResultStatusEnum(ResultStatusEnum resultStatus, JsonPresentationFields elementType) {
1262 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1263 switch (resultStatus) {
1265 responseEnum = ActionStatus.OK;
1267 case ELEMENT_NOT_FOUND:
1268 if(elementType!= null && elementType == JsonPresentationFields.PROPERTY){
1269 responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
1272 case INVALID_PROPERTY_DEFAULT_VALUE:
1273 case INVALID_PROPERTY_TYPE:
1274 case INVALID_PROPERTY_VALUE:
1275 case INVALID_PROPERTY_NAME:
1276 case MISSING_ENTRY_SCHEMA_TYPE:
1277 responseEnum = ActionStatus.INVALID_PROPERTY;
1280 responseEnum = ActionStatus.GENERAL_ERROR;
1283 return responseEnum;
1286 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus, AdditionalInfoParameterInfo additionalInfoParameterInfo, NodeTypeEnum nodeType, AdditionalInformationEnum labelOrValue) {
1288 if (additionalInfoParameterInfo == null) {
1289 additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
1291 if (labelOrValue == null) {
1292 labelOrValue = AdditionalInformationEnum.None;
1295 ResponseFormat responseFormat = null;
1296 switch (actionStatus) {
1297 case COMPONENT_NAME_ALREADY_EXIST:
1298 responseFormat = getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey());
1300 case ADDITIONAL_INFORMATION_EXCEEDS_LIMIT:
1301 responseFormat = getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(), ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString());
1303 case ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED:
1304 responseFormat = getResponseFormat(actionStatus, nodeType.name().toLowerCase());
1306 case ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED:
1307 responseFormat = getResponseFormat(actionStatus);
1309 case ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS:
1310 responseFormat = getResponseFormat(actionStatus);
1312 case ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS:
1313 responseFormat = getResponseFormat(actionStatus);
1315 case ADDITIONAL_INFORMATION_NOT_FOUND:
1316 responseFormat = getResponseFormat(actionStatus);
1319 responseFormat = getResponseFormat(actionStatus);
1323 return responseFormat;
1326 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus) {
1327 return getResponseFormatAdditionalProperty(actionStatus, null, null, null);
1330 public ActionStatus convertFromStorageResponseForConsumer(StorageOperationStatus storageResponse) {
1331 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1333 switch (storageResponse) {
1335 responseEnum = ActionStatus.OK;
1337 case CONNECTION_FAILURE:
1339 responseEnum = ActionStatus.GENERAL_ERROR;
1342 responseEnum = ActionStatus.INVALID_CONTENT;
1344 case ENTITY_ALREADY_EXISTS:
1345 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1347 case SCHEMA_VIOLATION:
1348 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1351 responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
1354 responseEnum = ActionStatus.GENERAL_ERROR;
1357 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1358 return responseEnum;
1361 public ActionStatus convertFromStorageResponseForGroupType(StorageOperationStatus storageResponse) {
1362 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1364 switch (storageResponse) {
1366 responseEnum = ActionStatus.OK;
1368 case CONNECTION_FAILURE:
1370 responseEnum = ActionStatus.GENERAL_ERROR;
1373 responseEnum = ActionStatus.INVALID_CONTENT;
1375 case ENTITY_ALREADY_EXISTS:
1376 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1378 case SCHEMA_VIOLATION:
1379 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1382 responseEnum = ActionStatus.GENERAL_ERROR;
1385 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1386 return responseEnum;
1389 public ActionStatus convertFromStorageResponseForDataType(StorageOperationStatus storageResponse) {
1390 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1392 switch (storageResponse) {
1394 responseEnum = ActionStatus.OK;
1396 case CONNECTION_FAILURE:
1398 responseEnum = ActionStatus.GENERAL_ERROR;
1401 responseEnum = ActionStatus.INVALID_CONTENT;
1403 case ENTITY_ALREADY_EXISTS:
1404 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1406 case SCHEMA_VIOLATION:
1407 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1409 case CANNOT_UPDATE_EXISTING_ENTITY:
1410 responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
1413 responseEnum = ActionStatus.GENERAL_ERROR;
1416 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1417 return responseEnum;
1420 public ResponseFormat getResponseFormatByGroupType(ActionStatus actionStatus, GroupTypeDefinition groupType) {
1421 if (groupType == null) {
1422 return getResponseFormat(actionStatus);
1424 ResponseFormat responseFormat;
1426 switch (actionStatus) {
1427 case GROUP_MEMBER_EMPTY:
1428 case GROUP_TYPE_ALREADY_EXIST:
1429 responseFormat = getResponseFormat(actionStatus, groupType.getType());
1432 responseFormat = getResponseFormat(actionStatus);
1435 return responseFormat;
1439 public ResponseFormat getResponseFormatByPolicyType(ActionStatus actionStatus, PolicyTypeDefinition policyType) {
1440 if (policyType == null) {
1441 return getResponseFormat(actionStatus);
1444 ResponseFormat responseFormat;
1445 if (actionStatus == ActionStatus.POLICY_TYPE_ALREADY_EXIST) {
1446 responseFormat = getResponseFormat(actionStatus, policyType.getType());
1449 responseFormat = getResponseFormat(actionStatus);
1451 return responseFormat;
1455 public ResponseFormat getResponseFormatByDataType(ActionStatus actionStatus, DataTypeDefinition dataType, List<String> properties) {
1456 if (dataType == null) {
1457 return getResponseFormat(actionStatus);
1459 ResponseFormat responseFormat;
1461 switch (actionStatus) {
1462 case DATA_TYPE_ALREADY_EXIST:
1463 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1465 case DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM:
1466 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1468 case DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY:
1469 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1471 case DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR:
1472 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1474 case DATA_TYPE_DERIVED_IS_MISSING:
1475 responseFormat = getResponseFormat(actionStatus, dataType.getDerivedFromName());
1477 case DATA_TYPE_DUPLICATE_PROPERTY:
1478 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1480 case DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE:
1481 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1483 case DATA_TYPE_CANNOT_HAVE_PROPERTIES:
1484 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1486 case DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST:
1487 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1491 responseFormat = getResponseFormat(actionStatus);
1494 return responseFormat;
1497 public StorageOperationStatus convertToStorageOperationStatus(CassandraOperationStatus cassandraStatus) {
1498 StorageOperationStatus result;
1499 switch (cassandraStatus) {
1501 result = StorageOperationStatus.OK;
1504 result = StorageOperationStatus.NOT_FOUND;
1506 case CLUSTER_NOT_CONNECTED:
1507 case KEYSPACE_NOT_CONNECTED:
1508 result = StorageOperationStatus.CONNECTION_FAILURE;
1511 result = StorageOperationStatus.GENERAL_ERROR;
1518 public ResponseFormat getResponseFormat(ComponentException exception) {
1519 ResponseFormat responseFormat = exception.getResponseFormat();
1520 if (responseFormat != null) {
1521 return responseFormat;
1523 return getResponseFormat(exception.getActionStatus(), exception.getParams());