Package org.ff4j.core

Examples of org.ff4j.core.Feature


    }

    /** {@inheritDoc} */
    @Override
    public Feature read(String featureUid) {
        Feature fp = getCacheManager().get(featureUid);
        // not in cache but may has been created from now
        if (null == fp) {
            fp = getTarget().read(featureUid);
            getCacheManager().put(fp);
        }
View Full Code Here


    }
   
    /** {@inheritDoc} */
    @Override
    public void enable(String uid) {
        Feature f = read(uid);
        f.enable();
        update(f);
    }
View Full Code Here

    }

    /** {@inheritDoc} */
    @Override
    public void disable(String uid) {
        Feature f = read(uid);
        f.disable();
        update(f);
    }
View Full Code Here

        Set<String> rights2 = new HashSet<String>(Arrays.asList(new String[] {ROLE_USER,ROLE_ADMIN}));
        // Given
        assertFf4j.assertThatFeatureExist(F1);
        assertFf4j.assertThatFeatureHasNotRole(F1, ROLE_ADMIN);
        // When
        Feature fpBis = testedStore.read(F1);
        fpBis.setPermissions(rights2);
        testedStore.update(fpBis);
        // Then
        assertFf4j.assertThatFeatureHasRole(F1, ROLE_USER);
        assertFf4j.assertThatFeatureHasRole(F1, ROLE_ADMIN);
    }
View Full Code Here

    public void testUpdateFlipLessAutorisation() {
        // Given
        assertFf4j.assertThatFeatureExist(F1);
        assertFf4j.assertThatFeatureHasRole(F1, ROLE_USER);
        // When
        testedStore.update(new Feature(F1, false, null));
        // Then
        assertFf4j.assertThatFeatureHasNotRole(F1, ROLE_USER);
    }
View Full Code Here

    @Test
    public void testUpdateFlipMoreAutorisationNotExist() {
        // Given
        assertFf4j.assertThatFeatureHasNotRole(F1, ROLE_NEW);
        Set<String> rights2 = new HashSet<String>(Arrays.asList(new String[] {ROLE_USER,ROLE_NEW}));
        Feature fpBis = new Feature(F1, false, G1, "desci2", rights2);
        // When
        testedStore.update(fpBis);
        // Then
        assertFf4j.assertThatFeatureHasRole(F1, ROLE_USER);
        assertFf4j.assertThatFeatureHasRole(F1, ROLE_NEW);
View Full Code Here

        ResultSet rs = null;
        try {
            // Returns features
            ps = buildStatement(SQLQUERY_GET_FEATURE_BY_ID, uid);
            rs = ps.executeQuery();
            Feature f = null;
            if (rs.next()) {
                f = mapRow2Feature(rs);
            } else {
                throw new FeatureNotFoundException(uid);
            }

            // 2nd request
            ps = ps.getConnection().prepareStatement(SQL_GET_ROLES);
            ps.setString(1, uid);
            rs = ps.executeQuery();
            while (rs.next()) {
                f.getPermissions().add(rs.getString("ROLE_NAME"));
            }
            return f;
        } catch (SQLException sqlEX) {
            throw new FeatureAccessException("Cannot check feature existence, error related to database", sqlEX);
        } finally {
View Full Code Here

     * @throws SQLException
     *             error accured when parsing resultSet
     */
    private Feature mapRow2Feature(ResultSet rs) throws SQLException {
        // Feature
        Feature f = null;
        boolean enabled = rs.getInt(COL_FEAT_ENABLE) > 0;
        String featUid = rs.getString(COL_FEAT_UID);
        f = new Feature(featUid, enabled, rs.getString(COL_FEAT_DESCRIPTION), rs.getString(COL_FEAT_GROUPNAME));
        // Strategy
        String strategy = rs.getString(COL_FEAT_STRATEGY);
        if (strategy != null && !"".equals(strategy)) {
            try {
                FlippingStrategy flipStrategy = (FlippingStrategy) Class.forName(strategy).newInstance();
                flipStrategy.init(featUid, ParameterUtils.toMap(rs.getString(COL_FEAT_EXPRESSION)));
                f.setFlippingStrategy(flipStrategy);
            } catch (InstantiationException ie) {
                throw new FeatureAccessException("Cannot instantiate Strategy, no default constructor available", ie);
            } catch (IllegalAccessException iae) {
                throw new FeatureAccessException("Cannot instantiate Strategy, no visible constructor", iae);
            } catch (ClassNotFoundException e) {
View Full Code Here

            throw new FeatureNotFoundException(uid);
        }
        Connection sqlConn = null;
        PreparedStatement ps = null;
        try {
            Feature fp = read(uid);

            // Create connection
            sqlConn = getDataSource().getConnection();
            sqlConn.setAutoCommit(false);

            // Delete Roles
            if (fp.getPermissions() != null) {
                for (String role : fp.getPermissions()) {
                    ps = sqlConn.prepareStatement(SQL_DELETE_ROLE);
                    ps.setString(1, fp.getUid());
                    ps.setString(2, role);
                    ps.executeUpdate();
                }
            }

            // Delete Feature
            ps = sqlConn.prepareStatement(SQL_DELETE);
            ps.setString(1, fp.getUid());
            ps.executeUpdate();

            // Commit
            sqlConn.commit();
View Full Code Here

        try {
            // Returns features
            ps = buildStatement(SQLQUERY_ALLFEATURES);
            rs = ps.executeQuery();
            while (rs.next()) {
                Feature f = mapRow2Feature(rs);
                mapFP.put(f.getUid(), f);
            }

            // Returns Roles
            rs = ps.getConnection().prepareStatement(SQL_GET_ALLROLES).executeQuery();
            while (rs.next()) {
View Full Code Here

TOP

Related Classes of org.ff4j.core.Feature

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.