View Javadoc

1   package org.rice.krms.test;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.HashMap;
6   import java.util.List;
7   import java.util.Map;
8   
9   import org.kuali.rice.krad.bo.BusinessObject;
10  import org.kuali.rice.krad.bo.PersistableBusinessObject;
11  import org.kuali.rice.krad.service.BusinessObjectService;
12  import org.kuali.rice.krms.impl.repository.ContextBo;
13  import org.kuali.rice.krms.impl.repository.KrmsTypeBo;
14  import org.kuali.rice.krms.impl.repository.TermSpecificationBo;
15  import org.springframework.transaction.annotation.Transactional;
16  import org.springframework.util.CollectionUtils;
17  
18  public class TestBoService implements BusinessObjectService {
19  
20  	private Map<Class<?>, String> idFieldNamesMap = new HashMap<Class<?>, String>();
21  
22  	{
23  		idFieldNamesMap.put(KrmsTypeBo.class, "id");
24  		idFieldNamesMap.put(ContextBo.class, "id");
25  		idFieldNamesMap.put(TermSpecificationBo.class, "id");
26  	}
27  
28  	private final GenericTestDao dao;
29  
30  	public TestBoService(GenericTestDao genericDao) {
31  		this.dao = genericDao;
32  	}
33  
34  	public void addIdFieldNameMapping(Class<?> clazz, String fieldName) {
35  		idFieldNamesMap.put(clazz, fieldName);
36  	}
37  	
38  	/* (non-Javadoc)
39  	 * @see BusinessObjectService#save(PersistableBusinessObject)
40  	 */
41  	@Override
42  	public PersistableBusinessObject save(PersistableBusinessObject bo) {
43  		return dao.save(bo);
44  	}
45  
46  	/* (non-Javadoc)
47  	 * @see BusinessObjectService#save(java.util.List)
48  	 */
49  	@SuppressWarnings({ "unchecked", "rawtypes" })
50  	@Override
51  	public List<? extends PersistableBusinessObject> save(
52  			List<? extends PersistableBusinessObject> businessObjects) {
53  		List results = new ArrayList();
54  		if (!CollectionUtils.isEmpty(businessObjects)) {
55  			for (PersistableBusinessObject bo : businessObjects) {
56  				results.add(save(bo));
57  			}
58  		}
59  		return results;
60  	}
61  
62  
63  	/* (non-Javadoc)
64  	 * @see BusinessObjectService#linkAndSave(PersistableBusinessObject)
65  	 */
66  	@Override
67  	public PersistableBusinessObject linkAndSave(
68  			PersistableBusinessObject bo) {
69  		// TODO Auto-generated method stub
70  		throw new UnsupportedOperationException();
71  	}
72  
73  	/* (non-Javadoc)
74  	 * @see BusinessObjectService#linkAndSave(java.util.List)
75  	 */
76  	@Override
77  	public List<? extends PersistableBusinessObject> linkAndSave(
78  			List<? extends PersistableBusinessObject> businessObjects) {
79  		// TODO Auto-generated method stub
80  		throw new UnsupportedOperationException();
81  	}
82  
83  	/* (non-Javadoc)
84  	 * @see BusinessObjectService#findBySinglePrimaryKey(java.lang.Class, java.lang.Object)
85  	 */
86  	@Override
87  	public <T extends BusinessObject> T findBySinglePrimaryKey(
88  			Class<T> clazz, Object primaryKey) {
89  		String idFieldName = "id";
90  		if (idFieldNamesMap.containsKey(clazz)) idFieldName = idFieldNamesMap.get(clazz);
91  		return (T) dao.findById((String)primaryKey, idFieldName, clazz);
92  	}
93  
94  	/* (non-Javadoc)
95  	 * @see BusinessObjectService#findByPrimaryKey(java.lang.Class, java.util.Map)
96  	 */
97  	@Override
98  	public <T extends BusinessObject> T findByPrimaryKey(Class<T> clazz,
99  			Map<String, ?> primaryKeys) {
100 		Collection<T> results = dao.findMatching(clazz, primaryKeys);
101 		if (!CollectionUtils.isEmpty(results)) {
102 			if (results.size() > 1) throw new IllegalStateException("primary key fetch should only return one result!");
103 			return results.iterator().next();
104 		}
105 		return null;
106 	}
107 
108 	/* (non-Javadoc)
109 	 * @see BusinessObjectService#retrieve(PersistableBusinessObject)
110 	 */
111 	@Override
112 	public PersistableBusinessObject retrieve(
113 			PersistableBusinessObject object) {
114 		// TODO Auto-generated method stub
115 		throw new UnsupportedOperationException();
116 	}
117 
118 	/* (non-Javadoc)
119 	 * @see BusinessObjectService#findAll(java.lang.Class)
120 	 */
121 	@Override
122 	public <T extends BusinessObject> Collection<T> findAll(Class<T> clazz) {
123 		// TODO Auto-generated method stub
124 		throw new UnsupportedOperationException();
125 	}
126 
127 	/* (non-Javadoc)
128 	 * @see BusinessObjectService#findAllOrderBy(java.lang.Class, java.lang.String, boolean)
129 	 */
130 	@Override
131 	public <T extends BusinessObject> Collection<T> findAllOrderBy(
132 			Class<T> clazz, String sortField, boolean sortAscending) {
133 		// TODO Auto-generated method stub
134 		throw new UnsupportedOperationException();
135 	}
136 
137 	/* (non-Javadoc)
138 	 * @see BusinessObjectService#findMatching(java.lang.Class, java.util.Map)
139 	 */
140 	@Override
141 	public <T extends BusinessObject> Collection<T> findMatching(
142 			Class<T> clazz, Map<String, ?> fieldValues) {
143 		return dao.findMatching(clazz, fieldValues);
144 	}
145 
146 	/* (non-Javadoc)
147 	 * @see BusinessObjectService#countMatching(java.lang.Class, java.util.Map)
148 	 */
149 	@Override
150 	public int countMatching(Class clazz, Map<String, ?> fieldValues) {
151 		throw new UnsupportedOperationException();
152 	}
153 
154 	/* (non-Javadoc)
155 	 * @see BusinessObjectService#countMatching(java.lang.Class, java.util.Map, java.util.Map)
156 	 */
157 	@Override
158 	public int countMatching(Class clazz,
159 			Map<String, ?> positiveFieldValues,
160 			Map<String, ?> negativeFieldValues) {
161 		throw new UnsupportedOperationException();
162 	}
163 
164 	/* (non-Javadoc)
165 	 * @see BusinessObjectService#findMatchingOrderBy(java.lang.Class, java.util.Map, java.lang.String, boolean)
166 	 */
167 	@Override
168 	public <T extends BusinessObject> Collection<T> findMatchingOrderBy(
169 			Class<T> clazz, Map<String, ?> fieldValues, String sortField,
170 			boolean sortAscending) {
171 		throw new UnsupportedOperationException();
172 	}
173 
174 	/* (non-Javadoc)
175 	 * @see BusinessObjectService#delete(PersistableBusinessObject)
176 	 */
177 	@Override
178 	public void delete(PersistableBusinessObject bo) {
179 		throw new UnsupportedOperationException();			
180 	}
181 
182 	/* (non-Javadoc)
183 	 * @see BusinessObjectService#delete(java.util.List)
184 	 */
185 	@Override
186 	public void delete(List<? extends PersistableBusinessObject> boList) {
187 		throw new UnsupportedOperationException();			
188 	}
189 
190 	/* (non-Javadoc)
191 	 * @see BusinessObjectService#deleteMatching(java.lang.Class, java.util.Map)
192 	 */
193     @Override
194     @Transactional
195     public void deleteMatching(Class clazz, Map<String, ?> fieldValues) {
196         dao.deleteMatching(clazz, fieldValues);
197     }
198 
199 	/* (non-Javadoc)
200 	 * @see BusinessObjectService#getReferenceIfExists(BusinessObject, java.lang.String)
201 	 */
202 	@Override
203 	public BusinessObject getReferenceIfExists(BusinessObject bo,
204 			String referenceName) {
205 		throw new UnsupportedOperationException();
206 	}
207 
208 	/* (non-Javadoc)
209 	 * @see BusinessObjectService#linkUserFields(PersistableBusinessObject)
210 	 */
211 	@Override
212 	public void linkUserFields(PersistableBusinessObject bo) {
213 		throw new UnsupportedOperationException();
214 	}
215 
216 	/* (non-Javadoc)
217 	 * @see BusinessObjectService#linkUserFields(java.util.List)
218 	 */
219 	@Override
220 	public void linkUserFields(List<PersistableBusinessObject> bos) {
221 		throw new UnsupportedOperationException();		}
222 
223 	/* (non-Javadoc)
224 	 * @see BusinessObjectService#manageReadOnly(PersistableBusinessObject)
225 	 */
226 	@Override
227 	public PersistableBusinessObject manageReadOnly(
228 			PersistableBusinessObject bo) {
229 		throw new UnsupportedOperationException();
230 	}
231 
232 }