001/* 002 * (C) Copyright 2020 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 * Nour AL KOTOB 018 */ 019package org.nuxeo.ecm.restapi.server.jaxrs.management; 020 021import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED; 022import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 023 024import java.util.List; 025 026import javax.ws.rs.GET; 027import javax.ws.rs.POST; 028import javax.ws.rs.Path; 029import javax.ws.rs.PathParam; 030import javax.ws.rs.Produces; 031import javax.ws.rs.core.Response; 032 033import org.nuxeo.ecm.webengine.model.WebObject; 034import org.nuxeo.ecm.webengine.model.impl.AbstractResource; 035import org.nuxeo.ecm.webengine.model.impl.ResourceTypeImpl; 036import org.nuxeo.runtime.api.Framework; 037import org.nuxeo.runtime.migration.Migration; 038import org.nuxeo.runtime.migration.MigrationService; 039 040/** 041 * @since 11.3 042 */ 043@WebObject(type = ManagementObject.MANAGEMENT_OBJECT_PREFIX + "migration") 044@Produces(APPLICATION_JSON) 045public class MigrationObject extends AbstractResource<ResourceTypeImpl> { 046 047 @GET 048 @Path("{migrationId}") 049 public Migration doGet(@PathParam("migrationId") String migrationId) { 050 return Framework.getService(MigrationService.class).getMigration(migrationId); 051 } 052 053 @GET 054 public List<Migration> doGetList() { 055 return Framework.getService(MigrationService.class).getMigrations(); 056 } 057 058 @POST 059 @Path("{migrationId}/probe") 060 public Migration doProbe(@PathParam("migrationId") String migrationId) { 061 Framework.getService(MigrationService.class).probeAndSetState(migrationId); 062 return doGet(migrationId); 063 } 064 065 @POST 066 @Path("{migrationId}/run") 067 public Response doRun(@PathParam("migrationId") String migrationId) { 068 Framework.getService(MigrationService.class).probeAndRun(migrationId); 069 return Response.status(SC_ACCEPTED).build(); 070 } 071 072 @POST 073 @Path("{migrationId}/run/{stepId}") 074 public Response doRun(@PathParam("migrationId") String migrationId, @PathParam("stepId") String stepId) { 075 Framework.getService(MigrationService.class).runStep(migrationId, stepId); 076 return Response.status(SC_ACCEPTED).build(); 077 } 078 079}