001/* 002 * (C) Copyright 2017 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 * Antoine Taillefer <[email protected]> 018 */ 019package org.nuxeo.ecm.restapi.server.jaxrs.drive; 020 021import java.io.File; 022 023import javax.ws.rs.GET; 024import javax.ws.rs.Path; 025import javax.ws.rs.Produces; 026import javax.ws.rs.core.MediaType; 027import javax.ws.rs.core.Response; 028 029import org.nuxeo.common.Environment; 030import org.nuxeo.ecm.webengine.model.WebObject; 031import org.nuxeo.ecm.webengine.model.exceptions.WebResourceNotFoundException; 032import org.nuxeo.ecm.webengine.model.impl.DefaultObject; 033 034/** 035 * @since 9.10 036 */ 037@WebObject(type = "drive") 038@Produces(MediaType.APPLICATION_JSON) 039public class NuxeoDriveObject extends DefaultObject { 040 041 public static final String NUXEO_DRIVE_CONFIGURATION_FILE = "nuxeo-drive-config.json"; 042 043 /** 044 * Retrieves the Nuxeo Drive global configuration. 045 * 046 * @implNote The configuration file is expected to be in the server's configuration folder, copied from the 047 * {@code drive} template. 048 */ 049 @GET 050 @Path("configuration") 051 public Response getConfiguration() { 052 File configurationFolder = Environment.getDefault().getConfig(); 053 File configurationFile = new File(configurationFolder, NUXEO_DRIVE_CONFIGURATION_FILE); 054 if (!configurationFile.exists()) { 055 throw new WebResourceNotFoundException("Nuxeo Drive configuration file not found."); 056 } 057 return Response.ok().entity(configurationFile).type(MediaType.APPLICATION_JSON).build(); 058 } 059 060}