PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/factory/factory-core/src/main/java/org/qualipso/factory/eventqueue/EventQueueServiceBean.java

https://github.com/moustictoto/Ulysse
Java | 1111 lines | 681 code | 153 blank | 277 comment | 139 complexity | 5749a0993eebf0aa655d51d91cb70f44 MD5 | raw file
  1. /*
  2. * Qualipso Funky Factory
  3. * Copyright (C) 2006-2010 INRIA
  4. * http://www.inria.fr - molli@loria.fr
  5. *
  6. * This is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU Lesser General Public License version 3
  8. * as published by the Free Software Foundation. See the GNU
  9. * Lesser General Public License in LGPL.txt for more details.
  10. *
  11. * You should have received a copy of the GNU Lesser General Public
  12. * License along with this software; if not, write to the Free
  13. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  14. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  15. *
  16. * Initial authors :
  17. *
  18. *Elamri Firas
  19. *Yuksel Huriye
  20. *Secondary authors :
  21. *Amrou Mohanned Khalifa
  22. *Yiqing Li
  23. */
  24. package org.qualipso.factory.eventqueue;
  25. import java.util.ArrayList;
  26. import java.util.Date;
  27. import java.util.Iterator;
  28. import java.util.UUID;
  29. import javax.annotation.Resource;
  30. import javax.ejb.EJB;
  31. import javax.ejb.SessionContext;
  32. import javax.ejb.Stateless;
  33. import javax.jws.WebMethod;
  34. import javax.jws.WebService;
  35. import javax.jws.soap.SOAPBinding;
  36. import javax.jws.soap.SOAPBinding.Style;
  37. import javax.persistence.EntityManager;
  38. import javax.persistence.PersistenceContext;
  39. import org.apache.commons.logging.Log;
  40. import org.apache.commons.logging.LogFactory;
  41. import org.jboss.ejb3.annotation.SecurityDomain;
  42. import org.jboss.ws.annotation.EndpointConfig;
  43. import org.jboss.wsf.spi.annotation.WebContext;
  44. import org.qualipso.factory.FactoryException;
  45. import org.qualipso.factory.FactoryNamingConvention;
  46. import org.qualipso.factory.FactoryResource;
  47. import org.qualipso.factory.FactoryResourceIdentifier;
  48. import org.qualipso.factory.FactoryResourceProperty;
  49. import org.qualipso.factory.binding.BindingService;
  50. import org.qualipso.factory.binding.PathHelper;
  51. import org.qualipso.factory.core.CoreServiceException;
  52. import org.qualipso.factory.eventqueue.entity.Event;
  53. import org.qualipso.factory.eventqueue.entity.EventQueue;
  54. import org.qualipso.factory.membership.MembershipService;
  55. import org.qualipso.factory.notification.NotificationService;
  56. import org.qualipso.factory.security.pap.PAPService;
  57. import org.qualipso.factory.security.pap.PAPServiceHelper;
  58. import org.qualipso.factory.security.pep.PEPService;
  59. /**
  60. * Implementation of the ClockService. Provides a time service for the factory.
  61. *
  62. * @author <a href="mailto:christophe.bouthier@loria.fr">Christophe Bouthier</a>
  63. * @author Nicolas HENRY
  64. * @author Marlène HANTZ
  65. * @date 27 July 2009
  66. */
  67. @Stateless(name = EventQueueService.SERVICE_NAME, mappedName = FactoryNamingConvention.SERVICE_PREFIX + EventQueueService.SERVICE_NAME)
  68. @WebService(endpointInterface = "org.qualipso.factory.eventqueue.EventQueueService", targetNamespace = FactoryNamingConvention.SERVICE_NAMESPACE
  69. + EventQueueService.SERVICE_NAME, serviceName = EventQueueService.SERVICE_NAME)
  70. @WebContext(contextRoot = FactoryNamingConvention.WEB_SERVICE_CORE_MODULE_CONTEXT, urlPattern = FactoryNamingConvention.WEB_SERVICE_URL_PATTERN_PREFIX
  71. + EventQueueService.SERVICE_NAME)
  72. @SOAPBinding(style = Style.RPC)
  73. @SecurityDomain(value = "JBossWSDigest")
  74. @EndpointConfig(configName = "Standard WSSecurity Endpoint")
  75. public class EventQueueServiceBean implements EventQueueService {
  76. private static Log logger = LogFactory.getLog(EventQueueServiceBean.class);
  77. private BindingService binding;
  78. private PEPService pep;
  79. private PAPService pap;
  80. private NotificationService notification;
  81. private MembershipService membership;
  82. private SessionContext ctx;
  83. private EntityManager em;
  84. public EventQueueServiceBean() {
  85. }
  86. /**
  87. * cette methode positionne l Entity Manager
  88. *
  89. * @param em
  90. * Entity Manager
  91. */
  92. @PersistenceContext
  93. public void setEntityManager(EntityManager em) {
  94. this.em = em;
  95. }
  96. /**
  97. * cette methode retourne l Entity Manager
  98. *
  99. * @return em l'entity manager
  100. */
  101. public EntityManager getEntityManager() {
  102. return this.em;
  103. }
  104. /**
  105. * cette methode positionne la Session Context
  106. *
  107. * @param ctx
  108. * la Session Context
  109. */
  110. @Resource
  111. public void setSessionContext(SessionContext ctx) {
  112. this.ctx = ctx;
  113. }
  114. /**
  115. * cette methode retourne la Session Context
  116. *
  117. * @return la Session Context
  118. */
  119. public SessionContext getSessionContext() {
  120. return this.ctx;
  121. }
  122. /**
  123. * cette methode positionne le Binding Service
  124. *
  125. * @param binding
  126. * le Binding Service
  127. *
  128. */
  129. @EJB
  130. public void setBindingService(BindingService binding) {
  131. this.binding = binding;
  132. }
  133. /**
  134. *
  135. *cette methode retourne le Binding Service
  136. *
  137. * @return le Binding Service
  138. */
  139. public BindingService getBindingService() {
  140. return this.binding;
  141. }
  142. /**
  143. * cette methode positionne le PEP Service
  144. *
  145. * @param pep
  146. * le PEP Service
  147. *
  148. */
  149. @EJB
  150. public void setPEPService(PEPService pep) {
  151. this.pep = pep;
  152. }
  153. /**
  154. * cette methode retourne le PEP Service
  155. *
  156. * @return PEP Service
  157. */
  158. public PEPService getPEPService() {
  159. return this.pep;
  160. }
  161. /**
  162. * cette methode positionne le PAP Service
  163. *
  164. * @param pap
  165. * le PAP Service
  166. *
  167. */
  168. @EJB
  169. public void setPAPService(PAPService pap) {
  170. this.pap = pap;
  171. }
  172. /**
  173. * cette methode retourne le PAP Service
  174. *
  175. * @return PAPS ervice
  176. */
  177. public PAPService getPAPService() {
  178. return this.pap;
  179. }
  180. /**
  181. * cette methode positionne le Notification Service
  182. *
  183. * @param notification
  184. * le Notification Service
  185. *
  186. */
  187. @EJB
  188. public void setNotificationService(NotificationService notification) {
  189. this.notification = notification;
  190. }
  191. /**
  192. * cette methode retourne le Notification Service
  193. *
  194. * @return le Service Notification
  195. */
  196. public NotificationService getNotificationService() {
  197. return this.notification;
  198. }
  199. /**
  200. * cette methode positionne le Membership Service
  201. *
  202. * @param membership
  203. * le Membership Service
  204. *
  205. */
  206. @EJB
  207. public void setMembershipService(MembershipService membership) {
  208. this.membership = membership;
  209. }
  210. /**
  211. * cette methode retourne le Membership Service
  212. *
  213. * @return le Membership Service
  214. */
  215. public MembershipService getMembershipService() {
  216. return this.membership;
  217. }
  218. /**
  219. * cette methode retourne les evenements contenu dans la queue sinon une
  220. * exception si la queue n est pas trouve
  221. *
  222. * @param name
  223. * le nom de la queue
  224. * @return returne un tableau des evenements contenu dans la queue
  225. */
  226. @Override
  227. public Event[] getEvents(String path) throws EventQueueServiceException {
  228. FactoryResourceIdentifier identifier;
  229. try {
  230. identifier = binding.lookup(path);
  231. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  232. String caller = membership.getProfilePathForConnectedIdentifier();
  233. pep.checkSecurity(caller, path, "read");
  234. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  235. if (eventqueue == null) {
  236. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  237. }
  238. Event[] evs = new Event[eventqueue.getEvents().size()];
  239. /*ArrayList<Event> evts = new ArrayList<Event>();
  240. ArrayList<Event> allEvts = eventqueue.getEvents();
  241. for (Event event : allEvts) {
  242. try{
  243. pep.checkSecurity(caller,event.getFromResource(), "read");
  244. evts.add(event);
  245. }catch(PEPServiceException e){
  246. }
  247. }*/
  248. return eventqueue.getEvents().toArray(evs);
  249. } else {
  250. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  251. }
  252. } catch (Exception e) {
  253. logger.error("unable to get events", e);
  254. ctx.setRollbackOnly();
  255. throw new EventQueueServiceException("unable to get events", e);
  256. }
  257. }
  258. /**
  259. * cette méthode permet de creer une nouvelle queue a partir de son nom
  260. * sinon retourne une exception si la queue n a pas pu etre cree la queue
  261. * est rendu persistante et bindee par la suite
  262. *
  263. * @param name
  264. * le nom de la nouvelle queue a creer
  265. *
  266. */
  267. @Override
  268. public void createEventQueue(String path) throws EventQueueServiceException {
  269. logger.info("createEventQueue(...) called");
  270. logger.debug("params : path=" + path);
  271. try {
  272. String caller = membership.getProfilePathForConnectedIdentifier();
  273. pep.checkSecurity(caller, PathHelper.getParentPath(path), "create");
  274. EventQueue evq = new EventQueue();
  275. evq.setId(UUID.randomUUID().toString());
  276. evq.setEvents(new ArrayList<Event>());
  277. em.persist(evq);
  278. binding.bind(evq.getFactoryResourceIdentifier(), path);
  279. String policyId = UUID.randomUUID().toString();
  280. pap.createPolicy(policyId, PAPServiceHelper.addRuleToPolicy(PAPServiceHelper.buildOwnerPolicy(policyId, caller, path), "", new String[] { "create",
  281. "read", "update" }));
  282. binding.setProperty(path, FactoryResourceProperty.OWNER, caller);
  283. binding.setProperty(path, FactoryResourceProperty.POLICY_ID, policyId);
  284. } catch (Exception e) {
  285. logger.error("unable to create an event queue", e);
  286. ctx.setRollbackOnly();
  287. throw new EventQueueServiceException("unable to create an event queue", e);
  288. }
  289. }
  290. /**
  291. * cette methode place un evenement dans la queue associe au name sinon
  292. * retourne une exception si l evenement n est pas ajoute
  293. *
  294. * @param name
  295. * le nom de l'event queue
  296. * @param event
  297. * l evenement a pusher dans la queue
  298. *
  299. */
  300. @Override
  301. public void pushEvent(String path, Event event) throws EventQueueServiceException {
  302. FactoryResourceIdentifier identifier;
  303. try {
  304. if (event == null) {
  305. throw new IllegalArgumentException("event can't be null");
  306. }
  307. identifier = binding.lookup(path);
  308. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  309. String caller = membership.getProfilePathForConnectedIdentifier();
  310. pep.checkSecurity(caller, path, "update");
  311. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  312. if (eventqueue == null) {
  313. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  314. }
  315. eventqueue.getEvents().add(event);
  316. em.persist(eventqueue);
  317. } else {
  318. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  319. }
  320. } catch (Exception e) {
  321. logger.error("unable to pushEvent an event in the event queue", e);
  322. ctx.setRollbackOnly();
  323. throw new EventQueueServiceException("unable to pushEvent an event in the event queue", e);
  324. }
  325. }
  326. /**
  327. * cette methode retourne l event queue associe a path sinon une exception
  328. * si l'event queue n'est pas trouve
  329. *
  330. * @param path
  331. * le path de l event queue
  332. * @return event queue associé a path
  333. */
  334. @Override
  335. public FactoryResource findResource(String path) throws FactoryException {
  336. logger.info("findResource(...) called");
  337. logger.debug("params : path=" + path);
  338. FactoryResourceIdentifier identifier = binding.lookup(path);
  339. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  340. String caller = membership.getProfilePathForConnectedIdentifier();
  341. pep.checkSecurity(caller, path, "read");
  342. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  343. if (eventqueue == null) {
  344. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  345. }
  346. return eventqueue;
  347. }
  348. throw new EventQueueServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  349. }
  350. @Override
  351. public Event getLastEvent(String path) throws EventQueueServiceException {
  352. FactoryResourceIdentifier identifier;
  353. try {
  354. identifier = binding.lookup(path);
  355. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  356. String caller = membership.getProfilePathForConnectedIdentifier();
  357. pep.checkSecurity(caller, path, "read");
  358. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  359. if (eventqueue == null) {
  360. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  361. }
  362. int size = eventqueue.getEvents().size();
  363. Event[] evq = new Event[size];
  364. evq = eventqueue.getEvents().toArray(evq);
  365. Event result = evq[size - 1];
  366. return result;
  367. } else {
  368. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  369. }
  370. } catch (Exception e) {
  371. logger.error("unable to get Last Event", e);
  372. ctx.setRollbackOnly();
  373. throw new EventQueueServiceException("unable to get Last Event", e);
  374. }
  375. }
  376. /**
  377. * cette methode retourne le Resource Type List
  378. *
  379. * @return Resource Type List
  380. */
  381. @Override
  382. public String[] getResourceTypeList() {
  383. return RESOURCE_TYPE_LIST;
  384. }
  385. /**
  386. * cette methode retourne le nom du service
  387. *
  388. * @return le nom du cervice
  389. */
  390. @Override
  391. public String getServiceName() {
  392. return SERVICE_NAME;
  393. }
  394. @Override
  395. public void deleteEvent(String path, Event e) throws EventQueueServiceException {
  396. FactoryResourceIdentifier identifier;
  397. try {
  398. identifier = binding.lookup(path);
  399. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  400. String caller = membership.getProfilePathForConnectedIdentifier();
  401. pep.checkSecurity(caller, path, "update");
  402. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  403. if (eventqueue == null) {
  404. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  405. }
  406. /*
  407. * int size = eventqueue.getEvents().size(); Event[] evq = new
  408. * Event[size]; evq = eventqueue.getEvents().toArray(evq);
  409. */
  410. ArrayList<Event> newEventList = eventqueue.getEvents();
  411. if (newEventList.remove(e)) {
  412. eventqueue.setEvents(newEventList);
  413. em.merge(eventqueue);
  414. } else {
  415. throw new EventQueueServiceException("this event doesn't exist in this queue");
  416. }
  417. } else {
  418. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  419. }
  420. } catch (Exception ex) {
  421. logger.error("unable to delete Event", ex);
  422. ctx.setRollbackOnly();
  423. throw new EventQueueServiceException("unable to delete Event", ex);
  424. }
  425. }
  426. /**
  427. *
  428. * return an array of event that have or contains the same ressourceType
  429. *
  430. * @param path
  431. * path of the EventQueue
  432. * @param ressourceType
  433. * the type of resource event
  434. * @param substring
  435. * true if typeRssource contains parameter typeRessource, false
  436. * if typeRssource contains exactly the parameter typeRessource
  437. * @return array of event
  438. * @throws EventQueueServiceException
  439. */
  440. @WebMethod
  441. public Event[] findEventByRessourceType(String path, String ressourceType, boolean substring) throws EventQueueServiceException {
  442. FactoryResourceIdentifier identifier;
  443. try {
  444. // li des cas exceptionnelles
  445. if ((path == null) || (ressourceType == null))
  446. throw new EventQueueServiceException("Le parametre n'est pas correct verifier le path ou le ressourceType");
  447. identifier = binding.lookup(path);
  448. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  449. String caller = membership.getProfilePathForConnectedIdentifier();
  450. pep.checkSecurity(caller, path, "read");
  451. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  452. if (eventqueue == null) {
  453. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  454. }
  455. ArrayList<Event> resultContains = new ArrayList<Event>();
  456. ArrayList<Event> resultEquals = new ArrayList<Event>();
  457. ArrayList<Event> listEvent = eventqueue.getEvents();
  458. Iterator<Event> it = listEvent.iterator();
  459. while (it.hasNext()) {
  460. Event ev = it.next();
  461. if (substring == true && ev.getResourceType().contains(ressourceType)) {
  462. resultContains.add(ev);
  463. }
  464. if (substring == false && ev.getResourceType().equals(ressourceType)) {
  465. resultEquals.add(ev);
  466. }
  467. }
  468. if (substring == true) {
  469. return (Event[]) (resultContains.toArray());
  470. } else {
  471. return (Event[]) (resultEquals.toArray());
  472. }
  473. }
  474. else {
  475. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  476. }
  477. } catch (Exception e) {
  478. logger.error("unable to find Event By Ressource Type", e);
  479. ctx.setRollbackOnly();
  480. throw new EventQueueServiceException("unable to find Event By Ressource Type", e);
  481. }
  482. }
  483. /**
  484. * return an array of event that have or contains the same thrower
  485. *
  486. * @param path
  487. * path of the EventQueue
  488. * @param thrower
  489. * thrower of event
  490. * @param substring
  491. * true if thrower contains the string parameter thrower , false
  492. * if thrower contains exactly the parameter thrower.
  493. * @return array of event (return an array of event that have or contains
  494. * the same thrower)
  495. * @throws EventQueueServiceException
  496. */
  497. @WebMethod
  498. public Event[] findEventBythrower(String path, String thrower, boolean substring) throws EventQueueServiceException {
  499. FactoryResourceIdentifier identifier;
  500. try {
  501. identifier = binding.lookup(path);
  502. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  503. String caller = membership.getProfilePathForConnectedIdentifier();
  504. pep.checkSecurity(caller, path, "read");
  505. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  506. if (eventqueue == null) {
  507. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  508. }
  509. ArrayList<Event> resultContains = new ArrayList<Event>();
  510. ArrayList<Event> resultFalse = new ArrayList<Event>();
  511. ArrayList<Event> listEvent = eventqueue.getEvents();
  512. Iterator<Event> it = listEvent.iterator();
  513. while (it.hasNext()) {
  514. Event ev = it.next();
  515. if (substring == true && ev.getThrowedBy().contains(thrower)) {
  516. resultContains.add(ev);
  517. }
  518. if (substring == false && ev.getThrowedBy().equals(thrower)) {
  519. resultFalse.add(ev);
  520. }
  521. }
  522. if (substring == true) {
  523. Event[] tab = new Event[resultContains.size()];
  524. int i = 0;
  525. while (i < resultContains.size()) {
  526. tab[i] = resultContains.get(i);
  527. i++;
  528. }
  529. return tab;
  530. } else {
  531. Event[] tab = new Event[resultFalse.size()];
  532. int i = 0;
  533. while (i < resultFalse.size()) {
  534. tab[i] = resultFalse.get(i);
  535. i++;
  536. }
  537. return tab;
  538. }
  539. }
  540. else {
  541. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  542. }
  543. } catch (Exception e) {
  544. logger.error("unable to find Event By thrower", e);
  545. ctx.setRollbackOnly();
  546. throw new EventQueueServiceException("unable to find Event By thrower", e);
  547. }
  548. }
  549. /**
  550. *
  551. * @param path
  552. * path of the EventQueue
  553. * @param fromRessource
  554. * fromRessource of event
  555. * @param substring
  556. * true if fromRessource contains the string parameter
  557. * fromRessource , false if thrower contains exactly the
  558. * parameter fromRessource.
  559. * @return array of event ( return an array of event that have or contains
  560. * the same fromRessource )
  561. * @throws EventQueueServiceException
  562. */
  563. @WebMethod
  564. public Event[] findEventByFromRessource(String path, String fromRessource, boolean substring) throws EventQueueServiceException {
  565. FactoryResourceIdentifier identifier;
  566. try {
  567. // li des cas exceptionnelles
  568. if ((path == null) || (fromRessource == null))
  569. throw new EventQueueServiceException("Le parametre n'est pas correct verifier le path ou fromRessource");
  570. identifier = binding.lookup(path);
  571. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  572. String caller = membership.getProfilePathForConnectedIdentifier();
  573. pep.checkSecurity(caller, path, "read");
  574. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  575. if (eventqueue == null) {
  576. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  577. }
  578. ArrayList<Event> resultContains = new ArrayList<Event>();
  579. ArrayList<Event> resultFalse = new ArrayList<Event>();
  580. ArrayList<Event> listEvent = eventqueue.getEvents();
  581. Iterator<Event> it = listEvent.iterator();
  582. while (it.hasNext()) {
  583. Event ev = it.next();
  584. if (substring == true && ev.getFromResource().contains(fromRessource)) {
  585. resultContains.add(ev);
  586. }
  587. if (substring == false && ev.getFromResource().equals(fromRessource)) {
  588. resultFalse.add(ev);
  589. }
  590. }
  591. if (substring == true) {
  592. Event[] tab = new Event[resultContains.size()];
  593. int i = 0;
  594. while (i < resultContains.size()) {
  595. tab[i] = resultContains.get(i);
  596. i++;
  597. }
  598. return tab;
  599. } else {
  600. Event[] tab = new Event[resultFalse.size()];
  601. int i = 0;
  602. while (i < resultFalse.size()) {
  603. tab[i] = resultFalse.get(i);
  604. i++;
  605. }
  606. return tab;
  607. }
  608. }
  609. else {
  610. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  611. }
  612. } catch (Exception e) {
  613. logger.error("unable to find Event By from Ressource", e);
  614. ctx.setRollbackOnly();
  615. throw new EventQueueServiceException("unable to find Event By from Ressource", e);
  616. }
  617. }
  618. /**
  619. *
  620. * @param path
  621. * path of the EventQueue
  622. * @param date
  623. * date of the event
  624. * @return array of event ( return an array of event having the same date )
  625. * @throws EventQueueServiceException
  626. */
  627. @WebMethod
  628. public Event[] findEventByDate(String path, Date date) throws EventQueueServiceException {
  629. FactoryResourceIdentifier identifier;
  630. try {
  631. identifier = binding.lookup(path);
  632. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  633. String caller = membership.getProfilePathForConnectedIdentifier();
  634. pep.checkSecurity(caller, path, "read");
  635. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  636. if (eventqueue == null) {
  637. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  638. }
  639. ArrayList<Event> result = new ArrayList<Event>();
  640. ArrayList<Event> listEvent = eventqueue.getEvents();
  641. Iterator<Event> it = listEvent.iterator();
  642. while (it.hasNext()) {
  643. Event ev = it.next();
  644. if (ev.getDate().equals(date)) {
  645. result.add(ev);
  646. }
  647. }
  648. Event[] tab = new Event[result.size()];
  649. int i = 0;
  650. while (i < result.size()) {
  651. tab[i] = result.get(i);
  652. i++;
  653. }
  654. // return (Event[]) (result.toArray());
  655. return tab;
  656. }
  657. else {
  658. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  659. }
  660. } catch (Exception e) {
  661. logger.error("unable to find Event By Date", e);
  662. ctx.setRollbackOnly();
  663. throw new EventQueueServiceException("unable to find Event By Date", e);
  664. }
  665. }
  666. /**
  667. *
  668. * @param path
  669. * path of the EventQueue
  670. * @param date
  671. * date of the event
  672. * @return array of event (return an array of event having date lesser or
  673. * equal of the parameter date )
  674. * @throws EventQueueServiceException
  675. */
  676. @WebMethod
  677. public Event[] findEventByDateInf(String path, Date date) throws EventQueueServiceException {
  678. FactoryResourceIdentifier identifier;
  679. try {
  680. identifier = binding.lookup(path);
  681. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  682. String caller = membership.getProfilePathForConnectedIdentifier();
  683. pep.checkSecurity(caller, path, "read");
  684. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  685. if (eventqueue == null) {
  686. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  687. }
  688. ArrayList<Event> result = new ArrayList<Event>();
  689. ArrayList<Event> listEvent = eventqueue.getEvents();
  690. Iterator<Event> it = listEvent.iterator();
  691. while (it.hasNext()) {
  692. Event ev = (Event) it.next();
  693. if (ev.getDate().before(date) || ev.getDate().equals(date)) {
  694. result.add(ev);
  695. }
  696. }// while
  697. // return (Event[]) (result.toArray());
  698. Event[] tab = new Event[result.size()];
  699. int i = 0;
  700. while (i < result.size()) {
  701. tab[i] = result.get(i);
  702. i++;
  703. }
  704. return tab;
  705. }
  706. else {
  707. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  708. }
  709. } catch (Exception e) {
  710. logger.error("unable to find Event By DateSup", e);
  711. ctx.setRollbackOnly();
  712. throw new EventQueueServiceException("unable to find Event By DateSup", e);
  713. }
  714. }
  715. /**
  716. *
  717. * @param path
  718. * path of the EventQueue
  719. * @param date
  720. * date date of the event
  721. * @return array of event (return an array of event having date superior or
  722. * equal of the parameter date )
  723. * @throws EventQueueServiceException
  724. */
  725. @WebMethod
  726. public Event[] findEventByDateSup(String path, Date date) throws EventQueueServiceException {
  727. FactoryResourceIdentifier identifier;
  728. try {
  729. identifier = binding.lookup(path);
  730. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  731. String caller = membership.getProfilePathForConnectedIdentifier();
  732. pep.checkSecurity(caller, path, "read");
  733. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  734. if (eventqueue == null) {
  735. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  736. }
  737. ArrayList<Event> result = new ArrayList<Event>();
  738. ArrayList<Event> listEvent = eventqueue.getEvents();
  739. Iterator<Event> it = listEvent.iterator();
  740. while (it.hasNext()) {
  741. Event ev = it.next();
  742. if (ev.getDate().after(date) || ev.getDate().equals(date)) {
  743. result.add(ev);
  744. }
  745. }// while
  746. Event[] tab = new Event[result.size()];
  747. int i = 0;
  748. while (i < result.size()) {
  749. tab[i] = result.get(i);
  750. i++;
  751. }
  752. return tab;
  753. }
  754. else {
  755. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  756. }
  757. } catch (Exception e) {
  758. logger.error("unable to find Event By DateInf", e);
  759. ctx.setRollbackOnly();
  760. throw new EventQueueServiceException("unable to find Event By DateInf", e);
  761. }
  762. }
  763. /**
  764. *
  765. * @param path
  766. * path of the EventQueue
  767. * @param date1
  768. * date of the event
  769. * @param date2
  770. * date of the event
  771. * @return array of event (return an array of event having date between
  772. * date1 and date2 where date1<= date2)
  773. * @throws EventQueueServiceException
  774. */
  775. @WebMethod
  776. public Event[] findEventByDateBetween(String path, Date date1, Date date2) throws EventQueueServiceException {
  777. FactoryResourceIdentifier identifier;
  778. try {
  779. identifier = binding.lookup(path);
  780. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  781. String caller = membership.getProfilePathForConnectedIdentifier();
  782. pep.checkSecurity(caller, path, "read");
  783. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  784. if (eventqueue == null) {
  785. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  786. }
  787. ArrayList<Event> result = new ArrayList<Event>();
  788. ArrayList<Event> listEvent = eventqueue.getEvents();
  789. Iterator<Event> it = listEvent.iterator();
  790. while (it.hasNext()) {
  791. Event ev = it.next();
  792. // correction d'un bug concernant date1 et date2 et inversé
  793. // if (((ev.getDate().before(date1)) ||
  794. // (ev.getDate().equals(date1))) &&
  795. // ((ev.getDate().after(date2)) ||
  796. // (ev.getDate().equals(date2)))) {
  797. // result.add(ev);
  798. // }
  799. if ((ev.getDate().getTime() >= date1.getTime()) && (ev.getDate().getTime() <= date2.getTime())) {
  800. result.add(ev);
  801. }
  802. }// while
  803. Event[] tab = new Event[result.size()];
  804. int i = 0;
  805. while (i < result.size()) {
  806. tab[i] = result.get(i);
  807. i++;
  808. }
  809. return tab;
  810. }
  811. else {
  812. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  813. }
  814. } catch (Exception e) {
  815. logger.error("unable to find Event By Date Between", e);
  816. ctx.setRollbackOnly();
  817. throw new EventQueueServiceException("unable to find Event By Date Between", e);
  818. }
  819. }
  820. /**
  821. *
  822. * @param path
  823. * @param eventType
  824. * @param substring
  825. * @return
  826. * @throws EventQueueServiceException
  827. */
  828. @WebMethod
  829. public Event[] findEventByEventType(String path, String eventType, boolean substring) throws EventQueueServiceException {
  830. FactoryResourceIdentifier identifier;
  831. try {
  832. // li des cas exceptionnelles
  833. if ((path == null) || (eventType == null))
  834. throw new EventQueueServiceException("Le parametre n'est pas correct . Verifier le path ou l'eventType");
  835. identifier = binding.lookup(path);
  836. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  837. String caller = membership.getProfilePathForConnectedIdentifier();
  838. pep.checkSecurity(caller, path, "read");
  839. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  840. if (eventqueue == null) {
  841. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  842. }
  843. ArrayList<Event> resultContains = new ArrayList<Event>();
  844. ArrayList<Event> resultEquals = new ArrayList<Event>();
  845. ArrayList<Event> listEvent = eventqueue.getEvents();
  846. Iterator<Event> it = listEvent.iterator();
  847. while (it.hasNext()) {
  848. Event ev = it.next();
  849. if ((substring == true) && (ev.getEventType().contains(eventType))) {
  850. resultContains.add(ev);
  851. }
  852. if ((substring == false) && (ev.getEventType().equals(eventType))) {
  853. resultEquals.add(ev);
  854. }
  855. }// while
  856. if (substring == true) {
  857. Event[] tab = new Event[resultContains.size()];
  858. int i = 0;
  859. while (i < resultContains.size()) {
  860. tab[i] = resultContains.get(i);
  861. i++;
  862. }
  863. return tab;
  864. } else {
  865. Event[] tab = new Event[resultEquals.size()];
  866. int i = 0;
  867. while (i < resultEquals.size()) {
  868. tab[i] = resultEquals.get(i);
  869. i++;
  870. }
  871. return tab;
  872. }
  873. }
  874. else {
  875. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  876. }
  877. } catch (Exception e) {
  878. logger.error("unable to find Event By EventType", e);
  879. ctx.setRollbackOnly();
  880. throw new EventQueueServiceException("unable to find Event By EventType", e);
  881. }
  882. }
  883. public Event[] findObjectEvent(String path, Event event) throws EventQueueServiceException {
  884. FactoryResourceIdentifier identifier;
  885. try {
  886. identifier = binding.lookup(path);
  887. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  888. String caller = membership.getProfilePathForConnectedIdentifier();
  889. pep.checkSecurity(caller, path, "read");
  890. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  891. if (eventqueue == null) {
  892. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  893. }
  894. ArrayList<Event> result = new ArrayList<Event>();
  895. ArrayList<Event> listEvent = eventqueue.getEvents();
  896. Iterator<Event> it = listEvent.iterator();
  897. while (it.hasNext()) {
  898. Event ev = it.next();
  899. if (ev.equals(event)) {
  900. result.add(ev);
  901. }
  902. }
  903. Event[] tab = new Event[result.size()];
  904. int i = 0;
  905. while (i < result.size()) {
  906. tab[i] = result.get(i);
  907. i++;
  908. }
  909. return tab;
  910. }
  911. else {
  912. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  913. }
  914. } catch (Exception e) {
  915. logger.error("unable to find Object Event", e);
  916. ctx.setRollbackOnly();
  917. throw new EventQueueServiceException("unable to find Object Event", e);
  918. }
  919. }
  920. @Override
  921. public void removeQueue(String path) throws EventQueueServiceException {
  922. FactoryResourceIdentifier identifier;
  923. try {
  924. identifier = binding.lookup(path);
  925. if (identifier.getType().equals(EventQueue.RESOURCE_NAME)) {
  926. String caller = membership.getProfilePathForConnectedIdentifier();
  927. pep.checkSecurity(caller, path, "update");
  928. EventQueue eventqueue = em.find(EventQueue.class, identifier.getId());
  929. if (eventqueue == null) {
  930. throw new EventQueueServiceException("unable to find an event queue for id " + identifier.getId());
  931. }
  932. em.remove(eventqueue);
  933. binding.unbind(path);
  934. } else {
  935. throw new CoreServiceException("Resource " + identifier + " is not managed by Event Queue Service");
  936. }
  937. } catch (Exception e) {
  938. logger.error("unable to remove event queue", e);
  939. ctx.setRollbackOnly();
  940. throw new EventQueueServiceException("unable to create an event queue", e);
  941. }
  942. }
  943. @WebMethod
  944. public Event[] findEventBySimpleParameter(String path, String eventType, String thrower, String resourceType, String fromRessource, Date date,
  945. boolean dateSup, boolean dateInf) throws EventQueueServiceException {
  946. return null;
  947. }
  948. @WebMethod
  949. public Event[] findEventByComposedParameter(String path, String eventType, String thrower, String resourceType, String fromRessource, Date date1, Date date2)
  950. throws EventQueueServiceException {
  951. return null;
  952. }
  953. @Override
  954. public void generateXML(String path) {
  955. // TODO Auto-generated method stub
  956. }
  957. }