MIFOSX-1808 Group hierarchy updation issue corrected.Center summary is now getting updated properly.

This commit is contained in:
Chandrika
2015-03-16 19:16:42 -04:00
parent 7fcdb77f36
commit 7f95e4bf20
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);
}
public void generateHierarchy() {
if (this.parent != null) {
this.hierarchy = this.parent.hierarchyOf(getId());
} else {
this.hierarchy = "." + getId() + ".";
}
}
public void generateHierarchy() {
if (this.parent != null) {
this.hierarchy = this.parent.hierarchyOf(getId());
} else {
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) {
return this.hierarchy + id.toString() + ".";
return this.hierarchy + id.toString() + ".";
}
public boolean isOfficeIdentifiedBy(final Long officeId) {
@@ -375,7 +383,7 @@ public final class Group extends AbstractPersistable<Long> {
}
return staffId;
}
private void addChild(final Group group) {
this.groupMembers.add(group);
}
@@ -522,6 +530,8 @@ public final class Group extends AbstractPersistable<Long> {
this.groupMembers.add(group);
differences.add(group.getId().toString());
group.setParent(this);
group.generateHierarchy();
}
return differences;
@@ -534,6 +544,7 @@ public final class Group extends AbstractPersistable<Long> {
if (hasGroupAsMember(group)) {
this.groupMembers.remove(group);
differences.add(group.getId().toString());
group.resetHierarchy();
} else {
throw new GroupNotExistsInCenterException(group.getId(), getId());
}
@@ -131,7 +131,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
parentGroup = this.groupRepository.findOneWithNotFoundDetection(centerId);
officeId = parentGroup.officeId();
}
final Office groupOffice = this.officeRepository.findOne(officeId);
if (groupOffice == null) { throw new OfficeNotFoundException(officeId); }
@@ -184,9 +184,10 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
}
// 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);
newGroup.captureStaffHistoryDuringCenterCreation(staff, activationDate);
@@ -414,7 +415,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
groupForUpdate.unassignStaff();
}
this.groupRepository.saveAndFlush(groupForUpdate);
actualChanges.put(staffIdParamName, null);
return new CommandProcessingResultBuilder() //
@@ -756,17 +757,17 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
public CommandProcessingResult associateGroupsToCenter(final Long centerId, final JsonCommand command) {
this.fromApiJsonDeserializer.validateForAssociateGroups(command.json());
final Group centerForUpdate = this.groupRepository.findOneWithNotFoundDetection(centerId);
final Set<Group> groupMembers = assembleSetOfChildGroups(centerForUpdate.officeId(), command);
checkGroupMembersMeetingSyncWithCenterMeeting(centerId, groupMembers);
final Map<String, Object> actualChanges = new HashMap<>();
final List<String> changes = centerForUpdate.associateGroups(groupMembers);
if (!changes.isEmpty()) {
actualChanges.put(GroupingTypesApiConstants.groupMembersParamName, changes);
}
this.groupRepository.saveAndFlush(centerForUpdate);
return new CommandProcessingResultBuilder() //