List of usage examples for javax.ejb TransactionAttributeType SUPPORTS
TransactionAttributeType SUPPORTS
To view the source code for javax.ejb TransactionAttributeType SUPPORTS.
Click Source Link
REQUIRED
case. From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public List<String> findMetadataObjectsForTarget(String target) throws CoreServiceException, AccessDeniedException { LOGGER.log(Level.FINE, "finding metadata for target [" + target + "]"); try {//ww w . j a va 2 s. c o m List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkPermission(target, subjects, "read"); TypedQuery<MetadataObject> query = em .createNamedQuery("findMetadataObjectsForTarget", MetadataObject.class) .setParameter("target", target); List<MetadataObject> mdos = query.getResultList(); List<String> results = new ArrayList<String>(); for (MetadataObject mdo : mdos) { String key = registry.lookup(mdo.getObjectIdentifier()); results.add(key); } return results; } catch (RegistryServiceException | MembershipServiceException | AuthorisationServiceException | KeyNotFoundException | IdentifierNotRegisteredException e) { LOGGER.log(Level.SEVERE, "unexpected error occurred during finding metadata", e); throw new CoreServiceException("unable to find metadata for target [" + target + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public List<String> findMetadataObjectsForTargetAndName(String target, String name) throws CoreServiceException, AccessDeniedException { LOGGER.log(Level.FINE, "finding metadata for target [" + target + "]"); try {/* w ww .j av a 2s. c o m*/ List<String> subjects = membership.getConnectedIdentifierSubjects(); authorisation.checkPermission(target, subjects, "read"); TypedQuery<MetadataObject> query = em .createNamedQuery("findMetadataObjectsForTargetAndName", MetadataObject.class) .setParameter("target", target).setParameter("name", name); List<MetadataObject> mdos = query.getResultList(); List<String> results = new ArrayList<String>(); for (MetadataObject mdo : mdos) { String key = registry.lookup(mdo.getObjectIdentifier()); results.add(key); } return results; } catch (RegistryServiceException | MembershipServiceException | AuthorisationServiceException | KeyNotFoundException | IdentifierNotRegisteredException e) { LOGGER.log(Level.SEVERE, "unexpected error occurred during finding metadata", e); throw new CoreServiceException("unable to find metadata for target [" + target + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public List<MetadataFormat> listMetadataFormat() throws CoreServiceException { List<MetadataFormat> formats = listAllMetadataFormat(); Map<String, MetadataFormat> latest = new HashMap<String, MetadataFormat>(); for (MetadataFormat format : formats) { if (!latest.containsKey(format.getName())) { latest.put(format.getName(), format); } else if (latest.get(format.getName()).getSerial() < format.getSerial()) { latest.put(format.getName(), format); }//from www . j ava 2s . c om } List<MetadataFormat> filteredformats = new ArrayList<MetadataFormat>(); filteredformats.addAll(latest.values()); return filteredformats; }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public List<MetadataFormat> listAllMetadataFormat() { TypedQuery<MetadataFormat> query = em.createNamedQuery("listMetadataFormat", MetadataFormat.class); return query.getResultList(); }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public MetadataFormat getMetadataFormat(String name) { LOGGER.log(Level.FINE, "reading metadata format for name [" + name + "]"); TypedQuery<MetadataFormat> query = em.createNamedQuery("findMetadataFormatForName", MetadataFormat.class) .setParameter("name", name); List<MetadataFormat> formats = query.getResultList(); if (formats.isEmpty()) { return null; }/*w ww . j ava2 s .co m*/ return formats.get(0); }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public MetadataFormat findMetadataFormatById(String id) throws CoreServiceException { MetadataFormat format = em.find(MetadataFormat.class, id); if (format == null) { throw new CoreServiceException("unable to find a metadata format for id " + id + " in the storage"); }/*from w ww. jav a 2 s . c o m*/ return format; }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public InputStream download(String key) throws CoreServiceException, DataNotFoundException, KeyNotFoundException, AccessDeniedException { LOGGER.log(Level.FINE, "download content from store for object with key [" + key + "]"); try {/*from w w w . j a va 2s .c om*/ String caller = membership.getProfileKeyForConnectedIdentifier(); List<String> subjects = membership.getConnectedIdentifierSubjects(); OrtolangObjectIdentifier identifier = registry.lookup(key); String hash; switch (identifier.getType()) { case DataObject.OBJECT_TYPE: { authorisation.checkPermission(key, subjects, "download"); DataObject object = em.find(DataObject.class, identifier.getId()); if (object == null) { throw new CoreServiceException( "unable to load object with id [" + identifier.getId() + "] from storage"); } hash = object.getStream(); break; } case MetadataObject.OBJECT_TYPE: { authorisation.checkPermission(key, subjects, "read"); MetadataObject object = em.find(MetadataObject.class, identifier.getId()); if (object == null) { throw new CoreServiceException( "unable to load metadata with id [" + identifier.getId() + "] from storage"); } hash = object.getStream(); break; } default: throw new CoreServiceException("unable to find downloadable content for key [" + key + "]"); } if (hash != null && hash.length() > 0) { InputStream stream = binarystore.get(hash); ArgumentsBuilder argumentsBuilder = new ArgumentsBuilder("hash", hash); notification.throwEvent(key, caller, identifier.getType(), OrtolangEvent.buildEventType(CoreService.SERVICE_NAME, identifier.getType(), "download"), argumentsBuilder.build()); return stream; } else { throw new DataNotFoundException("there is no preview available for this data object"); } } catch (NotificationServiceException | BinaryStoreServiceException | MembershipServiceException | RegistryServiceException | AuthorisationServiceException e) { LOGGER.log(Level.SEVERE, "unexpected error occurred during getting preview content", e); throw new CoreServiceException("unable to get preview content", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public OrtolangObject findObject(String key) throws OrtolangException { try {/* w w w .j av a 2s . c om*/ OrtolangObjectIdentifier identifier = registry.lookup(key); if (!identifier.getService().equals(CoreService.SERVICE_NAME)) { throw new OrtolangException( "object identifier " + identifier + " does not refer to service " + getServiceName()); } switch (identifier.getType()) { case Workspace.OBJECT_TYPE: return readWorkspace(key); case DataObject.OBJECT_TYPE: return readDataObject(key); case Collection.OBJECT_TYPE: return readCollection(key); case Link.OBJECT_TYPE: return readLink(key); case MetadataObject.OBJECT_TYPE: return readMetadataObject(key); } throw new OrtolangException( "object identifier " + identifier + " does not refer to service " + getServiceName()); } catch (CoreServiceException | RegistryServiceException | KeyNotFoundException e) { throw new OrtolangException("unable to find an object for key " + key); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public OrtolangObjectSize getSize(String key) throws OrtolangException { LOGGER.log(Level.FINE, "calculating size for object with key [" + key + "]"); try {/* ww w .j a v a 2 s . co m*/ List<String> subjects = membership.getConnectedIdentifierSubjects(); OrtolangObjectIdentifier cidentifier = registry.lookup(key); if (!cidentifier.getService().equals(CoreService.SERVICE_NAME)) { throw new OrtolangException( "object identifier " + cidentifier + " does not refer to service " + getServiceName()); } OrtolangObjectSize ortolangObjectSize = new OrtolangObjectSize(); switch (cidentifier.getType()) { case DataObject.OBJECT_TYPE: { authorisation.checkPermission(key, subjects, "read"); DataObject dataObject = em.find(DataObject.class, cidentifier.getId()); ortolangObjectSize.addElement(DataObject.OBJECT_TYPE, dataObject.getSize()); break; } case Collection.OBJECT_TYPE: { ortolangObjectSize = getCollectionSize(key, cidentifier, ortolangObjectSize, subjects); break; } case Workspace.OBJECT_TYPE: { authorisation.checkPermission(key, subjects, "read"); Workspace workspace = em.find(Workspace.class, cidentifier.getId()); ortolangObjectSize = getCollectionSize(workspace.getHead(), registry.lookup(workspace.getHead()), ortolangObjectSize, subjects); for (SnapshotElement snapshotElement : workspace.getSnapshots()) { ortolangObjectSize = getCollectionSize(snapshotElement.getKey(), registry.lookup(snapshotElement.getKey()), ortolangObjectSize, subjects); } ortolangObjectSize.addElement("members", workspace.getMembers().split(",").length); ortolangObjectSize.addElement("snapshots", workspace.getSnapshots().size()); break; } } return ortolangObjectSize; } catch (CoreServiceException | MembershipServiceException | RegistryServiceException | AuthorisationServiceException | AccessDeniedException | KeyNotFoundException e) { LOGGER.log(Level.SEVERE, "unexpected error while calculating object size", e); throw new OrtolangException("unable to calculate size for object with key [" + key + "]", e); } }
From source file:fr.ortolang.diffusion.core.CoreServiceBean.java
@Override @TransactionAttribute(TransactionAttributeType.SUPPORTS) public List<OrtolangObject> findObjectByBinaryHash(String hash) throws OrtolangException { try {// w ww . j a v a2 s. c o m TypedQuery<DataObject> query = em.createNamedQuery("findObjectByBinaryHash", DataObject.class) .setParameter("hash", hash); List<DataObject> objects = query.getResultList(); for (DataObject object : objects) { object.setKey(registry.lookup(object.getObjectIdentifier())); } TypedQuery<MetadataObject> query2 = em .createNamedQuery("findMetadataObjectByBinaryHash", MetadataObject.class) .setParameter("hash", hash); List<MetadataObject> objects2 = query2.getResultList(); for (MetadataObject mobject : objects2) { mobject.setKey(registry.lookup(mobject.getObjectIdentifier())); } List<OrtolangObject> oobjects = new ArrayList<OrtolangObject>(); oobjects.addAll(objects); oobjects.addAll(objects2); return oobjects; } catch (Exception e) { throw new OrtolangException("unable to find an object for hash " + hash); } }