001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.datadictionary;
017
018import org.kuali.rice.krad.datadictionary.exception.AttributeValidationException;
019import org.kuali.rice.krad.util.ExternalizableBusinessObjectUtils;
020
021/**
022    Support attributes define additional attributes that can be used to generate
023    lookup field conversions and lookup parameters.
024
025    Field conversions and lookup parameters are normally generated using foreign key relationships
026    defined within OJB and the DD.  Because Person objects are linked in a special way (i.e. they may
027    come from an external data source and not from the DB, such as LDAP), it is often necessary to define
028    extra fields that are related to each other, sort of like a supplemental foreign key.
029
030    sourceName is the name of the POJO property of the business object
031    targetName is the name of attribute that corresponds to the sourceName in the looked up BO
032    identifier when true, only the field marked as an identifier will be passed in as a lookup parameter
033               at most one supportAttribute for each relationship should be defined as identifier="true"
034 */
035public class SupportAttributeDefinition extends PrimitiveAttributeDefinition {
036    private static final long serialVersionUID = -1719022365280776405L;
037    
038        protected boolean identifier;
039    
040    public SupportAttributeDefinition() {}
041
042    public boolean isIdentifier() {
043        return identifier;
044    }
045    
046    /**
047     * identifier when true, only the field marked as an identifier will be passed in as a lookup parameter
048               at most one supportAttribute for each relationship should be defined as identifier="true"
049     */
050    public void setIdentifier(boolean identifier) {
051        this.identifier = identifier;
052    }
053
054    /**
055     * Directly validate simple fields.
056     * 
057     * @see org.kuali.rice.krad.datadictionary.DataDictionaryDefinition#completeValidation(java.lang.Class, java.lang.Object)
058     */
059    public void completeValidation(Class rootBusinessObjectClass, Class otherBusinessObjectClass) {
060        if (!DataDictionary.isPropertyOf(rootBusinessObjectClass, getSourceName())) {
061            throw new AttributeValidationException("unable to find attribute '" + getSourceName() + "' in relationship class '" + rootBusinessObjectClass + "' (" + "" + ")");
062        }
063        if (!DataDictionary.isPropertyOf(otherBusinessObjectClass, getTargetName())
064                        && !ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface( otherBusinessObjectClass )) {
065            throw new AttributeValidationException("unable to find attribute '" + getTargetName() + "' in related class '" + otherBusinessObjectClass.getName() + "' (" + "" + ")");
066        }
067    }
068    
069    /**
070     * @see java.lang.Object#toString()
071     */
072    @Override
073    public String toString() {
074        return "SupportAttributeDefinition (" + getSourceName()+","+getTargetName()+","+identifier+")";
075    }
076    
077}
078