diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeTransactionsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeTransactionsApiResource.java index 056fba6fd..eddab3696 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeTransactionsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeTransactionsApiResource.java @@ -4,19 +4,25 @@ import java.math.BigDecimal; import java.util.Locale; import javax.ws.rs.Consumes; +import javax.ws.rs.GET; import javax.ws.rs.POST; 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.Response; +import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; import org.mifosng.platform.api.commands.BranchMoneyTransferCommand; import org.mifosng.platform.api.data.EntityIdentifier; +import org.mifosng.platform.api.data.OfficeTransactionData; import org.mifosng.platform.api.infrastructure.ApiDataConversionService; +import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService; import org.mifosng.platform.exceptions.UnrecognizedQueryParamException; +import org.mifosng.platform.organisation.service.OfficeReadPlatformService; import org.mifosng.platform.organisation.service.OfficeWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -29,10 +35,35 @@ public class OfficeTransactionsApiResource { @Autowired private OfficeWritePlatformService writePlatformService; + + @Autowired + private OfficeReadPlatformService readPlatformService; @Autowired private ApiDataConversionService apiDataConversionService; + @Autowired + private ApiJSONFormattingService jsonFormattingService; + + @GET + @Path("template") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String newOfficeTransactionDetails(@Context UriInfo uriInfo) { + + OfficeTransactionData officeTransactionData = this.readPlatformService + .retrieveNewOfficeTransactionDetails(); + + String filterName = "myFilter"; + String defaultFieldList = "transactionDate"; + String allowedFieldList = "currencyOptions,allowedOffices"; + String selectedFields = defaultFieldList + "," + allowedFieldList; + return this.jsonFormattingService.convertRequest(officeTransactionData, + filterName, allowedFieldList, selectedFields, + uriInfo.getQueryParameters()); + } + + @POST @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeTransactionData.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeTransactionData.java new file mode 100644 index 000000000..f963f3ed1 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/data/OfficeTransactionData.java @@ -0,0 +1,49 @@ +package org.mifosng.platform.api.data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import org.codehaus.jackson.map.annotate.JsonFilter; +import org.joda.time.LocalDate; + +@JsonFilter("myFilter") +public class OfficeTransactionData implements Serializable { + + private LocalDate transactionDate; + private List currencyOptions = new ArrayList(); + private List allowedOffices = new ArrayList(); + + public OfficeTransactionData() { + // + } + + public OfficeTransactionData(final LocalDate transactionDate) { + this.transactionDate = transactionDate; + } + + public LocalDate getTransactionDate() { + return transactionDate; + } + + public void setTransactionDate(LocalDate transactionDate) { + this.transactionDate = transactionDate; + } + + public List getCurrencyOptions() { + return currencyOptions; + } + + public void setCurrencyOptions(List currencyOptions) { + this.currencyOptions = currencyOptions; + } + + public List getAllowedOffices() { + return allowedOffices; + } + + public void setAllowedOffices(List allowedOffices) { + this.allowedOffices = allowedOffices; + } + +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformService.java index d50d42ae4..f632df177 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformService.java @@ -5,6 +5,7 @@ import java.util.List; import org.mifosng.platform.api.data.OfficeData; import org.mifosng.platform.api.data.OfficeLookup; +import org.mifosng.platform.api.data.OfficeTransactionData; public interface OfficeReadPlatformService { @@ -17,4 +18,6 @@ public interface OfficeReadPlatformService { OfficeData retrieveNewOfficeTemplate(); List retrieveAllowedParents(Long officeId); + + OfficeTransactionData retrieveNewOfficeTransactionDetails(); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java index 8beb0810a..6de439d96 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java @@ -7,8 +7,11 @@ import java.util.Collection; import java.util.List; import org.joda.time.LocalDate; +import org.mifosng.platform.api.data.CurrencyData; import org.mifosng.platform.api.data.OfficeData; import org.mifosng.platform.api.data.OfficeLookup; +import org.mifosng.platform.api.data.OfficeTransactionData; +import org.mifosng.platform.currency.service.CurrencyReadPlatformService; import org.mifosng.platform.exceptions.OfficeNotFoundException; import org.mifosng.platform.infrastructure.JdbcSupport; import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource; @@ -25,11 +28,15 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService private final JdbcTemplate jdbcTemplate; private final PlatformSecurityContext context; + private final CurrencyReadPlatformService currencyReadPlatformService; private final static String nameDecoratedBaseOnHierarchy = "concat(substring('........................................', 1, ((LENGTH(o.hierarchy) - LENGTH(REPLACE(o.hierarchy, '.', '')) - 1) * 4)), o.name)"; @Autowired - public OfficeReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource) { + public OfficeReadPlatformServiceImpl(final PlatformSecurityContext context, + final CurrencyReadPlatformService currencyReadPlatformService, + final TenantAwareRoutingDataSource dataSource) { this.context = context; + this.currencyReadPlatformService = currencyReadPlatformService; this.jdbcTemplate = new JdbcTemplate(dataSource); } @@ -89,11 +96,11 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService String hierarchySearchString = hierarchy + "%"; OfficeMapper rm = new OfficeMapper(); - String sql = "select " - + rm.officeSchema() + String sql = "select " + rm.officeSchema() + "where o.hierarchy like ? order by o.hierarchy"; - return this.jdbcTemplate.query(sql, rm, new Object[] {hierarchySearchString}); + return this.jdbcTemplate.query(sql, rm, + new Object[] { hierarchySearchString }); } @Override @@ -104,11 +111,11 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService String hierarchySearchString = hierarchy + "%"; OfficeLookupMapper rm = new OfficeLookupMapper(); - String sql = "select " - + rm.officeLookupSchema() + String sql = "select " + rm.officeLookupSchema() + "where o.hierarchy like ? order by o.hierarchy"; - return this.jdbcTemplate.query(sql, rm, new Object[] {hierarchySearchString}); + return this.jdbcTemplate.query(sql, rm, + new Object[] { hierarchySearchString }); } @Override @@ -120,7 +127,8 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService OfficeMapper rm = new OfficeMapper(); String sql = "select " + rm.officeSchema() + " where o.id = ?"; - OfficeData selectedOffice = this.jdbcTemplate.queryForObject(sql, rm, new Object[] {officeId}); + OfficeData selectedOffice = this.jdbcTemplate.queryForObject(sql, + rm, new Object[] { officeId }); return selectedOffice; } catch (EmptyResultDataAccessException e) { @@ -162,4 +170,21 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService return filterParentLookups; } + + @Override + public OfficeTransactionData retrieveNewOfficeTransactionDetails() { + context.authenticatedUser(); + + List parentLookups = new ArrayList( + retrieveAllOfficesForLookup()); + List currencyOptions = currencyReadPlatformService + .retrieveAllowedCurrencies(); + + OfficeTransactionData officeTransactionData = new OfficeTransactionData( + new LocalDate()); + officeTransactionData.setAllowedOffices(parentLookups); + officeTransactionData.setCurrencyOptions(currencyOptions); + + return officeTransactionData; + } } \ No newline at end of file