diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/EnumOptionData.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/EnumOptionData.java
index 41e6416b6..1f39ee0d2 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/EnumOptionData.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/EnumOptionData.java
@@ -10,11 +10,11 @@ package org.mifosplatform.infrastructure.core.data;
* Immutable data object representing generic enumeration value.
*
*/
-@SuppressWarnings("unused")
public class EnumOptionData {
private final Long id;
private final String code;
+ @SuppressWarnings("unused")
private final String value;
public EnumOptionData(final Long id, final String code, final String value) {
@@ -27,7 +27,7 @@ public class EnumOptionData {
return id;
}
- public String getCode() {
- return this.code;
- }
+ public String getCode() {
+ return code;
+ }
}
\ No newline at end of file
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 c3dc9ae90..d9fa91303 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
@@ -5,25 +5,6 @@
*/
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.service.CommandWrapperBuilder;
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.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;
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")
@Component
@Scope("singleton")
@@ -102,7 +91,7 @@ public class CalendarsApiResource {
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveCalendarsByEntity(@PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId,
- @Context final UriInfo uriInfo) {
+ @Context final UriInfo uriInfo,@DefaultValue("all") @QueryParam("calendarType") String calendarType) {
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
@@ -110,15 +99,18 @@ public class CalendarsApiResource {
Collection calendarsData = new ArrayList();
+ List calendarTypeOptions = createEnumOptionDataListFromQueryParameter(calendarType);
+
+
if (!associationParameters.isEmpty()) {
if (associationParameters.contains("parentCalendars")) {
calendarsData.addAll(this.readPlatformService.retrieveParentCalendarsByEntity(entityId,
- CalendarEntityType.valueOf(entityType.toUpperCase()).getValue()));
+ CalendarEntityType.valueOf(entityType.toUpperCase()).getValue(),calendarTypeOptions));
}
}
calendarsData.addAll(this.readPlatformService.retrieveCalendarsByEntity(entityId,
- CalendarEntityType.valueOf(entityType.toUpperCase()).getValue()));
+ CalendarEntityType.valueOf(entityType.toUpperCase()).getValue(),calendarTypeOptions));
// Add recurring dates
calendarsData = this.readPlatformService.generateRecurringDates(calendarsData);
@@ -192,4 +184,34 @@ public class CalendarsApiResource {
final List remindByOptions = this.dropdownReadPlatformService.retrieveCalendarRemindByOptions();
return new CalendarData(calendarData, entityTypeOptions, calendarTypeOptions, remindByOptions);
}
+
+
+ public List createEnumOptionDataListFromQueryParameter(String calendarTypeQuery) {
+ List calendarTypeOptions = new ArrayList();
+ // adding all calendar Types if
+ if(calendarTypeQuery.equalsIgnoreCase("all")){
+ return calendarTypeOptions;
+ }
+ // creating a list of calendar type options from the comma separated query parameter.
+ List calendarTypeOptionsInQuery = new ArrayList();
+ 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;
+ }
+
}
\ No newline at end of file
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 dc75f2f9f..3a70381a3 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,17 +5,19 @@
*/
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 java.util.Collection;
+import java.util.List;
+
public interface CalendarReadPlatformService {
CalendarData retrieveCalendar(final Long calendarId, Long entityId, Integer entityTypeId);
- Collection retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId);
+ Collection retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, List calendarTypeOptions);
- Collection retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId);
+ Collection retrieveParentCalendarsByEntity(final Long entityId, final Integer entityTypeId, List calendarTypeOptions);
Collection retrieveAllCalendars();
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 fe82f7991..0a5e788b5 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
@@ -9,6 +9,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.data.EnumOptionData;
@@ -84,7 +85,7 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
}
@Override
- public CalendarData retrieveCalendar(final Long calendarId, Long entityId, Integer entityTypeId) {
+ public CalendarData retrieveCalendar(final Long calendarId, final Long entityId, final Integer entityTypeId) {
try {
final CalendarDataMapper rm = new CalendarDataMapper();
@@ -98,24 +99,43 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
}
@Override
- public Collection retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId) {
+ public Collection retrieveCalendarsByEntity(final Long entityId, final Integer entityTypeId, final List calendarTypeOptions) {
final CalendarDataMapper rm = new CalendarDataMapper();
- final String sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? order by c.start_date ";
+ Collection result=null;
- return this.jdbcTemplate.query(sql, rm, new Object[] { entityId, entityTypeId });
+ String sql="";
+
+ if (calendarTypeOptions == null || 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
- public Collection retrieveParentCalendarsByEntity(Long entityId, Integer entityTypeId) {
-
+ public Collection retrieveParentCalendarsByEntity( final Long entityId, final Integer entityTypeId, final List calendarTypeOptions ) {
+
final CalendarDataMapper rm = new CalendarDataMapper();
+ Collection result=null;
+ String sql="";
CalendarEntityType ceType = CalendarEntityType.fromInt(entityTypeId);
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.
- return this.jdbcTemplate.query(sql, rm, new Object[] { entityId, CalendarEntityType.CENTERS.getValue() });
+ if (calendarTypeOptions == null || 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
@@ -134,7 +154,7 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
}
@Override
- public CalendarData generateRecurringDate(CalendarData calendarData) {
+ public CalendarData generateRecurringDate(final CalendarData calendarData) {
if(!calendarData.isRepeating()) return calendarData;
final String rrule = calendarData.getRecurrence();
final LocalDate currentDate = DateUtils.getLocalDateOfTenant();
@@ -155,7 +175,7 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
}
@Override
- public Collection generateRecurringDates(Collection calendarsData) {
+ public Collection generateRecurringDates(final Collection calendarsData) {
Collection recuCalendarsData = new ArrayList();
for (CalendarData calendarData : calendarsData) {
@@ -166,7 +186,7 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
}
@Override
- public CalendarData retrieveLoanCalendar(Long loanId) {
+ public CalendarData retrieveLoanCalendar(final Long loanId) {
final CalendarDataMapper rm = new CalendarDataMapper();
final String sql = rm.schema() + " and ci.entity_id = ? and ci.entity_type_enum = ? order by c.start_date ";
@@ -210,4 +230,20 @@ public class CalendarReadPlatformServiceImpl implements CalendarReadPlatformServ
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(final List calendarTypeOptions){
+ int size = calendarTypeOptions.size();
+ String sqlCalendarTypeOptions = "(" + calendarTypeOptions.get(0).getId().toString();
+ for(int i=1;i loanTermFrequencyTypeOptions = loanDropdownReadPlatformService.retrieveLoanTermFrequencyTypeOptions();
- final Collection repaymentFrequencyTypeOptions = loanDropdownReadPlatformService.retrieveRepaymentFrequencyTypeOptions();
- final Collection interestRateFrequencyTypeOptions = loanDropdownReadPlatformService.retrieveInterestRateFrequencyTypeOptions();
+ final Collection loanTermFrequencyTypeOptions = loanDropdownReadPlatformService
+ .retrieveLoanTermFrequencyTypeOptions();
+ final Collection repaymentFrequencyTypeOptions = loanDropdownReadPlatformService
+ .retrieveRepaymentFrequencyTypeOptions();
+ final Collection interestRateFrequencyTypeOptions = loanDropdownReadPlatformService
+ .retrieveInterestRateFrequencyTypeOptions();
final Collection amortizationTypeOptions = loanDropdownReadPlatformService.retrieveLoanAmortizationTypeOptions();
final Collection interestTypeOptions = loanDropdownReadPlatformService.retrieveLoanInterestTypeOptions();
- final Collection interestCalculationPeriodTypeOptions = loanDropdownReadPlatformService.retrieveLoanInterestRateCalculatedInPeriodOptions();
+ final Collection interestCalculationPeriodTypeOptions = loanDropdownReadPlatformService
+ .retrieveLoanInterestRateCalculatedInPeriodOptions();
final Collection fundOptions = this.fundReadPlatformService.retrieveAllFunds();
- final Collection repaymentStrategyOptions = this.loanDropdownReadPlatformService.retreiveTransactionProcessingStrategies();
+ final Collection repaymentStrategyOptions = this.loanDropdownReadPlatformService
+ .retreiveTransactionProcessingStrategies();
final Collection loanPurposeOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode("LoanPurpose");
- final Collection loanCollateralOptions = this.codeValueReadPlatformService.retrieveCodeValuesByCode("LoanCollateral");
+ final Collection loanCollateralOptions = this.codeValueReadPlatformService
+ .retrieveCodeValuesByCode("LoanCollateral");
final boolean feeChargesOnly = false;
final Collection chargeOptions = this.chargeReadPlatformService.retrieveLoanApplicableCharges(feeChargesOnly);
-
+
return LoanAccountData.loanProductWithTemplateDefaults(loanProduct, loanTermFrequencyTypeOptions, repaymentFrequencyTypeOptions,
repaymentStrategyOptions, interestRateFrequencyTypeOptions, amortizationTypeOptions, interestTypeOptions,
interestCalculationPeriodTypeOptions, fundOptions, chargeOptions, loanPurposeOptions, loanCollateralOptions);
}
@Override
- public LoanAccountData retrieveClientDetailsTemplate(Long clientId) {
+ public LoanAccountData retrieveClientDetailsTemplate(final Long clientId) {
context.authenticatedUser();
@@ -879,7 +886,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
}
@Override
- public LoanAccountData retrieveGroupDetailsTemplate(Long groupId) {
+ public LoanAccountData retrieveGroupDetailsTemplate(final Long groupId) {
context.authenticatedUser();
final GroupGeneralData groupAccount = this.groupReadPlatformService.retrieveOne(groupId);
final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant();
@@ -887,27 +894,28 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
}
@Override
- public LoanAccountData retrieveGroupAndMembersDetailsTemplate(Long groupId) {
+ public LoanAccountData retrieveGroupAndMembersDetailsTemplate(final Long groupId) {
GroupGeneralData groupAccount = this.groupReadPlatformService.retrieveOne(groupId);
final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant();
-
- // get group associations
+
+ // get group associations
Collection membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId);
if (!CollectionUtils.isEmpty(membersOfGroup)) {
groupAccount = GroupGeneralData.withAssocations(groupAccount, membersOfGroup);
}
-
+
return LoanAccountData.groupDefaults(groupAccount, expectedDisbursementDate);
}
@Override
- public Collection retrieveCalendars(Long groupId) {
+ public Collection retrieveCalendars(final Long groupId) {
Collection calendarsData = new ArrayList();
- calendarsData.addAll(this.calendarReadPlatformService.retrieveParentCalendarsByEntity(groupId,CalendarEntityType.GROUPS.getValue()));
- calendarsData.addAll(this.calendarReadPlatformService.retrieveCalendarsByEntity(groupId,CalendarEntityType.GROUPS.getValue()));
+ calendarsData.addAll(this.calendarReadPlatformService.retrieveParentCalendarsByEntity(groupId,
+ CalendarEntityType.GROUPS.getValue(), null));
+ calendarsData
+ .addAll(this.calendarReadPlatformService.retrieveCalendarsByEntity(groupId, CalendarEntityType.GROUPS.getValue(), null));
calendarsData = this.calendarReadPlatformService.generateRecurringDates(calendarsData);
return calendarsData;
}
-
}
\ No newline at end of file