001/* 002 * (C) Copyright 2019 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nour AL KOTOB 018 */ 019package org.nuxeo.ecm.restapi.server.jaxrs.management; 020 021import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND; 022import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 023 024import javax.ws.rs.GET; 025import javax.ws.rs.Path; 026import javax.ws.rs.PathParam; 027import javax.ws.rs.Produces; 028 029import org.nuxeo.ecm.core.api.NuxeoException; 030import org.nuxeo.ecm.core.bulk.BulkService; 031import org.nuxeo.ecm.core.bulk.message.BulkStatus; 032import org.nuxeo.ecm.core.bulk.message.BulkStatus.State; 033import org.nuxeo.ecm.webengine.model.WebObject; 034import org.nuxeo.ecm.webengine.model.impl.AbstractResource; 035import org.nuxeo.ecm.webengine.model.impl.ResourceTypeImpl; 036import org.nuxeo.runtime.api.Framework; 037 038/** 039 * @since 11.3 040 */ 041@WebObject(type = ManagementObject.MANAGEMENT_OBJECT_PREFIX + "bulk") 042@Produces(APPLICATION_JSON) 043public class BulkObject extends AbstractResource<ResourceTypeImpl> { 044 045 /** 046 * Gets the {@link BulkStatus} for the given {@code commandId}. 047 */ 048 @GET 049 @Path("{commandId}") 050 public BulkStatus doGetStatus(@PathParam("commandId") String commandId) { 051 BulkStatus status = Framework.getService(BulkService.class).getStatus(commandId); 052 if (status.getState() == State.UNKNOWN) { 053 // the command id doesn't exist 054 throw new NuxeoException("commandId doesn't exist: " + commandId, SC_NOT_FOUND); 055 } 056 return status; 057 } 058}