@GET @Path("{groupId}/clientstransfertemplate") @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) public String retrieveClientTranferTemplate( @Context final UriInfo uriInfo, @PathParam("groupId") final Long groupId, @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly) { this.context.authenticatedUser().validateHasReadPermission("GROUP"); GroupGeneralData group = this.groupReadPlatformService.retrieveOne(groupId); final boolean transferActiveLoans = true; final boolean inheritDestinationGroupLoanOfficer = true; Collection<ClientData> membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId); if (CollectionUtils.isEmpty(membersOfGroup)) { membersOfGroup = null; } final boolean loanOfficersOnly = false; Collection<StaffData> staffOptions = null; if (staffInSelectedOfficeOnly) { staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(group.officeId()); } else { staffOptions = this.staffReadPlatformService.retrieveAllStaffInOfficeAndItsParentOfficeHierarchy( group.officeId(), loanOfficersOnly); } if (CollectionUtils.isEmpty(staffOptions)) { staffOptions = null; } Collection<GroupGeneralData> groupOptions = this.groupReadPlatformService.retrieveGroupsForLookup(group.officeId(), groupId); GroupTransferData data = GroupTransferData.template( groupId, membersOfGroup, groupOptions, staffOptions, transferActiveLoans, inheritDestinationGroupLoanOfficer); final Set<String> GROUP_TRANSFERS_DATA_PARAMETERS = new HashSet<String>( Arrays.asList( "groupId", "clientOptions", "groupOptions", "staffOptions", "transferActiveLoans", "inheritDestinationGroupLoanOfficer")); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.toApiJsonSerializer.serialize(settings, data, GROUP_TRANSFERS_DATA_PARAMETERS); }
@Override public GroupGeneralData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { final Long id = JdbcSupport.getLong(rs, "id"); final String displayName = rs.getString("displayName"); return GroupGeneralData.lookup(id, displayName); }
@Override public GroupGeneralData retrieveTemplate( final Long officeId, final boolean isCenterGroup, final boolean staffInSelectedOfficeOnly) { final Long defaultOfficeId = defaultToUsersOfficeIfNull(officeId); Collection<CenterData> centerOptions = null; if (isCenterGroup) { centerOptions = this.centerReadPlatformService.retrieveAllForDropdown(defaultOfficeId); } final Collection<OfficeData> officeOptions = this.officeReadPlatformService.retrieveAllOfficesForDropdown(); final boolean loanOfficersOnly = false; Collection<StaffData> staffOptions = null; if (staffInSelectedOfficeOnly) { staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(defaultOfficeId); } else { staffOptions = this.staffReadPlatformService.retrieveAllStaffInOfficeAndItsParentOfficeHierarchy( defaultOfficeId, loanOfficersOnly); } if (CollectionUtils.isEmpty(staffOptions)) { staffOptions = null; } Collection<ClientData> clientOptions = this.clientReadPlatformService.retrieveAllForLookupByOfficeId(defaultOfficeId); if (CollectionUtils.isEmpty(clientOptions)) { clientOptions = null; } final Collection<CodeValueData> availableRoles = this.codeValueReadPlatformService.retrieveCodeValuesByCode( GroupingTypesApiConstants.GROUP_ROLE_NAME); final Long centerId = null; final String centerName = null; final Long staffId = null; final String staffName = null; return GroupGeneralData.template( defaultOfficeId, centerId, centerName, staffId, staffName, centerOptions, officeOptions, staffOptions, clientOptions, availableRoles); }
@GET @Path("{groupId}") @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) public String retrieveOne( @Context final UriInfo uriInfo, @PathParam("groupId") final Long groupId, @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly, @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); // 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("calendars")) { 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")) { collectionMeetingCalendar = this.calendarReadPlatformService.retrieveCollctionCalendarByEntity( groupId, CalendarEntityType.GROUPS.getValue()); } 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); } final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.groupGeneralApiJsonSerializer.serialize( settings, group, GroupingTypesApiConstants.GROUP_RESPONSE_DATA_PARAMETERS); }
@Override public JLGCollectionSheetData generateGroupCollectionSheet( final Long groupId, final JsonQuery query) { this.collectionSheetGenerateCommandFromApiJsonDeserializer.validateForGenerateCollectionSheet( query.json()); final Long calendarId = query.longValueOfParameterNamed(calendarIdParamName); final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName); final DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); final String transactionDateStr = df.format(transactionDate.toDate()); final Calendar calendar = this.calendarRepositoryWrapper.findOneWithNotFoundDetection(calendarId); // check if transaction against calendar effective from date if (!calendar.isValidRecurringDate(transactionDate)) { throw new NotValidRecurringDateException( "collectionsheet", "The date '" + transactionDate + "' is not a valid meeting date.", transactionDate); } final AppUser currentUser = this.context.authenticatedUser(); final String hierarchy = currentUser.getOffice().getHierarchy(); final String officeHierarchy = hierarchy + "%"; final GroupGeneralData group = this.groupReadPlatformService.retrieveOne(groupId); final JLGCollectionSheetFaltDataMapper mapper = new JLGCollectionSheetFaltDataMapper(); // entityType should be center if it's within a center final CalendarEntityType entityType = (group.isChildGroup()) ? CalendarEntityType.CENTERS : CalendarEntityType.GROUPS; final SqlParameterSource namedParameters = new MapSqlParameterSource() .addValue("dueDate", transactionDateStr) .addValue("groupId", group.getId()) .addValue("officeHierarchy", officeHierarchy) .addValue("entityTypeId", entityType.getValue()); final Collection<JLGCollectionSheetFlatData> collectionSheetFlatDatas = this.namedParameterjdbcTemplate.query( mapper.collectionSheetSchema(false), namedParameters, mapper); // loan data for collection sheet JLGCollectionSheetData collectionSheetData = buildJLGCollectionSheet(transactionDate, collectionSheetFlatDatas); // mandatory savings data for collection sheet Collection<JLGGroupData> groupsWithSavingsData = this.namedParameterjdbcTemplate.query( mandatorySavingsExtractor.collectionSheetSchema(false), namedParameters, mandatorySavingsExtractor); // merge savings data into loan data mergeSavingsGroupDataIntoCollectionsheetData(groupsWithSavingsData, collectionSheetData); collectionSheetData = JLGCollectionSheetData.withSavingsProducts( collectionSheetData, retrieveSavingsProducts(groupsWithSavingsData)); return collectionSheetData; }