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 java.util.Set; 019 020import javax.xml.bind.annotation.XmlAccessType; 021import javax.xml.bind.annotation.XmlAccessorType; 022import javax.xml.bind.annotation.XmlElement; 023import javax.xml.bind.annotation.XmlElementWrapper; 024import javax.xml.bind.annotation.XmlRootElement; 025 026import org.apache.log4j.Logger; 027 028import service.tut.pori.contentanalysis.AsyncTask.TaskType; 029 030/** 031 * Registration details for Task Finished Web Socket Service. 032 * 033 * Backend ids, task ids and task types work as filters, not giving any values equals to "accept all values". 034 * 035 * When using user id or anonymous task filter, the user must have the appropriate permissions to access these tasks. 036 * In practice this means that the user must be the owner/creator of the task or have extended user permissions (e.g. ROLE_BACKEND). 037 */ 038@XmlRootElement(name=Definitions.ELEMENT_REGISTRATION) 039@XmlAccessorType(XmlAccessType.NONE) 040public class Registration { 041 private static final Logger LOGGER = Logger.getLogger(Registration.class); 042 @XmlElementWrapper(name=Definitions.ELEMENT_BACKEND_ID_LIST) 043 @XmlElement(name=service.tut.pori.contentanalysis.Definitions.ELEMENT_BACKEND_ID) 044 private Set<Integer> _backendIds = null; 045 @XmlElement(name=Definitions.ELEMENT_LISTEN_ANONYMOUS_TASKS) 046 private boolean _listenAnonymousTasks = false; 047 @XmlElementWrapper(name=Definitions.ELEMENT_TASK_ID_LIST) 048 @XmlElement(name=service.tut.pori.contentanalysis.Definitions.ELEMENT_TASK_ID) 049 private Set<Long> _taskIds = null; 050 @XmlElementWrapper(name=Definitions.ELEMENT_TASK_TYPE_LIST) 051 @XmlElement(name=service.tut.pori.contentanalysis.Definitions.ELEMENT_TASK_TYPE) 052 private Set<TaskType> _tasktypes = null; 053 @XmlElementWrapper(name=Definitions.ELEMENT_USER_ID_LIST) 054 @XmlElement(name=core.tut.pori.users.Definitions.ELEMENT_USER_ID) 055 private Set<Long> _userIds = null; 056 057 /** 058 * @return the taskIds 059 */ 060 public Set<Long> getTaskIds() { 061 return _taskIds; 062 } 063 064 /** 065 * @param taskIds the taskIds to set 066 */ 067 public void setTaskIds(Set<Long> taskIds) { 068 _taskIds = taskIds; 069 } 070 071 /** 072 * @return the tasktypes 073 */ 074 public Set<TaskType> getTasktypes() { 075 return _tasktypes; 076 } 077 078 /** 079 * @param tasktypes the tasktypes to set 080 */ 081 public void setTasktypes(Set<TaskType> tasktypes) { 082 _tasktypes = tasktypes; 083 } 084 085 /** 086 * @return the backendIds 087 */ 088 public Set<Integer> getBackendIds() { 089 return _backendIds; 090 } 091 092 /** 093 * @param backendIds the backendIds to set 094 */ 095 public void setBackendIds(Set<Integer> backendIds) { 096 _backendIds = backendIds; 097 } 098 099 /** 100 * 101 * @param backendId 102 * @return true if the given backendId has been given or the backendId set is empty or null 103 */ 104 public boolean hasBackendId(Integer backendId){ 105 if(_backendIds == null || _backendIds.isEmpty()){ 106 LOGGER.debug("No "+Definitions.ELEMENT_BACKEND_ID_LIST+" : returning true."); 107 return true; 108 }else{ 109 return _backendIds.contains(backendId); 110 } 111 } 112 113 /** 114 * 115 * @param taskType 116 * @return true if the given TaskType has been given or the taskType set is empty or null 117 */ 118 public boolean hasTaskType(TaskType taskType){ 119 if(_tasktypes == null || _tasktypes.isEmpty()){ 120 LOGGER.debug("No "+Definitions.ELEMENT_TASK_TYPE_LIST+" : returning true."); 121 return true; 122 }else{ 123 return _tasktypes.contains(taskType); 124 } 125 } 126 127 /** 128 * 129 * @param taskId 130 * @return true if the given taskId has been given or the taskId set is empty or null 131 */ 132 public boolean hasTaskId(Long taskId){ 133 if(_taskIds == null || _taskIds.isEmpty()){ 134 LOGGER.debug("No "+Definitions.ELEMENT_TASK_ID_LIST+" : returning true."); 135 return true; 136 }else{ 137 return _taskIds.contains(taskId); 138 } 139 } 140 141 /** 142 * @return the listenAnonymousTasks 143 */ 144 public boolean isListenAnonymousTasks() { 145 return _listenAnonymousTasks; 146 } 147 148 /** 149 * @param listenAnonymousTasks the listenAnonymousTasks to set 150 */ 151 public void setListenAnonymousTasks(boolean listenAnonymousTasks) { 152 _listenAnonymousTasks = listenAnonymousTasks; 153 } 154 155 /** 156 * @return the userIds 157 */ 158 public Set<Long> getUserIds() { 159 return _userIds; 160 } 161 162 /** 163 * @param userIds the userIds to set 164 */ 165 public void setUserIds(Set<Long> userIds) { 166 _userIds = userIds; 167 } 168 169 /** 170 * 171 * @param userId 172 * @return true if and only if the user id list contains the given user id 173 */ 174 public boolean hasUserId(Long userId){ 175 return (_userIds == null ? false : _userIds.contains(userId)); 176 } 177}