001: /*
002: * Copyright 2005 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Oct 7, 2005
014: * @author James Dixon
015: */
016:
017: package com.pentaho.repository.subscribe;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.dom4j.Document;
025: import org.pentaho.commons.connection.memory.MemoryMetaData;
026: import org.pentaho.core.system.PentahoSystem;
027:
028: public class Subscription {
029:
030: protected static final int ClassVersionNumber = 6;
031:
032: public static final int TYPE_PERSONAL = 1;
033:
034: public static final int TYPE_ROLE = 2;
035:
036: public static final int TYPE_GROUP = 3;
037:
038: public static final int COLUMN_USER = 0;
039:
040: public static final int COLUMN_ID = 1;
041:
042: public static final int COLUMN_DESTINATION = 2;
043:
044: public static final int COLUMN_CONTENT_ID = 3;
045:
046: public static final int COLUMN_TITLE = 4;
047:
048: public static final int COLUMN_SOLUTION = 5;
049:
050: public static final int COLUMN_PATH = 6;
051:
052: public static final int COLUMN_ACTION = 7;
053:
054: private static final String baseHeaders[] = {
055: "user", "id", "destination", "contentid", "title", "solution", "path", "action" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
056:
057: private String id;
058:
059: private int type;
060:
061: private String user;
062:
063: private String title;
064:
065: private SubscribeContent content;
066:
067: private Map parameters;
068:
069: private List schedules;
070:
071: private String destination;
072:
073: private int revision = -1; // Hibernate Revision
074:
075: public static MemoryMetaData getMetadata(String parameterNames[]) {
076: Object columnHeaders[][] = new Object[1][];
077: String headerNames[] = new String[baseHeaders.length
078: + parameterNames.length];
079: for (int i = 0; i < baseHeaders.length; i++) {
080: headerNames[i] = baseHeaders[i];
081: }
082: int offset = baseHeaders.length;
083: for (int i = 0; i < parameterNames.length; i++) {
084: headerNames[offset + i] = parameterNames[i];
085: }
086: columnHeaders[0] = headerNames;
087: return new MemoryMetaData(columnHeaders, null);
088: }
089:
090: protected Subscription() {
091: // Needed for Hibernate to instantiate and set properties.
092: }
093:
094: public Subscription(String subscriptionId, String user,
095: String title, SubscribeContent content, String destination,
096: int type) {
097: this .user = user;
098: this .title = title;
099: this .content = content;
100: this .type = type;
101: this .destination = destination;
102: parameters = new HashMap();
103: schedules = new ArrayList();
104: id = subscriptionId;
105: }
106:
107: public Subscription(String subscriptionId, String user,
108: String title, SubscribeContent content, String destination,
109: int type, Map parameters) {
110: this .user = user;
111: this .title = title;
112: this .content = content;
113: this .type = type;
114: this .parameters = parameters;
115: this .destination = destination;
116: schedules = new ArrayList();
117: id = subscriptionId;
118: }
119:
120: public boolean equals(Object other) {
121: if (this == other) {
122: return true;
123: }
124: if (!(other instanceof Subscription)) {
125: return false;
126: }
127: final Subscription that = (Subscription) other;
128: return this .getId().equals(that.getId());
129: }
130:
131: public int hashCode() {
132: return getId().hashCode();
133: }
134:
135: /**
136: * @return Returns the revision.
137: */
138: public int getRevision() {
139: return revision;
140: }
141:
142: /**
143: * @param revision
144: * The revision to set. This is set by hibernate.
145: */
146: protected void setRevision(int revision) {
147: this .revision = revision;
148: }
149:
150: public void addSchedule(Schedule sched) {
151: schedules.add(sched);
152: }
153:
154: public List getSchedules() {
155: return schedules;
156: }
157:
158: public String getUser() {
159: return user;
160: }
161:
162: public String getTitle() {
163: return title;
164: }
165:
166: public String getDestination() {
167: return destination;
168: }
169:
170: public SubscribeContent getContent() {
171: return content;
172: }
173:
174: public Map getParameters() {
175: return parameters;
176: }
177:
178: public String getId() {
179: return id;
180: }
181:
182: protected void setId(String value) {
183: id = value;
184: }
185:
186: public int getType() {
187: return type;
188: }
189:
190: public Document asDocument() {
191: return null;
192: }
193:
194: public String asXml() {
195: return null;
196: }
197:
198: protected void setContent(SubscribeContent content) {
199: this .content = content;
200: }
201:
202: public void setDestination(String destination) {
203: this .destination = destination;
204: }
205:
206: protected void setParameters(Map parameters) {
207: this .parameters = parameters;
208: }
209:
210: protected void setSchedules(List schedules) {
211: this .schedules = schedules;
212: }
213:
214: public void setTitle(String title) {
215: this .title = title;
216: }
217:
218: protected void setType(int type) {
219: this .type = type;
220: }
221:
222: protected void setUser(String user) {
223: this .user = user;
224: }
225:
226: public Object[] toResultRow(String parameterNames[]) {
227: Object[] result = new Object[baseHeaders.length
228: + parameterNames.length];
229:
230: // expand the subscription into results
231: result[COLUMN_USER] = this .getUser();
232: result[COLUMN_ID] = this .getId();
233: result[COLUMN_DESTINATION] = this .getDestination();
234: result[COLUMN_CONTENT_ID] = this .getContent()
235: .getActionReference();
236: PentahoSystem.ActionInfo contentInfo = PentahoSystem
237: .parseActionString(this .getContent()
238: .getActionReference());
239: result[COLUMN_TITLE] = this .getTitle();
240: result[COLUMN_SOLUTION] = contentInfo.getSolutionName();
241: result[COLUMN_PATH] = contentInfo.getPath();
242: if (parameters != null) {
243: result[COLUMN_ACTION] = parameters.get("action"); //$NON-NLS-1$
244: if (result[COLUMN_ACTION] == null) {
245: result[COLUMN_ACTION] = contentInfo.getActionName();
246: }
247: } else {
248: result[COLUMN_ACTION] = contentInfo.getActionName();
249: }
250:
251: int offset = baseHeaders.length;
252: for (int i = 0; i < parameterNames.length; i++) {
253: result[offset + i] = parameters.get(parameterNames[i]);
254: }
255:
256: return result;
257:
258: }
259:
260: }
|