001/*
002 * (C) Copyright 2014-2018 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 *     dmetzler
018 */
019
020package org.nuxeo.ecm.restapi.server.jaxrs;
021
022import java.util.List;
023
024import javax.ws.rs.MatrixParam;
025import javax.ws.rs.Path;
026import javax.ws.rs.PathParam;
027import javax.ws.rs.Produces;
028
029import org.apache.commons.lang3.StringUtils;
030import org.nuxeo.ecm.core.api.DocumentNotFoundException;
031import org.nuxeo.ecm.webengine.model.WebObject;
032import org.nuxeo.ecm.webengine.model.exceptions.WebResourceNotFoundException;
033import org.nuxeo.ecm.webengine.model.impl.ModuleRoot;
034
035/**
036 * The root entry for the WebEngine module.
037 *
038 * @since 5.7.2
039 */
040@Path("/api/v1{repo : (/repo/[^/]+?)?}")
041@Produces("text/html;charset=UTF-8")
042@WebObject(type = "APIRoot")
043public class APIRoot extends ModuleRoot {
044
045    @Path("/")
046    public Object doGetRepository(@PathParam("repo") String repositoryParam) throws DocumentNotFoundException {
047        if (StringUtils.isNotBlank(repositoryParam)) {
048            String repoName = repositoryParam.substring("repo/".length() + 1);
049            try {
050                ctx.setRepositoryName(repoName);
051            } catch (IllegalArgumentException e) {
052                throw new WebResourceNotFoundException(e.getMessage());
053            }
054
055        }
056        return newObject("repo");
057    }
058
059    @Path("/user")
060    public Object doGetUser() {
061        return newObject("users");
062    }
063
064    @Path("/group")
065    public Object doGetGroup() {
066        return newObject("groups");
067    }
068
069    @Path("/automation")
070    public Object getAutomationEndPoint() {
071        return newObject("automation");
072    }
073
074    @Path("/directory")
075    public Object doGetDirectory() {
076        return newObject("directory");
077    }
078
079    @Path("/doc")
080    public Object doGetDocumentation() {
081        return newObject("doc");
082    }
083
084    @Path("/query")
085    public Object doQuery() {
086        return newObject("query");
087    }
088
089    @Path("/config")
090    public Object doGetConfig() {
091        return newObject("config");
092    }
093
094    @Path("/conversion")
095    public Object doGetConversion() {
096        return newObject("conversions");
097    }
098
099    /**
100     * @since 10.3
101     */
102    @Path("/bulk")
103    @SuppressWarnings("deprecation")
104    // we need to handle ids matrix because matrix aren't present in path used for dispatch
105    public Object bulk(@MatrixParam("id") List<String> ids) {
106        if (ids.isEmpty()) {
107            return newObject("bulkActionFramework");
108        } else {
109            return RepositoryObject.getBulkDocuments(this, ids);
110        }
111    }
112
113    /**
114     * @since 7.2
115     */
116    @Path("/ext/{otherPath}")
117    public Object route(@PathParam("otherPath") String otherPath) {
118        return newObject(otherPath);
119    }
120}