get parent groups details along with client data
This commit is contained in:
+3
-3
@@ -53,9 +53,9 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class ClientsApiResource {
|
||||
|
||||
private final Set<String> CLIENT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "accountNo", "officeId", "officeName",
|
||||
"externalId", "firstname", "middlename", "lastname", "fullname", "joinedDate", "displayName", "clientOrBusinessName",
|
||||
"allowedOffices", "imagePresent"));
|
||||
private final Set<String> CLIENT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "accountNo", "externalId", "firstname",
|
||||
"middlename", "lastname", "fullname", "displayName", "officeId", "officeName", "joinedDate", "imageKey", "imagePresent",
|
||||
"parentGroups", "allowedOffices", "currentChange", "allChanges"));
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ClientReadPlatformService clientReadPlatformService;
|
||||
|
||||
+18
-7
@@ -11,6 +11,7 @@ import java.util.List;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.organisation.office.data.OfficeLookup;
|
||||
import org.mifosplatform.portfolio.group.data.GroupLookup;
|
||||
|
||||
/**
|
||||
* Immutable data object representing client data.
|
||||
@@ -31,7 +32,7 @@ final public class ClientData {
|
||||
private final String imageKey;
|
||||
@SuppressWarnings("unused")
|
||||
private final Boolean imagePresent;
|
||||
|
||||
private final Collection<GroupLookup> parentGroups;
|
||||
private final List<OfficeLookup> allowedOffices;
|
||||
|
||||
private final ClientData currentChange;
|
||||
@@ -42,24 +43,33 @@ final public class ClientData {
|
||||
|
||||
String localDisplayName = null;
|
||||
return new ClientData(null, officeId, null, id, firstname, middlename, lastname, fullname, localDisplayName, externalId,
|
||||
joiningDate, null, null, null, null);
|
||||
joiningDate, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public static ClientData integrateChanges(final ClientData clientData, ClientData currentChange, final Collection<ClientData> allChanges) {
|
||||
return new ClientData(clientData.accountNo, clientData.officeId, clientData.officeName, clientData.id, clientData.firstname,
|
||||
clientData.middlename, clientData.lastname, clientData.fullname, clientData.displayName, clientData.externalId,
|
||||
clientData.joinedDate, clientData.imageKey, clientData.allowedOffices, currentChange, allChanges);
|
||||
clientData.joinedDate, clientData.imageKey, clientData.allowedOffices, currentChange, allChanges, clientData.parentGroups);
|
||||
}
|
||||
|
||||
public static ClientData template(final Long officeId, final LocalDate joinedDate, final List<OfficeLookup> allowedOffices) {
|
||||
return new ClientData(null, officeId, null, null, null, null, null, null, null, null, joinedDate, null, allowedOffices, null, null);
|
||||
return new ClientData(null, officeId, null, null, null, null, null, null, null, null, joinedDate, null, allowedOffices, null, null,
|
||||
null);
|
||||
}
|
||||
|
||||
public static ClientData templateOnTop(final ClientData clientData, final List<OfficeLookup> allowedOffices) {
|
||||
|
||||
return new ClientData(clientData.accountNo, clientData.officeId, clientData.officeName, clientData.id, clientData.firstname,
|
||||
clientData.middlename, clientData.lastname, clientData.fullname, clientData.displayName, clientData.externalId,
|
||||
clientData.joinedDate, clientData.imageKey, allowedOffices, clientData.currentChange, clientData.allChanges);
|
||||
clientData.joinedDate, clientData.imageKey, allowedOffices, clientData.currentChange, clientData.allChanges,
|
||||
clientData.parentGroups);
|
||||
}
|
||||
|
||||
public static ClientData setParentGroups(final ClientData clientData, final Collection<GroupLookup> parentGroups) {
|
||||
return new ClientData(clientData.accountNo, clientData.officeId, clientData.officeName, clientData.id, clientData.firstname,
|
||||
clientData.middlename, clientData.lastname, clientData.fullname, clientData.displayName, clientData.externalId,
|
||||
clientData.joinedDate, clientData.imageKey, clientData.allowedOffices, clientData.currentChange, clientData.allChanges,
|
||||
parentGroups);
|
||||
}
|
||||
|
||||
public static ClientData clientIdentifier(final Long id, final String accountIdentifier, final String firstname,
|
||||
@@ -67,13 +77,13 @@ final public class ClientData {
|
||||
final String officeName) {
|
||||
|
||||
return new ClientData(accountIdentifier, officeId, officeName, id, firstname, middlename, lastname, fullname, displayName, null,
|
||||
null, null, null, null, null);
|
||||
null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public ClientData(final String accountNo, final Long officeId, final String officeName, final Long id, final String firstname,
|
||||
final String middlename, final String lastname, final String fullname, final String displayName, final String externalId,
|
||||
final LocalDate joinedDate, final String imageKey, final List<OfficeLookup> allowedOffices, final ClientData currentChange,
|
||||
final Collection<ClientData> allChanges) {
|
||||
final Collection<ClientData> allChanges, final Collection<GroupLookup> parentGroups) {
|
||||
this.accountNo = accountNo;
|
||||
this.officeId = officeId;
|
||||
this.officeName = officeName;
|
||||
@@ -94,6 +104,7 @@ final public class ClientData {
|
||||
this.allowedOffices = allowedOffices;
|
||||
this.currentChange = currentChange;
|
||||
this.allChanges = allChanges;
|
||||
this.parentGroups = parentGroups;
|
||||
}
|
||||
|
||||
public String displayName() {
|
||||
|
||||
+27
-3
@@ -23,6 +23,7 @@ import org.mifosplatform.portfolio.client.data.ClientAccountSummaryData;
|
||||
import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.client.data.ClientLookup;
|
||||
import org.mifosplatform.portfolio.client.exception.ClientNotFoundException;
|
||||
import org.mifosplatform.portfolio.group.data.GroupLookup;
|
||||
import org.mifosplatform.portfolio.loanaccount.data.LoanStatusEnumData;
|
||||
import org.mifosplatform.portfolio.loanproduct.service.LoanEnumerations;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
@@ -75,10 +76,15 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
ClientMapper rm = new ClientMapper();
|
||||
|
||||
String sql = "select " + rm.clientSchema() + " and c.id = " + clientId;
|
||||
ClientData clientData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { hierarchySearchString });
|
||||
|
||||
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { hierarchySearchString });
|
||||
ParentGroupsMapper cgrm = new ParentGroupsMapper();
|
||||
String cgSql = "select " + cgrm.parentGroupsSchema();
|
||||
Collection<GroupLookup> parentGroups = this.jdbcTemplate.query(cgSql, cgrm, new Object[] { clientId });
|
||||
|
||||
return ClientData.setParentGroups(clientData , parentGroups);
|
||||
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new ClientNotFoundException(clientId);
|
||||
}
|
||||
@@ -149,7 +155,25 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
final String officeName = rs.getString("officeName");
|
||||
|
||||
return new ClientData(accountNo, officeId, officeName, id, firstname, middlename, lastname, fullname, displayName, externalId,
|
||||
joinedDate, imageKey, null, null, null);
|
||||
joinedDate, imageKey, null, null, null ,null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class ParentGroupsMapper implements RowMapper<GroupLookup> {
|
||||
|
||||
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 ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long groupId = JdbcSupport.getLong(rs, "groupId");
|
||||
final String groupName = rs.getString("groupName");
|
||||
|
||||
return new GroupLookup(groupId, groupName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user