001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/reports/api/src/java/org/theospi/portfolio/reports/model/ReportParam.java $
003: * $Id:ReportParam.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.reports.model;
021:
022: import org.sakaiproject.metaobj.shared.model.Id;
023:
024: import java.util.List;
025: import java.util.ArrayList;
026:
027: public class ReportParam {
028: /** the identifier to the report paramater */
029: private Id paramId = null;
030:
031: /** the identifier to the report definition for the paramater */
032: private Report report = null;
033:
034: /** the reportDefParamId for the report definition parameter */
035: private ReportDefinitionParam reportDefinitionParam = null;
036:
037: /** the type for the report definition Parameter
038: * This is validation rules for fillin parameters,
039: * a set of strings for sets (both value and title),
040: * and the query if the value type is a sql query
041: */
042: private String value = null;
043:
044: /** true when the value passes the test and false when the value changes */
045: private boolean validated = false;
046:
047: /** the results of the last validation */
048: private boolean valid = false;
049:
050: private String reportDefParamIdMark = null;
051:
052: private List listValue = null;
053:
054: /**
055: * the getter for the paramId property
056: * @return String the unique identifier
057: */
058: public Id getParamId() {
059: return paramId;
060: }
061:
062: /**
063: * the setter for the paramId property. This is set by the bean
064: * and by hibernate.
065: * @param paramId String
066: */
067: public void setParamId(Id paramId) {
068: this .paramId = paramId;
069: }
070:
071: /**
072: * the getter for the report property
073: * @return String the unique identifier
074: */
075: public Report getReport() {
076: return report;
077: }
078:
079: /**
080: * the setter for the report property. This is set by the bean
081: * and by hibernate.
082: * @param report Report
083: */
084: public void setReport(Report report) {
085: this .report = report;
086: }
087:
088: /**
089: * the getter for the reportDefinitionParam property
090: * @return ReportDefinitionParam the unique identifier
091: */
092: public ReportDefinitionParam getReportDefinitionParam() {
093: return reportDefinitionParam;
094: }
095:
096: /**
097: * the setter for the reportDefinitionParam property. This is set by the bean
098: * and by hibernate.
099: * @param reportDefinitionParam String
100: */
101: public void setReportDefinitionParam(
102: ReportDefinitionParam reportDefinitionParam) {
103: this .reportDefinitionParam = reportDefinitionParam;
104: }
105:
106: /**
107: * This is a way of separating the report definition from the report in the database
108: * this is a temp solution while the report definitions aren't being stored in the database
109: * @return String
110: */
111: public String getReportDefParamIdMark() {
112: if (reportDefinitionParam == null)
113: return reportDefParamIdMark;
114: return reportDefinitionParam.getIdString();
115: }
116:
117: /**
118: * this is the link to report definition
119: * @param reportDefIdMark String
120: */
121: public void setReportDefParamIdMark(String reportDefParamIdMark) {
122: reportDefinitionParam = null;
123: this .reportDefParamIdMark = reportDefParamIdMark;
124: }
125:
126: /**
127: * the getter for the value property
128: * @return String the value
129: */
130: public String getValue() {
131: if (value == null && getListValue() != null) {
132: value = getListValue().toString();
133: }
134: return value;
135: }
136:
137: /**
138: * the setter for the value property. This is set by the bean or the user
139: * and by hibernate.
140: * @param value String
141: */
142: public void setValue(String value) {
143: this .value = value;
144: validated = false;
145: }
146:
147: /**
148: * Checks to make sure that the value can be selected.
149: * Apply validation rules, check against set, check against the sql results
150: * @return boolean
151: */
152: public boolean valid() {
153: if (value == null)
154: return false;
155: if (!validated) {
156: valid = true;
157:
158: //do the check here
159:
160: validated = true;
161: }
162: return valid;
163: }
164:
165: public List getListValue() {
166: if (listValue == null && this .value != null) {
167: initListValue(this .value);
168: }
169: return listValue;
170: }
171:
172: public void setListValue(List listValue) {
173: this .listValue = listValue;
174: validated = false;
175: }
176:
177: public void initListValue(String value) {
178: if (value == null
179: || ((value.indexOf("[") < 0) || (value.indexOf("]") < 0)))
180: return;
181: String strSet = value.substring(value.indexOf("[") + 1, value
182: .indexOf("]"));
183: String[] set = strSet.split(",");
184: List valueList = new ArrayList();
185: for (int i = 0; i < set.length; i++) {
186: valueList.add(set[i].trim());
187: }
188: setListValue(valueList);
189: }
190: }
|