Example usage for javax.ejb TransactionAttributeType SUPPORTS

List of usage examples for javax.ejb TransactionAttributeType SUPPORTS

Introduction

In this page you can find the example usage for javax.ejb TransactionAttributeType SUPPORTS.

Prototype

TransactionAttributeType SUPPORTS

To view the source code for javax.ejb TransactionAttributeType SUPPORTS.

Click Source Link

Document

If the client calls with a transaction context, the container performs the same steps as described in the REQUIRED case.

Usage

From source file:com.flexive.ejb.beans.ScriptingEngineBean.java

/**
 * {@inheritDoc}//from   w ww. j  a va 2 s . c o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<String[]> getAvailableScriptEngines() throws FxApplicationException {
    final List<String[]> ret = JDK6Scripting.getAvailableScriptEngines();
    // Add gy extension f. Groovy
    ret.add(0, new String[] { "gy", "gy: Groovy v" + FxSharedUtils.getBundledGroovyVersion()
            + " (Bundled GroovyShell v" + FxSharedUtils.getBundledGroovyVersion() + ")" });
    return ret;
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Set<OrtolangObjectPid> buildWorkspacePidList(String wskey, String tag) throws CoreServiceException {
    LOGGER.log(Level.FINE, "building pid list for workspace [" + wskey + "]");
    try {/*from www  .j  a va2s  .co m*/
        List<String> subjects = membership.getConnectedIdentifierSubjects();

        OrtolangObjectIdentifier identifier = registry.lookup(wskey);
        checkObjectType(identifier, Workspace.OBJECT_TYPE);
        authorisation.checkPermission(wskey, subjects, "read");

        Workspace workspace = em.find(Workspace.class, identifier.getId());
        if (workspace == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + identifier.getId() + "] from storage");
        }
        if (!workspace.containsTagName(tag)) {
            throw new CoreServiceException(
                    "the workspace with key: " + wskey + " does not containt a tag with name: " + tag);
        }
        String snapshot = workspace.findTagByName(tag).getSnapshot();
        String root = workspace.findSnapshotByName(snapshot).getKey();

        Set<OrtolangObjectPid> pids = new HashSet<OrtolangObjectPid>();
        String apiUrlBase = OrtolangConfig.getInstance().getProperty(OrtolangConfig.Property.API_URL_SSL)
                + OrtolangConfig.getInstance().getProperty(OrtolangConfig.Property.API_PATH_CONTENT);
        String marketUrlBase = OrtolangConfig.getInstance()
                .getProperty(OrtolangConfig.Property.MARKET_SERVER_URL) + "market/item";
        buildHandleList(workspace.getAlias(), tag, root, pids, PathBuilder.newInstance(), apiUrlBase,
                marketUrlBase);
        return pids;
    } catch (RegistryServiceException | MembershipServiceException | AuthorisationServiceException
            | KeyNotFoundException | OrtolangException | InvalidPathException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during building workspace pid list", e);
        throw new CoreServiceException("unexpected error while trying to build workspace pid list", e);
    }
}

From source file:com.flexive.ejb.beans.PhraseEngineBean.java

