コード例 #1
0
ファイル: GroupsApiResource.java プロジェクト: Bredun/mifosx
  @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);
  }
コード例 #2
0
ファイル: GroupsApiResource.java プロジェクト: Bredun/mifosx
  @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);
  }