2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 * Modifications copyright (c) 2019 Nokia
20 * ================================================================================
22 package org.openecomp.sdc.be.components.impl;
24 import static java.util.Collections.emptySet;
26 import java.util.List;
29 import org.apache.commons.collections4.CollectionUtils;
30 import org.apache.commons.lang3.StringUtils;
31 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
32 import org.openecomp.sdc.be.components.validation.UserValidations;
33 import org.openecomp.sdc.be.config.ConfigurationManager;
34 import org.openecomp.sdc.be.dao.api.ActionStatus;
35 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
36 import org.openecomp.sdc.be.model.GroupTypeDefinition;
37 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
38 import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
42 @Component("groupTypeBusinessLogic")
43 public class GroupTypeBusinessLogic {
45 private final GroupTypeOperation groupTypeOperation;
46 private final JanusGraphDao janusGraphDao;
47 private final UserValidations userValidations;
50 public GroupTypeBusinessLogic(GroupTypeOperation groupTypeOperation, JanusGraphDao janusGraphDao, UserValidations userValidations) {
51 this.groupTypeOperation = groupTypeOperation;
52 this.janusGraphDao = janusGraphDao;
53 this.userValidations = userValidations;
56 public List<GroupTypeDefinition> getAllGroupTypes(String userId, String internalComponentType, String internalComponentModel) {
57 List<GroupTypeDefinition> groupTypes = null;
59 userValidations.validateUserExists(userId);
60 Set<String> excludeGroupTypes = getExcludedGroupTypes(internalComponentType);
61 groupTypes = groupTypeOperation.getAllGroupTypes(excludeGroupTypes, internalComponentModel);
64 if (CollectionUtils.isNotEmpty(groupTypes)) {
65 janusGraphDao.commit();
70 public GroupTypeDefinition getLatestGroupTypeByType(String groupTypeName, String modelName) {
71 return groupTypeOperation.getLatestGroupTypeByType(groupTypeName, modelName).left().on(e -> failOnGetGroupType(e, groupTypeName));
74 public Set<String> getExcludedGroupTypes(String internalComponentType) {
75 if (StringUtils.isEmpty(internalComponentType)) {
78 Map<String, Set<String>> excludedGroupTypesMapping = ConfigurationManager.getConfigurationManager().getConfiguration()
79 .getExcludedGroupTypesMapping();
80 Set<String> excludedTypes = excludedGroupTypesMapping.get(internalComponentType);
81 return excludedTypes == null ? emptySet() : excludedTypes;
84 private GroupTypeDefinition failOnGetGroupType(StorageOperationStatus status, String groupType) {
85 janusGraphDao.rollback();
86 if (status == StorageOperationStatus.NOT_FOUND) {
87 throw new ByActionStatusComponentException(ActionStatus.GROUP_TYPE_IS_INVALID, groupType);
89 throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);