/**
 * {@inheritDoc}// w  ww. j  av a  2s. c  o  m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxPhraseTreeNode loadPhraseTreeNode(int category, long nodeId, long mandatorId, boolean mandator2top,
        long... _mandators) throws FxNotFoundException {
    Connection con = null;
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        return loadPhraseTreeNode(con, true, category, nodeId, mandatorId, mandator2top, _mandators);
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, con, null);
    }
}

From source file:com.flexive.ejb.beans.PhraseEngineBean.java

/**
 * {@inheritDoc}/*from w w  w .ja  v  a 2 s  . c  o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxPhraseTreeNode loadPhraseTreeNode(long nodeId, long mandatorId, boolean mandator2top,
        long... _mandators) throws FxNotFoundException {
    return loadPhraseTreeNode(FxPhraseCategorySelection.CATEGORY_DEFAULT, nodeId, mandatorId, mandator2top,
            _mandators);
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
private void buildHandleList(String wsalias, String tag, String key, Set<OrtolangObjectPid> pids,
        PathBuilder path, String apiUrlBase, String marketUrlBase)
        throws CoreServiceException, KeyNotFoundException, OrtolangException, InvalidPathException {
    try {//from w w w . j  av a  2 s  .com
        OrtolangObject object = findObject(key);
        LOGGER.log(Level.FINE, "Generating pid for key: " + key);
        String target = ((path.isRoot()) ? marketUrlBase : apiUrlBase) + "/" + wsalias + "/" + tag
                + ((path.isRoot()) ? "" : path.build());
        String dynHandle = OrtolangConfig.getInstance().getProperty(OrtolangConfig.Property.HANDLE_PREFIX) + "/"
                + wsalias + ((path.isRoot()) ? "" : path.build());
        String staticHandle = OrtolangConfig.getInstance().getProperty(OrtolangConfig.Property.HANDLE_PREFIX)
                + "/" + wsalias + "/" + tag + ((path.isRoot()) ? "" : path.build());
        OrtolangObjectPid dpid = new OrtolangObjectPid(OrtolangObjectPid.Type.HANDLE, dynHandle, key, target,
                false);
        boolean adddpid = true;
        for (OrtolangObjectPid pid : pids) {
            if (pid.getName().equals(dpid.getName()) && pid.isUserbased()) {
                adddpid = false;
                break;
            }
        }
        if (adddpid) {
            pids.add(dpid);
        }
        OrtolangObjectPid spid = new OrtolangObjectPid(OrtolangObjectPid.Type.HANDLE, staticHandle, key, target,
                false);
        boolean addspid = true;
        for (OrtolangObjectPid pid : pids) {
            if (pid.getName().equals(spid.getName()) && pid.isUserbased()) {
                addspid = false;
                break;
            }
        }
        if (addspid) {
            pids.add(spid);
        }
        if (object instanceof MetadataSource) {
            MetadataElement mde = ((MetadataSource) object).findMetadataByName(MetadataFormat.PID);
            if (mde != null) {
                LOGGER.log(Level.FINE, "PID metadata found, load json and generate corresponding pids");
                MetadataObject md = readMetadataObject(mde.getKey());
                try {
                    JsonReader reader = Json.createReader(binarystore.get(md.getStream()));
                    JsonObject json = reader.readObject();
                    if (json.containsKey("pids")) {
                        JsonArray jpids = json.getJsonArray("pids");
                        for (int i = 0; i < jpids.size(); i++) {
                            JsonObject jpid = jpids.getJsonObject(i);
                            LOGGER.log(Level.FINE, "Generating metadata based pid for key: " + key);
                            String ctarget = ((path.isRoot()) ? marketUrlBase : apiUrlBase) + "/" + wsalias
                                    + "/" + tag + ((path.isRoot()) ? "" : path.build());
                            OrtolangObjectPid upid = new OrtolangObjectPid(OrtolangObjectPid.Type.HANDLE,
                                    jpid.getString("value"), key, ctarget, true);
                            Iterator<OrtolangObjectPid> iter = pids.iterator();
                            while (iter.hasNext()) {
                                OrtolangObjectPid pid = iter.next();
                                if (pid.getName().equals(upid.getName())) {
                                    iter.remove();
                                }
                            }
                            pids.add(upid);
                        }
                    }
                    reader.close();
                } catch (BinaryStoreServiceException | DataNotFoundException e) {
                    LOGGER.log(Level.SEVERE, "unable to read pid metadata", e);
                }
            }
        }
        if (object instanceof Collection) {
            for (CollectionElement element : ((Collection) object).getElements()) {
                buildHandleList(wsalias, tag, element.getKey(), pids, path.clone().path(element.getName()),
                        apiUrlBase, marketUrlBase);
            }
        }
    } catch (AccessDeniedException e) {
        LOGGER.log(Level.INFO, "Unable to generate a PID for an object that has been set private.");
    }
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Map<String, String> listWorkspaceContent(String wskey, String snapshot) throws CoreServiceException {
    LOGGER.log(Level.FINE, "listing content of workspace [" + wskey + "]");
    try {//from w  ww. jav  a  2 s  .  c om
        List<String> subjects = membership.getConnectedIdentifierSubjects();

        OrtolangObjectIdentifier identifier = registry.lookup(wskey);
        checkObjectType(identifier, Workspace.OBJECT_TYPE);
        authorisation.checkPermission(wskey, subjects, "read");

        Workspace workspace = em.find(Workspace.class, identifier.getId());
        if (workspace == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + identifier.getId() + "] from storage");
        }
        String root;
        if (Workspace.HEAD.equals(snapshot)) {
            root = workspace.getHead();
        } else {
            if (!workspace.containsSnapshotName(snapshot)) {
                throw new CoreServiceException("the workspace with key: " + wskey
                        + " does not contain a snapshot with name: " + snapshot);
            }
            root = workspace.findSnapshotByName(snapshot).getKey();
        }

        return listCollectionContent(root).getPathKeyMap();
    } catch (RegistryServiceException | MembershipServiceException | AuthorisationServiceException
            | KeyNotFoundException | OrtolangException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during listing workspace content", e);
        throw new CoreServiceException("unexpected error while trying to list workspace content", e);
    }
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
private void listContent(String key, PathBuilder path, CollectionContent collectionContent)
        throws OrtolangException, InvalidPathException {
    OrtolangObject object = findObject(key);
    collectionContent.add(object, path.build());
    if (object instanceof Collection) {
        for (CollectionElement element : ((Collection) object).getElements()) {
            listContent(element.getKey(), path.clone().path(element.getName()), collectionContent);
        }//from   w w  w.  java 2  s .c o m
    }
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
private CollectionWrapper getWorkspaceContentTree(String key, PathBuilder path, CollectionWrapper parent)
        throws KeyNotFoundException, InvalidPathException, RegistryServiceException {
    OrtolangObjectIdentifier identifier = registry.lookup(key);
    OrtolangObjectWrapper ortolangObjectWrapper;
    switch (identifier.getType()) {
    case Collection.OBJECT_TYPE:
        Collection collection = em.find(Collection.class, identifier.getId());
        ortolangObjectWrapper = OrtolangObjectWrapper.fromOrtolangObject(collection, path.build());
        for (CollectionElement element : collection.getElements()) {
            getWorkspaceContentTree(element.getKey(), path.clone().path(element.getName()),
                    (CollectionWrapper) ortolangObjectWrapper);
        }//from   w ww . ja  v  a  2 s .c om
        if (parent != null) {
            parent.addChild(ortolangObjectWrapper);
        }
        return (CollectionWrapper) ortolangObjectWrapper;
    case DataObject.OBJECT_TYPE:
        DataObject dataObject = em.find(DataObject.class, identifier.getId());
        ortolangObjectWrapper = OrtolangObjectWrapper.fromOrtolangObject(dataObject, path.build());
        parent.addChild(ortolangObjectWrapper);
        break;
    case Link.OBJECT_TYPE:
        Link link = em.find(Link.class, identifier.getId());
        ortolangObjectWrapper = OrtolangObjectWrapper.fromOrtolangObject(link, path.build());
        parent.addChild(ortolangObjectWrapper);
        break;
    }
    return null;
}

From source file:fr.ortolang.diffusion.core.CoreServiceBean.java

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<Change> diffWorkspaceContent(String wskey, String lsnapshot, String rsnapshot)
        throws CoreServiceException {
    LOGGER.log(Level.FINE, "diff content of workspace [" + wskey + "] between snapshots [" + lsnapshot
            + "] and [" + rsnapshot + "]");
    try {//from  www .  ja  v a 2s .  c o  m
        List<String> subjects = membership.getConnectedIdentifierSubjects();

        OrtolangObjectIdentifier identifier = registry.lookup(wskey);
        checkObjectType(identifier, Workspace.OBJECT_TYPE);
        authorisation.checkPermission(wskey, subjects, "read");

        Workspace workspace = em.find(Workspace.class, identifier.getId());
        if (workspace == null) {
            throw new CoreServiceException(
                    "unable to load workspace with id [" + identifier.getId() + "] from storage");
        }
        String lroot;
        if (lsnapshot.equals(Workspace.HEAD)) {
            lroot = workspace.getHead();
        } else {
            if (!workspace.containsSnapshotName(lsnapshot)) {
                throw new CoreServiceException("the workspace with key: " + wskey
                        + " does not containt a snapshot with name: " + lsnapshot);
            }
            lroot = workspace.findSnapshotByName(lsnapshot).getKey();
        }
        String rroot;
        if (rsnapshot.equals(Workspace.HEAD)) {
            rroot = workspace.getHead();
        } else {
            if (!workspace.containsSnapshotName(rsnapshot)) {
                throw new CoreServiceException("the workspace with key: " + wskey
                        + " does not containt a snapshot with name: " + rsnapshot);
            }
            rroot = workspace.findSnapshotByName(rsnapshot).getKey();
        }

        CollectionWrapper lcontent = getWorkspaceContentTree(lroot, PathBuilder.newInstance(), null);
        CollectionWrapper rcontent = getWorkspaceContentTree(rroot, PathBuilder.newInstance(), null);

        Javers javers = JaversBuilder.javers().build();
        Diff diff = javers.compare(lcontent, rcontent);

        return diff.getChanges();

    } catch (RegistryServiceException | MembershipServiceException | AuthorisationServiceException
            | KeyNotFoundException | OrtolangException | InvalidPathException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during diff workspace content", e);
        throw new CoreServiceException("unexpected error while trying to diff workspace content", e);
    }
}

From source file:com.flexive.ejb.beans.AccountEngineBean.java

/**
 * {@inheritDoc}/*from www.  j  a va  2s  . co m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<Account> getAssignedUsers(long groupId, int startIdx, int maxEntries)
        throws FxApplicationException {

    final UserTicket ticket = FxContext.getUserTicket();

    // Load the requested group
    final UserGroup theGroup = CacheAdmin.getEnvironment().getUserGroup(groupId);

    long[] groups = { theGroup.getId() };

    // Return the users from ALL mandators assigned to the group if the caller is GLOBAL_SUPERVISOR.
    // Else only look for users within the callers mandator.
    Long mandatorId = ticket.isGlobalSupervisor() ? -1 : ticket.getMandatorId();

    // Load the users

    return loadAll(null, null, null, null, null, mandatorId, null, groups, startIdx, maxEntries);
}