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.ContentEngineBean.java

/**
 * {@inheritDoc}//from  w  w  w. j av a 2  s  . c  o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String exportContent(FxContent content) throws FxApplicationException {
    return ConversionEngine.getXStream().toXML(content);
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public String resolveWorkspaceMetadata(String wskey, String root, String path, String name)
        throws CoreServiceException, InvalidPathException, AccessDeniedException, PathNotFoundException {
    LOGGER.log(Level.FINE, "resolving into workspace [" + wskey + "] and root [" + root
            + "] metadata with name [" + name + "] at path [" + path + "]");
    try {//from  w  w  w .j av a 2 s  .  co m
        String key = resolveWorkspacePath(wskey, root, path);
        MetadataElement cmdelement = loadMetadataElement(name, key);
        if (cmdelement == null) {
            throw new CoreServiceException(
                    "a metadata object with name [" + name + "] does not exists for at path [" + path + "]");
        }
        return cmdelement.getKey();
    } catch (KeyNotFoundException | RegistryServiceException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during resolving metadata", e);
        throw new CoreServiceException("unable to resolve into workspace [" + wskey + "] metadata name [" + name
                + "] at [" + path + "]", e);
    }
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Set<String> buildWorkspaceReviewList(String wskey, String snapshot)
        throws CoreServiceException, AccessDeniedException {
    LOGGER.log(Level.FINE, "building review list for workspace [" + wskey + "]");
    try {//w ww  .jav a2s  . com
        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.containsSnapshotName(snapshot)) {
            throw new CoreServiceException("the workspace with key: " + wskey
                    + " does not containt a snapshot with name: " + snapshot);
        }
        String root = workspace.findSnapshotByName(snapshot).getKey();

        Set<String> keys = new HashSet<String>();
        systemListCollectionKeys(root, keys);
        return keys;
    } catch (RegistryServiceException | MembershipServiceException | AuthorisationServiceException
            | KeyNotFoundException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during building workspace review list", e);
        throw new CoreServiceException("unexpected error while trying to build workspace review list", e);
    }
}

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

@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Map<String, Map<String, List<String>>> buildWorkspacePublicationMap(String wskey, String snapshot)
        throws CoreServiceException {
    LOGGER.log(Level.FINE, "building publication map for workspace [" + wskey + "]");
    try {/*from w ww.  j a  va  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");
        }
        if (!workspace.containsSnapshotName(snapshot)) {
            throw new CoreServiceException(
                    "the workspace with key: " + wskey + " does not contain a snapshot with name: " + snapshot);
        }
        String root = workspace.findSnapshotByName(snapshot).getKey();

        Map<String, Map<String, List<String>>> map = new HashMap<String, Map<String, List<String>>>();

        AuthorisationPolicyTemplate defaultTemplate = authorisation
                .getPolicyTemplate(AuthorisationPolicyTemplate.DEFAULT);
        Map<String, String> aclParams = new HashMap<String, String>();
        aclParams.put("${workspace.members}", workspace.getMembers());
        if (workspace.getPrivileged() != "") {
            aclParams.put("${workspace.privileged}", workspace.getPrivileged());
        }
        builtPublicationMap(root, map, authorisation.getPolicyRules(defaultTemplate.getTemplate()), aclParams);
        return map;
    } catch (RegistryServiceException | MembershipServiceException | AuthorisationServiceException
            | KeyNotFoundException | OrtolangException e) {
        LOGGER.log(Level.SEVERE, "unexpected error occurred during building workspace publication map", e);
        throw new CoreServiceException("unexpected error while trying to build workspace publication map", e);
    }
}

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

/**
 * {@inheritDoc}/*ww  w. ja v a 2s .c  o  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<FxPhraseTreeNode> loadPhraseTree(boolean mandator2top, long... _mandators) {
    return loadPhraseTree(FxPhraseCategorySelection.CATEGORY_DEFAULT, mandator2top, _mandators);
}

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

/**
 * {@inheritDoc}/*from w ww  .j ava 2 s.co  m*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public List<FxPhraseTreeNode> loadPhraseTree(int category, boolean mandator2top, long... _mandators) {
    Connection con = null;
    PreparedStatement ps = null;
    PreparedStatement psPhrase = null;
    long[] mandators = checkMandatorFiltering(_mandators);
    if (mandators.length == 2 && mandator2top) {
        long tmp = mandators[0];
        mandators[0] = mandators[1];
        mandators[1] = tmp;
    }
    //load the node's phrase to check if it exists
    try {
        // Obtain a database connection
        con = Database.getDbConnection();
        List<FxPhraseTreeNode> nodes = Lists.newArrayListWithExpectedSize(5);
        //                                1  2        3        4              5        6         7   8
        ps = con.prepareStatement("SELECT ID,MANDATOR,PARENTID,PARENTMANDATOR,PHRASEID,PMANDATOR,POS,CAT FROM "
                + TBL_PHRASE_TREE
                + " WHERE MANDATOR=? AND CAT=? AND PARENTID IS NULL AND PARENTMANDATOR IS NULL ORDER BY POS");
        /* 1 .. id 2 .. lang 3 .. val 4 .. tag 5 .. mandator 6 .. key 7 .. hidden 8 .. category*/
        psPhrase = con.prepareStatement("SELECT p.ID,v.LANG,v.PVAL,v.TAG,p.MANDATOR,p.PKEY,p.HID,p.CAT FROM "
                + TBL_PHRASE + " p, " + TBL_PHRASE_VALUES
                + " v WHERE p.ID=? AND p.MANDATOR=? AND v.ID=p.ID AND v.MANDATOR=p.MANDATOR");
        ps.setInt(2, category);
        for (long mandator : mandators) {
            ps.setLong(1, mandator);
            ResultSet rs = ps.executeQuery();
            while (rs != null && rs.next()) {
                psPhrase.setLong(1, rs.getLong(5));
                psPhrase.setLong(2, rs.getLong(6));
                ResultSet rsPhrase = psPhrase.executeQuery();
                if (rsPhrase == null || !rsPhrase.next())
                    throw new FxNotFoundException("ex.phrases.notFound.id", rs.getLong(5), rs.getLong(6))
                            .asRuntimeException();
                nodes.add(new FxPhraseTreeNode(rs.getLong(1), rs.getLong(2), rs.getInt(8),
                        FxPhraseTreeNode.NOT_SET, FxPhraseTreeNode.NOT_SET, loadPhrase(rsPhrase), null)
                                .setPos(rs.getLong(7)));
                rsPhrase.close();
            }
            if (rs != null)
                rs.close();
        }
        if (nodes.size() > 0) {
            ps.close();
            ps = con.prepareStatement(
                    "SELECT ID,MANDATOR,PARENTID,PARENTMANDATOR,PHRASEID,PMANDATOR,POS,CAT FROM "
                            + TBL_PHRASE_TREE
                            + " WHERE MANDATOR=? AND PARENTID=? AND PARENTMANDATOR=? AND CAT=? ORDER BY POS");
            ps.setInt(4, category);
            for (FxPhraseTreeNode node : nodes)
                loadChildren(node, mandators, ps, psPhrase);
        }
        return nodes;
    } catch (SQLException exc) {
        EJBUtils.rollback(ctx);
        throw new FxDbException(LOG, exc, "ex.db.sqlError", exc.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(PhraseEngineBean.class, psPhrase);
        Database.closeObjects(PhraseEngineBean.class, con, ps);
    }
}

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

