View Javadoc

1   /**
2    * Copyright 2005-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  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.kns.rules.DocumentRuleBase;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  import org.springframework.util.CollectionUtils;
27  
28  /**
29   * This is a description of what this class does - shyu don't forget to fill this in. 
30   * 
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public class PersonDocumentRoleRule extends DocumentRuleBase implements AddRoleRule {
35      public static final String ERROR_PATH = "newRole.roleId";
36  
37  	public boolean processAddRole(AddRoleEvent addRoleEvent) {
38  		PersonDocumentRole newRole = addRoleEvent.getRole();
39  		IdentityManagementPersonDocument document = (IdentityManagementPersonDocument)addRoleEvent.getDocument();
40  		boolean rulePassed = true;
41  //    	List<String> roleIds = KimImplServiceLocator.getUiDocumentService().getAssignableRoleIds();
42  
43          if (newRole == null || StringUtils.isBlank(newRole.getRoleId())) {
44              rulePassed = false;
45              GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_EMPTY_ENTRY, new String[] {"Role"});
46          	
47  //        } else if (roleIds.isEmpty() || !roleIds.contains(newRole.getRoleId())) {
48  //            errorMap.putError(ERROR_PATH, RiceKeyConstants.ERROR_ASSIGN_ROLE, new String[] {newRole.getRoleId()});
49  //            rulePassed = false;
50          } else {
51  		    for (PersonDocumentRole role : document.getRoles()) {
52  		    	if (role.getRoleId().equals(newRole.getRoleId())) {
53  		            rulePassed = false;
54  		            GlobalVariables.getMessageMap().putError(ERROR_PATH, RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Role"});
55  		    		
56  		    	}
57  		    }
58          }
59  
60          // KULRICE-7930  Check for field validation errors
61          if(!CollectionUtils.isEmpty(GlobalVariables.getMessageMap().getErrorMessagesForProperty("newRole.*", true))) {
62              rulePassed = false;
63          }
64  
65  		return rulePassed;
66  	} 
67  
68  }