@@ -38989,7 +38989,7 @@ POST surveys/1/scorecards
|
||||
Content-Type: application/json
|
||||
Request Body:
|
||||
{
|
||||
"staffId": 1,
|
||||
"userId": 1,
|
||||
"clientId": 1,
|
||||
"createdOn": 1451905784553,
|
||||
"scorecardValues":
|
||||
@@ -39069,7 +39069,7 @@ No Request Body
|
||||
<code class="method-response">
|
||||
[
|
||||
{
|
||||
"staffId": 1,
|
||||
"userId": 1,
|
||||
"clientId": 1,
|
||||
"createdOn": 1451905784553,
|
||||
"scorecardValues":
|
||||
|
||||
@@ -6,20 +6,17 @@
|
||||
package org.mifosplatform.spm.api;
|
||||
|
||||
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.ClientRepository;
|
||||
import org.mifosplatform.portfolio.client.exception.ClientNotFoundException;
|
||||
import org.mifosplatform.spm.data.ScorecardData;
|
||||
import org.mifosplatform.spm.data.ScorecardValue;
|
||||
import org.mifosplatform.spm.domain.Scorecard;
|
||||
import org.mifosplatform.spm.domain.Survey;
|
||||
import org.mifosplatform.spm.exception.SurveyNotFoundException;
|
||||
import org.mifosplatform.spm.service.ScorecardService;
|
||||
import org.mifosplatform.spm.service.SpmService;
|
||||
import org.mifosplatform.spm.util.ScorecardMapper;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -27,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -39,18 +35,15 @@ public class ScorecardApiResource {
|
||||
private final PlatformSecurityContext securityContext;
|
||||
private final SpmService spmService;
|
||||
private final ScorecardService scorecardService;
|
||||
private final StaffRepository staffRepository;
|
||||
private final ClientRepository clientRepository;
|
||||
|
||||
@Autowired
|
||||
public ScorecardApiResource(final PlatformSecurityContext securityContext, final SpmService spmService,
|
||||
final ScorecardService scorecardService, final StaffRepository staffRepository,
|
||||
final ClientRepository clientRepository) {
|
||||
final ScorecardService scorecardService, final ClientRepository clientRepository) {
|
||||
super();
|
||||
this.securityContext = securityContext;
|
||||
this.spmService = spmService;
|
||||
this.scorecardService = scorecardService;
|
||||
this.staffRepository = staffRepository;
|
||||
this.clientRepository = clientRepository;
|
||||
}
|
||||
|
||||
@@ -77,23 +70,17 @@ public class ScorecardApiResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Transactional
|
||||
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 Staff staff = this.staffRepository.findOne(scorecardData.getStaffId());
|
||||
|
||||
if (staff == null) {
|
||||
throw new StaffNotFoundException(scorecardData.getStaffId());
|
||||
}
|
||||
|
||||
final Client client = this.clientRepository.findOne(scorecardData.getClientId());
|
||||
|
||||
if (client == null) {
|
||||
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}")
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
public class ScorecardData {
|
||||
|
||||
private Long staffId;
|
||||
private Long userId;
|
||||
private Long clientId;
|
||||
private Date createdOn;
|
||||
private List<ScorecardValue> scorecardValues;
|
||||
@@ -19,21 +19,21 @@ public class ScorecardData {
|
||||
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) {
|
||||
super();
|
||||
this.staffId = staffId;
|
||||
this.userId = userId;
|
||||
this.clientId = clientId;
|
||||
this.createdOn = createdOn;
|
||||
this.scorecardValues = scorecardValues;
|
||||
}
|
||||
|
||||
public Long getStaffId() {
|
||||
return staffId;
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setStaffId(Long staffId) {
|
||||
this.staffId = staffId;
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getClientId() {
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
*/
|
||||
package org.mifosplatform.spm.domain;
|
||||
|
||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||
import org.mifosplatform.portfolio.client.domain.Client;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.springframework.data.jpa.domain.AbstractPersistable;
|
||||
|
||||
import javax.persistence.*;
|
||||
@@ -29,8 +29,8 @@ public class Scorecard extends AbstractPersistable<Long> {
|
||||
private Response response;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "staff_id")
|
||||
private Staff staff;
|
||||
@JoinColumn(name = "user_id")
|
||||
private AppUser appUser;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "client_id")
|
||||
@@ -72,12 +72,12 @@ public class Scorecard extends AbstractPersistable<Long> {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public Staff getStaff() {
|
||||
return staff;
|
||||
public AppUser getAppUser() {
|
||||
return appUser;
|
||||
}
|
||||
|
||||
public void setStaff(Staff staff) {
|
||||
this.staff = staff;
|
||||
public void setAppUser(AppUser appUser) {
|
||||
this.appUser = appUser;
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.mifosplatform.spm.domain.Question;
|
||||
import org.mifosplatform.spm.domain.Response;
|
||||
import org.mifosplatform.spm.domain.Scorecard;
|
||||
import org.mifosplatform.spm.domain.Survey;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -30,7 +31,7 @@ public class ScorecardMapper {
|
||||
if ((scorecardData = scorecardDataMap.get(scorecard.getCreatedOn())) == null) {
|
||||
scorecardData = new ScorecardData();
|
||||
scorecardDataMap.put(scorecard.getCreatedOn(), scorecardData);
|
||||
scorecardData.setStaffId(scorecard.getStaff().getId());
|
||||
scorecardData.setUserId(scorecard.getAppUser().getId());
|
||||
scorecardData.setClientId(scorecard.getClient().getId());
|
||||
scorecardData.setCreatedOn(scorecard.getCreatedOn());
|
||||
scorecardData.setScorecardValues(new ArrayList<ScorecardValue>());
|
||||
@@ -47,7 +48,7 @@ public class ScorecardMapper {
|
||||
}
|
||||
|
||||
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<ScorecardValue> scorecardValues = scorecardData.getScorecardValues();
|
||||
@@ -58,7 +59,7 @@ public class ScorecardMapper {
|
||||
scorecards.add(scorecard);
|
||||
scorecard.setSurvey(survey);
|
||||
ScorecardMapper.setQuestionAndResponse(scorecardValue, scorecard, survey);
|
||||
scorecard.setStaff(staff);
|
||||
scorecard.setAppUser(appUser);
|
||||
scorecard.setClient(client);
|
||||
scorecard.setCreatedOn(scorecardData.getCreatedOn());
|
||||
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