From 8e61abe4ed3454fb86e7d61a1d2b7c2574490bdf Mon Sep 17 00:00:00 2001 From: Vishwas Babu A J Date: Fri, 6 Jun 2014 11:23:50 -0700 Subject: [PATCH] removing most warnings in ppi/survey related code --- .../api/DatatablesApiResource.java | 12 +- .../dataqueries/data/DataTableValidator.java | 32 ++-- .../data/ResultsetColumnValueData.java | 2 + .../service/ReadWriteNonCoreDataService.java | 10 +- .../ReadWriteNonCoreDataServiceImpl.java | 136 ++++++---------- .../survey/api/LikelihoodApiConstants.java | 14 +- .../survey/api/LikelihoodApiResource.java | 31 ++-- .../survey/api/PovertyLineApiConstants.java | 6 - .../survey/api/PovertyLineApiResource.java | 43 ++--- .../survey/api/SurveyApiResource.java | 73 ++++----- .../survey/service/PovertyLineService.java | 9 +- .../service/PovertyLineServiceImpl.java | 126 +++++---------- .../service/ReadLikelihoodServiceImpl.java | 70 +++----- .../survey/service/ReadSurveyService.java | 12 +- .../survey/service/ReadSurveyServiceImpl.java | 150 +++++++----------- .../service/WriteLikelihoodServiceImpl.java | 36 ++--- .../service/WriteSurveyServiceImpl.java | 98 ++---------- 17 files changed, 286 insertions(+), 574 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/DatatablesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/DatatablesApiResource.java index fe91a33e7..62bd3af0b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/DatatablesApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/DatatablesApiResource.java @@ -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); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/DataTableValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/DataTableValidator.java index 1096d1bbb..7ac9a99a2 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/DataTableValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/DataTableValidator.java @@ -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>() {}.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, REGISTER_PARAMS); @@ -41,8 +42,9 @@ 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}); + final Integer category = this.fromApiJsonHelper.extractIntegerWithLocaleNamed(categoryParamName, element); + Object[] objectArray = new Integer[] { CATEGORY_PPI, CATEGORY_DEFAULT }; + baseDataValidator.reset().parameter(categoryParamName).value(category).isOneOfTheseValues(objectArray); } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ResultsetColumnValueData.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ResultsetColumnValueData.java index e5b65766e..eb4fe5928 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ResultsetColumnValueData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/data/ResultsetColumnValueData.java @@ -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; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataService.java index d35ba2f82..fe851a29c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataService.java @@ -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 { @@ -25,10 +23,10 @@ public interface ReadWriteNonCoreDataService { void registerDatatable(JsonCommand command); @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')") - void registerDatatable(JsonCommand command,String permissionTable); + void registerDatatable(JsonCommand command, String permissionTable); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'DEREGISTER_DATATABLE')") void deregisterDatatable(String datatable); @@ -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); - - } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java index 9a8c042d7..8e8bfe4bb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java @@ -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, @@ -109,7 +111,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ this.codeReadPlatformService = codeReadPlatformService; this.configurationDomainService = configurationDomainService; this.dataTableValidator = dataTableValidator; - //this.configurationWriteService = configurationWriteService; + // this.configurationWriteService = configurationWriteService; } @Override @@ -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()); @@ -213,16 +213,13 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ this.dataTableValidator.validateDataTableRegistration(command.json()); - this._registerDataTable(applicationTableName,dataTableName,category,permissionSql); + this._registerDataTable(applicationTableName, dataTableName, category, permissionSql); } @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,17 +227,14 @@ 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)) - { - this.jdbcTemplate.execute("insert into c_configuration (name, value, enabled ) values('"+dataTableName+"', '0','0')"); + if (this.isSurveyCategory(category)) { + 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 if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException( "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) { final Throwable realCause = dve.getMostSpecificCause(); // even if duplicate is only due to permission duplicate, okay to // show duplicate datatable error msg if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException( "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); throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "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,67 +271,38 @@ 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; + 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); } - public String getDataTableName(String url){ + @Override + public String getDataTableName(String url) { - String [] urlParts = url.split("/"); + String[] urlParts = url.split("/"); return urlParts[3]; } - public String getTableName(String url) - { - String [] urlParts = url.split("/"); + @Override + public String getTableName(String url) { + String[] urlParts = url.split("/"); 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 deleteFromConfigurationSql = "delete from c_configuration where name ='"+datatable+"'"; + final String deleteFromConfigurationSql = "delete from c_configuration where name ='" + datatable + "'"; String[] sqlArray = new String[4]; sqlArray[0] = deleteRolePermissionsSql; sqlArray[1] = deletePermissionsSql; sqlArray[2] = deleteRegisteredDatatableSql; - sqlArray[3] = deleteFromConfigurationSql ; + sqlArray[3] = deleteFromConfigurationSql; 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) { try { @@ -434,7 +398,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ final Throwable realCause = dve.getCause(); if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException( "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); throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", @@ -443,7 +407,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ final Throwable realCause = dve.getMostSpecificCause(); if (realCause.getMessage().contains("Duplicate entry")) { throw new PlatformDataIntegrityException( "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); 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, 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 @@ -1341,12 +1304,11 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ * @return */ public String getAddSqlWithScore(final List columnHeaders, final String datatable, final String fkName, - final Long appTableId, final Map queryParams) { + final Long appTableId, final Map queryParams) { final Map affectedColumns = getAffectedColumns(columnHeaders, queryParams, fkName); String pValueWrite = ""; - String addSql = ""; String scoresId = " "; final String singleQuote = "'"; @@ -1362,8 +1324,7 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ } else { pValueWrite = singleQuote + this.genericDataService.replace(pValue, singleQuote, singleQuote + singleQuote) + singleQuote; - scoresId +=pValueWrite +" ,"; - + scoresId += pValueWrite + " ,"; } columnName = "`" + key + "`"; @@ -1371,16 +1332,11 @@ public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataServ 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); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiConstants.java index 06fc754c4..830c222c4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiConstants.java @@ -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 UPDATE_LIKELIHOOD_DATA_PARAMETERS = new HashSet(Arrays.asList(ACTIVE)); - public static final Set VALID_LIKELIHOOD_ENABLED_VALUES = new HashSet( - Arrays.asList( - LikelihoodStatus.DISABLED, - LikelihoodStatus.ENABLED - )); + public static final Set VALID_LIKELIHOOD_ENABLED_VALUES = new HashSet(Arrays.asList(LikelihoodStatus.DISABLED, + LikelihoodStatus.ENABLED)); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiResource.java index 8f887b205..cecefb3a4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/LikelihoodApiResource.java @@ -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,33 +30,28 @@ import java.util.List; @Scope("singleton") public class LikelihoodApiResource { - - private final static Logger logger = LoggerFactory.getLogger(PovertyLineApiResource.class); private final DefaultToApiJsonSerializer toApiJsonSerializer; private final PlatformSecurityContext context; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final ReadLikelihoodService readService; - @Autowired LikelihoodApiResource(final PlatformSecurityContext context, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, - final DefaultToApiJsonSerializer toApiJsonSerializer, - final ReadLikelihoodService readService) { + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final DefaultToApiJsonSerializer toApiJsonSerializer, final ReadLikelihoodService readService) { this.context = context; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.toApiJsonSerializer = toApiJsonSerializer; this.readService = readService; - } @GET @Path("{ppiName}") @Consumes({ 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); @@ -65,7 +64,7 @@ public class LikelihoodApiResource { @Path("{ppiName}/{likelihoodId}") @Consumes({ 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); @@ -78,7 +77,7 @@ public class LikelihoodApiResource { @Path("{ppiName}/{likelihoodId}") @Consumes({ 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); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/PovertyLineApiConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/PovertyLineApiConstants.java index a8c4ed270..35ee86ae9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/PovertyLineApiConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/PovertyLineApiConstants.java @@ -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"; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/PovertyLineApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/PovertyLineApiResource.java index b4c522d42..7f7479b6d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/PovertyLineApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/PovertyLineApiResource.java @@ -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 toApiJsonSerializer; private final DefaultToApiJsonSerializer likelihoodToApiJsonSerializer; - // private final DefaultToApiJsonSerializer toApiJsonSerializer; + // private final DefaultToApiJsonSerializer + // toApiJsonSerializer; private final PlatformSecurityContext context; - private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PovertyLineService readService; - @Autowired - PovertyLineApiResource(final PlatformSecurityContext context, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, - final DefaultToApiJsonSerializer toApiJsonSerializer, - final PovertyLineService readService, - final DefaultToApiJsonSerializer likelihoodToApiJsonSerializer) { + PovertyLineApiResource(final PlatformSecurityContext context, final DefaultToApiJsonSerializer toApiJsonSerializer, + final PovertyLineService readService, final DefaultToApiJsonSerializer likelihoodToApiJsonSerializer) { this.context = context; - this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.toApiJsonSerializer = toApiJsonSerializer; this.readService = readService; this.likelihoodToApiJsonSerializer = likelihoodToApiJsonSerializer; @@ -55,7 +43,7 @@ public class PovertyLineApiResource { @Path("{ppiName}") @Consumes({ 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); @@ -63,20 +51,19 @@ public class PovertyLineApiResource { return this.toApiJsonSerializer.serialize(povertyLine); } + @GET @Path("{ppiName}/{likelihoodId}") @Consumes({ 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); - LikeliHoodPovertyLineData likeliHoodPovertyLineData = this.readService.retrieveForLikelihood(ppiName, likelihoodId); + LikeliHoodPovertyLineData likeliHoodPovertyLineData = this.readService.retrieveForLikelihood(ppiName, likelihoodId); return this.likelihoodToApiJsonSerializer.serialize(likeliHoodPovertyLineData); } - - } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/SurveyApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/SurveyApiResource.java index c75c5eb48..0ebc2c0ac 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/SurveyApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/api/SurveyApiResource.java @@ -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,12 +49,10 @@ public class SurveyApiResource { private final static Logger logger = LoggerFactory.getLogger(SurveyApiResource.class); @Autowired - public SurveyApiResource(final DefaultToApiJsonSerializer toApiJsonSerializer, - final PlatformSecurityContext context, - final ReadSurveyService readSurveyService, - final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, - final DefaultToApiJsonSerializer toApiJsonClientScoreOverviewSerializer, - final GenericDataService genericDataService){ + public SurveyApiResource(final DefaultToApiJsonSerializer toApiJsonSerializer, final PlatformSecurityContext context, + final ReadSurveyService readSurveyService, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final DefaultToApiJsonSerializer toApiJsonClientScoreOverviewSerializer, + final GenericDataService genericDataService) { this.toApiJsonSerializer = toApiJsonSerializer; this.context = context; @@ -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) { + @GET + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + 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 }) @@ -100,7 +92,7 @@ public class SurveyApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String createDatatableEntry(@PathParam("surveyName") final String datatable, @PathParam("apptableId") final Long apptableId, - final String apiRequestBodyAsJson) { + final String apiRequestBodyAsJson) { final CommandWrapper commandRequest = new CommandWrapperBuilder() // .fullFilSurvey(datatable, apptableId) // @@ -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 scores = this.readSurveyService.retrieveClientSurveyScoreOverview(clientId); @@ -126,32 +118,30 @@ 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); - 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 @Path("register/{surveyName}/{apptable}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) 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).withJson(apiRequestBodyAsJson).build(); + final CommandWrapper commandRequest = new CommandWrapperBuilder().registerSurvey(datatable, apptable) + .withJson(apiRequestBodyAsJson).build(); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); @@ -167,10 +157,11 @@ 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) // + .deleteDatatable(surveyName, clientId, fulfilledId) // .build(); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/PovertyLineService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/PovertyLineService.java index ee39153eb..99b064ab7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/PovertyLineService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/PovertyLineService.java @@ -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); + LikeliHoodPovertyLineData retrieveForLikelihood(final String ppiName, final Long likelihood); - //PovertyLineData retrieve(); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/PovertyLineServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/PovertyLineServiceImpl.java index 2aa8bbe28..1c3241228 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/PovertyLineServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/PovertyLineServiceImpl.java @@ -1,41 +1,34 @@ 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{ +public class PovertyLineServiceImpl implements PovertyLineService { - private final static Logger logger = LoggerFactory.getLogger(PovertyLineService.class); private final JdbcTemplate jdbcTemplate; private final DataSource dataSource; @Autowired - PovertyLineServiceImpl(final RoutingDataSource dataSource){ + PovertyLineServiceImpl(final RoutingDataSource dataSource) { this.dataSource = dataSource; this.jdbcTemplate = new JdbcTemplate(this.dataSource); } - @Override - public PpiPovertyLineData retrieveAll(final String ppiName) - { + public PpiPovertyLineData retrieveAll(final String ppiName) { final SqlRowSet povertyLines = this._getPovertyLines(ppiName); @@ -43,123 +36,88 @@ public class PovertyLineServiceImpl implements PovertyLineService{ List listOfLikeliHoodPovertyLineData = new ArrayList(); - while(likelihoods.next()) - { - final String codeName = likelihoods.getString("code"); + while (likelihoods.next()) { + final String codeName = likelihoods.getString("code"); List povertyLineDatas = new ArrayList(); // create a new povertyLine object when ever it belong to the // current likelihood - while (povertyLines.next()) - { - String likelihoodCode = povertyLines.getString("code"); + 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"))); + } + } povertyLines.beforeFirst(); // 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); } - PpiPovertyLineData ppiPovertyLineData = new PpiPovertyLineData(listOfLikeliHoodPovertyLineData,ppiName); + PpiPovertyLineData ppiPovertyLineData = new PpiPovertyLineData(listOfLikeliHoodPovertyLineData, ppiName); - return ppiPovertyLineData; + return ppiPovertyLineData; } @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 povertyLineDatas = new ArrayList(); - 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(); + povertyLines.first(); - // create the likelihood object with the list of povertyLine object - // belonging to it + // 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); + 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}); + 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 " - +" JOIN ppi_likelihoods lkh on lkh.id = lkp.likelihood_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_scores sc on sc.id = pl.score_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() -// { -// -// } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadLikelihoodServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadLikelihoodServiceImpl.java index 8b563320f..f35c9b71a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadLikelihoodServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadLikelihoodServiceImpl.java @@ -1,98 +1,76 @@ 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; @Autowired - ReadLikelihoodServiceImpl(final RoutingDataSource dataSource){ + ReadLikelihoodServiceImpl(final RoutingDataSource dataSource) { this.dataSource = dataSource; this.jdbcTemplate = new JdbcTemplate(this.dataSource); } @Override - public List retrieveAll(final String ppiName) - { - final SqlRowSet likelihood =this._getLikelihood(ppiName); + public List retrieveAll(final String ppiName) { + final SqlRowSet likelihood = this._getLikelihood(ppiName); List likelihoodDatas = new ArrayList(); - while(likelihood.next()) - { - likelihoodDatas.add(new LikelihoodData( - likelihood.getLong("id"), - likelihood.getString("name"), - likelihood.getString("code"), - likelihood.getLong("enabled") + 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}); + return this.jdbcTemplate.queryForRowSet(sql, new Object[] { ppiName }); } @Override - public LikelihoodData retrieve(final Long likelihoodId) - { - final SqlRowSet likelihood =this._getLikelihood(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"), - likelihood.getLong("enabled") + 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}); + return this.jdbcTemplate.queryForRowSet(sql, new Object[] { likelihoodId }); } - } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadSurveyService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadSurveyService.java index 54940b617..a249eb5a8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadSurveyService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadSurveyService.java @@ -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. */ @@ -16,11 +15,10 @@ public interface ReadSurveyService { SurveyDataTableData retrieveSurvey(String surveyName); - ListretrieveClientSurveyScoreOverview(String surveyName, Long clientId); - ListretrieveClientSurveyScoreOverview(Long clientId); + List retrieveClientSurveyScoreOverview(String surveyName, Long clientId); + + List retrieveClientSurveyScoreOverview(Long clientId); GenericResultsetData retrieveSurveyEntry(String surveyName, Long clientId, Long entryId); } - - diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadSurveyServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadSurveyServiceImpl.java index e8121654a..e3edece36 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadSurveyServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/ReadSurveyServiceImpl.java @@ -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 retrieveAllSurveys() - { + public List retrieveAllSurveys() { String sql = this.retrieveAllSurveySQL(""); @@ -65,38 +57,30 @@ public class ReadSurveyServiceImpl implements ReadSurveyService { final List 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,109 +96,83 @@ public class ReadSurveyServiceImpl implements ReadSurveyService { final List 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 retrieveClientSurveyScoreOverview(String surveyName, Long clientId) - { + @Override + public List 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; + 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; final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql); List scoresOverviews = new ArrayList(); - 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 ; + return scoresOverviews; } - public List retrieveClientSurveyScoreOverview(Long clientId) - { + @Override + public List retrieveClientSurveyScoreOverview(Long clientId) { final String surveyNameSql = retrieveAllSurveyNameSQL(); final SqlRowSet surveyNames = this.jdbcTemplate.queryForRowSet(surveyNameSql); ArrayList sqls = new ArrayList(); - 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 ); + 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); } List scoresOverviews = new ArrayList(); - for(String sql:sqls) - { - final SqlRowSet rs = this.jdbcTemplate.queryForRowSet(sql); + 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"))); } } - return scoresOverviews ; + 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))) " - + " and x_registered_table.category = "+ DataTableApiConstant.CATEGORY_PPI + + " and x_registered_table.category = " + DataTableApiConstant.CATEGORY_PPI + " 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); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteLikelihoodServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteLikelihoodServiceImpl.java index 113eaff11..b07189974 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteLikelihoodServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteLikelihoodServiceImpl.java @@ -1,47 +1,35 @@ 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. */ @Service -public class WriteLikelihoodServiceImpl implements WriteLikelihoodService{ +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, - final LikelihoodRepository repository){ - this.dataSource = dataSource; - this.jdbcTemplate = new JdbcTemplate(this.dataSource); + WriteLikelihoodServiceImpl(final PlatformSecurityContext context, final LikelihoodDataValidator likelihoodDataValidator, + final LikelihoodRepository repository) { 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 likelihoods = this.repository.findByPpiNameAndLikeliHoodId(likelihood.getPpiName(),likelihood.getId()); + if (likelihood.isActivateCommand(command)) { + List 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. diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteSurveyServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteSurveyServiceImpl.java index 90f5a042a..431708b87 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteSurveyServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/survey/service/WriteSurveyServiceImpl.java @@ -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)"; } @@ -132,8 +55,7 @@ public class WriteSurveyServiceImpl implements WriteSurveyService { @Override public CommandProcessingResult fullFillSurvey(final String dataTableName, final Long appTableId, final JsonCommand command) { - return readWriteNonCoreDataService.createPPIEntry(dataTableName,appTableId,command); + return readWriteNonCoreDataService.createPPIEntry(dataTableName, appTableId, command); } - }