Skip to content

Commit

Permalink
Add custom Configuration class for useradministration service (FINERA…
Browse files Browse the repository at this point in the history
…CT-1932)
  • Loading branch information
abhinav7sinha authored and galovics committed Aug 30, 2023
1 parent f829eaa commit 6910759
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.organisation.office.data.OfficeData;
Expand All @@ -39,34 +40,20 @@
import org.apache.fineract.useradministration.domain.AppUserRepository;
import org.apache.fineract.useradministration.domain.Role;
import org.apache.fineract.useradministration.exception.UserNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformService {

private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context;
private final JdbcTemplate jdbcTemplate;
private final OfficeReadPlatformService officeReadPlatformService;
private final RoleReadPlatformService roleReadPlatformService;
private final AppUserRepository appUserRepository;
private final StaffReadPlatformService staffReadPlatformService;

@Autowired
public AppUserReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate,
final OfficeReadPlatformService officeReadPlatformService, final RoleReadPlatformService roleReadPlatformService,
final AppUserRepository appUserRepository, final StaffReadPlatformService staffReadPlatformService) {
this.context = context;
this.officeReadPlatformService = officeReadPlatformService;
this.roleReadPlatformService = roleReadPlatformService;
this.appUserRepository = appUserRepository;
this.jdbcTemplate = jdbcTemplate;
this.staffReadPlatformService = staffReadPlatformService;
}

/*
* used for caching in spring expression language.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@
import org.springframework.data.domain.Sort;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

@Service
@Slf4j
@RequiredArgsConstructor
public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWritePlatformService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
Expand All @@ -30,29 +32,17 @@
import org.apache.fineract.useradministration.domain.PasswordValidationPolicy;
import org.apache.fineract.useradministration.domain.PasswordValidationPolicyRepository;
import org.apache.fineract.useradministration.exception.PasswordValidationPolicyNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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
@Slf4j
@RequiredArgsConstructor
public class PasswordPreferencesWritePlatformServiceJpaRepositoryImpl implements PasswordPreferencesWritePlatformService {

private static final Logger LOG = LoggerFactory.getLogger(PasswordPreferencesWritePlatformServiceJpaRepositoryImpl.class);
private final PasswordValidationPolicyRepository validationRepository;
private final PasswordPreferencesDataValidator dataValidator;

@Autowired
public PasswordPreferencesWritePlatformServiceJpaRepositoryImpl(final PasswordValidationPolicyRepository validationPolicyRepository,
final PasswordPreferencesDataValidator dataValidator) {
this.validationRepository = validationPolicyRepository;
this.dataValidator = dataValidator;

}

@Transactional
@Override
public CommandProcessingResult updatePreferences(final JsonCommand command) {
Expand Down Expand Up @@ -91,7 +81,7 @@ public CommandProcessingResult updatePreferences(final JsonCommand command) {
.with(changes) //
.build();
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
LOG.error("Error occured.", dve);
log.error("Error occured.", dve);
throw new PlatformDataIntegrityException("error.msg.password.validation.policy.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.", dve);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
import org.apache.fineract.useradministration.data.PasswordValidationPolicyData;
import org.apache.fineract.useradministration.exception.PasswordValidationPolicyNotFoundException;
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
public class PasswordValidationPolicyReadPlatformServiceImpl implements PasswordValidationPolicyReadPlatformService {

private final JdbcTemplate jdbcTemplate;
private final DatabaseSpecificSQLGenerator sqlGenerator;
private final PasswordValidationPolicyMapper passwordValidationPolicyMapper;

@Autowired
public PasswordValidationPolicyReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate, DatabaseSpecificSQLGenerator sqlGenerator) {
this.jdbcTemplate = jdbcTemplate;
this.sqlGenerator = sqlGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,21 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.useradministration.data.PermissionData;
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.core.RowMapper;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class PermissionReadPlatformServiceImpl implements PermissionReadPlatformService {

private static final Logger LOG = LoggerFactory.getLogger(PermissionReadPlatformServiceImpl.class);

private final PlatformSecurityContext context;
private final JdbcTemplate jdbcTemplate;
private final DatabaseSpecificSQLGenerator sqlGenerator;
private final PlatformSecurityContext context;

@Autowired
public PermissionReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate,
DatabaseSpecificSQLGenerator sqlGenerator) {
this.context = context;
this.jdbcTemplate = jdbcTemplate;
this.sqlGenerator = sqlGenerator;
}

@Override
public Collection<PermissionData> retrieveAllPermissions() {
Expand All @@ -55,7 +44,7 @@ public Collection<PermissionData> retrieveAllPermissions() {

final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper(sqlGenerator);
final String sql = mapper.permissionSchema();
LOG.debug("retrieveAllPermissions: {}", sql);
log.debug("retrieveAllPermissions: {}", sql);
return this.jdbcTemplate.query(sql, mapper, new Object[] {});
}

Expand All @@ -66,7 +55,7 @@ public Collection<PermissionData> retrieveAllMakerCheckerablePermissions() {

final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper(sqlGenerator);
final String sql = mapper.makerCheckerablePermissionSchema();
LOG.debug("retrieveAllMakerCheckerablePermissions: {}", sql);
log.debug("retrieveAllMakerCheckerablePermissions: {}", sql);

return this.jdbcTemplate.query(sql, mapper, new Object[] {});
}
Expand All @@ -76,7 +65,7 @@ public Collection<PermissionData> retrieveAllRolePermissions(final Long roleId)

final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper(sqlGenerator);
final String sql = mapper.rolePermissionSchema();
LOG.debug("retrieveAllRolePermissions: {}", sql);
log.debug("retrieveAllRolePermissions: {}", sql);

return this.jdbcTemplate.query(sql, mapper, new Object[] { roleId });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
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;
Expand All @@ -30,27 +31,17 @@
import org.apache.fineract.useradministration.domain.PermissionRepository;
import org.apache.fineract.useradministration.exception.PermissionNotFoundException;
import org.apache.fineract.useradministration.serialization.PermissionsCommandFromApiJsonDeserializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class PermissionWritePlatformServiceJpaRepositoryImpl implements PermissionWritePlatformService {

private final PlatformSecurityContext context;
private final PermissionRepository permissionRepository;
private final PermissionsCommandFromApiJsonDeserializer fromApiJsonDeserializer;

@Autowired
public PermissionWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final PermissionRepository permissionRepository, final PermissionsCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
this.context = context;
this.permissionRepository = permissionRepository;
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
}

@Caching(evict = { @CacheEvict(value = "users", allEntries = true), @CacheEvict(value = "usersByUsername", allEntries = true) })
@Transactional
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@
import org.apache.fineract.portfolio.self.registration.SelfServiceApiConstants;
import org.apache.fineract.useradministration.data.RoleData;
import org.apache.fineract.useradministration.exception.RoleNotFoundException;
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
public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {

private final JdbcTemplate jdbcTemplate;
private final RoleMapper roleRowMapper;

@Autowired
public RoleReadPlatformServiceImpl(final JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
this.roleRowMapper = new RoleMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@
import org.springframework.cache.annotation.Caching;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@RequiredArgsConstructor
public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatformService {
Expand Down
Loading

0 comments on commit 6910759

Please sign in to comment.