001/** 002 * Copyright 2014 Tampere University of Technology, Pori Department 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 */ 016package service.tut.pori.cawebsocket; 017 018import org.apache.log4j.Logger; 019 020import core.tut.pori.users.UserIdentity; 021import core.tut.pori.utils.XMLFormatter; 022import core.tut.pori.websocket.SocketService; 023 024/** 025 * Task Finished Service method definitions. 026 * 027 */ 028public class TaskFinishedService extends SocketService { 029 private static final Logger LOGGER = Logger.getLogger(TaskFinishedService.class); 030 private XMLFormatter _formatter = new XMLFormatter(); 031 032 @Override 033 public boolean accept(UserIdentity authenticatedUser) { 034 LOGGER.debug("Accepting new user, id: "+authenticatedUser.getUserId()); 035 return true; 036 } 037 038 @Override 039 public boolean accept() { 040 LOGGER.debug("Not accepting unauthorized connection..."); 041 return false; 042 } 043 044 @Override 045 public void received(UserIdentity authenticatedUser, String message) { 046 CAWebSocketCore.taskFinishedRegistered(authenticatedUser, _formatter.toObject(message, Registration.class)); 047 } 048 049 @Override 050 public void received(String message) throws UnsupportedOperationException { 051 throw new UnsupportedOperationException("Received message from unauthorized client."); // this should never be called 052 } 053 054 @Override 055 public void disconnected(UserIdentity authenticatedUser) { 056 CAWebSocketCore.taskFinishedUnregistered(authenticatedUser); 057 } 058 059 @Override 060 public void disconnected() { 061 LOGGER.warn("Unauthorized user disconnected."); // should never happen 062 } 063 064 @Override 065 public String getEndPointName() { 066 return Definitions.SERVICE_TASK_FINISHED; 067 } 068 069 /** 070 * 071 * @param authenticatedUser 072 * @param taskStatus 073 * @return true on success 074 */ 075 public boolean send(UserIdentity authenticatedUser, TaskStatus taskStatus) { 076 return super.send(authenticatedUser, _formatter.toString(taskStatus)); 077 } 078}