removing most warnings in ppi/survey related code
This commit is contained in:
+5
-7
@@ -6,7 +6,6 @@
|
|||||||
package org.mifosplatform.infrastructure.dataqueries.api;
|
package org.mifosplatform.infrastructure.dataqueries.api;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
@@ -33,13 +32,12 @@ import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
|||||||
import org.mifosplatform.infrastructure.dataqueries.service.GenericDataService;
|
import org.mifosplatform.infrastructure.dataqueries.service.GenericDataService;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService;
|
import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
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 org.slf4j.Logger;
|
//import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
@Path("/datatables")
|
@Path("/datatables")
|
||||||
@Component
|
@Component
|
||||||
@@ -53,8 +51,6 @@ public class DatatablesApiResource {
|
|||||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||||
private final static org.slf4j.Logger logger = LoggerFactory.getLogger(DatatablesApiResource.class);
|
private final static org.slf4j.Logger logger = LoggerFactory.getLogger(DatatablesApiResource.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DatatablesApiResource(final PlatformSecurityContext context, final GenericDataService genericDataService,
|
public DatatablesApiResource(final PlatformSecurityContext context, final GenericDataService genericDataService,
|
||||||
final ReadWriteNonCoreDataService readWriteNonCoreDataService,
|
final ReadWriteNonCoreDataService readWriteNonCoreDataService,
|
||||||
@@ -117,9 +113,11 @@ public class DatatablesApiResource {
|
|||||||
@Path("register/{datatable}/{apptable}")
|
@Path("register/{datatable}/{apptable}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String registerDatatable(@PathParam("datatable") final String datatable, @PathParam("apptable") final String apptable,final String apiRequestBodyAsJson) {
|
public String registerDatatable(@PathParam("datatable") final String datatable, @PathParam("apptable") final String apptable,
|
||||||
|
final String apiRequestBodyAsJson) {
|
||||||
|
|
||||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().registerDBDatatable(datatable,apptable).withJson(apiRequestBodyAsJson).build();
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().registerDBDatatable(datatable, apptable)
|
||||||
|
.withJson(apiRequestBodyAsJson).build();
|
||||||
|
|
||||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
|
|||||||
+17
-15
@@ -1,23 +1,25 @@
|
|||||||
package org.mifosplatform.infrastructure.dataqueries.data;
|
package org.mifosplatform.infrastructure.dataqueries.data;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.CATEGORY_DEFAULT;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.CATEGORY_PPI;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.DATATABLE_RESOURCE_NAME;
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.REGISTER_PARAMS;
|
||||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
import static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.categoryParamName;
|
||||||
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
|
||||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
|
||||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
|
||||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.*;
|
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||||
|
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
|
||||||
|
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DataTableValidator {
|
public class DataTableValidator {
|
||||||
@@ -31,7 +33,6 @@ public class DataTableValidator {
|
|||||||
|
|
||||||
public void validateDataTableRegistration(final String json) {
|
public void validateDataTableRegistration(final String json) {
|
||||||
|
|
||||||
|
|
||||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, REGISTER_PARAMS);
|
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, REGISTER_PARAMS);
|
||||||
|
|
||||||
@@ -41,8 +42,9 @@ public class DataTableValidator {
|
|||||||
|
|
||||||
if (this.fromApiJsonHelper.parameterExists(categoryParamName, element)) {
|
if (this.fromApiJsonHelper.parameterExists(categoryParamName, element)) {
|
||||||
|
|
||||||
final Integer category = this.fromApiJsonHelper.extractIntegerWithLocaleNamed(categoryParamName,element);
|
final Integer category = this.fromApiJsonHelper.extractIntegerWithLocaleNamed(categoryParamName, element);
|
||||||
baseDataValidator.reset().parameter(categoryParamName).value(category).isOneOfTheseValues(new Integer[]{CATEGORY_PPI,CATEGORY_DEFAULT});
|
Object[] objectArray = new Integer[] { CATEGORY_PPI, CATEGORY_DEFAULT };
|
||||||
|
baseDataValidator.reset().parameter(categoryParamName).value(category).isOneOfTheseValues(objectArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||||
|
|||||||
+2
@@ -13,6 +13,7 @@ public class ResultsetColumnValueData {
|
|||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
private final String value;
|
private final String value;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
private final Integer score;
|
private final Integer score;
|
||||||
|
|
||||||
public ResultsetColumnValueData(final int id, final String value) {
|
public ResultsetColumnValueData(final int id, final String value) {
|
||||||
@@ -20,6 +21,7 @@ public class ResultsetColumnValueData {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
this.score = null;
|
this.score = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultsetColumnValueData(final int id, final String value, final int score) {
|
public ResultsetColumnValueData(final int id, final String value, final int score) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
|||||||
+4
-6
@@ -6,13 +6,11 @@
|
|||||||
package org.mifosplatform.infrastructure.dataqueries.service;
|
package org.mifosplatform.infrastructure.dataqueries.service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
|
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.data.ResultsetColumnHeaderData;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
|
||||||
public interface ReadWriteNonCoreDataService {
|
public interface ReadWriteNonCoreDataService {
|
||||||
@@ -25,10 +23,10 @@ public interface ReadWriteNonCoreDataService {
|
|||||||
void registerDatatable(JsonCommand command);
|
void registerDatatable(JsonCommand command);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'REGISTER_DATATABLE')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'REGISTER_DATATABLE')")
|
||||||
void registerDatatable(String dataTableName,String applicationTableName);
|
void registerDatatable(String dataTableName, String applicationTableName);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'REGISTER_DATATABLE')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'REGISTER_DATATABLE')")
|
||||||
void registerDatatable(JsonCommand command,String permissionTable);
|
void registerDatatable(JsonCommand command, String permissionTable);
|
||||||
|
|
||||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DEREGISTER_DATATABLE')")
|
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DEREGISTER_DATATABLE')")
|
||||||
void deregisterDatatable(String datatable);
|
void deregisterDatatable(String datatable);
|
||||||
@@ -42,6 +40,7 @@ public interface ReadWriteNonCoreDataService {
|
|||||||
void deleteDatatable(String datatableName);
|
void deleteDatatable(String datatableName);
|
||||||
|
|
||||||
CommandProcessingResult createNewDatatableEntry(String datatable, Long appTableId, JsonCommand command);
|
CommandProcessingResult createNewDatatableEntry(String datatable, Long appTableId, JsonCommand command);
|
||||||
|
|
||||||
CommandProcessingResult createPPIEntry(String datatable, Long appTableId, JsonCommand command);
|
CommandProcessingResult createPPIEntry(String datatable, Long appTableId, JsonCommand command);
|
||||||
|
|
||||||
CommandProcessingResult updateDatatableEntryOneToOne(String datatable, Long appTableId, JsonCommand command);
|
CommandProcessingResult updateDatatableEntryOneToOne(String datatable, Long appTableId, JsonCommand command);
|
||||||
@@ -53,8 +52,7 @@ public interface ReadWriteNonCoreDataService {
|
|||||||
CommandProcessingResult deleteDatatableEntry(String datatable, Long appTableId, Long datatableId);
|
CommandProcessingResult deleteDatatableEntry(String datatable, Long appTableId, Long datatableId);
|
||||||
|
|
||||||
String getTableName(String Url);
|
String getTableName(String Url);
|
||||||
|
|
||||||
String getDataTableName(String Url);
|
String getDataTableName(String Url);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+46
-90
@@ -20,11 +20,9 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
import org.hibernate.exception.GenericJDBCException;
|
import org.hibernate.exception.GenericJDBCException;
|
||||||
import org.hibernate.exception.SQLGrammarException;
|
import org.hibernate.exception.SQLGrammarException;
|
||||||
import org.hibernate.service.config.internal.ConfigurationServiceImpl;
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.mifosplatform.infrastructure.codes.service.CodeReadPlatformService;
|
import org.mifosplatform.infrastructure.codes.service.CodeReadPlatformService;
|
||||||
import org.mifosplatform.infrastructure.configuration.domain.ConfigurationDomainService;
|
import org.mifosplatform.infrastructure.configuration.domain.ConfigurationDomainService;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
@@ -38,7 +36,11 @@ import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
|||||||
import org.mifosplatform.infrastructure.core.serialization.JsonParserHelper;
|
import org.mifosplatform.infrastructure.core.serialization.JsonParserHelper;
|
||||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant;
|
import org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.data.*;
|
import org.mifosplatform.infrastructure.dataqueries.data.DataTableValidator;
|
||||||
|
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
|
||||||
|
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
||||||
|
import org.mifosplatform.infrastructure.dataqueries.data.ResultsetColumnHeaderData;
|
||||||
|
import org.mifosplatform.infrastructure.dataqueries.data.ResultsetRowData;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.exception.DatatableNotFoundException;
|
import org.mifosplatform.infrastructure.dataqueries.exception.DatatableNotFoundException;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.exception.DatatableSystemErrorException;
|
import org.mifosplatform.infrastructure.dataqueries.exception.DatatableSystemErrorException;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
@@ -46,7 +48,6 @@ import org.mifosplatform.useradministration.domain.AppUser;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.mifosplatform.infrastructure.configuration.service.GlobalConfigurationWritePlatformServiceJpaRepositoryImpl;
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.dao.EmptyResultDataAccessException;
|
import org.springframework.dao.EmptyResultDataAccessException;
|
||||||
@@ -92,7 +93,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
private final CodeReadPlatformService codeReadPlatformService;
|
private final CodeReadPlatformService codeReadPlatformService;
|
||||||
private final DataTableValidator dataTableValidator;
|
private final DataTableValidator dataTableValidator;
|
||||||
|
|
||||||
//private final GlobalConfigurationWritePlatformServiceJpaRepositoryImpl configurationWriteService;
|
// private final GlobalConfigurationWritePlatformServiceJpaRepositoryImpl
|
||||||
|
// configurationWriteService;
|
||||||
|
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
public ReadWriteNonCoreDataServiceImpl(final RoutingDataSource dataSource, final PlatformSecurityContext context,
|
public ReadWriteNonCoreDataServiceImpl(final RoutingDataSource dataSource, final PlatformSecurityContext context,
|
||||||
@@ -109,7 +111,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
this.codeReadPlatformService = codeReadPlatformService;
|
this.codeReadPlatformService = codeReadPlatformService;
|
||||||
this.configurationDomainService = configurationDomainService;
|
this.configurationDomainService = configurationDomainService;
|
||||||
this.dataTableValidator = dataTableValidator;
|
this.dataTableValidator = dataTableValidator;
|
||||||
//this.configurationWriteService = configurationWriteService;
|
// this.configurationWriteService = configurationWriteService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -177,8 +179,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void registerDatatable(final String dataTableName, final String applicationTableName)
|
public void registerDatatable(final String dataTableName, final String applicationTableName) {
|
||||||
{
|
|
||||||
|
|
||||||
Integer category = DataTableApiConstant.CATEGORY_DEFAULT;
|
Integer category = DataTableApiConstant.CATEGORY_DEFAULT;
|
||||||
|
|
||||||
@@ -204,8 +205,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void registerDatatable(final JsonCommand command,final String permissionSql)
|
public void registerDatatable(final JsonCommand command, final String permissionSql) {
|
||||||
{
|
|
||||||
final String applicationTableName = this.getTableName(command.getUrl());
|
final String applicationTableName = this.getTableName(command.getUrl());
|
||||||
final String dataTableName = this.getDataTableName(command.getUrl());
|
final String dataTableName = this.getDataTableName(command.getUrl());
|
||||||
|
|
||||||
@@ -213,16 +213,13 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
|
|
||||||
this.dataTableValidator.validateDataTableRegistration(command.json());
|
this.dataTableValidator.validateDataTableRegistration(command.json());
|
||||||
|
|
||||||
this._registerDataTable(applicationTableName,dataTableName,category,permissionSql);
|
this._registerDataTable(applicationTableName, dataTableName, category, permissionSql);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private void _registerDataTable(final String applicationTableName,
|
private void _registerDataTable(final String applicationTableName, final String dataTableName, final Integer category,
|
||||||
final String dataTableName,
|
final String permissionsSql) {
|
||||||
final Integer category,
|
|
||||||
final String permissionsSql)
|
|
||||||
{
|
|
||||||
|
|
||||||
validateAppTable(applicationTableName);
|
validateAppTable(applicationTableName);
|
||||||
assertDataTableExists(dataTableName);
|
assertDataTableExists(dataTableName);
|
||||||
@@ -230,17 +227,14 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
final String registerDatatableSql = "insert into x_registered_table (registered_table_name, application_table_name,category) values ('"
|
final String registerDatatableSql = "insert into x_registered_table (registered_table_name, application_table_name,category) values ('"
|
||||||
+ dataTableName + "', '" + applicationTableName + "', '" + category + "')";
|
+ dataTableName + "', '" + applicationTableName + "', '" + category + "')";
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
final String[] sqlArray = { registerDatatableSql, permissionsSql };
|
final String[] sqlArray = { registerDatatableSql, permissionsSql };
|
||||||
this.jdbcTemplate.batchUpdate(sqlArray);
|
this.jdbcTemplate.batchUpdate(sqlArray);
|
||||||
|
|
||||||
// add the registered table to the config if it is a ppi
|
// add the registered table to the config if it is a ppi
|
||||||
if(this.isSurveyCategory(category))
|
if (this.isSurveyCategory(category)) {
|
||||||
{
|
this.jdbcTemplate.execute("insert into c_configuration (name, value, enabled ) values('" + dataTableName + "', '0','0')");
|
||||||
this.jdbcTemplate.execute("insert into c_configuration (name, value, enabled ) values('"+dataTableName+"', '0','0')");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -253,24 +247,22 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
// show duplicate datatable error msg
|
// show duplicate datatable error msg
|
||||||
if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException(
|
if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException(
|
||||||
"error.msg.datatable.registered", "Datatable `" + dataTableName
|
"error.msg.datatable.registered", "Datatable `" + dataTableName
|
||||||
+ "` is already registered against an application table.", "dataTableName", dataTableName); }
|
+ "` is already registered against an application table.", "dataTableName", dataTableName); }
|
||||||
} catch (final DataIntegrityViolationException dve) {
|
} catch (final DataIntegrityViolationException dve) {
|
||||||
final Throwable realCause = dve.getMostSpecificCause();
|
final Throwable realCause = dve.getMostSpecificCause();
|
||||||
// even if duplicate is only due to permission duplicate, okay to
|
// even if duplicate is only due to permission duplicate, okay to
|
||||||
// show duplicate datatable error msg
|
// show duplicate datatable error msg
|
||||||
if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException(
|
if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException(
|
||||||
"error.msg.datatable.registered", "Datatable `" + dataTableName
|
"error.msg.datatable.registered", "Datatable `" + dataTableName
|
||||||
+ "` is already registered against an application table.", "dataTableName", dataTableName); }
|
+ "` is already registered against an application table.", "dataTableName", dataTableName); }
|
||||||
logAsErrorUnexpectedDataIntegrityException(dve);
|
logAsErrorUnexpectedDataIntegrityException(dve);
|
||||||
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
|
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
|
||||||
"Unknown data integrity issue with resource.");
|
"Unknown data integrity issue with resource.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String _getPermissionSql(final String dataTableName)
|
private String _getPermissionSql(final String dataTableName) {
|
||||||
{
|
|
||||||
final String createPermission = "'CREATE_" + dataTableName + "'";
|
final String createPermission = "'CREATE_" + dataTableName + "'";
|
||||||
final String createPermissionChecker = "'CREATE_" + dataTableName + "_CHECKER'";
|
final String createPermissionChecker = "'CREATE_" + dataTableName + "_CHECKER'";
|
||||||
final String readPermission = "'READ_" + dataTableName + "'";
|
final String readPermission = "'READ_" + dataTableName + "'";
|
||||||
@@ -279,67 +271,38 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
final String deletePermission = "'DELETE_" + dataTableName + "'";
|
final String deletePermission = "'DELETE_" + dataTableName + "'";
|
||||||
final String deletePermissionChecker = "'DELETE_" + dataTableName + "_CHECKER'";
|
final String deletePermissionChecker = "'DELETE_" + dataTableName + "_CHECKER'";
|
||||||
|
|
||||||
return "insert into m_permission (grouping, code, action_name, entity_name, can_maker_checker) values "
|
return "insert into m_permission (grouping, code, action_name, entity_name, can_maker_checker) values " + "('datatable', "
|
||||||
+ "('datatable', "
|
+ createPermission + ", 'CREATE', '" + dataTableName + "', true)," + "('datatable', " + createPermissionChecker
|
||||||
+ createPermission
|
+ ", 'CREATE', '" + dataTableName + "', false)," + "('datatable', " + readPermission + ", 'READ', '" + dataTableName
|
||||||
+ ", 'CREATE', '"
|
+ "', false)," + "('datatable', " + updatePermission + ", 'UPDATE', '" + dataTableName + "', true)," + "('datatable', "
|
||||||
+ dataTableName
|
+ updatePermissionChecker + ", 'UPDATE', '" + dataTableName + "', false)," + "('datatable', " + deletePermission
|
||||||
+ "', true),"
|
+ ", 'DELETE', '" + dataTableName + "', true)," + "('datatable', " + deletePermissionChecker + ", 'DELETE', '"
|
||||||
+ "('datatable', "
|
|
||||||
+ createPermissionChecker
|
|
||||||
+ ", 'CREATE', '"
|
|
||||||
+ dataTableName
|
|
||||||
+ "', false),"
|
|
||||||
+ "('datatable', "
|
|
||||||
+ readPermission
|
|
||||||
+ ", 'READ', '"
|
|
||||||
+ dataTableName
|
|
||||||
+ "', false),"
|
|
||||||
+ "('datatable', "
|
|
||||||
+ updatePermission
|
|
||||||
+ ", 'UPDATE', '"
|
|
||||||
+ dataTableName
|
|
||||||
+ "', true),"
|
|
||||||
+ "('datatable', "
|
|
||||||
+ updatePermissionChecker
|
|
||||||
+ ", 'UPDATE', '"
|
|
||||||
+ dataTableName
|
|
||||||
+ "', false),"
|
|
||||||
+ "('datatable', "
|
|
||||||
+ deletePermission
|
|
||||||
+ ", 'DELETE', '"
|
|
||||||
+ dataTableName
|
|
||||||
+ "', true),"
|
|
||||||
+ "('datatable', "
|
|
||||||
+ deletePermissionChecker
|
|
||||||
+ ", 'DELETE', '"
|
|
||||||
+ dataTableName + "', false)";
|
+ dataTableName + "', false)";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer getCategory(final JsonCommand command)
|
private Integer getCategory(final JsonCommand command) {
|
||||||
{
|
|
||||||
Integer category = command.integerValueOfParameterNamedDefaultToNullIfZero(DataTableApiConstant.categoryParamName);
|
Integer category = command.integerValueOfParameterNamedDefaultToNullIfZero(DataTableApiConstant.categoryParamName);
|
||||||
if(category ==null) category = DataTableApiConstant.CATEGORY_DEFAULT;
|
if (category == null) category = DataTableApiConstant.CATEGORY_DEFAULT;
|
||||||
return category;
|
return category;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSurveyCategory(final Integer category)
|
private boolean isSurveyCategory(final Integer category) {
|
||||||
{
|
|
||||||
return category.equals(DataTableApiConstant.CATEGORY_PPI);
|
return category.equals(DataTableApiConstant.CATEGORY_PPI);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDataTableName(String url){
|
@Override
|
||||||
|
public String getDataTableName(String url) {
|
||||||
|
|
||||||
String [] urlParts = url.split("/");
|
String[] urlParts = url.split("/");
|
||||||
|
|
||||||
return urlParts[3];
|
return urlParts[3];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTableName(String url)
|
@Override
|
||||||
{
|
public String getTableName(String url) {
|
||||||
String [] urlParts = url.split("/");
|
String[] urlParts = url.split("/");
|
||||||
return urlParts[4];
|
return urlParts[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,13 +319,13 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
|
|
||||||
final String deleteRegisteredDatatableSql = "delete from x_registered_table where registered_table_name = '" + datatable + "'";
|
final String deleteRegisteredDatatableSql = "delete from x_registered_table where registered_table_name = '" + datatable + "'";
|
||||||
|
|
||||||
final String deleteFromConfigurationSql = "delete from c_configuration where name ='"+datatable+"'";
|
final String deleteFromConfigurationSql = "delete from c_configuration where name ='" + datatable + "'";
|
||||||
|
|
||||||
String[] sqlArray = new String[4];
|
String[] sqlArray = new String[4];
|
||||||
sqlArray[0] = deleteRolePermissionsSql;
|
sqlArray[0] = deleteRolePermissionsSql;
|
||||||
sqlArray[1] = deletePermissionsSql;
|
sqlArray[1] = deletePermissionsSql;
|
||||||
sqlArray[2] = deleteRegisteredDatatableSql;
|
sqlArray[2] = deleteRegisteredDatatableSql;
|
||||||
sqlArray[3] = deleteFromConfigurationSql ;
|
sqlArray[3] = deleteFromConfigurationSql;
|
||||||
|
|
||||||
this.jdbcTemplate.batchUpdate(sqlArray);
|
this.jdbcTemplate.batchUpdate(sqlArray);
|
||||||
}
|
}
|
||||||
@@ -410,6 +373,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public CommandProcessingResult createPPIEntry(final String dataTableName, final Long appTableId, final JsonCommand command) {
|
public CommandProcessingResult createPPIEntry(final String dataTableName, final Long appTableId, final JsonCommand command) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -434,7 +398,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
final Throwable realCause = dve.getCause();
|
final Throwable realCause = dve.getCause();
|
||||||
if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException(
|
if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException(
|
||||||
"error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName
|
"error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName
|
||||||
+ "` and application table with identifier `" + appTableId + "`.", "dataTableName", dataTableName, appTableId); }
|
+ "` and application table with identifier `" + appTableId + "`.", "dataTableName", dataTableName, appTableId); }
|
||||||
|
|
||||||
logAsErrorUnexpectedDataIntegrityException(dve);
|
logAsErrorUnexpectedDataIntegrityException(dve);
|
||||||
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
|
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
|
||||||
@@ -443,7 +407,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
final Throwable realCause = dve.getMostSpecificCause();
|
final Throwable realCause = dve.getMostSpecificCause();
|
||||||
if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException(
|
if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException(
|
||||||
"error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName
|
"error.msg.datatable.entry.duplicate", "An entry already exists for datatable `" + dataTableName
|
||||||
+ "` and application table with identifier `" + appTableId + "`.", "dataTableName", dataTableName, appTableId); }
|
+ "` and application table with identifier `" + appTableId + "`.", "dataTableName", dataTableName, appTableId); }
|
||||||
|
|
||||||
logAsErrorUnexpectedDataIntegrityException(dve);
|
logAsErrorUnexpectedDataIntegrityException(dve);
|
||||||
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
|
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
|
||||||
@@ -1075,7 +1039,6 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
public GenericResultsetData retrieveDataTableGenericResultSet(final String dataTableName, final Long appTableId, final String order,
|
public GenericResultsetData retrieveDataTableGenericResultSet(final String dataTableName, final Long appTableId, final String order,
|
||||||
final Long id) {
|
final Long id) {
|
||||||
|
|
||||||
|
|
||||||
final String appTable = queryForApplicationTableName(dataTableName);
|
final String appTable = queryForApplicationTableName(dataTableName);
|
||||||
|
|
||||||
checkMainResourceExistsWithinScope(appTable, appTableId);
|
checkMainResourceExistsWithinScope(appTable, appTableId);
|
||||||
@@ -1315,7 +1278,6 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
} else {
|
} else {
|
||||||
pValueWrite = singleQuote + this.genericDataService.replace(pValue, singleQuote, singleQuote + singleQuote) + singleQuote;
|
pValueWrite = singleQuote + this.genericDataService.replace(pValue, singleQuote, singleQuote + singleQuote) + singleQuote;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
columnName = "`" + key + "`";
|
columnName = "`" + key + "`";
|
||||||
insertColumns += ", " + columnName;
|
insertColumns += ", " + columnName;
|
||||||
@@ -1331,8 +1293,9 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is used special for ppi cases
|
* This method is used special for ppi cases Where the score need to be
|
||||||
* Where the score need to be computed
|
* computed
|
||||||
|
*
|
||||||
* @param columnHeaders
|
* @param columnHeaders
|
||||||
* @param datatable
|
* @param datatable
|
||||||
* @param fkName
|
* @param fkName
|
||||||
@@ -1341,12 +1304,11 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String getAddSqlWithScore(final List<ResultsetColumnHeaderData> columnHeaders, final String datatable, final String fkName,
|
public String getAddSqlWithScore(final List<ResultsetColumnHeaderData> columnHeaders, final String datatable, final String fkName,
|
||||||
final Long appTableId, final Map<String, String> queryParams) {
|
final Long appTableId, final Map<String, String> queryParams) {
|
||||||
|
|
||||||
final Map<String, String> affectedColumns = getAffectedColumns(columnHeaders, queryParams, fkName);
|
final Map<String, String> affectedColumns = getAffectedColumns(columnHeaders, queryParams, fkName);
|
||||||
|
|
||||||
String pValueWrite = "";
|
String pValueWrite = "";
|
||||||
String addSql = "";
|
|
||||||
String scoresId = " ";
|
String scoresId = " ";
|
||||||
final String singleQuote = "'";
|
final String singleQuote = "'";
|
||||||
|
|
||||||
@@ -1362,8 +1324,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
} else {
|
} else {
|
||||||
pValueWrite = singleQuote + this.genericDataService.replace(pValue, singleQuote, singleQuote + singleQuote) + singleQuote;
|
pValueWrite = singleQuote + this.genericDataService.replace(pValue, singleQuote, singleQuote + singleQuote) + singleQuote;
|
||||||
|
|
||||||
scoresId +=pValueWrite +" ,";
|
scoresId += pValueWrite + " ,";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
columnName = "`" + key + "`";
|
columnName = "`" + key + "`";
|
||||||
@@ -1371,16 +1332,11 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
|
|||||||
selectColumns += "," + pValueWrite + " as " + columnName;
|
selectColumns += "," + pValueWrite + " as " + columnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
scoresId = scoresId.replaceAll(" ,$", "");
|
scoresId = scoresId.replaceAll(" ,$", "");
|
||||||
|
|
||||||
addSql = "insert into `" + datatable + "` (`" + fkName + "` " + insertColumns + ")" + " select " + appTableId + " as id"
|
String vaddSql = "insert into `" + datatable + "` (`" + fkName + "` " + insertColumns + ", `score` )" + " select " + appTableId
|
||||||
+ selectColumns;
|
+ " as id" + selectColumns + " , ( SELECT SUM( code_score ) FROM m_code_value WHERE m_code_value.id IN (" + scoresId
|
||||||
|
+ " ) ) as score";
|
||||||
String vaddSql = "insert into `" + datatable + "` (`" + fkName + "` " + insertColumns + ", `score` )" + " select " + appTableId + " as id"
|
|
||||||
+ selectColumns + " , ( SELECT SUM( code_score ) FROM m_code_value WHERE m_code_value.id IN (" + scoresId + " ) ) as score";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger.info(vaddSql);
|
logger.info(vaddSql);
|
||||||
|
|
||||||
|
|||||||
+4
-10
@@ -1,14 +1,11 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.api;
|
package org.mifosplatform.infrastructure.survey.api;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.survey.data.LikelihoodStatus;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
import org.mifosplatform.infrastructure.survey.data.LikelihoodStatus;
|
||||||
* Created by Cieyou on 3/12/14.
|
|
||||||
*/
|
|
||||||
public class LikelihoodApiConstants {
|
public class LikelihoodApiConstants {
|
||||||
|
|
||||||
public static final String ACTIVE = "active";
|
public static final String ACTIVE = "active";
|
||||||
@@ -17,9 +14,6 @@ public class LikelihoodApiConstants {
|
|||||||
|
|
||||||
public static final Set<String> UPDATE_LIKELIHOOD_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(ACTIVE));
|
public static final Set<String> UPDATE_LIKELIHOOD_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(ACTIVE));
|
||||||
|
|
||||||
public static final Set<Long> VALID_LIKELIHOOD_ENABLED_VALUES = new HashSet<Long>(
|
public static final Set<Long> VALID_LIKELIHOOD_ENABLED_VALUES = new HashSet<Long>(Arrays.asList(LikelihoodStatus.DISABLED,
|
||||||
Arrays.asList(
|
LikelihoodStatus.ENABLED));
|
||||||
LikelihoodStatus.DISABLED,
|
|
||||||
LikelihoodStatus.ENABLED
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-16
@@ -1,5 +1,15 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.api;
|
package org.mifosplatform.infrastructure.survey.api;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
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.MediaType;
|
||||||
|
|
||||||
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;
|
||||||
@@ -8,16 +18,10 @@ import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSeria
|
|||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.infrastructure.survey.data.LikelihoodData;
|
import org.mifosplatform.infrastructure.survey.data.LikelihoodData;
|
||||||
import org.mifosplatform.infrastructure.survey.service.ReadLikelihoodService;
|
import org.mifosplatform.infrastructure.survey.service.ReadLikelihoodService;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
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.MediaType;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Cieyou on 3/12/14.
|
* Created by Cieyou on 3/12/14.
|
||||||
*/
|
*/
|
||||||
@@ -26,33 +30,28 @@ import java.util.List;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class LikelihoodApiResource {
|
public class LikelihoodApiResource {
|
||||||
|
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(PovertyLineApiResource.class);
|
|
||||||
private final DefaultToApiJsonSerializer<LikelihoodData> toApiJsonSerializer;
|
private final DefaultToApiJsonSerializer<LikelihoodData> toApiJsonSerializer;
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||||
private final ReadLikelihoodService readService;
|
private final ReadLikelihoodService readService;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
LikelihoodApiResource(final PlatformSecurityContext context,
|
LikelihoodApiResource(final PlatformSecurityContext context,
|
||||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
||||||
final DefaultToApiJsonSerializer<LikelihoodData> toApiJsonSerializer,
|
final DefaultToApiJsonSerializer<LikelihoodData> toApiJsonSerializer, final ReadLikelihoodService readService) {
|
||||||
final ReadLikelihoodService readService) {
|
|
||||||
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||||
this.readService = readService;
|
this.readService = readService;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{ppiName}")
|
@Path("{ppiName}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveAll(@PathParam("ppiName") final String ppiName){
|
public String retrieveAll(@PathParam("ppiName") final String ppiName) {
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(PovertyLineApiConstants.POVERTY_LINE_RESOURCE_NAME);
|
this.context.authenticatedUser().validateHasReadPermission(PovertyLineApiConstants.POVERTY_LINE_RESOURCE_NAME);
|
||||||
|
|
||||||
@@ -65,7 +64,7 @@ public class LikelihoodApiResource {
|
|||||||
@Path("{ppiName}/{likelihoodId}")
|
@Path("{ppiName}/{likelihoodId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieve(@PathParam("likelihoodId") final Long likelihoodId){
|
public String retrieve(@PathParam("likelihoodId") final Long likelihoodId) {
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(PovertyLineApiConstants.POVERTY_LINE_RESOURCE_NAME);
|
this.context.authenticatedUser().validateHasReadPermission(PovertyLineApiConstants.POVERTY_LINE_RESOURCE_NAME);
|
||||||
|
|
||||||
@@ -78,7 +77,7 @@ public class LikelihoodApiResource {
|
|||||||
@Path("{ppiName}/{likelihoodId}")
|
@Path("{ppiName}/{likelihoodId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String update(@PathParam("likelihoodId") final Long likelihoodId, final String apiRequestBodyAsJson){
|
public String update(@PathParam("likelihoodId") final Long likelihoodId, final String apiRequestBodyAsJson) {
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(PovertyLineApiConstants.POVERTY_LINE_RESOURCE_NAME);
|
this.context.authenticatedUser().validateHasReadPermission(PovertyLineApiConstants.POVERTY_LINE_RESOURCE_NAME);
|
||||||
|
|
||||||
|
|||||||
-6
@@ -1,11 +1,5 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.api;
|
package org.mifosplatform.infrastructure.survey.api;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Cieyou on 3/11/14.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class PovertyLineApiConstants {
|
public class PovertyLineApiConstants {
|
||||||
|
|
||||||
final static String POVERTY_LINE_RESOURCE_NAME = "PovertyLine";
|
final static String POVERTY_LINE_RESOURCE_NAME = "PovertyLine";
|
||||||
|
|||||||
+15
-28
@@ -1,50 +1,38 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.api;
|
package org.mifosplatform.infrastructure.survey.api;
|
||||||
|
|
||||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.infrastructure.survey.data.LikeliHoodPovertyLineData;
|
import org.mifosplatform.infrastructure.survey.data.LikeliHoodPovertyLineData;
|
||||||
import org.mifosplatform.infrastructure.survey.data.PovertyLineData;
|
|
||||||
import org.mifosplatform.infrastructure.survey.data.PpiPovertyLineData;
|
import org.mifosplatform.infrastructure.survey.data.PpiPovertyLineData;
|
||||||
import org.mifosplatform.infrastructure.survey.service.PovertyLineService;
|
import org.mifosplatform.infrastructure.survey.service.PovertyLineService;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
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.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Cieyou on 3/11/14.
|
|
||||||
*/
|
|
||||||
@Path("/povertyLine")
|
@Path("/povertyLine")
|
||||||
@Component
|
@Component
|
||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class PovertyLineApiResource {
|
public class PovertyLineApiResource {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(PovertyLineApiResource.class);
|
|
||||||
private final DefaultToApiJsonSerializer<PpiPovertyLineData> toApiJsonSerializer;
|
private final DefaultToApiJsonSerializer<PpiPovertyLineData> toApiJsonSerializer;
|
||||||
private final DefaultToApiJsonSerializer<LikeliHoodPovertyLineData> likelihoodToApiJsonSerializer;
|
private final DefaultToApiJsonSerializer<LikeliHoodPovertyLineData> likelihoodToApiJsonSerializer;
|
||||||
// private final DefaultToApiJsonSerializer<PpiPovertyLineData> toApiJsonSerializer;
|
// private final DefaultToApiJsonSerializer<PpiPovertyLineData>
|
||||||
|
// toApiJsonSerializer;
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
|
||||||
private final PovertyLineService readService;
|
private final PovertyLineService readService;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
PovertyLineApiResource(final PlatformSecurityContext context,
|
PovertyLineApiResource(final PlatformSecurityContext context, final DefaultToApiJsonSerializer<PpiPovertyLineData> toApiJsonSerializer,
|
||||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
final PovertyLineService readService, final DefaultToApiJsonSerializer<LikeliHoodPovertyLineData> likelihoodToApiJsonSerializer) {
|
||||||
final DefaultToApiJsonSerializer<PpiPovertyLineData> toApiJsonSerializer,
|
|
||||||
final PovertyLineService readService,
|
|
||||||
final DefaultToApiJsonSerializer<LikeliHoodPovertyLineData> likelihoodToApiJsonSerializer) {
|
|
||||||
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
|
||||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||||
this.readService = readService;
|
this.readService = readService;
|
||||||
this.likelihoodToApiJsonSerializer = likelihoodToApiJsonSerializer;
|
this.likelihoodToApiJsonSerializer = likelihoodToApiJsonSerializer;
|
||||||
@@ -55,7 +43,7 @@ public class PovertyLineApiResource {
|
|||||||
@Path("{ppiName}")
|
@Path("{ppiName}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveAll(@PathParam("ppiName") final String ppiName){
|
public String retrieveAll(@PathParam("ppiName") final String ppiName) {
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(PovertyLineApiConstants.POVERTY_LINE_RESOURCE_NAME);
|
this.context.authenticatedUser().validateHasReadPermission(PovertyLineApiConstants.POVERTY_LINE_RESOURCE_NAME);
|
||||||
|
|
||||||
@@ -63,20 +51,19 @@ public class PovertyLineApiResource {
|
|||||||
return this.toApiJsonSerializer.serialize(povertyLine);
|
return this.toApiJsonSerializer.serialize(povertyLine);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{ppiName}/{likelihoodId}")
|
@Path("{ppiName}/{likelihoodId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveAll(@PathParam("ppiName") final String ppiName,@PathParam("likelihoodId") final Long likelihoodId){
|
public String retrieveAll(@PathParam("ppiName") final String ppiName, @PathParam("likelihoodId") final Long likelihoodId) {
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(PovertyLineApiConstants.POVERTY_LINE_RESOURCE_NAME);
|
this.context.authenticatedUser().validateHasReadPermission(PovertyLineApiConstants.POVERTY_LINE_RESOURCE_NAME);
|
||||||
|
|
||||||
LikeliHoodPovertyLineData likeliHoodPovertyLineData = this.readService.retrieveForLikelihood(ppiName, likelihoodId);
|
LikeliHoodPovertyLineData likeliHoodPovertyLineData = this.readService.retrieveForLikelihood(ppiName, likelihoodId);
|
||||||
|
|
||||||
return this.likelihoodToApiJsonSerializer.serialize(likeliHoodPovertyLineData);
|
return this.likelihoodToApiJsonSerializer.serialize(likeliHoodPovertyLineData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-41
@@ -1,17 +1,23 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.api;
|
package org.mifosplatform.infrastructure.survey.api;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import java.util.List;
|
||||||
|
|
||||||
|
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.MediaType;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
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.ApiParameterHelper;
|
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonQuery;
|
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
|
|
||||||
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.dataqueries.data.DatatableData;
|
|
||||||
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.service.GenericDataService;
|
import org.mifosplatform.infrastructure.dataqueries.service.GenericDataService;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
@@ -19,22 +25,12 @@ import org.mifosplatform.infrastructure.survey.data.ClientScoresOverview;
|
|||||||
import org.mifosplatform.infrastructure.survey.data.SurveyData;
|
import org.mifosplatform.infrastructure.survey.data.SurveyData;
|
||||||
import org.mifosplatform.infrastructure.survey.data.SurveyDataTableData;
|
import org.mifosplatform.infrastructure.survey.data.SurveyDataTableData;
|
||||||
import org.mifosplatform.infrastructure.survey.service.ReadSurveyService;
|
import org.mifosplatform.infrastructure.survey.service.ReadSurveyService;
|
||||||
import org.mifosplatform.infrastructure.survey.service.ReadSurveyServiceImpl;
|
|
||||||
import org.mifosplatform.portfolio.client.domain.Client;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
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.lang.reflect.Array;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Cieyou on 2/27/14.
|
* Created by Cieyou on 2/27/14.
|
||||||
*/
|
*/
|
||||||
@@ -53,12 +49,10 @@ public class SurveyApiResource {
|
|||||||
private final static Logger logger = LoggerFactory.getLogger(SurveyApiResource.class);
|
private final static Logger logger = LoggerFactory.getLogger(SurveyApiResource.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public SurveyApiResource(final DefaultToApiJsonSerializer<SurveyData> toApiJsonSerializer,
|
public SurveyApiResource(final DefaultToApiJsonSerializer<SurveyData> toApiJsonSerializer, final PlatformSecurityContext context,
|
||||||
final PlatformSecurityContext context,
|
final ReadSurveyService readSurveyService, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
||||||
final ReadSurveyService readSurveyService,
|
final DefaultToApiJsonSerializer<ClientScoresOverview> toApiJsonClientScoreOverviewSerializer,
|
||||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
final GenericDataService genericDataService) {
|
||||||
final DefaultToApiJsonSerializer<ClientScoresOverview> toApiJsonClientScoreOverviewSerializer,
|
|
||||||
final GenericDataService genericDataService){
|
|
||||||
|
|
||||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@@ -68,11 +62,10 @@ public class SurveyApiResource {
|
|||||||
this.genericDataService = genericDataService;
|
this.genericDataService = genericDataService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
@GET
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
public String retrieveSurveys() {
|
||||||
public String retrieveSurveys(@Context final UriInfo uriInfo) {
|
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(SurveyApiConstants.SURVEY_RESOURCE_NAME);
|
this.context.authenticatedUser().validateHasReadPermission(SurveyApiConstants.SURVEY_RESOURCE_NAME);
|
||||||
|
|
||||||
@@ -80,7 +73,6 @@ public class SurveyApiResource {
|
|||||||
return this.toApiJsonSerializer.serialize(surveys);
|
return this.toApiJsonSerializer.serialize(surveys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{surveyName}")
|
@Path("{surveyName}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@@ -100,7 +92,7 @@ public class SurveyApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String createDatatableEntry(@PathParam("surveyName") final String datatable, @PathParam("apptableId") final Long apptableId,
|
public String createDatatableEntry(@PathParam("surveyName") final String datatable, @PathParam("apptableId") final Long apptableId,
|
||||||
final String apiRequestBodyAsJson) {
|
final String apiRequestBodyAsJson) {
|
||||||
|
|
||||||
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
|
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
|
||||||
.fullFilSurvey(datatable, apptableId) //
|
.fullFilSurvey(datatable, apptableId) //
|
||||||
@@ -112,13 +104,13 @@ public class SurveyApiResource {
|
|||||||
return this.toApiJsonSerializer.serialize(result);
|
return this.toApiJsonSerializer.serialize(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** FIXME Vishwas what does this API really do? ***/
|
||||||
@GET
|
@GET
|
||||||
@Path("{surveyName}/{clientId}")
|
@Path("{surveyName}/{clientId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String getClientSurveyOverview(@PathParam("surveyName") final String surveyName, @PathParam("clientId") final Long clientId) {
|
public String getClientSurveyOverview(@PathParam("surveyName") final String surveyName, @PathParam("clientId") final Long clientId) {
|
||||||
|
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(SurveyApiConstants.SURVEY_RESOURCE_NAME);
|
this.context.authenticatedUser().validateHasReadPermission(SurveyApiConstants.SURVEY_RESOURCE_NAME);
|
||||||
|
|
||||||
List<ClientScoresOverview> scores = this.readSurveyService.retrieveClientSurveyScoreOverview(clientId);
|
List<ClientScoresOverview> scores = this.readSurveyService.retrieveClientSurveyScoreOverview(clientId);
|
||||||
@@ -126,32 +118,30 @@ public class SurveyApiResource {
|
|||||||
return this.toApiJsonClientScoreOverviewSerializer.serialize(scores);
|
return this.toApiJsonClientScoreOverviewSerializer.serialize(scores);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("{surveyName}/{clientId}/{entryId}")
|
@Path("{surveyName}/{clientId}/{entryId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String getSurveyEntry(@PathParam("surveyName") final String surveyName, @PathParam("clientId") final Long clientId, @PathParam("entryId") final Long entryId) {
|
public String getSurveyEntry(@PathParam("surveyName") final String surveyName, @PathParam("clientId") final Long clientId,
|
||||||
|
@PathParam("entryId") final Long entryId) {
|
||||||
|
|
||||||
this.context.authenticatedUser().validateHasReadPermission(SurveyApiConstants.SURVEY_RESOURCE_NAME);
|
this.context.authenticatedUser().validateHasReadPermission(SurveyApiConstants.SURVEY_RESOURCE_NAME);
|
||||||
|
|
||||||
final GenericResultsetData results = this.readSurveyService.retrieveSurveyEntry(surveyName, clientId,entryId);
|
final GenericResultsetData results = this.readSurveyService.retrieveSurveyEntry(surveyName, clientId, entryId);
|
||||||
|
|
||||||
return this.genericDataService.generateJsonFromGenericResultsetData(results);
|
return this.genericDataService.generateJsonFromGenericResultsetData(results);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("register/{surveyName}/{apptable}")
|
@Path("register/{surveyName}/{apptable}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String register(@PathParam("surveyName") final String datatable, @PathParam("apptable") final String apptable,
|
public String register(@PathParam("surveyName") final String datatable, @PathParam("apptable") final String apptable,
|
||||||
final String apiRequestBodyAsJson) {
|
final String apiRequestBodyAsJson) {
|
||||||
|
|
||||||
|
final CommandWrapper commandRequest = new CommandWrapperBuilder().registerSurvey(datatable, apptable)
|
||||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().registerSurvey( datatable,apptable).withJson(apiRequestBodyAsJson).build();
|
.withJson(apiRequestBodyAsJson).build();
|
||||||
|
|
||||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|
||||||
@@ -167,10 +157,11 @@ public class SurveyApiResource {
|
|||||||
@Path("{surveyName}/{clientId}/{fulfilledId}")
|
@Path("{surveyName}/{clientId}/{fulfilledId}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String deleteDatatableEntries(@PathParam("surveyName") final String surveyName,@PathParam("clientId") final Long clientId, @PathParam("fulfilledId") final Long fulfilledId) {
|
public String deleteDatatableEntries(@PathParam("surveyName") final String surveyName, @PathParam("clientId") final Long clientId,
|
||||||
|
@PathParam("fulfilledId") final Long fulfilledId) {
|
||||||
|
|
||||||
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
|
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
|
||||||
.deleteDatatable(surveyName,clientId, fulfilledId) //
|
.deleteDatatable(surveyName, clientId, fulfilledId) //
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
|
||||||
|
|||||||
+1
-8
@@ -1,19 +1,12 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.service;
|
package org.mifosplatform.infrastructure.survey.service;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.survey.data.LikeliHoodPovertyLineData;
|
import org.mifosplatform.infrastructure.survey.data.LikeliHoodPovertyLineData;
|
||||||
import org.mifosplatform.infrastructure.survey.data.PovertyLineData;
|
|
||||||
import org.mifosplatform.infrastructure.survey.data.PpiPovertyLineData;
|
import org.mifosplatform.infrastructure.survey.data.PpiPovertyLineData;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Cieyou on 3/11/14.
|
|
||||||
*/
|
|
||||||
public interface PovertyLineService {
|
public interface PovertyLineService {
|
||||||
|
|
||||||
PpiPovertyLineData retrieveAll(final String ppiName);
|
PpiPovertyLineData retrieveAll(final String ppiName);
|
||||||
|
|
||||||
LikeliHoodPovertyLineData retrieveForLikelihood(final String ppiName,final Long likelihood);
|
LikeliHoodPovertyLineData retrieveForLikelihood(final String ppiName, final Long likelihood);
|
||||||
|
|
||||||
//PovertyLineData retrieve();
|
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-84
@@ -1,41 +1,34 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.service;
|
package org.mifosplatform.infrastructure.survey.service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||||
import org.mifosplatform.infrastructure.survey.data.LikeliHoodPovertyLineData;
|
import org.mifosplatform.infrastructure.survey.data.LikeliHoodPovertyLineData;
|
||||||
import org.mifosplatform.infrastructure.survey.data.PovertyLineData;
|
import org.mifosplatform.infrastructure.survey.data.PovertyLineData;
|
||||||
import org.mifosplatform.infrastructure.survey.data.PpiPovertyLineData;
|
import org.mifosplatform.infrastructure.survey.data.PpiPovertyLineData;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Cieyou on 3/11/14.
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
public class PovertyLineServiceImpl implements PovertyLineService{
|
public class PovertyLineServiceImpl implements PovertyLineService {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(PovertyLineService.class);
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
PovertyLineServiceImpl(final RoutingDataSource dataSource){
|
PovertyLineServiceImpl(final RoutingDataSource dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.jdbcTemplate = new JdbcTemplate(this.dataSource);
|
this.jdbcTemplate = new JdbcTemplate(this.dataSource);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PpiPovertyLineData retrieveAll(final String ppiName)
|
public PpiPovertyLineData retrieveAll(final String ppiName) {
|
||||||
{
|
|
||||||
|
|
||||||
final SqlRowSet povertyLines = this._getPovertyLines(ppiName);
|
final SqlRowSet povertyLines = this._getPovertyLines(ppiName);
|
||||||
|
|
||||||
@@ -43,123 +36,88 @@ public class PovertyLineServiceImpl implements PovertyLineService{
|
|||||||
|
|
||||||
List<LikeliHoodPovertyLineData> listOfLikeliHoodPovertyLineData = new ArrayList<LikeliHoodPovertyLineData>();
|
List<LikeliHoodPovertyLineData> listOfLikeliHoodPovertyLineData = new ArrayList<LikeliHoodPovertyLineData>();
|
||||||
|
|
||||||
while(likelihoods.next())
|
while (likelihoods.next()) {
|
||||||
{
|
final String codeName = likelihoods.getString("code");
|
||||||
final String codeName = likelihoods.getString("code");
|
|
||||||
|
|
||||||
List<PovertyLineData> povertyLineDatas = new ArrayList<PovertyLineData>();
|
List<PovertyLineData> povertyLineDatas = new ArrayList<PovertyLineData>();
|
||||||
|
|
||||||
// create a new povertyLine object when ever it belong to the
|
// create a new povertyLine object when ever it belong to the
|
||||||
// current likelihood
|
// current likelihood
|
||||||
while (povertyLines.next())
|
while (povertyLines.next()) {
|
||||||
{
|
String likelihoodCode = povertyLines.getString("code");
|
||||||
String likelihoodCode = povertyLines.getString("code");
|
|
||||||
|
|
||||||
if(likelihoodCode.equals(codeName))
|
if (likelihoodCode.equals(codeName)) {
|
||||||
{
|
povertyLineDatas.add(new PovertyLineData(povertyLines.getLong("id"), povertyLines.getLong("score_from"), povertyLines
|
||||||
povertyLineDatas.add(new PovertyLineData(
|
.getLong("score_to"), povertyLines.getDouble("poverty_line")));
|
||||||
povertyLines.getLong("id"),
|
}
|
||||||
povertyLines.getLong("score_from"),
|
}
|
||||||
povertyLines.getLong("score_to"),
|
|
||||||
povertyLines.getDouble("poverty_line")
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
povertyLines.beforeFirst();
|
povertyLines.beforeFirst();
|
||||||
|
|
||||||
// create the likelihood object with the list of povertyLine object
|
// create the likelihood object with the list of povertyLine object
|
||||||
// belonging to it
|
// belonging to it
|
||||||
|
|
||||||
LikeliHoodPovertyLineData likeliHoodPovertyLineData = new LikeliHoodPovertyLineData(
|
LikeliHoodPovertyLineData likeliHoodPovertyLineData = new LikeliHoodPovertyLineData(likelihoods.getLong("id"),
|
||||||
likelihoods.getLong("id"),
|
povertyLineDatas, likelihoods.getString("name"), likelihoods.getString("code"), likelihoods.getLong("enabled"));
|
||||||
povertyLineDatas,
|
|
||||||
likelihoods.getString("name"),
|
|
||||||
likelihoods.getString("code"),
|
|
||||||
likelihoods.getLong("enabled")
|
|
||||||
);
|
|
||||||
|
|
||||||
listOfLikeliHoodPovertyLineData.add(likeliHoodPovertyLineData);
|
listOfLikeliHoodPovertyLineData.add(likeliHoodPovertyLineData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PpiPovertyLineData ppiPovertyLineData = new PpiPovertyLineData(listOfLikeliHoodPovertyLineData,ppiName);
|
PpiPovertyLineData ppiPovertyLineData = new PpiPovertyLineData(listOfLikeliHoodPovertyLineData, ppiName);
|
||||||
|
|
||||||
return ppiPovertyLineData;
|
return ppiPovertyLineData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LikeliHoodPovertyLineData retrieveForLikelihood(final String ppiName, final Long likelihoodId)
|
public LikeliHoodPovertyLineData retrieveForLikelihood(final String ppiName, final Long likelihoodId) {
|
||||||
{
|
|
||||||
|
|
||||||
final SqlRowSet povertyLines = this._getPovertyLines(likelihoodId);
|
final SqlRowSet povertyLines = this._getPovertyLines(likelihoodId);
|
||||||
|
|
||||||
List<PovertyLineData> povertyLineDatas = new ArrayList<PovertyLineData>();
|
List<PovertyLineData> povertyLineDatas = new ArrayList<PovertyLineData>();
|
||||||
|
|
||||||
while (povertyLines.next())
|
while (povertyLines.next()) {
|
||||||
{
|
|
||||||
|
|
||||||
povertyLineDatas.add(new PovertyLineData(
|
povertyLineDatas.add(new PovertyLineData(povertyLines.getLong("id"), povertyLines.getLong("score_from"), povertyLines
|
||||||
povertyLines.getLong("id"),
|
.getLong("score_to"), povertyLines.getDouble("poverty_line")));
|
||||||
povertyLines.getLong("score_from"),
|
}
|
||||||
povertyLines.getLong("score_to"),
|
|
||||||
povertyLines.getDouble("poverty_line")
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
povertyLines.first();
|
povertyLines.first();
|
||||||
|
|
||||||
// create the likelihood object with the list of povertyLine object
|
// create the likelihood object with the list of povertyLine object
|
||||||
// belonging to it
|
// belonging to it
|
||||||
|
|
||||||
return new LikeliHoodPovertyLineData(
|
return new LikeliHoodPovertyLineData(povertyLines.getLong("likelihood_id"), povertyLineDatas, povertyLines.getString("name"),
|
||||||
povertyLines.getLong("likelihood_id"),
|
povertyLines.getString("code"), povertyLines.getLong("enabled"));
|
||||||
povertyLineDatas,
|
|
||||||
povertyLines.getString("name"),
|
|
||||||
povertyLines.getString("code"),
|
|
||||||
povertyLines.getLong("enabled")
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqlRowSet _getLikelihoods()
|
private SqlRowSet _getLikelihoods() {
|
||||||
{
|
String sql = "SELECT lkp.id, lkh.code , lkh.name, lkp.enabled " + " FROM ppi_likelihoods lkh "
|
||||||
String sql = "SELECT lkp.id, lkh.code , lkh.name, lkp.enabled "
|
|
||||||
+ " FROM ppi_likelihoods lkh "
|
|
||||||
+ " JOIN ppi_likelihoods_ppi lkp on lkp.likelihood_id = lkh.id ";
|
+ " JOIN ppi_likelihoods_ppi lkp on lkp.likelihood_id = lkh.id ";
|
||||||
return this.jdbcTemplate.queryForRowSet(sql);
|
return this.jdbcTemplate.queryForRowSet(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqlRowSet _getPovertyLines(final String ppiName)
|
private SqlRowSet _getPovertyLines(final String ppiName) {
|
||||||
{
|
|
||||||
String sql = "SELECT pl.id, sc.score_from, sc.score_to , pl.poverty_line,lkh.code , lkh.name , lkp.ppi_name "
|
String sql = "SELECT pl.id, sc.score_from, sc.score_to , pl.poverty_line,lkh.code , lkh.name , lkp.ppi_name "
|
||||||
+ " FROM ppi_poverty_line pl "
|
+ " FROM ppi_poverty_line pl " + " JOIN ppi_likelihoods lkh on lkh.id = pl.likelihood_ppi_id "
|
||||||
+ " JOIN ppi_likelihoods lkh on lkh.id = pl.likelihood_ppi_id "
|
+ " JOIN ppi_likelihoods_ppi lkp on lkp.id = pl.likelihood_ppi_id " + " JOIN ppi_scores sc on sc.id = pl.score_id "
|
||||||
+ " JOIN ppi_likelihoods_ppi lkp on lkp.id = pl.likelihood_ppi_id "
|
|
||||||
+ " JOIN ppi_scores sc on sc.id = pl.score_id "
|
|
||||||
+ " WHERE lkp.ppi_name = ? ";
|
+ " WHERE lkp.ppi_name = ? ";
|
||||||
|
|
||||||
return this.jdbcTemplate.queryForRowSet(sql, new Object[] {ppiName});
|
return this.jdbcTemplate.queryForRowSet(sql, new Object[] { ppiName });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqlRowSet _getPovertyLines(final Long likelihoodId)
|
private SqlRowSet _getPovertyLines(final Long likelihoodId) {
|
||||||
{
|
|
||||||
String sql = "SELECT pl.id, sc.score_from, sc.score_to , pl.poverty_line,lkh.code , lkp.enabled, lkp.id as likelihood_id , lkh.name , lkp.ppi_name "
|
String sql = "SELECT pl.id, sc.score_from, sc.score_to , pl.poverty_line,lkh.code , lkp.enabled, lkp.id as likelihood_id , lkh.name , lkp.ppi_name "
|
||||||
+ " FROM ppi_poverty_line pl "
|
+ " FROM ppi_poverty_line pl "
|
||||||
+" JOIN ppi_likelihoods_ppi lkp on lkp.id = pl.likelihood_ppi_id "
|
+ " JOIN ppi_likelihoods_ppi lkp on lkp.id = pl.likelihood_ppi_id "
|
||||||
+" JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_id "
|
+ " JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_id "
|
||||||
+ " JOIN ppi_scores sc on sc.id = pl.score_id "
|
+ " JOIN ppi_scores sc on sc.id = pl.score_id "
|
||||||
+ " WHERE pl.likelihood_ppi_id = ? ";
|
+ " WHERE pl.likelihood_ppi_id = ? ";
|
||||||
|
|
||||||
return this.jdbcTemplate.queryForRowSet(sql, new Object[] {likelihoodId});
|
return this.jdbcTemplate.queryForRowSet(sql, new Object[] { likelihoodId });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// public PovertyLineData retrieve()
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-46
@@ -1,98 +1,76 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.service;
|
package org.mifosplatform.infrastructure.survey.service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||||
import org.mifosplatform.infrastructure.survey.data.LikelihoodData;
|
import org.mifosplatform.infrastructure.survey.data.LikelihoodData;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Cieyou on 3/12/14.
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
public class ReadLikelihoodServiceImpl implements ReadLikelihoodService {
|
public class ReadLikelihoodServiceImpl implements ReadLikelihoodService {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(PovertyLineService.class);
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ReadLikelihoodServiceImpl(final RoutingDataSource dataSource){
|
ReadLikelihoodServiceImpl(final RoutingDataSource dataSource) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.jdbcTemplate = new JdbcTemplate(this.dataSource);
|
this.jdbcTemplate = new JdbcTemplate(this.dataSource);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<LikelihoodData> retrieveAll(final String ppiName)
|
public List<LikelihoodData> retrieveAll(final String ppiName) {
|
||||||
{
|
final SqlRowSet likelihood = this._getLikelihood(ppiName);
|
||||||
final SqlRowSet likelihood =this._getLikelihood(ppiName);
|
|
||||||
|
|
||||||
List<LikelihoodData> likelihoodDatas = new ArrayList<LikelihoodData>();
|
List<LikelihoodData> likelihoodDatas = new ArrayList<LikelihoodData>();
|
||||||
|
|
||||||
while(likelihood.next())
|
while (likelihood.next()) {
|
||||||
{
|
likelihoodDatas.add(new LikelihoodData(likelihood.getLong("id"), likelihood.getString("name"), likelihood.getString("code"),
|
||||||
likelihoodDatas.add(new LikelihoodData(
|
likelihood.getLong("enabled")
|
||||||
likelihood.getLong("id"),
|
|
||||||
likelihood.getString("name"),
|
|
||||||
likelihood.getString("code"),
|
|
||||||
likelihood.getLong("enabled")
|
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return likelihoodDatas;
|
return likelihoodDatas;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqlRowSet _getLikelihood(final String ppiName)
|
private SqlRowSet _getLikelihood(final String ppiName) {
|
||||||
{
|
String sql = "SELECT lkp.id, lkh.code , lkh.name, lkp.enabled " + " FROM ppi_poverty_line pl "
|
||||||
String sql = "SELECT lkp.id, lkh.code , lkh.name, lkp.enabled "
|
|
||||||
+ " FROM ppi_poverty_line pl "
|
|
||||||
+ " JOIN ppi_likelihoods_ppi lkp on lkp.id = pl.likelihood_ppi_id "
|
+ " JOIN ppi_likelihoods_ppi lkp on lkp.id = pl.likelihood_ppi_id "
|
||||||
+ " JOIN ppi_likelihoods lkh on lkp.likelihood_id = lkh.id "
|
+ " JOIN ppi_likelihoods lkh on lkp.likelihood_id = lkh.id " + " WHERE lkp.ppi_name = ? "
|
||||||
+ " WHERE lkp.ppi_name = ? "
|
|
||||||
+ " GROUP BY pl.likelihood_ppi_id ";
|
+ " GROUP BY pl.likelihood_ppi_id ";
|
||||||
|
|
||||||
return this.jdbcTemplate.queryForRowSet(sql, new Object[] {ppiName});
|
return this.jdbcTemplate.queryForRowSet(sql, new Object[] { ppiName });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LikelihoodData retrieve(final Long likelihoodId)
|
public LikelihoodData retrieve(final Long likelihoodId) {
|
||||||
{
|
final SqlRowSet likelihood = this._getLikelihood(likelihoodId);
|
||||||
final SqlRowSet likelihood =this._getLikelihood(likelihoodId);
|
|
||||||
|
|
||||||
likelihood.first();
|
likelihood.first();
|
||||||
|
|
||||||
return new LikelihoodData(
|
return new LikelihoodData(likelihood.getLong("id"), likelihood.getString("name"), likelihood.getString("code"),
|
||||||
likelihood.getLong("id"),
|
likelihood.getLong("enabled")
|
||||||
likelihood.getString("name"),
|
|
||||||
likelihood.getString("code"),
|
|
||||||
likelihood.getLong("enabled")
|
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqlRowSet _getLikelihood(final Long likelihoodId)
|
private SqlRowSet _getLikelihood(final Long likelihoodId) {
|
||||||
{
|
String sql = "SELECT lkp.id, lkh.code , lkh.name, lkp.enabled " + " FROM ppi_likelihoods lkh "
|
||||||
String sql = "SELECT lkp.id, lkh.code , lkh.name, lkp.enabled "
|
+ " JOIN ppi_likelihoods_ppi lkp on lkp.likelihood_id = lkh.id " + " WHERE lkp.id = ? ";
|
||||||
+ " FROM ppi_likelihoods lkh "
|
|
||||||
+ " JOIN ppi_likelihoods_ppi lkp on lkp.likelihood_id = lkh.id "
|
|
||||||
+ " WHERE lkp.id = ? ";
|
|
||||||
|
|
||||||
return this.jdbcTemplate.queryForRowSet(sql, new Object[] {likelihoodId});
|
return this.jdbcTemplate.queryForRowSet(sql, new Object[] { likelihoodId });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-7
@@ -1,12 +1,11 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.service;
|
package org.mifosplatform.infrastructure.survey.service;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
|
import java.util.List;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
||||||
import org.mifosplatform.infrastructure.survey.data.ClientScoresOverview;
|
import org.mifosplatform.infrastructure.survey.data.ClientScoresOverview;
|
||||||
import org.mifosplatform.infrastructure.survey.data.SurveyDataTableData;
|
import org.mifosplatform.infrastructure.survey.data.SurveyDataTableData;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Cieyou on 2/27/14.
|
* Created by Cieyou on 2/27/14.
|
||||||
*/
|
*/
|
||||||
@@ -16,11 +15,10 @@ public interface ReadSurveyService {
|
|||||||
|
|
||||||
SurveyDataTableData retrieveSurvey(String surveyName);
|
SurveyDataTableData retrieveSurvey(String surveyName);
|
||||||
|
|
||||||
List<ClientScoresOverview>retrieveClientSurveyScoreOverview(String surveyName, Long clientId);
|
List<ClientScoresOverview> retrieveClientSurveyScoreOverview(String surveyName, Long clientId);
|
||||||
List<ClientScoresOverview>retrieveClientSurveyScoreOverview(Long clientId);
|
|
||||||
|
List<ClientScoresOverview> retrieveClientSurveyScoreOverview(Long clientId);
|
||||||
|
|
||||||
GenericResultsetData retrieveSurveyEntry(String surveyName, Long clientId, Long entryId);
|
GenericResultsetData retrieveSurveyEntry(String surveyName, Long clientId, Long entryId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+54
-96
@@ -1,7 +1,11 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.service;
|
package org.mifosplatform.infrastructure.survey.service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.joda.time.LocalDate;
|
import org.joda.time.LocalDate;
|
||||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
|
||||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant;
|
import org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant;
|
||||||
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
|
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
|
||||||
@@ -13,18 +17,11 @@ import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext
|
|||||||
import org.mifosplatform.infrastructure.survey.data.ClientScoresOverview;
|
import org.mifosplatform.infrastructure.survey.data.ClientScoresOverview;
|
||||||
import org.mifosplatform.infrastructure.survey.data.LikelihoodStatus;
|
import org.mifosplatform.infrastructure.survey.data.LikelihoodStatus;
|
||||||
import org.mifosplatform.infrastructure.survey.data.SurveyDataTableData;
|
import org.mifosplatform.infrastructure.survey.data.SurveyDataTableData;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ReadSurveyServiceImpl implements ReadSurveyService {
|
public class ReadSurveyServiceImpl implements ReadSurveyService {
|
||||||
|
|
||||||
@@ -33,14 +30,10 @@ public class ReadSurveyServiceImpl implements ReadSurveyService {
|
|||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
private final GenericDataService genericDataService;
|
private final GenericDataService genericDataService;
|
||||||
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
||||||
private final static Logger logger = LoggerFactory.getLogger(ReadSurveyServiceImpl.class);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ReadSurveyServiceImpl(final PlatformSecurityContext context,
|
public ReadSurveyServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource,
|
||||||
final RoutingDataSource dataSource,
|
final GenericDataService genericDataService, final ReadWriteNonCoreDataService readWriteNonCoreDataService) {
|
||||||
final FromJsonHelper fromJsonHelper,
|
|
||||||
final GenericDataService genericDataService,
|
|
||||||
final ReadWriteNonCoreDataService readWriteNonCoreDataService){
|
|
||||||
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
@@ -50,8 +43,7 @@ public class ReadSurveyServiceImpl implements ReadSurveyService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SurveyDataTableData> retrieveAllSurveys()
|
public List<SurveyDataTableData> retrieveAllSurveys() {
|
||||||
{
|
|
||||||
|
|
||||||
String sql = this.retrieveAllSurveySQL("");
|
String sql = this.retrieveAllSurveySQL("");
|
||||||
|
|
||||||
@@ -65,38 +57,30 @@ public class ReadSurveyServiceImpl implements ReadSurveyService {
|
|||||||
final List<ResultsetColumnHeaderData> columnHeaderData = this.genericDataService
|
final List<ResultsetColumnHeaderData> columnHeaderData = this.genericDataService
|
||||||
.fillResultsetColumnHeaders(registeredDatatableName);
|
.fillResultsetColumnHeaders(registeredDatatableName);
|
||||||
|
|
||||||
surveyDataTables.add(
|
surveyDataTables.add(SurveyDataTableData.create(DatatableData.create(appTableName, registeredDatatableName, columnHeaderData),
|
||||||
SurveyDataTableData.create(
|
enabled));
|
||||||
DatatableData.create(appTableName, registeredDatatableName, columnHeaderData),
|
|
||||||
enabled
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return surveyDataTables;
|
return surveyDataTables;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String retrieveAllSurveySQL(String andClause )
|
private String retrieveAllSurveySQL(String andClause) {
|
||||||
{
|
|
||||||
// PERMITTED datatables
|
// PERMITTED datatables
|
||||||
return "select application_table_name, cf.enabled, registered_table_name" + " from x_registered_table "
|
return "select application_table_name, cf.enabled, registered_table_name" + " from x_registered_table "
|
||||||
+ " left join c_configuration cf on x_registered_table.registered_table_name = cf.name "
|
+ " left join c_configuration cf on x_registered_table.registered_table_name = cf.name " + " where exists" + " (select 'f'"
|
||||||
+ " where exists"
|
+ " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id"
|
||||||
+ " (select 'f'" + " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id"
|
|
||||||
+ " left join m_role_permission rp on rp.role_id = r.id" + " left join m_permission p on p.id = rp.permission_id"
|
+ " left join m_role_permission rp on rp.role_id = r.id" + " left join m_permission p on p.id = rp.permission_id"
|
||||||
+ " where ur.appuser_id = " + this.context.authenticatedUser().getId()
|
+ " where ur.appuser_id = " + this.context.authenticatedUser().getId()
|
||||||
+ " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', registered_table_name))) "
|
+ " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', registered_table_name))) "
|
||||||
+ " and x_registered_table.category = "+ DataTableApiConstant.CATEGORY_PPI
|
+ " and x_registered_table.category = " + DataTableApiConstant.CATEGORY_PPI + andClause
|
||||||
+ andClause + " order by application_table_name, registered_table_name";
|
+ " order by application_table_name, registered_table_name";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SurveyDataTableData retrieveSurvey(String surveyName)
|
public SurveyDataTableData retrieveSurvey(String surveyName) {
|
||||||
{
|
|
||||||
final String sql = "select cf.enabled, application_table_name, registered_table_name" + " from x_registered_table "
|
final String sql = "select cf.enabled, application_table_name, registered_table_name" + " from x_registered_table "
|
||||||
+ " left join c_configuration cf on x_registered_table.registered_table_name = cf.name "
|
+ " left join c_configuration cf on x_registered_table.registered_table_name = cf.name " + " where exists" + " (select 'f'"
|
||||||
+ " where exists"
|
+ " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id"
|
||||||
+ " (select 'f'" + " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id"
|
|
||||||
+ " left join m_role_permission rp on rp.role_id = r.id" + " left join m_permission p on p.id = rp.permission_id"
|
+ " left join m_role_permission rp on rp.role_id = r.id" + " left join m_permission p on p.id = rp.permission_id"
|
||||||
+ " where ur.appuser_id = " + this.context.authenticatedUser().getId() + " and registered_table_name='" + surveyName + "'"
|
+ " where ur.appuser_id = " + this.context.authenticatedUser().getId() + " and registered_table_name='" + surveyName + "'"
|
||||||
+ " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', registered_table_name))) "
|
+ " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', registered_table_name))) "
|
||||||
@@ -112,109 +96,83 @@ public class ReadSurveyServiceImpl implements ReadSurveyService {
|
|||||||
final List<ResultsetColumnHeaderData> columnHeaderData = this.genericDataService
|
final List<ResultsetColumnHeaderData> columnHeaderData = this.genericDataService
|
||||||
.fillResultsetColumnHeaders(registeredDatatableName);
|
.fillResultsetColumnHeaders(registeredDatatableName);
|
||||||
|
|
||||||
datatableData = SurveyDataTableData.create(
|
datatableData = SurveyDataTableData.create(DatatableData.create(appTableName, registeredDatatableName, columnHeaderData),
|
||||||
DatatableData.create(appTableName, registeredDatatableName, columnHeaderData),
|
enabled);
|
||||||
enabled
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return datatableData;
|
return datatableData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ClientScoresOverview> retrieveClientSurveyScoreOverview(String surveyName, Long clientId)
|
@Override
|
||||||
{
|
public List<ClientScoresOverview> retrieveClientSurveyScoreOverview(String surveyName, Long clientId) {
|
||||||
|
|
||||||
final String sql = "SELECT tz.id, lkh.name, lkh.code, poverty_line, tz.date, tz.score FROM "+surveyName+" tz"
|
final String sql = "SELECT tz.id, lkh.name, lkh.code, poverty_line, tz.date, tz.score FROM " + surveyName + " tz"
|
||||||
+" JOIN ppi_likelihoods_ppi lkp on lkp.ppi_name = '"+surveyName+"' AND enabled = '"+ LikelihoodStatus.ENABLED
|
+ " JOIN ppi_likelihoods_ppi lkp on lkp.ppi_name = '" + surveyName + "' AND enabled = '" + LikelihoodStatus.ENABLED
|
||||||
+"' JOIN ppi_scores sc on score_from <= tz.score AND score_to >=tz.score"
|
+ "' JOIN ppi_scores sc on score_from <= tz.score AND score_to >=tz.score"
|
||||||
+" JOIN ppi_poverty_line pvl on pvl.likelihood_ppi_id = lkp.id AND pvl.score_id = sc.id"
|
+ " JOIN ppi_poverty_line pvl on pvl.likelihood_ppi_id = lkp.id AND pvl.score_id = sc.id"
|
||||||
+" JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_id "
|
+ " JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_id " + " WHERE client_id = " + clientId;
|
||||||
+" WHERE client_id = "+clientId;
|
|
||||||
|
|
||||||
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
||||||
|
|
||||||
List<ClientScoresOverview> scoresOverviews = new ArrayList<ClientScoresOverview>();
|
List<ClientScoresOverview> scoresOverviews = new ArrayList<ClientScoresOverview>();
|
||||||
|
|
||||||
while(rs.next())
|
while (rs.next()) {
|
||||||
{
|
scoresOverviews.add(new ClientScoresOverview(rs.getString("code"), rs.getString("name"), rs.getLong("score"), rs
|
||||||
scoresOverviews.add(new ClientScoresOverview(
|
.getDouble("poverty_line"), new LocalDate(rs.getTimestamp("date").getTime()), rs.getLong("id"), surveyName));
|
||||||
rs.getString("code"),
|
|
||||||
rs.getString("name"),
|
|
||||||
rs.getLong("score"),
|
|
||||||
rs.getDouble("poverty_line"),
|
|
||||||
new LocalDate(rs.getTimestamp("date").getTime()),
|
|
||||||
rs.getLong("id"),
|
|
||||||
surveyName
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return scoresOverviews;
|
||||||
return scoresOverviews ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ClientScoresOverview> retrieveClientSurveyScoreOverview(Long clientId)
|
@Override
|
||||||
{
|
public List<ClientScoresOverview> retrieveClientSurveyScoreOverview(Long clientId) {
|
||||||
final String surveyNameSql = retrieveAllSurveyNameSQL();
|
final String surveyNameSql = retrieveAllSurveyNameSQL();
|
||||||
final SqlRowSet surveyNames = this.jdbcTemplate.queryForRowSet(surveyNameSql);
|
final SqlRowSet surveyNames = this.jdbcTemplate.queryForRowSet(surveyNameSql);
|
||||||
|
|
||||||
ArrayList<String> sqls = new ArrayList<String>();
|
ArrayList<String> sqls = new ArrayList<String>();
|
||||||
|
|
||||||
while(surveyNames .next())
|
while (surveyNames.next()) {
|
||||||
{
|
sqls.add("SELECT '" + surveyNames.getString("name")
|
||||||
sqls.add( "SELECT '"+surveyNames.getString("name") +"' as surveyName, tz.id, lkh.name, lkh.code, poverty_line, tz.date, tz.score FROM "+surveyNames.getString("name")+" tz"
|
+ "' as surveyName, tz.id, lkh.name, lkh.code, poverty_line, tz.date, tz.score FROM " + surveyNames.getString("name")
|
||||||
+" JOIN ppi_likelihoods_ppi lkp on lkp.ppi_name = '"+surveyNames.getString("name")+"' AND enabled = '"+ LikelihoodStatus.ENABLED
|
+ " tz" + " JOIN ppi_likelihoods_ppi lkp on lkp.ppi_name = '" + surveyNames.getString("name") + "' AND enabled = '"
|
||||||
+"' JOIN ppi_scores sc on score_from <= tz.score AND score_to >=tz.score"
|
+ LikelihoodStatus.ENABLED + "' JOIN ppi_scores sc on score_from <= tz.score AND score_to >=tz.score"
|
||||||
+" JOIN ppi_poverty_line pvl on pvl.likelihood_ppi_id = lkp.id AND pvl.score_id = sc.id"
|
+ " JOIN ppi_poverty_line pvl on pvl.likelihood_ppi_id = lkp.id AND pvl.score_id = sc.id"
|
||||||
+" JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_id "
|
+ " JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_id " + " WHERE client_id = " + clientId);
|
||||||
+" WHERE client_id = "+clientId );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ClientScoresOverview> scoresOverviews = new ArrayList<ClientScoresOverview>();
|
List<ClientScoresOverview> scoresOverviews = new ArrayList<ClientScoresOverview>();
|
||||||
|
|
||||||
for(String sql:sqls)
|
for (String sql : sqls) {
|
||||||
{
|
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
||||||
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
|
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
scoresOverviews.add(new ClientScoresOverview(rs.getString("code"), rs.getString("name"), rs.getLong("score"), rs
|
||||||
while(rs.next())
|
.getDouble("poverty_line"), new LocalDate(rs.getTimestamp("date").getTime()), rs.getLong("id"), rs
|
||||||
{
|
.getString("surveyName")));
|
||||||
scoresOverviews.add(new ClientScoresOverview(
|
|
||||||
rs.getString("code"),
|
|
||||||
rs.getString("name"),
|
|
||||||
rs.getLong("score"),
|
|
||||||
rs.getDouble("poverty_line"),
|
|
||||||
new LocalDate(rs.getTimestamp("date").getTime()),
|
|
||||||
rs.getLong("id"),
|
|
||||||
rs.getString("surveyName")
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return scoresOverviews ;
|
return scoresOverviews;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String retrieveAllSurveyNameSQL()
|
private String retrieveAllSurveyNameSQL() {
|
||||||
{
|
|
||||||
// PERMITTED datatables
|
// PERMITTED datatables
|
||||||
return "select cf.name from x_registered_table "
|
return "select cf.name from x_registered_table "
|
||||||
+ " join c_configuration cf on x_registered_table.registered_table_name = cf.name "
|
+ " join c_configuration cf on x_registered_table.registered_table_name = cf.name " + " where exists" + " (select 'f'"
|
||||||
+ " where exists"
|
+ " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id"
|
||||||
+ " (select 'f'" + " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id"
|
|
||||||
+ " left join m_role_permission rp on rp.role_id = r.id" + " left join m_permission p on p.id = rp.permission_id"
|
+ " left join m_role_permission rp on rp.role_id = r.id" + " left join m_permission p on p.id = rp.permission_id"
|
||||||
+ " where ur.appuser_id = " + this.context.authenticatedUser().getId()
|
+ " where ur.appuser_id = " + this.context.authenticatedUser().getId()
|
||||||
+ " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', registered_table_name))) "
|
+ " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', registered_table_name))) "
|
||||||
+ " and x_registered_table.category = "+ DataTableApiConstant.CATEGORY_PPI
|
+ " and x_registered_table.category = " + DataTableApiConstant.CATEGORY_PPI
|
||||||
+ " order by application_table_name, registered_table_name";
|
+ " order by application_table_name, registered_table_name";
|
||||||
}
|
}
|
||||||
|
|
||||||
public GenericResultsetData retrieveSurveyEntry(String surveyName, Long clientId, Long entryId)
|
@Override
|
||||||
{
|
public GenericResultsetData retrieveSurveyEntry(String surveyName, Long clientId, Long entryId) {
|
||||||
|
|
||||||
return readWriteNonCoreDataService.retrieveDataTableGenericResultSet(surveyName, clientId,
|
return readWriteNonCoreDataService.retrieveDataTableGenericResultSet(surveyName, clientId, null, entryId);
|
||||||
null, entryId);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-26
@@ -1,47 +1,35 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.service;
|
package org.mifosplatform.infrastructure.survey.service;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import java.util.List;
|
||||||
import org.mifosplatform.infrastructure.configuration.domain.GlobalConfigurationProperty;
|
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
|
||||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
||||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.infrastructure.survey.data.LikelihoodDataValidator;
|
import org.mifosplatform.infrastructure.survey.data.LikelihoodDataValidator;
|
||||||
import org.mifosplatform.infrastructure.survey.data.LikelihoodStatus;
|
|
||||||
import org.mifosplatform.infrastructure.survey.domain.Likelihood;
|
import org.mifosplatform.infrastructure.survey.domain.Likelihood;
|
||||||
import org.mifosplatform.infrastructure.survey.domain.LikelihoodRepository;
|
import org.mifosplatform.infrastructure.survey.domain.LikelihoodRepository;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Cieyou on 3/12/14.
|
* Created by Cieyou on 3/12/14.
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class WriteLikelihoodServiceImpl implements WriteLikelihoodService{
|
public class WriteLikelihoodServiceImpl implements WriteLikelihoodService {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(PovertyLineService.class);
|
private final static Logger logger = LoggerFactory.getLogger(PovertyLineService.class);
|
||||||
private final JdbcTemplate jdbcTemplate;
|
|
||||||
private final DataSource dataSource;
|
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final LikelihoodDataValidator likelihoodDataValidator;
|
private final LikelihoodDataValidator likelihoodDataValidator;
|
||||||
private final LikelihoodRepository repository;
|
private final LikelihoodRepository repository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
WriteLikelihoodServiceImpl (final RoutingDataSource dataSource,
|
WriteLikelihoodServiceImpl(final PlatformSecurityContext context, final LikelihoodDataValidator likelihoodDataValidator,
|
||||||
final PlatformSecurityContext context,
|
final LikelihoodRepository repository) {
|
||||||
final LikelihoodDataValidator likelihoodDataValidator,
|
|
||||||
final LikelihoodRepository repository){
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
this.jdbcTemplate = new JdbcTemplate(this.dataSource);
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.likelihoodDataValidator = likelihoodDataValidator;
|
this.likelihoodDataValidator = likelihoodDataValidator;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
@@ -49,8 +37,7 @@ public class WriteLikelihoodServiceImpl implements WriteLikelihoodService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult update(Long likelihoodId, JsonCommand command)
|
public CommandProcessingResult update(Long likelihoodId, JsonCommand command) {
|
||||||
{
|
|
||||||
|
|
||||||
this.context.authenticatedUser();
|
this.context.authenticatedUser();
|
||||||
|
|
||||||
@@ -60,16 +47,14 @@ public class WriteLikelihoodServiceImpl implements WriteLikelihoodService{
|
|||||||
|
|
||||||
final Likelihood likelihood = this.repository.findOne(likelihoodId);
|
final Likelihood likelihood = this.repository.findOne(likelihoodId);
|
||||||
|
|
||||||
|
|
||||||
if (!likelihood.update(command).isEmpty()) {
|
if (!likelihood.update(command).isEmpty()) {
|
||||||
this.repository.save(likelihood);
|
this.repository.save(likelihood);
|
||||||
|
|
||||||
if(likelihood.isActivateCommand(command))
|
if (likelihood.isActivateCommand(command)) {
|
||||||
{
|
List<Likelihood> likelihoods = this.repository
|
||||||
List<Likelihood> likelihoods = this.repository.findByPpiNameAndLikeliHoodId(likelihood.getPpiName(),likelihood.getId());
|
.findByPpiNameAndLikeliHoodId(likelihood.getPpiName(), likelihood.getId());
|
||||||
|
|
||||||
for(Likelihood aLikelihood:likelihoods)
|
for (Likelihood aLikelihood : likelihoods) {
|
||||||
{
|
|
||||||
aLikelihood.disable();
|
aLikelihood.disable();
|
||||||
}
|
}
|
||||||
this.repository.save(likelihoods);
|
this.repository.save(likelihoods);
|
||||||
@@ -86,7 +71,6 @@ public class WriteLikelihoodServiceImpl implements WriteLikelihoodService{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Guaranteed to throw an exception no matter what the data integrity issue
|
* Guaranteed to throw an exception no matter what the data integrity issue
|
||||||
* is.
|
* is.
|
||||||
|
|||||||
+10
-88
@@ -1,77 +1,29 @@
|
|||||||
package org.mifosplatform.infrastructure.survey.service;
|
package org.mifosplatform.infrastructure.survey.service;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
|
|
||||||
import org.mifosplatform.infrastructure.core.serialization.DatatableCommandFromApiJsonDeserializer;
|
|
||||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
|
||||||
import org.mifosplatform.infrastructure.core.serialization.JsonParserHelper;
|
|
||||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
|
||||||
import org.mifosplatform.infrastructure.dataqueries.data.DataTableValidator;
|
|
||||||
import org.mifosplatform.infrastructure.dataqueries.data.ResultsetColumnHeaderData;
|
|
||||||
import org.mifosplatform.infrastructure.dataqueries.service.GenericDataService;
|
|
||||||
import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService;
|
import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DataAccessException;
|
|
||||||
import org.springframework.dao.DataIntegrityViolationException;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Cieyou on 3/13/14.
|
* Created by Cieyou on 3/13/14.
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class WriteSurveyServiceImpl implements WriteSurveyService {
|
public class WriteSurveyServiceImpl implements WriteSurveyService {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(PovertyLineService.class);
|
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
|
||||||
private final DataSource dataSource;
|
|
||||||
private final PlatformSecurityContext context;
|
|
||||||
private final FromJsonHelper fromJsonHelper;
|
|
||||||
private final JsonParserHelper helper;
|
|
||||||
private final GenericDataService genericDataService;
|
|
||||||
private final DatatableCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
|
||||||
private final DataTableValidator dataTableValidator;
|
|
||||||
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
|
||||||
|
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
WriteSurveyServiceImpl(final RoutingDataSource dataSource,
|
WriteSurveyServiceImpl(final ReadWriteNonCoreDataService readWriteNonCoreDataService) {
|
||||||
final PlatformSecurityContext context,
|
|
||||||
final FromJsonHelper fromJsonHelper,
|
|
||||||
final GenericDataService genericDataService,
|
|
||||||
final DatatableCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
|
||||||
final DataTableValidator dataTableValidator,
|
|
||||||
final ReadWriteNonCoreDataService readWriteNonCoreDataService) {
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
this.jdbcTemplate = new JdbcTemplate(this.dataSource);
|
|
||||||
this.context = context;
|
|
||||||
this.fromJsonHelper = fromJsonHelper;
|
|
||||||
this.helper = new JsonParserHelper();
|
|
||||||
this.genericDataService = genericDataService;
|
|
||||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
|
||||||
this.dataTableValidator = dataTableValidator;
|
|
||||||
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
|
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommandProcessingResult registerSurvey(JsonCommand command)
|
public CommandProcessingResult registerSurvey(JsonCommand command) {
|
||||||
{
|
|
||||||
|
|
||||||
final String dataTableName = this.readWriteNonCoreDataService.getDataTableName(command.getUrl());
|
final String dataTableName = this.readWriteNonCoreDataService.getDataTableName(command.getUrl());
|
||||||
final String permissionSql = this._getPermissionSql(dataTableName);
|
final String permissionSql = this._getPermissionSql(dataTableName);
|
||||||
@@ -81,8 +33,7 @@ public class WriteSurveyServiceImpl implements WriteSurveyService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String _getPermissionSql(final String dataTableName)
|
private String _getPermissionSql(final String dataTableName) {
|
||||||
{
|
|
||||||
final String createPermission = "'CREATE_" + dataTableName + "'";
|
final String createPermission = "'CREATE_" + dataTableName + "'";
|
||||||
final String createPermissionChecker = "'CREATE_" + dataTableName + "_CHECKER'";
|
final String createPermissionChecker = "'CREATE_" + dataTableName + "_CHECKER'";
|
||||||
final String readPermission = "'READ_" + dataTableName + "'";
|
final String readPermission = "'READ_" + dataTableName + "'";
|
||||||
@@ -91,40 +42,12 @@ public class WriteSurveyServiceImpl implements WriteSurveyService {
|
|||||||
final String deletePermission = "'DELETE_" + dataTableName + "'";
|
final String deletePermission = "'DELETE_" + dataTableName + "'";
|
||||||
final String deletePermissionChecker = "'DELETE_" + dataTableName + "_CHECKER'";
|
final String deletePermissionChecker = "'DELETE_" + dataTableName + "_CHECKER'";
|
||||||
|
|
||||||
return "insert into m_permission (grouping, code, action_name, entity_name, can_maker_checker) values "
|
return "insert into m_permission (grouping, code, action_name, entity_name, can_maker_checker) values " + "('datatable', "
|
||||||
+ "('datatable', "
|
+ createPermission + ", 'CREATE', '" + dataTableName + "', false)," + "('datatable', " + createPermissionChecker
|
||||||
+ createPermission
|
+ ", 'CREATE', '" + dataTableName + "', false)," + "('datatable', " + readPermission + ", 'READ', '" + dataTableName
|
||||||
+ ", 'CREATE', '"
|
+ "', false)," + "('datatable', " + updatePermission + ", 'UPDATE', '" + dataTableName + "', false)," + "('datatable', "
|
||||||
+ dataTableName
|
+ updatePermissionChecker + ", 'UPDATE', '" + dataTableName + "', false)," + "('datatable', " + deletePermission
|
||||||
+ "', false),"
|
+ ", 'DELETE', '" + dataTableName + "', false)," + "('datatable', " + deletePermissionChecker + ", 'DELETE', '"
|
||||||
+ "('datatable', "
|
|
||||||
+ createPermissionChecker
|
|
||||||
+ ", 'CREATE', '"
|
|
||||||
+ dataTableName
|
|
||||||
+ "', false),"
|
|
||||||
+ "('datatable', "
|
|
||||||
+ readPermission
|
|
||||||
+ ", 'READ', '"
|
|
||||||
+ dataTableName
|
|
||||||
+ "', false),"
|
|
||||||
+ "('datatable', "
|
|
||||||
+ updatePermission
|
|
||||||
+ ", 'UPDATE', '"
|
|
||||||
+ dataTableName
|
|
||||||
+ "', false),"
|
|
||||||
+ "('datatable', "
|
|
||||||
+ updatePermissionChecker
|
|
||||||
+ ", 'UPDATE', '"
|
|
||||||
+ dataTableName
|
|
||||||
+ "', false),"
|
|
||||||
+ "('datatable', "
|
|
||||||
+ deletePermission
|
|
||||||
+ ", 'DELETE', '"
|
|
||||||
+ dataTableName
|
|
||||||
+ "', false),"
|
|
||||||
+ "('datatable', "
|
|
||||||
+ deletePermissionChecker
|
|
||||||
+ ", 'DELETE', '"
|
|
||||||
+ dataTableName + "', false)";
|
+ dataTableName + "', false)";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,8 +55,7 @@ public class WriteSurveyServiceImpl implements WriteSurveyService {
|
|||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult fullFillSurvey(final String dataTableName, final Long appTableId, final JsonCommand command) {
|
public CommandProcessingResult fullFillSurvey(final String dataTableName, final Long appTableId, final JsonCommand command) {
|
||||||
|
|
||||||
return readWriteNonCoreDataService.createPPIEntry(dataTableName,appTableId,command);
|
return readWriteNonCoreDataService.createPPIEntry(dataTableName, appTableId, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user