@@ -38989,7 +38989,7 @@ POST surveys/1/scorecards
|
|||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Request Body:
|
Request Body:
|
||||||
{
|
{
|
||||||
"staffId": 1,
|
"userId": 1,
|
||||||
"clientId": 1,
|
"clientId": 1,
|
||||||
"createdOn": 1451905784553,
|
"createdOn": 1451905784553,
|
||||||
"scorecardValues":
|
"scorecardValues":
|
||||||
@@ -39069,7 +39069,7 @@ No Request Body
|
|||||||
<code class="method-response">
|
<code class="method-response">
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"staffId": 1,
|
"userId": 1,
|
||||||
"clientId": 1,
|
"clientId": 1,
|
||||||
"createdOn": 1451905784553,
|
"createdOn": 1451905784553,
|
||||||
"scorecardValues":
|
"scorecardValues":
|
||||||
|
|||||||
@@ -6,20 +6,17 @@
|
|||||||
package org.mifosplatform.spm.api;
|
package org.mifosplatform.spm.api;
|
||||||
|
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
|
||||||
import org.mifosplatform.organisation.staff.domain.StaffRepository;
|
|
||||||
import org.mifosplatform.organisation.staff.exception.StaffNotFoundException;
|
|
||||||
import org.mifosplatform.portfolio.client.domain.Client;
|
import org.mifosplatform.portfolio.client.domain.Client;
|
||||||
import org.mifosplatform.portfolio.client.domain.ClientRepository;
|
import org.mifosplatform.portfolio.client.domain.ClientRepository;
|
||||||
import org.mifosplatform.portfolio.client.exception.ClientNotFoundException;
|
import org.mifosplatform.portfolio.client.exception.ClientNotFoundException;
|
||||||
import org.mifosplatform.spm.data.ScorecardData;
|
import org.mifosplatform.spm.data.ScorecardData;
|
||||||
import org.mifosplatform.spm.data.ScorecardValue;
|
|
||||||
import org.mifosplatform.spm.domain.Scorecard;
|
import org.mifosplatform.spm.domain.Scorecard;
|
||||||
import org.mifosplatform.spm.domain.Survey;
|
import org.mifosplatform.spm.domain.Survey;
|
||||||
import org.mifosplatform.spm.exception.SurveyNotFoundException;
|
import org.mifosplatform.spm.exception.SurveyNotFoundException;
|
||||||
import org.mifosplatform.spm.service.ScorecardService;
|
import org.mifosplatform.spm.service.ScorecardService;
|
||||||
import org.mifosplatform.spm.service.SpmService;
|
import org.mifosplatform.spm.service.SpmService;
|
||||||
import org.mifosplatform.spm.util.ScorecardMapper;
|
import org.mifosplatform.spm.util.ScorecardMapper;
|
||||||
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -27,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -39,18 +35,15 @@ public class ScorecardApiResource {
|
|||||||
private final PlatformSecurityContext securityContext;
|
private final PlatformSecurityContext securityContext;
|
||||||
private final SpmService spmService;
|
private final SpmService spmService;
|
||||||
private final ScorecardService scorecardService;
|
private final ScorecardService scorecardService;
|
||||||
private final StaffRepository staffRepository;
|
|
||||||
private final ClientRepository clientRepository;
|
private final ClientRepository clientRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ScorecardApiResource(final PlatformSecurityContext securityContext, final SpmService spmService,
|
public ScorecardApiResource(final PlatformSecurityContext securityContext, final SpmService spmService,
|
||||||
final ScorecardService scorecardService, final StaffRepository staffRepository,
|
final ScorecardService scorecardService, final ClientRepository clientRepository) {
|
||||||
final ClientRepository clientRepository) {
|
|
||||||
super();
|
super();
|
||||||
this.securityContext = securityContext;
|
this.securityContext = securityContext;
|
||||||
this.spmService = spmService;
|
this.spmService = spmService;
|
||||||
this.scorecardService = scorecardService;
|
this.scorecardService = scorecardService;
|
||||||
this.staffRepository = staffRepository;
|
|
||||||
this.clientRepository = clientRepository;
|
this.clientRepository = clientRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,23 +70,17 @@ public class ScorecardApiResource {
|
|||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
@Transactional
|
@Transactional
|
||||||
public void createScorecard(@PathParam("surveyId") final Long surveyId, final ScorecardData scorecardData) {
|
public void createScorecard(@PathParam("surveyId") final Long surveyId, final ScorecardData scorecardData) {
|
||||||
this.securityContext.authenticatedUser();
|
final AppUser appUser = this.securityContext.authenticatedUser();
|
||||||
|
|
||||||
final Survey survey = findSurvey(surveyId);
|
final Survey survey = findSurvey(surveyId);
|
||||||
|
|
||||||
final Staff staff = this.staffRepository.findOne(scorecardData.getStaffId());
|
|
||||||
|
|
||||||
if (staff == null) {
|
|
||||||
throw new StaffNotFoundException(scorecardData.getStaffId());
|
|
||||||
}
|
|
||||||
|
|
||||||
final Client client = this.clientRepository.findOne(scorecardData.getClientId());
|
final Client client = this.clientRepository.findOne(scorecardData.getClientId());
|
||||||
|
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
throw new ClientNotFoundException(scorecardData.getClientId());
|
throw new ClientNotFoundException(scorecardData.getClientId());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scorecardService.createScorecard(ScorecardMapper.map(scorecardData, survey, staff, client));
|
this.scorecardService.createScorecard(ScorecardMapper.map(scorecardData, survey, appUser, client));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Path("/clients/{clientId}")
|
@Path("/clients/{clientId}")
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ScorecardData {
|
public class ScorecardData {
|
||||||
|
|
||||||
private Long staffId;
|
private Long userId;
|
||||||
private Long clientId;
|
private Long clientId;
|
||||||
private Date createdOn;
|
private Date createdOn;
|
||||||
private List<ScorecardValue> scorecardValues;
|
private List<ScorecardValue> scorecardValues;
|
||||||
@@ -19,21 +19,21 @@ public class ScorecardData {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScorecardData(final Long staffId, final Long clientId, final Date createdOn,
|
public ScorecardData(final Long userId, final Long clientId, final Date createdOn,
|
||||||
final List<ScorecardValue> scorecardValues) {
|
final List<ScorecardValue> scorecardValues) {
|
||||||
super();
|
super();
|
||||||
this.staffId = staffId;
|
this.userId = userId;
|
||||||
this.clientId = clientId;
|
this.clientId = clientId;
|
||||||
this.createdOn = createdOn;
|
this.createdOn = createdOn;
|
||||||
this.scorecardValues = scorecardValues;
|
this.scorecardValues = scorecardValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getStaffId() {
|
public Long getUserId() {
|
||||||
return staffId;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStaffId(Long staffId) {
|
public void setUserId(Long userId) {
|
||||||
this.staffId = staffId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getClientId() {
|
public Long getClientId() {
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.spm.domain;
|
package org.mifosplatform.spm.domain;
|
||||||
|
|
||||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
|
||||||
import org.mifosplatform.portfolio.client.domain.Client;
|
import org.mifosplatform.portfolio.client.domain.Client;
|
||||||
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
@@ -29,8 +29,8 @@ public class Scorecard extends AbstractPersistable<Long> {
|
|||||||
private Response response;
|
private Response response;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "staff_id")
|
@JoinColumn(name = "user_id")
|
||||||
private Staff staff;
|
private AppUser appUser;
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "client_id")
|
@JoinColumn(name = "client_id")
|
||||||
@@ -72,12 +72,12 @@ public class Scorecard extends AbstractPersistable<Long> {
|
|||||||
this.response = response;
|
this.response = response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Staff getStaff() {
|
public AppUser getAppUser() {
|
||||||
return staff;
|
return appUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStaff(Staff staff) {
|
public void setAppUser(AppUser appUser) {
|
||||||
this.staff = staff;
|
this.appUser = appUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Client getClient() {
|
public Client getClient() {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.mifosplatform.spm.domain.Question;
|
|||||||
import org.mifosplatform.spm.domain.Response;
|
import org.mifosplatform.spm.domain.Response;
|
||||||
import org.mifosplatform.spm.domain.Scorecard;
|
import org.mifosplatform.spm.domain.Scorecard;
|
||||||
import org.mifosplatform.spm.domain.Survey;
|
import org.mifosplatform.spm.domain.Survey;
|
||||||
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ public class ScorecardMapper {
|
|||||||
if ((scorecardData = scorecardDataMap.get(scorecard.getCreatedOn())) == null) {
|
if ((scorecardData = scorecardDataMap.get(scorecard.getCreatedOn())) == null) {
|
||||||
scorecardData = new ScorecardData();
|
scorecardData = new ScorecardData();
|
||||||
scorecardDataMap.put(scorecard.getCreatedOn(), scorecardData);
|
scorecardDataMap.put(scorecard.getCreatedOn(), scorecardData);
|
||||||
scorecardData.setStaffId(scorecard.getStaff().getId());
|
scorecardData.setUserId(scorecard.getAppUser().getId());
|
||||||
scorecardData.setClientId(scorecard.getClient().getId());
|
scorecardData.setClientId(scorecard.getClient().getId());
|
||||||
scorecardData.setCreatedOn(scorecard.getCreatedOn());
|
scorecardData.setCreatedOn(scorecard.getCreatedOn());
|
||||||
scorecardData.setScorecardValues(new ArrayList<ScorecardValue>());
|
scorecardData.setScorecardValues(new ArrayList<ScorecardValue>());
|
||||||
@@ -47,7 +48,7 @@ public class ScorecardMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<Scorecard> map(final ScorecardData scorecardData, final Survey survey,
|
public static List<Scorecard> map(final ScorecardData scorecardData, final Survey survey,
|
||||||
final Staff staff, final Client client) {
|
final AppUser appUser, final Client client) {
|
||||||
final List<Scorecard> scorecards = new ArrayList<>();
|
final List<Scorecard> scorecards = new ArrayList<>();
|
||||||
|
|
||||||
final List<ScorecardValue> scorecardValues = scorecardData.getScorecardValues();
|
final List<ScorecardValue> scorecardValues = scorecardData.getScorecardValues();
|
||||||
@@ -58,7 +59,7 @@ public class ScorecardMapper {
|
|||||||
scorecards.add(scorecard);
|
scorecards.add(scorecard);
|
||||||
scorecard.setSurvey(survey);
|
scorecard.setSurvey(survey);
|
||||||
ScorecardMapper.setQuestionAndResponse(scorecardValue, scorecard, survey);
|
ScorecardMapper.setQuestionAndResponse(scorecardValue, scorecard, survey);
|
||||||
scorecard.setStaff(staff);
|
scorecard.setAppUser(appUser);
|
||||||
scorecard.setClient(client);
|
scorecard.setClient(client);
|
||||||
scorecard.setCreatedOn(scorecardData.getCreatedOn());
|
scorecard.setCreatedOn(scorecardData.getCreatedOn());
|
||||||
scorecard.setValue(scorecardValue.getValue());
|
scorecard.setValue(scorecardValue.getValue());
|
||||||
|
|||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
DROP TABLE IF EXISTS `m_survey_scorecards`;
|
||||||
|
CREATE TABLE `m_survey_scorecards` (
|
||||||
|
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`survey_id` BIGINT(20) NOT NULL,
|
||||||
|
`question_id` BIGINT(20) NOT NULL,
|
||||||
|
`response_id` BIGINT(20) NOT NULL,
|
||||||
|
`user_id` BIGINT(20) NOT NULL,
|
||||||
|
`client_id` BIGINT(20) NOT NULL,
|
||||||
|
`created_on` DATETIME NULL DEFAULT NULL,
|
||||||
|
`a_value` INT(4) NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
FOREIGN KEY (`survey_id`) REFERENCES `m_surveys` (`id`),
|
||||||
|
FOREIGN KEY (`question_id`) REFERENCES `m_survey_questions` (`id`),
|
||||||
|
FOREIGN KEY (`response_id`) REFERENCES `m_survey_responses` (`id`),
|
||||||
|
FOREIGN KEY (`user_id`) REFERENCES `m_appusers` (`id`),
|
||||||
|
FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`)
|
||||||
|
);
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
Reference in New Issue
Block a user