2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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=========================================================
20 package org.openecomp.sdc.be.components.validation.component;
22 import org.apache.commons.lang3.StringUtils;
23 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
24 import org.openecomp.sdc.be.dao.api.ActionStatus;
25 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
26 import org.openecomp.sdc.be.impl.ComponentsUtils;
27 import org.openecomp.sdc.be.model.Component;
28 import org.openecomp.sdc.be.model.User;
29 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
30 import org.openecomp.sdc.common.log.wrappers.Logger;
31 import org.openecomp.sdc.common.util.ValidationUtils;
32 import org.openecomp.sdc.exception.ResponseFormat;
34 @org.springframework.stereotype.Component
35 public class ComponentContactIdValidator implements ComponentFieldValidator {
37 private static final Logger log = Logger.getLogger(ComponentContactIdValidator.class.getName());
38 private ComponentsUtils componentsUtils;
40 public ComponentContactIdValidator(ComponentsUtils componentsUtils) {
41 this.componentsUtils = componentsUtils;
45 public void validateAndCorrectField(User user, Component component, AuditingActionEnum actionEnum) {
46 log.debug("validate component contactId");
47 ComponentTypeEnum type = component.getComponentType();
48 String contactId = component.getContactId();
49 if (StringUtils.isEmpty(contactId)) {
50 log.info("contact is missing.");
51 ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
52 componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
53 throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
55 validateContactId(contactId, user, component, actionEnum, type);
58 private void validateContactId(String contactId, User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum,
59 ComponentTypeEnum type) {
60 if (contactId != null && !ValidationUtils.validateContactId(contactId)) {
61 log.info("contact is invalid.");
62 ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
63 componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
64 throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());