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.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
23 import org.openecomp.sdc.be.dao.api.ActionStatus;
24 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
25 import org.openecomp.sdc.be.impl.ComponentsUtils;
26 import org.openecomp.sdc.be.model.Component;
27 import org.openecomp.sdc.be.model.User;
28 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
29 import org.openecomp.sdc.common.log.wrappers.Logger;
30 import org.openecomp.sdc.common.util.ValidationUtils;
31 import org.openecomp.sdc.exception.ResponseFormat;
33 @org.springframework.stereotype.Component
34 public class ComponentContactIdValidator implements ComponentFieldValidator {
36 private static final Logger log = Logger.getLogger(ComponentContactIdValidator.class.getName());
37 private ComponentsUtils componentsUtils;
39 public ComponentContactIdValidator(ComponentsUtils componentsUtils) {
40 this.componentsUtils = componentsUtils;
44 public void validateAndCorrectField(User user, Component component, AuditingActionEnum actionEnum) {
45 log.debug("validate component contactId");
46 ComponentTypeEnum type = component.getComponentType();
47 String contactId = component.getContactId();
48 if (!ValidationUtils.validateStringNotEmpty(contactId)) {
49 log.info("contact is missing.");
50 ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
51 componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
52 throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
54 validateContactId(contactId, user, component, actionEnum, type);
57 private void validateContactId(String contactId, User user, org.openecomp.sdc.be.model.Component component, AuditingActionEnum actionEnum,
58 ComponentTypeEnum type) {
59 if (contactId != null && !ValidationUtils.validateContactId(contactId)) {
60 log.info("contact is invalid.");
61 ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
62 componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
63 throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());