001package org.kuali.ole.deliver;
002
003import org.apache.log4j.Logger;
004import org.kuali.ole.deliver.form.OleLoanForm;
005import org.kuali.ole.describe.form.EditorForm;
006import org.kuali.ole.krad.OleComponent;
007import org.kuali.ole.krad.OleComponentUtils;
008import org.kuali.rice.krad.uif.component.Component;
009import org.kuali.rice.krad.uif.container.Group;
010import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
011import org.kuali.rice.krad.uif.view.View;
012
013import java.util.Iterator;
014import java.util.List;
015
016/**
017 * Created with IntelliJ IDEA.
018 * User: palanivel
019 * Date: 4/29/14
020 * Time: 3:55 PM
021 * To change this template use File | Settings | File Templates.
022 */
023public class OleGroup extends Group {
024    private static final Logger LOG = Logger
025            .getLogger(OleGroup.class);
026
027    private static String ALTER_DUE_DATE_ID = "AlterDueDateSection-HorizontalBoxSection";
028
029    private static String RENEWAL_ID = "RenewalDueDateSection-HorizontalBoxSection";
030
031    private static String PROXY_PATRON_ID = "RealPatronSection-HorizontalBoxSection";
032
033    private static String DAMAGED_ITEM_ID = "DamagedItem-HorizontalBoxSection";
034
035    private static String MISSING_PIECE_ID = "MissingPiece-HorizontalBoxSection";
036
037    private static String CLAIMS_RETURN_ID = "ClaimsReturn-HorizontalBoxSection";
038
039    private static String OVERRIDE_LOGIN = "OverRideLogInSectionLink";
040
041    private static String PATRON_NOTE_ID = "PatronUserNote-HorizontalBoxSection";
042
043    private static String CONFIRM_CIRULATION_LOCATION = "ConfirmCirculationLocationChange";
044
045    private static String MISSING_PIECE_RECORD_NOTE = "OLELoanView-RecordNote-MissingPiece-MessageBox";
046
047    private static String DAMAGED_RECORD_NOTE = "OLELoanView-RecordNote-Damaged-MessageBox";
048
049    private static String LOAN_CLAIMS_OPTIONS = "loanClaimsOption";
050
051
052    /**
053     * The following actions are performed:
054     *
055     * <ul>
056     * <li>Sets the bindByNamePrefix if blank on any InputField and
057     * FieldGroup instances within the items List</li>
058     * </ul>
059     *
060     * @see org.kuali.rice.krad.uif.component.ComponentBase#performInitialization(org.kuali.rice.krad.uif.view.View,
061     *      java.lang.Object)
062     */
063    @Override
064    public void performInitialization(View view, Object form) {
065
066        super.performInitialization(view, form);
067
068        boolean alterDueDate = ((OleLoanForm) form).isAlterDueDateFlag();
069        boolean renewDueDateFlag = ((OleLoanForm) form).isRenewDueDateFlag();
070        boolean realPatronFlag =  ((OleLoanForm) form).isRealPatronFlag();
071        boolean missingPieceDialog = ((OleLoanForm) form).isMissingPieceDialog();
072        boolean damagedItemDialog =  ((OleLoanForm) form).isDamagedItemDialog();
073        boolean claimsReturnFlag = ((OleLoanForm) form).isClaimsReturnFlag();
074        boolean overrideFlag = ((OleLoanForm) form).isOverrideFlag();
075        boolean patronNoteFlag = ((OleLoanForm) form).isPatronNoteFlag();
076        boolean changeLocationFlag = ((OleLoanForm) form).isChangeLocationFlag();
077        boolean displayMissingPieceNotePopup = ((OleLoanForm) form).isDisplayMissingPieceNotePopup();
078        boolean displayDamagedRecordNotePopup = ((OleLoanForm) form).isDisplayDamagedRecordNotePopup();
079        boolean claimsFlag = ((OleLoanForm) form).isClaimsFlag();
080        LOG.info("alterDueDate " + alterDueDate);
081        List<? extends Component> items = getItems();
082        Iterator<? extends Component> itemIterator = items.iterator();
083        while (itemIterator.hasNext()) {
084            Component component = itemIterator.next();
085            if (component == null) {
086                continue;
087            }
088
089            LOG.info("checking component " + component.getId());
090
091
092            if (ALTER_DUE_DATE_ID.equals(component.getId())
093                    && !alterDueDate) {
094                LOG.info("Omitting "+component.getId()+" from lifecycle");
095                itemIterator.remove();
096            }else if(RENEWAL_ID.equals(component.getId())
097                    && !renewDueDateFlag){
098                LOG.info("Omitting "+component.getId()+" from lifecycle");
099                itemIterator.remove();
100            }else if(PROXY_PATRON_ID.equals(component.getId())
101                    && !realPatronFlag){
102                LOG.info("Omitting "+component.getId()+" from lifecycle");
103                itemIterator.remove();
104            }else if(DAMAGED_ITEM_ID.equals(component.getId())
105                    && !damagedItemDialog){
106                LOG.info("Omitting "+component.getId()+" from lifecycle");
107                itemIterator.remove();
108            }else if(MISSING_PIECE_ID.equals(component.getId())
109                    && !missingPieceDialog){
110                LOG.info("Omitting "+component.getId()+" from lifecycle");
111                itemIterator.remove();
112            }else if(CLAIMS_RETURN_ID.equals(component.getId())
113                    && !claimsReturnFlag){
114                LOG.info("Omitting "+component.getId()+" from lifecycle");
115                itemIterator.remove();
116            }else if(OVERRIDE_LOGIN.equals(component.getId())
117                    && !overrideFlag){
118                LOG.info("Omitting "+component.getId()+" from lifecycle");
119                itemIterator.remove();
120            }else if(PATRON_NOTE_ID.equals(component.getId())
121                    && !patronNoteFlag){
122                LOG.info("Omitting "+component.getId()+" from lifecycle");
123                itemIterator.remove();
124            }else if(CONFIRM_CIRULATION_LOCATION.equals(component.getId())
125                    && !changeLocationFlag){
126                LOG.info("Omitting "+component.getId()+" from lifecycle");
127                itemIterator.remove();
128            }else if(MISSING_PIECE_RECORD_NOTE.equals(component.getId())
129                    && !displayMissingPieceNotePopup){
130                LOG.info("Omitting "+component.getId()+" from lifecycle");
131                itemIterator.remove();
132            }else if(DAMAGED_RECORD_NOTE.equals(component.getId())
133                    && !displayDamagedRecordNotePopup){
134                LOG.info("Omitting "+component.getId()+" from lifecycle");
135                itemIterator.remove();
136            }else if(LOAN_CLAIMS_OPTIONS.equals(component.getId())
137                    && !claimsFlag){
138                LOG.info("Omitting "+component.getId()+" from lifecycle");
139                itemIterator.remove();
140            }
141        }
142    }
143
144        /**
145         * Filters {@link OleComponent} instances based on
146         * {@link OleComponent#getFilterModelProperty()}, if the current model is
147         * available.
148         */
149        @Override
150        protected <T> void copyProperties(T component) {
151                List<? extends Component> srcitems = getItems();
152                
153                // prevent super() from copying items
154                setItems(null);
155                super.copyProperties(component);
156                setItems(srcitems);
157                
158                Group groupCopy = (Group) component;
159                groupCopy.setItems(OleComponentUtils.filterItems(srcitems));
160        }
161
162}