use of org.opencastproject.mediapackage.MediaPackageElement.Type in project opencast by opencast.
the class ExecuteServiceImpl method process.
/**
* {@inheritDoc}
*
* @throws ExecuteException
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(Job job) throws ExecuteException {
List<String> arguments = new ArrayList<String>(job.getArguments());
// Check this operation is allowed
if (!allowedCommands.contains("*") && !allowedCommands.contains(arguments.get(0)))
throw new ExecuteException("Command '" + arguments.get(0) + "' is not allowed");
String outFileName = null;
String strAux = null;
MediaPackage mp = null;
Type expectedType = null;
MediaPackageElement element = null;
Operation op = null;
try {
op = Operation.valueOf(job.getOperation());
int nargs = arguments.size();
if (nargs != 3 && nargs != 5) {
throw new IndexOutOfBoundsException("Incorrect number of parameters for operation execute_" + op + ": " + arguments.size());
}
if (nargs == 5) {
strAux = arguments.remove(4);
expectedType = (strAux == null) ? null : Type.valueOf(strAux);
outFileName = StringUtils.trimToNull(arguments.remove(3));
if ((StringUtils.isNotBlank(outFileName) && (expectedType == null)) || (StringUtils.isBlank(outFileName) && (expectedType != null))) {
throw new ExecuteException("The output type and filename must be both specified");
}
outFileName = (outFileName == null) ? null : job.getId() + "_" + outFileName;
}
switch(op) {
case Execute_Mediapackage:
mp = MediaPackageParser.getFromXml(arguments.remove(2));
return doProcess(arguments, mp, outFileName, expectedType);
case Execute_Element:
element = MediaPackageElementParser.getFromXml(arguments.remove(2));
return doProcess(arguments, element, outFileName, expectedType);
default:
throw new IllegalStateException("Don't know how to handle operation '" + job.getOperation() + "'");
}
} catch (MediaPackageException e) {
throw new ExecuteException("Error unmarshalling the input mediapackage/element", e);
} catch (IllegalArgumentException e) {
throw new ExecuteException("This service can't handle operations of type '" + op + "'", e);
} catch (IndexOutOfBoundsException e) {
throw new ExecuteException("The argument list for operation '" + op + "' does not meet expectations", e);
}
}
Aggregations