/**
   * Handles exporting the BusinessObject for this Inquiry to XML if it has a custom XML exporter
   * available.
   */
  @RequestMapping(params = "methodToCall=export")
  public ModelAndView export(
      @ModelAttribute("KualiForm") UifFormBase form,
      BindingResult result,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    InquiryForm inquiryForm = (InquiryForm) form;

    Object dataObject = inquiryForm.getDataObject();
    if (dataObject != null) {
      DataObjectEntry dataObjectEntry =
          KRADServiceLocatorWeb.getDataDictionaryService()
              .getDataDictionary()
              .getDataObjectEntry(inquiryForm.getDataObjectClassName());

      Class<? extends Exporter> exporterClass = dataObjectEntry.getExporterClass();
      if (exporterClass != null) {
        Exporter exporter = exporterClass.newInstance();

        response.setContentType(KRADConstants.XML_MIME_TYPE);
        response.setHeader("Content-disposition", "attachment; filename=export.xml");
        exporter.export(
            dataObjectEntry.getDataObjectClass(),
            Collections.singletonList(dataObject),
            KRADConstants.XML_FORMAT,
            response.getOutputStream());
      }
    }

    return null;
  }
 @SuppressWarnings("unchecked")
 @Override
 public List<String> listPrimaryKeyFieldNames(Class<?> type) {
   List<String> keys = new ArrayList<String>();
   if (type == null) {
     return keys;
   }
   if (isPersistable(type)) {
     keys = persistenceStructureService.listPrimaryKeyFieldNames(type);
   } else {
     ModuleService responsibleModuleService = kualiModuleService.getResponsibleModuleService(type);
     if (responsibleModuleService != null && responsibleModuleService.isExternalizable(type)) {
       keys = responsibleModuleService.listPrimaryKeyFieldNames(type);
     } else {
       // check the Data Dictionary for PK's of non PBO/EBO
       DataObjectEntry dataObjectEntry =
           dataDictionaryService.getDataDictionary().getDataObjectEntry(type.getName());
       if (dataObjectEntry != null) {
         List<String> pks = dataObjectEntry.getPrimaryKeys();
         if (pks != null) {
           keys = pks;
         }
       } else {
         LOG.warn(
             "Unable to retrieve data object entry for non-persistable KNS-managed class: "
                 + type.getName());
       }
     }
   }
   return keys;
 }
 /** @see org.kuali.rice.krad.service.LegacyDataAdapter */
 @Override
 public String getTitleAttribute(Class<?> dataObjectClass) {
   String titleAttribute = null;
   DataObjectEntry entry = getDataObjectEntry(dataObjectClass);
   if (entry != null) {
     titleAttribute = entry.getTitleAttribute();
   }
   return titleAttribute;
 }
  /**
   * @see
   *     org.kuali.rice.krad.service.DataDictionaryService#getGroupByAttributesForEffectiveDating(java.lang.Class)
   */
  public List<String> getGroupByAttributesForEffectiveDating(Class dataObjectClass) {
    List<String> groupByList = null;

    DataObjectEntry objectEntry = getDataDictionary().getDataObjectEntry(dataObjectClass.getName());
    if (objectEntry != null) {
      groupByList = objectEntry.getGroupByAttributesForEffectiveDating();
    }

    return groupByList;
  }
Ejemplo n.º 5
0
  @SuppressWarnings("unchecked")
  protected void addCollectionSectionsToInquiryView(
      InquiryView view, DataObjectEntry dataObjectEntry) {
    for (CollectionDefinition coll : dataObjectEntry.getCollections()) {
      // Create a new section
      DataObjectEntry collectionEntry =
          dataDictionaryService.getDataDictionary().getDataObjectEntry(coll.getDataObjectClass());
      // Extract the key fields on the collection which are linked to the parent.
      // When auto-generating the Inquiry Collection table, we want to exclude those.
      Collection<String> collectionFieldsLinkedToParent = new HashSet<String>();

      if (coll.getDataObjectCollection() != null) {
        for (DataObjectAttributeRelationship rel :
            coll.getDataObjectCollection().getAttributeRelationships()) {
          collectionFieldsLinkedToParent.add(rel.getChildAttributeName());
        }
      }

      if (collectionEntry == null) {
        LOG.warn(
            "Unable to find DataObjectEntry for collection class: " + coll.getDataObjectClass());
        continue;
      }

      CollectionGroup section = createCollectionInquirySection(coll.getName(), coll.getLabel());
      try {
        section.setCollectionObjectClass(Class.forName(coll.getDataObjectClass()));
      } catch (ClassNotFoundException e) {
        LOG.warn(
            "Unable to set class on collection section - class not found: "
                + coll.getDataObjectClass());
      }

      section.setPropertyName(coll.getName());
      // summary title : collection object label
      // Summary fields : PK fields?
      // add the attributes to the section
      for (AttributeDefinition attr : collectionEntry.getAttributes()) {
        boolean dontDisplay =
            hasHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.NO_INQUIRY);
        dontDisplay |= (attr.getControlField() instanceof HiddenControl);
        // Auto-exclude fields linked to the parent object
        dontDisplay |= collectionFieldsLinkedToParent.contains(attr.getName());

        if (dontDisplay) {
          continue;
        }

        DataField dataField = ComponentFactory.getDataField();
        dataField.setPropertyName(attr.getName());
        ((List<Component>) section.getItems()).add(dataField);
      }
      ((List<Group>) view.getItems()).add(section);
    }
  }
  /** @see org.kuali.rice.krad.service.LegacyDataAdapter#areNotesSupported(Class) */
  @Override
  public boolean areNotesSupported(Class<?> dataObjectClass) {
    boolean hasNotesSupport = false;

    DataObjectEntry entry = getDataObjectEntry(dataObjectClass);
    if (entry != null) {
      hasNotesSupport = entry.isBoNotesEnabled();
    }

    return hasNotesSupport;
  }
