implement jpa for likelihood write operation, set default value for registered table category, add likelihood table sql

This commit is contained in:
CieyouRaoul
2014-05-15 13:32:24 +02:00
parent c1acf1baae
commit 712b5e000c
10 changed files with 221 additions and 52 deletions
@@ -11,6 +11,5 @@ import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
public interface GlobalConfigurationWritePlatformService {
CommandProcessingResult update(Long configId, JsonCommand command);
CommandProcessingResult update(String name, JsonCommand command);
void addSurveyConfig(String name);
}
@@ -66,29 +66,6 @@ public class GlobalConfigurationWritePlatformServiceJpaRepositoryImpl implements
}
@Transactional
@Override
public CommandProcessingResult update(final String name, final JsonCommand command) {
this.context.authenticatedUser();
try {
this.globalConfigurationDataValidator.validateForUpdate(command);
final GlobalConfigurationProperty configItemForUpdate = this.repository.findOneByNameWithNotFoundDetection(name);
if (configItemForUpdate.updateTo(true)) {
this.repository.save(configItemForUpdate);
}
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(configItemForUpdate.getId()).build();
} catch (final DataIntegrityViolationException dve) {
handleDataIntegrityIssues(dve);
return CommandProcessingResult.empty();
}
}
@Transactional
@Override
@@ -75,7 +75,7 @@ public class LikelihoodApiResource {
}
@PUT
@Path("{likelihoodId}")
@Path("{ppiName}/{likelihoodId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String update(@PathParam("likelihoodId") final Long likelihoodId, final String apiRequestBodyAsJson){
@@ -126,19 +126,6 @@ public class SurveyApiResource {
return this.toApiJsonClientScoreOverviewSerializer.serialize(scores);
}
// @GET
// @Path("{clientId}")
// @Consumes({ MediaType.APPLICATION_JSON })
// @Produces({ MediaType.APPLICATION_JSON })
// public String getAllClientSurveyOverview( @PathParam("clientId") final Long clientId) {
//
//
// this.context.authenticatedUser().validateHasReadPermission(SurveyApiConstants.SURVEY_RESOURCE_NAME);
//
// List<ClientScoresOverview> scores = this.readSurveyService.retrieveClientSurveyScoreOverview(clientId);
//
// return this.toApiJsonClientScoreOverviewSerializer.serialize(scores);
// }
@GET
@Path("{surveyName}/{clientId}/{entryId}")
@@ -65,4 +65,9 @@ public final class Likelihood extends AbstractPersistable<Long> {
public Long getId() {
return super.getId();
}
public void disable()
{
this.enabled = LikelihoodStatus.DISABLED;
}
}
@@ -3,13 +3,15 @@ package org.mifosplatform.infrastructure.survey.domain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
* Created by Cieyou on 3/12/14.
*/
public interface LikelihoodRepository extends JpaRepository<Likelihood, Long>, JpaSpecificationExecutor<Likelihood> {
@Query("FROM Likelihood WHERE ppi_name =:ppiName AND id !=:id")
List<Likelihood> findByPpiNameAndLikeliHoodId(@Param("ppiName") String ppiName,@Param("id") Long likeliHoodId);
}
@@ -20,6 +20,7 @@ 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.
@@ -60,21 +61,18 @@ public class WriteLikelihoodServiceImpl implements WriteLikelihoodService{
final Likelihood likelihood = this.repository.findOne(likelihoodId);
String disableLikelihoodSql = "update ppi_likelihoods_ppi set enabled = "+ LikelihoodStatus.DISABLED
+ " WHERE ppi_likelihoods_ppi.id IN "
+ " ( SELECT t.id FROM ( SELECT * FROM ppi_likelihoods_ppi ) as t " +
" WHERE t.ppi_name = '" + likelihood.getPpiName()
+ "' AND t.id !=" +likelihood.getId()+ " ) ";
if (!likelihood.update(command).isEmpty()) {
this.repository.save(likelihood);
if(likelihood.isActivateCommand(command))
{
// disable the other likelihood
jdbcTemplate.execute(disableLikelihoodSql);
List<Likelihood> likelihoods = this.repository.findByPpiNameAndLikeliHoodId(likelihood.getPpiName(),likelihood.getId());
for(Likelihood aLikelihood:likelihoods)
{
aLikelihood.disable();
}
this.repository.save(likelihoods);
}
}