View Javadoc
1   /*
2    * Copyright 2011 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.ole.select.businessobject.options;
17  
18  import org.kuali.ole.select.OleSelectConstant;
19  import org.kuali.ole.sys.OLEConstants;
20  import org.kuali.rice.core.api.util.ConcreteKeyValue;
21  import org.kuali.rice.core.api.util.KeyValue;
22  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
23  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
24  import org.kuali.rice.krad.util.GlobalVariables;
25  
26  import java.util.ArrayList;
27  import java.util.Collections;
28  import java.util.HashMap;
29  import java.util.List;
30  
31  public class DefaultValueForValuesFinder extends KeyValuesBase {
32  
33      @Override
34      public List<KeyValue> getKeyValues() {
35          List<KeyValue> keyValues = new ArrayList<KeyValue>();
36          String systemUserRoleId = KimApiServiceLocator.getRoleService().getRoleIdByNamespaceCodeAndName(
37                  OLEConstants.CoreModuleNamespaces.OLE, OleSelectConstant.SYSTEM_USER_ROLE_NAME);
38  
39          if (KimApiServiceLocator.getRoleService().principalHasRole(
40                  GlobalVariables.getUserSession().getPrincipalId(),
41                  Collections.singletonList(systemUserRoleId), new HashMap<String, String>())) {
42              keyValues.add(new ConcreteKeyValue(OleSelectConstant.DEFAULT_VALUE_ROLE, OleSelectConstant.DEFAULT_VALUE_ROLE));
43              keyValues.add(new ConcreteKeyValue(OleSelectConstant.DEFAULT_VALUE_SYSTEM, OleSelectConstant.DEFAULT_VALUE_SYSTEM));
44          } else {
45              keyValues.add(new ConcreteKeyValue(OleSelectConstant.DEFAULT_VALUE_USER, OleSelectConstant.DEFAULT_VALUE_USER));
46          }
47          return keyValues;
48      }
49  
50  }