UserFilesComponent.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.pentaho.ui.component |
![]() |
![]() |
Pentaho |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* Copyright 2006 Pentaho Corporation. All rights reserved.
* This software was developed by Pentaho Corporation and is provided under the terms
* of the Mozilla Public License, Version 1.1, or any later version. You may not use
* this file except in compliance with the license. If you need a copy of the license,
* please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
* BI Platform. The Initial Developer is Pentaho Corporation.
*
* Software distributed under the Mozilla Public License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
* the license for the specific language governing your rights and limitations.
*
* @created Aug 18, 2005
* @author James Dixon
*/
package org.pentaho.ui.component;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.pentaho.core.repository.IContentItem;
import org.pentaho.core.repository.ISolutionRepository;
import org.pentaho.core.runtime.IBackgroundExecution;
import org.pentaho.core.session.IPentahoSession;
import org.pentaho.core.solution.HttpRequestParameterProvider;
import org.pentaho.core.solution.IActionSequence;
import org.pentaho.core.solution.SimpleParameterProvider;
import org.pentaho.core.system.PentahoSystem;
import org.pentaho.core.ui.IPentahoUrlFactory;
import org.pentaho.messages.Messages;
import org.pentaho.plugin.quartz.QuartzSystemListener;
import org.pentaho.ui.XmlComponent;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import com.pentaho.repository.subscribe.ISubscriptionRepository;
import com.pentaho.repository.subscribe.Subscription;
public class UserFilesComponent extends XmlComponent {
/**
*
*/
private static final long serialVersionUID = -7404173000559758744L;
protected final static String FILE = "file"; //$NON-NLS-1$
protected final static String NAME = "name"; //$NON-NLS-1$
protected final static String TIMESTAMP = "timestamp"; //$NON-NLS-1$
protected final static String ACTIONS = "actions"; //$NON-NLS-1$
protected final static String ACTION = "action"; //$NON-NLS-1$
protected final static String TITLE = "title"; //$NON-NLS-1$
protected final static String PARAMS = "params"; //$NON-NLS-1$
protected final static String PARAM = "param"; //$NON-NLS-1$
protected final static String PARAM_NAME = "param-name"; //$NON-NLS-1$
protected final static String PARAM_VALUE = "param-value"; //$NON-NLS-1$
protected final static String USER_FILES = "user-files"; //$NON-NLS-1$
protected final static String MIMETYPE = "mimetype"; //$NON-NLS-1$
protected final static String SIZE = "size"; //$NON-NLS-1$
protected HttpServletRequest request;
protected HttpServletResponse response;
private static final Log logger = LogFactory.getLog(UserFilesComponent.class);
public Log getLogger() {
return logger;
}
public UserFilesComponent() {
super(null, null, null);
setXsl("text/html", "UserFiles.xsl"); //$NON-NLS-1$ //$NON-NLS-2$
}
public UserFilesComponent(IPentahoUrlFactory urlFactory, HttpServletRequest request, HttpServletResponse response,
List messages) {
super(urlFactory, messages, null);
this.request = request;
this.response = response;
setXsl("text/html", "UserFiles.xsl"); //$NON-NLS-1$ //$NON-NLS-2$
}
public void setRequest(HttpServletRequest request) {
this.request = request;
}
public void setResponse(HttpServletResponse response) {
this.response = response;
}
public boolean validate() {
return true;
}
public Document getXmlContent() {
Document result = DocumentHelper.createDocument();
Element root = result.addElement(USER_FILES);
addFiles(root);
return result;
}
protected void addFiles(Element root) {
addScheduledAndExecuting(root);
addExecutedlist(root);
addSubscriptions(root);
}
protected void addScheduledAndExecuting(Element root) {
Element jobs = root.addElement("scheduled"); //$NON-NLS-1$
IPentahoSession session = getSession();
IBackgroundExecution backgroundExecution = PentahoSystem.getBackgroundExecutionHandler(session);
List jobsList = null;
if (backgroundExecution != null) {
jobsList = backgroundExecution.getScheduledAndExecutingBackgroundJobs(session);
} else {
jobsList = new ArrayList();
Element errorRoot = root.addElement("error"); //$NON-NLS-1$
errorRoot
.addElement("error-message").setText(Messages.getErrorString("UI.USER_ERROR_0003_NO_BACKGROUND_EXECUTION")); //$NON-NLS-1$//$NON-NLS-2$
}
if (jobsList != null && jobsList.size() > 0) {
for (int i = 0; i < jobsList.size(); i++) {
Element job = jobs.addElement(FILE);
JobDetail jobDetail = (JobDetail) jobsList.get(i);
JobDataMap jobDataMap = jobDetail.getJobDataMap();
job.addElement(NAME).setText(jobDataMap.getString(IBackgroundExecution.BACKGROUND_ACTION_NAME_STR));
job.addElement(TIMESTAMP).setText(jobDataMap.getString(IBackgroundExecution.BACKGROUND_SUBMITTED));
Element actions = job.addElement(ACTIONS);
Element action = actions.addElement(ACTION);
action.addElement(TITLE).setText(Messages.getString("UI.USER_CANCEL")); //$NON-NLS-1$
Element params = action.addElement(PARAMS);
Element param = params.addElement(PARAM);
param.addElement(PARAM_NAME).setText("del-job-name"); //$NON-NLS-1$
param.addElement(PARAM_VALUE).setText(jobDetail.getName());
param = params.addElement(PARAM);
param.addElement(PARAM_NAME).setText("del-job-group"); //$NON-NLS-1$
param.addElement(PARAM_VALUE).setText(jobDetail.getGroup());
param = params.addElement(PARAM);
param.addElement(PARAM_NAME).setText("action"); //$NON-NLS-1$
param.addElement(PARAM_VALUE).setText("cancel-job"); //$NON-NLS-1$
}
}
}
protected void addExecutedlist(Element root) {
Element jobs = root.addElement("executed"); //$NON-NLS-1$
IPentahoSession session = getSession();
IBackgroundExecution backgroundExecution = PentahoSystem.getBackgroundExecutionHandler(session);
List pastExecutionList = null;
if (backgroundExecution != null) {
pastExecutionList = backgroundExecution.getBackgroundExecutedContentList(session);
} else {
pastExecutionList = new ArrayList();
}
SimpleDateFormat fmt = new SimpleDateFormat();
for (int i = 0; i < pastExecutionList.size(); i++) {
IContentItem item = (IContentItem) pastExecutionList.get(i);
Element job = jobs.addElement(FILE);
job.addElement(NAME).setText(item.getTitle());
String dateStr = ""; //$NON-NLS-1$
Date time = item.getFileDateTime();
if (time != null) {
dateStr = fmt.format(time);
}
job.addElement(TIMESTAMP).setText(dateStr);
job.addElement(MIMETYPE).setText(item.getMimeType());
job.addElement(SIZE).setText(Long.toString(item.getFileSize()));
Element actions = job.addElement(ACTIONS);
Element action = actions.addElement(ACTION);
action.addElement(TITLE).setText(Messages.getString("UI.USER_VIEW")); //$NON-NLS-1$
Element params = action.addElement(PARAMS);
Element param = params.addElement(PARAM);
param.addElement(PARAM_NAME).setText("action"); //$NON-NLS-1$
param.addElement(PARAM_VALUE).setText("view"); //$NON-NLS-1$
param = params.addElement(PARAM);
param.addElement(PARAM_NAME).setText("id"); //$NON-NLS-1$
param.addElement(PARAM_VALUE).setText(item.getId());
action = actions.addElement(ACTION);
action.addElement(TITLE).setText(Messages.getString("UI.USER_DELETE")); //$NON-NLS-1$
params = action.addElement(PARAMS);
param = params.addElement(PARAM);
param.addElement(PARAM_NAME).setText("action"); //$NON-NLS-1$
param.addElement(PARAM_VALUE).setText("delete"); //$NON-NLS-1$
param = params.addElement(PARAM);
param.addElement(PARAM_NAME).setText("content-id"); //$NON-NLS-1$
param.addElement(PARAM_VALUE).setText(item.getId());
}
}
public boolean cancelJob(String jobName, String jobGroup) {
try {
Scheduler sched = QuartzSystemListener.getSchedulerInstance();
sched.deleteJob(jobName, jobGroup);
return true;
} catch (Throwable t) {
error(Messages.getErrorString("Scheduler.ERROR_0001_SCHEDULER_CANNOT_CANCEL", t.getMessage()), t); //$NON-NLS-1$
}
return false;
}
public boolean deleteContent(String contentId) {
try {
IPentahoSession session = getSession();
IBackgroundExecution backgroundExecution = PentahoSystem.getBackgroundExecutionHandler(session);
if (backgroundExecution != null) {
backgroundExecution.removeBackgroundExecutedContentForID(contentId, session);
return true;
} else {
return false;
}
} catch (Throwable t) {
error(Messages.getErrorString("Scheduler.ERROR_0001_SCHEDULER_CANNOT_CANCEL", t.getMessage()), t); //$NON-NLS-1$
}
return false;
}
protected void addSubscriptions(Element root) {
SubscriptionAdminUIComponent admin = null;
try {
admin = new SubscriptionAdminUIComponent(urlFactory, getMessages()); //$NON-NLS-1
// admin.setLoggingLevel( admin.DEBUG );
admin.validate(getSession(), null);
SimpleParameterProvider params = new SimpleParameterProvider();
admin.setParameterProvider(HttpRequestParameterProvider.SCOPE_REQUEST, params);
params.setParameter(SubscriptionAdminUIComponent.SCHEDULER_ACTION,
SubscriptionAdminUIComponent.ACTION_SUBSCRIPTION_SHOW_LIST);
params.setParameter("user", getSession().getName()); //$NON-NLS-1$
Document doc = admin.getXmlContent();
List subscriptionList = doc.selectNodes("listSubscriptions/subscriptions/subscription"); //$NON-NLS-1$
if (subscriptionList != null) {
ISubscriptionRepository subscriptionRepository = PentahoSystem.getSubscriptionRepository(getSession());
Iterator it = subscriptionList.iterator();
while (it.hasNext()) {
Element node = (Element) it.next();
String actionRef = node.selectSingleNode("actionRef").getText(); //$NON-NLS-1$
ISolutionRepository repo = PentahoSystem.getSolutionRepository(getSession());
PentahoSystem.ActionInfo actionInfo = PentahoSystem.parseActionString(actionRef);
IActionSequence action = repo.getActionSequence(actionInfo.getSolutionName(), actionInfo.getPath(),
actionInfo.getActionName(), repo.getLoggingLevel(), ISolutionRepository.ACTION_EXECUTE);
String actionTitle = action.getTitle();
node.addElement("action-title").setText(actionTitle); //$NON-NLS-1$
if (subscriptionRepository != null) {
try {
Subscription subscription = subscriptionRepository.getSubscription(node.selectSingleNode(
"@subscriptionId").getText(), getSession()); //$NON-NLS-1$
subscriptionRepository.addSubscriptionToDocument(subscription, node, null, getSession());
// subscriptionRepository.addSubscriptionsToDocument(getSession().getName(), actionRef, node, null, getSession());
} catch (Throwable t) {
error(Messages.getErrorString("PRO_SUBSCRIPTREP.ERROR_0005_GENERAL_ERROR"), t); //$NON-NLS-1$
}
}
}
}
Element subsRoot = doc.getRootElement();
subsRoot.detach();
root.add(subsRoot);
} catch (Exception e) {
error(Messages.getErrorString("PRO_SUBSCRIPTREP.ERROR_0005_GENERAL_ERROR"), e); //$NON-NLS-1$
}
}
}
The table below shows all metrics for UserFilesComponent.java.




