MIFOSX-331: merge in Kushas work for 1.2.0 release and fix merge conflict.

This commit is contained in:
Keith Woodlock
2013-05-12 10:35:01 +01:00
3 changed files with 77 additions and 58 deletions
@@ -18,9 +18,7 @@ import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext
import org.mifosplatform.portfolio.calendar.data.CalendarData; import org.mifosplatform.portfolio.calendar.data.CalendarData;
import org.mifosplatform.portfolio.calendar.domain.Calendar; import org.mifosplatform.portfolio.calendar.domain.Calendar;
import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType; 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.CalendarDropdownReadPlatformService;
import org.mifosplatform.portfolio.calendar.service.CalendarEnumerations;
import org.mifosplatform.portfolio.calendar.service.CalendarReadPlatformService; import org.mifosplatform.portfolio.calendar.service.CalendarReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@@ -87,6 +85,14 @@ public class CalendarsApiResource {
return this.toApiJsonSerializer.serialize(settings, calendarData, this.RESPONSE_DATA_PARAMETERS); return this.toApiJsonSerializer.serialize(settings, calendarData, this.RESPONSE_DATA_PARAMETERS);
} }
/**
* @param entityType
* @param entityId
* @param uriInfo
* @param calendarType
* @return
*/
@GET @GET
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@@ -99,7 +105,7 @@ public class CalendarsApiResource {
Collection<CalendarData> calendarsData = new ArrayList<CalendarData>(); Collection<CalendarData> calendarsData = new ArrayList<CalendarData>();
List<EnumOptionData> calendarTypeOptions = createEnumOptionDataListFromQueryParameter(calendarType); List<Integer> calendarTypeOptions = createIntegerListFromQueryParameter(calendarType);
if (!associationParameters.isEmpty()) { if (!associationParameters.isEmpty()) {
@@ -186,10 +192,14 @@ public class CalendarsApiResource {
} }
public List<EnumOptionData> createEnumOptionDataListFromQueryParameter(String calendarTypeQuery) { public List<Integer> createIntegerListFromQueryParameter(String calendarTypeQuery) {
List<EnumOptionData> calendarTypeOptions = new ArrayList<EnumOptionData>(); List<Integer> calendarTypeOptions = new ArrayList<Integer>();
// adding all calendar Types if // adding all calendar Types if query parameter is "all"
if(calendarTypeQuery.equalsIgnoreCase("all")){ if(calendarTypeQuery.equalsIgnoreCase("all")){
calendarTypeOptions.add(1);
calendarTypeOptions.add(2);
calendarTypeOptions.add(3);
calendarTypeOptions.add(4);
return calendarTypeOptions; return calendarTypeOptions;
} }
// creating a list of calendar type options from the comma separated query parameter. // creating a list of calendar type options from the comma separated query parameter.
@@ -201,13 +211,13 @@ public class CalendarsApiResource {
for(String calType : calendarTypeOptionsInQuery){ for(String calType : calendarTypeOptionsInQuery){
if(calType.equalsIgnoreCase("collection")) { if(calType.equalsIgnoreCase("collection")) {
calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.COLLECTION)); calendarTypeOptions.add(1);
} else if(calType.equalsIgnoreCase("training")) { } else if(calType.equalsIgnoreCase("training")) {
calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.TRAINING)); calendarTypeOptions.add(2);
} else if(calType.equalsIgnoreCase("audit")) { } else if(calType.equalsIgnoreCase("audit")) {
calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.AUDIT)); calendarTypeOptions.add(3);
} else if(calType.equalsIgnoreCase("general")) { } else if(calType.equalsIgnoreCase("general")) {
calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.GENERAL)); calendarTypeOptions.add(4);
} }
} }
@@ -5,7 +5,6 @@
*/ */
package org.mifosplatform.portfolio.calendar.service; package org.mifosplatform.portfolio.calendar.service;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.portfolio.calendar.data.CalendarData; import org.mifosplatform.portfolio.calendar.data.CalendarData;
import java.util.Collection; import java.util.Collection;
@@ -15,9 +14,9 @@ public interface CalendarReadPlatformService {
CalendarData retrieveCalendar(final Long calendarId, Long entityId, Integer entityTypeId); CalendarData retrieveCalendar(final Long calendarId, Long entityId, Integer entityTypeId);
Collection<CalendarData> retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, List<EnumOptionData> calendarTypeOptions); Collection<CalendarData> retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, List<Integer> calendarTypeOptions);
Collection<CalendarData> retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId, List<EnumOptionData> calendarTypeOptions); Collection<CalendarData> retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId, List<Integer> calendarTypeOptions);
Collection<CalendarData> retrieveAllCalendars(); Collection<CalendarData> retrieveAllCalendars();
@@ -28,4 +27,5 @@ public interface CalendarReadPlatformService {
Collection<CalendarData> generateRecurringDates(final Collection<CalendarData> calendarsData); Collection<CalendarData> generateRecurringDates(final Collection<CalendarData> calendarsData);
CalendarData retrieveLoanCalendar(final Long loanId); CalendarData retrieveLoanCalendar(final Long loanId);
} }
@@ -68,7 +68,7 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
final String recurrence = rs.getString("recurrence"); final String recurrence = rs.getString("recurrence");
final Integer remindById = rs.getInt("remindById"); final Integer remindById = rs.getInt("remindById");
EnumOptionData remindBy = null; EnumOptionData remindBy = null;
if(remindById != null && remindById != 0) remindBy = CalendarEnumerations.calendarRemindBy(remindById); if (remindById != null && remindById != 0) remindBy = CalendarEnumerations.calendarRemindBy(remindById);
final Integer firstReminder = rs.getInt("firstReminder"); final Integer firstReminder = rs.getInt("firstReminder");
final Integer secondReminder = rs.getInt("secondReminder"); final Integer secondReminder = rs.getInt("secondReminder");
final String humanReadable = CalendarHelper.getRRuleReadable(startDate, recurrence); final String humanReadable = CalendarHelper.getRRuleReadable(startDate, recurrence);
@@ -80,7 +80,9 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
final Long lastUpdatedByUserId = rs.getLong("updatingUserId"); final Long lastUpdatedByUserId = rs.getLong("updatingUserId");
final String lastUpdatedByUserName = rs.getString("updatingUserName"); final String lastUpdatedByUserName = rs.getString("updatingUserName");
return new CalendarData(id, entityId, entityType, title, description, location, startDate, endDate, duration, type, repeating, recurrence, remindBy, firstReminder, secondReminder, humanReadable, createdDate, lastUpdatedDate, createdByUserId, createdByUserName, lastUpdatedByUserId, lastUpdatedByUserName); return new CalendarData(id, entityId, entityType, title, description, location, startDate, endDate, duration, type, repeating,
recurrence, remindBy, firstReminder, secondReminder, humanReadable, createdDate, lastUpdatedDate, createdByUserId,
createdByUserName, lastUpdatedByUserId, lastUpdatedByUserName);
} }
} }
@@ -99,41 +101,46 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
} }
@Override @Override
public Collection<CalendarData> retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, final List<EnumOptionData> calendarTypeOptions) { public Collection<CalendarData> retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId,
final List<Integer> calendarTypeOptions) {
final CalendarDataMapper rm = new CalendarDataMapper(); final CalendarDataMapper rm = new CalendarDataMapper();
Collection<CalendarData> result=null; Collection<CalendarData> result = null;
String sql=""; String sql = "";
if (calendarTypeOptions == null || calendarTypeOptions.isEmpty()) { if (calendarTypeOptions == null || calendarTypeOptions.isEmpty()) {
sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? order by c.start_date "; 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 }); result = this.jdbcTemplate.query(sql, rm, new Object[] { entityId, entityTypeId });
} else if(!calendarTypeOptions.isEmpty()){ } else if (!calendarTypeOptions.isEmpty()) {
String sqlCalendarTypeOptions = createSqlValuesInString(calendarTypeOptions); String sqlCalendarTypeOptions = getSqlCalendarTypeOptionsInString(calendarTypeOptions);
sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? and c.calendar_type_enum in (?) order by c.start_date "; sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? and c.calendar_type_enum in ( " + sqlCalendarTypeOptions
result = this.jdbcTemplate.query(sql,rm, new Object[] {entityId, entityTypeId, sqlCalendarTypeOptions}); + " ) order by c.start_date ";
result = this.jdbcTemplate.query(sql, rm, new Object[] { entityId, entityTypeId });
} }
return result; return result;
} }
@Override @Override
public Collection<CalendarData> retrieveParentCalendarsByEntity( final Long entityId, final Integer entityTypeId, final List<EnumOptionData> calendarTypeOptions ) { public Collection<CalendarData> retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId,
final List<Integer> calendarTypeOptions) {
final CalendarDataMapper rm = new CalendarDataMapper(); final CalendarDataMapper rm = new CalendarDataMapper();
Collection<CalendarData> result=null; Collection<CalendarData> result = null;
String sql=""; String sql = "";
CalendarEntityType ceType = CalendarEntityType.fromInt(entityTypeId); CalendarEntityType ceType = CalendarEntityType.fromInt(entityTypeId);
String parentHeirarchyCondition = getParentHierarchyCondition(ceType); String parentHeirarchyCondition = getParentHierarchyCondition(ceType);
//FIXME :AA center is the parent entity of group, change this code to support more parent entity types. // FIXME :AA center is the parent entity of group, change this code to
// support more parent entity types.
if (calendarTypeOptions == null || calendarTypeOptions.isEmpty()) { if (calendarTypeOptions == null || calendarTypeOptions.isEmpty()) {
sql = rm.schema() + " " + parentHeirarchyCondition + " and ci.entity_type_enum = ? order by c.start_date "; 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() }); result = this.jdbcTemplate.query(sql, rm, new Object[] { entityId, CalendarEntityType.CENTERS.getValue() });
} else { } else {
String sqlCalendarTypeOptions = createSqlValuesInString(calendarTypeOptions); String sqlCalendarTypeOptions = getSqlCalendarTypeOptionsInString(calendarTypeOptions);
sql = rm.schema() + " " + parentHeirarchyCondition + " and ci.entity_type_enum = ? and c.calendar_type_enum in ? order by c.start_date "; sql = rm.schema() + " " + parentHeirarchyCondition + " and ci.entity_type_enum = ? and c.calendar_type_enum in ("
result = this.jdbcTemplate.query(sql,rm, new Object[] {entityId, entityTypeId, sqlCalendarTypeOptions}); + sqlCalendarTypeOptions + ") order by c.start_date ";
result = this.jdbcTemplate.query(sql, rm, new Object[] { entityId, entityTypeId });
} }
return result; return result;
} }
@@ -155,17 +162,17 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
@Override @Override
public CalendarData generateRecurringDate(final CalendarData calendarData) { public CalendarData generateRecurringDate(final CalendarData calendarData) {
if(!calendarData.isRepeating()) return calendarData; if (!calendarData.isRepeating()) return calendarData;
final String rrule = calendarData.getRecurrence(); final String rrule = calendarData.getRecurrence();
final LocalDate currentDate = DateUtils.getLocalDateOfTenant(); final LocalDate currentDate = DateUtils.getLocalDateOfTenant();
LocalDate seedDate = calendarData.getStartDate(); LocalDate seedDate = calendarData.getStartDate();
LocalDate endDate = calendarData.getEndDate(); LocalDate endDate = calendarData.getEndDate();
LocalDate startDate = calendarData.getStartDate(); LocalDate startDate = calendarData.getStartDate();
if(seedDate.isBefore(currentDate.minusYears(1))){ if (seedDate.isBefore(currentDate.minusYears(1))) {
startDate = currentDate.minusYears(1); startDate = currentDate.minusYears(1);
} }
if(endDate == null || endDate.isAfter(currentDate.plusYears(1))){ if (endDate == null || endDate.isAfter(currentDate.plusYears(1))) {
endDate = currentDate.plusYears(1); endDate = currentDate.plusYears(1);
} }
@@ -191,12 +198,13 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
final String sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? order by c.start_date "; final String sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? order by c.start_date ";
CalendarData calendarData = null; CalendarData calendarData = null;
final Collection<CalendarData> calendars = this.jdbcTemplate.query(sql, rm, new Object[] { loanId, CalendarEntityType.LOANS.getValue() }); final Collection<CalendarData> calendars = this.jdbcTemplate.query(sql, rm,
new Object[] { loanId, CalendarEntityType.LOANS.getValue() });
if(!CollectionUtils.isEmpty(calendars)){ if (!CollectionUtils.isEmpty(calendars)) {
for (CalendarData calendar : calendars) { for (CalendarData calendar : calendars) {
calendarData = calendar; calendarData = calendar;
break;//Loans are associated with only one calendar break;// Loans are associated with only one calendar
} }
} }
@@ -208,18 +216,19 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
switch (calendarEntityType) { switch (calendarEntityType) {
case CLIENTS: case CLIENTS:
//TODO : AA : do we need to propagate to top level parent in hierarchy? // TODO : AA : do we need to propagate to top level parent in
// hierarchy?
conditionSql = " and ci.entity_id in (select gc.group_id from m_client c join m_group_client gc " conditionSql = " and ci.entity_id in (select gc.group_id from m_client c join m_group_client gc "
+ " on c.id=gc.client_id where c.id = ? ) "; + " on c.id=gc.client_id where c.id = ? ) ";
break; break;
case GROUPS: case GROUPS:
//TODO : AA: add parent hierarchy for groups // TODO : AA: add parent hierarchy for groups
conditionSql = " and ci.entity_id in (select g.parent_id from m_group g where g.id = ? ) "; conditionSql = " and ci.entity_id in (select g.parent_id from m_group g where g.id = ? ) ";
break; break;
case LOANS: case LOANS:
//TODO : AA: do we need parent hierarchy calendars for loans? // TODO : AA: do we need parent hierarchy calendars for loans?
conditionSql = " and ci.entity_id = ? "; conditionSql = " and ci.entity_id = ? ";
break; break;
@@ -231,19 +240,19 @@ 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. * function returns a comma separated list of calendar_type_enum values ex.
* for ex. (1,2,3,4) * 1,2,3,4
*
* @param calendarTypeOptions * @param calendarTypeOptions
* @return * @return
*/ */
public String createSqlValuesInString(final List<EnumOptionData> calendarTypeOptions){ public String getSqlCalendarTypeOptionsInString(final List<Integer> calendarTypeOptions) {
String sqlCalendarTypeOptions = "";
int size = calendarTypeOptions.size(); int size = calendarTypeOptions.size();
String sqlCalendarTypeOptions = "(" + calendarTypeOptions.get(0).getId().toString(); for (int i = 0; i < size - 1; i++) {
for(int i=1;i<size;i++) { sqlCalendarTypeOptions += calendarTypeOptions.get(i).toString() + ",";
sqlCalendarTypeOptions += "," + calendarTypeOptions.get(i).getId().toString();
} }
sqlCalendarTypeOptions += ")"; sqlCalendarTypeOptions += calendarTypeOptions.get(size - 1).toString();
return sqlCalendarTypeOptions; return sqlCalendarTypeOptions;
} }
} }