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

org.daisy.pipeline.webservice.impl.JobBatchResource Maven / Gradle / Ivy

There is a newer version: 3.6.0
Show newest version
package org.daisy.pipeline.webservice.impl;

import org.daisy.pipeline.job.Job;
import org.daisy.pipeline.job.JobBatchId;
import org.daisy.pipeline.job.JobIdFactory;
import org.daisy.pipeline.job.JobManager;
import org.daisy.pipeline.webserviceutils.xml.JobsXmlWriter;
import org.daisy.pipeline.webserviceutils.xml.XmlWriterFactory;
import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.ext.xml.DomRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.Delete;
import org.restlet.resource.Get;
import org.w3c.dom.Document;

public class JobBatchResource extends JobsResource{
        JobBatchId batchId;
        @Override
        public void doInit() {
                super.doInit();
                String idParam = (String) getRequestAttributes().get("id");
                this.batchId=JobIdFactory.newBatchIdFromString(idParam);
        }

        /**
         * Gets the resource.
         *
         * @return the resource
         */
        @Get("xml")
        public Representation getResource() {
                if (!isAuthenticated()) {
                        setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
                        return null;
                }
                JobManager jobMan = webservice().getJobManager(this.getClient(),this.batchId);
                JobsXmlWriter writer = XmlWriterFactory.createXmlWriterForJobs(jobMan.getJobs());
                if(this.webservice().getConfiguration().isLocalFS()){
                	writer.withLocalPaths();
                }
                Document doc = writer.getXmlDocument();
                DomRepresentation dom = new DomRepresentation(MediaType.APPLICATION_XML, doc);
                setStatus(Status.SUCCESS_OK);
                return dom;
        }
        @Delete
        public void deleteResource() {
                if (!isAuthenticated()) {
                        setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
                        return;
                }

                if (batchId == null) {
                        setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                        return;

                } 
                JobManager jobMan = webservice().getJobManager(this.getClient(),this.batchId);
                for ( Job j: jobMan.deleteAll()) {
                        webservice().getStorage().
                                getJobConfigurationStorage().delete(j.getId());
                } 
                setStatus(Status.SUCCESS_NO_CONTENT);
        }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy