Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PersonDocumentRoleRule |
|
| 5.0;5 |
1 | /* | |
2 | * Copyright 2007-2008 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 | package org.kuali.rice.kim.rules.ui; | |
17 | ||
18 | import org.apache.commons.lang.StringUtils; | |
19 | import org.kuali.rice.core.api.util.RiceKeyConstants; | |
20 | import org.kuali.rice.kim.bo.ui.PersonDocumentRole; | |
21 | import org.kuali.rice.kim.document.IdentityManagementPersonDocument; | |
22 | import org.kuali.rice.kim.rule.event.ui.AddRoleEvent; | |
23 | import org.kuali.rice.kim.rule.ui.AddRoleRule; | |
24 | import org.kuali.rice.krad.rules.DocumentRuleBase; | |
25 | import org.kuali.rice.krad.util.GlobalVariables; | |
26 | ||
27 | /** | |
28 | * This is a description of what this class does - shyu don't forget to fill this in. | |
29 | * | |
30 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
31 | * | |
32 | */ | |
33 | 0 | public class PersonDocumentRoleRule extends DocumentRuleBase implements AddRoleRule { |
34 | public static final String ERROR_PATH = "newRole.roleId"; | |
35 | ||
36 | public boolean processAddRole(AddRoleEvent addRoleEvent) { | |
37 | 0 | PersonDocumentRole newRole = addRoleEvent.getRole(); |
38 | 0 | IdentityManagementPersonDocument document = (IdentityManagementPersonDocument)addRoleEvent.getDocument(); |
39 | 0 | boolean rulePassed = true; |
40 | // List<String> roleIds = KIMServiceLocatorInternal.getUiDocumentService().getAssignableRoleIds(); | |
41 | ||
42 | 0 | if (newRole == null || StringUtils.isBlank(newRole.getRoleId())) { |
43 | 0 | rulePassed = false; |
44 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Role"}); |
45 | ||
46 | // } else if (roleIds.isEmpty() || !roleIds.contains(newRole.getRoleId())) { | |
47 | // errorMap.putError(ERROR_PATH, RiceKeyConstants.ERROR_ASSIGN_ROLE, new String[] {newRole.getRoleId()}); | |
48 | // rulePassed = false; | |
49 | } else { | |
50 | 0 | for (PersonDocumentRole role : document.getRoles()) { |
51 | 0 | if (role.getRoleId().equals(newRole.getRoleId())) { |
52 | 0 | rulePassed = false; |
53 | 0 | GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Role"}); |
54 | ||
55 | } | |
56 | } | |
57 | } | |
58 | 0 | return rulePassed; |
59 | } | |
60 | ||
61 | } |