Catalog alignment
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / facade / operations / CatalogOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  */
20
21 package org.openecomp.sdc.be.facade.operations;
22
23 import org.openecomp.sdc.be.catalog.api.IComponentMessage;
24 import org.openecomp.sdc.be.catalog.api.IStatus;
25 import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum;
26 import org.openecomp.sdc.be.catalog.impl.ComponentMessage;
27 import org.openecomp.sdc.be.catalog.impl.DmaapProducer;
28 import org.openecomp.sdc.be.dao.api.ActionStatus;
29 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
30 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
31 import org.openecomp.sdc.be.model.CatalogUpdateTimestamp;
32 import org.openecomp.sdc.be.model.Component;
33 import org.openecomp.sdc.be.model.Resource;
34 import org.openecomp.sdc.common.log.wrappers.Logger;
35
36 import java.util.Arrays;
37 import java.util.List;
38
39
40 @org.springframework.stereotype.Component
41 public class CatalogOperation {
42     
43     private static final Logger log = Logger.getLogger(CatalogOperation.class); 
44     
45     private static final List<ResourceTypeEnum> EXCLUDE_TYPES = Arrays.asList(ResourceTypeEnum.VFCMT, ResourceTypeEnum.Configuration);
46     
47     private final DmaapProducer msProducer;
48     
49     public CatalogOperation(DmaapProducer msProducer){
50         this.msProducer = msProducer;
51     }
52     
53     public ActionStatus updateCatalog(ChangeTypeEnum changeTypeEnum, Component component){
54         ActionStatus result = ActionStatus.OK;
55        try{
56             if(isNeedToUpdateCatalog(component)){
57                 IComponentMessage message = new ComponentMessage(component, changeTypeEnum, CatalogUpdateTimestamp.buildDummyCatalogUpdateTimestamp());
58                 IStatus status = msProducer.pushMessage(message);
59                 result = FacadeOperationUtils.convertStatusToActionStatus(status);
60             }
61            
62        }catch(Exception e){
63            log.debug("updateCatalog - failed to updateCatalog and send notification {}", e.getMessage());
64            return ActionStatus.OK;
65        }
66         return result;
67     }
68     
69     private boolean isNeedToUpdateCatalog(Component component) {
70           boolean isUpdateCatalog = true;
71              if(component.getComponentType() == ComponentTypeEnum.RESOURCE){
72                  return ((Resource)component).isAbstract() || EXCLUDE_TYPES.contains(((Resource)component).getResourceType())? false : true;
73                
74               }
75             return isUpdateCatalog;
76      }
77
78
79     public DmaapProducer getMsProducer() {
80         return msProducer;
81     }
82     
83 }