View Javadoc
1   package org.kuali.ole.describe.keyvalue;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.describe.bo.OleItemAvailableStatus;
5   import org.kuali.rice.core.api.util.ConcreteKeyValue;
6   import org.kuali.rice.core.api.util.KeyValue;
7   import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
8   import org.kuali.rice.coreservice.api.parameter.Parameter;
9   import org.kuali.rice.coreservice.api.parameter.ParameterKey;
10  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
11  import org.kuali.rice.krad.service.KRADServiceLocator;
12  
13  import java.util.*;
14  
15  /**
16   * ItemStatus used to render the values for ItemStatus dropdown control.
17   */
18  public class ItemStatusForEditor extends KeyValuesBase {
19      /**
20       * This method returns the List of  ConcreteKeyValue (excludes the values in ITEM_STATUS_READONLY parameter),
21       * ConcreteKeyValue has two arguments itemAvailableStatusCode and
22       * itemAvailableStatusName.
23       *
24       * @return List<KeyValue>
25       */
26      @Override
27      public List<KeyValue> getKeyValues() {
28  
29          List<KeyValue> options = new ArrayList<KeyValue>();
30          Collection<OleItemAvailableStatus> oleItemAvailableStatuses = KRADServiceLocator.getBusinessObjectService().findAllOrderBy(OleItemAvailableStatus.class,"itemAvailableStatusCode",true);
31          options.add(new ConcreteKeyValue("", ""));
32  
33          String excludeItemStatus = getParameter("ITEM_STATUS_READONLY");
34          Map<String,String> map = new HashMap<>();
35          if(excludeItemStatus!=null && !excludeItemStatus.isEmpty()){
36              String[] itemStatusList = excludeItemStatus.split(",");
37              for(String itemStatus : itemStatusList){
38                  map.put(itemStatus,itemStatus);
39              }
40          }
41          for (OleItemAvailableStatus type : oleItemAvailableStatuses) {
42              if (type.isActive() && !map.containsKey(type.getItemAvailableStatusCode())) {
43                  options.add(new ConcreteKeyValue(type.getItemAvailableStatusCode(), type.getItemAvailableStatusName()));
44              }
45          }
46          return options;
47      }
48  
49      public String getParameter(String name){
50          ParameterKey parameterKey = ParameterKey.create(OLEConstants.APPL_ID, OLEConstants.DESC_NMSPC, OLEConstants.DESCRIBE_COMPONENT,name);
51          Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
52          return parameter!=null?parameter.getValue():null;
53      }
54  
55  }