Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1597 from mgeiss/MIFSX-SPM-5
Browse files Browse the repository at this point in the history
Mifsx spm 5
  • Loading branch information
Markus Geiß committed Jan 14, 2016
2 parents 34fe42c + b5c355c commit 787bad8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 36 deletions.
4 changes: 2 additions & 2 deletions api-docs/apiLive.htm
Original file line number Diff line number Diff line change
Expand Up @@ -38989,7 +38989,7 @@ <h3>Create a Scorecard entry</h3>
Content-Type: application/json
Request Body:
{
"staffId": 1,
"userId": 1,
"clientId": 1,
"createdOn": 1451905784553,
"scorecardValues":
Expand Down Expand Up @@ -39069,7 +39069,7 @@ <h3>List all Scorecard entries</h3>
<code class="method-response">
[
{
"staffId": 1,
"userId": 1,
"clientId": 1,
"createdOn": 1451905784553,
"scorecardValues":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,24 @@
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;
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;

Expand All @@ -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;
}

Expand All @@ -77,23 +70,17 @@ public List<ScorecardData> findBySurvey(@PathParam("surveyId") final Long survey
@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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class ScorecardData {

private Long staffId;
private Long userId;
private Long clientId;
private Date createdOn;
private List<ScorecardValue> scorecardValues;
Expand All @@ -19,21 +19,21 @@ public 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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")
Expand Down Expand Up @@ -72,12 +72,12 @@ public void setResponse(Response response) {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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.*;

Expand All @@ -30,7 +31,7 @@ public static List<ScorecardData> map(final List<Scorecard> scorecards) {
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>());
Expand All @@ -47,7 +48,7 @@ public static List<ScorecardData> map(final List<Scorecard> scorecards) {
}

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();
Expand All @@ -58,7 +59,7 @@ public static List<Scorecard> map(final ScorecardData scorecardData, final Surve
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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 787bad8

Please sign in to comment.