@QueryParam("roleId") final Long roleId) {
this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.GROUP_RESOURCE_NAME);
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
GroupGeneralData group = this.groupReadPlatformService.retrieveOne(groupId);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
// associations
Collection<ClientData> membersOfGroup = null;
Collection<GroupRoleData> groupRoles = null;
GroupRoleData selectedRole = null;
Collection<CalendarData> calendars = null;
CalendarData collectionMeetingCalendar = null;
if (!associationParameters.isEmpty()) {
if (associationParameters.contains("all")) {
associationParameters.addAll(Arrays.asList("clientMembers", "groupRoles", "calendars", "collectionMeetingCalendar"));
}
if (associationParameters.contains("clientMembers")) {
membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId);
if (CollectionUtils.isEmpty(membersOfGroup)) {
membersOfGroup = null;
}
}
if (associationParameters.contains("groupRoles")) {
groupRoles = this.groupRolesReadPlatformService.retrieveGroupRoles(groupId);
if (CollectionUtils.isEmpty(groupRoles)) {
groupRoles = null;
}
}
if (associationParameters.contains("parentCalendars")) {
final List<Integer> calendarTypeOptions = CalendarUtils.createIntegerListFromQueryParameter("all");
calendars = this.calendarReadPlatformService.retrieveParentCalendarsByEntity(groupId, CalendarEntityType.GROUPS.getValue(),
calendarTypeOptions);
if (CollectionUtils.isEmpty(calendars)) {
calendars = null;
}
}
if (associationParameters.contains("collectionMeetingCalendar")) {
if (group.isChildGroup()) {
collectionMeetingCalendar = this.calendarReadPlatformService.retrieveCollctionCalendarByEntity(group.getParentId(),
CalendarEntityType.CENTERS.getValue());
} else {
collectionMeetingCalendar = this.calendarReadPlatformService.retrieveCollctionCalendarByEntity(groupId,
CalendarEntityType.GROUPS.getValue());
}
if (collectionMeetingCalendar != null) {
final boolean withHistory = true;
final LocalDate tillDate = null;
final Collection<LocalDate> recurringDates = this.calendarReadPlatformService.generateRecurringDates(
collectionMeetingCalendar, withHistory, tillDate);
final Collection<LocalDate> nextTenRecurringDates = this.calendarReadPlatformService
.generateNextTenRecurringDates(collectionMeetingCalendar);
final MeetingData lastMeeting = this.meetingReadPlatformService.retrieveLastMeeting(collectionMeetingCalendar
.getCalendarInstanceId());
final LocalDate recentEligibleMeetingDate = this.calendarReadPlatformService
.generateNextEligibleMeetingDateForCollection(collectionMeetingCalendar, lastMeeting);
collectionMeetingCalendar = CalendarData.withRecurringDates(collectionMeetingCalendar, recurringDates,
nextTenRecurringDates, recentEligibleMeetingDate);
}
}
group = GroupGeneralData.withAssocations(group, membersOfGroup, groupRoles, calendars, collectionMeetingCalendar);
}
if (roleId != null) {
selectedRole = this.groupRolesReadPlatformService.retrieveGroupRole(groupId, roleId);
if (selectedRole != null) {
group = GroupGeneralData.updateSelectedRole(group, selectedRole);
}
}
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
if (template) {
final GroupGeneralData templateGroup = this.groupReadPlatformService.retrieveTemplate(group.officeId(), false,
staffInSelectedOfficeOnly);
group = GroupGeneralData.withTemplate(templateGroup, group);
}
return this.groupGeneralApiJsonSerializer.serialize(settings, group, GroupingTypesApiConstants.GROUP_RESPONSE_DATA_PARAMETERS);