MIFOSX-26 added group and client office validation.
This commit is contained in:
@@ -6,6 +6,23 @@ public class ClientLookup {
|
|||||||
|
|
||||||
private final Long id;
|
private final Long id;
|
||||||
private final String displayName;
|
private final String displayName;
|
||||||
|
private final Long officeId;
|
||||||
|
private final String officeName;
|
||||||
|
|
||||||
|
public ClientLookup(final Long id, final String firstname, final String lastname, final Long officeId, String officeName) {
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
StringBuilder displayNameBuilder = new StringBuilder(firstname);
|
||||||
|
if (StringUtils.isNotBlank(displayNameBuilder.toString())) {
|
||||||
|
displayNameBuilder.append(' ');
|
||||||
|
}
|
||||||
|
displayNameBuilder.append(lastname);
|
||||||
|
|
||||||
|
this.displayName = displayNameBuilder.toString();
|
||||||
|
|
||||||
|
this.officeId = officeId;
|
||||||
|
this.officeName = officeName;
|
||||||
|
}
|
||||||
|
|
||||||
public ClientLookup(final Long id, final String firstname, final String lastname) {
|
public ClientLookup(final Long id, final String firstname, final String lastname) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -18,6 +35,8 @@ public class ClientLookup {
|
|||||||
|
|
||||||
this.displayName = displayNameBuilder.toString();
|
this.displayName = displayNameBuilder.toString();
|
||||||
|
|
||||||
|
this.officeId = null;
|
||||||
|
this.officeName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
|
|||||||
@@ -141,7 +141,11 @@ 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.
|
||||||
*
|
*
|
||||||
* Any fields with unique constraints and prepended with id of record.
|
* 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>{
|
private static final class ClientLookupMapper implements RowMapper<ClientLookup>{
|
||||||
|
|
||||||
public String clientLookupSchema() {
|
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
|
@Override
|
||||||
@@ -154,7 +156,11 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
|||||||
if (StringUtils.isBlank(firstname)) {
|
if (StringUtils.isBlank(firstname)) {
|
||||||
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.client.domain.ClientRepository;
|
||||||
import org.mifosng.platform.exceptions.ClientNotFoundException;
|
import org.mifosng.platform.exceptions.ClientNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.GroupNotFoundException;
|
import org.mifosng.platform.exceptions.GroupNotFoundException;
|
||||||
|
import org.mifosng.platform.exceptions.InvalidOfficeException;
|
||||||
import org.mifosng.platform.exceptions.OfficeNotFoundException;
|
import org.mifosng.platform.exceptions.OfficeNotFoundException;
|
||||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||||
import org.mifosng.platform.group.domain.Group;
|
import org.mifosng.platform.group.domain.Group;
|
||||||
@@ -138,6 +139,10 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
|||||||
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())){
|
||||||
|
String errorMessage = "Group and Client must have the same office.";
|
||||||
|
throw new InvalidOfficeException("client", "attach.to.group", errorMessage);
|
||||||
|
}
|
||||||
clientMembers.add(client);
|
clientMembers.add(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user