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.service; 017 018import org.kuali.rice.krad.bo.DataObjectRelationship; 019import org.kuali.rice.krad.datadictionary.RelationshipDefinition; 020 021import java.util.List; 022import java.util.Map; 023 024/** 025 * Provides metadata such as relationships and key fields for data objects 026 * 027 * <p> 028 * Service provides a facade to the various services for retrieving metadata 029 * within the framework, such as the <code>DataDictionaryService</code> and 030 * the <code>PersistenceService</code> 031 * </p> 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 */ 035public interface DataObjectMetaDataService { 036 037 /** 038 * Checks the DataDictionary and OJB Repository File to determine the primary 039 * fields names for a given class. 040 * 041 * @param clazz - the Class to check for primary keys 042 * @return a list of the primary key field names or an empty list if none are found 043 */ 044 public List<String> listPrimaryKeyFieldNames(Class<?> clazz); 045 046 /** 047 * Determines the primary keys for the class of the given object, then for each 048 * key field retrieves the value from the object instance and populates the return 049 * map with the primary key name as the map key and the object value as the map value 050 * 051 * @param dataObject - object whose primary key field name,value pairs you want 052 * @return a Map containing the names and values of fields for the given class which 053 * are designated as key fields in the OJB repository file or DataDictionary 054 * @throws IllegalArgumentException if the given Object is null 055 */ 056 public Map<String, ?> getPrimaryKeyFieldValues(Object dataObject); 057 058 /** 059 * Determines the primary keys for the class of the given object, then for each 060 * key field retrieves the value from the object instance and populates the return 061 * map with the primary key name as the map key and the object value as the map value 062 * 063 * @param dataObject - object whose primary key field name,value pairs you want 064 * @param sortFieldNames - if true, the returned Map will iterate through its entries sorted by fieldName 065 * @return a Map containing the names and values of fields for the given class which 066 * are designated as key fields in the OJB repository file or DataDictionary 067 * @throws IllegalArgumentException if the given Object is null 068 */ 069 public Map<String, ?> getPrimaryKeyFieldValues(Object dataObject, boolean sortFieldNames); 070 071 /** 072 * Compares two dataObject instances for equality of type and key values using toString() 073 * of each value for comparison purposes. 074 * 075 * @param do1 076 * @param do2 077 * @return boolean indicating whether the two objects are equal. 078 */ 079 public boolean equalsByPrimaryKeys(Object do1, Object do2); 080 081 /** 082 * Attempts to find a relationship for the given attribute within the given 083 * data object 084 * 085 * <p> 086 * First the data dictionary is queried to find any relationship definitions 087 * setup that include the attribute, if found the 088 * <code>BusinessObjectRetationship</code> is build from that. If not and 089 * the data object class is persistent, relationships are retrieved from the 090 * persistence service. Nested attributes are handled in addition to 091 * external business objects. If multiple relationships are found, the one 092 * that contains the least amount of joining keys is returned 093 * </p> 094 * 095 * @param dataObject - data object instance that contains the attribute 096 * @param dataObjectClass - class for the data object that contains the attribute 097 * @param attributeName - property name for the attribute 098 * @param attributePrefix - property prefix for the attribute 099 * @param keysOnly - indicates whether only primary key fields should be returned 100 * in the relationship 101 * @param supportsLookup - indicates whether the relationship should support lookup 102 * @param supportsInquiry - indicates whether the relationship should support inquiry 103 * @return BusinessObjectRelationship for the attribute, or null if not 104 * found 105 */ 106 public DataObjectRelationship getDataObjectRelationship(Object dataObject, Class<?> dataObjectClass, 107 String attributeName, String attributePrefix, boolean keysOnly, boolean supportsLookup, 108 boolean supportsInquiry); 109 110 /** 111 * Attempts to find relationships for the given data object class 112 * 113 * <p> 114 * First the data dictionary is queried to find any relationship definitions 115 * <code>BusinessObjectRetationship</code> is build from that. If not and 116 * the data object class is persistent, relationships are retrieved from the 117 * persistence service. Nested attributes are handled in addition to 118 * external business objects. If multiple relationships are found, the one 119 * that contains the least amount of joining keys is returned 120 * </p> 121 * 122 * @param dataObjectClass - class for the data object that contains the attribute 123 * @return List of DataObjectRelationship for the class 124 */ 125 public List<DataObjectRelationship> getDataObjectRelationships(Class<?> dataObjectClass); 126 127 /** 128 * Fetches the RelationshipDefinition for the attribute with the given name within 129 * the given class 130 * 131 * @param dataObjectClass - data object class that contains the attribute 132 * @param attributeName - property name for the attribute 133 * @return RelationshipDefinition for the attribute, or null if not found 134 */ 135 public RelationshipDefinition getDictionaryRelationship(Class<?> dataObjectClass, String attributeName); 136 137 /** 138 * Returns the attribute to be associated with for object level markings. This would 139 * be the field chosen for inquiry links etc. 140 * 141 * @param dataObjectClass - data object class to obtain title attribute of 142 * @return property name of title attribute or null if data object entry not found 143 * @throws IllegalArgumentException if the given Class is null 144 */ 145 public String getTitleAttribute(Class<?> dataObjectClass); 146 147 /** 148 * Indicates whether notes are supported by the given data object class, currently this 149 * can only be true for business objects 150 * 151 * @param dataObjectClass - class for data object to check 152 * @return boolean true if notes are supported for data object, false if notes are not supported 153 */ 154 public boolean areNotesSupported(Class<?> dataObjectClass); 155 156 /** 157 * Builds a string that uniquely identifiers the data object instance 158 * 159 * <p> 160 * Based on the metadata available for the class of the data object, the values for fields that uniquely 161 * identify an instance are concatenated together into one string. For general data objects these fields 162 * will be the primary key fields defined in the data dictionary. For the case of objects with type 163 * <code>PersistableBusinessObject</code>, the object id field will be used. 164 * </p> 165 * 166 * @param dataObject - data object instance to build identifier string for 167 * @return String identifier string for data object 168 */ 169 public String getDataObjectIdentifierString(Object dataObject); 170}