Issue-331
This commit is contained in:
+8
@@ -26,4 +26,12 @@ public class EnumOptionData {
|
|||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+37
-22
@@ -5,25 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.portfolio.calendar.api;
|
package org.mifosplatform.portfolio.calendar.api;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
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.domain.CommandWrapper;
|
||||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||||
@@ -37,12 +18,20 @@ 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;
|
||||||
import org.springframework.stereotype.Component;
|
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.*;
|
||||||
|
|
||||||
@Path("/{entityType}/{entityId}/calendars")
|
@Path("/{entityType}/{entityId}/calendars")
|
||||||
@Component
|
@Component
|
||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
@@ -102,23 +91,24 @@ public class CalendarsApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveCalendarsByEntity(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId,
|
public String retrieveCalendarsByEntity(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId,
|
||||||
@Context final UriInfo uriInfo) {
|
@Context final UriInfo uriInfo, @QueryParam("calendarType") String calendarType) {
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
|
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
|
||||||
|
|
||||||
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
Collection<CalendarData> calendarsData = new ArrayList<CalendarData>();
|
Collection<CalendarData> calendarsData = new ArrayList<CalendarData>();
|
||||||
|
List<EnumOptionData> calendarTypeOptions = createEnumOptionDataListFromQueryParameter(calendarType);
|
||||||
|
|
||||||
if (!associationParameters.isEmpty()) {
|
if (!associationParameters.isEmpty()) {
|
||||||
if (associationParameters.contains("parentCalendars")) {
|
if (associationParameters.contains("parentCalendars")) {
|
||||||
calendarsData.addAll(this.readPlatformService.retrieveParentCalendarsByEntity(entityId,
|
calendarsData.addAll(this.readPlatformService.retrieveParentCalendarsByEntity(entityId,
|
||||||
CalendarEntityType.valueOf(entityType.toUpperCase()).getValue()));
|
CalendarEntityType.valueOf(entityType.toUpperCase()).getValue(),calendarTypeOptions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
calendarsData.addAll(this.readPlatformService.retrieveCalendarsByEntity(entityId,
|
calendarsData.addAll(this.readPlatformService.retrieveCalendarsByEntity(entityId,
|
||||||
CalendarEntityType.valueOf(entityType.toUpperCase()).getValue()));
|
CalendarEntityType.valueOf(entityType.toUpperCase()).getValue(),calendarTypeOptions));
|
||||||
|
|
||||||
// Add recurring dates
|
// Add recurring dates
|
||||||
calendarsData = this.readPlatformService.generateRecurringDates(calendarsData);
|
calendarsData = this.readPlatformService.generateRecurringDates(calendarsData);
|
||||||
@@ -192,4 +182,29 @@ public class CalendarsApiResource {
|
|||||||
final List<EnumOptionData> remindByOptions = this.dropdownReadPlatformService.retrieveCalendarRemindByOptions();
|
final List<EnumOptionData> remindByOptions = this.dropdownReadPlatformService.retrieveCalendarRemindByOptions();
|
||||||
return new CalendarData(calendarData, entityTypeOptions, calendarTypeOptions, remindByOptions);
|
return new CalendarData(calendarData, entityTypeOptions, calendarTypeOptions, remindByOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<EnumOptionData> createEnumOptionDataListFromQueryParameter(String calendarTypeQuery) {
|
||||||
|
List<EnumOptionData> calendarTypeOptions = null;
|
||||||
|
// creating a list of calendar type options from the comma separated query parameter.
|
||||||
|
List<String> calendarTypeOptionsInQuery = new ArrayList<String>();
|
||||||
|
StringTokenizer st = new StringTokenizer(calendarTypeQuery, ",");
|
||||||
|
while (st.hasMoreElements()) {
|
||||||
|
calendarTypeOptionsInQuery.add(st.nextElement().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String calType : calendarTypeOptionsInQuery){
|
||||||
|
if(calType.equalsIgnoreCase("collection")) {
|
||||||
|
calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.COLLECTION));
|
||||||
|
} else if(calType.equalsIgnoreCase("training")) {
|
||||||
|
calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.TRAINING));
|
||||||
|
} else if(calType.equalsIgnoreCase("audit")) {
|
||||||
|
calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.AUDIT));
|
||||||
|
} else if(calType.equalsIgnoreCase("general")) {
|
||||||
|
calendarTypeOptions.add(CalendarEnumerations.calendarType(CalendarType.GENERAL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return calendarTypeOptions;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+6
-4
@@ -5,17 +5,19 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.portfolio.calendar.service;
|
package org.mifosplatform.portfolio.calendar.service;
|
||||||
|
|
||||||
import java.util.Collection;
|
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.List;
|
||||||
|
|
||||||
public interface CalendarReadPlatformService {
|
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);
|
Collection<CalendarData> retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, List<EnumOptionData> calendarTypeOptions);
|
||||||
|
|
||||||
Collection<CalendarData> retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId);
|
Collection<CalendarData> retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId, List<EnumOptionData> calendarTypeOptions);
|
||||||
|
|
||||||
Collection<CalendarData> retrieveAllCalendars();
|
Collection<CalendarData> retrieveAllCalendars();
|
||||||
|
|
||||||
|
|||||||
+55
-16
@@ -5,11 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.portfolio.calendar.service;
|
package org.mifosplatform.portfolio.calendar.service;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
|
||||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||||
@@ -25,6 +20,12 @@ import org.springframework.jdbc.core.RowMapper;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformService {
|
public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformService {
|
||||||
|
|
||||||
@@ -98,24 +99,43 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<CalendarData> retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId) {
|
public Collection<CalendarData> retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, List<EnumOptionData> calendarTypeOptions) {
|
||||||
final CalendarDataMapper rm = new CalendarDataMapper();
|
final CalendarDataMapper rm = new CalendarDataMapper();
|
||||||
|
// the collection result will store the final result
|
||||||
final String sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? order by c.start_date ";
|
Collection<CalendarData> result=null;
|
||||||
|
// string sql is the sql statement that will be executed by jdbc.
|
||||||
return this.jdbcTemplate.query(sql, rm, new Object[] { entityId, entityTypeId });
|
String sql="";
|
||||||
|
// if calendarType options are not given by user then return all calendars.
|
||||||
|
if(calendarTypeOptions.isEmpty()) {
|
||||||
|
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});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<CalendarData> retrieveParentCalendarsByEntity(Long entityId, Integer entityTypeId) {
|
public Collection<CalendarData> retrieveParentCalendarsByEntity( Long entityId, Integer entityTypeId, List<EnumOptionData> calendarTypeOptions ) {
|
||||||
|
|
||||||
final CalendarDataMapper rm = new CalendarDataMapper();
|
final CalendarDataMapper rm = new CalendarDataMapper();
|
||||||
|
Collection<CalendarData> result=null;
|
||||||
|
String sql="";
|
||||||
CalendarEntityType ceType = CalendarEntityType.fromInt(entityTypeId);
|
CalendarEntityType ceType = CalendarEntityType.fromInt(entityTypeId);
|
||||||
String parentHeirarchyCondition = getParentHierarchyCondition(ceType);
|
String parentHeirarchyCondition = getParentHierarchyCondition(ceType);
|
||||||
final String sql = rm.schema() + " " + parentHeirarchyCondition
|
|
||||||
+ " and ci.entity_type_enum = ? order by c.start_date ";
|
|
||||||
//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.
|
||||||
return this.jdbcTemplate.query(sql, rm, new Object[] { entityId, CalendarEntityType.CENTERS.getValue() });
|
if(calendarTypeOptions.isEmpty()){
|
||||||
|
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});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -210,4 +230,23 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
|
|||||||
return conditionSql;
|
return conditionSql;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
* @param calendarTypeOptions
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String createSqlValuesInString(List<EnumOptionData> calendarTypeOptions){
|
||||||
|
int size = calendarTypeOptions.size();
|
||||||
|
String sqlCalendarTypeOptions = "(" + calendarTypeOptions.get(0).getId().toString();
|
||||||
|
for(int i=1;i<size;i++) {
|
||||||
|
sqlCalendarTypeOptions += "," + calendarTypeOptions.get(i).getId().toString();
|
||||||
|
}
|
||||||
|
sqlCalendarTypeOptions += ")";
|
||||||
|
|
||||||
|
return sqlCalendarTypeOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user