removing most warnings in ppi/survey related code

This commit is contained in:
Vishwas Babu A J
2014-06-06 11:23:50 -07:00
parent b63364962d
commit 8e61abe4ed
17 changed files with 286 additions and 574 deletions
@@ -6,7 +6,6 @@
package org.mifosplatform.infrastructure.dataqueries.api;
import java.util.List;
import java.util.logging.Logger;
import javax.ws.rs.Consumes;
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.ReadWriteNonCoreDataService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
//import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Path("/datatables")
@Component
@@ -53,8 +51,6 @@ public class DatatablesApiResource {
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final static org.slf4j.Logger logger = LoggerFactory.getLogger(DatatablesApiResource.class);
@Autowired
public DatatablesApiResource(final PlatformSecurityContext context, final GenericDataService genericDataService,
final ReadWriteNonCoreDataService readWriteNonCoreDataService,
@@ -117,9 +113,11 @@ public class DatatablesApiResource {
@Path("register/{datatable}/{apptable}")
@Consumes({ 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);
@@ -1,23 +1,25 @@
package org.mifosplatform.infrastructure.dataqueries.data;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.lang.StringUtils;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
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 static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.CATEGORY_DEFAULT;
import static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.CATEGORY_PPI;
import static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.DATATABLE_RESOURCE_NAME;
import static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.REGISTER_PARAMS;
import static org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant.categoryParamName;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
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
public class DataTableValidator {
@@ -31,7 +33,6 @@ public class DataTableValidator {
public void validateDataTableRegistration(final String json) {
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, REGISTER_PARAMS);
@@ -42,7 +43,8 @@ public class DataTableValidator {
if (this.fromApiJsonHelper.parameterExists(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); }
@@ -13,6 +13,7 @@ public class ResultsetColumnValueData {
private final int id;
private final String value;
@SuppressWarnings("unused")
private final Integer score;
public ResultsetColumnValueData(final int id, final String value) {
@@ -20,6 +21,7 @@ public class ResultsetColumnValueData {
this.value = value;
this.score = null;
}
public ResultsetColumnValueData(final int id, final String value, final int score) {
this.id = id;
this.value = value;
@@ -6,13 +6,11 @@
package org.mifosplatform.infrastructure.dataqueries.service;
import java.util.List;
import java.util.Map;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
import org.mifosplatform.infrastructure.dataqueries.data.ResultsetColumnHeaderData;
import org.springframework.security.access.prepost.PreAuthorize;
public interface ReadWriteNonCoreDataService {
@@ -42,6 +40,7 @@ public interface ReadWriteNonCoreDataService {
void deleteDatatable(String datatableName);
CommandProcessingResult createNewDatatableEntry(String datatable, Long appTableId, JsonCommand command);
CommandProcessingResult createPPIEntry(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);
String getTableName(String Url);
String getDataTableName(String Url);
}
@@ -20,11 +20,9 @@ import org.apache.commons.lang.StringUtils;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.exception.GenericJDBCException;
import org.hibernate.exception.SQLGrammarException;
import org.hibernate.service.config.internal.ConfigurationServiceImpl;
import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.codes.service.CodeReadPlatformService;
import org.mifosplatform.infrastructure.configuration.domain.ConfigurationDomainService;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
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.service.RoutingDataSource;
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.DatatableSystemErrorException;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
@@ -46,7 +48,6 @@ import org.mifosplatform.useradministration.domain.AppUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.mifosplatform.infrastructure.configuration.service.GlobalConfigurationWritePlatformServiceJpaRepositoryImpl;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.EmptyResultDataAccessException;
@@ -92,7 +93,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
private final CodeReadPlatformService codeReadPlatformService;
private final DataTableValidator dataTableValidator;
//private final GlobalConfigurationWritePlatformServiceJpaRepositoryImpl configurationWriteService;
// private final GlobalConfigurationWritePlatformServiceJpaRepositoryImpl
// configurationWriteService;
@Autowired(required = true)
public ReadWriteNonCoreDataServiceImpl(final RoutingDataSource dataSource, final PlatformSecurityContext context,
@@ -177,8 +179,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
@Transactional
@Override
public void registerDatatable(final String dataTableName, final String applicationTableName)
{
public void registerDatatable(final String dataTableName, final String applicationTableName) {
Integer category = DataTableApiConstant.CATEGORY_DEFAULT;
@@ -204,8 +205,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
@Transactional
@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 dataTableName = this.getDataTableName(command.getUrl());
@@ -218,11 +218,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
}
@Transactional
private void _registerDataTable(final String applicationTableName,
final String dataTableName,
final Integer category,
final String permissionsSql)
{
private void _registerDataTable(final String applicationTableName, final String dataTableName, final Integer category,
final String permissionsSql) {
validateAppTable(applicationTableName);
assertDataTableExists(dataTableName);
@@ -230,16 +227,13 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
final String registerDatatableSql = "insert into x_registered_table (registered_table_name, application_table_name,category) values ('"
+ dataTableName + "', '" + applicationTableName + "', '" + category + "')";
try {
final String[] sqlArray = { registerDatatableSql, permissionsSql };
this.jdbcTemplate.batchUpdate(sqlArray);
// 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')");
}
@@ -266,11 +260,9 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
"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 createPermissionChecker = "'CREATE_" + dataTableName + "_CHECKER'";
final String readPermission = "'READ_" + dataTableName + "'";
@@ -279,56 +271,27 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
final String deletePermission = "'DELETE_" + dataTableName + "'";
final String deletePermissionChecker = "'DELETE_" + dataTableName + "_CHECKER'";
return "insert into m_permission (grouping, code, action_name, entity_name, can_maker_checker) values "
+ "('datatable', "
+ createPermission
+ ", 'CREATE', '"
+ dataTableName
+ "', true),"
+ "('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', '"
return "insert into m_permission (grouping, code, action_name, entity_name, can_maker_checker) values " + "('datatable', "
+ createPermission + ", 'CREATE', '" + dataTableName + "', true)," + "('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)";
}
private Integer getCategory(final JsonCommand command)
{
private Integer getCategory(final JsonCommand command) {
Integer category = command.integerValueOfParameterNamedDefaultToNullIfZero(DataTableApiConstant.categoryParamName);
if (category == null) category = DataTableApiConstant.CATEGORY_DEFAULT;
return category;
}
private boolean isSurveyCategory(final Integer category)
{
private boolean isSurveyCategory(final Integer category) {
return category.equals(DataTableApiConstant.CATEGORY_PPI);
}
@Override
public String getDataTableName(String url) {
String[] urlParts = url.split("/");
@@ -337,8 +300,8 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
}
public String getTableName(String url)
{
@Override
public String getTableName(String url) {
String[] urlParts = url.split("/");
return urlParts[4];
}
@@ -410,6 +373,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
}
}
@Override
public CommandProcessingResult createPPIEntry(final String dataTableName, final Long appTableId, final JsonCommand command) {
try {
@@ -1075,7 +1039,6 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
public GenericResultsetData retrieveDataTableGenericResultSet(final String dataTableName, final Long appTableId, final String order,
final Long id) {
final String appTable = queryForApplicationTableName(dataTableName);
checkMainResourceExistsWithinScope(appTable, appTableId);
@@ -1315,7 +1278,6 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
} else {
pValueWrite = singleQuote + this.genericDataService.replace(pValue, singleQuote, singleQuote + singleQuote) + singleQuote;
}
columnName = "`" + key + "`";
insertColumns += ", " + columnName;
@@ -1331,8 +1293,9 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
}
/**
* This method is used special for ppi cases
* Where the score need to be computed
* This method is used special for ppi cases Where the score need to be
* computed
*
* @param columnHeaders
* @param datatable
* @param fkName
@@ -1346,7 +1309,6 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
final Map<String, String> affectedColumns = getAffectedColumns(columnHeaders, queryParams, fkName);
String pValueWrite = "";
String addSql = "";
String scoresId = " ";
final String singleQuote = "'";
@@ -1364,23 +1326,17 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ
scoresId += pValueWrite + " ,";
}
columnName = "`" + key + "`";
insertColumns += ", " + columnName;
selectColumns += "," + pValueWrite + " as " + columnName;
}
scoresId = scoresId.replaceAll(" ,$", "");
addSql = "insert into `" + datatable + "` (`" + fkName + "` " + insertColumns + ")" + " select " + appTableId + " as id"
+ selectColumns;
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";
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);
@@ -1,14 +1,11 @@
package org.mifosplatform.infrastructure.survey.api;
import org.mifosplatform.infrastructure.survey.data.LikelihoodStatus;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* Created by Cieyou on 3/12/14.
*/
import org.mifosplatform.infrastructure.survey.data.LikelihoodStatus;
public class LikelihoodApiConstants {
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<Long> VALID_LIKELIHOOD_ENABLED_VALUES = new HashSet<Long>(
Arrays.asList(
LikelihoodStatus.DISABLED,
LikelihoodStatus.ENABLED
));
public static final Set<Long> VALID_LIKELIHOOD_ENABLED_VALUES = new HashSet<Long>(Arrays.asList(LikelihoodStatus.DISABLED,
LikelihoodStatus.ENABLED));
}
@@ -1,5 +1,15 @@
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.service.CommandWrapperBuilder;
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.survey.data.LikelihoodData;
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.context.annotation.Scope;
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.
*/
@@ -26,26 +30,21 @@ import java.util.List;
@Scope("singleton")
public class LikelihoodApiResource {
private final static Logger logger = LoggerFactory.getLogger(PovertyLineApiResource.class);
private final DefaultToApiJsonSerializer<LikelihoodData> toApiJsonSerializer;
private final PlatformSecurityContext context;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final ReadLikelihoodService readService;
@Autowired
LikelihoodApiResource(final PlatformSecurityContext context,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final DefaultToApiJsonSerializer<LikelihoodData> toApiJsonSerializer,
final ReadLikelihoodService readService) {
final DefaultToApiJsonSerializer<LikelihoodData> toApiJsonSerializer, final ReadLikelihoodService readService) {
this.context = context;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.toApiJsonSerializer = toApiJsonSerializer;
this.readService = readService;
}
@GET
@@ -1,11 +1,5 @@
package org.mifosplatform.infrastructure.survey.api;
import org.springframework.stereotype.Service;
/**
* Created by Cieyou on 3/11/14.
*/
public class PovertyLineApiConstants {
final static String POVERTY_LINE_RESOURCE_NAME = "PovertyLine";
@@ -1,50 +1,38 @@
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.security.service.PlatformSecurityContext;
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.service.PovertyLineService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import java.util.List;
/**
* Created by Cieyou on 3/11/14.
*/
@Path("/povertyLine")
@Component
@Scope("singleton")
public class PovertyLineApiResource {
private final static Logger logger = LoggerFactory.getLogger(PovertyLineApiResource.class);
private final DefaultToApiJsonSerializer<PpiPovertyLineData> toApiJsonSerializer;
private final DefaultToApiJsonSerializer<LikeliHoodPovertyLineData> likelihoodToApiJsonSerializer;
// private final DefaultToApiJsonSerializer<PpiPovertyLineData> toApiJsonSerializer;
// private final DefaultToApiJsonSerializer<PpiPovertyLineData>
// toApiJsonSerializer;
private final PlatformSecurityContext context;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final PovertyLineService readService;
@Autowired
PovertyLineApiResource(final PlatformSecurityContext context,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final DefaultToApiJsonSerializer<PpiPovertyLineData> toApiJsonSerializer,
final PovertyLineService readService,
final DefaultToApiJsonSerializer<LikeliHoodPovertyLineData> likelihoodToApiJsonSerializer) {
PovertyLineApiResource(final PlatformSecurityContext context, final DefaultToApiJsonSerializer<PpiPovertyLineData> toApiJsonSerializer,
final PovertyLineService readService, final DefaultToApiJsonSerializer<LikeliHoodPovertyLineData> likelihoodToApiJsonSerializer) {
this.context = context;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.toApiJsonSerializer = toApiJsonSerializer;
this.readService = readService;
this.likelihoodToApiJsonSerializer = likelihoodToApiJsonSerializer;
@@ -63,6 +51,7 @@ public class PovertyLineApiResource {
return this.toApiJsonSerializer.serialize(povertyLine);
}
@GET
@Path("{ppiName}/{likelihoodId}")
@Consumes({ MediaType.APPLICATION_JSON })
@@ -77,6 +66,4 @@ public class PovertyLineApiResource {
}
}
@@ -1,17 +1,23 @@
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.mifosplatform.commands.domain.CommandWrapper;
import org.mifosplatform.commands.service.CommandWrapperBuilder;
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.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
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.service.GenericDataService;
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.SurveyDataTableData;
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.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.List;
/**
* Created by Cieyou on 2/27/14.
*/
@@ -53,10 +49,8 @@ public class SurveyApiResource {
private final static Logger logger = LoggerFactory.getLogger(SurveyApiResource.class);
@Autowired
public SurveyApiResource(final DefaultToApiJsonSerializer<SurveyData> toApiJsonSerializer,
final PlatformSecurityContext context,
final ReadSurveyService readSurveyService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
public SurveyApiResource(final DefaultToApiJsonSerializer<SurveyData> toApiJsonSerializer, final PlatformSecurityContext context,
final ReadSurveyService readSurveyService, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final DefaultToApiJsonSerializer<ClientScoresOverview> toApiJsonClientScoreOverviewSerializer,
final GenericDataService genericDataService) {
@@ -68,11 +62,10 @@ public class SurveyApiResource {
this.genericDataService = genericDataService;
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveSurveys(@Context final UriInfo uriInfo) {
public String retrieveSurveys() {
this.context.authenticatedUser().validateHasReadPermission(SurveyApiConstants.SURVEY_RESOURCE_NAME);
@@ -80,7 +73,6 @@ public class SurveyApiResource {
return this.toApiJsonSerializer.serialize(surveys);
}
@GET
@Path("{surveyName}")
@Consumes({ MediaType.APPLICATION_JSON })
@@ -112,13 +104,13 @@ public class SurveyApiResource {
return this.toApiJsonSerializer.serialize(result);
}
/** FIXME Vishwas what does this API really do? ***/
@GET
@Path("{surveyName}/{clientId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String getClientSurveyOverview(@PathParam("surveyName") final String surveyName, @PathParam("clientId") final Long clientId) {
this.context.authenticatedUser().validateHasReadPermission(SurveyApiConstants.SURVEY_RESOURCE_NAME);
List<ClientScoresOverview> scores = this.readSurveyService.retrieveClientSurveyScoreOverview(clientId);
@@ -126,13 +118,12 @@ public class SurveyApiResource {
return this.toApiJsonClientScoreOverviewSerializer.serialize(scores);
}
@GET
@Path("{surveyName}/{clientId}/{entryId}")
@Consumes({ 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);
@@ -142,7 +133,6 @@ public class SurveyApiResource {
}
@PUT
@Path("register/{surveyName}/{apptable}")
@Consumes({ MediaType.APPLICATION_JSON })
@@ -150,8 +140,8 @@ public class SurveyApiResource {
public String register(@PathParam("surveyName") final String datatable, @PathParam("apptable") final String apptable,
final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().registerSurvey( datatable,apptable).withJson(apiRequestBodyAsJson).build();
final CommandWrapper commandRequest = new CommandWrapperBuilder().registerSurvey(datatable, apptable)
.withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -167,7 +157,8 @@ public class SurveyApiResource {
@Path("{surveyName}/{clientId}/{fulfilledId}")
@Consumes({ 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() //
.deleteDatatable(surveyName, clientId, fulfilledId) //
@@ -1,19 +1,12 @@
package org.mifosplatform.infrastructure.survey.service;
import org.mifosplatform.infrastructure.survey.data.LikeliHoodPovertyLineData;
import org.mifosplatform.infrastructure.survey.data.PovertyLineData;
import org.mifosplatform.infrastructure.survey.data.PpiPovertyLineData;
import java.util.List;
/**
* Created by Cieyou on 3/11/14.
*/
public interface PovertyLineService {
PpiPovertyLineData retrieveAll(final String ppiName);
LikeliHoodPovertyLineData retrieveForLikelihood(final String ppiName, final Long likelihood);
//PovertyLineData retrieve();
}
@@ -1,27 +1,22 @@
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.survey.data.LikeliHoodPovertyLineData;
import org.mifosplatform.infrastructure.survey.data.PovertyLineData;
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.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
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
public class PovertyLineServiceImpl implements PovertyLineService {
private final static Logger logger = LoggerFactory.getLogger(PovertyLineService.class);
private final JdbcTemplate jdbcTemplate;
private final DataSource dataSource;
@@ -32,10 +27,8 @@ public class PovertyLineServiceImpl implements PovertyLineService{
}
@Override
public PpiPovertyLineData retrieveAll(final String ppiName)
{
public PpiPovertyLineData retrieveAll(final String ppiName) {
final SqlRowSet povertyLines = this._getPovertyLines(ppiName);
@@ -43,26 +36,19 @@ public class PovertyLineServiceImpl implements PovertyLineService{
List<LikeliHoodPovertyLineData> listOfLikeliHoodPovertyLineData = new ArrayList<LikeliHoodPovertyLineData>();
while(likelihoods.next())
{
while (likelihoods.next()) {
final String codeName = likelihoods.getString("code");
List<PovertyLineData> povertyLineDatas = new ArrayList<PovertyLineData>();
// create a new povertyLine object when ever it belong to the
// current likelihood
while (povertyLines.next())
{
while (povertyLines.next()) {
String likelihoodCode = povertyLines.getString("code");
if(likelihoodCode.equals(codeName))
{
povertyLineDatas.add(new PovertyLineData(
povertyLines.getLong("id"),
povertyLines.getLong("score_from"),
povertyLines.getLong("score_to"),
povertyLines.getDouble("poverty_line")
));
if (likelihoodCode.equals(codeName)) {
povertyLineDatas.add(new PovertyLineData(povertyLines.getLong("id"), povertyLines.getLong("score_from"), povertyLines
.getLong("score_to"), povertyLines.getDouble("poverty_line")));
}
}
@@ -71,13 +57,8 @@ public class PovertyLineServiceImpl implements PovertyLineService{
// create the likelihood object with the list of povertyLine object
// belonging to it
LikeliHoodPovertyLineData likeliHoodPovertyLineData = new LikeliHoodPovertyLineData(
likelihoods.getLong("id"),
povertyLineDatas,
likelihoods.getString("name"),
likelihoods.getString("code"),
likelihoods.getLong("enabled")
);
LikeliHoodPovertyLineData likeliHoodPovertyLineData = new LikeliHoodPovertyLineData(likelihoods.getLong("id"),
povertyLineDatas, likelihoods.getString("name"), likelihoods.getString("code"), likelihoods.getLong("enabled"));
listOfLikeliHoodPovertyLineData.add(likeliHoodPovertyLineData);
@@ -89,22 +70,16 @@ public class PovertyLineServiceImpl implements PovertyLineService{
}
@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);
List<PovertyLineData> povertyLineDatas = new ArrayList<PovertyLineData>();
while (povertyLines.next())
{
while (povertyLines.next()) {
povertyLineDatas.add(new PovertyLineData(
povertyLines.getLong("id"),
povertyLines.getLong("score_from"),
povertyLines.getLong("score_to"),
povertyLines.getDouble("poverty_line")
));
povertyLineDatas.add(new PovertyLineData(povertyLines.getLong("id"), povertyLines.getLong("score_from"), povertyLines
.getLong("score_to"), povertyLines.getDouble("poverty_line")));
}
povertyLines.first();
@@ -112,39 +87,28 @@ public class PovertyLineServiceImpl implements PovertyLineService{
// create the likelihood object with the list of povertyLine object
// belonging to it
return new LikeliHoodPovertyLineData(
povertyLines.getLong("likelihood_id"),
povertyLineDatas,
povertyLines.getString("name"),
povertyLines.getString("code"),
povertyLines.getLong("enabled")
);
return new LikeliHoodPovertyLineData(povertyLines.getLong("likelihood_id"), povertyLineDatas, povertyLines.getString("name"),
povertyLines.getString("code"), povertyLines.getLong("enabled"));
}
private SqlRowSet _getLikelihoods()
{
String sql = "SELECT lkp.id, lkh.code , lkh.name, lkp.enabled "
+ " FROM ppi_likelihoods lkh "
private SqlRowSet _getLikelihoods() {
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 ";
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 "
+ " FROM ppi_poverty_line pl "
+ " 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 "
+ " FROM ppi_poverty_line pl " + " 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 "
+ " WHERE lkp.ppi_name = ? ";
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 "
+ " FROM ppi_poverty_line pl "
+ " JOIN ppi_likelihoods_ppi lkp on lkp.id = pl.likelihood_ppi_id "
@@ -156,10 +120,4 @@ public class PovertyLineServiceImpl implements PovertyLineService{
}
// public PovertyLineData retrieve()
// {
//
// }
}
@@ -1,25 +1,20 @@
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.survey.data.LikelihoodData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
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
public class ReadLikelihoodServiceImpl implements ReadLikelihoodService {
private final static Logger logger = LoggerFactory.getLogger(PovertyLineService.class);
private final JdbcTemplate jdbcTemplate;
private final DataSource dataSource;
@@ -31,35 +26,26 @@ public class ReadLikelihoodServiceImpl implements ReadLikelihoodService {
}
@Override
public List<LikelihoodData> retrieveAll(final String ppiName)
{
public List<LikelihoodData> retrieveAll(final String ppiName) {
final SqlRowSet likelihood = this._getLikelihood(ppiName);
List<LikelihoodData> likelihoodDatas = new ArrayList<LikelihoodData>();
while(likelihood.next())
{
likelihoodDatas.add(new LikelihoodData(
likelihood.getLong("id"),
likelihood.getString("name"),
likelihood.getString("code"),
while (likelihood.next()) {
likelihoodDatas.add(new LikelihoodData(likelihood.getLong("id"), likelihood.getString("name"), likelihood.getString("code"),
likelihood.getLong("enabled")
));
}
return likelihoodDatas;
}
private SqlRowSet _getLikelihood(final String ppiName)
{
String sql = "SELECT lkp.id, lkh.code , lkh.name, lkp.enabled "
+ " FROM ppi_poverty_line pl "
private SqlRowSet _getLikelihood(final String ppiName) {
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 lkh on lkp.likelihood_id = lkh.id "
+ " WHERE lkp.ppi_name = ? "
+ " JOIN ppi_likelihoods lkh on lkp.likelihood_id = lkh.id " + " WHERE lkp.ppi_name = ? "
+ " GROUP BY pl.likelihood_ppi_id ";
return this.jdbcTemplate.queryForRowSet(sql, new Object[] { ppiName });
@@ -67,32 +53,24 @@ public class ReadLikelihoodServiceImpl implements ReadLikelihoodService {
}
@Override
public LikelihoodData retrieve(final Long likelihoodId)
{
public LikelihoodData retrieve(final Long likelihoodId) {
final SqlRowSet likelihood = this._getLikelihood(likelihoodId);
likelihood.first();
return new LikelihoodData(
likelihood.getLong("id"),
likelihood.getString("name"),
likelihood.getString("code"),
return new LikelihoodData(likelihood.getLong("id"), likelihood.getString("name"), likelihood.getString("code"),
likelihood.getLong("enabled")
);
}
private SqlRowSet _getLikelihood(final Long likelihoodId)
{
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 "
+ " WHERE lkp.id = ? ";
private SqlRowSet _getLikelihood(final Long likelihoodId) {
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 " + " WHERE lkp.id = ? ";
return this.jdbcTemplate.queryForRowSet(sql, new Object[] { likelihoodId });
}
}
@@ -1,12 +1,11 @@
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.survey.data.ClientScoresOverview;
import org.mifosplatform.infrastructure.survey.data.SurveyDataTableData;
import java.util.List;
/**
* Created by Cieyou on 2/27/14.
*/
@@ -17,10 +16,9 @@ public interface ReadSurveyService {
SurveyDataTableData retrieveSurvey(String surveyName);
List<ClientScoresOverview> retrieveClientSurveyScoreOverview(String surveyName, Long clientId);
List<ClientScoresOverview> retrieveClientSurveyScoreOverview(Long clientId);
GenericResultsetData retrieveSurveyEntry(String surveyName, Long clientId, Long entryId);
}
@@ -1,7 +1,11 @@
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.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
import org.mifosplatform.infrastructure.dataqueries.api.DataTableApiConstant;
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.LikelihoodStatus;
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.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Service;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;
@Service
public class ReadSurveyServiceImpl implements ReadSurveyService {
@@ -33,14 +30,10 @@ public class ReadSurveyServiceImpl implements ReadSurveyService {
private final DataSource dataSource;
private final GenericDataService genericDataService;
private final ReadWriteNonCoreDataService readWriteNonCoreDataService;
private final static Logger logger = LoggerFactory.getLogger(ReadSurveyServiceImpl.class);
@Autowired
public ReadSurveyServiceImpl(final PlatformSecurityContext context,
final RoutingDataSource dataSource,
final FromJsonHelper fromJsonHelper,
final GenericDataService genericDataService,
final ReadWriteNonCoreDataService readWriteNonCoreDataService){
public ReadSurveyServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource,
final GenericDataService genericDataService, final ReadWriteNonCoreDataService readWriteNonCoreDataService) {
this.context = context;
this.dataSource = dataSource;
@@ -50,8 +43,7 @@ public class ReadSurveyServiceImpl implements ReadSurveyService {
}
@Override
public List<SurveyDataTableData> retrieveAllSurveys()
{
public List<SurveyDataTableData> retrieveAllSurveys() {
String sql = this.retrieveAllSurveySQL("");
@@ -65,38 +57,30 @@ public class ReadSurveyServiceImpl implements ReadSurveyService {
final List<ResultsetColumnHeaderData> columnHeaderData = this.genericDataService
.fillResultsetColumnHeaders(registeredDatatableName);
surveyDataTables.add(
SurveyDataTableData.create(
DatatableData.create(appTableName, registeredDatatableName, columnHeaderData),
enabled
)
);
surveyDataTables.add(SurveyDataTableData.create(DatatableData.create(appTableName, registeredDatatableName, columnHeaderData),
enabled));
}
return surveyDataTables;
}
private String retrieveAllSurveySQL(String andClause )
{
private String retrieveAllSurveySQL(String andClause) {
// PERMITTED datatables
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 "
+ " where exists"
+ " (select 'f'" + " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id"
+ " left join c_configuration cf on x_registered_table.registered_table_name = cf.name " + " where exists" + " (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"
+ " 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 x_registered_table.category = "+ DataTableApiConstant.CATEGORY_PPI
+ andClause + " order by application_table_name, registered_table_name";
+ " and x_registered_table.category = " + DataTableApiConstant.CATEGORY_PPI + andClause
+ " order by application_table_name, registered_table_name";
}
@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 "
+ " left join c_configuration cf on x_registered_table.registered_table_name = cf.name "
+ " where exists"
+ " (select 'f'" + " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id"
+ " left join c_configuration cf on x_registered_table.registered_table_name = cf.name " + " where exists" + " (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"
+ " 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))) "
@@ -112,83 +96,60 @@ public class ReadSurveyServiceImpl implements ReadSurveyService {
final List<ResultsetColumnHeaderData> columnHeaderData = this.genericDataService
.fillResultsetColumnHeaders(registeredDatatableName);
datatableData = SurveyDataTableData.create(
DatatableData.create(appTableName, registeredDatatableName, columnHeaderData),
enabled
);
datatableData = SurveyDataTableData.create(DatatableData.create(appTableName, registeredDatatableName, columnHeaderData),
enabled);
}
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"
+ " 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_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 "
+" WHERE client_id = "+clientId;
+ " JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_id " + " WHERE client_id = " + clientId;
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
List<ClientScoresOverview> scoresOverviews = new ArrayList<ClientScoresOverview>();
while(rs.next())
{
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"),
surveyName
));
while (rs.next()) {
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"), surveyName));
}
return scoresOverviews;
}
public List<ClientScoresOverview> retrieveClientSurveyScoreOverview(Long clientId)
{
@Override
public List<ClientScoresOverview> retrieveClientSurveyScoreOverview(Long clientId) {
final String surveyNameSql = retrieveAllSurveyNameSQL();
final SqlRowSet surveyNames = this.jdbcTemplate.queryForRowSet(surveyNameSql);
ArrayList<String> sqls = new ArrayList<String>();
while(surveyNames .next())
{
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"
+" JOIN ppi_likelihoods_ppi lkp on lkp.ppi_name = '"+surveyNames.getString("name")+"' AND enabled = '"+ LikelihoodStatus.ENABLED
+"' JOIN ppi_scores sc on score_from <= tz.score AND score_to >=tz.score"
while (surveyNames.next()) {
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" + " JOIN ppi_likelihoods_ppi lkp on lkp.ppi_name = '" + surveyNames.getString("name") + "' AND enabled = '"
+ 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_likelihoods lkh on lkh.id = lkp.likelihood_id "
+" WHERE client_id = "+clientId );
+ " JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_id " + " WHERE client_id = " + clientId);
}
List<ClientScoresOverview> scoresOverviews = new ArrayList<ClientScoresOverview>();
for(String sql:sqls)
{
for (String sql : sqls) {
final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql);
while(rs.next())
{
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")
));
while (rs.next()) {
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")));
}
}
@@ -196,13 +157,11 @@ public class ReadSurveyServiceImpl implements ReadSurveyService {
return scoresOverviews;
}
private String retrieveAllSurveyNameSQL()
{
private String retrieveAllSurveyNameSQL() {
// PERMITTED datatables
return "select cf.name from x_registered_table "
+ " join c_configuration cf on x_registered_table.registered_table_name = cf.name "
+ " where exists"
+ " (select 'f'" + " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id"
+ " join c_configuration cf on x_registered_table.registered_table_name = cf.name " + " where exists" + " (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"
+ " 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))) "
@@ -210,11 +169,10 @@ public class ReadSurveyServiceImpl implements ReadSurveyService {
+ " 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,
null, entryId);
return readWriteNonCoreDataService.retrieveDataTableGenericResultSet(surveyName, clientId, null, entryId);
}
}
@@ -1,27 +1,21 @@
package org.mifosplatform.infrastructure.survey.service;
import com.google.gson.JsonElement;
import org.mifosplatform.infrastructure.configuration.domain.GlobalConfigurationProperty;
import java.util.List;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
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.survey.data.LikelihoodDataValidator;
import org.mifosplatform.infrastructure.survey.data.LikelihoodStatus;
import org.mifosplatform.infrastructure.survey.domain.Likelihood;
import org.mifosplatform.infrastructure.survey.domain.LikelihoodRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.sql.DataSource;
import java.util.List;
/**
* Created by Cieyou on 3/12/14.
*/
@@ -29,19 +23,13 @@ import java.util.List;
public class WriteLikelihoodServiceImpl implements WriteLikelihoodService {
private final static Logger logger = LoggerFactory.getLogger(PovertyLineService.class);
private final JdbcTemplate jdbcTemplate;
private final DataSource dataSource;
private final PlatformSecurityContext context;
private final LikelihoodDataValidator likelihoodDataValidator;
private final LikelihoodRepository repository;
@Autowired
WriteLikelihoodServiceImpl (final RoutingDataSource dataSource,
final PlatformSecurityContext context,
final LikelihoodDataValidator likelihoodDataValidator,
WriteLikelihoodServiceImpl(final PlatformSecurityContext context, final LikelihoodDataValidator likelihoodDataValidator,
final LikelihoodRepository repository) {
this.dataSource = dataSource;
this.jdbcTemplate = new JdbcTemplate(this.dataSource);
this.context = context;
this.likelihoodDataValidator = likelihoodDataValidator;
this.repository = repository;
@@ -49,8 +37,7 @@ public class WriteLikelihoodServiceImpl implements WriteLikelihoodService{
}
@Override
public CommandProcessingResult update(Long likelihoodId, JsonCommand command)
{
public CommandProcessingResult update(Long likelihoodId, JsonCommand command) {
this.context.authenticatedUser();
@@ -60,16 +47,14 @@ public class WriteLikelihoodServiceImpl implements WriteLikelihoodService{
final Likelihood likelihood = this.repository.findOne(likelihoodId);
if (!likelihood.update(command).isEmpty()) {
this.repository.save(likelihood);
if(likelihood.isActivateCommand(command))
{
List<Likelihood> likelihoods = this.repository.findByPpiNameAndLikeliHoodId(likelihood.getPpiName(),likelihood.getId());
if (likelihood.isActivateCommand(command)) {
List<Likelihood> likelihoods = this.repository
.findByPpiNameAndLikeliHoodId(likelihood.getPpiName(), likelihood.getId());
for(Likelihood aLikelihood:likelihoods)
{
for (Likelihood aLikelihood : likelihoods) {
aLikelihood.disable();
}
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
* is.
@@ -1,77 +1,29 @@
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.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.security.service.PlatformSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.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.
*/
@Service
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;
@Autowired(required = true)
WriteSurveyServiceImpl(final RoutingDataSource dataSource,
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;
WriteSurveyServiceImpl(final ReadWriteNonCoreDataService readWriteNonCoreDataService) {
this.readWriteNonCoreDataService = readWriteNonCoreDataService;
}
@Override
@Transactional
public CommandProcessingResult registerSurvey(JsonCommand command)
{
public CommandProcessingResult registerSurvey(JsonCommand command) {
final String dataTableName = this.readWriteNonCoreDataService.getDataTableName(command.getUrl());
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 createPermissionChecker = "'CREATE_" + dataTableName + "_CHECKER'";
final String readPermission = "'READ_" + dataTableName + "'";
@@ -91,40 +42,12 @@ public class WriteSurveyServiceImpl implements WriteSurveyService {
final String deletePermission = "'DELETE_" + dataTableName + "'";
final String deletePermissionChecker = "'DELETE_" + dataTableName + "_CHECKER'";
return "insert into m_permission (grouping, code, action_name, entity_name, can_maker_checker) values "
+ "('datatable', "
+ createPermission
+ ", 'CREATE', '"
+ dataTableName
+ "', false),"
+ "('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', '"
return "insert into m_permission (grouping, code, action_name, entity_name, can_maker_checker) values " + "('datatable', "
+ createPermission + ", 'CREATE', '" + dataTableName + "', false)," + "('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)";
}
@@ -135,5 +58,4 @@ public class WriteSurveyServiceImpl implements WriteSurveyService {
return readWriteNonCoreDataService.createPPIEntry(dataTableName, appTableId, command);
}
}