MIFOSX-26 added group and client office validation.
This commit is contained in:
@@ -6,8 +6,10 @@ public class ClientLookup {
|
||||
|
||||
private final Long id;
|
||||
private final String displayName;
|
||||
private final Long officeId;
|
||||
private final String officeName;
|
||||
|
||||
public ClientLookup(final Long id, final String firstname, final String lastname) {
|
||||
public ClientLookup(final Long id, final String firstname, final String lastname, final Long officeId, String officeName) {
|
||||
this.id = id;
|
||||
|
||||
StringBuilder displayNameBuilder = new StringBuilder(firstname);
|
||||
@@ -17,7 +19,24 @@ public class ClientLookup {
|
||||
displayNameBuilder.append(lastname);
|
||||
|
||||
this.displayName = displayNameBuilder.toString();
|
||||
|
||||
|
||||
this.officeId = officeId;
|
||||
this.officeName = officeName;
|
||||
}
|
||||
|
||||
public ClientLookup(final Long id, final String firstname, final String lastname) {
|
||||
this.id = id;
|
||||
|
||||
StringBuilder displayNameBuilder = new StringBuilder(firstname);
|
||||
if (StringUtils.isNotBlank(displayNameBuilder.toString())) {
|
||||
displayNameBuilder.append(' ');
|
||||
}
|
||||
displayNameBuilder.append(lastname);
|
||||
|
||||
this.displayName = displayNameBuilder.toString();
|
||||
|
||||
this.officeId = null;
|
||||
this.officeName = null;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
|
||||
@@ -141,7 +141,11 @@ public class Client extends AbstractAuditableCustom<AppUser, Long> {
|
||||
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.
|
||||
*
|
||||
* Any fields with unique constraints and prepended with id of record.
|
||||
|
||||
+8
-2
@@ -143,7 +143,9 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
private static final class ClientLookupMapper implements RowMapper<ClientLookup>{
|
||||
|
||||
public String clientLookupSchema() {
|
||||
return "c.id as id, c.firstname as firstname, c.lastname as lastname from m_client c";
|
||||
return "c.id as id, c.firstname as firstname, c.lastname as lastname, " +
|
||||
"c.office_id as officeId, o.name as officeName " +
|
||||
"from m_client c join m_office o on o.id = c.office_id";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,7 +156,11 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
if (StringUtils.isBlank(firstname)) {
|
||||
firstname = "";
|
||||
}
|
||||
return new ClientLookup(id, firstname, lastname);
|
||||
|
||||
Long officeId = rs.getLong("officeId");
|
||||
String officeName = rs.getString("officeName");
|
||||
|
||||
return new ClientLookup(id, firstname, lastname, officeId, officeName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package org.mifosng.platform.exceptions;
|
||||
|
||||
/**
|
||||
* {@link AbstractPlatformDomainRuleException} thrown when office mismatch occurs
|
||||
*/
|
||||
public class InvalidOfficeException extends AbstractPlatformDomainRuleException {
|
||||
|
||||
public InvalidOfficeException(final String entity, final String postFix, String defaultUserMessage, Object... defaultUserMessageArgs) {
|
||||
super("error.msg."+entity+"."+postFix+".invalid.office", defaultUserMessage, defaultUserMessageArgs);
|
||||
}
|
||||
}
|
||||
+5
@@ -9,6 +9,7 @@ import org.mifosng.platform.client.domain.Client;
|
||||
import org.mifosng.platform.client.domain.ClientRepository;
|
||||
import org.mifosng.platform.exceptions.ClientNotFoundException;
|
||||
import org.mifosng.platform.exceptions.GroupNotFoundException;
|
||||
import org.mifosng.platform.exceptions.InvalidOfficeException;
|
||||
import org.mifosng.platform.exceptions.OfficeNotFoundException;
|
||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||
import org.mifosng.platform.group.domain.Group;
|
||||
@@ -138,6 +139,10 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
||||
if (client == null || client.isDeleted()) {
|
||||
throw new ClientNotFoundException(id);
|
||||
}
|
||||
if (!client.getOffice().getId().equals(command.getOfficeId())){
|
||||
String errorMessage = "Group and Client must have the same office.";
|
||||
throw new InvalidOfficeException("client", "attach.to.group", errorMessage);
|
||||
}
|
||||
clientMembers.add(client);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user