001/* 002 * (C) Copyright 2010 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 * mcedica 018 */ 019package org.nuxeo.ecm.webengine.management.statuses; 020 021import javax.ws.rs.GET; 022import javax.ws.rs.PUT; 023import javax.ws.rs.Path; 024 025import org.nuxeo.ecm.core.management.api.ProbeInfo; 026import org.nuxeo.ecm.core.management.api.ProbeManager; 027import org.nuxeo.ecm.webengine.model.WebObject; 028import org.nuxeo.ecm.webengine.model.impl.DefaultObject; 029import org.nuxeo.runtime.api.Framework; 030 031/** 032 * List and execute a probe 033 * 034 * @author matic 035 */ 036@WebObject(type = "Probe") 037public class ProbeObject extends DefaultObject { 038 039 private ProbeInfo info; 040 041 public static ProbeObject newProbe(DefaultObject parent, ProbeInfo info) { 042 return (ProbeObject) parent.newObject("Probe", info); 043 } 044 045 @Override 046 protected void initialize(Object... args) { 047 assert args != null && args.length == 1; 048 info = (ProbeInfo) args[0]; 049 } 050 051 @GET 052 public Object doGet() { 053 return getView("index"); 054 } 055 056 @PUT 057 public Object doPut() { 058 return doRun(); 059 } 060 061 /** 062 * For easier invocation using links. 063 */ 064 @GET 065 @Path("/@run") 066 public Object doRun() { 067 ProbeManager probeMgr = Framework.getLocalService(ProbeManager.class); 068 probeMgr.runProbe(info); 069 return redirect(getPath()); 070 } 071 072 public ProbeInfo getInfo() { 073 return info; 074 } 075 076}