| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 29 | |
|
| 30 | |
|
| 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 | |
|
| 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 | |
|
| 47 | |
|
| 48 | |
|
| 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 | |
} |