View Javadoc
1   package org.kuali.ole.batch.keyvalue;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.batch.bo.OLEBatchProcessProfileConstantsBo;
6   import org.kuali.ole.select.bo.OLEDonor;
7   import org.kuali.rice.core.api.util.ConcreteKeyValue;
8   import org.kuali.rice.core.api.util.KeyValue;
9   import org.kuali.rice.krad.service.KRADServiceLocator;
10  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
11  import org.kuali.rice.krad.uif.view.ViewModel;
12  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
13  import org.springframework.util.CollectionUtils;
14  
15  import java.util.ArrayList;
16  import java.util.HashSet;
17  import java.util.List;
18  import java.util.Set;
19  
20  /**
21   * Created by rajeshbabuk on 21/7/14.
22   */
23  public class OLEBatchProcessDonorKeyValueFinder extends UifKeyValuesFinderBase {
24      @Override
25      public List<KeyValue> getKeyValues(ViewModel model) {
26          List<KeyValue> keyValues = new ArrayList<KeyValue>();
27          MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) model;
28          OLEBatchProcessProfileConstantsBo oleBatchProcessProfileConstantsBo = null;
29          if (!CollectionUtils.isEmpty(maintenanceForm.getNewCollectionLines())) {
30              oleBatchProcessProfileConstantsBo = (OLEBatchProcessProfileConstantsBo) maintenanceForm.getNewCollectionLines().get("document.newMaintainableObject.dataObject.oleBatchProcessProfileConstantsList");
31          }
32          if (oleBatchProcessProfileConstantsBo != null) {
33              String dataType = oleBatchProcessProfileConstantsBo.getDataType();
34              if (StringUtils.isNotBlank(dataType)) {
35                  String attributeName = oleBatchProcessProfileConstantsBo.getAttributeName();
36                  String oldAttributeName = oleBatchProcessProfileConstantsBo.getOldAttributeName();
37                  if (!StringUtils.isBlank(attributeName)) {
38                      if (oldAttributeName == null || !attributeName.equalsIgnoreCase(oldAttributeName)) {
39                          oleBatchProcessProfileConstantsBo.setOldAttributeName(attributeName);
40                          if (dataType.equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_PROCESS_PROFILE_DATATYPE_ITEM) || dataType.equalsIgnoreCase(OLEConstants.OLEBatchProcess.BATCH_PROCESS_PROFILE_DATATYPE_EHOLDINGS)) {
41                              List<OLEDonor> donorInfoList = (List<OLEDonor>) KRADServiceLocator.getBusinessObjectService().findAll(OLEDonor.class);
42                              if (attributeName.equalsIgnoreCase(OLEConstants.OLEBatchProcess.DESTINATION_FIELD_DONOR_CODE)) {
43                                  if (!CollectionUtils.isEmpty(donorInfoList)) {
44                                      Set<KeyValue> donorCodes = new HashSet<>();
45                                      for (OLEDonor oleDonor : donorInfoList) {
46                                          donorCodes.add(new ConcreteKeyValue(oleDonor.getDonorCode(), oleDonor.getDonorCode()));
47                                      }
48                                      keyValues.addAll(donorCodes);
49                                  }
50                              } else if (attributeName.equalsIgnoreCase(OLEConstants.OLEBatchProcess.DESTINATION_FIELD_DONOR_PUBLIC_DISPLAY)) {
51                                  if (!CollectionUtils.isEmpty(donorInfoList)) {
52                                      Set<KeyValue> donorPublicDisplays = new HashSet<>();
53                                      for (OLEDonor oleDonor : donorInfoList) {
54                                          donorPublicDisplays.add(new ConcreteKeyValue(oleDonor.getDonorPublicDisplay(), oleDonor.getDonorPublicDisplay()));
55                                      }
56                                      keyValues.addAll(donorPublicDisplays);
57                                  }
58                              } else if (attributeName.equalsIgnoreCase(OLEConstants.OLEBatchProcess.DESTINATION_FIELD_DONOR_NOTE)) {
59                                  if (!CollectionUtils.isEmpty(donorInfoList)) {
60                                      Set<KeyValue> donorNotes = new HashSet<>();
61                                      for (OLEDonor oleDonor : donorInfoList) {
62                                          donorNotes.add(new ConcreteKeyValue(oleDonor.getDonorNote(), oleDonor.getDonorNote()));
63                                      }
64                                      keyValues.addAll(donorNotes);
65                                  }
66                              }
67                          }
68                      }
69                  }
70              }
71          }
72          return keyValues;
73      }
74  }