PageRenderTime 41ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/icat3-exposed/src/main/java/uk/icat3/sessionbeans/ICAT.java

http://icatproject.googlecode.com/
Java | 405 lines | 281 code | 30 blank | 94 comment | 0 complexity | 92e043b3278431aa21b82b43e74add53 MD5 | raw file
Possible License(s): GPL-2.0
  1. package uk.icat3.sessionbeans;
  2. import java.util.Collection;
  3. import java.util.List;
  4. import javax.annotation.Resource;
  5. import javax.ejb.EJB;
  6. import javax.ejb.Stateless;
  7. import javax.ejb.TransactionAttribute;
  8. import javax.ejb.TransactionAttributeType;
  9. import javax.interceptor.ExcludeClassInterceptors;
  10. import javax.interceptor.Interceptors;
  11. import javax.jws.WebMethod;
  12. import javax.jws.WebParam;
  13. import javax.jws.WebResult;
  14. import javax.jws.WebService;
  15. import javax.servlet.http.HttpServletRequest;
  16. import javax.xml.ws.RequestWrapper;
  17. import javax.xml.ws.ResponseWrapper;
  18. import javax.xml.ws.WebServiceContext;
  19. import javax.xml.ws.handler.MessageContext;
  20. import uk.icat3.data.DownloadInfo;
  21. import uk.icat3.entity.Application;
  22. import uk.icat3.entity.Datafile;
  23. import uk.icat3.entity.DatafileFormat;
  24. import uk.icat3.entity.DatafileParameter;
  25. import uk.icat3.entity.Dataset;
  26. import uk.icat3.entity.DatasetParameter;
  27. import uk.icat3.entity.DatasetType;
  28. import uk.icat3.entity.EntityBaseBean;
  29. import uk.icat3.entity.Facility;
  30. import uk.icat3.entity.FacilityCycle;
  31. import uk.icat3.entity.Group;
  32. import uk.icat3.entity.InputDatafile;
  33. import uk.icat3.entity.InputDataset;
  34. import uk.icat3.entity.Instrument;
  35. import uk.icat3.entity.InstrumentScientist;
  36. import uk.icat3.entity.Investigation;
  37. import uk.icat3.entity.InvestigationType;
  38. import uk.icat3.entity.InvestigationUser;
  39. import uk.icat3.entity.Job;
  40. import uk.icat3.entity.Keyword;
  41. import uk.icat3.entity.NotificationRequest;
  42. import uk.icat3.entity.OutputDatafile;
  43. import uk.icat3.entity.OutputDataset;
  44. import uk.icat3.entity.ParameterType;
  45. import uk.icat3.entity.Publication;
  46. import uk.icat3.entity.RelatedDatafile;
  47. import uk.icat3.entity.Sample;
  48. import uk.icat3.entity.SampleParameter;
  49. import uk.icat3.entity.Shift;
  50. import uk.icat3.entity.Study;
  51. import uk.icat3.entity.Study.StudyStatus;
  52. import uk.icat3.entity.StudyInvestigation;
  53. import uk.icat3.entity.User;
  54. import uk.icat3.entity.UserGroup;
  55. import uk.icat3.exceptions.BadParameterException;
  56. import uk.icat3.exceptions.ICATAPIException;
  57. import uk.icat3.exceptions.IcatInternalException;
  58. import uk.icat3.exceptions.InsufficientPrivilegesException;
  59. import uk.icat3.exceptions.NoSuchObjectFoundException;
  60. import uk.icat3.exceptions.NoSuchUserException;
  61. import uk.icat3.exceptions.ObjectAlreadyExistsException;
  62. import uk.icat3.exceptions.SessionException;
  63. import uk.icat3.exceptions.ValidationException;
  64. import uk.icat3.jaxb.gen.DatasetStatus;
  65. import uk.icat3.manager.EntityInfo;
  66. import uk.icat3.sessionbeans.data.DownloadManagerLocal;
  67. import uk.icat3.sessionbeans.interceptor.DownloadInterceptor;
  68. import uk.icat3.sessionbeans.interceptor.LogoutInterceptor;
  69. import uk.icat3.sessionbeans.manager.BeanManagerLocal;
  70. import uk.icat3.sessionbeans.manager.XMLIngestionManagerLocal;
  71. import uk.icat3.sessionbeans.util.Constants;
  72. import uk.icat3.user.UserDetails;
  73. @Stateless
  74. @WebService(targetNamespace = "http://icatproject.org")
  75. @TransactionAttribute(value = TransactionAttributeType.REQUIRED)
  76. public class ICAT extends ICATCompat {
  77. @EJB
  78. private XMLIngestionManagerLocal xmlIngestionManagerLocal;
  79. @EJB
  80. private DownloadManagerLocal downloadManagerLocal;
  81. @EJB
  82. private BeanManagerLocal beanManagerLocal;
  83. @Resource
  84. WebServiceContext webServiceContext;
  85. public ICAT() {
  86. }
  87. @WebMethod
  88. public List<?> search(@WebParam(name = "sessionId") String sessionId,
  89. @WebParam(name = "query") String query)
  90. throws BadParameterException, IcatInternalException,
  91. InsufficientPrivilegesException, SessionException {
  92. return beanManagerLocal.search(sessionId, query);
  93. }
  94. @WebMethod
  95. public Object create(@WebParam(name = "sessionId") String sessionId,
  96. @WebParam(name = "bean") EntityBaseBean bean)
  97. throws SessionException, InsufficientPrivilegesException,
  98. NoSuchObjectFoundException, ValidationException,
  99. ObjectAlreadyExistsException, IcatInternalException {
  100. return beanManagerLocal.create(sessionId, bean);
  101. }
  102. @WebMethod
  103. public List<Object> createMany(@WebParam(name = "sessionId") String sessionId,
  104. @WebParam(name = "beans") List<EntityBaseBean> beans)
  105. throws SessionException, InsufficientPrivilegesException,
  106. NoSuchObjectFoundException, ValidationException,
  107. ObjectAlreadyExistsException, IcatInternalException {
  108. return beanManagerLocal.createMany(sessionId, beans);
  109. }
  110. @WebMethod
  111. public void delete(@WebParam(name = "sessionId") String sessionId,
  112. @WebParam(name = "bean") EntityBaseBean bean)
  113. throws SessionException, InsufficientPrivilegesException,
  114. NoSuchObjectFoundException, ValidationException,
  115. ObjectAlreadyExistsException, IcatInternalException {
  116. beanManagerLocal.delete(sessionId, bean);
  117. }
  118. @WebMethod
  119. public void update(@WebParam(name = "sessionId") String sessionId,
  120. @WebParam(name = "bean") EntityBaseBean bean)
  121. throws SessionException, InsufficientPrivilegesException,
  122. NoSuchObjectFoundException, ValidationException,
  123. IcatInternalException {
  124. beanManagerLocal.update(sessionId, bean);
  125. }
  126. @WebMethod
  127. public EntityBaseBean get(@WebParam(name = "sessionId") String sessionId,
  128. @WebParam(name = "query") String query,
  129. @WebParam(name = "primaryKey") Object primaryKey)
  130. throws SessionException, NoSuchObjectFoundException,
  131. InsufficientPrivilegesException, BadParameterException,
  132. IcatInternalException {
  133. return beanManagerLocal.get(sessionId, query, primaryKey);
  134. }
  135. @WebMethod
  136. public EntityInfo getEntityInfo(@WebParam(name = "beanName") String beanName)
  137. throws BadParameterException, IcatInternalException {
  138. return beanManagerLocal.getEntityInfo(beanName);
  139. }
  140. @WebMethod
  141. public void dummy(@WebParam Datafile datafile,
  142. @WebParam DatafileFormat datafileFormat,
  143. @WebParam DatafileParameter datafileParameter,
  144. @WebParam Dataset dataset,
  145. @WebParam DatasetParameter datasetParameter,
  146. @WebParam DatasetStatus datasetStatus,
  147. @WebParam DatasetType datasetType, @WebParam Facility facility,
  148. @WebParam FacilityCycle facilityCycle,
  149. @WebParam InstrumentScientist facilityInstrumentScientist,
  150. @WebParam User user, @WebParam Instrument instrument,
  151. @WebParam Investigation investigation,
  152. @WebParam InvestigationType investigationType,
  153. @WebParam InvestigationUser investigator,
  154. @WebParam Keyword keyword, @WebParam ParameterType parameter,
  155. @WebParam Publication publication,
  156. @WebParam RelatedDatafile relatedDatafile, @WebParam Sample sample,
  157. @WebParam SampleParameter sampleParameter, @WebParam Shift shift,
  158. @WebParam Study study,
  159. @WebParam StudyInvestigation studyInvestigation,
  160. @WebParam StudyStatus studyStatus,
  161. @WebParam Application application, @WebParam Job job,
  162. @WebParam InputDataset inputDataset,
  163. @WebParam OutputDataset outputDataset,
  164. @WebParam InputDatafile inputDatafile,
  165. @WebParam OutputDatafile outputDatafile,
  166. @WebParam NotificationRequest notificationRequest,
  167. @WebParam Group group, @WebParam UserGroup userGroup) {
  168. beanManagerLocal.dummy(facility);
  169. }
  170. @WebMethod(operationName = "loginAdmin")
  171. @ExcludeClassInterceptors
  172. public String loginAdmin(@WebParam(name = "sessionId") String sessionId,
  173. @WebParam(name = "runAsUserFedId") String runAsUserFedId)
  174. throws SessionException {
  175. return user.loginAdmin(sessionId, runAsUserFedId);
  176. }
  177. @WebMethod
  178. @ExcludeClassInterceptors
  179. public String login(@WebParam(name = "username") String username,
  180. @WebParam(name = "password") String password)
  181. throws SessionException, IcatInternalException {
  182. MessageContext msgCtxt = webServiceContext.getMessageContext();
  183. HttpServletRequest req = (HttpServletRequest) msgCtxt
  184. .get(MessageContext.SERVLET_REQUEST);
  185. return user.login(username, password, req);
  186. }
  187. @WebMethod(operationName = "loginLifetime")
  188. @ExcludeClassInterceptors
  189. @RequestWrapper(className = "uk.icat3.sessionbeans.jaxws.loginLifetime")
  190. @ResponseWrapper(className = "uk.icat3.sessionbeans.jaxws.loginLifetimeResponse")
  191. public String login(@WebParam(name = "username") String username,
  192. @WebParam(name = "password") String password,
  193. @WebParam(name = "lifetime") int lifetime) throws SessionException,
  194. IcatInternalException {
  195. MessageContext msgCtxt = webServiceContext.getMessageContext();
  196. HttpServletRequest req = (HttpServletRequest) msgCtxt
  197. .get(MessageContext.SERVLET_REQUEST);
  198. return user.login(username, password, lifetime, req);
  199. }
  200. @WebMethod
  201. @Interceptors(LogoutInterceptor.class)
  202. public boolean logout(@WebParam(name = "sessionId") String sessionId) {
  203. return user.logout(sessionId);
  204. }
  205. @WebMethod(operationName = "getUserDetails")
  206. public UserDetails getUserDetails(
  207. @WebParam(name = "sessionId") String sessionId,
  208. @WebParam(name = "usersName") String usersName)
  209. throws SessionException, NoSuchUserException {
  210. return this.user.getUserDetails(sessionId, usersName);
  211. }
  212. @WebMethod()
  213. public boolean isSessionValid(@WebParam(name = "sessionId") String sessionId) {
  214. try {
  215. return this.user.isSessionValid(sessionId);
  216. } catch (Exception e) {
  217. return false;
  218. }
  219. }
  220. @WebMethod
  221. public Long[] ingestMetadata(
  222. @WebParam(name = "sessionId") String sessionId,
  223. @WebParam(name = "xml") String xml) throws SessionException,
  224. ValidationException, InsufficientPrivilegesException,
  225. ICATAPIException {
  226. return xmlIngestionManagerLocal.ingestMetadata(sessionId, xml);
  227. }
  228. /**
  229. * Downloads a datafile
  230. *
  231. * @param sessionId
  232. * session id of the user.
  233. * @param datafileId
  234. * datafile id that is to be downloaded
  235. * @throws uk.icat3.exceptions.SessionException
  236. * if the session id is invalid
  237. * @throws uk.icat3.exceptions.NoSuchObjectFoundException
  238. * if entity does not exist in database
  239. * @throws uk.icat3.exceptions.InsufficientPrivilegesException
  240. * if user has insufficient privileges to the object
  241. * @return Url of the file
  242. * @throws IcatInternalException
  243. */
  244. @WebMethod
  245. @Interceptors(DownloadInterceptor.class)
  246. public @WebResult(name = "URL")
  247. String downloadDatafile(@WebParam(name = "sessionId") String sessionId,
  248. @WebParam(name = "datafileId") Long datafileId)
  249. throws SessionException, NoSuchObjectFoundException,
  250. InsufficientPrivilegesException, IcatInternalException {
  251. return downloadManagerLocal.downloadDatafile(sessionId, datafileId);
  252. }
  253. /**
  254. * Downloads a dataset
  255. *
  256. * @param sessionId
  257. * session id of the user.
  258. * @param datasetId
  259. * dataset id that is to be downloaded
  260. * @throws uk.icat3.exceptions.SessionException
  261. * if the session id is invalid
  262. * @throws uk.icat3.exceptions.NoSuchObjectFoundException
  263. * if entity does not exist in database
  264. * @throws uk.icat3.exceptions.InsufficientPrivilegesException
  265. * if user has insufficient privileges to the object
  266. * @return Url of the zipped dataset
  267. * @throws IcatInternalException
  268. */
  269. @WebMethod
  270. @Interceptors(DownloadInterceptor.class)
  271. public @WebResult(name = "URL")
  272. String downloadDataset(@WebParam(name = "sessionId") String sessionId,
  273. @WebParam(name = "datasetId") Long datasetId)
  274. throws SessionException, NoSuchObjectFoundException,
  275. InsufficientPrivilegesException, IcatInternalException {
  276. return downloadManagerLocal.downloadDataset(sessionId, datasetId);
  277. }
  278. /**
  279. * Downloads a collection of datafiles
  280. *
  281. * @param sessionId
  282. * session id of the user.
  283. * @param datafileIds
  284. * Collection of the datafile ids that are to be downloaded
  285. * @throws uk.icat3.exceptions.SessionException
  286. * if the session id is invalid
  287. * @throws uk.icat3.exceptions.NoSuchObjectFoundException
  288. * if entity does not exist in database
  289. * @throws uk.icat3.exceptions.InsufficientPrivilegesException
  290. * if user has insufficient privileges to the object
  291. * @return Url of the zipped datafiles
  292. * @throws IcatInternalException
  293. */
  294. @WebMethod
  295. @Interceptors(DownloadInterceptor.class)
  296. public @WebResult(name = "URL")
  297. String downloadDatafiles(@WebParam(name = "sessionId") String sessionId,
  298. @WebParam(name = "datafileIds") Collection<Long> datafileIds)
  299. throws SessionException, NoSuchObjectFoundException,
  300. InsufficientPrivilegesException, IcatInternalException {
  301. return downloadManagerLocal.downloadDatafiles(sessionId, datafileIds);
  302. }
  303. /**
  304. * Checks if user has access to download the files. This will be called from
  305. * the data service to check that the request coming in is valid with ICAT
  306. *
  307. * @param sessionId
  308. * session id of the user.
  309. * @param datafileIds
  310. * ids of the files that are to be downloaded
  311. * @throws uk.icat3.exceptions.SessionException
  312. * if the session id is invalid
  313. * @throws uk.icat3.exceptions.NoSuchObjectFoundException
  314. * if entity does not exist in database
  315. * @throws uk.icat3.exceptions.InsufficientPrivilegesException
  316. * if user has insufficient privileges to the object
  317. * @return DownloadInfo downloadinfo
  318. * @throws IcatInternalException
  319. */
  320. @WebMethod
  321. public @WebResult(name = "downloadInfo")
  322. DownloadInfo checkDatafileDownloadAccess(
  323. @WebParam(name = "sessionId") String sessionId,
  324. @WebParam(name = "datafileIds") Collection<Long> datafileIds)
  325. throws SessionException, NoSuchObjectFoundException,
  326. InsufficientPrivilegesException, IcatInternalException {
  327. return downloadManagerLocal.checkDatafileDownloadAccess(sessionId,
  328. datafileIds);
  329. }
  330. /**
  331. * Checks if user has access to download the dataset. This will be called
  332. * from the data service to check that the request coming in is valid with
  333. * ICAT
  334. *
  335. * @param sessionId
  336. * session id of the user.
  337. * @param datasetId
  338. * id of the dataset that are to be downloaded
  339. * @throws uk.icat3.exceptions.SessionException
  340. * if the session id is invalid
  341. * @throws uk.icat3.exceptions.NoSuchObjectFoundException
  342. * if entity does not exist in database
  343. * @throws uk.icat3.exceptions.InsufficientPrivilegesException
  344. * if user has insufficient privileges to the object
  345. * @return DownloadInfo downloadinfo
  346. * @throws IcatInternalException
  347. */
  348. @WebMethod
  349. public @WebResult(name = "downloadInfo")
  350. DownloadInfo checkDatasetDownloadAccess(
  351. @WebParam(name = "sessionId") String sessionId,
  352. @WebParam(name = "datasetId") Long datasetId)
  353. throws SessionException, NoSuchObjectFoundException,
  354. InsufficientPrivilegesException, IcatInternalException {
  355. return downloadManagerLocal.checkDatasetDownloadAccess(sessionId,
  356. datasetId);
  357. }
  358. /**
  359. * Returns the current version of the ICAT API in use
  360. *
  361. * @param sessionId
  362. * session id of the user.
  363. * @throws uk.icat3.exceptions.SessionException
  364. * if the session id is invalid
  365. * @throws uk.icat3.exceptions.InsufficientPrivilegesException
  366. * if user has insufficient privileges to the object
  367. * @return String the Current ICAT API Version (manually updated)
  368. */
  369. @WebMethod(operationName = "getICATAPIVersion")
  370. public String getICATAPIVersion(
  371. @WebParam(name = "sessionId") String sessionId)
  372. throws SessionException, InsufficientPrivilegesException {
  373. return Constants.CURRENT_ICAT_API_VERSION;
  374. }
  375. }