1 /*
2 * Copyright 2006-2013 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.kuali.rice.krad.data;
18
19 import java.util.List;
20 import java.util.Map;
21
22 import org.kuali.rice.krad.data.metadata.DataObjectMetadata;
23 import org.springframework.beans.BeanWrapper;
24 import org.springframework.beans.BeansException;
25
26 /**
27 * Wraps a data object and it's associated metadata. Provides additional utility methods to access portions of the data
28 * object based on the metadata that's available.
29 *
30 * <p>This interface extends the {@link BeanWrapper} interface provided by Spring which means property references can
31 * be nested and may be auto-grown depending on the setting of {@link #isAutoGrowNestedPaths()}</p>
32 *
33 * @param <T> the type of the data object instance which is wrapped by this accessor
34 */
35 public interface DataObjectWrapper<T> extends BeanWrapper {
36
37 /**
38 * Return the type of the wrapped data object.
39 *
40 * @return the type of the wrapped data instance, or <code>null</code> if no wrapped object has been set
41 */
42 @Override
43 Class<T> getWrappedClass();
44
45 /**
46 * Returns the data object wrapped by this accessor.
47 *
48 * @return the data object wrapped by this accessor
49 */
50 @Override
51 T getWrappedInstance();
52
53 /**
54 * Returns the metadata of the data object wrapped by this accessor.
55 *
56 * @return the metadata of the data object wrapped by this accessor
57 */
58 DataObjectMetadata getMetadata();
59
60 /**
61 * Get the current value of the specified property, but suppresses any
62 * {@link org.springframework.beans.NullValueInNestedPathException}s that would be thrown if a null value is
63 * encountered in a nested path and just returns null instead. This method is essentially a convenience method to
64 * prevent calling code from having to wrap calls to {@link #getPropertyValue(String)} with a try-catch block to
65 * check for NullValueInNestedPathExceptions.
66 *
67 * @param propertyName the name of the property to get the value of
68 * (may be a nested path and/or an indexed/mapped property)
69 * @return the value of the property, or null if any null values were encountered in nested paths
70 * @throws org.springframework.beans.InvalidPropertyException if there is no such property or
71 * if the property isn't readable
72 * @throws org.springframework.beans.PropertyAccessException if the property was valid but the
73 * accessor method failed
74 */
75 Object getPropertyValueNullSafe(String propertyName) throws BeansException;
76
77 /**
78 * Returns a map containing the values of the primary keys on this data object. The key of this map will be the
79 * attribute name of the primary key field on the data object and the value will the value of that primary key
80 * attribute on the data object wrapped by this accessor. If this data object has no primary key fields, an empty
81 * map will be returned.
82 *
83 * @return a map of primary key values where the key is the attribute name of the primary key field and the value
84 * is the value of that primary key field on the wrapped data object
85 */
86 Map<String, Object> getPrimaryKeyValues();
87
88 /**
89 * Determines if the given data object is equal to the data object wrapped by this accessor based on primary key
90 * values only. If the given object is null, then this method will always return false.
91 *
92 * @param object the object to compare to the data object wrapped by this accessor
93 * @return true if the primary key values are equal, false otherwise
94 */
95 boolean equalsByPrimaryKey(T object);
96
97 /**
98 * Returns whether all fields in the primary key are populated with a non-null/non-blank value.
99 */
100 boolean areAllPrimaryKeyAttributesPopulated();
101
102 /**
103 * Returns whether any fields in the primary key is populated with a non-null/non-blank value.
104 */
105 boolean areAnyPrimaryKeyAttributesPopulated();
106
107 /**
108 * Returns the list of field of the primary key which have a null or blank value.
109 */
110 List<String> getUnpopulatedPrimaryKeyAttributeNames();
111 }