/**
   * Loads the Notes for the note target on this Document.
   *
   * @param document the document for which to load the notes
   */
  protected void loadNotes(final Document document) {
    if (isNoteTargetReady(document)) {
      Object legacyObjectClass;
      if (document instanceof MaintenanceDocument) {
        MaintenanceDocument mdoc = (MaintenanceDocument) document;
        legacyObjectClass =
            ((Maintainable)
                    org.apache.commons.lang.ObjectUtils.defaultIfNull(
                        mdoc.getOldMaintainableObject(), mdoc.getNewMaintainableObject()))
                .getDataObjectClass();
      } else {
        legacyObjectClass = document.getClass();
      }

      List<Note> notes = new ArrayList<Note>();
      if (StringUtils.isNotBlank(document.getNoteTarget().getObjectId())) {
        notes.addAll(getNoteService().getByRemoteObjectId(document.getNoteTarget().getObjectId()));
      }
      // notes created on 'disapprove' are linked to Doc Header, so this checks that even if
      // notetype = BO
      if (document.getNoteType().equals(NoteType.BUSINESS_OBJECT)
          && document.getDocumentHeader().getWorkflowDocument().isDisapproved()) {
        notes.addAll(
            getNoteService().getByRemoteObjectId(document.getDocumentHeader().getObjectId()));
      }

      document.setNotes(notes);
    }
  }
 @Override
 public void processAfterCopy(
     MaintenanceDocument document, Map<String, String[]> requestParameters) {
   Book book = ((Book) document.getNewMaintainableObject().getDataObject());
   book.setIsbn(null);
   super.processAfterCopy(document, requestParameters);
 }
Exemplo n.º 3
0
  protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
    boolean isValid = true;
    OleAgreementType oleAgreementType =
        (OleAgreementType) document.getNewMaintainableObject().getDataObject();

    isValid &= validateOleAgreementTypeName(oleAgreementType);
    return isValid;
  }
Exemplo n.º 4
0
  protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
    boolean isValid = true;
    OleLicenseRequestLocation oleLicenseRequestLocation =
        (OleLicenseRequestLocation) document.getNewMaintainableObject().getDataObject();

    isValid &= validateOleLicenseRequestLocation(oleLicenseRequestLocation);
    return isValid;
  }
