/** * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.mifosplatform.portfolio.account.api; import java.util.Date; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import org.mifosplatform.accounting.journalentry.api.DateParam; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.core.service.Page; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.portfolio.account.data.StandingInstructionDTO; import org.mifosplatform.portfolio.account.data.StandingInstructionHistoryData; import org.mifosplatform.portfolio.account.service.StandingInstructionHistoryReadPlatformService; import org.mifosplatform.infrastructure.core.service.SearchParameters; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; @Path("/standinginstructionrunhistory") @Component @Scope("singleton") public class StandingInstructionHistoryApiResource { private final PlatformSecurityContext context; private final DefaultToApiJsonSerializer<StandingInstructionHistoryData> toApiJsonSerializer; private final ApiRequestParameterHelper apiRequestParameterHelper; private final StandingInstructionHistoryReadPlatformService standingInstructionHistoryReadPlatformService; @Autowired public StandingInstructionHistoryApiResource(final PlatformSecurityContext context, final ApiRequestParameterHelper apiRequestParameterHelper, final StandingInstructionHistoryReadPlatformService standingInstructionHistoryReadPlatformService, final DefaultToApiJsonSerializer<StandingInstructionHistoryData> toApiJsonSerializer) { this.context = context; this.toApiJsonSerializer = toApiJsonSerializer; this.apiRequestParameterHelper = apiRequestParameterHelper; this.standingInstructionHistoryReadPlatformService = standingInstructionHistoryReadPlatformService; } @GET @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String retrieveAll(@Context final UriInfo uriInfo, @QueryParam("sqlSearch") final String sqlSearch, @QueryParam("externalId") final String externalId, @QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit, @QueryParam("orderBy") final String orderBy, @QueryParam("sortOrder") final String sortOrder, @QueryParam("transferType") final Integer transferType, @QueryParam("clientName") final String clientName, @QueryParam("clientId") final Long clientId, @QueryParam("fromAccountId") final Long fromAccount, @QueryParam("fromAccountType") final Integer fromAccountType, @QueryParam("locale") final String locale, @QueryParam("dateFormat") final String dateFormat, @QueryParam("fromDate") final DateParam fromDateParam, @QueryParam("toDate") final DateParam toDateParam) { this.context.authenticatedUser().validateHasReadPermission(StandingInstructionApiConstants.STANDING_INSTRUCTION_RESOURCE_NAME); final SearchParameters searchParameters = SearchParameters.forAccountTransfer(sqlSearch, externalId, offset, limit, orderBy, sortOrder); Date startDateRange = null; Date endDateRange = null; if (fromDateParam != null) { startDateRange = fromDateParam.getDate("fromDate", dateFormat, locale); } if (toDateParam != null) { endDateRange = toDateParam.getDate("toDate", dateFormat, locale); } StandingInstructionDTO standingInstructionDTO = new StandingInstructionDTO(searchParameters, transferType, clientName, clientId, fromAccount, fromAccountType, startDateRange, endDateRange); final Page<StandingInstructionHistoryData> history = this.standingInstructionHistoryReadPlatformService .retrieveAll(standingInstructionDTO); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); return this.toApiJsonSerializer.serialize(settings, history); } }