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;
759 case DECLARED_INPUT_USED_BY_OPERATION:
760 responseEnum = ActionStatus.DECLARED_INPUT_USED_BY_OPERATION;
763 responseEnum = ActionStatus.GENERAL_ERROR;
766 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
770 public ActionStatus convertFromToscaError(ToscaError toscaError) {
771 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
772 if (toscaError == null) {
775 switch (toscaError) {// TODO match errors
776 case NODE_TYPE_CAPABILITY_ERROR:
777 case NOT_SUPPORTED_TOSCA_TYPE:
778 case NODE_TYPE_REQUIREMENT_ERROR:
779 responseEnum = ActionStatus.INVALID_CONTENT;
782 responseEnum = ActionStatus.GENERAL_ERROR;
788 public ActionStatus convertFromStorageResponseForCapabilityType(StorageOperationStatus storageResponse) {
789 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
791 switch (storageResponse) {
793 responseEnum = ActionStatus.OK;
795 case CONNECTION_FAILURE:
797 responseEnum = ActionStatus.GENERAL_ERROR;
800 responseEnum = ActionStatus.INVALID_CONTENT;
802 case ENTITY_ALREADY_EXISTS:
803 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
805 case SCHEMA_VIOLATION:
806 responseEnum = ActionStatus.CAPABILITY_TYPE_ALREADY_EXIST;
809 responseEnum = ActionStatus.GENERAL_ERROR;
812 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
816 public ActionStatus convertFromStorageResponseForLifecycleType(StorageOperationStatus storageResponse) {
817 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
819 switch (storageResponse) {
821 responseEnum = ActionStatus.OK;
823 case CONNECTION_FAILURE:
825 responseEnum = ActionStatus.GENERAL_ERROR;
828 responseEnum = ActionStatus.INVALID_CONTENT;
830 case ENTITY_ALREADY_EXISTS:
831 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
833 case SCHEMA_VIOLATION:
834 responseEnum = ActionStatus.LIFECYCLE_TYPE_ALREADY_EXIST;
837 responseEnum = ActionStatus.GENERAL_ERROR;
840 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
844 public ActionStatus convertFromStorageResponseForResourceInstance(StorageOperationStatus storageResponse, boolean isRelation) {
845 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
847 switch (storageResponse) {
849 responseEnum = ActionStatus.OK;
852 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
854 case INVALID_PROPERTY:
855 responseEnum = ActionStatus.INVALID_PROPERTY;
858 responseEnum = ActionStatus.GENERAL_ERROR;
861 responseEnum = ActionStatus.INVALID_CONTENT;
863 case MATCH_NOT_FOUND:
864 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
866 case SCHEMA_VIOLATION:
867 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
871 responseEnum = ActionStatus.RESOURCE_INSTANCE_RELATION_NOT_FOUND;
873 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
877 responseEnum = ActionStatus.GENERAL_ERROR;
880 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
884 public ResponseFormat getResponseFormatForResourceInstance(ActionStatus actionStatus, String serviceName, String resourceInstanceName) {
885 ResponseFormat responseFormat;
887 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
888 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
891 responseFormat = getResponseFormat(actionStatus, serviceName);
893 return responseFormat;
896 public ResponseFormat getResponseFormatForResourceInstanceProperty(ActionStatus actionStatus, String resourceInstanceName) {
897 ResponseFormat responseFormat;
898 if (actionStatus == ActionStatus.RESOURCE_INSTANCE_NOT_FOUND) {
899 responseFormat = getResponseFormat(actionStatus, resourceInstanceName);
902 responseFormat = getResponseFormat(actionStatus);
904 return responseFormat;
907 public ActionStatus convertFromStorageResponseForResourceInstanceProperty(StorageOperationStatus storageResponse) {
908 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
910 switch (storageResponse) {
912 responseEnum = ActionStatus.OK;
915 responseEnum = ActionStatus.RESOURCE_INSTANCE_BAD_REQUEST;
918 responseEnum = ActionStatus.GENERAL_ERROR;
921 responseEnum = ActionStatus.INVALID_CONTENT;
923 case MATCH_NOT_FOUND:
924 responseEnum = ActionStatus.RESOURCE_INSTANCE_MATCH_NOT_FOUND;
926 case SCHEMA_VIOLATION:
927 responseEnum = ActionStatus.RESOURCE_INSTANCE_ALREADY_EXIST;
930 responseEnum = ActionStatus.RESOURCE_INSTANCE_NOT_FOUND;
933 responseEnum = ActionStatus.GENERAL_ERROR;
936 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
940 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, String comment) {
941 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, comment, null, null);
944 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum) {
945 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), ResourceVersionInfo.newBuilder().build());
948 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum, String comment) {
949 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), ResourceVersionInfo.newBuilder().build(), null,
950 comment, null, null);
953 public void auditComponentAdmin(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ComponentTypeEnum typeEnum, ResourceVersionInfo prevComponent) {
954 auditComponent(responseFormat, modifier, component, actionEnum, new ResourceCommonInfo(typeEnum.getValue()), prevComponent);
957 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent) {
958 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, null, null, null, null);
961 public void auditComponent(ResponseFormat responseFormat, User modifier, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, String comment) {
962 auditComponent(responseFormat, modifier, null, actionEnum, resourceCommonInfo, ResourceVersionInfo.newBuilder().build(), null, comment, null, null);
965 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent) {
966 auditComponent(responseFormat, modifier, component, actionEnum, resourceCommonInfo, prevComponent, currComponent, null, null, null);
969 public void auditComponent(ResponseFormat responseFormat, User modifier, Component component, AuditingActionEnum actionEnum, ResourceCommonInfo resourceCommonInfo, ResourceVersionInfo prevComponent, ResourceVersionInfo currComponent,
970 String comment, ArtifactDefinition artifactDefinition, String did) {
971 if (actionEnum != null) {
973 String currState = null;
974 String invariantUUID = null;
975 String currArtifactUid = null;
976 String currVersion = null;
977 String dcurrStatus = null;
979 log.trace(INSIDE_AUDITING_FOR_AUDIT_ACTION, actionEnum);
981 String message = getMessageString(responseFormat);
982 int status = responseFormat.getStatus();
983 String artifactData = buildAuditingArtifactData(artifactDefinition);
985 if (component != null) {
986 // fields that are filled during creation and might still be empty
987 if (component.getLifecycleState() != null) {
988 currState = component.getLifecycleState().name();
990 uuid = component.getUUID();
991 invariantUUID = component.getInvariantUUID();
992 currVersion = component.getVersion();
993 if (StringUtils.isEmpty(resourceCommonInfo.getResourceName())) {
994 resourceCommonInfo.setResourceName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
997 if (currComponent != null) {
998 currArtifactUid = currComponent.getArtifactUuid();
999 dcurrStatus = currComponent.getDistributionStatus();
1000 if (currState == null) { //probably it was not set
1001 currState = currComponent.getState();
1003 if (currVersion == null) { //probably it was not set
1004 currVersion = currComponent.getVersion();
1007 AuditEventFactory factory = AuditResourceEventFactoryManager.createResourceEventFactory(
1009 CommonAuditData.newBuilder()
1011 .description(message)
1012 .requestId(ThreadLocalsHolder.getUuid())
1013 .serviceInstanceId(uuid)
1015 resourceCommonInfo, prevComponent,
1016 ResourceVersionInfo.newBuilder()
1017 .artifactUuid(currArtifactUid)
1019 .version(currVersion)
1020 .distributionStatus(dcurrStatus)
1023 modifier, artifactData, comment, did, null);
1025 getAuditingManager().auditEvent(factory);
1029 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String status) {
1030 auditDistributionEngine(action, environmentName, distributionTopicData, null, null, status);
1034 public void auditDistributionEngine(AuditingActionEnum action, String environmentName, DistributionTopicData distributionTopicData, String role, String apiKey, String status) {
1035 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager.createDistributionEngineEventFactory(action,
1036 environmentName, distributionTopicData, role, apiKey, status);
1037 getAuditingManager().auditEvent(factory);
1041 public void auditEnvironmentEngine(AuditingActionEnum actionEnum, String environmentID,
1042 String environmentType, String action, String environmentName, String tenantContext) {
1043 AuditEventFactory factory = new AuditEcompOpEnvEventFactory(actionEnum, environmentID, environmentName,
1044 environmentType, action, tenantContext);
1045 getAuditingManager().auditEvent(factory);
1048 public void auditDistributionNotification(String serviceUUID, String resourceName, String resourceType, String currVersion, User modifier, String environmentName, String currState,
1049 String topicName, String distributionId, String description, String status, String workloadContext, String tenant) {
1051 AuditEventFactory factory = new AuditDistributionNotificationEventFactory(
1052 CommonAuditData.newBuilder()
1053 .serviceInstanceId(serviceUUID)
1055 .description(description)
1056 .requestId(ThreadLocalsHolder.getUuid())
1058 new ResourceCommonInfo(resourceName, resourceType),
1059 ResourceVersionInfo.newBuilder()
1061 .version(currVersion)
1063 distributionId, modifier, topicName,
1064 new OperationalEnvAuditData(environmentName, workloadContext, tenant));
1066 getAuditingManager().auditEvent(factory);
1069 public void auditAuthEvent(String url, String user, String authStatus, String realm) {
1070 AuditEventFactory factory = new AuditAuthRequestEventFactory(
1071 CommonAuditData.newBuilder()
1072 .requestId(ThreadLocalsHolder.getUuid())
1074 user, url, realm, authStatus);
1075 getAuditingManager().auditEvent(factory);
1078 public void auditDistributionStatusNotification(String distributionId, String consumerId, String topicName, String resourceUrl, String statusTime, String status, String errorReason) {
1079 ThreadLocalsHolder.setUuid(distributionId);
1081 AuditEventFactory factory = new AuditDistributionStatusEventFactory(
1082 CommonAuditData.newBuilder()
1083 .description(errorReason)
1085 .requestId(distributionId)
1087 new DistributionData(consumerId, resourceUrl),
1088 distributionId, topicName, statusTime);
1090 getAuditingManager().auditEvent(factory);
1093 public void auditGetUebCluster(String consumerId, String status, String description) {
1094 AuditEventFactory factory = new AuditGetUebClusterEventFactory(
1095 CommonAuditData.newBuilder()
1096 .description(description)
1098 .requestId(ThreadLocalsHolder.getUuid())
1102 getAuditingManager().auditEvent(factory);
1105 public void auditMissingInstanceIdAsDistributionEngineEvent(AuditingActionEnum actionEnum, String status) {
1106 AuditEventFactory factory = AuditDistributionEngineEventFactoryManager.createDistributionEngineEventFactory(
1108 DistributionTopicData.newBuilder()
1109 .build(), null, null, status);
1110 getAuditingManager().auditEvent(factory);
1114 public void auditRegisterOrUnRegisterEvent(AuditingActionEnum action, String consumerId, String apiPublicKey, String envName, String status, String distributionStatus, String notifTopicName, String statusTopicName) {
1115 String appliedStatus = !StringUtils.isEmpty(status) ? status : distributionStatus;
1117 AuditEventFactory factory = new AuditRegUnregDistributionEngineEventFactory(action,
1118 CommonAuditData.newBuilder()
1119 .requestId(ThreadLocalsHolder.getUuid())
1120 .status(appliedStatus)
1122 DistributionTopicData.newBuilder()
1123 .statusTopic(statusTopicName)
1124 .notificationTopic(notifTopicName)
1126 consumerId, apiPublicKey, envName);
1128 getAuditingManager().auditEvent(factory);
1131 public void auditServiceDistributionDeployed(String serviceName, String serviceVersion, String serviceUUID, String distributionId, String status, String desc, User modifier) {
1133 AuditEventFactory factory = new AuditDistributionDeployEventFactory(
1134 CommonAuditData.newBuilder()
1135 .requestId(ThreadLocalsHolder.getUuid())
1136 .serviceInstanceId(serviceUUID)
1140 new ResourceCommonInfo(serviceName, "Service"),
1145 getAuditingManager().auditEvent(factory);
1149 public void auditConsumerCredentialsEvent(AuditingActionEnum actionEnum, ConsumerDefinition consumer, ResponseFormat responseFormat, User modifier) {
1150 AuditEventFactory factory = new AuditConsumerEventFactory(actionEnum,
1151 CommonAuditData.newBuilder()
1152 .description(getMessageString(responseFormat))
1153 .status(responseFormat.getStatus())
1154 .requestId(ThreadLocalsHolder.getUuid())
1156 modifier, consumer);
1158 getAuditingManager().auditEvent(factory);
1161 public void auditGetUsersList(User user, String details, ResponseFormat responseFormat) {
1163 AuditEventFactory factory = new AuditGetUsersListEventFactory(
1164 CommonAuditData.newBuilder()
1165 .description(getMessageString(responseFormat))
1166 .status(responseFormat.getStatus())
1167 .requestId(ThreadLocalsHolder.getUuid())
1170 getAuditingManager().auditEvent(factory);
1173 public void auditAdminUserAction(AuditingActionEnum actionEnum, User modifier, User userBefore, User userAfter, ResponseFormat responseFormat) {
1175 AuditEventFactory factory = new AuditUserAdminEventFactory(actionEnum,
1176 CommonAuditData.newBuilder()
1177 .description(getMessageString(responseFormat))
1178 .status(responseFormat.getStatus())
1179 .requestId(ThreadLocalsHolder.getUuid())
1181 modifier, userBefore, userAfter);
1183 getAuditingManager().auditEvent(factory);
1186 public void auditUserAccess(User user, ResponseFormat responseFormat) {
1188 AuditEventFactory factory = new AuditUserAccessEventFactory(CommonAuditData.newBuilder()
1189 .description(getMessageString(responseFormat))
1190 .status(responseFormat.getStatus())
1191 .requestId(ThreadLocalsHolder.getUuid())
1195 getAuditingManager().auditEvent(factory);
1198 public void auditGetCategoryHierarchy(User user, String details, ResponseFormat responseFormat) {
1200 AuditEventFactory factory = new AuditGetCategoryHierarchyEventFactory(CommonAuditData.newBuilder()
1201 .description(getMessageString(responseFormat))
1202 .status(responseFormat.getStatus())
1203 .requestId(ThreadLocalsHolder.getUuid())
1207 getAuditingManager().auditEvent(factory);
1210 public ResponseFormat getResponseFormatByComponent(ActionStatus actionStatus, Component component, ComponentTypeEnum type) {
1211 if (component == null) {
1212 return getResponseFormat(actionStatus);
1214 ResponseFormat responseFormat;
1216 switch (actionStatus) {
1217 case COMPONENT_VERSION_ALREADY_EXIST:
1218 responseFormat = getResponseFormat(ActionStatus.COMPONENT_VERSION_ALREADY_EXIST, type.getValue(), component.getVersion());
1220 case RESOURCE_NOT_FOUND:
1221 responseFormat = getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1223 case COMPONENT_NAME_ALREADY_EXIST:
1224 responseFormat = getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, type.getValue(), component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1226 case COMPONENT_IN_USE:
1227 responseFormat = getResponseFormat(ActionStatus.COMPONENT_IN_USE, type.name().toLowerCase(), component.getUniqueId());
1229 case SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND:
1230 responseFormat = getResponseFormat(ActionStatus.SERVICE_DEPLOYMENT_ARTIFACT_NOT_FOUND, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
1233 responseFormat = getResponseFormat(actionStatus);
1236 return responseFormat;
1239 public boolean validateStringNotEmpty(String value) {
1240 return value != null && !value.trim().isEmpty();
1243 public ActionStatus convertFromStorageResponseForAdditionalInformation(StorageOperationStatus storageResponse) {
1244 ActionStatus responseEnum;
1246 switch (storageResponse) {
1248 responseEnum = ActionStatus.OK;
1250 case ENTITY_ALREADY_EXISTS:
1251 responseEnum = ActionStatus.COMPONENT_NAME_ALREADY_EXIST;
1254 responseEnum = ActionStatus.ADDITIONAL_INFORMATION_NOT_FOUND;
1257 responseEnum = ActionStatus.GENERAL_ERROR;
1260 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1261 return responseEnum;
1264 public ActionStatus convertFromResultStatusEnum(ResultStatusEnum resultStatus, JsonPresentationFields elementType) {
1265 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1266 switch (resultStatus) {
1268 responseEnum = ActionStatus.OK;
1270 case ELEMENT_NOT_FOUND:
1271 if(elementType!= null && elementType == JsonPresentationFields.PROPERTY){
1272 responseEnum = ActionStatus.PROPERTY_NOT_FOUND;
1275 case INVALID_PROPERTY_DEFAULT_VALUE:
1276 case INVALID_PROPERTY_TYPE:
1277 case INVALID_PROPERTY_VALUE:
1278 case INVALID_PROPERTY_NAME:
1279 case MISSING_ENTRY_SCHEMA_TYPE:
1280 responseEnum = ActionStatus.INVALID_PROPERTY;
1283 responseEnum = ActionStatus.GENERAL_ERROR;
1286 return responseEnum;
1289 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus, AdditionalInfoParameterInfo additionalInfoParameterInfo, NodeTypeEnum nodeType, AdditionalInformationEnum labelOrValue) {
1291 if (additionalInfoParameterInfo == null) {
1292 additionalInfoParameterInfo = new AdditionalInfoParameterInfo();
1294 if (labelOrValue == null) {
1295 labelOrValue = AdditionalInformationEnum.None;
1298 ResponseFormat responseFormat = null;
1299 switch (actionStatus) {
1300 case COMPONENT_NAME_ALREADY_EXIST:
1301 responseFormat = getResponseFormat(actionStatus, "Additional parameter", additionalInfoParameterInfo.getKey());
1303 case ADDITIONAL_INFORMATION_EXCEEDS_LIMIT:
1304 responseFormat = getResponseFormat(actionStatus, labelOrValue.name().toLowerCase(), ValidationUtils.ADDITIONAL_INFORMATION_KEY_MAX_LENGTH.toString());
1306 case ADDITIONAL_INFORMATION_MAX_NUMBER_REACHED:
1307 responseFormat = getResponseFormat(actionStatus, nodeType.name().toLowerCase());
1309 case ADDITIONAL_INFORMATION_EMPTY_STRING_NOT_ALLOWED:
1310 responseFormat = getResponseFormat(actionStatus);
1312 case ADDITIONAL_INFORMATION_KEY_NOT_ALLOWED_CHARACTERS:
1313 responseFormat = getResponseFormat(actionStatus);
1315 case ADDITIONAL_INFORMATION_VALUE_NOT_ALLOWED_CHARACTERS:
1316 responseFormat = getResponseFormat(actionStatus);
1318 case ADDITIONAL_INFORMATION_NOT_FOUND:
1319 responseFormat = getResponseFormat(actionStatus);
1322 responseFormat = getResponseFormat(actionStatus);
1326 return responseFormat;
1329 public ResponseFormat getResponseFormatAdditionalProperty(ActionStatus actionStatus) {
1330 return getResponseFormatAdditionalProperty(actionStatus, null, null, null);
1333 public ActionStatus convertFromStorageResponseForConsumer(StorageOperationStatus storageResponse) {
1334 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1336 switch (storageResponse) {
1338 responseEnum = ActionStatus.OK;
1340 case CONNECTION_FAILURE:
1342 responseEnum = ActionStatus.GENERAL_ERROR;
1345 responseEnum = ActionStatus.INVALID_CONTENT;
1347 case ENTITY_ALREADY_EXISTS:
1348 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1350 case SCHEMA_VIOLATION:
1351 responseEnum = ActionStatus.CONSUMER_ALREADY_EXISTS;
1354 responseEnum = ActionStatus.ECOMP_USER_NOT_FOUND;
1357 responseEnum = ActionStatus.GENERAL_ERROR;
1360 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1361 return responseEnum;
1364 public ActionStatus convertFromStorageResponseForGroupType(StorageOperationStatus storageResponse) {
1365 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1367 switch (storageResponse) {
1369 responseEnum = ActionStatus.OK;
1371 case CONNECTION_FAILURE:
1373 responseEnum = ActionStatus.GENERAL_ERROR;
1376 responseEnum = ActionStatus.INVALID_CONTENT;
1378 case ENTITY_ALREADY_EXISTS:
1379 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1381 case SCHEMA_VIOLATION:
1382 responseEnum = ActionStatus.GROUP_TYPE_ALREADY_EXIST;
1385 responseEnum = ActionStatus.GENERAL_ERROR;
1388 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1389 return responseEnum;
1392 public ActionStatus convertFromStorageResponseForDataType(StorageOperationStatus storageResponse) {
1393 ActionStatus responseEnum = ActionStatus.GENERAL_ERROR;
1395 switch (storageResponse) {
1397 responseEnum = ActionStatus.OK;
1399 case CONNECTION_FAILURE:
1401 responseEnum = ActionStatus.GENERAL_ERROR;
1404 responseEnum = ActionStatus.INVALID_CONTENT;
1406 case ENTITY_ALREADY_EXISTS:
1407 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1409 case SCHEMA_VIOLATION:
1410 responseEnum = ActionStatus.DATA_TYPE_ALREADY_EXIST;
1412 case CANNOT_UPDATE_EXISTING_ENTITY:
1413 responseEnum = ActionStatus.DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST;
1416 responseEnum = ActionStatus.GENERAL_ERROR;
1419 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1420 return responseEnum;
1423 public ResponseFormat getResponseFormatByGroupType(ActionStatus actionStatus, GroupTypeDefinition groupType) {
1424 if (groupType == null) {
1425 return getResponseFormat(actionStatus);
1427 ResponseFormat responseFormat;
1429 switch (actionStatus) {
1430 case GROUP_MEMBER_EMPTY:
1431 case GROUP_TYPE_ALREADY_EXIST:
1432 responseFormat = getResponseFormat(actionStatus, groupType.getType());
1435 responseFormat = getResponseFormat(actionStatus);
1438 return responseFormat;
1442 public ResponseFormat getResponseFormatByPolicyType(ActionStatus actionStatus, PolicyTypeDefinition policyType) {
1443 if (policyType == null) {
1444 return getResponseFormat(actionStatus);
1447 ResponseFormat responseFormat;
1448 if (actionStatus == ActionStatus.POLICY_TYPE_ALREADY_EXIST) {
1449 responseFormat = getResponseFormat(actionStatus, policyType.getType());
1452 responseFormat = getResponseFormat(actionStatus);
1454 return responseFormat;
1458 public ResponseFormat getResponseFormatByDataType(ActionStatus actionStatus, DataTypeDefinition dataType, List<String> properties) {
1459 if (dataType == null) {
1460 return getResponseFormat(actionStatus);
1462 ResponseFormat responseFormat;
1464 switch (actionStatus) {
1465 case DATA_TYPE_ALREADY_EXIST:
1466 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1468 case DATA_TYPE_NOR_PROPERTIES_NEITHER_DERIVED_FROM:
1469 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1471 case DATA_TYPE_PROPERTIES_CANNOT_BE_EMPTY:
1472 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1474 case DATA_TYPE_PROPERTY_ALREADY_DEFINED_IN_ANCESTOR:
1475 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1477 case DATA_TYPE_DERIVED_IS_MISSING:
1478 responseFormat = getResponseFormat(actionStatus, dataType.getDerivedFromName());
1480 case DATA_TYPE_DUPLICATE_PROPERTY:
1481 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1483 case DATA_TYPE_PROEPRTY_CANNOT_HAVE_SAME_TYPE_OF_DATA_TYPE:
1484 responseFormat = getResponseFormat(actionStatus, dataType.getName(), properties == null ? "" : String.valueOf(properties));
1486 case DATA_TYPE_CANNOT_HAVE_PROPERTIES:
1487 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1489 case DATA_TYPE_CANNOT_BE_UPDATED_BAD_REQUEST:
1490 responseFormat = getResponseFormat(actionStatus, dataType.getName());
1494 responseFormat = getResponseFormat(actionStatus);
1497 return responseFormat;
1500 public StorageOperationStatus convertToStorageOperationStatus(CassandraOperationStatus cassandraStatus) {
1501 StorageOperationStatus result;
1502 switch (cassandraStatus) {
1504 result = StorageOperationStatus.OK;
1507 result = StorageOperationStatus.NOT_FOUND;
1509 case CLUSTER_NOT_CONNECTED:
1510 case KEYSPACE_NOT_CONNECTED:
1511 result = StorageOperationStatus.CONNECTION_FAILURE;
1514 result = StorageOperationStatus.GENERAL_ERROR;
1521 public ResponseFormat getResponseFormat(ComponentException exception) {
1522 ResponseFormat responseFormat = exception.getResponseFormat();
1523 if (responseFormat != null) {
1524 return responseFormat;
1526 return getResponseFormat(exception.getActionStatus(), exception.getParams());
1528 public ActionStatus convertFromStorageResponseForRelationshipType(
1529 StorageOperationStatus storageResponse) {
1530 ActionStatus responseEnum;
1532 switch (storageResponse) {
1534 responseEnum = ActionStatus.OK;
1536 case CONNECTION_FAILURE:
1538 responseEnum = ActionStatus.GENERAL_ERROR;
1541 responseEnum = ActionStatus.INVALID_CONTENT;
1543 case ENTITY_ALREADY_EXISTS:
1544 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1546 case SCHEMA_VIOLATION:
1547 responseEnum = ActionStatus.RELATIONSHIP_TYPE_ALREADY_EXIST;
1550 responseEnum = ActionStatus.GENERAL_ERROR;
1553 log.debug(CONVERT_STORAGE_RESPONSE_TO_ACTION_RESPONSE, storageResponse, responseEnum);
1554 return responseEnum;