-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run Kitodo Script commands via Active MQ
- Loading branch information
1 parent
83b1b9f
commit 7fd387a
Showing
4 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Kitodo/src/main/java/org/kitodo/production/interfaces/activemq/KitodoScriptProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* (c) Kitodo. Key to digital objects e. V. <contact@kitodo.org> | ||
* | ||
* This file is part of the Kitodo project. | ||
* | ||
* It is licensed under GNU General Public License version 3 or later. | ||
* | ||
* For the full copyright and license information, please read the | ||
* GPL3-License.txt file that was distributed with this source code. | ||
*/ | ||
|
||
package org.kitodo.production.interfaces.activemq; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import javax.jms.JMSException; | ||
|
||
import org.kitodo.config.ConfigCore; | ||
import org.kitodo.config.enums.ParameterCore; | ||
import org.kitodo.data.database.beans.Process; | ||
import org.kitodo.data.database.exceptions.DAOException; | ||
import org.kitodo.data.exceptions.DataException; | ||
import org.kitodo.exceptions.InvalidImagesException; | ||
import org.kitodo.exceptions.MediaNotFoundException; | ||
import org.kitodo.exceptions.ProcessorException; | ||
import org.kitodo.production.services.ServiceManager; | ||
import org.kitodo.production.services.command.KitodoScriptService; | ||
import org.kitodo.production.services.data.ProcessService; | ||
|
||
/** | ||
* Executes instructions to start a Kitodo Script command from the Active MQ | ||
* interface. The MapMessage must contain the command statement in the | ||
* {@code script} argument. You pass a list of the process IDs as | ||
* {@code processes}. | ||
*/ | ||
public class KitodoScriptProcessor extends ActiveMQProcessor { | ||
|
||
private final KitodoScriptService kitodoScriptService = ServiceManager.getKitodoScriptService(); | ||
private final ProcessService processService = ServiceManager.getProcessService(); | ||
|
||
public KitodoScriptProcessor() { | ||
super(ConfigCore.getOptionalString(ParameterCore.ACTIVE_MQ_KITODO_SCRIPT_QUEUE).orElse(null)); | ||
} | ||
|
||
@Override | ||
protected void process(MapMessageObjectReader ticket) throws ProcessorException, JMSException { | ||
try { | ||
String script = ticket.getMandatoryString("script"); | ||
Collection<Integer> processIds = ticket.getCollectionOfInteger("processes"); | ||
List<Process> processes = new ArrayList<>(processIds.size()); | ||
for (Integer id : processIds) { | ||
processes.add(processService.getById(id)); | ||
} | ||
kitodoScriptService.execute(processes, script); | ||
} catch (DAOException | DataException | IOException | InvalidImagesException | MediaNotFoundException e) { | ||
throw new ProcessorException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters