FIXED MIFOSX-24: General Issues with Groups so far
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE portfolio_group ADD UNIQUE (name);
|
||||||
@@ -19,6 +19,7 @@ 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.ClientMemberData;
|
||||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||||
import org.mifosng.platform.api.data.GroupData;
|
import org.mifosng.platform.api.data.GroupData;
|
||||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||||
@@ -49,7 +50,7 @@ public class GroupsApiResource {
|
|||||||
public String retrieveAllGroups(@Context final UriInfo uriInfo){
|
public String retrieveAllGroups(@Context final UriInfo uriInfo){
|
||||||
|
|
||||||
Set<String> typicalResponseParameters = new HashSet<String>(
|
Set<String> typicalResponseParameters = new HashSet<String>(
|
||||||
Arrays.asList("id", "name", "externalId")
|
Arrays.asList("id", "name", "externalId", "clientMembers")
|
||||||
);
|
);
|
||||||
|
|
||||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
@@ -61,6 +62,10 @@ public class GroupsApiResource {
|
|||||||
|
|
||||||
Collection<GroupData> groups = this.groupReadPlatformService.retrieveAllGroups();
|
Collection<GroupData> groups = this.groupReadPlatformService.retrieveAllGroups();
|
||||||
|
|
||||||
|
for (GroupData group : groups){
|
||||||
|
group.setClientMembers(this.groupReadPlatformService.retrieveClientMembers(group.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
return this.apiDataConversionService.convertGroupDataToJson(prettyPrint, responseParameters, groups.toArray(new GroupData[groups.size()]));
|
return this.apiDataConversionService.convertGroupDataToJson(prettyPrint, responseParameters, groups.toArray(new GroupData[groups.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +87,9 @@ public class GroupsApiResource {
|
|||||||
|
|
||||||
GroupData group = this.groupReadPlatformService.retrieveGroup(groupId);
|
GroupData group = this.groupReadPlatformService.retrieveGroup(groupId);
|
||||||
|
|
||||||
|
Collection<ClientMemberData> clientMembers = this.groupReadPlatformService.retrieveClientMembers(groupId);
|
||||||
|
group.setClientMembers(clientMembers);
|
||||||
|
|
||||||
return this.apiDataConversionService.convertGroupDataToJson(prettyPrint, responseParameters, group);
|
return this.apiDataConversionService.convertGroupDataToJson(prettyPrint, responseParameters, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.mifosng.platform.api.data;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
public class ClientMemberData {
|
||||||
|
|
||||||
|
private final Long id;
|
||||||
|
private final String displayName;
|
||||||
|
|
||||||
|
public ClientMemberData(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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
package org.mifosng.platform.api.data;
|
package org.mifosng.platform.api.data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class GroupData {
|
public class GroupData {
|
||||||
|
|
||||||
private final Long id;
|
private final Long id;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String externalId;
|
private final String externalId;
|
||||||
|
|
||||||
|
private Collection<ClientMemberData> clientMembers = new ArrayList<ClientMemberData>();
|
||||||
|
|
||||||
public GroupData(Long id, String name, String externalId) {
|
public GroupData(Long id, String name, String externalId) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -25,4 +30,12 @@ public class GroupData {
|
|||||||
return externalId;
|
return externalId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<ClientMemberData> getClientMembers() {
|
||||||
|
return clientMembers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientMembers(Collection<ClientMemberData> clientMembers) {
|
||||||
|
this.clientMembers = clientMembers;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -380,7 +380,7 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
|||||||
@Override
|
@Override
|
||||||
public String convertGroupDataToJson(boolean prettyPrint, Set<String> responseParameters, GroupData... groups) {
|
public String convertGroupDataToJson(boolean prettyPrint, Set<String> responseParameters, GroupData... groups) {
|
||||||
final Set<String> supportedParameters = new HashSet<String>(
|
final Set<String> supportedParameters = new HashSet<String>(
|
||||||
Arrays.asList("id", "name", "externalId")
|
Arrays.asList("id", "name", "externalId", "clientMembers")
|
||||||
);
|
);
|
||||||
|
|
||||||
final Set<String> parameterNamesToSkip = new HashSet<String>();
|
final Set<String> parameterNamesToSkip = new HashSet<String>();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import org.mifosng.platform.user.domain.AppUser;
|
|||||||
@Table(name = "portfolio_group")
|
@Table(name = "portfolio_group")
|
||||||
public class Group extends AbstractAuditableCustom<AppUser, Long> {
|
public class Group extends AbstractAuditableCustom<AppUser, Long> {
|
||||||
|
|
||||||
@Column(name = "name", length = 100)
|
@Column(name = "name", length = 100, unique = true)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(name = "external_id", length = 100, unique = true)
|
@Column(name = "external_id", length = 100, unique = true)
|
||||||
@@ -34,7 +34,7 @@ public class Group extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
joinColumns = @JoinColumn(name = "group_id"),
|
joinColumns = @JoinColumn(name = "group_id"),
|
||||||
inverseJoinColumns = @JoinColumn(name = "client_id"))
|
inverseJoinColumns = @JoinColumn(name = "client_id"))
|
||||||
private Set<Client> clientMembers;
|
private Set<Client> clientMembers;
|
||||||
|
|
||||||
public Group() {
|
public Group() {
|
||||||
this.name = null;
|
this.name = null;
|
||||||
this.externalId = null;
|
this.externalId = null;
|
||||||
@@ -61,7 +61,7 @@ public class Group extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(GroupCommand command) {
|
public void update(final GroupCommand command, final Set<Client> clientMembers) {
|
||||||
if (command.isExternalIdChanged()) {
|
if (command.isExternalIdChanged()) {
|
||||||
this.externalId = command.getExternalId();
|
this.externalId = command.getExternalId();
|
||||||
}
|
}
|
||||||
@@ -69,6 +69,10 @@ public class Group extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
if (command.isNameChanged()) {
|
if (command.isNameChanged()) {
|
||||||
this.name = command.getName();
|
this.name = command.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (clientMembers != null && command.isClientMembersChanged()){
|
||||||
|
this.clientMembers = clientMembers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addClientMember(final Client member){
|
public void addClientMember(final Client member){
|
||||||
@@ -83,6 +87,7 @@ public class Group extends AbstractAuditableCustom<AppUser, Long> {
|
|||||||
public void delete() {
|
public void delete() {
|
||||||
this.deleted = true;
|
this.deleted = true;
|
||||||
this.externalId = this.getId() + "_" + this.externalId;
|
this.externalId = this.getId() + "_" + this.externalId;
|
||||||
|
this.name = this.getId() + "_" + this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDeleted() {
|
public boolean isDeleted() {
|
||||||
|
|||||||
+2
@@ -42,6 +42,8 @@ public class GroupCommandValidator {
|
|||||||
baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank();
|
baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank();
|
||||||
baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100);
|
baseDataValidator.reset().parameter("externalId").value(command.getExternalId()).ignoreIfNull().notExceedingLengthOf(100);
|
||||||
|
|
||||||
|
baseDataValidator.reset().parameter("clientMembers").value(command.getClientMembers()).ignoreIfNull();
|
||||||
|
|
||||||
if (!dataValidationErrors.isEmpty()) {
|
if (!dataValidationErrors.isEmpty()) {
|
||||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -2,6 +2,7 @@ package org.mifosng.platform.group.service;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.mifosng.platform.api.data.ClientMemberData;
|
||||||
import org.mifosng.platform.api.data.GroupData;
|
import org.mifosng.platform.api.data.GroupData;
|
||||||
|
|
||||||
public interface GroupReadPlatformService {
|
public interface GroupReadPlatformService {
|
||||||
@@ -9,5 +10,6 @@ public interface GroupReadPlatformService {
|
|||||||
Collection<GroupData> retrieveAllGroups();
|
Collection<GroupData> retrieveAllGroups();
|
||||||
|
|
||||||
GroupData retrieveGroup(Long groupId);
|
GroupData retrieveGroup(Long groupId);
|
||||||
|
|
||||||
|
Collection<ClientMemberData> retrieveClientMembers(Long groupId);
|
||||||
}
|
}
|
||||||
|
|||||||
+33
@@ -4,6 +4,8 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.mifosng.platform.api.data.ClientMemberData;
|
||||||
import org.mifosng.platform.api.data.GroupData;
|
import org.mifosng.platform.api.data.GroupData;
|
||||||
import org.mifosng.platform.exceptions.GroupNotFoundException;
|
import org.mifosng.platform.exceptions.GroupNotFoundException;
|
||||||
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
||||||
@@ -73,4 +75,35 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<ClientMemberData> retrieveClientMembers(Long groupId){
|
||||||
|
|
||||||
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
|
ClientMemberSummaryDataMapper rm = new ClientMemberSummaryDataMapper();
|
||||||
|
|
||||||
|
String sql = "select " + rm.clientMemberSummarySchema() + " where cm.is_deleted = 0 and pgc.group_id = ?";
|
||||||
|
|
||||||
|
return this.jdbcTemplate.query(sql, rm, new Object[] {groupId});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class ClientMemberSummaryDataMapper implements RowMapper<ClientMemberData> {
|
||||||
|
|
||||||
|
public String clientMemberSummarySchema() {
|
||||||
|
return "cm.id, cm.firstname, cm.lastname from portfolio_client cm INNER JOIN portfolio_group_client pgc ON pgc.client_id = cm.id";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClientMemberData mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||||
|
Long id = rs.getLong("id");
|
||||||
|
String firstname = rs.getString("firstname");
|
||||||
|
String lastname = rs.getString("lastname");
|
||||||
|
if (StringUtils.isBlank(firstname)) {
|
||||||
|
firstname = "";
|
||||||
|
}
|
||||||
|
return new ClientMemberData(id, firstname, lastname);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -65,7 +65,10 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
|||||||
if (groupForUpdate == null || groupForUpdate.isDeleted()) {
|
if (groupForUpdate == null || groupForUpdate.isDeleted()) {
|
||||||
throw new GroupNotFoundException(command.getId());
|
throw new GroupNotFoundException(command.getId());
|
||||||
}
|
}
|
||||||
groupForUpdate.update(command);
|
|
||||||
|
final Set<Client> clientMembers = assembleSetOfClients(command);
|
||||||
|
|
||||||
|
groupForUpdate.update(command, clientMembers);
|
||||||
|
|
||||||
groupRepository.save(groupForUpdate);
|
groupRepository.save(groupForUpdate);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user