28efd150186e395ae4451933760b9cc2f41cdfbe
[dcaegen2/services.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : DataLake
4  * ================================================================================
5  * Copyright 2019 China Mobile
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.onap.datalake.feeder.service;
22
23
24 import org.onap.datalake.feeder.domain.Portal;
25 import org.onap.datalake.feeder.dto.PortalConfig;
26 import org.onap.datalake.feeder.repository.PortalRepository;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.stereotype.Service;
29
30 import java.util.ArrayList;
31 import java.util.List;
32
33 /**
34  * Service for portals
35  *
36  * @author guochunmeng
37  *
38  */
39 @Service
40 public class PortalService {
41
42     @Autowired
43     private PortalRepository portalRepository;
44
45     public Portal fillPortalConfiguration(PortalConfig portalConfig)
46     {
47         Portal portal = new Portal();
48         fillPortal(portalConfig, portal);
49         return portal;
50     }
51     public void fillPortalConfiguration(PortalConfig portalConfig, Portal portal)
52     {
53         fillPortal(portalConfig, portal);
54     }
55
56     private void fillPortal(PortalConfig portalConfig, Portal portal) {
57
58         portal.setName(portalConfig.getName());
59         portal.setLogin(portalConfig.getLogin());
60         portal.setPass(portalConfig.getPass());
61         portal.setEnabled(portalConfig.getEnabled());
62         portal.setHost(portalConfig.getHost());
63         portal.setPort(portalConfig.getPort());
64
65     }
66
67
68     public List<String> listNames(boolean enabled){
69
70         List<String> names = new ArrayList<>();
71         Iterable<Portal> ret = portalRepository.findByEnabled(enabled);
72         for(Portal portal:ret) {
73             names.add(portal.getName());
74         }
75
76         return names;
77     }
78
79 }