1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
package org.kuali.student.core.organization.service.impl; |
10 | |
|
11 | |
import java.util.ArrayList; |
12 | |
import java.util.HashMap; |
13 | |
import java.util.HashSet; |
14 | |
import java.util.List; |
15 | |
import java.util.Map; |
16 | |
import java.util.Set; |
17 | |
|
18 | |
import javax.jws.WebService; |
19 | |
import javax.persistence.NoResultException; |
20 | |
|
21 | |
import org.apache.log4j.Logger; |
22 | |
import org.kuali.student.common.dictionary.old.dto.ObjectStructure; |
23 | |
import org.kuali.student.common.dictionary.service.old.DictionaryService; |
24 | |
import org.kuali.student.common.dto.StatusInfo; |
25 | |
import org.kuali.student.common.exceptions.AlreadyExistsException; |
26 | |
import org.kuali.student.common.exceptions.DataValidationErrorException; |
27 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
28 | |
import org.kuali.student.common.exceptions.InvalidParameterException; |
29 | |
import org.kuali.student.common.exceptions.MissingParameterException; |
30 | |
import org.kuali.student.common.exceptions.OperationFailedException; |
31 | |
import org.kuali.student.common.exceptions.PermissionDeniedException; |
32 | |
import org.kuali.student.common.exceptions.VersionMismatchException; |
33 | |
import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo; |
34 | |
import org.kuali.student.common.search.dto.SearchRequest; |
35 | |
import org.kuali.student.common.search.dto.SearchResult; |
36 | |
import org.kuali.student.common.search.dto.SearchResultTypeInfo; |
37 | |
import org.kuali.student.common.search.dto.SearchTypeInfo; |
38 | |
import org.kuali.student.common.search.service.SearchManager; |
39 | |
import org.kuali.student.common.validation.dto.ValidationResultInfo; |
40 | |
import org.kuali.student.common.validator.old.Validator; |
41 | |
import org.kuali.student.core.organization.dao.OrganizationDao; |
42 | |
import org.kuali.student.core.organization.dto.OrgHierarchyInfo; |
43 | |
import org.kuali.student.core.organization.dto.OrgInfo; |
44 | |
import org.kuali.student.core.organization.dto.OrgOrgRelationInfo; |
45 | |
import org.kuali.student.core.organization.dto.OrgOrgRelationTypeInfo; |
46 | |
import org.kuali.student.core.organization.dto.OrgPersonRelationInfo; |
47 | |
import org.kuali.student.core.organization.dto.OrgPersonRelationTypeInfo; |
48 | |
import org.kuali.student.core.organization.dto.OrgPositionRestrictionInfo; |
49 | |
import org.kuali.student.core.organization.dto.OrgTreeInfo; |
50 | |
import org.kuali.student.core.organization.dto.OrgTypeInfo; |
51 | |
import org.kuali.student.core.organization.entity.Org; |
52 | |
import org.kuali.student.core.organization.entity.OrgHierarchy; |
53 | |
import org.kuali.student.core.organization.entity.OrgOrgRelation; |
54 | |
import org.kuali.student.core.organization.entity.OrgOrgRelationType; |
55 | |
import org.kuali.student.core.organization.entity.OrgPersonRelation; |
56 | |
import org.kuali.student.core.organization.entity.OrgPersonRelationType; |
57 | |
import org.kuali.student.core.organization.entity.OrgPositionRestriction; |
58 | |
import org.kuali.student.core.organization.entity.OrgType; |
59 | |
import org.kuali.student.core.organization.service.OrganizationService; |
60 | |
import org.kuali.student.core.organizationsearch.service.impl.OrganizationSearch; |
61 | |
import org.springframework.transaction.annotation.Transactional; |
62 | |
|
63 | |
@WebService(endpointInterface = "org.kuali.student.core.organization.service.OrganizationService", serviceName = "OrganizationService", portName = "OrganizationService", targetNamespace = "http://student.kuali.org/wsdl/organization") |
64 | |
@Transactional(readOnly = true, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class}) |
65 | 2 | public class OrganizationServiceImpl implements OrganizationService { |
66 | |
|
67 | 2 | final Logger logger = Logger.getLogger(OrganizationServiceImpl.class); |
68 | |
|
69 | |
private OrganizationDao organizationDao; |
70 | |
private DictionaryService dictionaryServiceDelegate; |
71 | |
private SearchManager searchManager; |
72 | |
private Validator validator; |
73 | |
|
74 | |
private Map<String, OrganizationSearch> searchOperations; |
75 | |
|
76 | |
public void setSearchOperations(Map<String, OrganizationSearch> searchOperations) { |
77 | 0 | this.searchOperations = searchOperations; |
78 | 0 | } |
79 | |
|
80 | |
@Override |
81 | |
@Transactional(readOnly = false) |
82 | |
public OrgPositionRestrictionInfo addPositionRestrictionToOrg(String orgId, String orgPersonRelationTypeKey, OrgPositionRestrictionInfo orgPositionRestrictionInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
83 | |
|
84 | |
|
85 | 2 | checkForMissingParameter(orgId, "orgId"); |
86 | 2 | checkForMissingParameter(orgPersonRelationTypeKey, "orgPersonRelationTypeKey"); |
87 | 2 | checkForMissingParameter(orgPositionRestrictionInfo, "orgPositionRestrictionInfo"); |
88 | |
|
89 | |
|
90 | 2 | orgPositionRestrictionInfo.setOrgId(orgId); |
91 | 2 | orgPositionRestrictionInfo.setOrgPersonRelationTypeKey(orgPersonRelationTypeKey); |
92 | |
|
93 | 2 | OrgPositionRestriction orgPositionRestriction = null; |
94 | |
|
95 | |
|
96 | |
try { |
97 | 2 | orgPositionRestriction = OrganizationAssembler.toOrgPositionRestriction(false, orgPositionRestrictionInfo, organizationDao); |
98 | 2 | } catch (VersionMismatchException e) {} |
99 | |
|
100 | |
|
101 | 2 | organizationDao.create(orgPositionRestriction); |
102 | |
|
103 | |
|
104 | 2 | OrgPositionRestrictionInfo createdOrgPositionRestrictionInfo = OrganizationAssembler.toOrgPositionRestrictionInfo(orgPositionRestriction); |
105 | 2 | return createdOrgPositionRestrictionInfo; |
106 | |
} |
107 | |
|
108 | |
@Override |
109 | |
@Transactional(readOnly = false) |
110 | |
public OrgOrgRelationInfo createOrgOrgRelation(String orgId, String relatedOrgId, String orgOrgRelationTypeKey, OrgOrgRelationInfo orgOrgRelationInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException { |
111 | |
|
112 | |
|
113 | 1 | checkForMissingParameter(orgId, "orgId"); |
114 | 1 | checkForMissingParameter(relatedOrgId, "relatedOrgId"); |
115 | 1 | checkForMissingParameter(orgOrgRelationTypeKey, "orgOrgRelationTypeKey"); |
116 | 1 | checkForMissingParameter(orgOrgRelationInfo, "orgOrgRelationInfo"); |
117 | |
|
118 | |
|
119 | 1 | orgOrgRelationInfo.setOrgId(orgId); |
120 | 1 | orgOrgRelationInfo.setRelatedOrgId(relatedOrgId); |
121 | 1 | orgOrgRelationInfo.setType(orgOrgRelationTypeKey); |
122 | |
|
123 | 1 | OrgOrgRelation orgOrgRelation = null; |
124 | |
|
125 | |
|
126 | |
try { |
127 | 1 | orgOrgRelation = OrganizationAssembler.toOrgOrgRelation(false, orgOrgRelationInfo, organizationDao); |
128 | 1 | } catch (VersionMismatchException e) {} |
129 | |
|
130 | |
|
131 | 1 | organizationDao.create(orgOrgRelation); |
132 | |
|
133 | |
|
134 | 1 | OrgOrgRelationInfo createdOrgOrgRelationInfo = OrganizationAssembler.toOrgOrgRelationInfo(orgOrgRelation); |
135 | 1 | return createdOrgOrgRelationInfo; |
136 | |
} |
137 | |
|
138 | |
@Override |
139 | |
@Transactional(readOnly = false) |
140 | |
public OrgPersonRelationInfo createOrgPersonRelation(String orgId, String personId, String orgPersonRelationTypeKey, OrgPersonRelationInfo orgPersonRelationInfo) throws AlreadyExistsException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException { |
141 | |
|
142 | |
|
143 | 1 | checkForMissingParameter(orgId, "orgId"); |
144 | 1 | checkForMissingParameter(personId, "personId"); |
145 | 1 | checkForMissingParameter(orgPersonRelationTypeKey, "orgPersonRelationTypeKey"); |
146 | 1 | checkForMissingParameter(orgPersonRelationTypeKey, "orgPersonRelationTypeKey"); |
147 | |
|
148 | |
|
149 | 1 | if (!organizationDao.validatePositionRestriction(orgId, orgPersonRelationTypeKey)) { |
150 | 0 | throw new InvalidParameterException("There is no Position for this relationship"); |
151 | |
} |
152 | |
|
153 | |
|
154 | 1 | orgPersonRelationInfo.setOrgId(orgId); |
155 | 1 | orgPersonRelationInfo.setPersonId(personId); |
156 | 1 | orgPersonRelationInfo.setType(orgPersonRelationTypeKey); |
157 | |
|
158 | 1 | OrgPersonRelation orgPersonRelation = null; |
159 | |
|
160 | |
|
161 | |
try { |
162 | 1 | orgPersonRelation = OrganizationAssembler.toOrgPersonRelation(false, orgPersonRelationInfo, organizationDao); |
163 | 1 | } catch (VersionMismatchException e) {} |
164 | |
|
165 | |
|
166 | 1 | organizationDao.create(orgPersonRelation); |
167 | |
|
168 | |
|
169 | 1 | OrgPersonRelationInfo createdOrgPersonRelationInfo = OrganizationAssembler.toOrgPersonRelationInfo(orgPersonRelation); |
170 | 1 | return createdOrgPersonRelationInfo; |
171 | |
} |
172 | |
|
173 | |
@Override |
174 | |
@Transactional(readOnly = false) |
175 | |
public OrgInfo createOrganization(String orgTypeKey, OrgInfo orgInfo) throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
176 | |
|
177 | |
|
178 | 1 | checkForMissingParameter(orgTypeKey, "orgTypeKey"); |
179 | 1 | checkForMissingParameter(orgInfo, "orgInfo"); |
180 | |
|
181 | |
|
182 | 1 | orgInfo.setType(orgTypeKey); |
183 | |
|
184 | |
try { |
185 | 1 | List<ValidationResultInfo> validations = validateOrg("", orgInfo); |
186 | 1 | for (ValidationResultInfo validationResult : validations) { |
187 | 0 | if (validationResult.isError()) |
188 | 0 | throw new DataValidationErrorException(validationResult.toString()); |
189 | |
} |
190 | 0 | } catch (DoesNotExistException e1) { |
191 | 0 | logger.error("Exception occured: ", e1); |
192 | 1 | } |
193 | |
|
194 | 1 | Org org = null; |
195 | |
|
196 | |
|
197 | |
try { |
198 | 1 | org = OrganizationAssembler.toOrg(false, orgInfo, organizationDao); |
199 | 0 | } catch (DoesNotExistException e) { |
200 | |
|
201 | 0 | logger.info(e.getMessage(), e); |
202 | 0 | throw new OperationFailedException(e.getMessage(), e); |
203 | 0 | } catch (VersionMismatchException e) { |
204 | |
|
205 | 0 | logger.info(e.getMessage(), e); |
206 | 0 | throw new OperationFailedException(e.getMessage(), e); |
207 | 1 | } |
208 | |
|
209 | |
|
210 | 1 | organizationDao.create(org); |
211 | |
|
212 | |
|
213 | 1 | OrgInfo createdOrgInfo = OrganizationAssembler.toOrgInfo(org); |
214 | 1 | return createdOrgInfo; |
215 | |
|
216 | |
} |
217 | |
|
218 | |
@Override |
219 | |
@Transactional(readOnly = false) |
220 | |
public StatusInfo deleteOrganization(String orgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
221 | |
|
222 | 1 | checkForMissingParameter(orgId, "orgId"); |
223 | |
|
224 | 1 | Org org = organizationDao.fetch(Org.class, orgId); |
225 | |
|
226 | 1 | if (org == null) { |
227 | 0 | throw new DoesNotExistException("Org does not exist for id: " + orgId); |
228 | |
} |
229 | |
|
230 | 1 | organizationDao.delete(org); |
231 | |
|
232 | 1 | StatusInfo statusInfo = new StatusInfo(); |
233 | 1 | statusInfo.setSuccess(true); |
234 | 1 | return statusInfo; |
235 | |
} |
236 | |
|
237 | |
@Override |
238 | |
public List<String> getAllDescendants(String orgId, String orgHierarchy) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
239 | |
|
240 | 4 | checkForMissingParameter(orgId, "orgId"); |
241 | 4 | checkForMissingParameter(orgId, "orgHierarchy"); |
242 | |
|
243 | 4 | List<String> descendants = this.organizationDao.getAllDescendants(orgId, orgHierarchy); |
244 | 4 | return descendants; |
245 | |
} |
246 | |
|
247 | |
@Override |
248 | |
public List<OrgPersonRelationInfo> getAllOrgPersonRelationsByOrg(String orgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
249 | 2 | checkForMissingParameter(orgId, "orgId"); |
250 | |
|
251 | 2 | return OrganizationAssembler.toOrgPersonRelationInfos(organizationDao.getAllOrgPersonRelationsByOrg(orgId)); |
252 | |
} |
253 | |
|
254 | |
@Override |
255 | |
public List<OrgPersonRelationInfo> getAllOrgPersonRelationsByPerson(String personId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
256 | 2 | checkForMissingParameter(personId, "personId"); |
257 | |
|
258 | 2 | List<OrgPersonRelation> orgPersonRelationInfo = organizationDao.getAllOrgPersonRelationsByPerson(personId); |
259 | 2 | return OrganizationAssembler.toOrgPersonRelationInfos(orgPersonRelationInfo); |
260 | |
} |
261 | |
|
262 | |
@Override |
263 | |
public List<String> getAllAncestors(String orgId, String orgHierarchy) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
264 | 4 | checkForMissingParameter(orgId, "orgId"); |
265 | 4 | checkForMissingParameter(orgHierarchy, "orgHierarchy"); |
266 | |
|
267 | 4 | List<String> ancestors = this.organizationDao.getAllAncestors(orgId, orgHierarchy); |
268 | 4 | return ancestors; |
269 | |
} |
270 | |
|
271 | |
@Override |
272 | |
public List<OrgHierarchyInfo> getOrgHierarchies() throws OperationFailedException { |
273 | 1 | return OrganizationAssembler.toOrgHierarchyInfos(organizationDao.find(OrgHierarchy.class)); |
274 | |
|
275 | |
} |
276 | |
|
277 | |
@Override |
278 | |
public OrgHierarchyInfo getOrgHierarchy(String orgHierarchyKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
279 | 2 | checkForMissingParameter(orgHierarchyKey, "orgHierarchyKey"); |
280 | |
|
281 | 2 | return OrganizationAssembler.toOrgHierarchyInfo(organizationDao.fetch(OrgHierarchy.class, orgHierarchyKey)); |
282 | |
} |
283 | |
|
284 | |
@Override |
285 | |
public OrgOrgRelationInfo getOrgOrgRelation(String orgOrgRelationId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
286 | 3 | checkForMissingParameter(orgOrgRelationId, "orgOrgRelationId"); |
287 | |
|
288 | 2 | return OrganizationAssembler.toOrgOrgRelationInfo(organizationDao.fetch(OrgOrgRelation.class, orgOrgRelationId)); |
289 | |
|
290 | |
} |
291 | |
|
292 | |
@Override |
293 | |
public OrgOrgRelationTypeInfo getOrgOrgRelationType(String orgOrgRelationTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
294 | 2 | checkForMissingParameter(orgOrgRelationTypeKey, "orgOrgRelationTypeKey"); |
295 | |
|
296 | 2 | return OrganizationAssembler.toOrgOrgRelationTypeInfo(organizationDao.fetch(OrgOrgRelationType.class, orgOrgRelationTypeKey)); |
297 | |
} |
298 | |
|
299 | |
@Override |
300 | |
public List<OrgOrgRelationTypeInfo> getOrgOrgRelationTypes() throws OperationFailedException { |
301 | 1 | List<OrgOrgRelationType> orgOrgRelationTypes = organizationDao.find(OrgOrgRelationType.class); |
302 | 1 | return OrganizationAssembler.toOrgOrgRelationTypeInfos(orgOrgRelationTypes); |
303 | |
} |
304 | |
|
305 | |
@Override |
306 | |
public List<OrgOrgRelationTypeInfo> getOrgOrgRelationTypesForOrgHierarchy(String orgHierarchyKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
307 | 2 | checkForMissingParameter(orgHierarchyKey, "orgHierarchyKey"); |
308 | |
|
309 | 2 | List<OrgOrgRelationType> orgOrgRelationTypes = organizationDao.getOrgOrgRelationTypesForOrgHierarchy(orgHierarchyKey); |
310 | 2 | return OrganizationAssembler.toOrgOrgRelationTypeInfos(orgOrgRelationTypes); |
311 | |
} |
312 | |
|
313 | |
@Override |
314 | |
public List<OrgOrgRelationTypeInfo> getOrgOrgRelationTypesForOrgType(String orgTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
315 | 2 | checkForMissingParameter(orgTypeKey, "orgTypeKey"); |
316 | |
|
317 | 2 | List<OrgOrgRelationType> orgOrgRelationTypes = organizationDao.getOrgOrgRelationTypesForOrgType(orgTypeKey); |
318 | 2 | return OrganizationAssembler.toOrgOrgRelationTypeInfos(orgOrgRelationTypes); |
319 | |
} |
320 | |
|
321 | |
@Override |
322 | |
public List<OrgOrgRelationInfo> getOrgOrgRelationsByIdList(List<String> orgOrgRelationIdList) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
323 | 3 | checkForMissingParameter(orgOrgRelationIdList, "orgOrgRelationIdList"); |
324 | |
|
325 | 3 | List<OrgOrgRelation> orgOrgRelations = organizationDao.getOrgOrgRelationsByIdList(orgOrgRelationIdList); |
326 | 3 | return OrganizationAssembler.toOrgOrgRelationInfos(orgOrgRelations); |
327 | |
} |
328 | |
|
329 | |
@Override |
330 | |
public List<OrgOrgRelationInfo> getOrgOrgRelationsByOrg(String orgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
331 | |
|
332 | 2 | checkForMissingParameter(orgId, "orgId"); |
333 | |
|
334 | 2 | List<OrgOrgRelation> orgOrgRelations = organizationDao.getOrgOrgRelationsByOrg(orgId); |
335 | 2 | return OrganizationAssembler.toOrgOrgRelationInfos(orgOrgRelations); |
336 | |
} |
337 | |
|
338 | |
@Override |
339 | |
public List<OrgOrgRelationInfo> getOrgOrgRelationsByRelatedOrg(String relatedOrgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
340 | 2 | checkForMissingParameter(relatedOrgId, "relatedOrgId"); |
341 | |
|
342 | 2 | List<OrgOrgRelation> orgOrgRelations = organizationDao.getOrgOrgRelationsByRelatedOrg(relatedOrgId); |
343 | 2 | return OrganizationAssembler.toOrgOrgRelationInfos(orgOrgRelations); |
344 | |
} |
345 | |
|
346 | |
@Override |
347 | |
public OrgPersonRelationInfo getOrgPersonRelation(String orgPersonRelationId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
348 | 0 | checkForMissingParameter(orgPersonRelationId, "orgPersonRelationId"); |
349 | |
|
350 | 0 | OrgPersonRelation opr = organizationDao.fetch(OrgPersonRelation.class, orgPersonRelationId); |
351 | 0 | return OrganizationAssembler.toOrgPersonRelationInfo(opr); |
352 | |
} |
353 | |
|
354 | |
@Override |
355 | |
public OrgPersonRelationTypeInfo getOrgPersonRelationType(String orgPersonRelationTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
356 | 0 | checkForMissingParameter(orgPersonRelationTypeKey, "orgPersonRelationTypeKey"); |
357 | |
|
358 | 0 | OrgPersonRelationType oprt = organizationDao.fetch(OrgPersonRelationType.class, orgPersonRelationTypeKey); |
359 | 0 | return OrganizationAssembler.toOrgPersonRelationTypeInfo(oprt); |
360 | |
} |
361 | |
|
362 | |
@Override |
363 | |
public List<OrgPersonRelationTypeInfo> getOrgPersonRelationTypes() throws OperationFailedException { |
364 | 0 | List<OrgPersonRelationType> oprts = organizationDao.find(OrgPersonRelationType.class); |
365 | 0 | return OrganizationAssembler.toOrgPersonRelationTypeInfos(oprts); |
366 | |
} |
367 | |
|
368 | |
@Override |
369 | |
public List<OrgPersonRelationTypeInfo> getOrgPersonRelationTypesForOrgType(String orgTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
370 | 2 | checkForMissingParameter(orgTypeKey, "orgTypeKey"); |
371 | |
|
372 | 2 | List<OrgPersonRelationType> oprts = organizationDao.getOrgPersonRelationTypesForOrgType(orgTypeKey); |
373 | 2 | return OrganizationAssembler.toOrgPersonRelationTypeInfos(oprts); |
374 | |
} |
375 | |
|
376 | |
@Override |
377 | |
public List<OrgPersonRelationInfo> getOrgPersonRelationsByIdList(List<String> orgPersonRelationIdList) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
378 | 3 | checkForMissingParameter(orgPersonRelationIdList, "orgPersonRelationIdList"); |
379 | |
|
380 | 3 | List<OrgPersonRelation> oprts = organizationDao.getOrgPersonRelationsByIdList(orgPersonRelationIdList); |
381 | 3 | return OrganizationAssembler.toOrgPersonRelationInfos(oprts); |
382 | |
} |
383 | |
|
384 | |
@Override |
385 | |
public List<OrgPersonRelationInfo> getOrgPersonRelationsByOrg(String orgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
386 | 0 | checkForMissingParameter(orgId, "orgId"); |
387 | |
|
388 | 0 | List<OrgPersonRelation> relations = organizationDao.getAllOrgPersonRelationsByOrg(orgId); |
389 | 0 | return OrganizationAssembler.toOrgPersonRelationInfos(relations); |
390 | |
} |
391 | |
|
392 | |
@Override |
393 | |
public List<OrgPersonRelationInfo> getOrgPersonRelationsByPerson(String personId, String orgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
394 | 4 | checkForMissingParameter(personId, "personId"); |
395 | 4 | checkForMissingParameter(orgId, "orgId"); |
396 | |
|
397 | 4 | List<OrgPersonRelation> oprts = organizationDao.getOrgPersonRelationsByPerson(personId, orgId); |
398 | 4 | return OrganizationAssembler.toOrgPersonRelationInfos(oprts); |
399 | |
} |
400 | |
|
401 | |
@Override |
402 | |
public OrgTypeInfo getOrgType(String orgTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
403 | 2 | checkForMissingParameter(orgTypeKey, "orgTypeKey"); |
404 | |
|
405 | 2 | return OrganizationAssembler.toOrgTypeInfo(organizationDao.fetch(OrgType.class, orgTypeKey)); |
406 | |
} |
407 | |
|
408 | |
@Override |
409 | |
public List<OrgTypeInfo> getOrgTypes() throws OperationFailedException { |
410 | 1 | return OrganizationAssembler.toOrgTypeInfos(organizationDao.find(OrgType.class)); |
411 | |
} |
412 | |
|
413 | |
@Override |
414 | |
public OrgInfo getOrganization(String orgId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
415 | 4 | checkForMissingParameter(orgId, "orgId"); |
416 | |
|
417 | 4 | return OrganizationAssembler.toOrgInfo(organizationDao.fetch(Org.class, orgId)); |
418 | |
} |
419 | |
|
420 | |
@Override |
421 | |
public List<OrgInfo> getOrganizationsByIdList(List<String> orgIdList) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
422 | 0 | checkForMissingParameter(orgIdList, "orgIdList"); |
423 | |
|
424 | 0 | List<Org> orgs = this.organizationDao.getOrganizationsByIdList(orgIdList); |
425 | 0 | return OrganizationAssembler.toOrgInfos(orgs); |
426 | |
} |
427 | |
|
428 | |
@Override |
429 | |
public List<String> getPersonIdsForOrgByRelationType(String orgId, String orgPersonRelationTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
430 | 2 | checkForMissingParameter(orgId, "orgId"); |
431 | 2 | checkForMissingParameter(orgPersonRelationTypeKey, "orgPersonRelationTypeKey"); |
432 | |
|
433 | 2 | return organizationDao.getPersonIdsForOrgByRelationType(orgId, orgPersonRelationTypeKey); |
434 | |
} |
435 | |
|
436 | |
@Override |
437 | |
public List<OrgPositionRestrictionInfo> getPositionRestrictionsByOrg(String orgId) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException { |
438 | 2 | checkForMissingParameter(orgId, "orgId"); |
439 | |
|
440 | 2 | List<OrgPositionRestriction> restrictions = organizationDao.getPositionRestrictionsByOrg(orgId); |
441 | 2 | return OrganizationAssembler.toOrgPositionRestrictionInfos(restrictions); |
442 | |
} |
443 | |
|
444 | |
@Override |
445 | |
public Boolean hasOrgOrgRelation(String orgId, String comparisonOrgId, String orgOrgRelationTypeKey) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
446 | |
|
447 | 2 | checkForMissingParameter(orgId, "orgId"); |
448 | 2 | checkForMissingParameter(comparisonOrgId, "comparisonOrgId"); |
449 | 2 | checkForMissingParameter(orgOrgRelationTypeKey, "orgOrgRelationTypeKey"); |
450 | |
|
451 | 2 | boolean result = organizationDao.hasOrgOrgRelation(orgId, comparisonOrgId, orgOrgRelationTypeKey); |
452 | 2 | return Boolean.valueOf(result); |
453 | |
} |
454 | |
|
455 | |
@Override |
456 | |
public Boolean hasOrgPersonRelation(String orgId, String personId, String orgPersonRelationTypeKey) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
457 | 7 | checkForMissingParameter(orgId, "orgId"); |
458 | 6 | checkForMissingParameter(personId, "personId"); |
459 | 5 | checkForMissingParameter(orgPersonRelationTypeKey, "orgPersonRelationTypeKey"); |
460 | |
|
461 | 4 | return organizationDao.hasOrgPersonRelation(orgId, personId, orgPersonRelationTypeKey); |
462 | |
} |
463 | |
|
464 | |
@Override |
465 | |
public Boolean isDescendant(String orgId, String descendantOrgId, String orgHierarchy) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
466 | 3 | checkForMissingParameter(orgId, "orgId"); |
467 | 3 | checkForMissingParameter(descendantOrgId, "descendantOrgId"); |
468 | 3 | checkForMissingParameter(orgHierarchy, "orgHierarchy"); |
469 | |
|
470 | |
|
471 | 3 | List<String> ancestors = organizationDao.getAllAncestors(descendantOrgId, orgHierarchy); |
472 | 3 | boolean result = ancestors.contains(orgId); |
473 | 3 | return Boolean.valueOf(result); |
474 | |
} |
475 | |
|
476 | |
@Override |
477 | |
@Transactional(readOnly = false) |
478 | |
public StatusInfo removeOrgOrgRelation(String orgOrgRelationId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
479 | 3 | checkForMissingParameter(orgOrgRelationId, "orgOrgRelationId"); |
480 | |
|
481 | 2 | organizationDao.delete(OrgOrgRelation.class, orgOrgRelationId); |
482 | 1 | return new StatusInfo(); |
483 | |
} |
484 | |
|
485 | |
@Override |
486 | |
@Transactional(readOnly = false) |
487 | |
public StatusInfo removeOrgPersonRelation(String orgPersonRelationId) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
488 | 5 | checkForMissingParameter(orgPersonRelationId, "orgPersonRelationId"); |
489 | |
|
490 | 3 | organizationDao.delete(OrgPersonRelation.class, orgPersonRelationId); |
491 | 1 | return new StatusInfo(); |
492 | |
} |
493 | |
|
494 | |
@Override |
495 | |
@Transactional(readOnly = false) |
496 | |
public StatusInfo removePositionRestrictionFromOrg(String orgId, String orgPersonRelationTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
497 | |
|
498 | 5 | checkForMissingParameter(orgId, "orgId"); |
499 | 4 | checkForMissingParameter(orgPersonRelationTypeKey, "orgPersonRelationTypeKey"); |
500 | 3 | OrgPositionRestriction opr = null; |
501 | |
try { |
502 | 3 | opr = organizationDao.getPositionRestrictionByOrgAndPersonRelationTypeKey(orgId, orgPersonRelationTypeKey); |
503 | 1 | if (opr == null) { |
504 | 0 | throw new DoesNotExistException(); |
505 | |
} |
506 | 2 | } catch (NoResultException e) { |
507 | 2 | throw new DoesNotExistException(); |
508 | 1 | } |
509 | 1 | organizationDao.delete(opr); |
510 | 1 | return new StatusInfo(); |
511 | |
} |
512 | |
|
513 | |
@Override |
514 | |
@Transactional(readOnly = false) |
515 | |
public OrgOrgRelationInfo updateOrgOrgRelation(String orgOrgRelationId, OrgOrgRelationInfo orgOrgRelationInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
516 | |
|
517 | 0 | checkForMissingParameter(orgOrgRelationId, "orgOrgRelationId"); |
518 | 0 | checkForMissingParameter(orgOrgRelationId, "orgOrgRelationId"); |
519 | |
|
520 | |
|
521 | 0 | orgOrgRelationInfo.setId(orgOrgRelationId); |
522 | |
|
523 | 0 | OrgOrgRelation orgOrgRelation = null; |
524 | |
|
525 | |
|
526 | 0 | orgOrgRelation = OrganizationAssembler.toOrgOrgRelation(true, orgOrgRelationInfo, organizationDao); |
527 | |
|
528 | |
|
529 | 0 | OrgOrgRelation updatedOrgOrgRelation = organizationDao.update(orgOrgRelation); |
530 | |
|
531 | |
|
532 | 0 | OrgOrgRelationInfo updatedOrgOrgRelationInfo = OrganizationAssembler.toOrgOrgRelationInfo(updatedOrgOrgRelation); |
533 | 0 | return updatedOrgOrgRelationInfo; |
534 | |
|
535 | |
} |
536 | |
|
537 | |
@Override |
538 | |
@Transactional(readOnly = false) |
539 | |
public OrgPersonRelationInfo updateOrgPersonRelation(String orgPersonRelationId, OrgPersonRelationInfo orgPersonRelationInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
540 | |
|
541 | 0 | checkForMissingParameter(orgPersonRelationId, "orgPersonRelationId"); |
542 | 0 | checkForMissingParameter(orgPersonRelationInfo, "orgPersonRelationInfo"); |
543 | |
|
544 | |
|
545 | 0 | if (!organizationDao.validatePositionRestriction(orgPersonRelationInfo.getOrgId(), orgPersonRelationInfo.getType())) { |
546 | 0 | throw new InvalidParameterException("There is no Position for this relationship"); |
547 | |
} |
548 | |
|
549 | |
|
550 | 0 | orgPersonRelationInfo.setId(orgPersonRelationId); |
551 | |
|
552 | 0 | OrgPersonRelation orgPersonRelation = null; |
553 | |
|
554 | |
|
555 | 0 | orgPersonRelation = OrganizationAssembler.toOrgPersonRelation(true, orgPersonRelationInfo, organizationDao); |
556 | |
|
557 | |
|
558 | 0 | orgPersonRelation = organizationDao.update(orgPersonRelation); |
559 | |
|
560 | |
|
561 | 0 | OrgPersonRelationInfo createdOrgPersonRelationInfo = OrganizationAssembler.toOrgPersonRelationInfo(orgPersonRelation); |
562 | 0 | return createdOrgPersonRelationInfo; |
563 | |
} |
564 | |
|
565 | |
@Override |
566 | |
@Transactional(readOnly = false) |
567 | |
public OrgInfo updateOrganization(String orgId, OrgInfo orgInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
568 | |
|
569 | |
|
570 | 2 | checkForMissingParameter(orgId, "orgId"); |
571 | 2 | checkForMissingParameter(orgInfo, "orgInfo"); |
572 | |
|
573 | |
|
574 | 2 | orgInfo.setId(orgId); |
575 | |
|
576 | 2 | Org org = null; |
577 | |
|
578 | |
|
579 | 2 | org = OrganizationAssembler.toOrg(true, orgInfo, organizationDao); |
580 | |
|
581 | |
|
582 | 1 | Org updatedOrg = organizationDao.update(org); |
583 | |
|
584 | |
|
585 | 1 | OrgInfo updatedOrgInfo = OrganizationAssembler.toOrgInfo(updatedOrg); |
586 | 1 | return updatedOrgInfo; |
587 | |
|
588 | |
} |
589 | |
|
590 | |
@Override |
591 | |
@Transactional(readOnly = false) |
592 | |
public OrgPositionRestrictionInfo updatePositionRestrictionForOrg(String orgId, String orgPersonRelationTypeKey, OrgPositionRestrictionInfo orgPositionRestrictionInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
593 | |
|
594 | |
|
595 | 0 | checkForMissingParameter(orgId, "orgId"); |
596 | 0 | checkForMissingParameter(orgPersonRelationTypeKey, "orgPersonRelationTypeKey"); |
597 | 0 | checkForMissingParameter(orgPositionRestrictionInfo, "orgPositionRestrictionInfo"); |
598 | |
|
599 | |
|
600 | 0 | orgPositionRestrictionInfo.setOrgId(orgId); |
601 | 0 | orgPositionRestrictionInfo.setOrgPersonRelationTypeKey(orgPersonRelationTypeKey); |
602 | |
|
603 | 0 | OrgPositionRestriction orgPositionRestriction = null; |
604 | |
|
605 | |
|
606 | 0 | orgPositionRestriction = OrganizationAssembler.toOrgPositionRestriction(true, orgPositionRestrictionInfo, organizationDao); |
607 | |
|
608 | |
|
609 | 0 | OrgPositionRestriction updated = organizationDao.update(orgPositionRestriction); |
610 | |
|
611 | |
|
612 | 0 | OrgPositionRestrictionInfo updatedOrgPositionRestrictionInfo = OrganizationAssembler.toOrgPositionRestrictionInfo(updated); |
613 | 0 | return updatedOrgPositionRestrictionInfo; |
614 | |
} |
615 | |
|
616 | |
@Override |
617 | |
public List<ValidationResultInfo> validateOrg(String validationType, OrgInfo orgInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
618 | |
|
619 | 1 | checkForMissingParameter(validationType, "validationType"); |
620 | 1 | checkForMissingParameter(orgInfo, "orgInfo"); |
621 | |
|
622 | |
|
623 | |
|
624 | |
|
625 | 1 | return new ArrayList<ValidationResultInfo>(0); |
626 | |
} |
627 | |
|
628 | |
@Override |
629 | |
public List<ValidationResultInfo> validateOrgOrgRelation(String validationType, OrgOrgRelationInfo orgOrgRelationInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
630 | 0 | checkForMissingParameter(validationType, "validationType"); |
631 | 0 | checkForMissingParameter(orgOrgRelationInfo, "orgOrgRelationInfo"); |
632 | |
|
633 | 0 | List<ValidationResultInfo> valResults = validator.validateTypeStateObject(orgOrgRelationInfo, getObjectStructure("orgOrgRelationInfo")); |
634 | 0 | return valResults; |
635 | |
} |
636 | |
|
637 | |
@Override |
638 | |
public List<ValidationResultInfo> validateOrgPersonRelation(String validationType, OrgPersonRelationInfo orgPersonRelationInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
639 | 0 | checkForMissingParameter(validationType, "validationType"); |
640 | |
|
641 | 0 | List<ValidationResultInfo> valResults = validator.validateTypeStateObject(orgPersonRelationInfo, getObjectStructure("orgPersonRelationInfo")); |
642 | 0 | return valResults; |
643 | |
|
644 | |
} |
645 | |
|
646 | |
@Override |
647 | |
public List<ValidationResultInfo> validateOrgPositionRestriction(String validationType, OrgPositionRestrictionInfo orgPositionRestrictionInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
648 | 0 | checkForMissingParameter(validationType, "validationType"); |
649 | 0 | checkForMissingParameter(orgPositionRestrictionInfo, "orgPositionRestrictionInfo"); |
650 | |
|
651 | 0 | return null; |
652 | |
} |
653 | |
|
654 | |
@Override |
655 | |
public SearchCriteriaTypeInfo getSearchCriteriaType(String searchCriteriaTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
656 | |
|
657 | 0 | return searchManager.getSearchCriteriaType(searchCriteriaTypeKey); |
658 | |
} |
659 | |
|
660 | |
@Override |
661 | |
public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes() throws OperationFailedException { |
662 | 0 | return searchManager.getSearchCriteriaTypes(); |
663 | |
} |
664 | |
|
665 | |
@Override |
666 | |
public SearchResultTypeInfo getSearchResultType(String searchResultTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
667 | 0 | checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey"); |
668 | 0 | return searchManager.getSearchResultType(searchResultTypeKey); |
669 | |
} |
670 | |
|
671 | |
@Override |
672 | |
public List<SearchResultTypeInfo> getSearchResultTypes() throws OperationFailedException { |
673 | 0 | return searchManager.getSearchResultTypes(); |
674 | |
} |
675 | |
|
676 | |
@Override |
677 | |
public SearchTypeInfo getSearchType(String searchTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
678 | 0 | checkForMissingParameter(searchTypeKey, "searchTypeKey"); |
679 | 0 | return searchManager.getSearchType(searchTypeKey); |
680 | |
} |
681 | |
|
682 | |
@Override |
683 | |
public List<SearchTypeInfo> getSearchTypes() throws OperationFailedException { |
684 | 0 | return searchManager.getSearchTypes(); |
685 | |
} |
686 | |
|
687 | |
@Override |
688 | |
public List<SearchTypeInfo> getSearchTypesByCriteria(String searchCriteriaTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
689 | 0 | checkForMissingParameter(searchCriteriaTypeKey, "searchCriteriaTypeKey"); |
690 | 0 | return searchManager.getSearchTypesByCriteria(searchCriteriaTypeKey); |
691 | |
} |
692 | |
|
693 | |
@Override |
694 | |
public List<SearchTypeInfo> getSearchTypesByResult(String searchResultTypeKey) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
695 | 0 | checkForMissingParameter(searchResultTypeKey, "searchResultTypeKey"); |
696 | 0 | return searchManager.getSearchTypesByResult(searchResultTypeKey); |
697 | |
} |
698 | |
|
699 | |
public OrganizationDao getOrganizationDao() { |
700 | 0 | return organizationDao; |
701 | |
} |
702 | |
|
703 | |
public void setOrganizationDao(OrganizationDao organizationDao) { |
704 | 1 | this.organizationDao = organizationDao; |
705 | 1 | } |
706 | |
|
707 | |
@Override |
708 | |
public ObjectStructure getObjectStructure(String objectTypeKey) { |
709 | 0 | return dictionaryServiceDelegate.getObjectStructure(objectTypeKey); |
710 | |
} |
711 | |
|
712 | |
@Override |
713 | |
public List<String> getObjectTypes() { |
714 | 0 | return dictionaryServiceDelegate.getObjectTypes(); |
715 | |
} |
716 | |
|
717 | |
@Override |
718 | |
public List<OrgTreeInfo> getOrgTree(String rootOrgId, String orgHierarchyId, int maxLevels) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
719 | 2 | checkForMissingParameter(rootOrgId, "rootOrgId"); |
720 | 2 | checkForMissingParameter(orgHierarchyId, "orgHierarchyId"); |
721 | |
|
722 | 2 | Set<OrgTreeInfo> results = new HashSet<OrgTreeInfo>(); |
723 | 2 | Org rootOrg = organizationDao.fetch(Org.class, rootOrgId); |
724 | 2 | OrgTreeInfo root = new OrgTreeInfo(rootOrgId, null, rootOrg.getLongName()); |
725 | 2 | root.setPositions(this.organizationDao.getOrgMemebershipCount(root.getOrgId())); |
726 | 2 | root.setOrgHierarchyId(orgHierarchyId); |
727 | 2 | results.add(root); |
728 | 2 | if (maxLevels >= 0) { |
729 | 2 | results.addAll(parseOrgTree(rootOrgId, orgHierarchyId, maxLevels, 0)); |
730 | |
} |
731 | 2 | return new ArrayList<OrgTreeInfo>(results); |
732 | |
} |
733 | |
|
734 | |
private List<OrgTreeInfo> parseOrgTree(String rootOrgId, String orgHierarchyId, int maxLevels, int currentLevel) { |
735 | 169 | List<OrgTreeInfo> results = new ArrayList<OrgTreeInfo>(); |
736 | 169 | if (maxLevels == 0 || currentLevel < maxLevels) { |
737 | 161 | List<OrgTreeInfo> orgTreeInfos = this.organizationDao.getOrgTreeInfo(rootOrgId, orgHierarchyId); |
738 | 161 | for (OrgTreeInfo orgTreeInfo : orgTreeInfos) { |
739 | 167 | orgTreeInfo.setPositions(this.organizationDao.getOrgMemebershipCount(orgTreeInfo.getOrgId())); |
740 | 167 | results.addAll(parseOrgTree(orgTreeInfo.getOrgId(), orgHierarchyId, maxLevels, currentLevel + 1)); |
741 | |
} |
742 | 161 | results.addAll(orgTreeInfos); |
743 | |
} |
744 | 169 | return results; |
745 | |
} |
746 | |
|
747 | |
|
748 | |
|
749 | |
|
750 | |
|
751 | |
|
752 | |
|
753 | |
|
754 | |
|
755 | |
private void checkForMissingParameter(Object param, String paramName) throws MissingParameterException { |
756 | 145 | if (param == null) { |
757 | 9 | throw new MissingParameterException(paramName + " can not be null"); |
758 | |
} |
759 | 136 | } |
760 | |
|
761 | |
public SearchManager getSearchManager() { |
762 | 0 | return searchManager; |
763 | |
} |
764 | |
|
765 | |
public void setSearchManager(SearchManager searchManager) { |
766 | 1 | this.searchManager = searchManager; |
767 | 1 | } |
768 | |
|
769 | |
public DictionaryService getDictionaryServiceDelegate() { |
770 | 0 | return dictionaryServiceDelegate; |
771 | |
} |
772 | |
|
773 | |
public void setDictionaryServiceDelegate(DictionaryService dictionaryServiceDelegate) { |
774 | 1 | this.dictionaryServiceDelegate = dictionaryServiceDelegate; |
775 | 1 | } |
776 | |
|
777 | |
public Validator getValidator() { |
778 | 0 | return validator; |
779 | |
} |
780 | |
|
781 | |
public void setValidator(Validator validator) { |
782 | 0 | this.validator = validator; |
783 | 0 | } |
784 | |
|
785 | |
@Override |
786 | |
public SearchResult search(SearchRequest searchRequest) throws MissingParameterException { |
787 | 5 | checkForMissingParameter(searchRequest, "searchRequest"); |
788 | |
|
789 | |
|
790 | 5 | if (searchOperations != null) { |
791 | 0 | OrganizationSearch search = searchOperations.get(searchRequest.getSearchKey()); |
792 | 0 | if (search != null) { |
793 | 0 | return search.search(searchRequest); |
794 | |
} |
795 | |
} |
796 | |
|
797 | 5 | return searchManager.search(searchRequest, organizationDao); |
798 | |
} |
799 | |
|
800 | |
} |