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 org.apache.commons.lang3.StringUtils;
25 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
26 import org.openecomp.sdc.be.components.validation.UserValidations;
27 import org.openecomp.sdc.be.config.ConfigurationManager;
28 import org.openecomp.sdc.be.dao.api.ActionStatus;
29 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
30 import org.openecomp.sdc.be.impl.ComponentsUtils;
31 import org.openecomp.sdc.be.model.GroupTypeDefinition;
32 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
33 import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation;
34 import org.springframework.stereotype.Component;
36 import java.util.List;
40 import static java.util.Collections.emptySet;
42 @Component("groupTypeBusinessLogic")
43 public class GroupTypeBusinessLogic {
45 private final GroupTypeOperation groupTypeOperation;
46 private final JanusGraphDao janusGraphDao;
47 private final UserValidations userValidations;
48 private final ComponentsUtils componentsUtils;
50 public GroupTypeBusinessLogic(GroupTypeOperation groupTypeOperation, JanusGraphDao janusGraphDao, UserValidations userValidations, ComponentsUtils componentsUtils) {
51 this.groupTypeOperation = groupTypeOperation;
52 this.janusGraphDao = janusGraphDao;
53 this.userValidations = userValidations;
54 this.componentsUtils = componentsUtils;
58 public List<GroupTypeDefinition> getAllGroupTypes(String userId, String internalComponentType) {
60 userValidations.validateUserExists(userId, "get group types", true);
61 Set<String> excludeGroupTypes = getExcludedGroupTypes(internalComponentType);
62 return groupTypeOperation.getAllGroupTypes(excludeGroupTypes);
64 janusGraphDao.commit();
68 public GroupTypeDefinition getLatestGroupTypeByType(String groupTypeName) {
69 return groupTypeOperation.getLatestGroupTypeByType(groupTypeName, true)
71 .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().getExcludedGroupTypesMapping();
79 Set<String> excludedTypes = excludedGroupTypesMapping.get(internalComponentType);
80 return excludedTypes == null ? emptySet() : excludedTypes;
83 private GroupTypeDefinition failOnGetGroupType(StorageOperationStatus status, String groupType) {
84 janusGraphDao.rollback();
85 if (status == StorageOperationStatus.NOT_FOUND) {
86 throw new ByActionStatusComponentException(ActionStatus.GROUP_TYPE_IS_INVALID, groupType);
88 throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);