예제 #1
0
 public Boolean getAllowsNoteAttachments() {
   if (allowsNoteAttachments == null) {
     DocumentEntry entry =
         (DocumentEntry)
             getDataDictionaryService().getDataDictionary().getDocumentEntry(getClass().getName());
     allowsNoteAttachments = entry.getAllowsNoteAttachments();
   }
   return allowsNoteAttachments;
 }
  /**
   * @see
   *     org.kuali.rice.krad.service.DataDictionaryService#getDocumentClassByTypeName(java.lang.String)
   */
  public Class<? extends Document> getDocumentClassByTypeName(String documentTypeName) {
    Class clazz = null;

    DocumentEntry documentEntry = getDataDictionary().getDocumentEntry(documentTypeName);
    if (documentEntry != null) {
      clazz = documentEntry.getDocumentClass();
    }

    return clazz;
  }
  /**
   * Produces legacy KNS rows to use for search attributes. This method was left intact to help ease
   * conversion until KNS is replaced with KRAD.
   */
  protected List<Row> getSearchingRows(String documentTypeName) {

    List<Row> docSearchRows = new ArrayList<Row>();

    Class boClass = DocumentHeader.class;

    Field descriptionField = FieldUtils.getPropertyField(boClass, "documentDescription", true);
    descriptionField.setFieldDataType(
        KewApiConstants.SearchableAttributeConstants.DATA_TYPE_STRING);

    Field orgDocNumberField =
        FieldUtils.getPropertyField(boClass, "organizationDocumentNumber", true);
    orgDocNumberField.setFieldDataType(
        KewApiConstants.SearchableAttributeConstants.DATA_TYPE_STRING);

    List<Field> fieldList = new ArrayList<Field>();
    fieldList.add(descriptionField);
    docSearchRows.add(new Row(fieldList));

    fieldList = new ArrayList<Field>();
    fieldList.add(orgDocNumberField);
    docSearchRows.add(new Row(fieldList));

    DocumentEntry entry =
        KRADServiceLocatorWeb.getDataDictionaryService()
            .getDataDictionary()
            .getDocumentEntry(documentTypeName);
    if (entry == null) return docSearchRows;
    if (entry instanceof MaintenanceDocumentEntry) {
      Class<? extends BusinessObject> businessObjectClass =
          getBusinessObjectClass(documentTypeName);
      Class<? extends Maintainable> maintainableClass = getMaintainableClass(documentTypeName);

      KualiGlobalMaintainableImpl globalMaintainable = null;
      try {
        globalMaintainable = (KualiGlobalMaintainableImpl) maintainableClass.newInstance();
        businessObjectClass = globalMaintainable.getPrimaryEditedBusinessObjectClass();
      } catch (Exception ie) {
        // was not a globalMaintainable.
      }

      if (businessObjectClass != null)
        docSearchRows.addAll(createFieldRowsForBusinessObject(businessObjectClass));
    }

    WorkflowAttributes workflowAttributes = entry.getWorkflowAttributes();
    if (workflowAttributes != null)
      docSearchRows.addAll(createFieldRowsForWorkflowAttributes(workflowAttributes));

    return docSearchRows;
  }
  /**
   * @see
   *     org.kuali.rice.krad.service.DataDictionaryService#getDocumentTypeNameByClass(java.lang.Class)
   */
  public String getDocumentTypeNameByClass(Class documentClass) {
    if (documentClass == null) {
      throw new IllegalArgumentException("invalid (null) documentClass");
    }
    if (!Document.class.isAssignableFrom(documentClass)) {
      throw new IllegalArgumentException("invalid (non-Document) documentClass");
    }

    String documentTypeName = null;

    DocumentEntry documentEntry = getDataDictionary().getDocumentEntry(documentClass.getName());
    if (documentEntry != null) {
      documentTypeName = documentEntry.getDocumentTypeName();
    }

    return documentTypeName;
  }
  @Override
  public List<DocumentAttribute> extractDocumentAttributes(
      ExtensionDefinition extensionDefinition, DocumentWithContent documentWithContent) {
    List<DocumentAttribute> attributes = new ArrayList<DocumentAttribute>();

    String docId = documentWithContent.getDocument().getDocumentId();

    DocumentService docService = KRADServiceLocatorWeb.getDocumentService();
    Document doc = null;
    try {
      doc = docService.getByDocumentHeaderIdSessionless(docId);
    } catch (WorkflowException we) {
      LOG.error("Unable to retrieve document " + docId + " in getSearchStorageValues()", we);
    }

    String attributeValue = "";
    if (doc != null) {
      if (doc.getDocumentHeader() != null) {
        attributeValue = doc.getDocumentHeader().getDocumentDescription();
      } else {
        attributeValue = "null document header";
      }
    } else {
      attributeValue = "null document";
    }
    DocumentAttributeString attribute =
        DocumentAttributeFactory.createStringAttribute("documentDescription", attributeValue);
    attributes.add(attribute);

    attributeValue = "";
    if (doc != null) {
      if (doc.getDocumentHeader() != null) {
        attributeValue = doc.getDocumentHeader().getOrganizationDocumentNumber();
      } else {
        attributeValue = "null document header";
      }
    } else {
      attributeValue = "null document";
    }
    attribute =
        DocumentAttributeFactory.createStringAttribute(
            "organizationDocumentNumber", attributeValue);
    attributes.add(attribute);

    if (doc != null && doc instanceof MaintenanceDocument) {
      final Class<? extends BusinessObject> businessObjectClass =
          getBusinessObjectClass(documentWithContent.getDocument().getDocumentTypeName());
      if (businessObjectClass != null) {
        if (GlobalBusinessObject.class.isAssignableFrom(businessObjectClass)) {
          final GlobalBusinessObject globalBO =
              retrieveGlobalBusinessObject(docId, businessObjectClass);

          if (globalBO != null) {
            attributes.addAll(findAllDocumentAttributesForGlobalBusinessObject(globalBO));
          }
        } else {
          attributes.addAll(
              parsePrimaryKeyValuesFromDocument(businessObjectClass, (MaintenanceDocument) doc));
        }
      }
    }
    if (doc != null) {
      DocumentEntry docEntry =
          KRADServiceLocatorWeb.getDataDictionaryService()
              .getDataDictionary()
              .getDocumentEntry(documentWithContent.getDocument().getDocumentTypeName());
      if (docEntry != null) {
        WorkflowAttributes workflowAttributes = docEntry.getWorkflowAttributes();
        WorkflowAttributePropertyResolutionService waprs =
            KNSServiceLocator.getWorkflowAttributePropertyResolutionService();
        attributes.addAll(waprs.resolveSearchableAttributeValues(doc, workflowAttributes));
      } else {
        LOG.error(
            "Unable to find DD document entry for document type: "
                + documentWithContent.getDocument().getDocumentTypeName());
      }
    }
    return attributes;
  }