/** * C-Nery - A home automation web application for C-Bus. * Copyright (C) 2008,2009,2012 Dave Oxley <dave@daveoxley.co.uk>. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package com.daveoxley.cnery.webservice; import com.daveoxley.cbus.CGateSession; import com.daveoxley.cbus.Project; import com.daveoxley.cnery.Version; import com.daveoxley.cnery.scenes.GCMGroupListener; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import org.jboss.seam.Component; import org.jboss.seam.contexts.Contexts; import org.jboss.seam.util.Conversions; import org.jboss.seam.util.Conversions.PropertyValue; /** * * @author Dave Oxley <dave@daveoxley.co.uk> */ @WebService(serviceName = "Admin") public class Admin { @WebMethod(operationName = "getVersion") public String getVersion() { return Version.getVersionMini(); } @WebMethod(operationName = "listProjects") public String[] listProjects() { try{ CGateSession cGateSession = (CGateSession)Component.getInstance("cGateSession"); List<com.daveoxley.cbus.Project> _projects = com.daveoxley.cbus.Project.dir(cGateSession, false); Collections.sort(_projects); ArrayList<String> projects = new ArrayList<String>(); for (Project p : _projects) projects.add(p.getName()); return projects.toArray(new String[]{}); } catch (Exception e) { e.printStackTrace(); } return null; } @WebMethod(operationName = "getGCMSenderId") public String getGCMSenderId() { Map<String, Conversions.PropertyValue> properties = (Map<String, PropertyValue>)Contexts.getApplicationContext().get(Component.PROPERTIES); return properties.get("com.daveoxley.cnery.GOOGLE_GCM_SENDER_ID").getSingleValue(); } @WebMethod(operationName = "register") public Boolean register(@WebParam(name = "regId") String regId) { GCMGroupListener gcmListener = (GCMGroupListener)Component.getInstance("gcmGroupListener"); gcmListener.register(regId); return true; } @WebMethod(operationName = "unregister") public Boolean unregister(@WebParam(name = "regId") String regId) { GCMGroupListener gcmListener = (GCMGroupListener)Component.getInstance("gcmGroupListener"); gcmListener.unregister(regId); return true; } }