/**
 * {@inheritDoc}/*from w ww.j  a va2 s  .com*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxLock getLock(FxPK pk) {
    Connection con = null;
    try {
        con = Database.getDbConnection();
        FxCachedContent cachedContent = CacheAdmin.getCachedContent(pk);
        if (cachedContent != null)
            return cachedContent.getContent().getLock();
        return StorageManager.getLockStorage().getLock(con, pk);
    } catch (SQLException e) {
        //noinspection ThrowableInstanceNeverThrown
        throw new FxLockException(e, "ex.db.sqlError", e.getMessage()).asRuntimeException();
    } catch (FxNotFoundException e) {
        throw e.asRuntimeException();
    } catch (FxLockException e) {
        throw e.asRuntimeException();
    } finally {
        Database.closeObjects(ContentEngineBean.class, con, null);
    }
}

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

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
private void builtPublicationMap(String key, Map<String, Map<String, List<String>>> map,
        Map<String, List<String>> current, Map<String, String> params)
        throws KeyNotFoundException, CoreServiceException, OrtolangException {
    Object object = readObject(key);
    if (object instanceof MetadataSource) {
        MetadataElement mde = ((MetadataSource) object).findMetadataByName(MetadataFormat.ACL);
        if (mde != null) {
            LOGGER.log(Level.FINE, "ACL metadata found, load json, find policy template and render it...");
            MetadataObject md = (MetadataObject) readObject(mde.getKey());
            try {
                JsonReader reader = Json.createReader(binarystore.get(md.getStream()));
                JsonObject json = reader.readObject();
                String template = json.getString("template");
                reader.close();/*  w  w  w.j a v a  2s.com*/
                AuthorisationPolicyTemplate policy = authorisation.getPolicyTemplate(template);
                Map<String, List<String>> rules = authorisation.getPolicyRules(policy.getTemplate());
                Map<String, List<String>> filtered = new HashMap<String, List<String>>();
                for (Entry<String, List<String>> entry : rules.entrySet()) {
                    if (params.containsKey(entry.getKey())) {
                        filtered.put(params.get(entry.getKey()), entry.getValue());
                    } else {
                        filtered.put(entry.getKey(), entry.getValue());
                    }
                }
                current = filtered;
            } catch (AuthorisationServiceException | BinaryStoreServiceException | DataNotFoundException e) {
                LOGGER.log(Level.SEVERE, "unable to read acl metadata", e);
            }
        }
    }
    map.put(key, current);
    if (object instanceof MetadataSource) {
        for (MetadataElement element : ((MetadataSource) object).getMetadatas()) {
            map.put(element.getKey(), current);
        }
    }
    if (object instanceof Collection) {
        for (CollectionElement element : ((Collection) object).getElements()) {
            builtPublicationMap(element.getKey(), map, current, params);
        }
    }
}

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

