add officetransactions/template resource
This commit is contained in:
+31
@@ -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})
|
||||
|
||||
+49
@@ -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<CurrencyData> currencyOptions = new ArrayList<CurrencyData>();
|
||||
private List<OfficeLookup> allowedOffices = new ArrayList<OfficeLookup>();
|
||||
|
||||
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<CurrencyData> getCurrencyOptions() {
|
||||
return currencyOptions;
|
||||
}
|
||||
|
||||
public void setCurrencyOptions(List<CurrencyData> currencyOptions) {
|
||||
this.currencyOptions = currencyOptions;
|
||||
}
|
||||
|
||||
public List<OfficeLookup> getAllowedOffices() {
|
||||
return allowedOffices;
|
||||
}
|
||||
|
||||
public void setAllowedOffices(List<OfficeLookup> allowedOffices) {
|
||||
this.allowedOffices = allowedOffices;
|
||||
}
|
||||
|
||||
}
|
||||
+3
@@ -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<OfficeLookup> retrieveAllowedParents(Long officeId);
|
||||
|
||||
OfficeTransactionData retrieveNewOfficeTransactionDetails();
|
||||
}
|
||||
+33
-8
@@ -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<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(
|
||||
retrieveAllOfficesForLookup());
|
||||
List<CurrencyData> currencyOptions = currencyReadPlatformService
|
||||
.retrieveAllowedCurrencies();
|
||||
|
||||
OfficeTransactionData officeTransactionData = new OfficeTransactionData(
|
||||
new LocalDate());
|
||||
officeTransactionData.setAllowedOffices(parentLookups);
|
||||
officeTransactionData.setCurrencyOptions(currencyOptions);
|
||||
|
||||
return officeTransactionData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user