| 1 |  |  package org.kuali.student.lum.program.server; | 
  | 2 |  |   | 
  | 3 |  |  import org.kuali.student.common.ui.server.gwt.AbstractDataService; | 
  | 4 |  |  import org.kuali.student.core.exceptions.InvalidParameterException; | 
  | 5 |  |  import org.kuali.student.core.exceptions.OperationFailedException; | 
  | 6 |  |  import org.kuali.student.lum.lu.service.LuService; | 
  | 7 |  |  import org.kuali.student.lum.program.client.ProgramClientConstants; | 
  | 8 |  |  import org.kuali.student.lum.program.dto.MajorDisciplineInfo; | 
  | 9 |  |  import org.kuali.student.lum.program.service.ProgramService; | 
  | 10 |  |   | 
  | 11 |  |  import java.util.List; | 
  | 12 |  |  import java.util.Map; | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |   | 
  | 17 | 0 |  public class MajorDisciplineDataService extends AbstractDataService { | 
  | 18 |  |   | 
  | 19 |  |      private static final long serialVersionUID = 1L; | 
  | 20 |  |       | 
  | 21 |  |      private ProgramService programService; | 
  | 22 |  |      private LuService luService; | 
  | 23 |  |   | 
  | 24 |  |      @Override | 
  | 25 |  |      protected String getDefaultWorkflowDocumentType() { | 
  | 26 | 0 |          return null; | 
  | 27 |  |      } | 
  | 28 |  |   | 
  | 29 |  |      @Override | 
  | 30 |  |      protected String getDefaultMetaDataState() { | 
  | 31 | 0 |          return null; | 
  | 32 |  |      } | 
  | 33 |  |   | 
  | 34 |  |      @Override | 
  | 35 |  |      protected Object get(String id) throws Exception { | 
  | 36 |  |               | 
  | 37 |  |          MajorDisciplineInfo returnDTO; | 
  | 38 | 0 |          if (null == id || id.length() == 0) { | 
  | 39 | 0 |              returnDTO = new MajorDisciplineInfo(); | 
  | 40 | 0 |              returnDTO.setType(ProgramClientConstants.MAJOR_PROGRAM); | 
  | 41 | 0 |              returnDTO.setState(ProgramClientConstants.STATE_DRAFT); | 
  | 42 | 0 |              returnDTO.setCredentialProgramId(getCredentialId()); | 
  | 43 |  |          } else { | 
  | 44 | 0 |              returnDTO = programService.getMajorDiscipline(id); | 
  | 45 |  |          } | 
  | 46 | 0 |          return returnDTO; | 
  | 47 |  |      } | 
  | 48 |  |   | 
  | 49 |  |      @Override | 
  | 50 |  |      protected Object save(Object dto, Map<String, Object> properties) throws Exception { | 
  | 51 | 0 |          if (dto instanceof MajorDisciplineInfo) { | 
  | 52 | 0 |              MajorDisciplineInfo mdInfo = (MajorDisciplineInfo) dto; | 
  | 53 | 0 |              if (mdInfo.getId() == null && mdInfo.getVersionInfo() != null) { | 
  | 54 | 0 |                      String majorVersionIndId = mdInfo.getVersionInfo().getVersionIndId(); | 
  | 55 | 0 |                      mdInfo = programService.createNewMajorDisciplineVersion(majorVersionIndId, "New major discipline version"); | 
  | 56 | 0 |              } else if (mdInfo.getId() == null){ | 
  | 57 | 0 |                  mdInfo = programService.createMajorDiscipline(mdInfo); | 
  | 58 |  |              } else { | 
  | 59 | 0 |                  mdInfo = programService.updateMajorDiscipline(mdInfo); | 
  | 60 |  |              } | 
  | 61 | 0 |              return mdInfo; | 
  | 62 |  |          } else { | 
  | 63 | 0 |              throw new InvalidParameterException("Only persistence of MajorDiscipline is supported by this DataService implementation."); | 
  | 64 |  |          } | 
  | 65 |  |      }   | 
  | 66 |  |   | 
  | 67 |  |      @Override | 
  | 68 |  |      protected Class<?> getDtoClass() { | 
  | 69 | 0 |          return MajorDisciplineInfo.class; | 
  | 70 |  |      } | 
  | 71 |  |   | 
  | 72 |  |      private String getCredentialId() throws Exception { | 
  | 73 |  |   | 
  | 74 | 0 |              List<String> credIds = luService.getCluIdsByLuType(ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM, ProgramClientConstants.STATE_ACTIVE); | 
  | 75 | 0 |              if (null == credIds || credIds.size() != 1) { | 
  | 76 | 0 |                  throw new OperationFailedException("A single credential program of type " + ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM + " is required; database contains " + | 
  | 77 |  |                                                      (null == credIds ? "0" : credIds.size() + | 
  | 78 |  |                                                      ".")); | 
  | 79 |  |              } | 
  | 80 | 0 |              return credIds.get(0); | 
  | 81 |  |      } | 
  | 82 |  |   | 
  | 83 |  |      public void setProgramService(ProgramService programService) { | 
  | 84 | 0 |          this.programService = programService; | 
  | 85 | 0 |      } | 
  | 86 |  |   | 
  | 87 |  |      public void setLuService(LuService luService) { | 
  | 88 | 0 |          this.luService = luService; | 
  | 89 | 0 |      } | 
  | 90 |  |   | 
  | 91 |  |  } |