/**
 * {@inheritDoc}/* w  ww  . j a v  a 2s .  com*/
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public FxScriptResult runScript(String name, FxScriptBinding binding, String code)
        throws FxApplicationException {
    FxPermissionUtils.checkRole(FxContext.getUserTicket(), Role.ScriptExecution);
    return LocalScriptingCache.internal_runScript(name, binding, code);
}

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

/**
 * {@inheritDoc}//from  ww w  .j  a  v  a2s . c  o m
 */
@Override
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public int getAccountMatches(String name, String loginName, String email, Boolean isActive, Boolean isConfirmed,
        Long mandatorId, int[] isInRole, long[] isInGroup) throws FxApplicationException {

    Connection con = null;
    Statement stmt = null;
    final UserTicket ticket = FxContext.getUserTicket();
    String curSql = _buildSearchStmt(ticket, name, loginName, email, isActive, isConfirmed, mandatorId,
            isInRole, isInGroup, true);
    try {
        // Obtain a database connection
        con = Database.getDbConnection();

        // Load the users
        stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(curSql);
        if (rs != null && rs.next())
            return rs.getInt(1);
        return -1;

    } catch (SQLException exc) {
        throw new FxLoadException(LOG, exc, "ex.account.loadAll.failed.sql", exc.getMessage(), curSql);
    } finally {
        Database.closeObjects(AccountEngineBean.class, con, stmt);
    }
}