Ejemplo n.º 7
0
  @SuppressWarnings("unchecked")
  protected void addAttributeSectionsToInquiryView(
      InquiryView view, DataObjectEntry dataObjectEntry) {
    // Set up data structures to manage the creation of sections
    Map<String, Group> inquirySectionsById = new HashMap<String, Group>();
    Group currentGroup = createInquirySection("default", dataObjectEntry.getObjectLabel());
    inquirySectionsById.put(currentGroup.getId(), currentGroup);
    ((List<Group>) view.getItems()).add(currentGroup);

    // Loop over the attributes on the data object, adding them into the inquiry
    // If we have an @Section notation, switch to the section, creating if the ID is unknown
    List<Component> items =
        (List<Component>) currentGroup.getItems(); // needed to deal with generics issue
    for (AttributeDefinition attr : dataObjectEntry.getAttributes()) {
      boolean dontDisplay =
          hasHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.NO_INQUIRY);
      dontDisplay |= (attr.getControlField() instanceof HiddenControl);
      // Check for a section hint
      // Create or retrieve existing section as determined by the ID on the annotation
      UifDisplayHint sectionHint =
          getHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.SECTION);
      if (sectionHint != null) {
        if (StringUtils.isNotBlank(sectionHint.id())) {
          currentGroup = inquirySectionsById.get(sectionHint.id());
          if (currentGroup == null) {
            String sectionLabel = sectionHint.label();
            if (StringUtils.isBlank(sectionLabel)) {
              sectionLabel = deriveHumanFriendlyNameFromPropertyName(sectionHint.id());
            }

            currentGroup = createInquirySection(sectionHint.id(), sectionHint.label());
            inquirySectionsById.put(currentGroup.getId(), currentGroup);
            ((List<Group>) view.getItems()).add(currentGroup);
          }
        } else {
          LOG.warn("SECTION UifDisplayHint given without an ID - assuming 'default'");
          currentGroup = inquirySectionsById.get("default");
        }
        items = (List<Component>) currentGroup.getItems();
      }

      // This is checked after the section test, since the @Section annotation
      // would be on the FK field
      if (dontDisplay) {
        continue;
      }

      DataField dataField = ComponentFactory.getDataField();
      dataField.setPropertyName(attr.getName());
      dataField.setLabel(attr.getLabel());
      items.add(dataField);
    }
  }
Ejemplo n.º 8
0
  /**
   * @see
   *     org.kuali.rice.krad.uif.service.UifDefaultingService#deriveLookupViewFromMetadata(org.kuali.rice.krad.datadictionary.DataObjectEntry)
   */
  @Override
  public LookupView deriveLookupViewFromMetadata(DataObjectEntry dataObjectEntry) {
    LookupView view = ComponentFactory.getLookupView();
    view.setHeaderText(dataObjectEntry.getObjectLabel() + " Lookup");
    view.setDataObjectClass(dataObjectEntry.getDataObjectClass());
    view.setCriteriaFields(new ArrayList<Component>());
    view.setResultFields(new ArrayList<Component>());
    view.setDefaultSortAttributeNames(dataObjectEntry.getPrimaryKeys());

    addAttributesToLookupCriteria(view, dataObjectEntry);
    addAttributesToLookupResults(view, dataObjectEntry);

    return view;
  }
Ejemplo n.º 9
0
 protected void addAttributesToLookupResults(LookupView view, DataObjectEntry dataObjectEntry) {
   AttributeDefinition activeAttribute = null;
   for (AttributeDefinition attr : dataObjectEntry.getAttributes()) {
     // Check if we have been told not to display this attribute here
     boolean dontDisplay =
         hasHintOfType(attr.getDataObjectAttribute(), UifDisplayHintType.NO_LOOKUP_RESULT);
     dontDisplay |= (attr.getControlField() instanceof HiddenControl);
     if (dontDisplay) {
       continue;
     }
     if (attr.getName().equals(KRADPropertyConstants.ACTIVE)) {
       activeAttribute = attr;
       continue; // leave until the end of the lookup results
     }
     DataField field = ComponentFactory.getDataField();
     field.setPropertyName(attr.getName());
     view.getResultFields().add(field);
   }
   // If there was one, add the active attribute at the end
   if (activeAttribute != null) {
     DataField field = ComponentFactory.getDataField();
     field.setPropertyName(activeAttribute.getName());
     view.getResultFields().add(field);
   }
 }
Ejemplo n.º 10
0
  /**
   * @see
   *     org.kuali.rice.krad.uif.service.UifDefaultingService#deriveInquiryViewFromMetadata(org.kuali.rice.krad.datadictionary.DataObjectEntry)
   */
  @Override
  public InquiryView deriveInquiryViewFromMetadata(DataObjectEntry dataObjectEntry) {
    // Create the main view object and set the title and BO class
    InquiryView view = ComponentFactory.getInquiryView();
    view.setHeaderText(dataObjectEntry.getObjectLabel());
    view.setDataObjectClassName(dataObjectEntry.getDataObjectClass());

    addAttributeSectionsToInquiryView(view, dataObjectEntry);

    // TODO: if there are updatable reference objects, include sections for them

    // If there are collections on the object, include sections for them
    addCollectionSectionsToInquiryView(view, dataObjectEntry);

    return view;
  }