cleaning up -MIFOSX-1877

This commit is contained in:
Vishwas Babu A J
2015-03-26 22:38:17 +05:30
parent 3b71c90773
commit cc010e5b37
8 changed files with 115 additions and 162 deletions
@@ -5,73 +5,63 @@
*/
package org.mifosplatform.integrationtests.common;
import java.util.HashMap;
import java.util.Random;
import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
public class WorkingDaysHelper {
private static final String WORKINGDAYS_URL = "/mifosng-provider/api/v1/workingdays";
private static final String CREATE_HOLIDAY_URL = WORKINGDAYS_URL + "?" + Utils.TENANT_IDENTIFIER;
private static final String WORKINGDAYS_URL = "/mifosng-provider/api/v1/workingdays";
public static Object updateWorkingDays(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
final String UPDATE_WORKINGDAYS_URL = WORKINGDAYS_URL +"/" +workingDaysId(requestSpec,responseSpec) + "?" + Utils.TENANT_IDENTIFIER;
final String UPDATE_WORKINGDAYS_URL = WORKINGDAYS_URL + "?" + Utils.TENANT_IDENTIFIER;
System.out.println("---------------------------------UPDATE WORKINGDAY---------------------------------------------");
return Utils.performServerPut(requestSpec, responseSpec,UPDATE_WORKINGDAYS_URL, updateWorkingDaysAsJson(), "");
return Utils.performServerPut(requestSpec, responseSpec, UPDATE_WORKINGDAYS_URL, updateWorkingDaysAsJson(), "");
}
public static Object updateWorkingDaysWithWrongRecurrence(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,String jsonAttributeToGetback){
final String UPDATE_WORKINGDAYS_URL = WORKINGDAYS_URL +"/" +workingDaysId(requestSpec,responseSpec) + "?" + Utils.TENANT_IDENTIFIER;
System.out.println("---------------------------------UPDATE WORKINGDAY WITH WRONG RECURRENCE-----------------------------------------");
return Utils.performServerPut(requestSpec, responseSpec,UPDATE_WORKINGDAYS_URL, updateWorkingDayWithWrongRecur(), jsonAttributeToGetback);
public static Object updateWorkingDaysWithWrongRecurrence(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, String jsonAttributeToGetback) {
final String UPDATE_WORKINGDAYS_URL = WORKINGDAYS_URL + "?" + Utils.TENANT_IDENTIFIER;
System.out
.println("---------------------------------UPDATE WORKINGDAY WITH WRONG RECURRENCE-----------------------------------------");
return Utils.performServerPut(requestSpec, responseSpec, UPDATE_WORKINGDAYS_URL, updateWorkingDayWithWrongRecur(),
jsonAttributeToGetback);
}
public static String updateWorkingDaysAsJson(){
public static String updateWorkingDaysAsJson() {
final HashMap<String, Object> map = new HashMap<>();
map.put("recurrence", "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH");
map.put("locale", "en");
map.put("repaymentRescheduleType", randomInt(1,4));
map.put("repaymentRescheduleType", randomInt(1, 4));
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public static String updateWorkingDayWithWrongRecur(){
public static String updateWorkingDayWithWrongRecur() {
final HashMap<String, Object> map = new HashMap<>();
map.put("recurrence", "FREQ=WEEKLY;INTERVAL=1;BYDAY=MP,TI,TE,TH");
map.put("locale", "en");
map.put("repaymentRescheduleType", randomInt(1,4));
map.put("repaymentRescheduleType", randomInt(1, 4));
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public static int randomInt(int low, int high){
public static int randomInt(int low, int high) {
int i = new Random().nextInt(high) + low;
return i;
}
public static int workingDaysId(final RequestSpecification requestSpec,final ResponseSpecification responseSpec){
List<HashMap<String, Object>> workingDaysId = getAllWorkingDays(requestSpec,responseSpec);
final HashMap<String, Object> workingDay = workingDaysId.get(0);
return (int) workingDay.get("id");
public static int workingDaysId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
HashMap<String, Object> workingDays = getAllWorkingDays(requestSpec, responseSpec);
return (int) workingDays.get("id");
}
public static HashMap<String, Object> getAllWorkingDays(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
public static ArrayList<HashMap<String, Object>> getAllWorkingDays(
final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
return Utils.performServerGet(requestSpec, responseSpec, WORKINGDAYS_URL + "?"
+ Utils.TENANT_IDENTIFIER, "");
return Utils.performServerGet(requestSpec, responseSpec, WORKINGDAYS_URL + "?" + Utils.TENANT_IDENTIFIER, "");
}
@@ -200,7 +200,7 @@ public class CommandWrapper {
public boolean isUpdate() {
// permissions resource has special update which involves no resource.
return isPermissionResource() && isUpdateOperation() || isCurrencyResource() && isUpdateOperation() || isCacheResource()
&& isUpdateOperation() || isUpdateOperation() && this.entityId != null;
&& isUpdateOperation() || isWorkingDaysResource() && isUpdateOperation() || isUpdateOperation() && this.entityId != null;
}
public boolean isUpdateOperation() {
@@ -258,7 +258,7 @@ public class CommandWrapper {
public boolean isAccountNumberFormatResource() {
return this.entityName.equals(AccountNumberFormatConstants.ENTITY_NAME.toUpperCase());
}
public boolean isApprove() {
return this.actionName.equalsIgnoreCase("APPROVE");
}
@@ -394,19 +394,19 @@ public class CommandWrapper {
public boolean isLoanResource() {
return this.entityName.equalsIgnoreCase("LOAN");
}
public boolean isTellerResource() {
return this.entityName.equalsIgnoreCase("TELLER");
}
public boolean isAllocateCashier() {
return this.actionName.equalsIgnoreCase("ALLOCATECASHIER");
}
public boolean isUpdateCashierAllocation() {
return this.actionName.equalsIgnoreCase("UPDATECASHIERALLOCATION");
}
public boolean isDeleteCashierAllocation() {
return this.actionName.equalsIgnoreCase("DELETECASHIERALLOCATION");
}
@@ -414,7 +414,7 @@ public class CommandWrapper {
public boolean isAllocateCashToCashier() {
return this.actionName.equalsIgnoreCase("ALLOCATECASHTOCASHIER");
}
public boolean isSettleCashFromCashier() {
return this.actionName.equalsIgnoreCase("SETTLECASHFROMCASHIER");
}
@@ -488,13 +488,15 @@ public class CommandWrapper {
}
public boolean isUpdateDisbursementDate() {
return this.actionName.equalsIgnoreCase("UPDATE") && this.entityName.equalsIgnoreCase("DISBURSEMENTDETAIL") && this.entityId != null;
return this.actionName.equalsIgnoreCase("UPDATE") && this.entityName.equalsIgnoreCase("DISBURSEMENTDETAIL")
&& this.entityId != null;
}
public boolean addAndDeleteDisbursementDetails() {
return this.actionName.equalsIgnoreCase("UPDATE") && this.entityName.equalsIgnoreCase("DISBURSEMENTDETAIL") && this.entityId == null;
return this.actionName.equalsIgnoreCase("UPDATE") && this.entityName.equalsIgnoreCase("DISBURSEMENTDETAIL")
&& this.entityId == null;
}
public boolean isStandingInstruction() {
return this.entityName.equalsIgnoreCase("STANDINGINSTRUCTION");
}
@@ -701,12 +703,11 @@ public class CommandWrapper {
public boolean isCollectionSheetResource() {
return this.entityName.equals("COLLECTIONSHEET");
}
public boolean isSaveIndividualCollectionSheet() {
return isCollectionSheetResource() && this.actionName.equalsIgnoreCase("SAVE");
}
public boolean isCenterResource() {
return this.entityName.equalsIgnoreCase("CENTER");
}
@@ -2353,11 +2353,11 @@ public class CommandWrapperBuilder {
this.href = "/entitytoentitymapping/" + mapId;
return this;
}
public CommandWrapperBuilder updateWorkingDays(final Long workingDaysId) {
public CommandWrapperBuilder updateWorkingDays() {
this.actionName = "UPDATE";
this.entityName = "WORKINGDAYS";
this.entityId = workingDaysId;
this.href = "/workingdays/" + workingDaysId;
this.href = "/workingdays/";
return this;
}
@@ -5,6 +5,15 @@
*/
package org.mifosplatform.organisation.workingdays.api;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.commands.service.CommandWrapperBuilder;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
@@ -19,27 +28,22 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import java.util.Collection;
@Path("/workingdays")
@Component
@Scope("singleton")
public class WorkingDaysApiResource {
private final DefaultToApiJsonSerializer<WorkingDaysData> toApiJsonSerializer;
private final WorkingDaysReadPlatformService workingDaysReadPlatformService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final PlatformSecurityContext context;
private final ApiRequestParameterHelper apiRequestParameterHelper;
@Autowired
public WorkingDaysApiResource(DefaultToApiJsonSerializer<WorkingDaysData> toApiJsonSerializer, WorkingDaysReadPlatformService workingDaysReadPlatformService, PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, PlatformSecurityContext context, ApiRequestParameterHelper apiRequestParameterHelper) {
public WorkingDaysApiResource(DefaultToApiJsonSerializer<WorkingDaysData> toApiJsonSerializer,
WorkingDaysReadPlatformService workingDaysReadPlatformService,
PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, PlatformSecurityContext context,
ApiRequestParameterHelper apiRequestParameterHelper) {
this.toApiJsonSerializer = toApiJsonSerializer;
this.workingDaysReadPlatformService = workingDaysReadPlatformService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
@@ -47,63 +51,41 @@ public class WorkingDaysApiResource {
this.apiRequestParameterHelper = apiRequestParameterHelper;
}
@GET
@Path("{workingdaysId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveOne(@PathParam("workingdaysId") final Long workingDaysId, @Context final UriInfo uriInfo){
this.context.authenticatedUser().validateHasReadPermission(WorkingDaysApiConstants.WORKING_DAYS_RESOURCE_NAME);
final WorkingDaysData workingDaysData = this.workingDaysReadPlatformService.retrieveOne(workingDaysId);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings,workingDaysData);
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveAll(@Context final UriInfo uriInfo){
public String retrieveAll(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(WorkingDaysApiConstants.WORKING_DAYS_RESOURCE_NAME);
final Collection<WorkingDaysData> workingDaysData = this.workingDaysReadPlatformService.retrieveAll();
final WorkingDaysData workingDaysData = this.workingDaysReadPlatformService.retrieve();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings,workingDaysData);
return this.toApiJsonSerializer.serialize(settings, workingDaysData);
}
@PUT
@Path("{workingdaysId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String update(@PathParam("workingdaysId") final Long workingDaysId,final String jsonRequestBody, @Context final UriInfo uriInfo){
this.context.authenticatedUser().validateHasReadPermission(WorkingDaysApiConstants.WORKING_DAYS_RESOURCE_NAME);
public String update(final String jsonRequestBody) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateWorkingDays(workingDaysId).withJson(jsonRequestBody).build();
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateWorkingDays().withJson(jsonRequestBody).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
@GET
@Path("/template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String template(@Context final UriInfo uriInfo){
public String template(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(WorkingDaysApiConstants.WORKING_DAYS_RESOURCE_NAME);
final WorkingDaysData repaymentRescheduleOptions = this.workingDaysReadPlatformService.repaymentRescheduleType();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings,repaymentRescheduleOptions,WorkingDaysApiConstants.WORKING_DAYS_TEMPLATE_PARAMETERS);
return this.toApiJsonSerializer.serialize(settings, repaymentRescheduleOptions,
WorkingDaysApiConstants.WORKING_DAYS_TEMPLATE_PARAMETERS);
}
}
@@ -16,7 +16,4 @@ public class WorkingDaysNotFoundException extends AbstractPlatformResourceNotFou
super("error.msg.working.days.not.configured", "Must configure the Working days for the organisation.");
}
public WorkingDaysNotFoundException(Long id){
super("error.msg.workingdays.id.invalid", "Working day with identifier " + id + " does not exist", id);
}
}
@@ -5,15 +5,11 @@
*/
package org.mifosplatform.organisation.workingdays.service;
import org.mifosplatform.organisation.workingdays.data.WorkingDaysData;
import java.util.Collection;
public interface WorkingDaysReadPlatformService {
Collection<WorkingDaysData> retrieveAll();
WorkingDaysData retrieveOne(Long id);
WorkingDaysData retrieve();
WorkingDaysData repaymentRescheduleType();
}
@@ -5,11 +5,14 @@
*/
package org.mifosplatform.organisation.workingdays.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.workingdays.data.WorkingDaysData;
import org.mifosplatform.organisation.workingdays.domain.RepaymentRescheduleType;
import org.mifosplatform.organisation.workingdays.domain.WorkingDaysEnumerations;
@@ -20,24 +23,16 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
@Service
public class WorkingDaysReadPlatformServiceImpl implements WorkingDaysReadPlatformService{
public class WorkingDaysReadPlatformServiceImpl implements WorkingDaysReadPlatformService {
private final PlatformSecurityContext context;
private final JdbcTemplate jdbcTemplate;
@Autowired
public WorkingDaysReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource) {
this.context = context;
public WorkingDaysReadPlatformServiceImpl(final RoutingDataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
private static final class WorkingDaysMapper implements RowMapper<WorkingDaysData> {
private final String schema;
@@ -49,48 +44,40 @@ public class WorkingDaysReadPlatformServiceImpl implements WorkingDaysReadPlatfo
this.schema = sqlBuilder.toString();
}
public String schema() {
return this.schema;
}
@Override
public WorkingDaysData mapRow(ResultSet rs, int rowNum) throws SQLException {
public WorkingDaysData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
final Long id = rs.getLong("id");
final String recurrence = rs.getString("recurrence");
final Integer statusEnum = JdbcSupport.getInteger(rs, "status_enum");
final EnumOptionData status = WorkingDaysEnumerations.workingDaysStatusType(statusEnum);
return new WorkingDaysData(id,recurrence,status);
return new WorkingDaysData(id, recurrence, status);
}
}
@Override
public Collection<WorkingDaysData> retrieveAll() {
final WorkingDaysMapper rm = new WorkingDaysMapper();
final String sql = " select " + rm.schema() ;
return this.jdbcTemplate.query(sql, rm, new Object[] {});
}
@Override
public WorkingDaysData retrieveOne(final Long id) {
public WorkingDaysData retrieve() {
try {
final WorkingDaysMapper rm = new WorkingDaysMapper();
final String sql = " select " + rm.schema() + " where w.id = ?";
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { id });
final WorkingDaysMapper rm = new WorkingDaysMapper();
final String sql = " select " + rm.schema();
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] {});
} catch (final EmptyResultDataAccessException e) {
throw new WorkingDaysNotFoundException(id);
throw new WorkingDaysNotFoundException();
}
}
@Override
public WorkingDaysData repaymentRescheduleType() {
Collection<EnumOptionData> repaymentRescheduleOptions = Arrays.asList(WorkingDaysEnumerations.repaymentRescheduleType(RepaymentRescheduleType.SAME_DAY),
Collection<EnumOptionData> repaymentRescheduleOptions = Arrays.asList(
WorkingDaysEnumerations.repaymentRescheduleType(RepaymentRescheduleType.SAME_DAY),
WorkingDaysEnumerations.repaymentRescheduleType(RepaymentRescheduleType.MOVE_TO_NEXT_WORKING_DAY),
WorkingDaysEnumerations.repaymentRescheduleType(RepaymentRescheduleType.MOVE_TO_NEXT_REPAYMENT_MEETING_DAY),
WorkingDaysEnumerations.repaymentRescheduleType(RepaymentRescheduleType.MOVE_TO_PREVIOUS_WORKING_DAY)
);
return new WorkingDaysData(null,null,null,repaymentRescheduleOptions);
WorkingDaysEnumerations.repaymentRescheduleType(RepaymentRescheduleType.MOVE_TO_PREVIOUS_WORKING_DAY));
return new WorkingDaysData(null, null, null, repaymentRescheduleOptions);
}
}
@@ -1,36 +1,36 @@
INSERT INTO `m_permission` (
`grouping` ,
`code` ,
`entity_name` ,
`action_name` ,
`can_maker_checker`
)
VALUES (
'organisation', 'READ_WORKINGDAYS', 'WORKINGDAYS', 'READ', '0'
);
INSERT INTO `m_permission` (
`grouping` ,
`code` ,
`entity_name` ,
`action_name` ,
`can_maker_checker`
)
VALUES (
'organisation', 'UPDATE_WORKINGDAYS', 'WORKINGDAYS', 'UPDATE', '0'
);
INSERT INTO `m_permission` (
`grouping` ,
`code` ,
`entity_name` ,
`action_name` ,
`can_maker_checker`
)
VALUES (
'organisation', 'UPDATE_WORKINGDAYS_CHECKER', 'WORKINGDAYS', 'UPDATE_CHECKER', '0'
);
INSERT INTO `m_permission` (
`grouping` ,
`code` ,
`entity_name` ,
`action_name` ,
`can_maker_checker`
)
VALUES (
'organisation', 'READ_WORKINGDAYS', 'WORKINGDAYS', 'READ', '0'
);
INSERT INTO `m_permission` (
`grouping` ,
`code` ,
`entity_name` ,
`action_name` ,
`can_maker_checker`
)
VALUES (
'organisation', 'UPDATE_WORKINGDAYS', 'WORKINGDAYS', 'UPDATE', '0'
);
INSERT INTO `m_permission` (
`grouping` ,
`code` ,
`entity_name` ,
`action_name` ,
`can_maker_checker`
)
VALUES (
'organisation', 'UPDATE_WORKINGDAYS_CHECKER', 'WORKINGDAYS', 'UPDATE_CHECKER', '0'
);