001/* 002 * (C) Copyright 2014 Nuxeo SA (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 * dmetzler 018 */ 019 020package org.nuxeo.ecm.restapi.server.jaxrs; 021 022import javax.ws.rs.Path; 023import javax.ws.rs.PathParam; 024import javax.ws.rs.Produces; 025 026import org.apache.commons.lang.StringUtils; 027import org.nuxeo.ecm.core.api.DocumentNotFoundException; 028import org.nuxeo.ecm.webengine.model.WebObject; 029import org.nuxeo.ecm.webengine.model.exceptions.WebResourceNotFoundException; 030import org.nuxeo.ecm.webengine.model.impl.ModuleRoot; 031 032/** 033 * The root entry for the WebEngine module. 034 * 035 * @since 5.7.2 036 */ 037@Path("/api/v1{repo : (/repo/[^/]+?)?}") 038@Produces("text/html;charset=UTF-8") 039@WebObject(type = "APIRoot") 040public class APIRoot extends ModuleRoot { 041 042 @Path("/") 043 public Object doGetRepository(@PathParam("repo") String repositoryParam) throws DocumentNotFoundException { 044 if (StringUtils.isNotBlank(repositoryParam)) { 045 String repoName = repositoryParam.substring("repo/".length() + 1); 046 try { 047 ctx.setRepositoryName(repoName); 048 } catch (IllegalArgumentException e) { 049 throw new WebResourceNotFoundException(e.getMessage()); 050 } 051 052 } 053 return newObject("repo"); 054 } 055 056 @Path("/user") 057 public Object doGetUser() { 058 return newObject("users"); 059 } 060 061 @Path("/group") 062 public Object doGetGroup() { 063 return newObject("groups"); 064 } 065 066 @Path("/automation") 067 public Object getAutomationEndPoint() { 068 return newObject("automation"); 069 } 070 071 @Path("/directory") 072 public Object doGetDirectory() { 073 return newObject("directory"); 074 } 075 076 @Path("/doc") 077 public Object doGetDocumentation() { 078 return newObject("doc"); 079 } 080 081 @Path("/query") 082 public Object doQuery() { 083 return newObject("query"); 084 } 085 086 @Path("/config") 087 public Object doGetConfig() { 088 return newObject("config"); 089 } 090 091 @Path("/conversion") 092 public Object doGetConversion() { 093 return newObject("conversions"); 094 } 095 096 /** 097 * @since 7.2 098 */ 099 @Path("/ext/{otherPath}") 100 public Object route(@PathParam("otherPath") String otherPath) { 101 return newObject(otherPath); 102 } 103}