コード例 #1
0
  /**
   * gets the relationship that the attribute represents on the class
   *
   * @param c - the class to which the attribute belongs
   * @param attributeName - property name for the attribute
   * @return a relationship definition for the attribute
   */
  @Override
  public RelationshipDefinition getDictionaryRelationship(Class<?> c, String attributeName) {
    DataDictionaryEntry entryBase =
        KRADServiceLocatorWeb.getDataDictionaryService()
            .getDataDictionary()
            .getDictionaryObjectEntry(c.getName());
    if (entryBase == null) {
      return null;
    }

    RelationshipDefinition relationship = null;

    List<RelationshipDefinition> ddRelationships = entryBase.getRelationships();

    int minKeys = Integer.MAX_VALUE;
    for (RelationshipDefinition def : ddRelationships) {
      // favor key sizes of 1 first
      if (def.getPrimitiveAttributes().size() == 1) {
        for (PrimitiveAttributeDefinition primitive : def.getPrimitiveAttributes()) {
          if (primitive.getSourceName().equals(attributeName)
              || def.getObjectAttributeName().equals(attributeName)) {
            relationship = def;
            minKeys = 1;
            break;
          }
        }
      } else if (def.getPrimitiveAttributes().size() < minKeys) {
        for (PrimitiveAttributeDefinition primitive : def.getPrimitiveAttributes()) {
          if (primitive.getSourceName().equals(attributeName)
              || def.getObjectAttributeName().equals(attributeName)) {
            relationship = def;
            minKeys = def.getPrimitiveAttributes().size();
            break;
          }
        }
      }
    }

    // check the support attributes
    if (relationship == null) {
      for (RelationshipDefinition def : ddRelationships) {
        if (def.hasIdentifier()) {
          if (def.getIdentifier().getSourceName().equals(attributeName)) {
            relationship = def;
          }
        }
      }
    }

    return relationship;
  }
コード例 #2
0
  protected org.kuali.rice.krad.bo.DataObjectRelationship getRelationshipMetadata(
      Class<?> dataObjectClass, String attributeName, String attributePrefix) {

    RelationshipDefinition relationshipDefinition =
        getDictionaryRelationship(dataObjectClass, attributeName);
    if (relationshipDefinition == null) {
      return null;
    }

    org.kuali.rice.krad.bo.DataObjectRelationship dataObjectRelationship =
        new org.kuali.rice.krad.bo.DataObjectRelationship(
            relationshipDefinition.getSourceClass(),
            relationshipDefinition.getObjectAttributeName(),
            relationshipDefinition.getTargetClass());

    if (!StringUtils.isEmpty(attributePrefix)) {
      attributePrefix += ".";
    }

    List<PrimitiveAttributeDefinition> primitives = relationshipDefinition.getPrimitiveAttributes();
    for (PrimitiveAttributeDefinition primitiveAttributeDefinition : primitives) {
      dataObjectRelationship
          .getParentToChildReferences()
          .put(
              attributePrefix + primitiveAttributeDefinition.getSourceName(),
              primitiveAttributeDefinition.getTargetName());
    }

    return dataObjectRelationship;
  }
コード例 #3
0
 /**
  * @see
  *     org.kuali.rice.krad.service.DataDictionaryService#getRelationshipAttributeMap(java.lang.String,
  *     java.lang.String)
  */
 public Map<String, String> getRelationshipAttributeMap(
     String entryName, String relationshipName) {
   Map<String, String> attributeMap = new HashMap<String, String>();
   RelationshipDefinition relationshipDefinition =
       getRelationshipDefinition(entryName, relationshipName);
   for (Iterator iter = relationshipDefinition.getPrimitiveAttributes().iterator();
       iter.hasNext(); ) {
     PrimitiveAttributeDefinition attribute = (PrimitiveAttributeDefinition) iter.next();
     attributeMap.put(attribute.getTargetName(), attribute.getSourceName());
   }
   return attributeMap;
 }
コード例 #4
0
  public List<String> getRelationshipTargetAttributes(String entryName, String relationshipName) {
    List<String> targetAttributes = null;

    RelationshipDefinition rd = getRelationshipDefinition(entryName, relationshipName);
    if (rd != null) {
      targetAttributes = new ArrayList<String>();

      for (PrimitiveAttributeDefinition pad : rd.getPrimitiveAttributes()) {
        targetAttributes.add(pad.getTargetName());
      }
    }

    return targetAttributes;
  }
コード例 #5
0
  public List<String> getRelationshipEntriesForTargetAttribute(
      String entryName, String targetAttributeName) {
    List<String> relationships = new ArrayList<String>();

    DataDictionaryEntryBase entry =
        (DataDictionaryEntryBase) getDataDictionary().getDictionaryObjectEntry(entryName);

    for (RelationshipDefinition def : entry.getRelationships()) {
      for (PrimitiveAttributeDefinition pddef : def.getPrimitiveAttributes()) {
        if (StringUtils.equals(targetAttributeName, pddef.getTargetName())) {
          relationships.add(def.getObjectAttributeName());
          break;
        }
      }
    }
    return relationships;
  }
コード例 #6
0
  protected org.kuali.rice.krad.bo.DataObjectRelationship
      populateRelationshipFromDictionaryReference(
          Class<?> dataObjectClass,
          RelationshipDefinition ddReference,
          String attributePrefix,
          boolean keysOnly) {
    org.kuali.rice.krad.bo.DataObjectRelationship relationship =
        new org.kuali.rice.krad.bo.DataObjectRelationship(
            dataObjectClass, ddReference.getObjectAttributeName(), ddReference.getTargetClass());

    for (PrimitiveAttributeDefinition def : ddReference.getPrimitiveAttributes()) {
      if (StringUtils.isNotBlank(attributePrefix)) {
        relationship
            .getParentToChildReferences()
            .put(attributePrefix + "." + def.getSourceName(), def.getTargetName());
      } else {
        relationship.getParentToChildReferences().put(def.getSourceName(), def.getTargetName());
      }
    }

    if (!keysOnly) {
      for (SupportAttributeDefinition def : ddReference.getSupportAttributes()) {
        if (StringUtils.isNotBlank(attributePrefix)) {
          relationship
              .getParentToChildReferences()
              .put(attributePrefix + "." + def.getSourceName(), def.getTargetName());
          if (def.isIdentifier()) {
            relationship.setUserVisibleIdentifierKey(attributePrefix + "." + def.getSourceName());
          }
        } else {
          relationship.getParentToChildReferences().put(def.getSourceName(), def.getTargetName());
          if (def.isIdentifier()) {
            relationship.setUserVisibleIdentifierKey(def.getSourceName());
          }
        }
      }
    }

    return relationship;
  }