Survey bug fix 529, 530
This commit is contained in:
@@ -30,8 +30,10 @@ import javax.ws.rs.PUT;
|
|||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.apache.fineract.infrastructure.core.exception.UnrecognizedQueryParamException;
|
||||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.apache.fineract.spm.data.SurveyData;
|
import org.apache.fineract.spm.data.SurveyData;
|
||||||
import org.apache.fineract.spm.domain.Survey;
|
import org.apache.fineract.spm.domain.Survey;
|
||||||
@@ -62,10 +64,15 @@ public class SpmApiResource {
|
|||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<SurveyData> fetchActiveSurveys() {
|
public List<SurveyData> fetchAllSurveys(@QueryParam("isActive") final Boolean isActive) {
|
||||||
this.securityContext.authenticatedUser();
|
this.securityContext.authenticatedUser();
|
||||||
final List<SurveyData> result = new ArrayList<>();
|
final List<SurveyData> result = new ArrayList<>();
|
||||||
final List<Survey> surveys = this.spmService.fetchValidSurveys();
|
List<Survey> surveys = null;
|
||||||
|
if(isActive != null && isActive){
|
||||||
|
surveys = this.spmService.fetchValidSurveys();
|
||||||
|
}else{
|
||||||
|
surveys = this.spmService.fetchAllSurveys();
|
||||||
|
}
|
||||||
if (surveys != null) {
|
if (surveys != null) {
|
||||||
for (final Survey survey : surveys) {
|
for (final Survey survey : surveys) {
|
||||||
result.add(SurveyMapper.map(survey));
|
result.add(SurveyMapper.map(survey));
|
||||||
@@ -110,14 +117,21 @@ public class SpmApiResource {
|
|||||||
return getResponse(survey.getId());
|
return getResponse(survey.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@DELETE
|
@POST
|
||||||
@Path("/{id}")
|
@Path("/{id}")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Transactional
|
@Transactional
|
||||||
public void deactivateSurvey(@PathParam("id") final Long id) {
|
public void activateOrDeactivateSurvey(@PathParam("id") final Long id, @QueryParam("command") final String command) {
|
||||||
this.securityContext.authenticatedUser();
|
this.securityContext.authenticatedUser();
|
||||||
this.spmService.deactivateSurvey(id);
|
if(command != null && command.equalsIgnoreCase("activate")){
|
||||||
|
this.spmService.activateSurvey(id);;
|
||||||
|
}else if(command != null && command.equalsIgnoreCase("deactivate")){
|
||||||
|
this.spmService.deactivateSurvey(id);
|
||||||
|
}else{
|
||||||
|
throw new UnrecognizedQueryParamException("command", command);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getResponse(Long id) {
|
private String getResponse(Long id) {
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.fineract.spm.exception;
|
||||||
|
|
||||||
|
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
|
||||||
|
|
||||||
|
|
||||||
|
public class SurveyResponseNotAvailableException extends AbstractPlatformDomainRuleException {
|
||||||
|
|
||||||
|
public SurveyResponseNotAvailableException() {
|
||||||
|
super("error.msg.no.survey.response","No response available for survey.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+3
@@ -31,6 +31,9 @@ public interface SurveyRepository extends JpaRepository<Survey, Long> {
|
|||||||
@Query("select s from Survey s where :pointInTime between s.validFrom and s.validTo")
|
@Query("select s from Survey s where :pointInTime between s.validFrom and s.validTo")
|
||||||
List<Survey> fetchActiveSurveys(@Param("pointInTime") final Date pointInTime);
|
List<Survey> fetchActiveSurveys(@Param("pointInTime") final Date pointInTime);
|
||||||
|
|
||||||
|
@Query("select s from Survey s ")
|
||||||
|
List<Survey> fetchAllSurveys();
|
||||||
|
|
||||||
@Query("select s from Survey s where s.key = :key and :pointInTime between s.validFrom and s.validTo")
|
@Query("select s from Survey s where s.key = :key and :pointInTime between s.validFrom and s.validTo")
|
||||||
Survey findByKey(@Param("key") final String key, @Param("pointInTime") final Date pointInTime);
|
Survey findByKey(@Param("key") final String key, @Param("pointInTime") final Date pointInTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,12 @@ public class SpmService {
|
|||||||
return this.surveyRepository.fetchActiveSurveys(new Date());
|
return this.surveyRepository.fetchActiveSurveys(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Survey> fetchAllSurveys() {
|
||||||
|
this.securityContext.authenticatedUser();
|
||||||
|
|
||||||
|
return this.surveyRepository.fetchAllSurveys();
|
||||||
|
}
|
||||||
|
|
||||||
public Survey findById(final Long id) {
|
public Survey findById(final Long id) {
|
||||||
this.securityContext.authenticatedUser();
|
this.securityContext.authenticatedUser();
|
||||||
Survey survey = this.surveyRepository.findOne(id);
|
Survey survey = this.surveyRepository.findOne(id);
|
||||||
@@ -127,6 +133,21 @@ public class SpmService {
|
|||||||
this.surveyRepository.save(survey);
|
this.surveyRepository.save(survey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void activateSurvey(final Long id) {
|
||||||
|
this.securityContext.authenticatedUser();
|
||||||
|
|
||||||
|
final Survey survey = findById(id);
|
||||||
|
LocalDate validFrom = DateUtils.getLocalDateOfTenant() ;
|
||||||
|
Calendar cal = Calendar.getInstance() ;
|
||||||
|
cal.setTime(validFrom.toDate());
|
||||||
|
cal.add(Calendar.YEAR, 100);
|
||||||
|
survey.setValidFrom(validFrom.toDate());
|
||||||
|
survey.setValidTo(cal.getTime());
|
||||||
|
|
||||||
|
this.surveyRepository.save(survey);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static DateTime getStartOfToday() {
|
public static DateTime getStartOfToday() {
|
||||||
return DateTime.now().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0);
|
return DateTime.now().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.apache.fineract.spm.domain.Question;
|
|||||||
import org.apache.fineract.spm.domain.Response;
|
import org.apache.fineract.spm.domain.Response;
|
||||||
import org.apache.fineract.spm.domain.Scorecard;
|
import org.apache.fineract.spm.domain.Scorecard;
|
||||||
import org.apache.fineract.spm.domain.Survey;
|
import org.apache.fineract.spm.domain.Survey;
|
||||||
|
import org.apache.fineract.spm.exception.SurveyResponseNotAvailableException;
|
||||||
import org.apache.fineract.useradministration.domain.AppUser;
|
import org.apache.fineract.useradministration.domain.AppUser;
|
||||||
|
|
||||||
public class ScorecardMapper {
|
public class ScorecardMapper {
|
||||||
@@ -43,7 +44,7 @@ public class ScorecardMapper {
|
|||||||
|
|
||||||
final List<ScorecardValue> scorecardValues = scorecardData.getScorecardValues();
|
final List<ScorecardValue> scorecardValues = scorecardData.getScorecardValues();
|
||||||
|
|
||||||
if (scorecardValues != null) {
|
if (scorecardValues != null && !scorecardValues.isEmpty()) {
|
||||||
for (ScorecardValue scorecardValue : scorecardValues) {
|
for (ScorecardValue scorecardValue : scorecardValues) {
|
||||||
final Scorecard scorecard = new Scorecard();
|
final Scorecard scorecard = new Scorecard();
|
||||||
scorecards.add(scorecard);
|
scorecards.add(scorecard);
|
||||||
@@ -54,6 +55,8 @@ public class ScorecardMapper {
|
|||||||
scorecard.setCreatedOn(DateUtils.getLocalDateOfTenant().toDate());
|
scorecard.setCreatedOn(DateUtils.getLocalDateOfTenant().toDate());
|
||||||
scorecard.setValue(scorecardValue.getValue());
|
scorecard.setValue(scorecardValue.getValue());
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
throw new SurveyResponseNotAvailableException();
|
||||||
}
|
}
|
||||||
return scorecards;
|
return scorecards;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user