Skip to content

Commit

Permalink
#559 | Handle issue with GroupDashboards import for DefaultGroups "Ev…
Browse files Browse the repository at this point in the history
…eryone"/"Administrators"
  • Loading branch information
himeshr committed Mar 21, 2024
1 parent 9ee6dbe commit 9ef0082
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -51,12 +52,22 @@ public List<GroupDashboard> save(List<GroupDashboardContract> request) throws Va
public void saveFromBundle(List<GroupDashboardBundleContract> request) {
List<GroupDashboard> groupDashboards = new ArrayList<>();
for (GroupDashboardBundleContract contract : request) {
Long organisationId = UserContextHolder.getUserContext().getOrganisationId();
GroupDashboard groupDashboard = EntityHelper.newOrExistingEntity(groupDashboardRepository, contract.getUuid(), null, new GroupDashboard());
Group group = groupRepository.findByUuid(contract.getGroupUUID());
Group group = null;
if(contract.isGroupOneOfTheDefaultGroups() && !StringUtils.isEmpty(contract.getGroupName())) {
group = groupRepository.findByNameAndOrganisationId(contract.getGroupName(), organisationId);
} else {
group = groupRepository.findByUuid(contract.getGroupUUID());
}
if(group == null) {
throw new RuntimeException("Unable to process import of Group Dashboards, due to missing mandatory details."
+ "\nPlease download a newer version of the bundle from the source organisation and try uploading again.");
}
Dashboard dashboard = dashboardRepository.findByUuid(contract.getDashboardUUID());
groupDashboard.setDashboard(dashboard);
groupDashboard.setGroup(group);
groupDashboard.setOrganisationId(UserContextHolder.getUserContext().getOrganisationId());
groupDashboard.setOrganisationId(organisationId);
groupDashboards.add(groupDashboard);
}
groupDashboardRepository.saveAll(groupDashboards);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class GroupDashboardBundleContract extends BaseBundleContract {
private boolean isSecondaryDashboard;
private String dashboardUUID;
private String groupUUID;
private String groupName;
private boolean isGroupOneOfTheDefaultGroups;
private String dashboardName;
private String dashboardDescription;

Expand All @@ -17,6 +19,8 @@ public static GroupDashboardBundleContract fromEntity(GroupDashboard groupDashbo
contract.isPrimaryDashboard = groupDashboard.isPrimaryDashboard();
contract.isSecondaryDashboard = groupDashboard.isSecondaryDashboard();
contract.groupUUID = groupDashboard.getGroup().getUuid();
contract.groupName = groupDashboard.getGroup().getName();
contract.isGroupOneOfTheDefaultGroups = groupDashboard.getGroup().isOneOfTheDefaultGroups();
contract.dashboardUUID = groupDashboard.getDashboard().getUuid();
contract.dashboardName = groupDashboard.getDashboard().getName();
contract.dashboardDescription = groupDashboard.getDashboard().getDescription();
Expand Down Expand Up @@ -70,4 +74,20 @@ public String getDashboardDescription() {
public void setDashboardDescription(String dashboardDescription) {
this.dashboardDescription = dashboardDescription;
}

public String getGroupName() {
return groupName;
}

public void setGroupName(String groupName) {
this.groupName = groupName;
}

public boolean isGroupOneOfTheDefaultGroups() {
return isGroupOneOfTheDefaultGroups;
}

public void setGroupIsOneOfTheDefaultGroups(boolean oneOfTheDefaultGroups) {
isGroupOneOfTheDefaultGroups = oneOfTheDefaultGroups;
}
}

0 comments on commit 9ef0082

Please sign in to comment.