All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mycore.services.packaging.MCRPackerManager Maven / Gradle / Ivy

There is a newer version: 2024.05
Show newest version
/*
 * This file is part of ***  M y C o R e  ***
 * See http://www.mycore.de/ for details.
 *
 * MyCoRe is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MyCoRe is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MyCoRe.  If not, see .
 */

package org.mycore.services.packaging;

import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mycore.access.MCRAccessException;
import org.mycore.common.MCRException;
import org.mycore.common.MCRUsageException;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.services.queuedjob.MCRJob;
import org.mycore.services.queuedjob.MCRJobQueue;

/**
 * 

Used to pack packages in a specific format, using {@link MCRJobQueue}.

*

You have to define a packer id and assign a packer class which extends {@link MCRPacker}.

* * MCR.Packaging.Packer.MyPackerID.Class = org.mycore.packaging.MyPackerClass * *

*

You now have to pass properties required by the packer:

* * MCR.Packaging.Packer.MyPackerID.somePropertyForPacker = value * *

* * @author Sebastian Hofmann (mcrshofm) */ public class MCRPackerManager { private static final Logger LOGGER = LogManager.getLogger(); private static final MCRJobQueue PACKER_JOB_QUEUE = initializeJobQueue(); private static MCRJobQueue initializeJobQueue() { LOGGER.info("Initializing jobQueue for Packaging!"); return MCRJobQueue.getInstance(MCRPackerJobAction.class); } /** * Creates and starts a new PackagingJob. *

The rights you need to start a Packer depends on the implementation!

* @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 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; } private static void checkPacker(String packer, Map jobParameters) throws MCRUsageException, MCRAccessException { MCRPacker instance = MCRConfiguration2 .getOrThrow("MCR.Packaging.Packer." + packer + ".Class", MCRConfiguration2::instantiateClass); instance.setParameter(jobParameters); instance.setConfiguration(MCRPackerJobAction.getConfiguration(packer)); instance.checkSetup(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy