001/*
002 * (C) Copyright 2006-2012 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 *     Nuxeo - initial API and implementation
018 *
019 */
020package org.nuxeo.connect.client.we;
021
022import javax.ws.rs.GET;
023import javax.ws.rs.Path;
024import javax.ws.rs.PathParam;
025import javax.ws.rs.Produces;
026import javax.ws.rs.QueryParam;
027
028import org.apache.commons.logging.Log;
029import org.apache.commons.logging.LogFactory;
030import org.nuxeo.connect.update.Package;
031import org.nuxeo.connect.update.PackageException;
032import org.nuxeo.connect.update.PackageUpdateService;
033import org.nuxeo.ecm.webengine.model.WebObject;
034import org.nuxeo.ecm.webengine.model.impl.DefaultObject;
035import org.nuxeo.runtime.api.Framework;
036
037/**
038 * Provides REST bindings for {@link Package} removal.
039 *
040 * @author <a href="mailto:tm@nuxeo.com">Thierry Martins</a>
041 */
042@WebObject(type = "removeHandler")
043public class RemoveHandler extends DefaultObject {
044
045    protected static final Log log = LogFactory.getLog(RemoveHandler.class);
046
047    @GET
048    @Produces("text/html")
049    @Path(value = "start/{pkgId}")
050    public Object startInstall(@PathParam("pkgId") String pkgId, @QueryParam("source") String source) {
051        try {
052            PackageUpdateService pus = Framework.getLocalService(PackageUpdateService.class);
053            pus.removePackage(pkgId);
054            return getView("removeDone").arg("pkgId", pkgId).arg("source", source);
055        } catch (PackageException e) {
056            log.error("Error during first step of installation", e);
057            return getView("removeError").arg("e", e);
058        }
059    }
060
061}