Exemplo n.º 5
0
 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
   boolean isValid = true;
   OLEProblemType problemType =
       (OLEProblemType) document.getNewMaintainableObject().getDataObject();
   isValid &=
       validateProblemTypeName(problemType) && validateProblemTypeDefaultIndicator(problemType);
   return isValid;
 }
  @Override
  public List<Map<String, String>> resolveMultipleRoleQualifiers(
      @WebParam(name = "kewTypeId") String kewTypeId,
      @WebParam(name = "roleId") String roleId,
      @WebParam(name = "document") Document document,
      @WebParam(name = "documentContent") DocumentContent documentContent) {
    List<Map<String, String>> deptQualifiers = new ArrayList<Map<String, String>>();
    // try to get values from maintainable object if instance of position
    try {
      org.kuali.rice.krad.document.Document doc =
          KRADServiceLocatorWeb.getDocumentService()
              .getByDocumentHeaderId(document.getDocumentId());
      if (doc instanceof MaintenanceDocument) {
        MaintenanceDocument md = (MaintenanceDocument) doc;
        if (md.getNewMaintainableObject().getDataObject() instanceof PositionBo) {
          PositionBo position = (PositionBo) (md.getNewMaintainableObject().getDataObject());

          for (PositionDepartmentBo positionDepartment : position.getDepartmentList()) {
            if (!positionDepartment.getDeptAfflObj().isPrimaryIndicator()) {
              Map<String, String> qualifiers = new HashMap<String, String>();
              qualifiers.put(
                  KPMERoleMemberAttribute.DEPARTMENT.getRoleMemberAttributeName(),
                  String.valueOf(positionDepartment.getDepartment()));
              qualifiers.put(
                  KPMERoleMemberAttribute.GROUP_KEY_CODE.getRoleMemberAttributeName(),
                  String.valueOf(positionDepartment.getGroupKeyCode()));
              deptQualifiers.add(qualifiers);
            }
          }
        }
      }
    } catch (WorkflowException e) {
      LOG.error("Unable to retrieve document with documemnt ID: " + document.getDocumentId());
    }

    if (deptQualifiers.isEmpty()) {
      Map<String, String> qualifiers = new HashMap<String, String>();
      qualifiers.put(
          KPMERoleMemberAttribute.DEPARTMENT.getRoleMemberAttributeName(), StringUtils.EMPTY);
      qualifiers.put(
          KPMERoleMemberAttribute.GROUP_KEY_CODE.getRoleMemberAttributeName(), StringUtils.EMPTY);
      deptQualifiers.add(qualifiers);
    }
    return deptQualifiers;
  }
  @Override
  public void processAfterCopy(
      MaintenanceDocument document, Map<String, String[]> requestParameters) {
    ContextBo context = (ContextBo) document.getNewMaintainableObject().getDataObject();

    context.setId(contextIdIncrementer.getNewId());

    super.processAfterCopy(document, requestParameters);
  }
  /**
   * @see
   *     org.kuali.rice.krad.service.DocumentService#cancelDocument(org.kuali.rice.krad.document.Document,
   *     java.lang.String)
   */
  @Override
  public Document cancelDocument(Document document, String annotation) throws WorkflowException {
    checkForNulls(document);
    // if (!getDocumentActionFlags(document).getCanCancel()) {
    //    throw buildAuthorizationException("cancel", document);
    // }
    if (document instanceof MaintenanceDocument) {
      MaintenanceDocument maintDoc = ((MaintenanceDocument) document);
      if (maintDoc.getOldMaintainableObject() != null
          && (maintDoc.getOldMaintainableObject().getDataObject() instanceof BusinessObject)) {
        ((BusinessObject) maintDoc.getOldMaintainableObject().getDataObject()).refresh();
      }

      if (maintDoc.getNewMaintainableObject().getDataObject() instanceof BusinessObject) {
        ((BusinessObject) maintDoc.getNewMaintainableObject().getDataObject()).refresh();
      }
    }
    prepareWorkflowDocument(document);
    getWorkflowDocumentService()
        .cancel(document.getDocumentHeader().getWorkflowDocument(), annotation);
    UserSessionUtils.addWorkflowDocument(
        GlobalVariables.getUserSession(), document.getDocumentHeader().getWorkflowDocument());

    removeAdHocPersonsAndWorkgroups(document);
    return document;
  }
  @Override
  public Object retrieveObjectForEditOrCopy(
      MaintenanceDocument document, Map<String, String> dataObjectKeys) {

    ContextBo contextBo = (ContextBo) super.retrieveObjectForEditOrCopy(document, dataObjectKeys);

    if (KRADConstants.MAINTENANCE_COPY_ACTION.equals(getMaintenanceAction())) {
      document.getDocumentHeader().setDocumentDescription("New Context Document");

      contextBo = contextBo.copyContext(" Copy " + System.currentTimeMillis());
    }

    return contextBo;
  }
  protected static void populateCreateCourseOfferingForm(
      MaintenanceDocumentForm form, HttpServletRequest request) {
    int firstValue = 0;

    try {
      ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
      MaintenanceDocument document = form.getDocument();
      String termId = request.getParameter(CourseOfferingConstants.TARGET_TERM_ID);
      CourseInfo courseInfo =
          CourseOfferingManagementUtil.getCourseService()
              .getCourse(request.getParameter(CourseOfferingConstants.COURSE_ID), contextInfo);

      // 1. set CourseOfferingInfo - no saved Course Offering as of yet (see logic in
      // CourseOfferingEditMaintainableImpl.retrieveObjectForEditOrCopy
      CourseOfferingInfo coInfo =
          CourseOfferingManagementUtil.createCourseOfferingInfo(termId, courseInfo);
      // set the default value for hasWaitlist based on info defined in ks-enroll-config.xml through
      // CourseWaitListServiceFacade
      coInfo.setHasWaitlist(getCourseWaitListServiceFacade().getHasWaitlist());

      CourseOfferingEditWrapper formObject = new CourseOfferingEditWrapper(coInfo);
      formObject.setCreateCO(true);

      // 2. set CourseInfo
      formObject.setCourse(courseInfo);

      // 3. set formatOfferingList
      formObject.setFormatOfferingList(new ArrayList<FormatOfferingWrapper>());
      FormatOfferingWrapper defaultFO = new FormatOfferingWrapper();
      defaultFO.setFormatId(courseInfo.getFormats().get(firstValue).getId());
      defaultFO.getRenderHelper().setNewRow(true);
      defaultFO.setCourseOfferingWrapper(formObject);
      formObject.getFormatOfferingList().add(defaultFO);
      formObject.setFinalExamDriver(LuServiceConstants.LU_EXAM_DRIVER_AO_KEY);

      // 4. Checking if Grading Options should be disabled or not and assign default (if no value)
      // 5. Checking if there are any student registration options from CLU for screen display
      List<String> studentRegOptions = new ArrayList<String>();
      List<String> crsGradingOptions = new ArrayList<String>();
      if (courseInfo != null) {
        List<String> gradingOptions = courseInfo.getGradingOptions();
        Set<String> regOpts =
            new HashSet<String>(
                Arrays.asList(
                    CourseOfferingServiceConstants.ALL_STUDENT_REGISTRATION_OPTION_TYPE_KEYS));
        for (String gradingOption : gradingOptions) {
          if (regOpts.contains(gradingOption)) {
            studentRegOptions.add(gradingOption);
          } else {
            crsGradingOptions.add(gradingOption);
          }
        }
        // Audit is pulled out into a dynamic attribute on course so map it back
        if ("true"
            .equals(
                courseInfo.getAttributeValue(
                    CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_AUDIT))) {
          studentRegOptions.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT);
        }
      }

      formObject.setStudentRegOptions(studentRegOptions);
      formObject.setCrsGradingOptions(crsGradingOptions);

      // 6. Defining Credit Option and if CLU is fixed (then it's disabled)
      boolean creditOptionFixed = false;
      CreditOptionInfo creditOption = new CreditOptionInfo();

      // Grab the Course's credit constraints
      // FindBugs: getCreditOptions() null check is in CourseInfo
      List<ResultValuesGroupInfo> courseCreditOptions = courseInfo.getCreditOptions();

      // Lookup the related course's credit constraints and set them on the creditOption
      if (!courseCreditOptions.isEmpty()) {
        ResultValuesGroupInfo resultValuesGroupInfo = courseCreditOptions.get(firstValue);
        // Check for fixed
        if (resultValuesGroupInfo
            .getTypeKey()
            .equalsIgnoreCase(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED)) {
          if (!resultValuesGroupInfo.getResultValueKeys().isEmpty()) {
            creditOption.setCourseFixedCredits(
                CourseOfferingManagementUtil.getLrcService()
                    .getResultValue(
                        resultValuesGroupInfo.getResultValueKeys().get(firstValue), contextInfo)
                    .getValue());
          }
          // Set the flag
          creditOptionFixed = true;

          // Default the value
          creditOption.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED);
          creditOption.setFixedCredit(creditOption.getCourseFixedCredits());
          creditOption.getAllowedCredits().add(creditOption.getCourseFixedCredits());
        } else {
          // This is either range or multiple

          // Copy all the allowed credits and sort so that the multiple checkboxes can be properly
          // displayed
          List<ResultValueInfo> resultValueInfos =
              CourseOfferingManagementUtil.getLrcService()
                  .getResultValuesForResultValuesGroup(resultValuesGroupInfo.getKey(), contextInfo);
          for (ResultValueInfo rVI : resultValueInfos) {
            creditOption.getAllowedCredits().add(rVI.getValue());
          }
          Collections.sort(creditOption.getAllowedCredits());

          if (resultValuesGroupInfo
              .getTypeKey()
              .equalsIgnoreCase(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE)) {
            creditOption.setCourseMinCredits(
                resultValuesGroupInfo.getResultValueRange().getMinValue());
            creditOption.setCourseMaxCredits(
                resultValuesGroupInfo.getResultValueRange().getMaxValue());

            // Default the value
            creditOption.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE);
            creditOption.setMinCredits(creditOption.getCourseMinCredits());
            creditOption.setMaxCredits(creditOption.getCourseMaxCredits());
          } else if (resultValuesGroupInfo
              .getTypeKey()
              .equalsIgnoreCase(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE)) {
            // Default the value
            creditOption.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE);
            creditOption.getCredits().addAll(creditOption.getAllowedCredits());
          }
        }
      }

      formObject.setCreditOption(creditOption);
      formObject.setCreditOptionFixed(creditOptionFixed);

      formObject.setOrganizationNames(new ArrayList<OrganizationInfoWrapper>());

      ArrayList<OrganizationInfoWrapper> orgList = new ArrayList<OrganizationInfoWrapper>();

      if (courseInfo.getUnitsContentOwner() != null
          && !courseInfo.getUnitsContentOwner().isEmpty()) {
        for (String orgId : courseInfo.getUnitsContentOwner()) {
          OrgInfo orgInfo =
              CourseOfferingManagementUtil.getOrganizationService().getOrg(orgId, contextInfo);
          orgList.add(new OrganizationInfoWrapper(orgInfo));
        }
      }
      formObject.setOrganizationNames(orgList);

      // retrieve exam period id for the term that the CO is attached to
      try {
        String examPeriodId =
            CourseOfferingManagementUtil.getExamOfferingServiceFacade()
                .getExamPeriodId(
                    formObject.getCourseOfferingInfo().getTermId(),
                    ContextUtils.createDefaultContextInfo());
        if (!StringUtils.isEmpty(examPeriodId)) {
          formObject.setExamPeriodId(examPeriodId);
        }
      } catch (DoesNotExistException e) {
        LOG.warn(
            "The Term {} that the course offering {} is attached to doesn't have an exam period to create exam offerings.",
            formObject.getCourseOfferingInfo().getTermId(),
            formObject.getCourseOfferingCode());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }

      formObject.setUseFinalExamMatrixSystemDefault(
          CourseOfferingManagementUtil.getExamOfferingServiceFacade().isUseFinalExamMatrix());
      formObject.setUseFinalExamMatrix(
          CourseOfferingManagementUtil.getExamOfferingServiceFacade().isUseFinalExamMatrix());

      // adding SOC
      SocInfo socInfo =
          CourseOfferingManagementUtil.getCourseOfferingSetService()
              .getSoc(request.getParameter(CourseOfferingConstants.SOC_ID), contextInfo);
      formObject.setSocInfo(socInfo);

      setTermPropertiesOnFormObject(formObject, termId, contextInfo);
      formObject.setContextBar(
          CourseOfferingContextBar.NEW_INSTANCE(
              formObject.getTerm(),
              formObject.getSocInfo(),
              CourseOfferingManagementUtil.getStateService(),
              CourseOfferingManagementUtil.getAcademicCalendarService(),
              contextInfo));

      document.getNewMaintainableObject().setDataObject(formObject);
      document.getOldMaintainableObject().setDataObject(formObject);
      document.getDocumentHeader().setDocumentDescription("Create CO - " + courseInfo.getCode());

    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }