001/* 002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * mcedica 016 */ 017package org.nuxeo.ecm.webengine.management.statuses; 018 019import javax.ws.rs.GET; 020import javax.ws.rs.PUT; 021import javax.ws.rs.Path; 022 023import org.nuxeo.ecm.core.management.api.ProbeInfo; 024import org.nuxeo.ecm.core.management.api.ProbeManager; 025import org.nuxeo.ecm.webengine.model.WebObject; 026import org.nuxeo.ecm.webengine.model.impl.DefaultObject; 027import org.nuxeo.runtime.api.Framework; 028 029/** 030 * List and execute a probe 031 * 032 * @author matic 033 */ 034@WebObject(type = "Probe") 035public class ProbeObject extends DefaultObject { 036 037 private ProbeInfo info; 038 039 public static ProbeObject newProbe(DefaultObject parent, ProbeInfo info) { 040 return (ProbeObject) parent.newObject("Probe", info); 041 } 042 043 @Override 044 protected void initialize(Object... args) { 045 assert args != null && args.length == 1; 046 info = (ProbeInfo) args[0]; 047 } 048 049 @GET 050 public Object doGet() { 051 return getView("index"); 052 } 053 054 @PUT 055 public Object doPut() { 056 return doRun(); 057 } 058 059 /** 060 * For easier invocation using links. 061 */ 062 @GET 063 @Path("/@run") 064 public Object doRun() { 065 ProbeManager probeMgr = Framework.getLocalService(ProbeManager.class); 066 probeMgr.runProbe(info); 067 return redirect(getPath()); 068 } 069 070 public ProbeInfo getInfo() { 071 return info; 072 } 073 074}