001/**
002 * Copyright 2005-2018 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.web.form;
017
018import java.io.Serializable;
019
020/**
021 * Holds response data for a basic dialog that has been triggered from a server call.
022 *
023 * @author Kuali Rice Team (rice.collab@kuali.org)
024 */
025public class DialogResponse implements Serializable {
026    private static final long serialVersionUID = -3533683391767027067L;
027
028    protected static final String TRUE_VALUES = "/true/yes/y/on/1/";
029
030    private String dialogId;
031
032    private String response;
033    private String explanation;
034
035    /**
036     * Default Constructor.
037     */
038    public DialogResponse() {
039    }
040
041    /**
042     * Constructor taking dialog id, response, and explanation.
043     */
044    public DialogResponse(String dialogId, String response, String explanation) {
045        this.dialogId = dialogId;
046        this.response = response;
047        this.explanation = explanation;
048    }
049
050    /**
051     * Id for the dialog whose response has been captured.
052     *
053     * @return dialog id
054     */
055    public String getDialogId() {
056        return dialogId;
057    }
058
059    /**
060     * @see DialogResponse#getDialogId()
061     */
062    public void setDialogId(String dialogId) {
063        this.dialogId = dialogId;
064    }
065
066    /**
067     * String response for the dialog action (button) that was chosen.
068     *
069     * @return String dialog response
070     */
071    public String getResponse() {
072        return response;
073    }
074
075    /**
076     * Returns the response for the dialog as a boolean.
077     *
078     * @return boolean dialog response
079     * @see DialogResponse#TRUE_VALUES
080     */
081    public boolean getResponseAsBoolean() {
082        if (response != null) {
083            StringBuilder builder = new StringBuilder();
084            builder.append("/").append(response.toLowerCase()).append("/");
085
086            if (TRUE_VALUES.contains(builder.toString())) {
087                return true;
088            }
089        }
090
091        return false;
092    }
093
094    /**
095     * @see DialogResponse#getResponse()
096     */
097    public void setResponse(String response) {
098        this.response = response;
099    }
100
101    /**
102     * If the dialog contained an explanation field that binds to the generic form property, the value (if any)
103     * given by the user.
104     *
105     * <p>Note if the explanation field was found to a different model property, its contents will not be
106     * available here. It should be retrieved from the corresponding model property.</p>
107     *
108     * @return string explanation value
109     */
110    public String getExplanation() {
111        return explanation;
112    }
113
114    /**
115     * @see DialogResponse#getExplanation()
116     */
117    public void setExplanation(String explanation) {
118        this.explanation = explanation;
119    }
120}