| /** |
| * 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.infrastructure.configuration.domain; |
| |
| import java.util.Date; |
| import org.apache.commons.lang.StringUtils; |
| import org.apache.fineract.infrastructure.cache.domain.CacheType; |
| import org.apache.fineract.infrastructure.cache.domain.PlatformCache; |
| import org.apache.fineract.infrastructure.cache.domain.PlatformCacheRepository; |
| import org.apache.fineract.useradministration.domain.Permission; |
| import org.apache.fineract.useradministration.domain.PermissionRepository; |
| import org.apache.fineract.useradministration.exception.PermissionNotFoundException; |
| import org.springframework.beans.factory.annotation.Autowired; |
| import org.springframework.stereotype.Service; |
| import org.springframework.transaction.annotation.Transactional; |
| |
| @Service |
| public class ConfigurationDomainServiceJpa implements ConfigurationDomainService { |
| |
| private final PermissionRepository permissionRepository; |
| private final GlobalConfigurationRepositoryWrapper globalConfigurationRepository; |
| private final PlatformCacheRepository cacheTypeRepository; |
| |
| @Autowired |
| public ConfigurationDomainServiceJpa(final PermissionRepository permissionRepository, |
| final GlobalConfigurationRepositoryWrapper globalConfigurationRepository, final PlatformCacheRepository cacheTypeRepository) { |
| this.permissionRepository = permissionRepository; |
| this.globalConfigurationRepository = globalConfigurationRepository; |
| this.cacheTypeRepository = cacheTypeRepository; |
| } |
| |
| @Override |
| public boolean isMakerCheckerEnabledForTask(final String taskPermissionCode) { |
| if (StringUtils.isBlank(taskPermissionCode)) { throw new PermissionNotFoundException(taskPermissionCode); } |
| |
| final Permission thisTask = this.permissionRepository.findOneByCode(taskPermissionCode); |
| if (thisTask == null) { throw new PermissionNotFoundException(taskPermissionCode); } |
| |
| final String makerCheckerConfigurationProperty = "maker-checker"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository |
| .findOneByNameWithNotFoundDetection(makerCheckerConfigurationProperty); |
| |
| return thisTask.hasMakerCheckerEnabled() && property.isEnabled(); |
| } |
| |
| @Override |
| public boolean isAmazonS3Enabled() { |
| return this.globalConfigurationRepository.findOneByNameWithNotFoundDetection("amazon-S3").isEnabled(); |
| } |
| |
| @Override |
| public boolean isRescheduleFutureRepaymentsEnabled() { |
| final String rescheduleRepaymentsConfigurationProperty = "reschedule-future-repayments"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository |
| .findOneByNameWithNotFoundDetection(rescheduleRepaymentsConfigurationProperty); |
| return property.isEnabled(); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.apache.fineract.infrastructure.configuration.domain. |
| * ConfigurationDomainService#isHolidaysEnabled() |
| */ |
| @Override |
| public boolean isRescheduleRepaymentsOnHolidaysEnabled() { |
| final String holidaysConfigurationProperty = "reschedule-repayments-on-holidays"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository |
| .findOneByNameWithNotFoundDetection(holidaysConfigurationProperty); |
| return property.isEnabled(); |
| } |
| |
| @Override |
| public boolean allowTransactionsOnHolidayEnabled() { |
| final String allowTransactionsOnHolidayProperty = "allow-transactions-on-holiday"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository |
| .findOneByNameWithNotFoundDetection(allowTransactionsOnHolidayProperty); |
| return property.isEnabled(); |
| } |
| |
| @Override |
| public boolean allowTransactionsOnNonWorkingDayEnabled() { |
| final String propertyName = "allow-transactions-on-non_workingday"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.isEnabled(); |
| } |
| |
| @Override |
| public boolean isConstraintApproachEnabledForDatatables() { |
| final String propertyName = "constraint_approach_for_datatables"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.isEnabled(); |
| } |
| |
| @Override |
| public boolean isEhcacheEnabled() { |
| return this.cacheTypeRepository.findOne(Long.valueOf(1)).isEhcacheEnabled(); |
| } |
| |
| @Transactional |
| @Override |
| public void updateCache(final CacheType cacheType) { |
| final PlatformCache cache = this.cacheTypeRepository.findOne(Long.valueOf(1)); |
| cache.update(cacheType); |
| this.cacheTypeRepository.save(cache); |
| } |
| |
| @Override |
| public Long retrievePenaltyWaitPeriod() { |
| final String propertyName = "penalty-wait-period"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.getValue(); |
| } |
| |
| @Override |
| public Long retrieveGraceOnPenaltyPostingPeriod() { |
| final String propertyName = "grace-on-penalty-posting"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.getValue(); |
| } |
| |
| @Override |
| public boolean isPasswordForcedResetEnable() { |
| final String propertyName = "force-password-reset-days"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.isEnabled(); |
| } |
| |
| @Override |
| public Long retrievePasswordLiveTime() { |
| final String propertyName = "force-password-reset-days"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.getValue(); |
| } |
| |
| @Override |
| public Long retrieveOpeningBalancesContraAccount() { |
| final String propertyName = "office-opening-balances-contra-account"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.getValue(); |
| } |
| |
| @Override |
| public boolean isSavingsInterestPostingAtCurrentPeriodEnd() { |
| final String propertyName = "savings-interest-posting-current-period-end"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.isEnabled(); |
| } |
| |
| @Override |
| public Integer retrieveFinancialYearBeginningMonth() { |
| final String propertyName = "financial-year-beginning-month"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| if (property.isEnabled()) return property.getValue().intValue(); |
| return 1; |
| } |
| |
| @Override |
| public Integer retrieveMinAllowedClientsInGroup() { |
| final String propertyName = "min-clients-in-group"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| if (property.isEnabled()) { return property.getValue().intValue(); } |
| return null; |
| } |
| |
| @Override |
| public Integer retrieveMaxAllowedClientsInGroup() { |
| final String propertyName = "max-clients-in-group"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| if (property.isEnabled()) { return property.getValue().intValue(); } |
| return null; |
| } |
| |
| @Override |
| public boolean isMeetingMandatoryForJLGLoans() { |
| final String propertyName = "meetings-mandatory-for-jlg-loans"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.isEnabled(); |
| } |
| |
| @Override |
| public int getRoundingMode() { |
| final String propertyName = "rounding-mode"; |
| int defaultValue = 6; // 6 Stands for HALF-EVEN |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| if (property.isEnabled()) { |
| int value = property.getValue().intValue(); |
| if (value < 0 || value > 6) { |
| return defaultValue; |
| } |
| return value; |
| } |
| return defaultValue; |
| } |
| |
| public boolean isBackdatePenaltiesEnabled() { |
| final String propertyName = "backdate-penalties-enabled"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.isEnabled(); |
| } |
| |
| @Override |
| public boolean isOrganisationstartDateEnabled() { |
| final String propertyName = "organisation-start-date"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.isEnabled(); |
| } |
| |
| @Override |
| public Date retrieveOrganisationStartDate() { |
| final String propertyName = "organisation-start-date"; |
| final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); |
| return property.getDateValue(); |
| } |
| |
| } |