Repository: fineract
Updated Branches:
  refs/heads/develop 6b113cc18 -> a3e8c5e5b


Survey bug fix 529, 530


Project: http://git-wip-us.apache.org/repos/asf/fineract/repo
Commit: http://git-wip-us.apache.org/repos/asf/fineract/commit/db59e8cd
Tree: http://git-wip-us.apache.org/repos/asf/fineract/tree/db59e8cd
Diff: http://git-wip-us.apache.org/repos/asf/fineract/diff/db59e8cd

Branch: refs/heads/develop
Commit: db59e8cd7a7fe1ceee2e11934268ffa45f3dbdd8
Parents: d6accae
Author: nazeer shaik <nazeer.sh...@confluxtechnologies.com>
Authored: Tue Nov 14 14:56:38 2017 +0530
Committer: nazeer shaik <nazeer.sh...@confluxtechnologies.com>
Committed: Tue Nov 14 14:56:38 2017 +0530

----------------------------------------------------------------------
 .../apache/fineract/spm/api/SpmApiResource.java | 24 ++++++++++++----
 .../SurveyResponseNotAvailableException.java    | 30 ++++++++++++++++++++
 .../spm/repository/SurveyRepository.java        |  3 ++
 .../apache/fineract/spm/service/SpmService.java | 21 ++++++++++++++
 .../fineract/spm/util/ScorecardMapper.java      |  5 +++-
 5 files changed, 77 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/fineract/blob/db59e8cd/fineract-provider/src/main/java/org/apache/fineract/spm/api/SpmApiResource.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/spm/api/SpmApiResource.java
 
b/fineract-provider/src/main/java/org/apache/fineract/spm/api/SpmApiResource.java
index 46afed0..1e00a71 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/spm/api/SpmApiResource.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/spm/api/SpmApiResource.java
@@ -30,8 +30,10 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 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.spm.data.SurveyData;
 import org.apache.fineract.spm.domain.Survey;
@@ -62,10 +64,15 @@ public class SpmApiResource {
     @Consumes({ MediaType.APPLICATION_JSON })
     @Produces({ MediaType.APPLICATION_JSON })
     @Transactional
-    public List<SurveyData> fetchActiveSurveys() {
+    public List<SurveyData> fetchAllSurveys(@QueryParam("isActive") final 
Boolean isActive) {
         this.securityContext.authenticatedUser();
         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) {
             for (final Survey survey : surveys) {
                 result.add(SurveyMapper.map(survey));
@@ -110,14 +117,21 @@ public class SpmApiResource {
         return getResponse(survey.getId());
     }
 
-    @DELETE
+    @POST
     @Path("/{id}")
     @Consumes({ MediaType.APPLICATION_JSON })
     @Produces({ MediaType.APPLICATION_JSON })
     @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.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) {

http://git-wip-us.apache.org/repos/asf/fineract/blob/db59e8cd/fineract-provider/src/main/java/org/apache/fineract/spm/exception/SurveyResponseNotAvailableException.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/spm/exception/SurveyResponseNotAvailableException.java
 
b/fineract-provider/src/main/java/org/apache/fineract/spm/exception/SurveyResponseNotAvailableException.java
new file mode 100644
index 0000000..a194b6c
--- /dev/null
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/spm/exception/SurveyResponseNotAvailableException.java
@@ -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.");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/fineract/blob/db59e8cd/fineract-provider/src/main/java/org/apache/fineract/spm/repository/SurveyRepository.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/spm/repository/SurveyRepository.java
 
b/fineract-provider/src/main/java/org/apache/fineract/spm/repository/SurveyRepository.java
index 6c6344a..4e60376 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/spm/repository/SurveyRepository.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/spm/repository/SurveyRepository.java
@@ -30,6 +30,9 @@ public interface SurveyRepository extends 
JpaRepository<Survey, Long> {
 
     @Query("select s from Survey s where :pointInTime between s.validFrom and 
s.validTo")
     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")
     Survey findByKey(@Param("key") final String key, @Param("pointInTime") 
final Date pointInTime);

http://git-wip-us.apache.org/repos/asf/fineract/blob/db59e8cd/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java
 
b/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java
index 8d6f0fa..a1e837a 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/spm/service/SpmService.java
@@ -61,6 +61,12 @@ public class SpmService {
 
         return this.surveyRepository.fetchActiveSurveys(new Date());
     }
+    
+    public List<Survey> fetchAllSurveys() {
+        this.securityContext.authenticatedUser();
+
+        return this.surveyRepository.fetchAllSurveys();
+    }
 
     public Survey findById(final Long id) {
         this.securityContext.authenticatedUser();
@@ -127,6 +133,21 @@ public class SpmService {
         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() {
         return 
DateTime.now().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0);
     }

http://git-wip-us.apache.org/repos/asf/fineract/blob/db59e8cd/fineract-provider/src/main/java/org/apache/fineract/spm/util/ScorecardMapper.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/spm/util/ScorecardMapper.java
 
b/fineract-provider/src/main/java/org/apache/fineract/spm/util/ScorecardMapper.java
index 60588d8..573c52d 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/spm/util/ScorecardMapper.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/spm/util/ScorecardMapper.java
@@ -29,6 +29,7 @@ import org.apache.fineract.spm.domain.Question;
 import org.apache.fineract.spm.domain.Response;
 import org.apache.fineract.spm.domain.Scorecard;
 import org.apache.fineract.spm.domain.Survey;
+import org.apache.fineract.spm.exception.SurveyResponseNotAvailableException;
 import org.apache.fineract.useradministration.domain.AppUser;
 
 public class ScorecardMapper {
@@ -43,7 +44,7 @@ public class ScorecardMapper {
 
         final List<ScorecardValue> scorecardValues = 
scorecardData.getScorecardValues();
 
-        if (scorecardValues != null) {
+        if (scorecardValues != null && !scorecardValues.isEmpty()) {
            for (ScorecardValue scorecardValue : scorecardValues) {
                final Scorecard scorecard = new Scorecard();
                scorecards.add(scorecard);
@@ -54,6 +55,8 @@ public class ScorecardMapper {
                
scorecard.setCreatedOn(DateUtils.getLocalDateOfTenant().toDate());
                scorecard.setValue(scorecardValue.getValue());
            }
+        }else{
+            throw new SurveyResponseNotAvailableException();
         }
         return scorecards;
     }

Reply via email to