Ejemplo n.º 1
0
 protected CollectionGroup createCollectionInquirySection(String groupId, String headerText) {
   CollectionGroup group = ComponentFactory.getCollectionWithDisclosureGroupTableLayout();
   group.setId(groupId);
   group.setHeaderText(headerText);
   group.setItems(new ArrayList<Component>());
   ((TableLayoutManager) group.getLayoutManager()).setRenderSequenceField(false);
   return group;
 }
Ejemplo n.º 2
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);
    }
  }
Ejemplo n.º 3
0
 /** {@inheritDoc} */
 @Override
 public void performInitialization(Object model) {
   List<Component> items = new ArrayList<Component>();
   List<Object> modelCollection =
       ObjectPropertyUtils.getPropertyValue(model, tabCollectionPropertyName);
   int index = 0;
   for (Object tabObj : modelCollection) {
     String idSuffix;
     if (idSuffixPropertyName != null) {
       idSuffix = ObjectPropertyUtils.getPropertyValueAsText(tabObj, idSuffixPropertyName);
     } else {
       idSuffix = Integer.toString(index);
     }
     Group newGroup = ComponentUtils.copy(groupPrototype, "_" + idSuffix);
     if (expressionProperties != null && !expressionProperties.isEmpty()) {
       Map<String, Object> tabContext = new HashMap<String, Object>();
       for (Map.Entry<String, String> entry : expressionProperties.entrySet()) {
         tabContext.put(
             entry.getKey(), ObjectPropertyUtils.getPropertyValueAsText(tabObj, entry.getValue()));
       }
       ContextUtils.pushAllToContextDeep(newGroup, tabContext);
     }
     if (setFieldBindingObjectPath && newGroup instanceof CollectionGroup) {
       ((CollectionGroup) newGroup)
           .getBindingInfo()
           .setBindingObjectPath(tabCollectionPropertyName + "[" + index + "]");
     } else if (setFieldBindingObjectPath) {
       newGroup.setFieldBindingObjectPath(tabCollectionPropertyName + "[" + index + "]");
     }
     items.add(newGroup);
     index++;
   }
   setItems(items);
   super.performInitialization(model);
 }
  /** test {@link ComponentUtils#copyUsingCloning} using a CollectionGroup object */
  @Test
  public void testCopyUsingCloningWithSimpleCollectionGroupSucceeds() {
    CollectionGroup collectionGroupOriginal = initializeCollectionGroup();
    CollectionGroup collectionGroupCopy = copy(collectionGroupOriginal);

    assertTrue(ComponentCopyPropertiesMatch(collectionGroupOriginal, collectionGroupCopy));

    for (int i = 0; i < collectionGroupOriginal.getAddLineItems().size(); i++) {
      assertTrue(
          ComponentCopyPropertiesMatch(
              (ComponentBase) collectionGroupOriginal.getAddLineItems().get(i),
              (ComponentBase) collectionGroupCopy.getAddLineItems().get(i)));
    }

    for (int i = 0; i < collectionGroupOriginal.getAddLineActions().size(); i++) {
      assertTrue(
          ComponentCopyPropertiesMatch(
              collectionGroupOriginal.getAddLineActions().get(i),
              collectionGroupCopy.getAddLineActions().get(i)));
    }
  }
  @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addAlertLine")
  public ModelAndView addAlertLine(
      @ModelAttribute("KualiForm") DocumentFormBase formBase,
      BindingResult result,
      HttpServletRequest request,
      HttpServletResponse response) {
    String selectedCollectionPath =
        formBase.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
    if (StringUtils.isBlank(selectedCollectionPath)) {
      throw new RuntimeException(
          "Selected collection was not set for add line action, cannot add new line");
    }
    CollectionGroup collectionGroup =
        formBase.getPostedView().getViewIndex().getCollectionGroupByPath(selectedCollectionPath);
    String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
    Object addLine = ObjectPropertyUtils.getPropertyValue(formBase, addLinePath);
    ModelAndView modelAndView = super.addLine(formBase, result, request, response);
    List<String> principalIds = new ArrayList<String>();
    MaintenanceDocumentForm maintenanceDocumentForm =
        (MaintenanceDocumentForm) modelAndView.getModel().get("KualiForm");
    OlePersistableBusinessObjectBase olePersistableBusinessObjectBase =
        (OlePersistableBusinessObjectBase)
            maintenanceDocumentForm.getDocument().getNewMaintainableObject().getDataObject();
    AlertBo alertBo = olePersistableBusinessObjectBase.getAlertBoList().get(0);
    olePersistableBusinessObjectBase.getAlertBoList().remove(0);
    if (StringUtils.isBlank(alertBo.getReceivingGroupId())
        && StringUtils.isBlank(alertBo.getReceivingUserId())
        && StringUtils.isBlank(alertBo.getReceivingRoleId())
        && StringUtils.isBlank(alertBo.getReceivingGroupId())
        && StringUtils.isEmpty(alertBo.getReceivingUserName())
        && StringUtils.isEmpty(alertBo.getReceivingRoleName())
        && StringUtils.isEmpty(alertBo.getReceivingGroupName())) {
      GlobalVariables.getMessageMap()
          .putErrorForSectionId("OLE-AlertSection", OLEConstants.SELECT_USER);
      return modelAndView;
    }
    alertBo.setAlertCreateDate(new Date(System.currentTimeMillis()));
    alertBo.setAlertInitiatorId(GlobalVariables.getUserSession().getPrincipalId());
    alertBo.setAlertInitiatorName(
        alertService.getName(GlobalVariables.getUserSession().getPrincipalId()));

    String status = null;
    if (alertBo.getAlertDate() != null) {
      Date alertDate = alertBo.getAlertDate();
      if (alertDate.toString().equals(new Date(System.currentTimeMillis()).toString())) {
        status = "Active";
      } else {
        int dateCompare = alertBo.getAlertDate().compareTo(new Date(System.currentTimeMillis()));
        if (dateCompare > 0) {
          status = "Future";
        } else if (dateCompare < 0) {
          status = "Complete";
        }
      }
    }
    alertBo.setStatus(status);
    alertBo.setAlertStatus(true);
    List<AlertBo> alerts = new ArrayList<AlertBo>();
    if (StringUtils.isNotBlank(alertBo.getReceivingUserId())
        && (alertBo.getReceivingUserName() == null
            || (alertBo.getReceivingUserName() != null
                && alertBo.getReceivingUserName().trim().isEmpty()))) {
      alertBo.setReceivingUserName(alertService.getName(alertBo.getReceivingUserId()));
    }
    if (StringUtils.isBlank(alertBo.getReceivingUserId())
        && (alertBo.getReceivingUserName() != null
            && !alertBo.getReceivingUserName().trim().isEmpty())) {
      alertBo.setReceivingUserId(alertService.getPersonId(alertBo.getReceivingUserName()));
    }
    if (StringUtils.isNotBlank(alertBo.getReceivingUserId())) {
      principalIds.add(alertBo.getReceivingUserId());
    }
    alerts.addAll(alertService.getAlertBo(alertBo, principalIds, false, false));
    principalIds = new ArrayList<String>();

    if (StringUtils.isNotBlank(alertBo.getReceivingGroupId())
        && (alertBo.getReceivingGroupName() == null
            || (alertBo.getReceivingGroupName() != null
                && alertBo.getReceivingGroupName().trim().isEmpty()))) {
      alertBo.setReceivingGroupName(alertService.getGroupName(alertBo.getReceivingGroupId()));
    }
    if (StringUtils.isBlank(alertBo.getReceivingGroupId())
        && (alertBo.getReceivingGroupName() != null
            && !alertBo.getReceivingGroupName().trim().isEmpty())) {
      alertBo.setReceivingGroupId(alertService.getGroupId((alertBo.getReceivingUserName())));
    }

    if (StringUtils.isNotBlank(alertBo.getReceivingGroupId())) {
      List<String> memberIds = groupService.getMemberPrincipalIds(alertBo.getReceivingGroupId());
      principalIds.addAll(memberIds);
    }
    alerts.addAll(alertService.getAlertBo(alertBo, principalIds, false, true));

    principalIds = new ArrayList<String>();

    if (StringUtils.isNotBlank(alertBo.getReceivingRoleId())
        && (alertBo.getReceivingRoleName() == null
            || (alertBo.getReceivingRoleName() != null
                && alertBo.getReceivingRoleName().trim().isEmpty()))) {
      alertBo.setReceivingRoleName(alertService.getRoleName(alertBo.getReceivingRoleId()));
    }
    if (StringUtils.isBlank(alertBo.getReceivingRoleId())
        && (alertBo.getReceivingRoleName() != null
            && !alertBo.getReceivingRoleName().trim().isEmpty())) {
      alertBo.setReceivingRoleId(alertService.getRoleId((alertBo.getReceivingRoleName())));
    }

    if (StringUtils.isNotBlank(alertBo.getReceivingRoleId())) {
      List<String> roleIds = new ArrayList<String>();
      roleIds.add(alertBo.getReceivingRoleId());
      Role role = roleService.getRole(alertBo.getReceivingRoleId());
      Collection collection =
          (Collection)
              roleService.getRoleMemberPrincipalIds(
                  role.getNamespaceCode(), role.getName(), new HashMap<String, String>());
      List<String> memberIds = new ArrayList<String>();
      memberIds.addAll(collection);
      principalIds.addAll(memberIds);
    }

    alerts.addAll(alertService.getAlertBo(alertBo, principalIds, true, false));

    olePersistableBusinessObjectBase.getAlertBoList().addAll(alerts);
    if (StringUtils.isBlank(alertBo.getReceivingUserId())
        && StringUtils.isNotBlank(alertBo.getReceivingGroupId())) {
      olePersistableBusinessObjectBase.getAlertBoList().remove(0);
    }
    if (StringUtils.isNotBlank(alertBo.getReceivingUserId())
        && StringUtils.isNotBlank(alertBo.getReceivingGroupId())) {
      alertBo.setReceivingGroupName(null);
      alertBo.setReceivingGroupId(null);
    }

    return modelAndView;
  }