001package org.kuali.ole.deliver.maintenance;
002
003import org.apache.commons.collections.CollectionUtils;
004import org.apache.commons.lang3.StringUtils;
005import org.kuali.ole.deliver.bo.OleCirculationDesk;
006import org.kuali.ole.deliver.bo.OleCirculationDeskLocation;
007import org.kuali.rice.krad.maintenance.MaintainableImpl;
008import org.kuali.rice.krad.maintenance.MaintenanceDocument;
009
010import java.util.ArrayList;
011import java.util.List;
012import java.util.Map;
013
014/**
015 * Created with IntelliJ IDEA.
016 * User: aurojyotit
017 * Date: 2/6/15
018 * Time: 1:27 PM
019 * To change this template use File | Settings | File Templates.
020 */
021public class OleCirculationDeskMaintenanceImpl extends MaintainableImpl {
022
023    @Override
024    public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
025        Object object = super.retrieveObjectForEditOrCopy(document, dataObjectKeys);
026        if (object != null && object instanceof OleCirculationDesk) {
027            OleCirculationDesk oleCirculationDesk = (OleCirculationDesk) object;
028            List<OleCirculationDeskLocation> oleCirculationDeskLocationList = new ArrayList<OleCirculationDeskLocation>();
029            List<OleCirculationDeskLocation> olePickupCirculationDeskLocations = new ArrayList<OleCirculationDeskLocation>();
030            if (CollectionUtils.isNotEmpty(oleCirculationDesk.getOleCirculationDeskLocations())) {
031                for (OleCirculationDeskLocation oleCirculationDeskLocation : oleCirculationDesk.getOleCirculationDeskLocations()) {
032                    if (StringUtils.isNotBlank(oleCirculationDeskLocation.getCirculationPickUpDeskLocation())) {
033                        olePickupCirculationDeskLocations.add(oleCirculationDeskLocation);
034                    } else {
035                        oleCirculationDeskLocationList.add(oleCirculationDeskLocation);
036                    }
037                }
038            }
039            oleCirculationDesk.setOleCirculationDeskLocationList(oleCirculationDeskLocationList);
040            oleCirculationDesk.setOlePickupCirculationDeskLocations(olePickupCirculationDeskLocations);
041        }
042        return object;
043    }
044}