001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.krad.uif.view;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.krad.datadictionary.DocumentEntry;
020import org.kuali.rice.krad.datadictionary.MaintenanceDocumentEntry;
021import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
022import org.kuali.rice.krad.uif.UifConstants;
023import org.kuali.rice.krad.uif.UifConstants.ViewType;
024import org.kuali.rice.krad.uif.component.RequestParameter;
025
026/**
027 * View type for Maintenance documents
028 *
029 * <p>
030 * Supports primary display for a new maintenance record, in which case the
031 * fields are display for populating the new record, and an edit maintenance
032 * record, which is a comparison view with the old record read-only on the left
033 * side and the new record (changed record) on the right side
034 * </p>
035 *
036 * <p>
037 * The <code>MaintenanceView</code> provides the interface for the maintenance
038 * framework. It works with the <code>Maintainable</code> service and
039 * maintenance controller.
040 * </p>
041 *
042 * <p>
043 * Maintenance views are primarily configured by the object class they are
044 * associated with. This provides the default dictionary information for the
045 * fields. If more than one maintenance view is needed for the same object
046 * class, the view name can be used to further identify an unique view
047 * </p>
048 *
049 * @author Kuali Rice Team (rice.collab@kuali.org)
050 */
051public class MaintenanceView extends DocumentView {
052    private static final long serialVersionUID = -3382802967703882341L;
053
054    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceView.class);
055
056    private Class<?> dataObjectClassName;
057
058    private String oldObjectBindingPath;
059
060    @RequestParameter
061    private String maintenanceAction;
062
063    public MaintenanceView() {
064        super();
065
066        setViewTypeName(ViewType.MAINTENANCE);
067    }
068
069    /**
070     * The following initialization is performed:
071     *
072     * <ul>
073     * <li>Set the abstractTypeClasses map for the maintenance object path</li>
074     * </ul>
075     *
076     * @see org.kuali.rice.krad.uif.container.ContainerBase#performInitialization(org.kuali.rice.krad.uif.view.View, java.lang.Object)
077     */
078    @Override
079    public void performInitialization(View view, Object model) {
080        super.performInitialization(view, model);
081
082        getAbstractTypeClasses().put(getDefaultBindingObjectPath(), getDataObjectClassName());
083        getAbstractTypeClasses().put(getOldObjectBindingPath(), getDataObjectClassName());
084    }
085
086    /**
087     * Overrides to retrieve the a {@link MaintenanceDocumentEntry} based on the configured data object class
088     *
089     * @return MaintenanceDocumentEntry document entry (exception thrown if not found)
090     */
091    @Override
092    protected MaintenanceDocumentEntry getDocumentEntryForView() {
093        MaintenanceDocumentEntry documentEntry = null;
094        String docTypeName = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(
095                getDataObjectClassName());
096        if (StringUtils.isNotBlank(docTypeName)) {
097            documentEntry = KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentEntry(
098                    docTypeName);
099        }
100
101        if (documentEntry == null) {
102            throw new RuntimeException(
103                    "Unable to find maintenance document entry for data object class: " + getDataObjectClassName()
104                            .getName());
105        }
106
107        return documentEntry;
108    }
109
110    /**
111     * Class name for the object the maintenance document applies to
112     *
113     * <p>
114     * The object class name is used to pick up a dictionary entry which will
115     * feed the attribute field definitions and other configuration. In addition
116     * it is used to configure the <code>Maintainable</code> which will carry
117     * out the maintenance action
118     * </p>
119     *
120     * @return Class<?> maintenance object class
121     */
122    public Class<?> getDataObjectClassName() {
123        return this.dataObjectClassName;
124    }
125
126    /**
127     * Setter for the object class name
128     *
129     * @param dataObjectClassName
130     */
131    public void setDataObjectClassName(Class<?> dataObjectClassName) {
132        this.dataObjectClassName = dataObjectClassName;
133    }
134
135    /**
136     * Gives the binding path to the old object (record being edited) to display
137     * for comparison
138     *
139     * @return String old object binding path
140     */
141    public String getOldObjectBindingPath() {
142        return this.oldObjectBindingPath;
143    }
144
145    /**
146     * Setter for the old object binding path
147     *
148     * @param oldObjectBindingPath
149     */
150    public void setOldObjectBindingPath(String oldObjectBindingPath) {
151        this.oldObjectBindingPath = oldObjectBindingPath;
152    }
153
154    /**
155     * Indicates what maintenance action (new, edit, copy) was
156     * requested
157     *
158     * @return String maintenance action
159     */
160    public String getMaintenanceAction() {
161        return maintenanceAction;
162    }
163
164    /**
165     * Setter for the maintenance action
166     *
167     * @param maintenanceAction
168     */
169    public void setMaintenanceAction(String maintenanceAction) {
170        this.maintenanceAction = maintenanceAction;
171    }
172
173}