}
private List<GWTJahiaJobDetail> convertToGWTJobs(List<JobDetail> jobDetails, Locale locale, JahiaUser jahiaUser) {
List<GWTJahiaJobDetail> jobs = new ArrayList<GWTJahiaJobDetail>();
for (JobDetail jobDetail : jobDetails) {
JobDataMap jobDataMap = jobDetail.getJobDataMap();
Date created = (Date) jobDataMap.get(BackgroundJob.JOB_CREATED);
final String status = jobDataMap.getString(BackgroundJob.JOB_STATUS);
final String user = StringUtils.substringAfter(jobDataMap.getString(BackgroundJob.JOB_USERKEY), "}");
final String message = jobDataMap.getString(BackgroundJob.JOB_MESSAGE);
final Long beginTime = getLong(jobDataMap, BackgroundJob.JOB_BEGIN);
final Long endTime = getLong(jobDataMap, BackgroundJob.JOB_END);
if (created == null && beginTime != null) {
// this can happen for cron scheduler jobs.
created = new Date(beginTime);
}
Long duration = getLong(jobDataMap, BackgroundJob.JOB_DURATION);
if ((duration == null) && (beginTime != null) && (endTime == null) && BackgroundJob.STATUS_EXECUTING.equals(status)) {
// here we have a currently running job, let's calculate the duration until now.
duration = System.currentTimeMillis() - beginTime.longValue();
}
final String jobLocale = jobDataMap.getString(BackgroundJob.JOB_CURRENT_LOCALE);
String targetNodeIdentifier = null;
String targetAction = null;
String targetWorkspace = null;
// if ((jahiaUser != null) && (!jahiaUser.getUserKey().equals(user))) {
// we must check whether the user has the permission to view other users's jobs
// if (!jahiaUser.isPermitted(new PermissionIdentity("view-all-jobs"))) {
// // he doesn't we skip this entry.
// continue;
// }
// }
String description = jobDetail.getDescription();
final List<String> targetPaths = new ArrayList<String>();
String fileName = jobDataMap.getString(ImportJob.FILENAME);
if (BackgroundJob.getGroupName(PublicationJob.class).equals(jobDetail.getGroup())) {
@SuppressWarnings("unchecked")
List<GWTJahiaNodeProperty> publicationInfos = (List<GWTJahiaNodeProperty>) jobDataMap.get(PublicationJob.PUBLICATION_PROPERTIES);
if (publicationInfos != null && publicationInfos.size() > 0) {
description += " " + publicationInfos.get(0).getValues();
}
} else if (BackgroundJob.getGroupName(ImportJob.class).equals(jobDetail.getGroup())) {
String uri = (String) jobDataMap.get(ImportJob.URI);
if (uri != null) {
targetPaths.add(uri);
description += " " + uri;
} else {
String destinationParentPath = jobDataMap.getString(ImportJob.DESTINATION_PARENT_PATH);
targetPaths.add(destinationParentPath);
}
} else if (BackgroundJob.getGroupName(ActionJob.class).equals(jobDetail.getGroup())) {
String actionToExecute = jobDataMap.getString(ActionJob.JOB_ACTION_TO_EXECUTE);
targetAction = actionToExecute;
String nodeUUID = jobDataMap.getString(ActionJob.JOB_NODE_UUID);
targetNodeIdentifier = nodeUUID;
} else if (BackgroundJob.getGroupName(RuleJob.class).equals(jobDetail.getGroup())) {
String ruleToExecute = jobDataMap.getString(RuleJob.JOB_RULE_TO_EXECUTE);
targetAction = ruleToExecute;
String nodeUUID = jobDataMap.getString(RuleJob.JOB_NODE_UUID);
targetNodeIdentifier = nodeUUID;
String workspace = jobDataMap.getString(RuleJob.JOB_WORKSPACE);
targetWorkspace = workspace;
} else if (BackgroundJob.getGroupName(TextExtractorJob.class).equals(jobDetail.getGroup())) {
String path = jobDataMap.getString(TextExtractorJob.JOB_PATH);
String extractNodePath = jobDataMap.getString(TextExtractorJob.JOB_EXTRACTNODE_PATH);
targetPaths.add(path);
targetPaths.add(extractNodePath);
}
GWTJahiaJobDetail job = new GWTJahiaJobDetail(jobDetail.getName(), created, user, description,
status, message, targetPaths,