@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); } }
/** * Sets relationships. * * <p>Looks at merge actions and whether the relationship is empty when adding, so not all * relationships are added. * * @param relationships list of data object relationships or null */ public void setRelationships(List<DataObjectRelationship> relationships) { if (relationships == null) { this.relationships = null; relationshipMap = null; lastAttributeToRelationshipMap = null; attributeToRelationshipMap = null; return; } this.relationships = Collections.unmodifiableList(relationships); relationshipMap = new HashMap<String, DataObjectRelationship>(relationships.size()); attributeToRelationshipMap = new HashMap<String, List<DataObjectRelationship>>(); lastAttributeToRelationshipMap = new HashMap<String, DataObjectRelationship>(relationships.size()); removedRelationshipNames = new ArrayList<String>(); // Builds maps to link attribute names to their relationships for (DataObjectRelationship rel : relationships) { // This is not quite correct - we really only want to not add the NO_OVERRIDE items if they // are // overriding something. However, at the point this is running, we don't know whether we will // be embedding // anything... if (rel.getMergeAction() != MetadataMergeAction.REMOVE && rel.getMergeAction() != MetadataMergeAction.NO_OVERRIDE) { // related object attribute name relationshipMap.put(rel.getName(), rel); // last attribute in list linking the objects if (!rel.getAttributeRelationships().isEmpty()) { DataObjectAttributeRelationship relAttr = rel.getAttributeRelationships().get(rel.getAttributeRelationships().size() - 1); lastAttributeToRelationshipMap.put(relAttr.getParentAttributeName(), rel); } // all relationships relating to an attribute for (DataObjectAttributeRelationship relAttr : rel.getAttributeRelationships()) { List<DataObjectRelationship> rels = attributeToRelationshipMap.get(relAttr.getParentAttributeName()); if (rels == null) { rels = new ArrayList<DataObjectRelationship>(); attributeToRelationshipMap.put(relAttr.getParentAttributeName(), rels); } rels.add(rel); } } // since the attribute will still exist in the embedded metadata, we need to put a block in on // the standard // cascade if (rel.getMergeAction() == MetadataMergeAction.REMOVE) { removedRelationshipNames.add(rel.getName()); } } relationshipMap = Collections.unmodifiableMap(relationshipMap); lastAttributeToRelationshipMap = Collections.unmodifiableMap(lastAttributeToRelationshipMap); attributeToRelationshipMap = Collections.unmodifiableMap(attributeToRelationshipMap); }