Merge pull request #1297 from chandrikamohith/1808

MIFOSX-1808 Group hierarchy updation issue corrected.Center summary is n...
This commit is contained in:
Vishwas Babu A J
2015-03-19 15:46:12 +05:30
2 changed files with 29 additions and 17 deletions
@@ -348,16 +348,24 @@ public final class Group extends AbstractPersistable<Long> {
return this.clientMembers.contains(client); return this.clientMembers.contains(client);
} }
public void generateHierarchy() { public void generateHierarchy() {
if (this.parent != null) { if (this.parent != null) {
this.hierarchy = this.parent.hierarchyOf(getId()); this.hierarchy = this.parent.hierarchyOf(getId());
} else { } else {
this.hierarchy = "." + getId() + "."; this.hierarchy = "." + getId() + ".";
} for (Group group : this.groupMembers) {
} group.setParent(this);
group.generateHierarchy();
}
}
}
public void resetHierarchy() {
this.hierarchy = "." + this.getId();
}
private String hierarchyOf(final Long id) { private String hierarchyOf(final Long id) {
return this.hierarchy + id.toString() + "."; return this.hierarchy + id.toString() + ".";
} }
public boolean isOfficeIdentifiedBy(final Long officeId) { public boolean isOfficeIdentifiedBy(final Long officeId) {
@@ -522,6 +530,8 @@ public final class Group extends AbstractPersistable<Long> {
this.groupMembers.add(group); this.groupMembers.add(group);
differences.add(group.getId().toString()); differences.add(group.getId().toString());
group.setParent(this);
group.generateHierarchy();
} }
return differences; return differences;
@@ -534,6 +544,7 @@ public final class Group extends AbstractPersistable<Long> {
if (hasGroupAsMember(group)) { if (hasGroupAsMember(group)) {
this.groupMembers.remove(group); this.groupMembers.remove(group);
differences.add(group.getId().toString()); differences.add(group.getId().toString());
group.resetHierarchy();
} else { } else {
throw new GroupNotExistsInCenterException(group.getId(), getId()); throw new GroupNotExistsInCenterException(group.getId(), getId());
} }
@@ -184,9 +184,10 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
} }
// pre-save to generate id for use in group hierarchy // pre-save to generate id for use in group hierarchy
this.groupRepository.save(newGroup); this.groupRepository.save(newGroup);
newGroup.generateHierarchy(); /* Generate hierarchy for a new center/group and all the child groups if they exist */
newGroup.generateHierarchy();
this.groupRepository.saveAndFlush(newGroup); this.groupRepository.saveAndFlush(newGroup);
newGroup.captureStaffHistoryDuringCenterCreation(staff, activationDate); newGroup.captureStaffHistoryDuringCenterCreation(staff, activationDate);
@@ -756,12 +757,12 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
public CommandProcessingResult associateGroupsToCenter(final Long centerId, final JsonCommand command) { public CommandProcessingResult associateGroupsToCenter(final Long centerId, final JsonCommand command) {
this.fromApiJsonDeserializer.validateForAssociateGroups(command.json()); this.fromApiJsonDeserializer.validateForAssociateGroups(command.json());
final Group centerForUpdate = this.groupRepository.findOneWithNotFoundDetection(centerId); final Group centerForUpdate = this.groupRepository.findOneWithNotFoundDetection(centerId);
final Set<Group> groupMembers = assembleSetOfChildGroups(centerForUpdate.officeId(), command); final Set<Group> groupMembers = assembleSetOfChildGroups(centerForUpdate.officeId(), command);
checkGroupMembersMeetingSyncWithCenterMeeting(centerId, groupMembers); checkGroupMembersMeetingSyncWithCenterMeeting(centerId, groupMembers);
final Map<String, Object> actualChanges = new HashMap<>(); final Map<String, Object> actualChanges = new HashMap<>();
final List<String> changes = centerForUpdate.associateGroups(groupMembers); final List<String> changes = centerForUpdate.associateGroups(groupMembers);
if (!changes.isEmpty()) { if (!changes.isEmpty()) {
actualChanges.put(GroupingTypesApiConstants.groupMembersParamName, changes); actualChanges.put(GroupingTypesApiConstants.groupMembersParamName, changes);