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.components.clean;
23 import java.util.HashMap;
24 import java.util.List;
27 import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
28 import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
29 import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
30 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
31 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
32 import org.openecomp.sdc.exception.ResponseFormat;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
38 import fj.data.Either;
40 @Component("componentsCleanBusinessLogic")
41 public class ComponentsCleanBusinessLogic extends BaseBusinessLogic {
44 private ResourceBusinessLogic resourceBusinessLogic;
47 private ServiceBusinessLogic serviceBusinessLogic;
49 private static Logger log = LoggerFactory.getLogger(ComponentsCleanBusinessLogic.class.getName());
51 public Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanComponents(List<NodeTypeEnum> componentsToClean) {
53 Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanedComponents = new HashMap<NodeTypeEnum, Either<List<String>, ResponseFormat>>();
55 log.trace("start cleanComponents");
56 for (NodeTypeEnum type : componentsToClean) {
59 processDeletionForType(cleanedComponents, NodeTypeEnum.Resource, resourceBusinessLogic);
62 processDeletionForType(cleanedComponents, NodeTypeEnum.Service, serviceBusinessLogic);
65 log.debug("{} component type does not have cleaning method defined", type);
70 log.trace("end cleanComponents");
71 return cleanedComponents;
74 private void processDeletionForType(Map<NodeTypeEnum, Either<List<String>, ResponseFormat>> cleanedComponents, NodeTypeEnum type, ComponentBusinessLogic componentBusinessLogic) {
75 Either<List<String>, ResponseFormat> deleteMarkedResources = componentBusinessLogic.deleteMarkedComponents();
76 if (deleteMarkedResources.isRight()) {
77 log.debug("failed to clean deleted components of type {}. error: {}", type, deleteMarkedResources.right().value().getFormattedMessage());
79 if (log.isDebugEnabled()) {
80 StringBuilder sb = new StringBuilder("list of deleted components - type " + type + ": ");
81 for (String id : deleteMarkedResources.left().value()) {
82 sb.append(id).append(", ");
84 log.debug(sb.toString());
87 cleanedComponents.put(type, deleteMarkedResources);