diff options
Diffstat (limited to 'components/datalake-handler/des/src/main/java/org/onap/datalake/des/service/DataExposureService.java')
-rw-r--r-- | components/datalake-handler/des/src/main/java/org/onap/datalake/des/service/DataExposureService.java | 121 |
1 files changed, 66 insertions, 55 deletions
diff --git a/components/datalake-handler/des/src/main/java/org/onap/datalake/des/service/DataExposureService.java b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/service/DataExposureService.java index c7d642b5..6ba41604 100644 --- a/components/datalake-handler/des/src/main/java/org/onap/datalake/des/service/DataExposureService.java +++ b/components/datalake-handler/des/src/main/java/org/onap/datalake/des/service/DataExposureService.java @@ -20,23 +20,22 @@ package org.onap.datalake.des.service; -import java.io.IOException; -import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Optional; + import org.onap.datalake.des.domain.DataExposure; +import org.onap.datalake.des.domain.Db; import org.onap.datalake.des.dto.DataExposureConfig; import org.onap.datalake.des.repository.DataExposureRepository; -import org.onap.datalake.feeder.domain.Db; -import org.onap.datalake.feeder.repository.DbRepository; +import org.onap.datalake.des.repository.DbRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** - * Service for DataExposure + * Service for DataExposure. * * @author Kai Lu * @@ -44,88 +43,100 @@ import org.springframework.stereotype.Service; @Service public class DataExposureService { - private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Autowired - private DataExposureRepository dataExposureRepository; - @Autowired - private DbRepository dbRepository; + private final Logger log = LoggerFactory.getLogger(this.getClass()); + @Autowired + private DataExposureRepository dataExposureRepository; + @Autowired + private DbRepository dbRepository; /** * getDataExposure. * * @param serviceId serviceId * - * @return DataExposure + * @return DataExposure * */ - public DataExposure getDataExposure(String serviceId) { - Optional<DataExposure> ret = dataExposureRepository.findById(serviceId); - return ret.isPresent() ? ret.get() : null; - } + public DataExposure getDataExposure(String serviceId) { + Optional<DataExposure> ret = dataExposureRepository.findById(serviceId); + return ret.isPresent() ? ret.get() : null; + } - public List<DataExposureConfig> queryAllDataExposure() { - List<DataExposure> dataExposureList = null; - List<DataExposureConfig> dataExposureConfigList = new ArrayList<>(); - dataExposureList = (List<DataExposure>) dataExposureRepository.findAll(); - if (!dataExposureList.isEmpty()) { - log.info("DataExposureList is not null"); - for (DataExposure dataExposure : dataExposureList) { - dataExposureConfigList.add(dataExposure.getDataExposureConfig()); - } - } - return dataExposureConfigList; - } + /** + * getDataExposure. + * + * @return DataExposure + * + */ + public List<DataExposureConfig> queryAllDataExposure() { + List<DataExposure> dataExposureList = null; + List<DataExposureConfig> dataExposureConfigList = new ArrayList<>(); + dataExposureList = (List<DataExposure>) dataExposureRepository.findAll(); + if (!dataExposureList.isEmpty()) { + log.info("DataExposureList is not null"); + for (DataExposure dataExposure : dataExposureList) { + dataExposureConfigList.add(dataExposure.getDataExposureConfig()); + } + } + return dataExposureConfigList; + } /** * getDataExposureById. * * @param id id * - * @return data exposure + * @return data exposure * */ - public DataExposure getDataExposureById(String id) { - Optional<DataExposure> ret = dataExposureRepository.findById(id); - return ret.isPresent() ? ret.get() : null; - } + public DataExposure getDataExposureById(String id) { + Optional<DataExposure> ret = dataExposureRepository.findById(id); + return ret.isPresent() ? ret.get() : null; + } /** * fillDataExposureConfiguration. * * @param dataExposureConfig DataExposureConfig * - * @return data exposure + * @return data exposure * */ - public DataExposure fillDataExposureConfiguration(DataExposureConfig dataExposureConfig) { - DataExposure dataExposure = new DataExposure(); - fillDataExposure(dataExposureConfig, dataExposure); - return dataExposure; - } + public DataExposure fillDataExposureConfiguration(DataExposureConfig dataExposureConfig) { + DataExposure dataExposure = new DataExposure(); + fillDataExposure(dataExposureConfig, dataExposure); + return dataExposure; + } /** * fillDataExposureConfiguration. * * @param dataExposureConfig DataExposureConfig - * @param dataExposure DataExposure + * @param dataExposure DataExposure * - * @return data exposure + * @return data exposure * */ - public void fillDataExposureConfiguration(DataExposureConfig dataExposureConfig, DataExposure dataExposure) { - fillDataExposure(dataExposureConfig, dataExposure); - } + public void fillDataExposureConfiguration(DataExposureConfig dataExposureConfig, DataExposure dataExposure) { + fillDataExposure(dataExposureConfig, dataExposure); + } + + private void fillDataExposure(DataExposureConfig dataExposureConfig, DataExposure dataExposure) + throws IllegalArgumentException { + + dataExposure.setId(dataExposureConfig.getId()); + dataExposure.setNote(dataExposureConfig.getNote()); + dataExposure.setSqlTemplate(dataExposureConfig.getSqlTemplate()); + if (dataExposureConfig.getDbId() == null) { + throw new IllegalArgumentException("Can not find db_id in db, db_id: " + dataExposureConfig.getDbId()); + } + + Optional<Db> dbOptional = dbRepository.findById(dataExposureConfig.getDbId()); + + if (!dbOptional.isPresent()) { + throw new IllegalArgumentException("db_id is null " + dataExposureConfig.getDbId()); + } - private void fillDataExposure(DataExposureConfig dataExposureConfig, DataExposure dataExposure) - throws IllegalArgumentException { - dataExposure.setId(dataExposureConfig.getId()); - dataExposure.setNote(dataExposureConfig.getNote()); - dataExposure.setSqlTemplate(dataExposureConfig.getSqlTemplate()); - if (dataExposureConfig.getDbId() == null) - throw new IllegalArgumentException("Can not find db_id in db, db_id: " + dataExposureConfig.getDbId()); - Optional<Db> dbOptional = dbRepository.findById(dataExposureConfig.getDbId()); - if (!dbOptional.isPresent()) - throw new IllegalArgumentException("db_id is null " + dataExposureConfig.getDbId()); - dataExposure.setDb(dbOptional.get()); - } + dataExposure.setDb(dbOptional.get()); + } } |