view holidays(improvement)
This commit is contained in:
+3
@@ -24,4 +24,7 @@ public class HolidayApiConstants {
|
|||||||
|
|
||||||
public static final Set<String> HOLIDAY_CREATE_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName,
|
public static final Set<String> HOLIDAY_CREATE_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName,
|
||||||
dateFormatParamName, name, fromDate, toDate, description, offices, repaymentsRescheduledTo));
|
dateFormatParamName, name, fromDate, toDate, description, offices, repaymentsRescheduledTo));
|
||||||
|
|
||||||
|
public static final Set<String> HOLIDAY_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(localeParamName,
|
||||||
|
dateFormatParamName, name, fromDate, toDate, repaymentsRescheduledTo));
|
||||||
}
|
}
|
||||||
|
|||||||
+49
-2
@@ -1,16 +1,29 @@
|
|||||||
package org.mifosplatform.organisation.holiday.api;
|
package org.mifosplatform.organisation.holiday.api;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
|
import org.mifosplatform.accounting.journalentry.api.DateParam;
|
||||||
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;
|
||||||
|
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
|
import org.mifosplatform.organisation.holiday.data.HolidayData;
|
||||||
|
import org.mifosplatform.organisation.holiday.service.HolidayReadPlatformService;
|
||||||
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;
|
||||||
@@ -20,13 +33,24 @@ import org.springframework.stereotype.Component;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class HolidaysApiResource {
|
public class HolidaysApiResource {
|
||||||
|
|
||||||
private final DefaultToApiJsonSerializer<Object> toApiJsonSerializer;
|
private final String resourceNameForPermissions = "HOLIDAY";
|
||||||
|
|
||||||
|
private final DefaultToApiJsonSerializer<HolidayData> toApiJsonSerializer;
|
||||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
|
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||||
|
|
||||||
|
private final HolidayReadPlatformService holidayReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public HolidaysApiResource(final DefaultToApiJsonSerializer<Object> toApiJsonSerializer, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
public HolidaysApiResource(final DefaultToApiJsonSerializer<HolidayData> toApiJsonSerializer,
|
||||||
|
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final PlatformSecurityContext context,
|
||||||
|
final ApiRequestParameterHelper apiRequestParameterHelper, final HolidayReadPlatformService holidayReadPlatformService) {
|
||||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||||
|
this.context = context;
|
||||||
|
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||||
|
this.holidayReadPlatformService = holidayReadPlatformService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@@ -41,5 +65,28 @@ public class HolidaysApiResource {
|
|||||||
return this.toApiJsonSerializer.serialize(result);
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
|
public String retrieveAllLoanProducts(@Context final UriInfo uriInfo, @QueryParam("officeId") final Long officeId,
|
||||||
|
@QueryParam("fromDate") final DateParam fromDateParam, @QueryParam("toDate") final DateParam toDateParam,
|
||||||
|
@QueryParam("locale") final String locale, @QueryParam("dateFormat") final String dateFormat) {
|
||||||
|
|
||||||
|
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||||
|
|
||||||
|
Date fromDate = null;
|
||||||
|
if (fromDateParam != null) {
|
||||||
|
fromDate = fromDateParam.getDate("fromDate", dateFormat, locale);
|
||||||
|
}
|
||||||
|
Date toDate = null;
|
||||||
|
if (toDateParam != null) {
|
||||||
|
toDate = toDateParam.getDate("toDate", dateFormat, locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collection<HolidayData> holidays = this.holidayReadPlatformService.retrieveAllHolidaysBySearchParamerters(officeId, fromDate, toDate);
|
||||||
|
|
||||||
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||||
|
return this.toApiJsonSerializer.serialize(settings, holidays, HolidayApiConstants.HOLIDAY_REQUEST_DATA_PARAMETERS);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package org.mifosplatform.organisation.holiday.data;
|
||||||
|
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
|
||||||
|
|
||||||
|
public class HolidayData {
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private final Long id;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private final String name;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private final LocalDate fromDate;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private final LocalDate toDate;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private final LocalDate repaymentsScheduleTO;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private final Long officeId;
|
||||||
|
|
||||||
|
public HolidayData(final Long id, final String name, final LocalDate fromDate, final LocalDate toDate,
|
||||||
|
final LocalDate repaymentsScheduleTO) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.fromDate = fromDate;
|
||||||
|
this.toDate = toDate;
|
||||||
|
this.repaymentsScheduleTO = repaymentsScheduleTO;
|
||||||
|
this.officeId = null;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
package org.mifosplatform.organisation.holiday.service;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.mifosplatform.organisation.holiday.data.HolidayData;
|
||||||
|
|
||||||
|
|
||||||
|
public interface HolidayReadPlatformService {
|
||||||
|
|
||||||
|
Collection<HolidayData> retrieveAllHolidaysBySearchParamerters(final Long officeId, Date fromDate, Date toDate);
|
||||||
|
}
|
||||||
+96
-1
@@ -1,5 +1,100 @@
|
|||||||
package org.mifosplatform.organisation.holiday.service;
|
package org.mifosplatform.organisation.holiday.service;
|
||||||
|
|
||||||
public class HolidayReadPlatformServiceImpl {
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
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.holiday.data.HolidayData;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class HolidayReadPlatformServiceImpl implements HolidayReadPlatformService {
|
||||||
|
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public HolidayReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource) {
|
||||||
|
this.context = context;
|
||||||
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class HolidayMapper implements RowMapper<HolidayData> {
|
||||||
|
|
||||||
|
private final String schema;
|
||||||
|
|
||||||
|
public HolidayMapper() {
|
||||||
|
final StringBuilder sqlBuilder = new StringBuilder(200);
|
||||||
|
sqlBuilder.append("h.id as id, h.name as name, h.from_date as fromDate, h.to_date as toDate, ");
|
||||||
|
sqlBuilder.append("h.repayments_rescheduled_to as repaymentsScheduleTO ");
|
||||||
|
sqlBuilder.append("from m_holiday h join m_holiday_office hf on h.id = hf.holiday_id and ");
|
||||||
|
schema = sqlBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String schema() {
|
||||||
|
return this.schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HolidayData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException {
|
||||||
|
final Long id = rs.getLong("id");
|
||||||
|
final String name = rs.getString("name");
|
||||||
|
final LocalDate fromDate = JdbcSupport.getLocalDate(rs, "fromDate");
|
||||||
|
final LocalDate toDate = JdbcSupport.getLocalDate(rs, "toDate");
|
||||||
|
final LocalDate repaymentsScheduleTO = JdbcSupport.getLocalDate(rs, "repaymentsScheduleTO");
|
||||||
|
|
||||||
|
return new HolidayData(id, name, fromDate, toDate, repaymentsScheduleTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<HolidayData> retrieveAllHolidaysBySearchParamerters(Long officeId, Date fromDate, Date toDate) {
|
||||||
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
|
final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
|
||||||
|
final Object[] objectArray = new Object[3];
|
||||||
|
int arrayPos = 0;
|
||||||
|
|
||||||
|
HolidayMapper rm = new HolidayMapper();
|
||||||
|
String sql = "select " + rm.schema() + " hf.office_id = ? ";
|
||||||
|
|
||||||
|
objectArray[arrayPos] = officeId;
|
||||||
|
arrayPos = arrayPos + 1;
|
||||||
|
|
||||||
|
if (fromDate != null || toDate != null) {
|
||||||
|
sql += "and ";
|
||||||
|
|
||||||
|
if (fromDate != null) {
|
||||||
|
sql += "h.from_Date >= ? ";
|
||||||
|
|
||||||
|
objectArray[arrayPos] = df.format(fromDate);
|
||||||
|
arrayPos = arrayPos + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toDate != null) {
|
||||||
|
sql += fromDate != null ? "and " : "";
|
||||||
|
sql += "h.to_date <= ? ";
|
||||||
|
objectArray[arrayPos] = df.format(toDate);
|
||||||
|
arrayPos = arrayPos + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Object[] finalObjectArray = Arrays.copyOf(objectArray, arrayPos);
|
||||||
|
|
||||||
|
return this.jdbcTemplate.query(sql, rm, finalObjectArray);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user