Add custom Configuration class for mix module (FINERACT-1932)

This commit is contained in:
Sinha, Abhinav
2023-10-26 15:07:23 +02:00
committed by Aleksandar Vidakovic
parent c13742f704
commit 9aa1c14b70
6 changed files with 69 additions and 28 deletions
@@ -20,23 +20,17 @@ package org.apache.fineract.mix.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.mix.data.MixTaxonomyMappingData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class MixTaxonomyMappingReadPlatformServiceImpl implements MixTaxonomyMappingReadPlatformService {
private final JdbcTemplate jdbcTemplate;
@Autowired
public MixTaxonomyMappingReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
private static final class TaxonomyMappingMapper implements RowMapper<MixTaxonomyMappingData> {
public String schema() {
@@ -18,27 +18,21 @@
*/
package org.apache.fineract.mix.service;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.mix.domain.MixTaxonomyMapping;
import org.apache.fineract.mix.domain.MixTaxonomyMappingRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
public class MixTaxonomyMappingWritePlatformServiceImpl implements MixTaxonomyMappingWritePlatformService {
private final MixTaxonomyMappingRepository mappingRepository;
@Autowired
public MixTaxonomyMappingWritePlatformServiceImpl(final MixTaxonomyMappingRepository mappingRepository) {
this.mappingRepository = mappingRepository;
}
@Transactional
@Override
public CommandProcessingResult updateMapping(final Long mappingId, final JsonCommand command) {
@@ -22,18 +22,14 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.apache.fineract.mix.data.MixTaxonomyData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@Service
public class MixTaxonomyReadPlatformServiceImpl implements MixTaxonomyReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final MixTaxonomyMapper mixTaxonomyMapper;
@Autowired
public MixTaxonomyReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
this.mixTaxonomyMapper = new MixTaxonomyMapper();
@@ -21,18 +21,14 @@ package org.apache.fineract.mix.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.fineract.mix.data.NamespaceData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@Service
public class NamespaceReadPlatformServiceImpl implements NamespaceReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final NamespaceMapper namespaceMapper;
@Autowired
public NamespaceReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
this.namespaceMapper = new NamespaceMapper();
@@ -30,21 +30,20 @@ import java.util.regex.Pattern;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.mix.data.MixTaxonomyData;
import org.apache.fineract.mix.data.MixTaxonomyMappingData;
import org.apache.fineract.mix.data.XBRLData;
import org.apache.fineract.mix.exception.XBRLMappingInvalidException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class XBRLResultServiceImpl implements XBRLResultService {
private static final Logger LOG = LoggerFactory.getLogger(XBRLResultServiceImpl.class);
private static final ScriptEngine SCRIPT_ENGINE = new ScriptEngineManager().getEngineByName("JavaScript");
private final MixTaxonomyMappingReadPlatformService readTaxonomyMappingService;
@@ -162,7 +161,7 @@ public class XBRLResultServiceImpl implements XBRLResultService {
eval = value.floatValue();
}
} catch (final ScriptException e) {
LOG.error("Problem occurred in processMappingString function", e);
log.error("Problem occurred in processMappingString function", e);
throw new IllegalArgumentException(e.getMessage(), e);
}
@@ -0,0 +1,62 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.mix.starter;
import org.apache.fineract.mix.domain.MixTaxonomyMappingRepository;
import org.apache.fineract.mix.service.MixTaxonomyMappingReadPlatformService;
import org.apache.fineract.mix.service.MixTaxonomyMappingReadPlatformServiceImpl;
import org.apache.fineract.mix.service.MixTaxonomyMappingWritePlatformService;
import org.apache.fineract.mix.service.MixTaxonomyMappingWritePlatformServiceImpl;
import org.apache.fineract.mix.service.MixTaxonomyReadPlatformService;
import org.apache.fineract.mix.service.MixTaxonomyReadPlatformServiceImpl;
import org.apache.fineract.mix.service.NamespaceReadPlatformService;
import org.apache.fineract.mix.service.NamespaceReadPlatformServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
@Configuration
public class MixConfiguration {
@Bean
@ConditionalOnMissingBean(MixTaxonomyMappingReadPlatformService.class)
public MixTaxonomyMappingReadPlatformService mixTaxonomyMappingReadPlatformService(JdbcTemplate jdbcTemplate) {
return new MixTaxonomyMappingReadPlatformServiceImpl(jdbcTemplate);
}
@Bean
@ConditionalOnMissingBean(MixTaxonomyMappingWritePlatformService.class)
public MixTaxonomyMappingWritePlatformService mixTaxonomyMappingWritePlatformService(MixTaxonomyMappingRepository mappingRepository) {
return new MixTaxonomyMappingWritePlatformServiceImpl(mappingRepository);
}
@Bean
@ConditionalOnMissingBean(MixTaxonomyReadPlatformService.class)
public MixTaxonomyReadPlatformService mixTaxonomyReadPlatformService(JdbcTemplate jdbcTemplate) {
return new MixTaxonomyReadPlatformServiceImpl(jdbcTemplate);
}
@Bean
@ConditionalOnMissingBean(NamespaceReadPlatformService.class)
public NamespaceReadPlatformService namespaceReadPlatformService(JdbcTemplate jdbcTemplate) {
return new NamespaceReadPlatformServiceImpl(jdbcTemplate);
}
}