MIFOSX-213: wip add status to centers and groups, tidy up CRUD on each and update api docs.
This commit is contained in:
+177
-224
@@ -32,281 +32,234 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
|
||||
|
||||
private final static Logger logger = LoggerFactory
|
||||
.getLogger(AuditReadPlatformServiceImpl.class);
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final AppUserReadPlatformService appUserReadPlatformService;
|
||||
private final static Logger logger = LoggerFactory.getLogger(AuditReadPlatformServiceImpl.class);
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final AppUserReadPlatformService appUserReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
public AuditReadPlatformServiceImpl(final PlatformSecurityContext context,
|
||||
final TenantAwareRoutingDataSource dataSource,
|
||||
final AppUserReadPlatformService appUserReadPlatformService) {
|
||||
this.context = context;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.appUserReadPlatformService = appUserReadPlatformService;
|
||||
}
|
||||
@Autowired
|
||||
public AuditReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
|
||||
final AppUserReadPlatformService appUserReadPlatformService) {
|
||||
this.context = context;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.appUserReadPlatformService = appUserReadPlatformService;
|
||||
}
|
||||
|
||||
private static final class AuditMapper implements RowMapper<AuditData> {
|
||||
private static final class AuditMapper implements RowMapper<AuditData> {
|
||||
|
||||
public String schema(boolean includeJson, String hierarchy) {
|
||||
public String schema(final boolean includeJson, final String hierarchy) {
|
||||
|
||||
String commandAsJsonString = "";
|
||||
if (includeJson)
|
||||
commandAsJsonString = ", aud.command_as_json as commandAsJson ";
|
||||
String commandAsJsonString = "";
|
||||
if (includeJson) commandAsJsonString = ", aud.command_as_json as commandAsJson ";
|
||||
|
||||
String partSql = " aud.id as id, aud.action_name as actionName, aud.entity_name as entityName,"
|
||||
+ " aud.resource_id as resourceId, aud.subresource_id as subresourceId,"
|
||||
+ " mk.username as maker, aud.made_on_date as madeOnDate, "
|
||||
+ "ck.username as checker, aud.checked_on_date as checkedOnDate, ev.enum_message_property as processingResult "
|
||||
+ commandAsJsonString
|
||||
+ ", "
|
||||
+ " o.name as officeName, gl.level_name as groupLevelName, g.name as groupName, c.display_name as clientName, "
|
||||
+ " l.account_no as loanAccountNo, s.account_no as savingsAccountNo "
|
||||
+ " from m_portfolio_command_source aud "
|
||||
+ " left join m_appuser mk on mk.id = aud.maker_id"
|
||||
+ " left join m_appuser ck on ck.id = aud.checker_id"
|
||||
+ " left join m_office o on o.id = aud.office_id"
|
||||
+ " left join m_group g on g.id = aud.group_id"
|
||||
+ " left join m_group_level gl on gl.id = g.level_id"
|
||||
+ " left join m_client c on c.id = aud.client_id"
|
||||
+ " left join m_loan l on l.id = aud.loan_id"
|
||||
+ " left join m_savings_account s on s.id = aud.savings_account_id"
|
||||
+ " left join r_enum_value ev on ev.enum_name = 'processing_result_enum' and ev.enum_id = aud.processing_result_enum";
|
||||
String partSql = " aud.id as id, aud.action_name as actionName, aud.entity_name as entityName,"
|
||||
+ " aud.resource_id as resourceId, aud.subresource_id as subresourceId,"
|
||||
+ " mk.username as maker, aud.made_on_date as madeOnDate, "
|
||||
+ "ck.username as checker, aud.checked_on_date as checkedOnDate, ev.enum_message_property as processingResult "
|
||||
+ commandAsJsonString + ", "
|
||||
+ " o.name as officeName, gl.level_name as groupLevelName, g.display_name as groupName, c.display_name as clientName, "
|
||||
+ " l.account_no as loanAccountNo, s.account_no as savingsAccountNo " + " from m_portfolio_command_source aud "
|
||||
+ " left join m_appuser mk on mk.id = aud.maker_id" + " left join m_appuser ck on ck.id = aud.checker_id"
|
||||
+ " left join m_office o on o.id = aud.office_id" + " left join m_group g on g.id = aud.group_id"
|
||||
+ " left join m_group_level gl on gl.id = g.level_id" + " left join m_client c on c.id = aud.client_id"
|
||||
+ " left join m_loan l on l.id = aud.loan_id" + " left join m_savings_account s on s.id = aud.savings_account_id"
|
||||
+ " left join r_enum_value ev on ev.enum_name = 'processing_result_enum' and ev.enum_id = aud.processing_result_enum";
|
||||
|
||||
// data scoping: head office (hierarchy = ".") can see all audit
|
||||
// entries
|
||||
if (!(hierarchy.equals("."))) {
|
||||
partSql += " join m_office o2 on o2.id = aud.office_id and o2.hierarchy like '"
|
||||
+ hierarchy + "%' ";
|
||||
}
|
||||
// data scoping: head office (hierarchy = ".") can see all audit
|
||||
// entries
|
||||
if (!(hierarchy.equals("."))) {
|
||||
partSql += " join m_office o2 on o2.id = aud.office_id and o2.hierarchy like '" + hierarchy + "%' ";
|
||||
}
|
||||
|
||||
return partSql;
|
||||
}
|
||||
return partSql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuditData mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
@Override
|
||||
public AuditData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long id = rs.getLong("id");
|
||||
final String actionName = rs.getString("actionName");
|
||||
final String entityName = rs.getString("entityName");
|
||||
final Long resourceId = JdbcSupport.getLong(rs, "resourceId");
|
||||
final Long subresourceId = JdbcSupport.getLong(rs, "subresourceId");
|
||||
final String maker = rs.getString("maker");
|
||||
final DateTime madeOnDate = JdbcSupport.getDateTime(rs,
|
||||
"madeOnDate");
|
||||
final String checker = rs.getString("checker");
|
||||
final DateTime checkedOnDate = JdbcSupport.getDateTime(rs,
|
||||
"checkedOnDate");
|
||||
final String processingResult = rs.getString("processingResult");
|
||||
String commandAsJson;
|
||||
// commandAsJson might not be on the select list of columns
|
||||
try {
|
||||
commandAsJson = rs.getString("commandAsJson");
|
||||
} catch (SQLException e) {
|
||||
commandAsJson = null;
|
||||
}
|
||||
final Long id = rs.getLong("id");
|
||||
final String actionName = rs.getString("actionName");
|
||||
final String entityName = rs.getString("entityName");
|
||||
final Long resourceId = JdbcSupport.getLong(rs, "resourceId");
|
||||
final Long subresourceId = JdbcSupport.getLong(rs, "subresourceId");
|
||||
final String maker = rs.getString("maker");
|
||||
final DateTime madeOnDate = JdbcSupport.getDateTime(rs, "madeOnDate");
|
||||
final String checker = rs.getString("checker");
|
||||
final DateTime checkedOnDate = JdbcSupport.getDateTime(rs, "checkedOnDate");
|
||||
final String processingResult = rs.getString("processingResult");
|
||||
String commandAsJson;
|
||||
// commandAsJson might not be on the select list of columns
|
||||
try {
|
||||
commandAsJson = rs.getString("commandAsJson");
|
||||
} catch (SQLException e) {
|
||||
commandAsJson = null;
|
||||
}
|
||||
|
||||
String officeName = rs.getString("officeName");
|
||||
String groupLevelName = rs.getString("groupLevelName");
|
||||
String groupName = rs.getString("groupName");
|
||||
String clientName = rs.getString("clientName");
|
||||
String loanAccountNo = rs.getString("loanAccountNo");
|
||||
String savingsAccountNo = rs.getString("savingsAccountNo");
|
||||
String officeName = rs.getString("officeName");
|
||||
String groupLevelName = rs.getString("groupLevelName");
|
||||
String groupName = rs.getString("groupName");
|
||||
String clientName = rs.getString("clientName");
|
||||
String loanAccountNo = rs.getString("loanAccountNo");
|
||||
String savingsAccountNo = rs.getString("savingsAccountNo");
|
||||
|
||||
return new AuditData(id, actionName, entityName, resourceId,
|
||||
subresourceId, maker, madeOnDate, checker, checkedOnDate,
|
||||
processingResult, commandAsJson, officeName,
|
||||
groupLevelName, groupName, clientName, loanAccountNo,
|
||||
savingsAccountNo);
|
||||
}
|
||||
}
|
||||
return new AuditData(id, actionName, entityName, resourceId, subresourceId, maker, madeOnDate, checker, checkedOnDate,
|
||||
processingResult, commandAsJson, officeName, groupLevelName, groupName, clientName, loanAccountNo, savingsAccountNo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AuditData> retrieveAuditEntries(String extraCriteria,
|
||||
boolean includeJson) {
|
||||
@Override
|
||||
public Collection<AuditData> retrieveAuditEntries(final String extraCriteria, final boolean includeJson) {
|
||||
|
||||
String updatedExtraCriteria = "";
|
||||
if (StringUtils.isNotBlank(extraCriteria))
|
||||
updatedExtraCriteria = " where (" + extraCriteria + ")";
|
||||
String updatedExtraCriteria = "";
|
||||
if (StringUtils.isNotBlank(extraCriteria)) updatedExtraCriteria = " where (" + extraCriteria + ")";
|
||||
|
||||
updatedExtraCriteria += " order by aud.id DESC";
|
||||
return retrieveEntries("audit", updatedExtraCriteria, includeJson);
|
||||
}
|
||||
updatedExtraCriteria += " order by aud.id DESC";
|
||||
return retrieveEntries("audit", updatedExtraCriteria, includeJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AuditData> retrieveAllEntriesToBeChecked(
|
||||
String extraCriteria, boolean includeJson) {
|
||||
@Override
|
||||
public Collection<AuditData> retrieveAllEntriesToBeChecked(final String extraCriteria, final boolean includeJson) {
|
||||
|
||||
String updatedExtraCriteria = "";
|
||||
if (StringUtils.isNotBlank(extraCriteria))
|
||||
updatedExtraCriteria = " where (" + extraCriteria + ")"
|
||||
+ " and aud.processing_result_enum = 2";
|
||||
else
|
||||
updatedExtraCriteria = " where aud.processing_result_enum = 2";
|
||||
String updatedExtraCriteria = "";
|
||||
if (StringUtils.isNotBlank(extraCriteria))
|
||||
updatedExtraCriteria = " where (" + extraCriteria + ")" + " and aud.processing_result_enum = 2";
|
||||
else
|
||||
updatedExtraCriteria = " where aud.processing_result_enum = 2";
|
||||
|
||||
updatedExtraCriteria += " order by aud.id";
|
||||
updatedExtraCriteria += " order by aud.id";
|
||||
|
||||
return retrieveEntries("makerchecker", updatedExtraCriteria,
|
||||
includeJson);
|
||||
}
|
||||
return retrieveEntries("makerchecker", updatedExtraCriteria, includeJson);
|
||||
}
|
||||
|
||||
public Collection<AuditData> retrieveEntries(String useType,
|
||||
String extraCriteria, boolean includeJson) {
|
||||
public Collection<AuditData> retrieveEntries(final String useType, final String extraCriteria, final boolean includeJson) {
|
||||
|
||||
if (!(useType.equals("audit") || useType.equals("makerchecker"))) {
|
||||
throw new PlatformDataIntegrityException(
|
||||
"error.msg.invalid.auditSearchTemplate.useType",
|
||||
"Invalid Audit Search Template UseType: " + useType);
|
||||
}
|
||||
if (!(useType.equals("audit") || useType.equals("makerchecker"))) { throw new PlatformDataIntegrityException(
|
||||
"error.msg.invalid.auditSearchTemplate.useType", "Invalid Audit Search Template UseType: " + useType); }
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
|
||||
final AuditMapper rm = new AuditMapper();
|
||||
String sql = "select " + rm.schema(includeJson, hierarchy);
|
||||
final AuditMapper rm = new AuditMapper();
|
||||
String sql = "select " + rm.schema(includeJson, hierarchy);
|
||||
|
||||
Boolean isLimitedChecker = false;
|
||||
if (useType.equals("makerchecker")) {
|
||||
if (currentUser.hasNotPermissionForAnyOf("ALL_FUNCTIONS",
|
||||
"CHECKER_SUPER_USER")) {
|
||||
isLimitedChecker = true;
|
||||
}
|
||||
}
|
||||
Boolean isLimitedChecker = false;
|
||||
if (useType.equals("makerchecker")) {
|
||||
if (currentUser.hasNotPermissionForAnyOf("ALL_FUNCTIONS", "CHECKER_SUPER_USER")) {
|
||||
isLimitedChecker = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isLimitedChecker) {
|
||||
sql += " join m_permission p on p.action_name = aud.action_name and p.entity_name = aud.entity_name and p.code like '%\\_CHECKER'"
|
||||
+ " join m_role_permission rp on rp.permission_id = p.id"
|
||||
+ " join m_role r on r.id = rp.role_id "
|
||||
+ " join m_appuser_role ur on ur.role_id = r.id and ur.appuser_id = "
|
||||
+ currentUser.getId();
|
||||
}
|
||||
sql += extraCriteria;
|
||||
if (isLimitedChecker) {
|
||||
sql += " join m_permission p on p.action_name = aud.action_name and p.entity_name = aud.entity_name and p.code like '%\\_CHECKER'"
|
||||
+ " join m_role_permission rp on rp.permission_id = p.id"
|
||||
+ " join m_role r on r.id = rp.role_id "
|
||||
+ " join m_appuser_role ur on ur.role_id = r.id and ur.appuser_id = " + currentUser.getId();
|
||||
}
|
||||
sql += extraCriteria;
|
||||
|
||||
logger.info("sql: " + sql);
|
||||
logger.info("sql: " + sql);
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] {});
|
||||
}
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuditData retrieveAuditEntry(Long auditId) {
|
||||
@Override
|
||||
public AuditData retrieveAuditEntry(final Long auditId) {
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
|
||||
final AuditMapper rm = new AuditMapper();
|
||||
final AuditMapper rm = new AuditMapper();
|
||||
|
||||
String sql = "select " + rm.schema(true, hierarchy);
|
||||
sql += " where aud.id = " + auditId;
|
||||
String sql = "select " + rm.schema(true, hierarchy);
|
||||
sql += " where aud.id = " + auditId;
|
||||
|
||||
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] {});
|
||||
}
|
||||
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuditSearchData retrieveSearchTemplate(String useType) {
|
||||
@Override
|
||||
public AuditSearchData retrieveSearchTemplate(final String useType) {
|
||||
|
||||
if (!(useType.equals("audit") || useType.equals("makerchecker"))) {
|
||||
throw new PlatformDataIntegrityException(
|
||||
"error.msg.invalid.auditSearchTemplate.useType",
|
||||
"Invalid Audit Search Template UseType: " + useType);
|
||||
}
|
||||
if (!(useType.equals("audit") || useType.equals("makerchecker"))) { throw new PlatformDataIntegrityException(
|
||||
"error.msg.invalid.auditSearchTemplate.useType", "Invalid Audit Search Template UseType: " + useType); }
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
final Collection<AppUserData> appUsers = appUserReadPlatformService
|
||||
.retrieveSearchTemplate();
|
||||
final Collection<AppUserData> appUsers = appUserReadPlatformService.retrieveSearchTemplate();
|
||||
|
||||
String sql = " SELECT distinct(action_name) as actionName FROM m_permission p ";
|
||||
sql += makercheckerCapabilityOnly(useType, currentUser);
|
||||
sql += " order by if(action_name in ('CREATE', 'DELETE', 'UPDATE'), action_name, 'ZZZ'), action_name";
|
||||
ActionNamesMapper mapper = new ActionNamesMapper();
|
||||
List<String> actionNames = this.jdbcTemplate.query(sql, mapper,
|
||||
new Object[] {});
|
||||
String sql = " SELECT distinct(action_name) as actionName FROM m_permission p ";
|
||||
sql += makercheckerCapabilityOnly(useType, currentUser);
|
||||
sql += " order by if(action_name in ('CREATE', 'DELETE', 'UPDATE'), action_name, 'ZZZ'), action_name";
|
||||
ActionNamesMapper mapper = new ActionNamesMapper();
|
||||
List<String> actionNames = this.jdbcTemplate.query(sql, mapper, new Object[] {});
|
||||
|
||||
sql = " select distinct(entity_name) as entityName from m_permission p ";
|
||||
sql += makercheckerCapabilityOnly(useType, currentUser);
|
||||
sql += " order by if(grouping = 'datatable', 'ZZZ', entity_name), entity_name";
|
||||
EntityNamesMapper mapper2 = new EntityNamesMapper();
|
||||
List<String> entityNames = this.jdbcTemplate.query(sql, mapper2,
|
||||
new Object[] {});
|
||||
sql = " select distinct(entity_name) as entityName from m_permission p ";
|
||||
sql += makercheckerCapabilityOnly(useType, currentUser);
|
||||
sql += " order by if(grouping = 'datatable', 'ZZZ', entity_name), entity_name";
|
||||
EntityNamesMapper mapper2 = new EntityNamesMapper();
|
||||
List<String> entityNames = this.jdbcTemplate.query(sql, mapper2, new Object[] {});
|
||||
|
||||
Collection<ProcessingResultLookup> processingResults = null;
|
||||
if (useType.equals("audit")) {
|
||||
ProcessingResultsMapper mapper3 = new ProcessingResultsMapper();
|
||||
processingResults = this.jdbcTemplate.query(mapper3.schema(),
|
||||
mapper3, new Object[] {});
|
||||
}
|
||||
Collection<ProcessingResultLookup> processingResults = null;
|
||||
if (useType.equals("audit")) {
|
||||
ProcessingResultsMapper mapper3 = new ProcessingResultsMapper();
|
||||
processingResults = this.jdbcTemplate.query(mapper3.schema(), mapper3, new Object[] {});
|
||||
}
|
||||
|
||||
return new AuditSearchData(appUsers, actionNames, entityNames,
|
||||
processingResults);
|
||||
}
|
||||
return new AuditSearchData(appUsers, actionNames, entityNames, processingResults);
|
||||
}
|
||||
|
||||
private String makercheckerCapabilityOnly(String useType,
|
||||
AppUser currentUser) {
|
||||
String sql = "";
|
||||
Boolean isLimitedChecker = false;
|
||||
if (useType.equals("makerchecker")) {
|
||||
if (currentUser.hasNotPermissionForAnyOf("ALL_FUNCTIONS",
|
||||
"CHECKER_SUPER_USER")) {
|
||||
isLimitedChecker = true;
|
||||
}
|
||||
}
|
||||
private String makercheckerCapabilityOnly(final String useType, final AppUser currentUser) {
|
||||
String sql = "";
|
||||
Boolean isLimitedChecker = false;
|
||||
if (useType.equals("makerchecker")) {
|
||||
if (currentUser.hasNotPermissionForAnyOf("ALL_FUNCTIONS", "CHECKER_SUPER_USER")) {
|
||||
isLimitedChecker = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isLimitedChecker) {
|
||||
sql += " join m_role_permission rp on rp.permission_id = p.id"
|
||||
+ " join m_role r on r.id = rp.role_id "
|
||||
+ " join m_appuser_role ur on ur.role_id = r.id and ur.appuser_id = "
|
||||
+ currentUser.getId();
|
||||
if (isLimitedChecker) {
|
||||
sql += " join m_role_permission rp on rp.permission_id = p.id" + " join m_role r on r.id = rp.role_id "
|
||||
+ " join m_appuser_role ur on ur.role_id = r.id and ur.appuser_id = " + currentUser.getId();
|
||||
|
||||
}
|
||||
sql += " where p.action_name is not null and p.action_name <> 'READ' ";
|
||||
if (isLimitedChecker) {
|
||||
sql += "and p.code like '%\\_CHECKER'";
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
sql += " where p.action_name is not null and p.action_name <> 'READ' ";
|
||||
if (isLimitedChecker) {
|
||||
sql += "and p.code like '%\\_CHECKER'";
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
private static final class ActionNamesMapper implements RowMapper<String> {
|
||||
private static final class ActionNamesMapper implements RowMapper<String> {
|
||||
|
||||
@Override
|
||||
public String mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
@Override
|
||||
public String mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
return rs.getString("actionName");
|
||||
}
|
||||
return rs.getString("actionName");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static final class EntityNamesMapper implements RowMapper<String> {
|
||||
private static final class EntityNamesMapper implements RowMapper<String> {
|
||||
|
||||
@Override
|
||||
public String mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
return rs.getString("entityName");
|
||||
}
|
||||
@Override
|
||||
public String mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
return rs.getString("entityName");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ProcessingResultsMapper implements
|
||||
RowMapper<ProcessingResultLookup> {
|
||||
private static final class ProcessingResultsMapper implements RowMapper<ProcessingResultLookup> {
|
||||
|
||||
@Override
|
||||
public ProcessingResultLookup mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
Long id = JdbcSupport.getLong(rs, "id");
|
||||
String processingResult = rs.getString("processingResult");
|
||||
@Override
|
||||
public ProcessingResultLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
Long id = JdbcSupport.getLong(rs, "id");
|
||||
String processingResult = rs.getString("processingResult");
|
||||
|
||||
return new ProcessingResultLookup(id, processingResult);
|
||||
}
|
||||
return new ProcessingResultLookup(id, processingResult);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return " select enum_id as id, enum_message_property as processingResult from r_enum_value where enum_name = 'processing_result_enum' "
|
||||
+ " order by enum_id";
|
||||
}
|
||||
}
|
||||
public String schema() {
|
||||
return " select enum_id as id, enum_message_property as processingResult from r_enum_value where enum_name = 'processing_result_enum' "
|
||||
+ " order by enum_id";
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -56,6 +56,10 @@ public final class Client extends AbstractPersistable<Long> {
|
||||
@Column(name = "status_enum", nullable = false)
|
||||
private Integer status;
|
||||
|
||||
@Column(name = "activation_date", nullable = true)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date activationDate;
|
||||
|
||||
@Column(name = "firstname", length = 50)
|
||||
private String firstname;
|
||||
|
||||
@@ -72,10 +76,6 @@ public final class Client extends AbstractPersistable<Long> {
|
||||
@Column(name = "display_name", length = 100, nullable = false)
|
||||
private String displayName;
|
||||
|
||||
@Column(name = "activation_date", nullable = true)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date activationDate;
|
||||
|
||||
@Column(name = "external_id", length = 100, nullable = true, unique = true)
|
||||
private String externalId;
|
||||
|
||||
|
||||
+2
-2
@@ -292,8 +292,8 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
private static final class ParentGroupsMapper implements RowMapper<GroupGeneralData> {
|
||||
|
||||
public String parentGroupsSchema() {
|
||||
return "gp.id As groupId , gp.name As groupName from m_client cl JOIN m_group_client gc ON cl.id = gc.client_id "
|
||||
+ "JOIN m_group gp ON gp.id = gc.group_id WHERE cl.id = ? AND gp.is_deleted = 0 ";
|
||||
return "gp.id As groupId , gp.display_name As groupName from m_client cl JOIN m_group_client gc ON cl.id = gc.client_id "
|
||||
+ "JOIN m_group gp ON gp.id = gc.group_id WHERE cl.id = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-4
@@ -84,18 +84,15 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
|
||||
final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
|
||||
|
||||
final Long officeId = client.getOffice().getId();
|
||||
|
||||
if (client.isNotPending()) { throw new ClientMustBePendingToBeDeletedException(clientId); }
|
||||
|
||||
List<Note> relatedNotes = this.noteRepository.findByClientId(clientId);
|
||||
this.noteRepository.deleteInBatch(relatedNotes);
|
||||
|
||||
// client.delete();
|
||||
this.clientRepository.delete(client);
|
||||
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withOfficeId(officeId) //
|
||||
.withOfficeId(client.officeId()) //
|
||||
.withClientId(clientId) //
|
||||
.withEntityId(clientId) //
|
||||
.build();
|
||||
|
||||
+1
-1
@@ -171,7 +171,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe
|
||||
|
||||
public String collectionSheetSchema() {
|
||||
|
||||
return "SELECT gp.name As groupName, "
|
||||
return "SELECT gp.display_name As groupName, "
|
||||
+ "gp.id As groupId, "
|
||||
+ "cl.display_name As clientName, "
|
||||
+ "sf.id As staffId, "
|
||||
|
||||
+2
-2
@@ -120,8 +120,8 @@ public class CentersApiResource {
|
||||
}
|
||||
|
||||
if (!associationParameters.isEmpty()) {
|
||||
if (associationParameters.contains("groups")) {
|
||||
center = CenterData.setGroups(center, this.centerReadPlatformService.retriveAssociatedGroups(centerId));
|
||||
if (associationParameters.contains("groupMembers")) {
|
||||
center = CenterData.setGroups(center, this.centerReadPlatformService.retrieveAssociatedGroups(centerId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+13
-1
@@ -22,6 +22,13 @@ public class GroupingTypesApiConstants {
|
||||
public static final String externalIdParamName = "externalId";
|
||||
public static final String officeIdParamName = "officeId";
|
||||
public static final String staffIdParamName = "staffId";
|
||||
public static final String activeParamName = "active";
|
||||
public static final String activationDateParamName = "activationDate";
|
||||
public static final String groupMembersParamName = "groupMembers";
|
||||
|
||||
// group parameters
|
||||
public static final String centerIdParamName = "centerId";
|
||||
public static final String clientMembersParamName = "clientMembers";
|
||||
|
||||
// response parameters
|
||||
public static final String hierarchyParamName = "hierarchy";
|
||||
@@ -32,7 +39,12 @@ public class GroupingTypesApiConstants {
|
||||
public static final String clientOptionsParamName = "clientOptions";
|
||||
|
||||
public static final Set<String> CENTER_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName,
|
||||
dateFormatParamName, nameParamName, externalIdParamName, officeIdParamName, staffIdParamName));
|
||||
dateFormatParamName, idParamName, nameParamName, externalIdParamName, officeIdParamName, staffIdParamName, activeParamName,
|
||||
activationDateParamName, groupMembersParamName));
|
||||
|
||||
public static final Set<String> GROUP_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName, dateFormatParamName,
|
||||
idParamName, nameParamName, externalIdParamName, centerIdParamName, officeIdParamName, staffIdParamName, activeParamName,
|
||||
activationDateParamName, clientMembersParamName));
|
||||
|
||||
/**
|
||||
* These parameters will match the class level parameters of
|
||||
|
||||
+10
-3
@@ -124,12 +124,19 @@ public class GroupsApiResource {
|
||||
public String retrieveOne(@Context final UriInfo uriInfo, @PathParam("groupId") final Long groupId) {
|
||||
|
||||
this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.GROUP_RESOURCE_NAME);
|
||||
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
|
||||
GroupGeneralData group = this.groupReadPlatformService.retrieveOne(groupId);
|
||||
|
||||
Collection<ClientData> membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId);
|
||||
if (CollectionUtils.isEmpty(membersOfGroup)) {
|
||||
membersOfGroup = null;
|
||||
// associations
|
||||
Collection<ClientData> membersOfGroup = null;
|
||||
if (!associationParameters.isEmpty()) {
|
||||
if (associationParameters.contains("clientMembers")) {
|
||||
membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId);
|
||||
if (CollectionUtils.isEmpty(membersOfGroup)) {
|
||||
membersOfGroup = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.group.command;
|
||||
|
||||
public class GroupCommand {
|
||||
|
||||
private final String externalId;
|
||||
private final String name;
|
||||
private final Long officeId;
|
||||
private final Long staffId;
|
||||
private final Long parentId;
|
||||
private final String[] clientMembers;
|
||||
private final String[] childGroups;
|
||||
|
||||
public GroupCommand(final String externalId, final String name, final Long officeId, final Long staffId, final String[] clientMembers,
|
||||
final String[] childGroups, final Long parentId) {
|
||||
this.officeId = officeId;
|
||||
this.staffId = staffId;
|
||||
this.parentId = parentId;
|
||||
this.externalId = externalId;
|
||||
this.name = name;
|
||||
this.clientMembers = clientMembers;
|
||||
this.childGroups = childGroups;
|
||||
|
||||
}
|
||||
|
||||
public Long getOfficeId() {
|
||||
return this.officeId;
|
||||
}
|
||||
|
||||
public Long getParentId() {
|
||||
return this.parentId;
|
||||
}
|
||||
|
||||
public Long getStaffId() {
|
||||
return this.staffId;
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
return this.externalId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String[] getClientMembers() {
|
||||
return this.clientMembers;
|
||||
}
|
||||
|
||||
public String[] getChildGroups() {
|
||||
return this.childGroups;
|
||||
}
|
||||
|
||||
}
|
||||
+47
-19
@@ -7,6 +7,8 @@ package org.mifosplatform.portfolio.group.data;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
|
||||
@@ -16,8 +18,15 @@ import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
public class CenterData {
|
||||
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String externalId;
|
||||
|
||||
private final EnumOptionData status;
|
||||
@SuppressWarnings("unused")
|
||||
private final boolean active;
|
||||
private final LocalDate activationDate;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final Long officeId;
|
||||
private final String officeName;
|
||||
private final Long staffId;
|
||||
@@ -25,51 +34,70 @@ public class CenterData {
|
||||
private final String hierarchy;
|
||||
|
||||
// associations
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<GroupGeneralData> groups;
|
||||
private final Collection<GroupGeneralData> groupMembers;
|
||||
|
||||
// template
|
||||
private final Collection<OfficeData> officeOptions;
|
||||
private final Collection<StaffData> staffOptions;
|
||||
private final Collection<GroupGeneralData> groupMembersOptions;
|
||||
|
||||
public static CenterData template(final Long officeId, final Collection<OfficeData> officeOptions,
|
||||
final Collection<StaffData> staffOptions) {
|
||||
return new CenterData(null, null, null, officeId, null, null, null, null, officeOptions, staffOptions, null);
|
||||
public static CenterData template(final Long officeId, final LocalDate activationDate, final Collection<OfficeData> officeOptions,
|
||||
final Collection<StaffData> staffOptions, final Collection<GroupGeneralData> groupMembersOptions) {
|
||||
return new CenterData(null, null, null, null, activationDate, officeId, null, null, null, null, null, officeOptions, staffOptions,
|
||||
groupMembersOptions);
|
||||
}
|
||||
|
||||
public static CenterData withTemplate(final CenterData templateCenter, final CenterData center) {
|
||||
return new CenterData(center.id, center.name, center.externalId, center.officeId, center.officeName, center.staffId,
|
||||
center.staffName, center.hierarchy, templateCenter.officeOptions, templateCenter.staffOptions, null);
|
||||
return new CenterData(center.id, center.name, center.externalId, center.status, center.activationDate, center.officeId,
|
||||
center.officeName, center.staffId, center.staffName, center.hierarchy, center.groupMembers, templateCenter.officeOptions,
|
||||
templateCenter.staffOptions, templateCenter.groupMembersOptions);
|
||||
}
|
||||
|
||||
public static CenterData instance(final Long id, final String name, final String externalId, final Long officeId,
|
||||
final String officeName, final Long staffId, final String staffName, final String hierarchy) {
|
||||
public static CenterData instance(final Long id, final String name, final String externalId, final EnumOptionData status,
|
||||
final LocalDate activationDate, final Long officeId, final String officeName, final Long staffId, final String staffName,
|
||||
final String hierarchy) {
|
||||
|
||||
final Collection<GroupGeneralData> groupMembers = null;
|
||||
final Collection<OfficeData> officeOptions = null;
|
||||
final Collection<StaffData> staffOptions = null;
|
||||
final Collection<GroupGeneralData> groupMembersOptions = null;
|
||||
|
||||
return new CenterData(id, name, externalId, officeId, officeName, staffId, staffName, hierarchy, officeOptions, staffOptions, null);
|
||||
}
|
||||
|
||||
public static CenterData setGroups(final CenterData centerData, final Collection<GroupGeneralData> groups){
|
||||
return new CenterData(centerData.id, centerData.name, centerData.externalId, centerData.officeId, centerData.officeName, centerData.staffId, centerData.staffName, centerData.hierarchy, centerData.officeOptions, centerData.staffOptions, groups);
|
||||
return new CenterData(id, name, externalId, status, activationDate, officeId, officeName, staffId, staffName, hierarchy,
|
||||
groupMembers, officeOptions, staffOptions, groupMembersOptions);
|
||||
}
|
||||
|
||||
private CenterData(final Long id, final String name, final String externalId, final Long officeId, final String officeName,
|
||||
final Long staffId, final String staffName, final String hierarchy, final Collection<OfficeData> officeOptions,
|
||||
final Collection<StaffData> staffOptions, final Collection<GroupGeneralData> groups) {
|
||||
public static CenterData setGroups(final CenterData centerData, final Collection<GroupGeneralData> groupMembers) {
|
||||
return new CenterData(centerData.id, centerData.name, centerData.externalId, centerData.status, centerData.activationDate,
|
||||
centerData.officeId, centerData.officeName, centerData.staffId, centerData.staffName, centerData.hierarchy, groupMembers,
|
||||
centerData.officeOptions, centerData.staffOptions, centerData.groupMembersOptions);
|
||||
}
|
||||
|
||||
private CenterData(final Long id, final String name, final String externalId, final EnumOptionData status,
|
||||
final LocalDate activationDate, final Long officeId, final String officeName, final Long staffId, final String staffName,
|
||||
final String hierarchy, final Collection<GroupGeneralData> groupMembers, final Collection<OfficeData> officeOptions,
|
||||
final Collection<StaffData> staffOptions, final Collection<GroupGeneralData> groupMembersOptions) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.externalId = externalId;
|
||||
this.status = status;
|
||||
if (status != null) {
|
||||
this.active = status.getId().equals(300L);
|
||||
} else {
|
||||
this.active = false;
|
||||
}
|
||||
this.activationDate = activationDate;
|
||||
this.officeId = officeId;
|
||||
this.officeName = officeName;
|
||||
this.staffId = staffId;
|
||||
this.staffName = staffName;
|
||||
this.hierarchy = hierarchy;
|
||||
|
||||
this.groupMembers = groupMembers;
|
||||
|
||||
//
|
||||
this.officeOptions = officeOptions;
|
||||
this.staffOptions = staffOptions;
|
||||
this.groups = groups;
|
||||
this.groupMembersOptions = groupMembersOptions;
|
||||
}
|
||||
|
||||
public Long officeId() {
|
||||
|
||||
+5
-5
@@ -76,7 +76,7 @@ public class GroupGeneralData {
|
||||
}
|
||||
|
||||
public static GroupGeneralData instance(final Long id, final String name, final String externalId, final Long officeId,
|
||||
final String officeName, final Long parentId, final String parentName, final Long staffId, final String staffName,
|
||||
final String officeName, final Long centerId, final String centerName, final Long staffId, final String staffName,
|
||||
final String hierarchy) {
|
||||
|
||||
final Collection<ClientData> clientMembers = null;
|
||||
@@ -85,12 +85,12 @@ public class GroupGeneralData {
|
||||
final Collection<StaffData> staffOptions = null;
|
||||
final Collection<ClientData> clientOptions = null;
|
||||
|
||||
return new GroupGeneralData(id, name, externalId, officeId, officeName, parentId, parentName, staffId, staffName, hierarchy,
|
||||
return new GroupGeneralData(id, name, externalId, officeId, officeName, centerId, centerName, staffId, staffName, hierarchy,
|
||||
clientMembers, centerOptions, officeOptions, staffOptions, clientOptions);
|
||||
}
|
||||
|
||||
private GroupGeneralData(final Long id, final String name, final String externalId, final Long officeId, final String officeName,
|
||||
final Long parentId, final String parentName, final Long staffId, final String staffName, final String hierarchy,
|
||||
final Long centerId, final String centerName, final Long staffId, final String staffName, final String hierarchy,
|
||||
final Collection<ClientData> clientMembers, final Collection<CenterData> centerOptions,
|
||||
final Collection<OfficeData> officeOptions, final Collection<StaffData> staffOptions, final Collection<ClientData> clientOptions) {
|
||||
this.id = id;
|
||||
@@ -98,8 +98,8 @@ public class GroupGeneralData {
|
||||
this.externalId = externalId;
|
||||
this.officeId = officeId;
|
||||
this.officeName = officeName;
|
||||
this.centerId = parentId;
|
||||
this.centerName = parentName;
|
||||
this.centerId = centerId;
|
||||
this.centerName = centerName;
|
||||
this.staffId = staffId;
|
||||
this.staffName = staffName;
|
||||
this.hierarchy = hierarchy;
|
||||
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.group.data;
|
||||
|
||||
/**
|
||||
* Immutable data object representing groups.
|
||||
*/
|
||||
@Deprecated
|
||||
public class GroupLookup {
|
||||
|
||||
private final Long id;
|
||||
private final String name;
|
||||
|
||||
public GroupLookup(final Long id, final String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
+57
-37
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package org.mifosplatform.portfolio.group.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -19,8 +20,11 @@ import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.organisation.office.domain.Office;
|
||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||
import org.mifosplatform.portfolio.client.domain.Client;
|
||||
@@ -28,15 +32,20 @@ import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
@Entity
|
||||
@Table(name = "m_group")
|
||||
public class Group extends AbstractPersistable<Long> {
|
||||
public final class Group extends AbstractPersistable<Long> {
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "parent_id")
|
||||
private final List<Group> children = new LinkedList<Group>();
|
||||
@Column(name = "external_id", length = 100, unique = true)
|
||||
private String externalId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "parent_id")
|
||||
private Group parent;
|
||||
/**
|
||||
* A value from {@link GroupingTypeStatus}.
|
||||
*/
|
||||
@Column(name = "status_enum", nullable = false)
|
||||
private Integer status;
|
||||
|
||||
@Column(name = "activation_date", nullable = true)
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date activationDate;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "office_id", nullable = false)
|
||||
@@ -46,21 +55,27 @@ public class Group extends AbstractPersistable<Long> {
|
||||
@JoinColumn(name = "staff_id", nullable = true)
|
||||
private Staff staff;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "parent_id")
|
||||
private Group parent;
|
||||
|
||||
/*
|
||||
* TODO - kw - it might be possible to just move this to be a java enum type
|
||||
* rather than 'levels' table.
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "level_id", nullable = false)
|
||||
private GroupLevel groupLevel;
|
||||
|
||||
@Column(name = "display_name", length = 100, unique = true)
|
||||
private String name;
|
||||
|
||||
@Column(name = "hierarchy", length = 100)
|
||||
private String hierarchy;
|
||||
|
||||
@Column(name = "name", length = 100, unique = true)
|
||||
private String name;
|
||||
|
||||
@Column(name = "external_id", length = 100, unique = true)
|
||||
private String externalId;
|
||||
|
||||
@Column(name = "is_deleted", nullable = false)
|
||||
private boolean deleted = false;
|
||||
@OneToMany(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "parent_id")
|
||||
private final List<Group> groupMembers = new LinkedList<Group>();
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "m_group_client", joinColumns = @JoinColumn(name = "group_id"), inverseJoinColumns = @JoinColumn(name = "client_id"))
|
||||
@@ -73,12 +88,20 @@ public class Group extends AbstractPersistable<Long> {
|
||||
}
|
||||
|
||||
public static Group newGroup(final Office office, final Staff staff, final Group parent, final GroupLevel groupLevel,
|
||||
final String name, final String externalId, final Set<Client> clientMembers, final Set<Group> childGroups) {
|
||||
return new Group(office, staff, parent, groupLevel, name, externalId, clientMembers, childGroups);
|
||||
final String name, final String externalId, final boolean active, final LocalDate activationDate,
|
||||
final Set<Client> clientMembers, final Set<Group> groupMembers) {
|
||||
|
||||
GroupingTypeStatus status = GroupingTypeStatus.PENDING;
|
||||
if (active) {
|
||||
status = GroupingTypeStatus.ACTIVE;
|
||||
}
|
||||
|
||||
return new Group(office, staff, parent, groupLevel, name, externalId, status, activationDate, clientMembers, groupMembers);
|
||||
}
|
||||
|
||||
public Group(final Office office, final Staff staff, final Group parent, final GroupLevel groupLevel, final String name,
|
||||
final String externalId, final Set<Client> clientMembers, final Set<Group> childGroups) {
|
||||
final String externalId, final GroupingTypeStatus status, final LocalDate activationDate, final Set<Client> clientMembers,
|
||||
final Set<Group> groupMembers) {
|
||||
this.office = office;
|
||||
this.staff = staff;
|
||||
this.groupLevel = groupLevel;
|
||||
@@ -88,6 +111,11 @@ public class Group extends AbstractPersistable<Long> {
|
||||
this.parent.addChild(this);
|
||||
}
|
||||
|
||||
this.status = status.getValue();
|
||||
if (activationDate != null) {
|
||||
this.activationDate = activationDate.toDate();
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
this.name = name.trim();
|
||||
} else {
|
||||
@@ -101,13 +129,21 @@ public class Group extends AbstractPersistable<Long> {
|
||||
if (clientMembers != null) {
|
||||
this.clientMembers = clientMembers;
|
||||
}
|
||||
if (childGroups != null) {
|
||||
this.children.addAll(childGroups);
|
||||
if (groupMembers != null) {
|
||||
this.groupMembers.addAll(groupMembers);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNotPending() {
|
||||
return !isPending();
|
||||
}
|
||||
|
||||
public boolean isPending() {
|
||||
return GroupingTypeStatus.fromInt(this.status).isPending();
|
||||
}
|
||||
|
||||
private void addChild(final Group group) {
|
||||
this.children.add(group);
|
||||
this.groupMembers.add(group);
|
||||
}
|
||||
|
||||
public Long getOfficeId() {
|
||||
@@ -182,22 +218,6 @@ public class Group extends AbstractPersistable<Long> {
|
||||
return this.clientMembers.contains(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete is a <i>soft delete</i>. Updates flag on group so it wont appear
|
||||
* in query/report results.
|
||||
*
|
||||
* Any fields with unique constraints and prepended with id of record.
|
||||
*/
|
||||
public void delete() {
|
||||
this.deleted = true;
|
||||
this.externalId = getId() + "_" + this.externalId;
|
||||
this.name = getId() + "_" + this.name;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return this.deleted;
|
||||
}
|
||||
|
||||
public void generateHierarchy() {
|
||||
|
||||
if (this.parent != null) {
|
||||
|
||||
+1
-2
@@ -74,5 +74,4 @@ public class GroupLevel extends AbstractPersistable<Long> {
|
||||
public boolean isIdentifiedByParentId(final Long parentLevelId) {
|
||||
return this.parentId.equals(parentLevelId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,19 +1,19 @@
|
||||
package org.mifosplatform.portfolio.group.data;
|
||||
package org.mifosplatform.portfolio.group.domain;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum GroupTypes {
|
||||
|
||||
CENTER(new Long(1), "groupTypes.center", "center"), //
|
||||
GROUP(new Long(2), "groupTypes.group", "group"), //
|
||||
INVALID(new Long(99), "lendingStrategy.invalid", "invalid");
|
||||
INVALID(0l, "lendingStrategy.invalid", "invalid"), //
|
||||
CENTER(1l, "groupTypes.center", "center"), //
|
||||
GROUP(2l, "groupTypes.group", "group"); //
|
||||
|
||||
private Long id;
|
||||
private String code;
|
||||
private String value;
|
||||
|
||||
GroupTypes(final Long id, final String code, final String value) {
|
||||
private GroupTypes(final Long id, final String code, final String value) {
|
||||
this.id = id;
|
||||
this.code = code;
|
||||
this.value = value;
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.group.domain;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
|
||||
public class GroupingTypeEnumerations {
|
||||
|
||||
public static EnumOptionData status(final Integer statusId) {
|
||||
return status(GroupingTypeStatus.fromInt(statusId));
|
||||
}
|
||||
|
||||
public static EnumOptionData status(final GroupingTypeStatus status) {
|
||||
EnumOptionData optionData = new EnumOptionData(GroupingTypeStatus.INVALID.getValue().longValue(),
|
||||
GroupingTypeStatus.INVALID.getCode(), "Invalid");
|
||||
switch (status) {
|
||||
case INVALID:
|
||||
optionData = new EnumOptionData(GroupingTypeStatus.INVALID.getValue().longValue(), GroupingTypeStatus.INVALID.getCode(),
|
||||
"Invalid");
|
||||
break;
|
||||
case PENDING:
|
||||
optionData = new EnumOptionData(GroupingTypeStatus.PENDING.getValue().longValue(), GroupingTypeStatus.PENDING.getCode(),
|
||||
"Pending");
|
||||
break;
|
||||
case ACTIVE:
|
||||
optionData = new EnumOptionData(GroupingTypeStatus.ACTIVE.getValue().longValue(), GroupingTypeStatus.ACTIVE.getCode(),
|
||||
"Active");
|
||||
break;
|
||||
case CLOSED:
|
||||
optionData = new EnumOptionData(GroupingTypeStatus.CLOSED.getValue().longValue(), GroupingTypeStatus.CLOSED.getCode(),
|
||||
"Closed");
|
||||
break;
|
||||
}
|
||||
|
||||
return optionData;
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.group.domain;
|
||||
|
||||
/**
|
||||
* Enum representation of grouping type status states.
|
||||
*/
|
||||
public enum GroupingTypeStatus {
|
||||
|
||||
INVALID(0, "groupingStatusType.invalid"), //
|
||||
PENDING(100, "groupingStatusType.pending"), //
|
||||
ACTIVE(300, "groupingStatusType.active"), //
|
||||
CLOSED(600, "groupingStatusType.closed");
|
||||
|
||||
private final Integer value;
|
||||
private final String code;
|
||||
|
||||
public static GroupingTypeStatus fromInt(final Integer statusValue) {
|
||||
|
||||
GroupingTypeStatus enumeration = GroupingTypeStatus.INVALID;
|
||||
switch (statusValue) {
|
||||
case 100:
|
||||
enumeration = GroupingTypeStatus.PENDING;
|
||||
break;
|
||||
case 300:
|
||||
enumeration = GroupingTypeStatus.ACTIVE;
|
||||
break;
|
||||
case 600:
|
||||
enumeration = GroupingTypeStatus.CLOSED;
|
||||
break;
|
||||
}
|
||||
return enumeration;
|
||||
}
|
||||
|
||||
private GroupingTypeStatus(final Integer value, final String code) {
|
||||
this.value = value;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public boolean hasStateOf(final GroupingTypeStatus state) {
|
||||
return this.value.equals(state.getValue());
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public boolean isPending() {
|
||||
return this.value.equals(GroupingTypeStatus.PENDING.getValue());
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return this.value.equals(GroupingTypeStatus.ACTIVE.getValue());
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return this.value.equals(GroupingTypeStatus.CLOSED.getValue());
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.group.exception;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||
|
||||
/**
|
||||
* A {@link RuntimeException} thrown when attempting to delete groups.
|
||||
*/
|
||||
public class GroupMustBePendingToBeDeletedException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public GroupMustBePendingToBeDeletedException(final Long id) {
|
||||
super("error.msg.group.cannot.be.deleted", "Group with identifier " + id + " cannot be deleted as it is not in `Pending` state.",
|
||||
id);
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler;
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
|
||||
import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -16,17 +16,16 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class CreateCenterCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final GroupWritePlatformService groupWritePlatformService;
|
||||
private static final Long LEVEL_ID = (long) 1;
|
||||
private final GroupingTypesWritePlatformService groupWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public CreateCenterCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
|
||||
public CreateCenterCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) {
|
||||
this.groupWritePlatformService = groupWritePlatformService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
return this.groupWritePlatformService.createGroup(null , LEVEL_ID , command);
|
||||
return this.groupWritePlatformService.createCenter(command);
|
||||
}
|
||||
}
|
||||
+4
-6
@@ -8,8 +8,7 @@ package org.mifosplatform.portfolio.group.handler;
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.group.data.GroupTypes;
|
||||
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
|
||||
import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -17,11 +16,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class CreateGroupCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final GroupWritePlatformService groupWritePlatformService;
|
||||
private static final Long LEVEL_ID = GroupTypes.GROUP.getId();;
|
||||
private final GroupingTypesWritePlatformService groupWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public CreateGroupCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
|
||||
public CreateGroupCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) {
|
||||
this.groupWritePlatformService = groupWritePlatformService;
|
||||
}
|
||||
|
||||
@@ -30,6 +28,6 @@ public class CreateGroupCommandHandler implements NewCommandSourceHandler {
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
|
||||
final Long centerId = command.longValueOfParameterNamed("centerId");
|
||||
return this.groupWritePlatformService.createGroup(centerId , LEVEL_ID , command);
|
||||
return this.groupWritePlatformService.createGroup(centerId, command);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler;
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
|
||||
import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class DeleteCenterCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final GroupWritePlatformService groupWritePlatformService;
|
||||
private final GroupingTypesWritePlatformService groupWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public DeleteCenterCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
|
||||
public DeleteCenterCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) {
|
||||
this.groupWritePlatformService = groupWritePlatformService;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler;
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
|
||||
import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class DeleteGroupCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final GroupWritePlatformService groupWritePlatformService;
|
||||
private final GroupingTypesWritePlatformService groupWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public DeleteGroupCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
|
||||
public DeleteGroupCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) {
|
||||
this.groupWritePlatformService = groupWritePlatformService;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler;
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
|
||||
import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class UnassignStaffCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final GroupWritePlatformService groupWritePlatformService;
|
||||
private final GroupingTypesWritePlatformService groupWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public UnassignStaffCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
|
||||
public UnassignStaffCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) {
|
||||
this.groupWritePlatformService = groupWritePlatformService;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler;
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
|
||||
import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class UpdateCenterCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final GroupWritePlatformService groupWritePlatformService;
|
||||
private final GroupingTypesWritePlatformService groupWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public UpdateCenterCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
|
||||
public UpdateCenterCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) {
|
||||
this.groupWritePlatformService = groupWritePlatformService;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,6 @@ public class UpdateCenterCommandHandler implements NewCommandSourceHandler {
|
||||
@Override
|
||||
public CommandProcessingResult processCommand(final JsonCommand command) {
|
||||
|
||||
return this.groupWritePlatformService.updateGroup(command.entityId(), command);
|
||||
return this.groupWritePlatformService.updateCenter(command.entityId(), command);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.group.handler;
|
||||
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.portfolio.group.service.GroupWritePlatformService;
|
||||
import org.mifosplatform.portfolio.group.service.GroupingTypesWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -16,10 +16,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Service
|
||||
public class UpdateGroupCommandHandler implements NewCommandSourceHandler {
|
||||
|
||||
private final GroupWritePlatformService groupWritePlatformService;
|
||||
private final GroupingTypesWritePlatformService groupWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public UpdateGroupCommandHandler(final GroupWritePlatformService groupWritePlatformService) {
|
||||
public UpdateGroupCommandHandler(final GroupingTypesWritePlatformService groupWritePlatformService) {
|
||||
this.groupWritePlatformService = groupWritePlatformService;
|
||||
}
|
||||
|
||||
|
||||
-183
@@ -1,183 +0,0 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.group.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.portfolio.client.command.ClientCommand;
|
||||
import org.mifosplatform.portfolio.group.command.GroupCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link ClientCommand}
|
||||
* 's.
|
||||
*/
|
||||
@Component
|
||||
public final class GroupCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer<GroupCommand> {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "externalId", "name", "officeId", "staffId",
|
||||
"centerId", "clientMembers", "childGroups"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public GroupCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupCommand commandFromApiJson(final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters);
|
||||
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
final String externalId = this.fromApiJsonHelper.extractStringNamed("externalId", element);
|
||||
final String name = this.fromApiJsonHelper.extractStringNamed("name", element);
|
||||
final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", element);
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed("staffId", element);
|
||||
final Long parentId = this.fromApiJsonHelper.extractLongNamed("parentId", element);
|
||||
final String[] clientMembers = this.fromApiJsonHelper.extractArrayNamed("clientMembers", element);
|
||||
final String[] childGroups = this.fromApiJsonHelper.extractArrayNamed("childGroups", element);
|
||||
|
||||
return new GroupCommand(externalId, name, officeId, staffId, clientMembers, childGroups, parentId);
|
||||
}
|
||||
|
||||
public void validateForCreate(final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters);
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("group");
|
||||
|
||||
/*
|
||||
* Name is a mandatory field and not exceeding length 100 character
|
||||
*/
|
||||
final String nameParameterName = "name";
|
||||
final String name = this.fromApiJsonHelper.extractStringNamed(nameParameterName, element);
|
||||
baseDataValidator.reset().parameter(nameParameterName).value(name).notNull().notExceedingLengthOf(100);
|
||||
|
||||
final String externalIdParameterName = "externalId";
|
||||
if (this.fromApiJsonHelper.parameterExists(externalIdParameterName, element)) {
|
||||
final String externalId = this.fromApiJsonHelper.extractStringNamed(externalIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(externalIdParameterName).value(externalId).ignoreIfNull().notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
/*
|
||||
* Either OfficeId or ParentId is mandatory to have value
|
||||
*/
|
||||
|
||||
final String centerIdParameterName = "centerId";
|
||||
if (this.fromApiJsonHelper.parameterExists(centerIdParameterName, element)) {
|
||||
final Long centerId = this.fromApiJsonHelper.extractLongNamed(centerIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(centerIdParameterName).value(centerId).notNull().integerGreaterThanZero();
|
||||
}else{
|
||||
final String officeIdParameterName = "officeId";
|
||||
final Long officeId = this.fromApiJsonHelper.extractLongNamed(officeIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(officeIdParameterName).value(officeId).notNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
final String staffIdParameterName = "staffId";
|
||||
if (this.fromApiJsonHelper.parameterExists(staffIdParameterName, element)) {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).ignoreIfNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public void validateForUpdate(final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
/*
|
||||
* Office updated is not supported
|
||||
*/
|
||||
final Set<String> supportedParametersForupdate = new HashSet<String>(Arrays.asList("id", "externalId", "name", "staffId",
|
||||
"parentId", "clientMembers", "childGroups"));
|
||||
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersForupdate);
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("group");
|
||||
|
||||
final String externalIdParameterName = "externalId";
|
||||
if (this.fromApiJsonHelper.parameterExists(externalIdParameterName, element)) {
|
||||
final String externalId = this.fromApiJsonHelper.extractStringNamed(externalIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(externalIdParameterName).value(externalId).ignoreIfNull().notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
final String parentIdParameterName = "parentId";
|
||||
if (this.fromApiJsonHelper.parameterExists(parentIdParameterName, element)) {
|
||||
final Long parentId = this.fromApiJsonHelper.extractLongNamed(parentIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(parentIdParameterName).value(parentId).ignoreIfNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
final String staffIdParameterName = "staffId";
|
||||
if (this.fromApiJsonHelper.parameterExists(staffIdParameterName, element)) {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).ignoreIfNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public void validateForUnassignStaff(final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
final Set<String> supportedParametersUnassignStaff = new HashSet<String>(Arrays.asList("staffId"));
|
||||
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersUnassignStaff);
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("group");
|
||||
|
||||
final String staffIdParameterName = "staffId";
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).notNull().integerGreaterThanZero();
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
}
|
||||
+377
@@ -0,0 +1,377 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.group.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.portfolio.client.api.ClientApiConstants;
|
||||
import org.mifosplatform.portfolio.client.command.ClientCommand;
|
||||
import org.mifosplatform.portfolio.group.api.GroupingTypesApiConstants;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link ClientCommand}
|
||||
* 's.
|
||||
*/
|
||||
@Component
|
||||
public final class GroupingTypesDataValidator {
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public GroupingTypesDataValidator(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
//
|
||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.",
|
||||
dataValidationErrors);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateForCreateCenter(final JsonCommand command) {
|
||||
|
||||
final String json = command.json();
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.CENTER_REQUEST_DATA_PARAMETERS);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
|
||||
.resource(GroupingTypesApiConstants.CENTER_RESOURCE_NAME);
|
||||
|
||||
JsonElement element = command.parsedJson();
|
||||
|
||||
final String name = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.nameParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.nameParamName).value(name).notNull().notExceedingLengthOf(100);
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.externalIdParamName, element)) {
|
||||
final String externalId = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.externalIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.externalIdParamName).value(externalId).notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
final Long officeId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.officeIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.officeIdParamName).value(officeId).notNull().integerGreaterThanZero();
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.staffIdParamName, element)) {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.staffIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.staffIdParamName).value(staffId).integerGreaterThanZero();
|
||||
}
|
||||
|
||||
final Boolean active = fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element);
|
||||
if (active != null) {
|
||||
if (active.booleanValue()) {
|
||||
final LocalDate joinedDate = fromApiJsonHelper.extractLocalDateNamed(GroupingTypesApiConstants.activationDateParamName,
|
||||
element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull();
|
||||
} else {
|
||||
// TODO - KW - not using config for now - just supporting move
|
||||
// to pending or active out of box.
|
||||
boolean isPendingApprovalEnabled = true;
|
||||
if (!isPendingApprovalEnabled) {
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.activeParamName)
|
||||
.failWithCode(".pending.status.not.allowed");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
baseDataValidator.reset().parameter(ClientApiConstants.activeParamName).value(active).trueOrFalseRequired(false);
|
||||
}
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
public void validateForCreateCenterGroup(final JsonCommand command) {
|
||||
|
||||
final String json = command.json();
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.GROUP_REQUEST_DATA_PARAMETERS);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
|
||||
.resource(GroupingTypesApiConstants.GROUP_RESOURCE_NAME);
|
||||
|
||||
JsonElement element = command.parsedJson();
|
||||
|
||||
final String name = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.nameParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.nameParamName).value(name).notNull().notExceedingLengthOf(100);
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.externalIdParamName, element)) {
|
||||
final String externalId = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.externalIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.externalIdParamName).value(externalId).notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
final Long centerId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.centerIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.centerIdParamName).value(centerId).notNull().integerGreaterThanZero();
|
||||
|
||||
// office is inherited from center
|
||||
final Long officeId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.officeIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.officeIdParamName).value(officeId).notNull().integerGreaterThanZero();
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.staffIdParamName, element)) {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.staffIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.staffIdParamName).value(staffId).integerGreaterThanZero();
|
||||
}
|
||||
|
||||
final Boolean active = fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element);
|
||||
if (active != null) {
|
||||
if (active.booleanValue()) {
|
||||
final LocalDate joinedDate = fromApiJsonHelper.extractLocalDateNamed(GroupingTypesApiConstants.activationDateParamName,
|
||||
element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull();
|
||||
} else {
|
||||
// TODO - KW - not using config for now - just supporting move
|
||||
// to pending or active out of box.
|
||||
boolean isPendingApprovalEnabled = true;
|
||||
if (!isPendingApprovalEnabled) {
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.activeParamName)
|
||||
.failWithCode(".pending.status.not.allowed");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
baseDataValidator.reset().parameter(ClientApiConstants.activeParamName).value(active).trueOrFalseRequired(false);
|
||||
}
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
public void validateForCreateGroup(final JsonCommand command) {
|
||||
final String json = command.json();
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.GROUP_REQUEST_DATA_PARAMETERS);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
|
||||
.resource(GroupingTypesApiConstants.GROUP_RESOURCE_NAME);
|
||||
|
||||
JsonElement element = command.parsedJson();
|
||||
|
||||
final String name = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.nameParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.nameParamName).value(name).notNull().notExceedingLengthOf(100);
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.externalIdParamName, element)) {
|
||||
final String externalId = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.externalIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.externalIdParamName).value(externalId).notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
// office is inherited from center
|
||||
final Long officeId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.officeIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.officeIdParamName).value(officeId).notNull().integerGreaterThanZero();
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.staffIdParamName, element)) {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.staffIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.staffIdParamName).value(staffId).integerGreaterThanZero();
|
||||
}
|
||||
|
||||
final Boolean active = fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element);
|
||||
if (active != null) {
|
||||
if (active.booleanValue()) {
|
||||
final LocalDate joinedDate = fromApiJsonHelper.extractLocalDateNamed(GroupingTypesApiConstants.activationDateParamName,
|
||||
element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull();
|
||||
} else {
|
||||
// TODO - KW - not using config for now - just supporting move
|
||||
// to pending or active out of box.
|
||||
boolean isPendingApprovalEnabled = true;
|
||||
if (!isPendingApprovalEnabled) {
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.activeParamName)
|
||||
.failWithCode(".pending.status.not.allowed");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
baseDataValidator.reset().parameter(ClientApiConstants.activeParamName).value(active).trueOrFalseRequired(false);
|
||||
}
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
public void validateForUpdateCenter(final JsonCommand command) {
|
||||
final String json = command.json();
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.CENTER_REQUEST_DATA_PARAMETERS);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
|
||||
.resource(GroupingTypesApiConstants.CENTER_RESOURCE_NAME);
|
||||
|
||||
JsonElement element = command.parsedJson();
|
||||
|
||||
final String name = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.nameParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.nameParamName).value(name).notNull().notExceedingLengthOf(100);
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.externalIdParamName, element)) {
|
||||
final String externalId = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.externalIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.externalIdParamName).value(externalId).notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
// dont support update of office at present when updating center?
|
||||
// final Long officeId =
|
||||
// this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.officeIdParamName,
|
||||
// element);
|
||||
// baseDataValidator.reset().parameter(GroupingTypesApiConstants.officeIdParamName).value(officeId).notNull().integerGreaterThanZero();
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.staffIdParamName, element)) {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.staffIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.staffIdParamName).value(staffId).integerGreaterThanZero();
|
||||
}
|
||||
|
||||
final Boolean active = fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element);
|
||||
if (active != null) {
|
||||
if (active.booleanValue()) {
|
||||
final LocalDate joinedDate = fromApiJsonHelper.extractLocalDateNamed(GroupingTypesApiConstants.activationDateParamName,
|
||||
element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull();
|
||||
}
|
||||
}
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
public void validateForUpdateGroup(final JsonCommand command) {
|
||||
final String json = command.json();
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.GROUP_REQUEST_DATA_PARAMETERS);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
|
||||
.resource(GroupingTypesApiConstants.GROUP_RESOURCE_NAME);
|
||||
|
||||
JsonElement element = command.parsedJson();
|
||||
|
||||
final String name = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.nameParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.nameParamName).value(name).notNull().notExceedingLengthOf(100);
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.externalIdParamName, element)) {
|
||||
final String externalId = this.fromApiJsonHelper.extractStringNamed(GroupingTypesApiConstants.externalIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.externalIdParamName).value(externalId).notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.officeIdParamName, element)) {
|
||||
final Long officeId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.officeIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.officeIdParamName).value(officeId).notNull()
|
||||
.integerGreaterThanZero();
|
||||
}
|
||||
|
||||
if (this.fromApiJsonHelper.parameterExists(GroupingTypesApiConstants.staffIdParamName, element)) {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.staffIdParamName, element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.staffIdParamName).value(staffId).integerGreaterThanZero();
|
||||
}
|
||||
|
||||
final Boolean active = fromApiJsonHelper.extractBooleanNamed(GroupingTypesApiConstants.activeParamName, element);
|
||||
if (active != null) {
|
||||
if (active.booleanValue()) {
|
||||
final LocalDate joinedDate = fromApiJsonHelper.extractLocalDateNamed(GroupingTypesApiConstants.activationDateParamName,
|
||||
element);
|
||||
baseDataValidator.reset().parameter(GroupingTypesApiConstants.activationDateParamName).value(joinedDate).notNull();
|
||||
}
|
||||
}
|
||||
|
||||
throwExceptionIfValidationWarningsExist(dataValidationErrors);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void validateForUpdate(final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
/*
|
||||
* Office updated is not supported
|
||||
*/
|
||||
final Set<String> supportedParametersForupdate = new HashSet<String>(Arrays.asList("id", "externalId", "name", "staffId",
|
||||
"parentId", "clientMembers", "childGroups"));
|
||||
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersForupdate);
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("group");
|
||||
|
||||
final String externalIdParameterName = "externalId";
|
||||
if (this.fromApiJsonHelper.parameterExists(externalIdParameterName, element)) {
|
||||
final String externalId = this.fromApiJsonHelper.extractStringNamed(externalIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(externalIdParameterName).value(externalId).ignoreIfNull().notExceedingLengthOf(100);
|
||||
}
|
||||
|
||||
final String parentIdParameterName = "parentId";
|
||||
if (this.fromApiJsonHelper.parameterExists(parentIdParameterName, element)) {
|
||||
final Long parentId = this.fromApiJsonHelper.extractLongNamed(parentIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(parentIdParameterName).value(parentId).ignoreIfNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
final String staffIdParameterName = "staffId";
|
||||
if (this.fromApiJsonHelper.parameterExists(staffIdParameterName, element)) {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).ignoreIfNull().integerGreaterThanZero();
|
||||
}
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
|
||||
public void validateForUnassignStaff(final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
final Set<String> supportedParametersUnassignStaff = new HashSet<String>(Arrays.asList("staffId"));
|
||||
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersUnassignStaff);
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
|
||||
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
|
||||
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("group");
|
||||
|
||||
final String staffIdParameterName = "staffId";
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).notNull().integerGreaterThanZero();
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
|
||||
"Validation errors exist.", dataValidationErrors); }
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package org.mifosplatform.portfolio.group.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||
import org.mifosplatform.portfolio.group.data.GroupGeneralData;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final class AllGroupTypesDataMapper implements RowMapper<GroupGeneralData> {
|
||||
|
||||
private final String schemaSql;
|
||||
|
||||
public AllGroupTypesDataMapper() {
|
||||
final StringBuilder sqlBuilder = new StringBuilder(400);
|
||||
sqlBuilder.append("g.id as id, g.external_id as externalId, g.display_name as displayName, ");
|
||||
sqlBuilder.append("g.office_id as officeId, o.name as officeName, ");
|
||||
sqlBuilder.append("g.parent_id as centerId, pg.display_name as centerName, ");
|
||||
sqlBuilder.append("g.staff_id as staffId, s.display_name as staffName, ");
|
||||
sqlBuilder.append("g.hierarchy as hierarchy ");
|
||||
sqlBuilder.append("from m_group g ");
|
||||
sqlBuilder.append("join m_office o on o.id = g.office_id ");
|
||||
sqlBuilder.append("left join m_staff s on s.id = g.staff_id ");
|
||||
sqlBuilder.append("left join m_group pg on pg.id = g.parent_id ");
|
||||
|
||||
this.schemaSql = sqlBuilder.toString();
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return this.schemaSql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupGeneralData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long id = rs.getLong("id");
|
||||
final String name = rs.getString("displayName");
|
||||
final String externalId = rs.getString("externalId");
|
||||
final Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
final Long centerId = JdbcSupport.getLong(rs, "centerId");
|
||||
final String centerName = rs.getString("centerName");
|
||||
final Long staffId = JdbcSupport.getLong(rs, "staffId");
|
||||
final String staffName = rs.getString("staffName");
|
||||
final String hierarchy = rs.getString("hierarchy");
|
||||
|
||||
return GroupGeneralData.instance(id, name, externalId, officeId, officeName, centerId, centerName, staffId, staffName, hierarchy);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -22,5 +22,5 @@ public interface CenterReadPlatformService {
|
||||
|
||||
GroupGeneralData retrieveCenterGroupTemplate(Long centerId);
|
||||
|
||||
Collection<GroupGeneralData> retriveAssociatedGroups(Long centerId);
|
||||
Collection<GroupGeneralData> retrieveAssociatedGroups(Long centerId);
|
||||
}
|
||||
|
||||
+76
-30
@@ -11,7 +11,10 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.configuration.domain.ConfigurationDomainService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
@@ -23,7 +26,8 @@ import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
|
||||
import org.mifosplatform.portfolio.group.data.CenterData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupGeneralData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupTypes;
|
||||
import org.mifosplatform.portfolio.group.domain.GroupTypes;
|
||||
import org.mifosplatform.portfolio.group.domain.GroupingTypeEnumerations;
|
||||
import org.mifosplatform.portfolio.group.exception.GroupNotFoundException;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -41,14 +45,21 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
private final ClientReadPlatformService clientReadPlatformService;
|
||||
private final OfficeReadPlatformService officeReadPlatformService;
|
||||
private final StaffReadPlatformService staffReadPlatformService;
|
||||
private final ConfigurationDomainService configurationDomainService;
|
||||
|
||||
// data mappers
|
||||
private final AllGroupTypesDataMapper allGroupTypesDataMapper = new AllGroupTypesDataMapper();
|
||||
|
||||
// data mappers
|
||||
private final CenterDataMapper centerMapper = new CenterDataMapper();
|
||||
private final GroupDataMapper groupDataMapper = new GroupDataMapper();
|
||||
|
||||
@Autowired
|
||||
public CenterReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
|
||||
final ClientReadPlatformService clientReadPlatformService, final OfficeReadPlatformService officeReadPlatformService,
|
||||
final StaffReadPlatformService staffReadPlatformService) {
|
||||
final ConfigurationDomainService configurationDomainService, final ClientReadPlatformService clientReadPlatformService,
|
||||
final OfficeReadPlatformService officeReadPlatformService, final StaffReadPlatformService staffReadPlatformService) {
|
||||
this.context = context;
|
||||
this.configurationDomainService = configurationDomainService;
|
||||
this.clientReadPlatformService = clientReadPlatformService;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.officeReadPlatformService = officeReadPlatformService;
|
||||
@@ -64,8 +75,8 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
|
||||
String sqlQueryCriteria = searchCriteria.getSqlSearch();
|
||||
if (StringUtils.isNotBlank(sqlQueryCriteria)) {
|
||||
sqlQueryCriteria = sqlQueryCriteria.replaceAll(" name ", " g.name ");
|
||||
sqlQueryCriteria = sqlQueryCriteria.replaceAll("name ", "g.name ");
|
||||
sqlQueryCriteria = sqlQueryCriteria.replaceAll(" display_name ", " g.display_name ");
|
||||
sqlQueryCriteria = sqlQueryCriteria.replaceAll("display_name ", "g.display_name ");
|
||||
extraCriteria = " and (" + sqlQueryCriteria + ")";
|
||||
}
|
||||
|
||||
@@ -81,7 +92,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
|
||||
final String name = searchCriteria.getName();
|
||||
if (name != null) {
|
||||
extraCriteria += " and g.name like " + ApiParameterHelper.sqlEncodeString(name + "%");
|
||||
extraCriteria += " and g.display_name like " + ApiParameterHelper.sqlEncodeString(name + "%");
|
||||
}
|
||||
|
||||
final String hierarchy = searchCriteria.getHierarchy();
|
||||
@@ -95,21 +106,22 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
|
||||
return extraCriteria;
|
||||
}
|
||||
|
||||
private static final String sqlQuery = "g.id as id, g.external_id as externalId, g.name as name, " +
|
||||
"g.office_id as officeId, o.name as officeName, " +
|
||||
"g.staff_id as staffId, s.display_name as staffName, " +
|
||||
"g.hierarchy as hierarchy " +
|
||||
"from m_group g " +
|
||||
"join m_office o on o.id = g.office_id " +
|
||||
"left join m_staff s on s.id = g.staff_id ";
|
||||
|
||||
|
||||
private static final String sqlQuery = "g.id as id, g.external_id as externalId, g.display_name as name, "
|
||||
+ "g.office_id as officeId, o.name as officeName, " //
|
||||
+ "g.staff_id as staffId, s.display_name as staffName, " //
|
||||
+ "g.status_enum as statusEnum, g.activation_date as activationDate, " //
|
||||
+ "g.hierarchy as hierarchy " //
|
||||
+ "from m_group g " //
|
||||
+ "join m_office o on o.id = g.office_id "
|
||||
+ "left join m_staff s on s.id = g.staff_id ";
|
||||
|
||||
private static final class CenterDataMapper implements RowMapper<CenterData> {
|
||||
|
||||
private final String schemaSql;
|
||||
|
||||
public CenterDataMapper() {
|
||||
|
||||
|
||||
this.schemaSql = sqlQuery;
|
||||
}
|
||||
|
||||
@@ -122,6 +134,9 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
|
||||
final Long id = rs.getLong("id");
|
||||
final String name = rs.getString("name");
|
||||
final Integer statusEnum = JdbcSupport.getInteger(rs, "statusEnum");
|
||||
final EnumOptionData status = GroupingTypeEnumerations.status(statusEnum);
|
||||
final LocalDate activationDate = JdbcSupport.getLocalDate(rs, "activationDate");
|
||||
final String externalId = rs.getString("externalId");
|
||||
final Long officeId = rs.getLong("officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
@@ -129,7 +144,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
final String staffName = rs.getString("staffName");
|
||||
final String hierarchy = rs.getString("hierarchy");
|
||||
|
||||
return CenterData.instance(id, name, externalId, officeId, officeName, staffId, staffName, hierarchy);
|
||||
return CenterData.instance(id, name, externalId, status, activationDate, officeId, officeName, staffId, staffName, hierarchy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +153,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
private final String schemaSql;
|
||||
|
||||
public GroupDataMapper() {
|
||||
|
||||
|
||||
this.schemaSql = sqlQuery;
|
||||
}
|
||||
|
||||
@@ -161,7 +176,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
return GroupGeneralData.instance(id, name, externalId, officeId, officeName, null, null, staffId, staffName, hierarchy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<CenterData> retrieveAll(final SearchParameters searchCriteria) {
|
||||
|
||||
@@ -179,7 +194,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
sql += " and (" + extraCriteria + ")";
|
||||
}
|
||||
|
||||
sql += "order by g.hierarchy";
|
||||
sql += " order by g.hierarchy";
|
||||
|
||||
return this.jdbcTemplate.query(sql, centerMapper, new Object[] { hierarchySearchString });
|
||||
}
|
||||
@@ -187,8 +202,6 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
@Override
|
||||
public Collection<CenterData> retrieveAllForDropdown(final Long officeId) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final AppUser currentUser = context.authenticatedUser();
|
||||
final String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
final String hierarchySearchString = hierarchy + "%";
|
||||
@@ -202,14 +215,47 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
@Override
|
||||
public CenterData retrieveTemplate(final Long officeId) {
|
||||
|
||||
final Long officeIdDefaulted = defaultToUsersOfficeIfNull(officeId);
|
||||
|
||||
final Collection<OfficeData> officeOptions = this.officeReadPlatformService.retrieveAllOfficesForDropdown();
|
||||
|
||||
Collection<StaffData> staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(officeId);
|
||||
Collection<StaffData> staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(officeIdDefaulted);
|
||||
if (CollectionUtils.isEmpty(staffOptions)) {
|
||||
staffOptions = null;
|
||||
}
|
||||
|
||||
return CenterData.template(officeId, officeOptions, staffOptions);
|
||||
Collection<GroupGeneralData> groupMembersOptions = retrieveAllGroupsForCenterDropdown(officeIdDefaulted);
|
||||
if (CollectionUtils.isEmpty(groupMembersOptions)) {
|
||||
groupMembersOptions = null;
|
||||
}
|
||||
|
||||
// final boolean clientPendingApprovalAllowed =
|
||||
// this.configurationDomainService.isClientPendingApprovalAllowedEnabled();
|
||||
|
||||
return CenterData.template(officeIdDefaulted, new LocalDate(), officeOptions, staffOptions, groupMembersOptions);
|
||||
}
|
||||
|
||||
private Collection<GroupGeneralData> retrieveAllGroupsForCenterDropdown(final Long officeId) {
|
||||
|
||||
final Long defaultOfficeId = defaultToUsersOfficeIfNull(officeId);
|
||||
|
||||
final AppUser currentUser = context.authenticatedUser();
|
||||
final String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
final String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
final String sql = "select " + allGroupTypesDataMapper.schema()
|
||||
+ " where g.office_id = ? and g.parent_id is null and g.level_Id = ? and o.hierarchy like ? order by g.hierarchy";
|
||||
|
||||
return this.jdbcTemplate.query(sql, allGroupTypesDataMapper, new Object[] { defaultOfficeId, GroupTypes.GROUP.getId(),
|
||||
hierarchySearchString });
|
||||
}
|
||||
|
||||
private Long defaultToUsersOfficeIfNull(final Long officeId) {
|
||||
Long defaultOfficeId = officeId;
|
||||
if (defaultOfficeId == null) {
|
||||
defaultOfficeId = this.context.authenticatedUser().getOffice().getId();
|
||||
}
|
||||
return defaultOfficeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,6 +268,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
|
||||
String sql = "select " + this.centerMapper.schema() + " where g.id = ? and o.hierarchy like ?";
|
||||
return this.jdbcTemplate.queryForObject(sql, this.centerMapper, new Object[] { centerId, hierarchySearchString });
|
||||
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new GroupNotFoundException(centerId);
|
||||
}
|
||||
@@ -251,8 +298,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
staffOptions = null;
|
||||
}
|
||||
|
||||
Collection<ClientData> clientOptions = this.clientReadPlatformService
|
||||
.retrieveAllForLookupByOfficeId(centerOfficeId);
|
||||
Collection<ClientData> clientOptions = this.clientReadPlatformService.retrieveAllForLookupByOfficeId(centerOfficeId);
|
||||
if (CollectionUtils.isEmpty(clientOptions)) {
|
||||
clientOptions = null;
|
||||
}
|
||||
@@ -262,8 +308,8 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<GroupGeneralData> retriveAssociatedGroups(Long centerId) {
|
||||
String sql = "select " + this.groupDataMapper.schema() + " where g.parent_id = ? ";
|
||||
return this.jdbcTemplate.query(sql, groupDataMapper, new Object[] { centerId });
|
||||
}
|
||||
public Collection<GroupGeneralData> retrieveAssociatedGroups(final Long centerId) {
|
||||
String sql = "select " + this.groupDataMapper.schema() + " where g.parent_id = ? ";
|
||||
return this.jdbcTemplate.query(sql, this.groupDataMapper, new Object[] { centerId });
|
||||
}
|
||||
}
|
||||
-17
@@ -7,12 +7,9 @@ package org.mifosplatform.portfolio.group.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.organisation.monetary.data.MoneyData;
|
||||
import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupGeneralData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupLevelData;
|
||||
|
||||
public interface GroupReadPlatformService {
|
||||
|
||||
@@ -26,18 +23,4 @@ public interface GroupReadPlatformService {
|
||||
GroupAccountSummaryCollectionData retrieveGroupAccountDetails(Long groupId);
|
||||
|
||||
Collection<GroupAccountSummaryData> retrieveGroupLoanAccountsByLoanOfficerId(Long groupId, Long loanOfficerId);
|
||||
|
||||
GroupLevelData retrieveGroupLevelDetails(Long levelId);
|
||||
|
||||
Collection<StaffData> retrieveStaffsbyOfficeId(Long officeId);
|
||||
|
||||
Long retrieveTotalNoOfChildGroups(Long groupId);
|
||||
|
||||
Long retrieveTotalClients(String hierarchy);
|
||||
|
||||
Collection<MoneyData> retrieveGroupLoanPortfolio(String hierarchy);
|
||||
|
||||
StaffData retrieveStaffsbyId(Long staffId);
|
||||
|
||||
Long getLevelIdByGroupId(final Long groupId);
|
||||
}
|
||||
+7
-206
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
package org.mifosplatform.portfolio.group.service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
@@ -17,11 +16,9 @@ import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.monetary.data.MoneyData;
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
|
||||
import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
import org.mifosplatform.organisation.staff.exception.StaffNotFoundException;
|
||||
import org.mifosplatform.organisation.staff.service.StaffReadPlatformService;
|
||||
import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
|
||||
@@ -30,9 +27,7 @@ import org.mifosplatform.portfolio.group.data.CenterData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupGeneralData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupLevelData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupTypes;
|
||||
import org.mifosplatform.portfolio.group.exception.GroupLevelNotFoundException;
|
||||
import org.mifosplatform.portfolio.group.domain.GroupTypes;
|
||||
import org.mifosplatform.portfolio.group.exception.GroupNotFoundException;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -50,9 +45,10 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
|
||||
private final ClientReadPlatformService clientReadPlatformService;
|
||||
private final OfficeReadPlatformService officeReadPlatformService;
|
||||
private final StaffReadPlatformService staffReadPlatformService;
|
||||
private final AllGroupTypesDataMapper allGroupTypesDataMapper = new AllGroupTypesDataMapper();
|
||||
private final CenterReadPlatformService centerReadPlatformService;
|
||||
|
||||
private final AllGroupTypesDataMapper allGroupTypesDataMapper = new AllGroupTypesDataMapper();
|
||||
|
||||
@Autowired
|
||||
public GroupReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
|
||||
final CenterReadPlatformService centerReadPlatformService, final ClientReadPlatformService clientReadPlatformService,
|
||||
@@ -81,8 +77,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
|
||||
staffOptions = null;
|
||||
}
|
||||
|
||||
Collection<ClientData> clientOptions = this.clientReadPlatformService
|
||||
.retrieveAllForLookupByOfficeId(defaultOfficeId);
|
||||
Collection<ClientData> clientOptions = this.clientReadPlatformService.retrieveAllForLookupByOfficeId(defaultOfficeId);
|
||||
if (CollectionUtils.isEmpty(clientOptions)) {
|
||||
clientOptions = null;
|
||||
}
|
||||
@@ -132,8 +127,8 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
|
||||
|
||||
String sqlSearch = searchCriteria.getSqlSearch();
|
||||
if (sqlSearch != null) {
|
||||
sqlSearch = sqlSearch.replaceAll(" name ", " g.name ");
|
||||
sqlSearch = sqlSearch.replaceAll("name ", "g.name ");
|
||||
sqlSearch = sqlSearch.replaceAll(" display_name ", " g.display_name ");
|
||||
sqlSearch = sqlSearch.replaceAll("display_name ", "g.display_name ");
|
||||
extraCriteria = " and (" + sqlSearch + ")";
|
||||
}
|
||||
|
||||
@@ -149,7 +144,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
|
||||
|
||||
final String name = searchCriteria.getName();
|
||||
if (name != null) {
|
||||
extraCriteria += " and g.name like " + ApiParameterHelper.sqlEncodeString("%" + name + "%");
|
||||
extraCriteria += " and g.display_name like " + ApiParameterHelper.sqlEncodeString("%" + name + "%");
|
||||
}
|
||||
|
||||
final String hierarchy = searchCriteria.getHierarchy();
|
||||
@@ -179,200 +174,6 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupLevelData retrieveGroupLevelDetails(final Long levelId) {
|
||||
|
||||
try {
|
||||
this.context.authenticatedUser();
|
||||
final GroupLevelDataMapper rm = new GroupLevelDataMapper();
|
||||
final String sql = "select " + rm.groupLevelSchema() + " where gl.id = ? ";
|
||||
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { levelId });
|
||||
|
||||
} catch (final EmptyResultDataAccessException e) {
|
||||
throw new GroupLevelNotFoundException(levelId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<StaffData> retrieveStaffsbyOfficeId(final Long officeId) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
final StaffDataMapper rm = new StaffDataMapper();
|
||||
final String sql = "select " + rm.staffDataSchema() + " where o.id = ?";
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { officeId });
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffData retrieveStaffsbyId(final Long staffId) {
|
||||
|
||||
try {
|
||||
this.context.authenticatedUser();
|
||||
final StaffDataMapper rm = new StaffDataMapper();
|
||||
final String sql = "select " + rm.staffDataSchema() + " where s.id = ?";
|
||||
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { staffId });
|
||||
|
||||
} catch (final EmptyResultDataAccessException e) {
|
||||
throw new StaffNotFoundException(staffId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getLevelIdByGroupId(final Long groupId) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
final String sqlTotalClients = "SELECT g.level_Id as levelId FROM m_group g WHERE g.id = ?";
|
||||
return this.jdbcTemplate.queryForLong(sqlTotalClients, new Object[] { groupId });
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long retrieveTotalClients(final String hierarchy) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final String groupHierarchy = hierarchy + "%";
|
||||
final String sqlTotalClients = "SELECT count(gc.client_id) FROM m_group_client gc JOIN m_group g "
|
||||
+ "ON gc.group_id = g.id WHERE g.hierarchy LIKE ? ";
|
||||
return this.jdbcTemplate.queryForLong(sqlTotalClients, new Object[] { groupHierarchy });
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long retrieveTotalNoOfChildGroups(final Long groupId) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
final String sqlTotalClients = "SELECT count(gc.id) FROM m_group g JOIN m_group gc WHERE g.id = gc.parent_id and g.id = ?";
|
||||
return this.jdbcTemplate.queryForLong(sqlTotalClients, new Object[] { groupId });
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<MoneyData> retrieveGroupLoanPortfolio(final String hierarchy) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final MoneyDataMapper rm = new MoneyDataMapper();
|
||||
|
||||
final String groupHierarchy = hierarchy + "%";
|
||||
final String sql = "select " + rm.moneyDataSchema() + " FROM m_group_client gc JOIN m_group g ON gc.group_id = g.id "
|
||||
+ "JOIN m_loan l ON l.client_id = gc.client_id LEFT JOIN m_organisation_currency oc ON oc.code = l.currency_code "
|
||||
+ " WHERE g.hierarchy LIKE ? GROUP BY l.currency_code ";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { groupHierarchy });
|
||||
|
||||
}
|
||||
|
||||
private static final class MoneyDataMapper implements RowMapper<MoneyData> {
|
||||
|
||||
public String moneyDataSchema() {
|
||||
return "l.currency_code as currencyCode, oc.decimal_places as decimalPlaces, sum(l.principal_amount) as amount";
|
||||
}
|
||||
|
||||
@Override
|
||||
public MoneyData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final String currencyCode = rs.getString("currencyCode");
|
||||
final Integer decimalPlaces = rs.getInt("decimalPlaces");
|
||||
final BigDecimal amount = rs.getBigDecimal("amount");
|
||||
|
||||
return new MoneyData(currencyCode, amount, decimalPlaces);
|
||||
}
|
||||
}
|
||||
|
||||
// GroupTopOfHierarchyData
|
||||
private static final class AllGroupTypesDataMapper implements RowMapper<GroupGeneralData> {
|
||||
|
||||
private final String schemaSql;
|
||||
|
||||
public AllGroupTypesDataMapper() {
|
||||
final StringBuilder sqlBuilder = new StringBuilder(400);
|
||||
sqlBuilder.append("g.id as id, g.external_id as externalId, g.name as name, ");
|
||||
sqlBuilder.append("g.office_id as officeId, o.name as officeName, ");
|
||||
sqlBuilder.append("g.parent_id as parentId, pg.name as parentName, ");
|
||||
sqlBuilder.append("g.staff_id as staffId, s.display_name as staffName, ");
|
||||
sqlBuilder.append("g.hierarchy as hierarchy ");
|
||||
sqlBuilder.append("from m_group g ");
|
||||
sqlBuilder.append("join m_office o on o.id = g.office_id ");
|
||||
sqlBuilder.append("left join m_staff s on s.id = g.staff_id ");
|
||||
sqlBuilder.append("left join m_group pg on pg.id = g.parent_id ");
|
||||
|
||||
this.schemaSql = sqlBuilder.toString();
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return this.schemaSql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupGeneralData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long id = rs.getLong("id");
|
||||
final String name = rs.getString("name");
|
||||
final String externalId = rs.getString("externalId");
|
||||
final Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
final Long parentId = JdbcSupport.getLong(rs, "parentId");
|
||||
final String parentName = rs.getString("parentName");
|
||||
final Long staffId = JdbcSupport.getLong(rs, "staffId");
|
||||
final String staffName = rs.getString("staffName");
|
||||
final String hierarchy = rs.getString("hierarchy");
|
||||
|
||||
return GroupGeneralData.instance(id, name, externalId, officeId, officeName, parentId, parentName, staffId, staffName,
|
||||
hierarchy);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class GroupLevelDataMapper implements RowMapper<GroupLevelData> {
|
||||
|
||||
public String groupLevelSchema() {
|
||||
return "gl.id as id, gl.level_name as levelName , gl.parent_id as parentLevelId , pgl.level_name as parentName , "
|
||||
+ "cgl.id as childLevelId,cgl.level_name as childLevelName,gl.super_parent as superParent ,"
|
||||
+ " gl.recursable as recursable , gl.can_have_clients as canHaveClients from m_group_level gl "
|
||||
+ " left join m_group_level pgl on pgl.id = gl.parent_id left join m_group_level cgl on gl.id = cgl.parent_id";
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupLevelData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long levelId = rs.getLong("id");
|
||||
final String levelName = rs.getString("levelName");
|
||||
final Long parentLevelId = rs.getLong("parentLevelId");
|
||||
final String parentLevelName = rs.getString("parentName");
|
||||
final Long childLevelId = rs.getLong("childLevelId");
|
||||
final String childLevelName = rs.getString("childLevelName");
|
||||
final boolean superParent = rs.getBoolean("superParent");
|
||||
final boolean recursable = rs.getBoolean("recursable");
|
||||
final boolean canHaveClients = rs.getBoolean("canHaveClients");
|
||||
|
||||
return new GroupLevelData(levelId, levelName, parentLevelId, parentLevelName, childLevelId, childLevelName, superParent,
|
||||
recursable, canHaveClients);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class StaffDataMapper implements RowMapper<StaffData> {
|
||||
|
||||
public String staffDataSchema() {
|
||||
return "s.id as id , s.is_loan_officer as isLoanOfficer , s.office_id as officeId , s.firstname as firstname, "
|
||||
+ "s.lastname as lastname , s.display_name as displayName , o.name as officeName from m_staff s join m_office o on s.office_id =o.id ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long id = rs.getLong("id");
|
||||
final String firstname = rs.getString("firstname");
|
||||
final String lastname = rs.getString("lastname");
|
||||
final String displayName = rs.getString("displayName");
|
||||
final Long officeId = rs.getLong("officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
final boolean isLoanOfficer = rs.getBoolean("isLoanOfficer");
|
||||
|
||||
return StaffData.instance(id, firstname, lastname, displayName, officeId, officeName, isLoanOfficer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupAccountSummaryCollectionData retrieveGroupAccountDetails(final Long groupId) {
|
||||
try {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
package org.mifosplatform.portfolio.group.service;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupTypes;
|
||||
import org.mifosplatform.portfolio.group.domain.GroupTypes;
|
||||
|
||||
public class GroupTypeEnumerations {
|
||||
|
||||
|
||||
+6
-3
@@ -8,14 +8,17 @@ package org.mifosplatform.portfolio.group.service;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
|
||||
public interface GroupWritePlatformService {
|
||||
public interface GroupingTypesWritePlatformService {
|
||||
|
||||
CommandProcessingResult createGroup(Long parentId, Long levelId, JsonCommand command);
|
||||
CommandProcessingResult createCenter(JsonCommand command);
|
||||
|
||||
CommandProcessingResult updateCenter(Long entityId, JsonCommand command);
|
||||
|
||||
CommandProcessingResult createGroup(Long centerId, JsonCommand command);
|
||||
|
||||
CommandProcessingResult updateGroup(Long groupId, JsonCommand command);
|
||||
|
||||
CommandProcessingResult deleteGroup(Long groupId);
|
||||
|
||||
CommandProcessingResult unassignStaff(Long grouptId, JsonCommand command);
|
||||
|
||||
}
|
||||
+123
-98
@@ -8,10 +8,12 @@ package org.mifosplatform.portfolio.group.service;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||
@@ -27,14 +29,19 @@ import org.mifosplatform.organisation.staff.exception.StaffNotFoundException;
|
||||
import org.mifosplatform.portfolio.client.domain.Client;
|
||||
import org.mifosplatform.portfolio.client.domain.ClientRepository;
|
||||
import org.mifosplatform.portfolio.client.exception.ClientNotFoundException;
|
||||
import org.mifosplatform.portfolio.group.api.GroupingTypesApiConstants;
|
||||
import org.mifosplatform.portfolio.group.domain.Group;
|
||||
import org.mifosplatform.portfolio.group.domain.GroupLevel;
|
||||
import org.mifosplatform.portfolio.group.domain.GroupLevelRepository;
|
||||
import org.mifosplatform.portfolio.group.domain.GroupRepository;
|
||||
import org.mifosplatform.portfolio.group.domain.GroupTypes;
|
||||
import org.mifosplatform.portfolio.group.exception.GroupHasNoStaffException;
|
||||
import org.mifosplatform.portfolio.group.exception.GroupMustBePendingToBeDeletedException;
|
||||
import org.mifosplatform.portfolio.group.exception.GroupNotFoundException;
|
||||
import org.mifosplatform.portfolio.group.exception.InvalidGroupLevelException;
|
||||
import org.mifosplatform.portfolio.group.serialization.GroupCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.portfolio.group.serialization.GroupingTypesDataValidator;
|
||||
import org.mifosplatform.portfolio.note.domain.Note;
|
||||
import org.mifosplatform.portfolio.note.domain.NoteRepository;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -46,53 +53,47 @@ import org.springframework.util.ObjectUtils;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@Service
|
||||
public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePlatformService {
|
||||
public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements GroupingTypesWritePlatformService {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(GroupWritePlatformServiceJpaRepositoryImpl.class);
|
||||
private final static Logger logger = LoggerFactory.getLogger(GroupingTypesWritePlatformServiceJpaRepositoryImpl.class);
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final GroupRepository groupRepository;
|
||||
private final ClientRepository clientRepository;
|
||||
private final OfficeRepository officeRepository;
|
||||
private final StaffRepository staffRepository;
|
||||
private final NoteRepository noteRepository;
|
||||
private final GroupLevelRepository groupLevelRepository;
|
||||
private final GroupCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final GroupingTypesDataValidator fromApiJsonDeserializer;
|
||||
|
||||
@Autowired
|
||||
public GroupWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final GroupRepository groupRepository,
|
||||
public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final GroupRepository groupRepository,
|
||||
final ClientRepository clientRepository, final OfficeRepository officeRepository, final StaffRepository staffRepository,
|
||||
final GroupLevelRepository groupLevelRepository, final GroupCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
|
||||
final NoteRepository noteRepository,
|
||||
final GroupLevelRepository groupLevelRepository, final GroupingTypesDataValidator fromApiJsonDeserializer) {
|
||||
this.context = context;
|
||||
this.groupRepository = groupRepository;
|
||||
this.clientRepository = clientRepository;
|
||||
this.officeRepository = officeRepository;
|
||||
this.staffRepository = staffRepository;
|
||||
this.noteRepository = noteRepository;
|
||||
this.groupLevelRepository = groupLevelRepository;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult createGroup(final Long parentId, final Long levelId, final JsonCommand command) {
|
||||
|
||||
GroupLevel groupLevel = this.groupLevelRepository.findOne(levelId);
|
||||
private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) {
|
||||
try {
|
||||
this.context.authenticatedUser();
|
||||
|
||||
this.fromApiJsonDeserializer.validateForCreate(command.json());
|
||||
|
||||
final String name = command.stringValueOfParameterNamed("name");
|
||||
final String externalId = command.stringValueOfParameterNamed("externalId");
|
||||
final String name = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName);
|
||||
final String externalId = command.stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName);
|
||||
|
||||
Long officeId = null;
|
||||
|
||||
Group parentGroup = null;
|
||||
|
||||
if (parentId == null) {
|
||||
officeId = command.longValueOfParameterNamed("officeId");
|
||||
if (centerId == null) {
|
||||
officeId = command.longValueOfParameterNamed(GroupingTypesApiConstants.officeIdParamName);
|
||||
} else {
|
||||
parentGroup = this.groupRepository.findOne(parentId);
|
||||
if (parentGroup == null || parentGroup.isDeleted()) { throw new GroupNotFoundException(parentId); }
|
||||
parentGroup = this.groupRepository.findOne(centerId);
|
||||
if (parentGroup == null) { throw new GroupNotFoundException(centerId); }
|
||||
officeId = parentGroup.getOfficeId();
|
||||
}
|
||||
|
||||
@@ -100,29 +101,21 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
if (groupOffice == null) { throw new OfficeNotFoundException(officeId); }
|
||||
|
||||
Staff staff = null;
|
||||
final Long staffId = command.longValueOfParameterNamed("staffId");
|
||||
|
||||
/**
|
||||
* Validate the staff is present in the given office or not
|
||||
*/
|
||||
final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
|
||||
if (staffId != null) {
|
||||
staff = this.staffRepository.findByOffice(staffId, officeId);
|
||||
if (staff == null) { throw new StaffNotFoundException(staffId); }
|
||||
}
|
||||
|
||||
Set<Client> clientMembers = null;
|
||||
if (groupLevel.canHaveClients()) {
|
||||
clientMembers = assembleSetOfClients(officeId, command);
|
||||
}
|
||||
final Set<Client> clientMembers = assembleSetOfClients(officeId, command);
|
||||
|
||||
//TODO -AA: Not sure about children are added at the time of group creation
|
||||
/*Set<Group> childGroups = null;
|
||||
if (groupLevel.isRecursable()) {
|
||||
childGroups = assembleSetOfChildGroups(officeId, command);
|
||||
}*/
|
||||
final Set<Group> groupMembers = assembleSetOfChildGroups(officeId, command);
|
||||
|
||||
final Group newGroup = Group
|
||||
.newGroup(groupOffice, staff, parentGroup, groupLevel, name, externalId, clientMembers, null);
|
||||
final boolean active = command.booleanPrimitiveValueOfParameterNamed(GroupingTypesApiConstants.activeParamName);
|
||||
final LocalDate activationDate = command.localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName);
|
||||
GroupLevel groupLevel = this.groupLevelRepository.findOne(groupingType.getId());
|
||||
final Group newGroup = Group.newGroup(groupOffice, staff, parentGroup, groupLevel, name, externalId, active, activationDate,
|
||||
clientMembers, groupMembers);
|
||||
|
||||
// pre-save to generate id for use in group hierarchy
|
||||
this.groupRepository.save(newGroup);
|
||||
@@ -139,40 +132,71 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
.build();
|
||||
|
||||
} catch (final DataIntegrityViolationException dve) {
|
||||
handleGroupDataIntegrityIssues(command, dve, groupLevel);
|
||||
return new CommandProcessingResult(Long.valueOf(-1));
|
||||
handleGroupDataIntegrityIssues(command, dve, groupingType);
|
||||
return CommandProcessingResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult createCenter(final JsonCommand command) {
|
||||
|
||||
this.fromApiJsonDeserializer.validateForCreateCenter(command);
|
||||
|
||||
final Long centerId = null;
|
||||
return createGroupingType(command, GroupTypes.CENTER, centerId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult createGroup(final Long centerId, final JsonCommand command) {
|
||||
|
||||
if (centerId != null) {
|
||||
this.fromApiJsonDeserializer.validateForCreateCenterGroup(command);
|
||||
} else {
|
||||
this.fromApiJsonDeserializer.validateForCreateGroup(command);
|
||||
}
|
||||
|
||||
return createGroupingType(command, GroupTypes.GROUP, centerId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult updateCenter(final Long centerId, final JsonCommand command) {
|
||||
|
||||
this.fromApiJsonDeserializer.validateForUpdateCenter(command);
|
||||
|
||||
return updateGroupingType(centerId, command, GroupTypes.CENTER);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult updateGroup(final Long groupId, final JsonCommand command) {
|
||||
|
||||
GroupLevel groupLevel = null;
|
||||
this.fromApiJsonDeserializer.validateForUpdateGroup(command);
|
||||
|
||||
return updateGroupingType(groupId, command, GroupTypes.GROUP);
|
||||
}
|
||||
|
||||
private CommandProcessingResult updateGroupingType(final Long groupId, final JsonCommand command, final GroupTypes groupingType) {
|
||||
|
||||
try {
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(9);
|
||||
|
||||
this.fromApiJsonDeserializer.validateForUpdate(command.json());
|
||||
|
||||
final Group groupForUpdate = this.groupRepository.findOne(groupId);
|
||||
if (groupForUpdate == null || groupForUpdate.isDeleted()) { throw new GroupNotFoundException(groupId); }
|
||||
if (groupForUpdate == null) { throw new GroupNotFoundException(groupId); }
|
||||
|
||||
final Long officeId = groupForUpdate.getOfficeId();
|
||||
|
||||
final String nameParamName = "name";
|
||||
if (command.isChangeInStringParameterNamed(nameParamName, groupForUpdate.getName())) {
|
||||
final String newValue = command.stringValueOfParameterNamed(nameParamName);
|
||||
actualChanges.put(nameParamName, newValue);
|
||||
if (command.isChangeInStringParameterNamed(GroupingTypesApiConstants.nameParamName, groupForUpdate.getName())) {
|
||||
final String newValue = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName);
|
||||
actualChanges.put(GroupingTypesApiConstants.nameParamName, newValue);
|
||||
groupForUpdate.setName(StringUtils.defaultIfEmpty(newValue, null));
|
||||
}
|
||||
|
||||
final String externalIdParamName = "externalId";
|
||||
if (command.isChangeInStringParameterNamed(externalIdParamName, groupForUpdate.getExternalId())) {
|
||||
final String newValue = command.stringValueOfParameterNamed(externalIdParamName);
|
||||
actualChanges.put(externalIdParamName, newValue);
|
||||
if (command.isChangeInStringParameterNamed(GroupingTypesApiConstants.externalIdParamName, groupForUpdate.getExternalId())) {
|
||||
final String newValue = command.stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName);
|
||||
actualChanges.put(GroupingTypesApiConstants.externalIdParamName, newValue);
|
||||
groupForUpdate.setExternalId(StringUtils.defaultIfEmpty(newValue, null));
|
||||
}
|
||||
|
||||
@@ -182,10 +206,9 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
presentStaffId = presentStaff.getId();
|
||||
}
|
||||
|
||||
final String staffIdParamName = "staffId";
|
||||
if (command.isChangeInLongParameterNamed(staffIdParamName, presentStaffId)) {
|
||||
final Long newValue = command.longValueOfParameterNamed(staffIdParamName);
|
||||
actualChanges.put(staffIdParamName, newValue);
|
||||
if (command.isChangeInLongParameterNamed(GroupingTypesApiConstants.staffIdParamName, presentStaffId)) {
|
||||
final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
|
||||
actualChanges.put(GroupingTypesApiConstants.staffIdParamName, newValue);
|
||||
|
||||
Staff newStaff = null;
|
||||
if (newValue != null) {
|
||||
@@ -195,7 +218,7 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
groupForUpdate.setStaff(newStaff);
|
||||
}
|
||||
|
||||
groupLevel = this.groupLevelRepository.findOne(groupForUpdate.getGroupLevel().getId());
|
||||
GroupLevel groupLevel = this.groupLevelRepository.findOne(groupForUpdate.getGroupLevel().getId());
|
||||
|
||||
/*
|
||||
* Ignoring parentId param, if group for update is super parent.
|
||||
@@ -204,7 +227,6 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
*/
|
||||
if (!groupLevel.isSuperParent()) {
|
||||
|
||||
final String parentIdParamName = "parentId";
|
||||
Long parentId = null;
|
||||
final Group presentParentGroup = groupForUpdate.getParent();
|
||||
|
||||
@@ -212,14 +234,14 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
parentId = presentParentGroup.getId();
|
||||
}
|
||||
|
||||
if (command.isChangeInLongParameterNamed(parentIdParamName, parentId)) {
|
||||
if (command.isChangeInLongParameterNamed(GroupingTypesApiConstants.centerIdParamName, parentId)) {
|
||||
|
||||
final Long newValue = command.longValueOfParameterNamed(parentIdParamName);
|
||||
actualChanges.put(parentIdParamName, newValue);
|
||||
final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.centerIdParamName);
|
||||
actualChanges.put(GroupingTypesApiConstants.centerIdParamName, newValue);
|
||||
Group newParentGroup = null;
|
||||
if (newValue != null) {
|
||||
newParentGroup = this.groupRepository.findOne(newValue);
|
||||
if (newParentGroup == null || newParentGroup.isDeleted()) { throw new StaffNotFoundException(newValue); }
|
||||
if (newParentGroup == null) { throw new StaffNotFoundException(newValue); }
|
||||
|
||||
if (!newParentGroup.isOfficeIdentifiedBy(officeId)) {
|
||||
final String errorMessage = "Group and parent group must have the same office";
|
||||
@@ -248,12 +270,11 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
}
|
||||
|
||||
final Set<Client> clientMembers = assembleSetOfClients(officeId, command);
|
||||
final String clientMembersParamName = "clientMembers";
|
||||
|
||||
if (!clientMembers.equals(groupForUpdate.getClientMembers())) {
|
||||
Set<Client> diffClients = Sets.symmetricDifference(clientMembers, groupForUpdate.getClientMembers());
|
||||
final String[] diffClientsIds = getClientIds(diffClients);
|
||||
actualChanges.put(clientMembersParamName, diffClientsIds);
|
||||
actualChanges.put(GroupingTypesApiConstants.clientMembersParamName, diffClientsIds);
|
||||
groupForUpdate.setClientMembers(clientMembers);
|
||||
}
|
||||
|
||||
@@ -262,15 +283,14 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(command.commandId()) //
|
||||
.withOfficeId(groupForUpdate.getId()) //
|
||||
//apart from group context group id does not make much sense
|
||||
.withGroupId(groupForUpdate.getId())
|
||||
.withGroupId(groupForUpdate.getId()) //
|
||||
.withEntityId(groupForUpdate.getId()) //
|
||||
.with(actualChanges) //
|
||||
.build();
|
||||
|
||||
} catch (final DataIntegrityViolationException dve) {
|
||||
handleGroupDataIntegrityIssues(command, dve, groupLevel);
|
||||
return new CommandProcessingResult(Long.valueOf(-1));
|
||||
handleGroupDataIntegrityIssues(command, dve, groupingType);
|
||||
return CommandProcessingResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +305,7 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
this.fromApiJsonDeserializer.validateForUnassignStaff(command.json());
|
||||
|
||||
final Group groupForUpdate = this.groupRepository.findOne(grouptId);
|
||||
if (groupForUpdate == null || groupForUpdate.isDeleted()) { throw new GroupNotFoundException(grouptId); }
|
||||
if (groupForUpdate == null) { throw new GroupNotFoundException(grouptId); }
|
||||
|
||||
final Staff presentStaff = groupForUpdate.getStaff();
|
||||
Long presentStaffId = null;
|
||||
@@ -309,26 +329,17 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Switched delete to hard delete of group. Will use 'status' when is added
|
||||
* to determine if group can be deleted or not along with contraints on
|
||||
* database i.e. cant delete group with any loans/savings accounts.
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public CommandProcessingResult deleteGroup(final Long groupId) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final Group groupForDelete = this.groupRepository.findOne(groupId);
|
||||
if (groupForDelete == null) { throw new GroupNotFoundException(groupId); }
|
||||
|
||||
// groupForDelete.delete();
|
||||
// this.groupRepository.save(groupForDelete);
|
||||
if (groupForDelete.isNotPending()) { throw new GroupMustBePendingToBeDeletedException(groupId); }
|
||||
|
||||
// List<Note> relatedNotes =
|
||||
// this.noteRepository.findByLoanId(loan.getId());
|
||||
// this.noteRepository.deleteInBatch(relatedNotes);
|
||||
final List<Note> relatedNotes = this.noteRepository.findByGroupId(groupId);
|
||||
this.noteRepository.deleteInBatch(relatedNotes);
|
||||
|
||||
this.groupRepository.delete(groupId);
|
||||
|
||||
@@ -342,7 +353,7 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
private Set<Client> assembleSetOfClients(final Long officeId, final JsonCommand command) {
|
||||
|
||||
final Set<Client> clientMembers = new HashSet<Client>();
|
||||
final String[] clientMembersArray = command.arrayValueOfParameterNamed("clientMembers");
|
||||
final String[] clientMembersArray = command.arrayValueOfParameterNamed(GroupingTypesApiConstants.clientMembersParamName);
|
||||
|
||||
if (!ObjectUtils.isEmpty(clientMembersArray)) {
|
||||
for (final String clientId : clientMembersArray) {
|
||||
@@ -360,16 +371,16 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
return clientMembers;
|
||||
}
|
||||
|
||||
/*private Set<Group> assembleSetOfChildGroups(final Long officeId, final JsonCommand command) {
|
||||
private Set<Group> assembleSetOfChildGroups(final Long officeId, final JsonCommand command) {
|
||||
|
||||
final Set<Group> childGroups = new HashSet<Group>();
|
||||
final String[] childGroupsArray = command.arrayValueOfParameterNamed("childGroups");
|
||||
final String[] childGroupsArray = command.arrayValueOfParameterNamed(GroupingTypesApiConstants.groupMembersParamName);
|
||||
|
||||
if (!ObjectUtils.isEmpty(childGroupsArray)) {
|
||||
for (final String groupId : childGroupsArray) {
|
||||
final Long id = Long.valueOf(groupId);
|
||||
final Group group = this.groupRepository.findOne(id);
|
||||
if (group == null || group.isDeleted()) { throw new GroupNotFoundException(id); }
|
||||
if (group == null) { throw new GroupNotFoundException(id); }
|
||||
if (!group.isOfficeIdentifiedBy(officeId)) {
|
||||
final String errorMessage = "Group and child groups must have the same office.";
|
||||
throw new InvalidOfficeException("group", "attach.to.parent.group", errorMessage);
|
||||
@@ -379,7 +390,7 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
}
|
||||
|
||||
return childGroups;
|
||||
}*/
|
||||
}
|
||||
|
||||
private String[] getClientIds(final Set<Client> clients) {
|
||||
|
||||
@@ -396,7 +407,19 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
* is.
|
||||
*/
|
||||
private void handleGroupDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve,
|
||||
final GroupLevel groupLevel) {
|
||||
final GroupTypes groupLevel) {
|
||||
|
||||
String levelName = "Invalid";
|
||||
switch (groupLevel) {
|
||||
case CENTER:
|
||||
levelName = "Center";
|
||||
break;
|
||||
case GROUP:
|
||||
levelName = "Group";
|
||||
break;
|
||||
case INVALID:
|
||||
break;
|
||||
}
|
||||
|
||||
final Throwable realCause = dve.getMostSpecificCause();
|
||||
String errorMessageForUser = null;
|
||||
@@ -404,20 +427,22 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
|
||||
if (realCause.getMessage().contains("external_id")) {
|
||||
|
||||
final String externalId = command.stringValueOfParameterNamed("externalId");
|
||||
errorMessageForUser = groupLevel.getLevelName() + " with externalId `" + externalId + "` already exists.";
|
||||
errorMessageForMachine = "error.msg." + groupLevel.getLevelName().toLowerCase() + ".duplicate.externalId";
|
||||
throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser, "externalId", externalId);
|
||||
final String externalId = command.stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName);
|
||||
errorMessageForUser = levelName + " with externalId `" + externalId + "` already exists.";
|
||||
errorMessageForMachine = "error.msg." + levelName.toLowerCase() + ".duplicate.externalId";
|
||||
throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser,
|
||||
GroupingTypesApiConstants.externalIdParamName, externalId);
|
||||
} else if (realCause.getMessage().contains("name")) {
|
||||
|
||||
final String name = command.stringValueOfParameterNamed("name");
|
||||
errorMessageForUser = groupLevel.getLevelName() + " with name `" + name + "` already exists.";
|
||||
errorMessageForMachine = "error.msg." + groupLevel.getLevelName().toLowerCase() + ".duplicate.name";
|
||||
throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser, "name", name);
|
||||
final String name = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName);
|
||||
errorMessageForUser = levelName + " with name `" + name + "` already exists.";
|
||||
errorMessageForMachine = "error.msg." + levelName.toLowerCase() + ".duplicate.name";
|
||||
throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser, GroupingTypesApiConstants.nameParamName,
|
||||
name);
|
||||
}
|
||||
|
||||
logger.error(dve.getMessage(), dve);
|
||||
throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue",
|
||||
"Unknown data integrity issue with resource.");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -96,7 +96,8 @@ public class BulkLoansReadPlatformServiceImpl implements BulkLoansReadPlatformSe
|
||||
private static final class StaffGroupMapper implements RowMapper<StaffAccountSummaryCollectionData.GroupSummary> {
|
||||
|
||||
public String schema() {
|
||||
return " g.id as id, g.name as name from m_group g" + " join m_loan l on g.id = l.group_id where l.loan_officer_id = ? ";
|
||||
return " g.id as id, g.display_name as name from m_group g"
|
||||
+ " join m_loan l on g.id = l.group_id where l.loan_officer_id = ? ";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -139,7 +139,7 @@ public class LoanAssembler {
|
||||
|
||||
if (groupId != null) {
|
||||
group = this.groupRepository.findOne(groupId);
|
||||
if (group == null || group.isDeleted()) { throw new GroupNotFoundException(groupId); }
|
||||
if (group == null) { throw new GroupNotFoundException(groupId); }
|
||||
|
||||
loanApplication = Loan.newGroupLoanApplication(accountNo, group, loanProduct, fund, loanOfficer,
|
||||
loanTransactionProcessingStrategy, loanSchedule, loanCharges);
|
||||
|
||||
+1
-1
@@ -296,7 +296,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
|
||||
+ " l.loanpurpose_cv_id as loanPurposeId, cv.code_value as loanPurposeName,"
|
||||
+ " lp.id as loanProductId, lp.name as loanProductName, lp.description as loanProductDescription,"
|
||||
+ " c.id as clientId, c.display_name as clientName, c.office_id as clientOfficeId,"
|
||||
+ " g.id as groupId, g.name as groupName, g.office_id as groupOfficeId, g.staff_id As groupStaffId , g.parent_id as groupParentId , g.hierarchy As groupHierarchy , g.external_id As groupExternalId , "
|
||||
+ " g.id as groupId, g.display_name as groupName, g.office_id as groupOfficeId, g.staff_id As groupStaffId , g.parent_id as groupParentId , g.hierarchy As groupHierarchy , g.external_id As groupExternalId , "
|
||||
+ " l.submittedon_date as submittedOnDate, sbu.username as submittedByUsername, sbu.firstname as submittedByFirstname, sbu.lastname as submittedByLastname,"
|
||||
+ " l.rejectedon_date as rejectedOnDate, rbu.username as rejectedByUsername, rbu.firstname as rejectedByFirstname, rbu.lastname as rejectedByLastname,"
|
||||
+ " l.withdrawnon_date as withdrawnOnDate, wbu.username as withdrawnByUsername, wbu.firstname as withdrawnByFirstname, wbu.lastname as withdrawnByLastname,"
|
||||
|
||||
+2
@@ -16,6 +16,8 @@ public interface NoteRepository extends JpaRepository<Note, Long>, JpaSpecificat
|
||||
|
||||
List<Note> findByClientId(Long id);
|
||||
|
||||
List<Note> findByGroupId(Long groupId);
|
||||
|
||||
Note findByLoanIdAndId(Long loanId, Long id);
|
||||
|
||||
Note findByClientIdAndId(Long clientId, Long id);
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ public class SavingsAccountAssembler {
|
||||
|
||||
if (groupId != null) {
|
||||
group = this.groupRepository.findOne(groupId);
|
||||
if (group == null || group.isDeleted()) { throw new GroupNotFoundException(groupId); }
|
||||
if (group == null) { throw new GroupNotFoundException(groupId); }
|
||||
}
|
||||
|
||||
BigDecimal interestRate = null;
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ public class SavingsAccountReadPlatformServiceImpl implements SavingsAccountRead
|
||||
sqlBuilder.append("sa.id as id, sa.account_no as accountNo, sa.external_id as externalId, ");
|
||||
sqlBuilder.append("sa.status_enum as statusEnum, sa.activation_date as activationDate, ");
|
||||
sqlBuilder.append("c.id as clientId, c.display_name as clientName, ");
|
||||
sqlBuilder.append("g.id as groupId, g.name as groupName, ");
|
||||
sqlBuilder.append("g.id as groupId, g.display_name as groupName, ");
|
||||
sqlBuilder.append("sp.id as productId, sp.name as productName, ");
|
||||
sqlBuilder.append("sa.currency_code as currencyCode, sa.currency_digits as currencyDigits, ");
|
||||
sqlBuilder.append("curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ");
|
||||
|
||||
+1
-1
@@ -173,7 +173,7 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi
|
||||
final Long groupId = command.longValueOfParameterNamed(SavingsApiConstants.groupIdParamName);
|
||||
if (groupId != null) {
|
||||
final Group group = this.groupRepository.findOne(groupId);
|
||||
if (group == null || group.isDeleted()) { throw new GroupNotFoundException(groupId); }
|
||||
if (group == null) { throw new GroupNotFoundException(groupId); }
|
||||
account.update(group);
|
||||
} else {
|
||||
final Group group = null;
|
||||
|
||||
+7
-7
@@ -29,7 +29,7 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SearchData> retriveMatchingData(SearchConditions searchConditions) {
|
||||
public Collection<SearchData> retriveMatchingData(final SearchConditions searchConditions) {
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
|
||||
@@ -45,7 +45,7 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService
|
||||
|
||||
private static final class SearchMapper implements RowMapper<SearchData> {
|
||||
|
||||
public String searchSchema(SearchConditions searchConditions) {
|
||||
public String searchSchema(final SearchConditions searchConditions) {
|
||||
|
||||
String union = " union all ";
|
||||
String clientExactMatchSql = " (select 'CLIENT' as entityType, c.id as entityId, c.display_name as entityName, c.external_id as entityExternalId, c.account_no as entityAccountNo "
|
||||
@@ -76,13 +76,13 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService
|
||||
+ " from m_client_identifier ci join m_client c on ci.client_id=c.id join m_office o on o.id = c.office_id "
|
||||
+ " where o.hierarchy like :hierarchy and ci.document_key like :partialSearch and ci.document_key not like :search) ";
|
||||
|
||||
String groupExactMatchSql = " (select 'GROUP' as entityType, g.id as entityId, g.name as entityName, g.external_id as entityExternalId, NULL as entityAccountNo "
|
||||
String groupExactMatchSql = " (select 'GROUP' as entityType, g.id as entityId, g.display_name as entityName, g.external_id as entityExternalId, NULL as entityAccountNo "
|
||||
+ " , g.office_id as parentId, o.name as parentName "
|
||||
+ " from m_group g join m_office o on o.id = g.office_id where o.hierarchy like :hierarchy and g.name like :search) ";
|
||||
+ " from m_group g join m_office o on o.id = g.office_id where o.hierarchy like :hierarchy and g.display_name like :search) ";
|
||||
|
||||
String groupMatchSql = " (select 'GROUP' as entityType, g.id as entityId, g.name as entityName, g.external_id as entityExternalId, NULL as entityAccountNo "
|
||||
String groupMatchSql = " (select 'GROUP' as entityType, g.id as entityId, g.display_name as entityName, g.external_id as entityExternalId, NULL as entityAccountNo "
|
||||
+ " , g.office_id as parentId, o.name as parentName "
|
||||
+ " from m_group g join m_office o on o.id = g.office_id where o.hierarchy like :hierarchy and g.name like :partialSearch and g.name not like :search) ";
|
||||
+ " from m_group g join m_office o on o.id = g.office_id where o.hierarchy like :hierarchy and g.display_name like :partialSearch and g.display_name not like :search) ";
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
|
||||
@@ -127,7 +127,7 @@ public class SearchReadPlatformServiceImpl implements SearchReadPlatformService
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchData mapRow(ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
public SearchData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
final Long entityId = JdbcSupport.getLong(rs, "entityId");
|
||||
final String entityAccountNo = rs.getString("entityAccountNo");
|
||||
final String entityExternalId = rs.getString("entityExternalId");
|
||||
|
||||
Reference in New Issue
Block a user