diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/api/CalendarsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/api/CalendarsApiResource.java index d9fa91303..d7a80ef7e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/api/CalendarsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/api/CalendarsApiResource.java @@ -18,9 +18,7 @@ import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext import org.mifosplatform.portfolio.calendar.data.CalendarData; import org.mifosplatform.portfolio.calendar.domain.Calendar; import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType; -import org.mifosplatform.portfolio.calendar.domain.CalendarType; import org.mifosplatform.portfolio.calendar.service.CalendarDropdownReadPlatformService; -import org.mifosplatform.portfolio.calendar.service.CalendarEnumerations; import org.mifosplatform.portfolio.calendar.service.CalendarReadPlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -87,6 +85,14 @@ public class CalendarsApiResource { return this.toApiJsonSerializer.serialize(settings, calendarData, this.RESPONSE_DATA_PARAMETERS); } + + /** + * @param entityType + * @param entityId + * @param uriInfo + * @param calendarType + * @return + */ @GET @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @@ -99,7 +105,7 @@ public class CalendarsApiResource { Collection calendarsData = new ArrayList(); - List calendarTypeOptions = createEnumOptionDataListFromQueryParameter(calendarType); + List calendarTypeOptions = createIntegerListFromQueryParameter(calendarType); if (!associationParameters.isEmpty()) { @@ -186,10 +192,14 @@ public class CalendarsApiResource { } - public List createEnumOptionDataListFromQueryParameter(String calendarTypeQuery) { - List calendarTypeOptions = new ArrayList(); - // adding all calendar Types if + public List createIntegerListFromQueryParameter(String calendarTypeQuery) { + List calendarTypeOptions = new ArrayList(); + // adding all calendar Types if query parameter is "all" if(calendarTypeQuery.equalsIgnoreCase("all")){ + calendarTypeOptions.add(1); + calendarTypeOptions.add(2); + calendarTypeOptions.add(3); + calendarTypeOptions.add(4); return calendarTypeOptions; } // creating a list of calendar type options from the comma separated query parameter. @@ -201,13 +211,13 @@ public class CalendarsApiResource { for(String calType : calendarTypeOptionsInQuery){ if(calType.equalsIgnoreCase("collection")) { - calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.COLLECTION)); + calendarTypeOptions.add(1); } else if(calType.equalsIgnoreCase("training")) { - calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.TRAINING)); + calendarTypeOptions.add(2); } else if(calType.equalsIgnoreCase("audit")) { - calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.AUDIT)); + calendarTypeOptions.add(3); } else if(calType.equalsIgnoreCase("general")) { - calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.GENERAL)); + calendarTypeOptions.add(4); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformService.java index 3a70381a3..81b02a433 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformService.java @@ -5,7 +5,6 @@ */ package org.mifosplatform.portfolio.calendar.service; -import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.portfolio.calendar.data.CalendarData; import java.util.Collection; @@ -15,9 +14,9 @@ public interface CalendarReadPlatformService { CalendarData retrieveCalendar(final Long calendarId, Long entityId, Integer entityTypeId); - Collection retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, List calendarTypeOptions); + Collection retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, List calendarTypeOptions); - Collection retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId, List calendarTypeOptions); + Collection retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId, List calendarTypeOptions); Collection retrieveAllCalendars(); @@ -28,4 +27,5 @@ public interface CalendarReadPlatformService { Collection generateRecurringDates(final Collection calendarsData); CalendarData retrieveLoanCalendar(final Long loanId); + } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java index 5591c5bd3..c62a8a470 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarReadPlatformServiceImpl.java @@ -99,7 +99,7 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ } @Override - public Collection retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, List calendarTypeOptions) { + public Collection retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, List calendarTypeOptions) { final CalendarDataMapper rm = new CalendarDataMapper(); // the collection result will store the final result Collection result=null; @@ -110,15 +110,15 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? order by c.start_date "; result = this.jdbcTemplate.query(sql, rm, new Object[] { entityId, entityTypeId }); } else if(!calendarTypeOptions.isEmpty()){ - String sqlCalendarTypeOptions = createSqlValuesInString(calendarTypeOptions); - sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? and c.calendar_type_enum in (?) order by c.start_date "; - result = this.jdbcTemplate.query(sql,rm, new Object[] {entityId, entityTypeId, sqlCalendarTypeOptions}); + String sqlCalendarTypeOptions = getSqlCalendarTypeOptionsInString(calendarTypeOptions); + sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? and c.calendar_type_enum in ( "+ sqlCalendarTypeOptions + " ) order by c.start_date "; + result = this.jdbcTemplate.query(sql, rm, new Object[]{entityId, entityTypeId}); } return result; } @Override - public Collection retrieveParentCalendarsByEntity( Long entityId, Integer entityTypeId, List calendarTypeOptions ) { + public Collection retrieveParentCalendarsByEntity( Long entityId, Integer entityTypeId, List calendarTypeOptions ) { final CalendarDataMapper rm = new CalendarDataMapper(); Collection result=null; @@ -131,9 +131,9 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ sql = rm.schema() + " " + parentHeirarchyCondition + " and ci.entity_type_enum = ? order by c.start_date "; result = this.jdbcTemplate.query(sql, rm, new Object[] { entityId, CalendarEntityType.CENTERS.getValue() }); } else { - String sqlCalendarTypeOptions = createSqlValuesInString(calendarTypeOptions); - sql = rm.schema() + " " + parentHeirarchyCondition + " and ci.entity_type_enum = ? and c.calendar_type_enum in ? order by c.start_date "; - result = this.jdbcTemplate.query(sql,rm, new Object[] {entityId, entityTypeId, sqlCalendarTypeOptions}); + String sqlCalendarTypeOptions = getSqlCalendarTypeOptionsInString(calendarTypeOptions); + sql = rm.schema() + " " + parentHeirarchyCondition + " and ci.entity_type_enum = ? and c.calendar_type_enum in ("+ sqlCalendarTypeOptions +") order by c.start_date "; + result = this.jdbcTemplate.query(sql,rm, new Object[] {entityId, entityTypeId}); } return result; } @@ -231,22 +231,20 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ } /** - * This method takes the List of calendarType options given in the request and creates a string to be used in the sql statement. - * for ex. (1,2,3,4) + * function returns a comma separated list of calendar_type_enum values ex. 1,2,3,4 * @param calendarTypeOptions * @return */ - public String createSqlValuesInString(List calendarTypeOptions){ + public String getSqlCalendarTypeOptionsInString(List calendarTypeOptions){ + String sqlCalendarTypeOptions = ""; int size = calendarTypeOptions.size(); - String sqlCalendarTypeOptions = "(" + calendarTypeOptions.get(0).getId().toString(); - for(int i=1;i