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 Nov 13, 2005
014: * @author James Dixon
015: */
016:
017: package org.pentaho.plugin.core;
018:
019: import java.util.Iterator;
020: import java.util.List;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.dom4j.Node;
025: import org.pentaho.core.session.IPentahoSession;
026: import org.pentaho.plugin.ComponentBase;
027:
028: import org.pentaho.core.subscribe.SubscriptionResultSet;
029: import org.pentaho.core.system.PentahoSystem;
030: import com.pentaho.repository.subscribe.ISubscriptionRepository;
031:
032: public class SubscriptionBurstComponent extends ComponentBase {
033:
034: private static final long serialVersionUID = 3756619517873159809L;
035:
036: public Log getLogger() {
037: return LogFactory.getLog(SubscriptionBurstComponent.class);
038: }
039:
040: protected boolean validateSystemSettings() {
041: // This component does not have any system settings to validate
042: return true;
043: }
044:
045: protected boolean validateAction() {
046: // check that we will get a schedule id
047: if (!isDefinedInput("schedule-id")) { //$NON-NLS-1$
048: return false;
049: }
050:
051: // check that we get the name of the output
052: if (!isDefinedInput("output-name")) { //$NON-NLS-1$
053: return false;
054: }
055:
056: // check that we have an ouput to use
057: if (getOutputNames().size() == 0) {
058: return false;
059: }
060: return true;
061: }
062:
063: public void done() {
064: // nothing to do here
065:
066: }
067:
068: protected boolean executeAction() {
069:
070: String scheduleId = getInputStringValue("schedule-id"); //$NON-NLS-1$
071: if (scheduleId == null) {
072: return false;
073: }
074: String outputName = getInputStringValue("output-name"); //$NON-NLS-1$
075: if (outputName == null) {
076: return false;
077: }
078:
079: IPentahoSession userSession = getSession();
080: ISubscriptionRepository subscriptionRepository = PentahoSystem
081: .getSubscriptionRepository(userSession);
082:
083: List outputNodes = getComponentDefinition().selectNodes(
084: "outputs/output"); //$NON-NLS-1$
085: if (outputNodes != null) {
086: String parameterNames[] = new String[outputNodes.size()];
087: Iterator outputsIterator = outputNodes.iterator();
088: int index = 0;
089: while (outputsIterator.hasNext()) {
090: parameterNames[index] = ((Node) outputsIterator.next())
091: .getText();
092: index++;
093: }
094: String solution = getSolutionName();
095: String path = getSolutionPath();
096: String action = getActionName();
097: SubscriptionResultSet results = subscriptionRepository
098: .getSubscriptions(scheduleId, userSession,
099: solution, path, action, parameterNames);
100: setOutputValue(outputName, results);
101: }
102:
103: return true;
104: }
105:
106: public boolean init() {
107: return true;
108: }
109:
110: }
|