remove usused warnings, make group data immutable.

This commit is contained in:
Keith Woodlock
2012-10-02 12:24:36 +01:00
parent 1bae87e447
commit b86966caf9
11 changed files with 122 additions and 138 deletions
@@ -121,20 +121,16 @@ public class DataTableApiResource {
.retrieveDataTableGenericResultSet(datatable, apptableId, .retrieveDataTableGenericResultSet(datatable, apptableId,
sqlFields, sqlOrder, null); sqlFields, sqlOrder, null);
boolean genericResultSet = ApiParameterHelper.genericResultSet(uriInfo String json = "";
.getQueryParameters()); final boolean genericResultSet = ApiParameterHelper.genericResultSet(uriInfo.getQueryParameters());
if (genericResultSet) { if (genericResultSet) {
boolean prettyPrints = ApiParameterHelper.prettyPrint(uriInfo boolean prettyPrints = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
.getQueryParameters()); json = this.apiJsonSerializerService.serializeGenericResultsetDataToJson(prettyPrints, results);
return this.apiJsonSerializerService
.serializeGenericResultsetDataToJson(prettyPrints, results);
} else { } else {
json = this.genericDataService.generateJsonFromGenericResultsetData(results);
return this.genericDataService
.generateJsonFromGenericResultsetData(results);
} }
return json;
} }
@POST @POST
@@ -1,6 +1,5 @@
package org.mifosng.platform.api; package org.mifosng.platform.api;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
@@ -20,7 +19,6 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.GroupCommand; import org.mifosng.platform.api.commands.GroupCommand;
import org.mifosng.platform.api.data.ClientAccountSummaryCollectionData;
import org.mifosng.platform.api.data.ClientLookup; import org.mifosng.platform.api.data.ClientLookup;
import org.mifosng.platform.api.data.EntityIdentifier; import org.mifosng.platform.api.data.EntityIdentifier;
import org.mifosng.platform.api.data.GroupAccountSummaryCollectionData; import org.mifosng.platform.api.data.GroupAccountSummaryCollectionData;
@@ -94,23 +92,26 @@ public class GroupsApiResource {
} }
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters()); boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
GroupData group = this.groupReadPlatformService.retrieveGroup(groupId); GroupData group = this.groupReadPlatformService.retrieveGroup(groupId);
final Collection<ClientLookup> clientMembers = this.groupReadPlatformService.retrieveClientMembers(groupId);
Collection<ClientLookup> availableClients = null;
Collection<OfficeLookup> allowedOffices = null;
group = new GroupData(group, clientMembers, availableClients, allowedOffices);
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
if (template) {
responseParameters.add("allowedClients");
responseParameters.add("allowedOffices");
Collection<ClientLookup> clientMembers = this.groupReadPlatformService.retrieveClientMembers(groupId); availableClients = this.clientReadPlatformService.retrieveAllIndividualClientsForLookup();
group.setClientMembers(clientMembers); availableClients.removeAll(group.clientMembers());
if (template) { allowedOffices = officeReadPlatformService.retrieveAllOfficesForLookup();
Collection<ClientLookup> availableClients = this.clientReadPlatformService.retrieveAllIndividualClientsForLookup();
availableClients.removeAll(group.getClientMembers());
group.setAllowedClients(availableClients);
responseParameters.add("allowedClients"); group = new GroupData(group, group.clientMembers(), availableClients, allowedOffices);
}
group.setAllowedOffices(new ArrayList<OfficeLookup>(officeReadPlatformService.retrieveAllOfficesForLookup()));
responseParameters.add("allowedOffices");
}
return this.apiJsonSerializerService.serializeGroupDataToJson(prettyPrint, responseParameters, group); return this.apiJsonSerializerService.serializeGroupDataToJson(prettyPrint, responseParameters, group);
} }
@@ -5,11 +5,14 @@ import org.apache.commons.lang.StringUtils;
public class ClientLookup { public class ClientLookup {
private final Long id; private final Long id;
@SuppressWarnings("unused")
private final String displayName; private final String displayName;
private final Long officeId; @SuppressWarnings("unused")
private final String officeName; private final Long officeId;
@SuppressWarnings("unused")
private final String officeName;
public ClientLookup(final Long id, final String firstname, final String lastname, final Long officeId, String officeName) { public ClientLookup(final Long id, final String firstname, final String lastname, final Long officeId, final String officeName) {
this.id = id; this.id = id;
StringBuilder displayNameBuilder = new StringBuilder(firstname); StringBuilder displayNameBuilder = new StringBuilder(firstname);
@@ -39,18 +42,10 @@ public class ClientLookup {
this.officeName = null; this.officeName = null;
} }
public Long getId() {
return id;
}
public String getDisplayName() {
return displayName;
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
ClientLookup clientLookup = (ClientLookup) obj; ClientLookup clientLookup = (ClientLookup) obj;
return this.id.equals(clientLookup.getId()); return this.id.equals(clientLookup.id);
} }
@Override @Override
@@ -1,46 +1,76 @@
package org.mifosng.platform.api.data; package org.mifosng.platform.api.data;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
/**
* Immutable data object representing groups.
*/
public class GroupData { public class GroupData {
private final Long id;
private final String name;
private final String externalId;
private final Long officeId;
private final String officeName;
private Collection<ClientLookup> clientMembers = new ArrayList<ClientLookup>(); private final Long id;
private Collection<ClientLookup> allowedClients = new ArrayList<ClientLookup>(); private final String name;
private Collection<OfficeLookup> allowedOffices = new ArrayList<OfficeLookup>(); private final String externalId;
private final Long officeId;
private final String officeName;
public GroupData(Long id, Long officeId, String officeName, String name, String externalId) { private final Collection<ClientLookup> clientMembers;
this.id = id; @SuppressWarnings("unused")
this.name = name; private final Collection<ClientLookup> allowedClients;
this.externalId = externalId; @SuppressWarnings("unused")
this.officeId = officeId; private final Collection<OfficeLookup> allowedOffices;
this.officeName = officeName;
}
public GroupData(Collection<ClientLookup> allowedClients, Collection<OfficeLookup> allowedOffices){ public GroupData(
this.id = null; final Long id,
this.name = null; final Long officeId,
this.externalId = null; final String officeName,
this.officeId = null; final String name,
this.officeName = null; final String externalId) {
this.allowedClients = allowedClients; this.id = id;
this.allowedOffices = allowedOffices; this.officeId = officeId;
} this.officeName = officeName;
this.name = name;
this.externalId = externalId;
public Long getId() { this.clientMembers = null;
return id; this.allowedClients = null;
} this.allowedOffices = null;
}
public String getName() { public GroupData(final GroupData group, final Collection<ClientLookup> clientMembers, final Collection<ClientLookup> allowedClients,
return name; final Collection<OfficeLookup> allowedOffices) {
} this.id = group.getId();
this.officeId = group.getOfficeId();
this.officeName = group.getOfficeName();
this.name = group.getName();
this.externalId = group.getExternalId();
this.clientMembers = clientMembers;
this.allowedClients = allowedClients;
this.allowedOffices = allowedOffices;
}
public GroupData(final Collection<ClientLookup> allowedClients, final Collection<OfficeLookup> allowedOffices) {
this.id = null;
this.officeId = null;
this.officeName = null;
this.name = null;
this.externalId = null;
this.clientMembers = null;
this.allowedClients = allowedClients;
this.allowedOffices = allowedOffices;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public String getExternalId() {
return externalId;
}
public Long getOfficeId() { public Long getOfficeId() {
return officeId; return officeId;
@@ -50,31 +80,7 @@ public class GroupData {
return officeName; return officeName;
} }
public String getExternalId() { public Collection<ClientLookup> clientMembers() {
return externalId; return this.clientMembers;
} }
}
public Collection<ClientLookup> getClientMembers() {
return clientMembers;
}
public void setClientMembers(Collection<ClientLookup> clientMembers) {
this.clientMembers = clientMembers;
}
public Collection<ClientLookup> getAllowedClients() {
return allowedClients;
}
public void setAllowedClients(Collection<ClientLookup> allowedClients) {
this.allowedClients = allowedClients;
}
public Collection<OfficeLookup> getAllowedOffices() {
return allowedOffices;
}
public void setAllowedOffices(Collection<OfficeLookup> allowedOffices) {
this.allowedOffices = allowedOffices;
}
}
@@ -21,7 +21,6 @@ import org.mifosng.platform.user.domain.AppUser;
@Table(name = "m_client") @Table(name = "m_client")
public class Client extends AbstractAuditableCustom<AppUser, Long> { public class Client extends AbstractAuditableCustom<AppUser, Long> {
@SuppressWarnings("unused")
@ManyToOne @ManyToOne
@JoinColumn(name = "office_id", nullable = false) @JoinColumn(name = "office_id", nullable = false)
private Office office; private Office office;
@@ -51,7 +50,7 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
return new Client(clientOffice, firstname, lastname, joiningDate, externalId); return new Client(clientOffice, firstname, lastname, joiningDate, externalId);
} }
public Client() { protected Client() {
this.office = null; this.office = null;
this.joiningDate = null; this.joiningDate = null;
this.firstName = null; this.firstName = null;
@@ -141,10 +140,6 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
this.displayName = this.firstName + " " + this.lastName; this.displayName = this.firstName + " " + this.lastName;
} }
public Office getOffice() {
return office;
}
/** /**
* Delete is a <i>soft delete</i>. Updates flag on client so it wont appear in query/report results. * Delete is a <i>soft delete</i>. Updates flag on client so it wont appear in query/report results.
* *
@@ -158,4 +153,8 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
public boolean isDeleted() { public boolean isDeleted() {
return deleted; return deleted;
} }
public boolean isOfficeIdentifiedBy(final Long officeId) {
return this.office.identifiedBy(officeId);
}
} }
@@ -22,7 +22,8 @@ import org.mifosng.platform.user.domain.AppUser;
@Table(name = "m_group") @Table(name = "m_group")
public class Group extends AbstractAuditableCustom<AppUser, Long> { public class Group extends AbstractAuditableCustom<AppUser, Long> {
@ManyToOne @SuppressWarnings("unused")
@ManyToOne
@JoinColumn(name = "office_id", nullable = false) @JoinColumn(name = "office_id", nullable = false)
private Office office; private Office office;
@@ -56,7 +56,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
} }
@Override @Override
public GroupData retrieveGroup(Long groupId) { public GroupData retrieveGroup(final Long groupId) {
try{ try{
this.context.authenticatedUser(); this.context.authenticatedUser();
@@ -134,12 +134,12 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
if (command.isClientMembersChanged() && !ObjectUtils.isEmpty(clientMembersArray)) { if (command.isClientMembersChanged() && !ObjectUtils.isEmpty(clientMembersArray)) {
for (String clientId : clientMembersArray) { for (String clientId : clientMembersArray) {
Long id = Long.valueOf(clientId); final Long id = Long.valueOf(clientId);
Client client = this.clientRepository.findOne(id); Client client = this.clientRepository.findOne(id);
if (client == null || client.isDeleted()) { if (client == null || client.isDeleted()) {
throw new ClientNotFoundException(id); throw new ClientNotFoundException(id);
} }
if (!client.getOffice().getId().equals(command.getOfficeId())){ if (!client.isOfficeIdentifiedBy(command.getOfficeId())){
String errorMessage = "Group and Client must have the same office."; String errorMessage = "Group and Client must have the same office.";
throw new InvalidOfficeException("client", "attach.to.group", errorMessage); throw new InvalidOfficeException("client", "attach.to.group", errorMessage);
} }
@@ -98,7 +98,6 @@ public class DepositAccount extends AbstractAuditableCustom<AppUser, Long> {
@Column(name = "is_renewal_allowed", nullable = false) @Column(name = "is_renewal_allowed", nullable = false)
private boolean renewalAllowed = false; private boolean renewalAllowed = false;
@SuppressWarnings("unused")
@Column(name = "is_preclosure_allowed", nullable = false) @Column(name = "is_preclosure_allowed", nullable = false)
private boolean preClosureAllowed = false; private boolean preClosureAllowed = false;
@@ -5,8 +5,6 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Collection; import java.util.Collection;
import javax.security.auth.login.AccountException;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.joda.time.Months; import org.joda.time.Months;
import org.mifosng.platform.api.data.ClientData; import org.mifosng.platform.api.data.ClientData;
@@ -56,26 +54,6 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead
String sql = "select " + mapper.schema() + " where da.is_deleted=0"; String sql = "select " + mapper.schema() + " where da.is_deleted=0";
return this.jdbcTemplate.query(sql,mapper, new Object[]{}); return this.jdbcTemplate.query(sql,mapper, new Object[]{});
// NOTE: when retrieving a list of deposit accounts, its unlikey we want to much detail so at that point in time,
// not likely that returning what transactions have is useful so removing it.
// DepositAccountTransactionMapper transactionMapper = new DepositAccountTransactionMapper();
// String transactionSchema = "Select " + transactionMapper.schema();
// Collection<DepositAccountTransactionData> depositAccountTransactionDatas = this.jdbcTemplate.query(transactionSchema, transactionMapper, new Object[]{});
// for (DepositAccountData depositAccountData : depositAccountDatas) {
// List<DepositAccountTransactionData> myAccountTransactionDatas = new ArrayList<DepositAccountTransactionData>();
//
// for (DepositAccountTransactionData depositAccountTransactionData : depositAccountTransactionDatas) {
// if (depositAccountData.getId().equals(depositAccountTransactionData.getAccountId())) {
// myAccountTransactionDatas.add(depositAccountTransactionData);
// }
// depositAccountData.setTransactions(myAccountTransactionDatas);
// }
// }
// return depositAccountDatas;
} }
@Override @Override
@@ -363,18 +363,27 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo
if (account == null || account.isDeleted()) { if (account == null || account.isDeleted()) {
throw new DepositAccountNotFoundException(command.getId()); throw new DepositAccountNotFoundException(command.getId());
} }
if(account.isRenewalAllowed()&&(new LocalDate().isAfter(account.maturesOnDate())||new LocalDate().isEqual(account.maturesOnDate()))){
if(account.getDepositStatus().equals(DepositAccountStatus.ACTIVE.getValue())){ // FIXME - KW - extract whats in this if into a method that naturally describes what you are checking.
final DepositAccount renewedAccount = this.depositAccountAssembler.assembleFrom(account,command); if (account.isRenewalAllowed()
&& (new LocalDate().isAfter(account.maturesOnDate()) || new LocalDate()
.isEqual(account.maturesOnDate()))) {
// FIXME - KW - rather than getting the status from account and then checking,
// add isActive behaviour on account so all places that use account dont have to repeat this type of checking.
if (account.getDepositStatus().equals(
DepositAccountStatus.ACTIVE.getValue())) {
final DepositAccount renewedAccount = this.depositAccountAssembler
.assembleFrom(account, command);
this.depositAccountRepository.save(renewedAccount); this.depositAccountRepository.save(renewedAccount);
account.closeDepositAccount(defaultDepositLifecycleStateMachine()); account.closeDepositAccount(defaultDepositLifecycleStateMachine());
this.depositAccountRepository.save(account); this.depositAccountRepository.save(account);
return new EntityIdentifier(renewedAccount.getId()); return new EntityIdentifier(renewedAccount.getId());
}else{
throw new DepositAccountReopenException(account.getMaturityDate());
} }
}else{
throw new DepositAccountReopenException(account.getMaturityDate()); throw new DepositAccountReopenException(account.getMaturityDate());
} }
throw new DepositAccountReopenException(account.getMaturityDate());
} }
} }