use of org.mycore.services.queuedjob.MCRJob in project mycore by MyCoRe-Org.
the class MCRPackerManagerTest method testPackerConfigurationStart.
@Test
public void testPackerConfigurationStart() throws Exception {
MCRConfiguration mcrConfiguration = MCRConfiguration.instance();
String testPackerPrefix = MCRPacker.PACKER_CONFIGURATION_PREFIX + TEST_PACKER_ID + ".";
Map<String, String> parameterMap = new Hashtable<>();
// add packer parameter
parameterMap.put("packer", TEST_PACKER_ID);
// add test parameter
parameterMap.put(MCRPackerMock.TEST_PARAMETER_KEY, MCRPackerMock.TEST_VALUE);
MCRJob packerJob = MCRPackerManager.startPacking(parameterMap);
Assert.assertNotNull("The Packer job is not present!", packerJob);
endTransaction();
Thread.sleep(1000);
startNewTransaction();
int waitTime = 10;
while (waitTime > 0 && !mcrConfiguration.getBoolean(MCRPackerMock.FINISHED_PROPERTY, false) && !mcrConfiguration.getBoolean(MCRPackerMock.SETUP_CHECKED_PROPERTY, false)) {
Thread.sleep(1000);
waitTime -= 1;
}
Assert.assertTrue("PackerJob did not finish in time!", waitTime > 0);
}
use of org.mycore.services.queuedjob.MCRJob in project mycore by MyCoRe-Org.
the class MCRPIJobRegistrationService method addDeleteJob.
/**
* @see #addRegisterJob(Map)
*/
protected void addDeleteJob(Map<String, String> contextParameters) {
MCRJob job = createJob(contextParameters, PiJobAction.DELETE);
REGISTER_JOB_QUEUE.offer(job);
}
use of org.mycore.services.queuedjob.MCRJob in project mycore by MyCoRe-Org.
the class MCRPackerManager method startPacking.
/**
* Creates and starts a new PackagingJob.
* <p>The rights you need to start a Packer depends on the implementation!</p>
* @param jobParameters the parameters which will be passed to the job. (Should include a packer)
* @return the created MCRJob
* @throws MCRUsageException if invalid parameters are passed to the packer
* @throws MCRAccessException if the current user doesn't have the rights to use the packer(on a specific object).
*/
public static MCRJob startPacking(Map<String, String> jobParameters) throws MCRUsageException, MCRAccessException {
String packer = jobParameters.get("packer");
if (packer == null) {
LOGGER.error("No Packer parameter found!");
return null;
}
checkPacker(packer, jobParameters);
MCRJob mcrJob = new MCRJob(MCRPackerJobAction.class);
mcrJob.setParameters(jobParameters);
if (!PACKER_JOB_QUEUE.offer(mcrJob)) {
throw new MCRException("Could not add Job to Queue!");
}
return mcrJob;
}
use of org.mycore.services.queuedjob.MCRJob in project mycore by MyCoRe-Org.
the class MCRPackerServlet method doGetPost.
@Override
protected void doGetPost(MCRServletJob job) throws IOException {
String packer = job.getRequest().getParameter("packer");
if (packer == null || packer.isEmpty()) {
try {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "No or invalid 'packer' parameter!");
} catch (IOException e) {
LOGGER.error("Error while sending request error to client!", e);
return;
}
}
Map<String, String> jobParameters = resolveJobParameters(job);
try {
MCRJob mcrJob = MCRPackerManager.startPacking(jobParameters);
if (mcrJob == null) {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "No packer parameter!");
}
} catch (MCRAccessException e) {
job.getResponse().sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
} catch (MCRUsageException e) {
job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Parameters: " + e.getMessage());
}
if (jobParameters.containsKey("redirect")) {
String redirect = jobParameters.get("redirect");
job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(redirect));
}
}
use of org.mycore.services.queuedjob.MCRJob in project mycore by MyCoRe-Org.
the class MCRPIJobRegistrationService method addRegisterJob.
/**
* Adds a register job which will be called in the persistent {@link MCRJob} environment in a extra thread.
* @param contextParameters pass parameters which are needed to register the PI. The parameter action and
* registrationServiceID will be added, because they are necessary to reassign the job to
* the right {@link MCRPIJobRegistrationService} and method.
*/
protected void addRegisterJob(Map<String, String> contextParameters) {
MCRJob job = createJob(contextParameters, PiJobAction.REGISTER);
REGISTER_JOB_QUEUE.offer(job);
}
Aggregations