コード例 #1
0
  @GET
  @Path("{productId}")
  @Consumes({MediaType.APPLICATION_JSON})
  @Produces({MediaType.APPLICATION_JSON})
  public String retrieveSavingProductDetails(
      @PathParam("productId") final Long productId, @Context final UriInfo uriInfo) {

    context.authenticatedUser().validateHasReadPermission(entityType);

    Set<String> typicalResponseParameters =
        new HashSet<String>(
            Arrays.asList(
                "id",
                "createdOn",
                "lastModifedOn",
                "locale",
                "name",
                "description",
                "currencyCode",
                "digitsAfterDecimal",
                "interstRate",
                "minInterestRate",
                "maxInterestRate",
                "savingsDepositAmount",
                "savingProductType",
                "tenureType",
                "tenure",
                "frequency",
                "interestType",
                "interestCalculationMethod",
                "minimumBalanceForWithdrawal",
                "isPartialDepositAllowed",
                "isLockinPeriodAllowed",
                "lockinPeriod",
                "lockinPeriodType",
                "depositEvery"));

    Set<String> responseParameters =
        ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
    if (responseParameters.isEmpty()) {
      responseParameters.addAll(typicalResponseParameters);
    }

    SavingProductData savingProduct =
        this.savingProductReadPlatformService.retrieveSavingProduct(productId);

    boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
    boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
    if (template) {
      savingProduct = handleTemplateRelatedData(responseParameters, savingProduct);
    }

    return this.apiJsonSerializerService.serializeSavingProductDataToJson(
        prettyPrint, responseParameters, savingProduct);
  }
コード例 #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);
  }