GroupUpdate api:in response send list of clients changed, using Guava symmetricDifference
This commit is contained in:
+15
-3
@@ -6,6 +6,7 @@
|
|||||||
package org.mifosplatform.portfolio.group.service;
|
package org.mifosplatform.portfolio.group.service;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -41,6 +42,7 @@ import org.springframework.dao.DataIntegrityViolationException;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePlatformService {
|
public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePlatformService {
|
||||||
@@ -243,9 +245,9 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
|||||||
final String clientMembersParamName = "clientMembers";
|
final String clientMembersParamName = "clientMembers";
|
||||||
|
|
||||||
if (!clientMembers.equals(groupForUpdate.getClientMembers())) {
|
if (!clientMembers.equals(groupForUpdate.getClientMembers())) {
|
||||||
final String[] newValue = command.arrayValueOfParameterNamed(clientMembersParamName);
|
Set<Client> diffClients = Sets.symmetricDifference(clientMembers, groupForUpdate.getClientMembers());
|
||||||
// TODO Use Guava's symmetricDifference
|
final String[] diffClientsIds = getClientIds(diffClients);
|
||||||
actualChanges.put(clientMembersParamName, newValue);
|
actualChanges.put(clientMembersParamName, diffClientsIds);
|
||||||
groupForUpdate.setClientMembers(clientMembers);
|
groupForUpdate.setClientMembers(clientMembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,6 +364,16 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla
|
|||||||
return childGroups;
|
return childGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String[] getClientIds(final Set<Client> clients) {
|
||||||
|
|
||||||
|
String[] clientIds = new String[clients.size()];
|
||||||
|
Iterator<Client> it = clients.iterator();
|
||||||
|
for (int i = 0; it.hasNext(); i++) {
|
||||||
|
clientIds[i] = it.next().getId().toString();
|
||||||
|
}
|
||||||
|
return clientIds;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Guaranteed to throw an exception no matter what the data integrity issue
|
* Guaranteed to throw an exception no matter what the data integrity issue
|
||||||
* is.
|
* is.
|
||||||
|
|||||||
Reference in New Issue
Block a user