Merge pull request #1297 from chandrikamohith/1808
MIFOSX-1808 Group hierarchy updation issue corrected.Center summary is n...
This commit is contained in:
+21
-10
@@ -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) {
|
||||||
@@ -375,7 +383,7 @@ public final class Group extends AbstractPersistable<Long> {
|
|||||||
}
|
}
|
||||||
return staffId;
|
return staffId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addChild(final Group group) {
|
private void addChild(final Group group) {
|
||||||
this.groupMembers.add(group);
|
this.groupMembers.add(group);
|
||||||
}
|
}
|
||||||
@@ -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());
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-7
@@ -131,7 +131,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
parentGroup = this.groupRepository.findOneWithNotFoundDetection(centerId);
|
parentGroup = this.groupRepository.findOneWithNotFoundDetection(centerId);
|
||||||
officeId = parentGroup.officeId();
|
officeId = parentGroup.officeId();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Office groupOffice = this.officeRepository.findOne(officeId);
|
final Office groupOffice = this.officeRepository.findOne(officeId);
|
||||||
if (groupOffice == null) { throw new OfficeNotFoundException(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
|
// 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);
|
||||||
@@ -414,7 +415,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
groupForUpdate.unassignStaff();
|
groupForUpdate.unassignStaff();
|
||||||
}
|
}
|
||||||
this.groupRepository.saveAndFlush(groupForUpdate);
|
this.groupRepository.saveAndFlush(groupForUpdate);
|
||||||
|
|
||||||
actualChanges.put(staffIdParamName, null);
|
actualChanges.put(staffIdParamName, null);
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
@@ -756,17 +757,17 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.groupRepository.saveAndFlush(centerForUpdate);
|
this.groupRepository.saveAndFlush(centerForUpdate);
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder() //
|
return new CommandProcessingResultBuilder() //
|
||||||
|
|||||||
Reference in New Issue
Block a user