summaryrefslogtreecommitdiff
path: root/orkweb/src/net/sf/oreka/services/RecSegmentFilter.java
blob: 20b12ef0af04f29a7147c3e683290f3ff4913246 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
 * Oreka -- A media capture and retrieval platform
 * 
 * Copyright (C) 2005, orecx LLC
 *
 * http://www.orecx.com
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License.
 * Please refer to http://www.gnu.org/copyleft/gpl.html
 *
 */

/**
 * 
 */
package net.sf.oreka.services;

import java.util.Date;

import net.sf.oreka.Direction;
import net.sf.oreka.orkweb.ContextListener;

import org.apache.log4j.Logger;

public class RecSegmentFilter extends FormFilter {

	static Logger logger = Logger.getLogger(RecSegmentFilter.class);
	
	private String minDuration = "";
	private String minDurationError;
	private String maxDuration = "";
	private String maxDurationError;
	private String localParty = "";
	private String localPartyError;
	private String remoteParty = "";
	private String remotePartyError;
	private Date startDate = null;
    private Date endDate = null;
	private Direction direction;

	private final String UNALLOWED_CHARACTER = "Unallowed character";
	private final String ENTER_A_NUMBER = "Enter a number";
	
	private boolean isStringInvalidParty(String party) {
		// See if there are any characters not listed here
		return (party.matches(".*[^A-Za-z0-9#\\*@].*"));
	}
	
	public String getErrorStyle(){
		return "error";
	}
	public String getOkStyle(){
		return "";
	}
	
	/**
	 * @return Returns the durationError.
	 */
	public String getMinDurationError() {
		return minDurationError;
	}
	


	/**
	 * @param durationError The durationError to set.
	 */
	public void setMinDurationError(String durationError) {
		this.minDurationError = durationError;
	}
	


	/**
	 * @return Returns the localPartyError.
	 */
	public String getLocalPartyError() {
		return localPartyError;
	}
	


	/**
	 * @param localPartyError The localPartyError to set.
	 */
	public void setLocalPartyError(String localPartyError) {
		this.localPartyError = localPartyError;
	}
	


	/**
	 * @return Returns the localParty.
	 */
	public String getLocalParty() {
		return localParty;
	}
	

	/**
	 * @param localParty The localParty to set.
	 */
	public void setLocalParty(String localParty) {
		
		if(localParty == null) {
			this.localParty = "";
		}
		else {
			localParty.trim();
			this.localParty = localParty;
		}
		if (isStringInvalidParty(this.localParty)) {
			setLocalPartyError(UNALLOWED_CHARACTER);
		}
		else {
			setLocalPartyError(null);
		}
	}
	

	public RecSegmentFilter() {
		
		minDuration = new String();
		localParty = new String();
		direction = Direction.ALL;
		
		long millisIn24hours = 24 * 3600 * 1000;
		endDate = new Date();
		
		// For now, retrieve 24 hours worth of records by default
		if (ContextListener.debugSwitch == false) {
			startDate = new Date(endDate.getTime() - millisIn24hours);
		}
		else {
			startDate = new Date(0);
		}
		
		/*
	    // Read properties file.
	    Properties properties = new Properties();
	    try {
	        properties.load(new FileInputStream("RecSegmentFilter.properties"));
	    } catch (IOException e) {
			System.out.println("@@@@@@@@@@");
	    }
		*/

	}


	/**
	 * @return Returns the duration.
	 */
	public String getMinDuration() {
		return minDuration;
	}
	


	/**
	 * @param minDuration The duration to set.
	 */
	public void setMinDuration(String minDuration) {
		
		if(minDuration == null) {
			this.minDuration = "";
		}
		else {
			minDuration.trim();
			this.minDuration = minDuration;
		}
		if (this.minDuration.matches(".*[^0-9].*")) {
			// there is a funny character here ...
			setMinDurationError(ENTER_A_NUMBER);
		}
		else {
			setMinDurationError(null);
		}
	}
	public Date getEndDate() {
		return endDate;
	}
	
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
	public Date getStartDate() {
		return startDate;
	}
	
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public String getRemoteParty() {
		return remoteParty;
	}
	

	public void setRemoteParty(String remoteParty) {
		if(remoteParty == null) {
			this.remoteParty = "";
		}
		else {
			remoteParty.trim();
			this.remoteParty = remoteParty;
		}
		if (isStringInvalidParty(this.remoteParty)) {
			setRemotePartyError(UNALLOWED_CHARACTER);
		}
		else {
			setRemotePartyError(null);
		}
	}
	

	public String getRemotePartyError() {
		return remotePartyError;
	}
	

	public void setRemotePartyError(String remotePartyError) {
		this.remotePartyError = remotePartyError;
	}

	public Direction getDirection() {
		return direction;
	}
	

	public void setDirection(Direction direction) {
		this.direction = direction;
	}

	public String getMaxDuration() {
		return maxDuration;
	}
	

	public void setMaxDuration(String maxDuration) {
		if(maxDuration == null) {
			this.maxDuration = "";
		}
		else {
			maxDuration.trim();
			this.maxDuration = maxDuration;
		}
		if (this.maxDuration.matches(".*[^0-9].*")) {
			// there is a funny character here ...
			setMaxDurationError(ENTER_A_NUMBER);
		}
		else {
			setMaxDurationError(null);
		}
	}
	

	public String getMaxDurationError() {
		return maxDurationError;
	}
	

	public void setMaxDurationError(String maxDurationError) {
		this.maxDurationError = maxDurationError;
	}
	
	
	
	
	

}