| 1 | |
package org.kuali.student.lum.program.server; |
| 2 | |
|
| 3 | |
import java.util.HashMap; |
| 4 | |
import java.util.List; |
| 5 | |
import java.util.Map; |
| 6 | |
|
| 7 | |
import org.kuali.student.common.dto.DtoConstants; |
| 8 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
| 9 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
| 10 | |
import org.kuali.student.common.ui.server.gwt.AbstractDataService; |
| 11 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
| 12 | |
import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo; |
| 13 | |
import org.kuali.student.core.assembly.transform.ProposalWorkflowFilter; |
| 14 | |
import org.kuali.student.lum.lu.service.LuService; |
| 15 | |
import org.kuali.student.lum.program.client.ProgramClientConstants; |
| 16 | |
import org.kuali.student.lum.program.client.ProgramConstants; |
| 17 | |
import org.kuali.student.lum.program.dto.MajorDisciplineInfo; |
| 18 | |
import org.kuali.student.lum.program.service.ProgramService; |
| 19 | |
import org.kuali.student.lum.program.service.ProgramServiceConstants; |
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | 0 | public class MajorDisciplineProposalDataService extends AbstractDataService { |
| 25 | |
|
| 26 | |
private static final long serialVersionUID = 1L; |
| 27 | |
|
| 28 | |
private ProgramService programService; |
| 29 | |
private LuService luService; |
| 30 | |
|
| 31 | |
@Override |
| 32 | |
protected String getDefaultWorkflowDocumentType() { |
| 33 | 0 | return null; |
| 34 | |
} |
| 35 | |
|
| 36 | |
@Override |
| 37 | |
protected String getDefaultMetaDataState() { |
| 38 | 0 | return null; |
| 39 | |
} |
| 40 | |
|
| 41 | |
@Override |
| 42 | |
protected Object get(String id) throws Exception { |
| 43 | |
|
| 44 | |
MajorDisciplineInfo returnDTO; |
| 45 | 0 | if (null == id || id.length() == 0) { |
| 46 | 0 | returnDTO = new MajorDisciplineInfo(); |
| 47 | 0 | returnDTO.setType(ProgramClientConstants.MAJOR_PROGRAM); |
| 48 | 0 | returnDTO.setState(DtoConstants.STATE_DRAFT); |
| 49 | 0 | returnDTO.setCredentialProgramId(getCredentialId()); |
| 50 | |
} else { |
| 51 | 0 | returnDTO = programService.getMajorDiscipline(id); |
| 52 | |
} |
| 53 | 0 | return returnDTO; |
| 54 | |
} |
| 55 | |
|
| 56 | |
@Override |
| 57 | |
protected Object save(Object dto, Map<String, Object> properties) throws Exception { |
| 58 | 0 | if (dto instanceof MajorDisciplineInfo) { |
| 59 | 0 | MajorDisciplineInfo mdInfo = (MajorDisciplineInfo) dto; |
| 60 | 0 | if (mdInfo.getId() == null && mdInfo.getVersionInfo() != null) { |
| 61 | |
|
| 62 | 0 | String majorVersionIndId = mdInfo.getVersionInfo().getVersionIndId(); |
| 63 | |
|
| 64 | |
|
| 65 | 0 | VersionDisplayInfo mdVersionInfo = programService.getCurrentVersion(ProgramServiceConstants.PROGRAM_NAMESPACE_MAJOR_DISCIPLINE_URI, majorVersionIndId); |
| 66 | 0 | mdInfo = programService.getMajorDiscipline(mdVersionInfo.getId()); |
| 67 | |
|
| 68 | |
|
| 69 | 0 | String startTerm = mdInfo.getStartTerm(); |
| 70 | 0 | String endTerm = mdInfo.getEndTerm(); |
| 71 | 0 | String endProgramEntryTerm = mdInfo.getEndProgramEntryTerm(); |
| 72 | 0 | String endInstAdmitTerm = mdInfo.getAttributes().get(ProgramConstants.END_INSTITUTIONAL_ADMIT_TERM); |
| 73 | 0 | Map<String,String> proposalAttributes = new HashMap<String,String>(); |
| 74 | 0 | if(startTerm!=null) |
| 75 | 0 | proposalAttributes.put("prevStartTerm",startTerm); |
| 76 | 0 | if(endTerm!=null) |
| 77 | 0 | proposalAttributes.put("prevEndTerm",endTerm); |
| 78 | 0 | if(endProgramEntryTerm!=null) |
| 79 | 0 | proposalAttributes.put("prevEndProgramEntryTerm",endProgramEntryTerm); |
| 80 | 0 | if(endInstAdmitTerm!=null) |
| 81 | 0 | proposalAttributes.put("prevEndInstAdmitTerm",endInstAdmitTerm); |
| 82 | 0 | properties.put(ProposalWorkflowFilter.PROPOSAL_ATTRIBUTES, proposalAttributes); |
| 83 | |
|
| 84 | 0 | mdInfo = programService.createNewMajorDisciplineVersion(majorVersionIndId, "New major discipline version"); |
| 85 | 0 | } else if (mdInfo.getId() == null){ |
| 86 | 0 | mdInfo = programService.createMajorDiscipline(mdInfo); |
| 87 | |
} else { |
| 88 | 0 | mdInfo = programService.updateMajorDiscipline(mdInfo); |
| 89 | |
} |
| 90 | 0 | return mdInfo; |
| 91 | |
} else { |
| 92 | 0 | throw new InvalidParameterException("Only persistence of MajorDiscipline is supported by this DataService implementation."); |
| 93 | |
} |
| 94 | |
} |
| 95 | |
|
| 96 | |
|
| 97 | |
@Override |
| 98 | |
protected List<ValidationResultInfo> validate(Object dto) throws Exception { |
| 99 | 0 | return programService.validateMajorDiscipline("OBJECT", (MajorDisciplineInfo)dto); |
| 100 | |
} |
| 101 | |
|
| 102 | |
@Override |
| 103 | |
protected Class<?> getDtoClass() { |
| 104 | 0 | return MajorDisciplineInfo.class; |
| 105 | |
} |
| 106 | |
|
| 107 | |
private String getCredentialId() throws Exception { |
| 108 | |
|
| 109 | 0 | List<String> credIds = luService.getCluIdsByLuType(ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM, DtoConstants.STATE_ACTIVE); |
| 110 | 0 | if (null == credIds || credIds.size() != 1) { |
| 111 | 0 | throw new OperationFailedException("A single credential program of type " + ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM + " is required; database contains " + |
| 112 | |
(null == credIds ? "0" : credIds.size() + |
| 113 | |
".")); |
| 114 | |
} |
| 115 | 0 | return credIds.get(0); |
| 116 | |
} |
| 117 | |
|
| 118 | |
public void setProgramService(ProgramService programService) { |
| 119 | 0 | this.programService = programService; |
| 120 | 0 | } |
| 121 | |
|
| 122 | |
public void setLuService(LuService luService) { |
| 123 | 0 | this.luService = luService; |
| 124 | 0 | } |
| 125 | |
|
| 126 | |
} |