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 * Salem Aouana 018 */ 019 020package org.nuxeo.ecm.restapi.server.jaxrs.management; 021 022import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 023 024import javax.servlet.http.HttpServletResponse; 025import javax.ws.rs.DELETE; 026import javax.ws.rs.Path; 027import javax.ws.rs.Produces; 028 029import org.nuxeo.ecm.core.api.NuxeoException; 030import org.nuxeo.ecm.core.blob.DocumentBlobManager; 031import org.nuxeo.ecm.core.blob.binary.BinaryManagerStatus; 032import org.nuxeo.ecm.webengine.model.WebObject; 033import org.nuxeo.ecm.webengine.model.impl.AbstractResource; 034import org.nuxeo.ecm.webengine.model.impl.ResourceTypeImpl; 035import org.nuxeo.runtime.api.Framework; 036 037/** 038 * Endpoint to manage the binaries. 039 * 040 * @since 11.3 041 */ 042@WebObject(type = ManagementObject.MANAGEMENT_OBJECT_PREFIX + "binaries") 043@Produces(APPLICATION_JSON) 044public class BinariesObject extends AbstractResource<ResourceTypeImpl> { 045 046 /** 047 * Garbage collect the unused (orphaned) binaries. 048 * 049 * @return {@link BinaryManagerStatus} if no gc is in progress, otherwise a 050 * {@link javax.ws.rs.core.Response.Status#CONFLICT} 051 */ 052 @DELETE 053 @Path("orphaned") 054 public BinaryManagerStatus garbageCollectBinaries() { 055 DocumentBlobManager documentBlobManager = Framework.getService(DocumentBlobManager.class); 056 057 if (documentBlobManager.isBinariesGarbageCollectionInProgress()) { 058 throw new NuxeoException(HttpServletResponse.SC_CONFLICT); 059 } 060 061 return documentBlobManager.garbageCollectBinaries(true); 062 } 063}