01: /*
02: * Copyright 2005 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11: * the license for the specific language governing your rights and limitations.
12: *
13: * @created Nov 1, 2005
14: * @author James Dixon
15: */
16:
17: package org.pentaho.core.subscribe;
18:
19: import org.pentaho.commons.connection.memory.MemoryResultSet;
20: import org.pentaho.core.session.IPentahoSession;
21:
22: import org.pentaho.core.system.PentahoSystem;
23: import com.pentaho.repository.subscribe.ISubscriptionRepository;
24: import com.pentaho.repository.subscribe.SubscribeContent;
25: import com.pentaho.repository.subscribe.Subscription;
26:
27: public class SubscriptionResultSet extends MemoryResultSet {
28:
29: IPentahoSession userSession;
30:
31: ISubscriptionRepository subscriptionRepository;
32:
33: String parameterNames[];
34:
35: String actionRef = null;
36:
37: public SubscriptionResultSet(String scheduleId,
38: IPentahoSession userSession, String parameterNames[],
39: String solution, String path, String action) {
40:
41: this .userSession = userSession;
42: this .parameterNames = parameterNames;
43: if (solution != null && path != null && action != null) {
44: actionRef = solution + "/" + path + "/" + action; //$NON-NLS-1$ //$NON-NLS-2$
45: }
46: setMetaData(Subscription.getMetadata(parameterNames));
47: subscriptionRepository = PentahoSystem
48: .getSubscriptionRepository(userSession);
49:
50: setRows(subscriptionRepository
51: .getSubscriptionsForSchedule(scheduleId));
52: }
53:
54: public Object[] next() {
55:
56: if (iterator == null) {
57: iterator = rows.iterator();
58: }
59: while (iterator.hasNext()) {
60: Subscription subscr = (Subscription) iterator.next();
61: if (actionRef != null) {
62: SubscribeContent content = subscr.getContent();
63: if (isBursterFor(actionRef, content
64: .getActionReference())) {
65: return subscr.toResultRow(parameterNames);
66: } else {
67: continue;
68: }
69: } else {
70: return subscr.toResultRow(parameterNames);
71: }
72: }
73: return null;
74: }
75:
76: private boolean isBursterFor(String bursterRef, String contentRef) {
77: try {
78: contentRef = contentRef.substring(contentRef
79: .lastIndexOf('/'), contentRef
80: .lastIndexOf(".xaction")); //$NON-NLS-1$
81: bursterRef = bursterRef.substring(bursterRef
82: .lastIndexOf('/'), bursterRef
83: .lastIndexOf("Burst.xaction")); //$NON-NLS-1$
84: return (bursterRef.equals(contentRef));
85: } catch (Throwable t) {
86: // if this blows up the compare would have falied anyway
87: }
88: return (false);
89: }
90:
91: public Object getValueAt(int row, int column) {
92: Object[] theRow = (Object[]) rows.get(row);
93: return theRow[column];
94: }
95:
96: }
|