Search in sources :

Example 1 with SimpleClient

use of io.jans.orm.sql.model.SimpleClient in project jans by JanssenProject.

the class SqlBatchJobSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SqlEntryManagerSample sqlEntryManagerSample = new SqlEntryManagerSample();
    // Create SQL entry manager
    final SqlEntryManager sqlEntryManager = sqlEntryManagerSample.createSqlEntryManager();
    BatchOperation<SimpleToken> tokenSQLBatchOperation = new ProcessBatchOperation<SimpleToken>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleToken> objects) {
            for (SimpleToken simpleTokenSQL : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(sqlEntryManager, simpleTokenSQL.getDn(), "exp", simpleTokenSQL.getAttribute("exp"));
                    simpleTokenSQL.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    sqlEntryManager.merge(simpleTokenSQL);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed tokens: " + processedCount);
        }
    };
    final Filter filter1 = Filter.createPresenceFilter("exp");
    sqlEntryManager.findEntries("o=jans", SimpleToken.class, filter1, SearchScope.SUB, new String[] { "exp" }, tokenSQLBatchOperation, 0, 0, 100);
    BatchOperation<SimpleSession> sessionBatchOperation = new ProcessBatchOperation<SimpleSession>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleSession> objects) {
            int currentProcessedCount = 0;
            for (SimpleSession simpleSession : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(sqlEntryManager, simpleSession.getDn(), "jansLastAccessTime", simpleSession.getAttribute("jansLastAccessTime"));
                    simpleSession.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    sqlEntryManager.merge(simpleSession);
                    processedCount++;
                    currentProcessedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Currnet batch count processed sessions: " + currentProcessedCount);
            LOG.info("Total processed sessions: " + processedCount);
        }
    };
    final Filter filter2 = Filter.createPresenceFilter("jansLastAccessTime");
    sqlEntryManager.findEntries("o=jans", SimpleSession.class, filter2, SearchScope.SUB, new String[] { "jansLastAccessTime" }, sessionBatchOperation, 0, 0, 100);
    BatchOperation<SimpleClient> clientBatchOperation = new ProcessBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed clients: " + processedCount);
        }
    };
    final Filter filter3 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result3 = sqlEntryManager.findEntries("o=jans", SimpleClient.class, filter3, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation, 0, 0, 1000);
    LOG.info("Result count (without collecting results): " + result3.size());
    BatchOperation<SimpleClient> clientBatchOperation2 = new DefaultBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed clients: " + processedCount);
        }
    };
    final Filter filter4 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result4 = sqlEntryManager.findEntries("o=jans", SimpleClient.class, filter4, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation2, 0, 0, 1000);
    LOG.info("Result count (with collecting results): " + result4.size());
}
Also used : CustomAttribute(io.jans.orm.model.base.CustomAttribute) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) DefaultBatchOperation(io.jans.orm.model.DefaultBatchOperation) SqlEntryManagerSample(io.jans.orm.sql.persistence.SqlEntryManagerSample) SqlEntryManager(io.jans.orm.sql.impl.SqlEntryManager) Filter(io.jans.orm.search.filter.Filter) ProcessBatchOperation(io.jans.orm.model.ProcessBatchOperation) List(java.util.List) SimpleClient(io.jans.orm.sql.model.SimpleClient) SimpleSession(io.jans.orm.sql.model.SimpleSession) SimpleToken(io.jans.orm.sql.model.SimpleToken)

Example 2 with SimpleClient

use of io.jans.orm.sql.model.SimpleClient in project jans by JanssenProject.

the class SqlSimpleClientSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SqlEntryManagerSample sqlEntryManagerSample = new SqlEntryManagerSample();
    // Create SQL entry manager
    SqlEntryManager sqlEntryManager = sqlEntryManagerSample.createSqlEntryManager();
    SimpleClient newClient = new SimpleClient();
    newClient.setDn("inum=test_clnt2,ou=client,o=gluu");
    newClient.setDefaultAcrValues(new String[] { "test_clnt2_acr" });
    newClient.setClientName("test_clnt2");
    sqlEntryManager.persist(newClient);
    Filter presenceFilter = Filter.createEqualityFilter("displayName", "test_clnt2");
    List<SimpleClient> results = sqlEntryManager.findEntries("ou=test_clnt2,o=gluu", SimpleClient.class, presenceFilter);
    for (SimpleClient client : results) {
        String[] acrs = client.getDefaultAcrValues();
        if (ArrayHelper.isNotEmpty(acrs)) {
            System.out.println(Arrays.toString(acrs));
        }
    }
    sqlEntryManager.remove(newClient.getDn(), SimpleClient.class);
}
Also used : Filter(io.jans.orm.search.filter.Filter) SimpleClient(io.jans.orm.sql.model.SimpleClient) SqlEntryManagerSample(io.jans.orm.sql.persistence.SqlEntryManagerSample) SqlEntryManager(io.jans.orm.sql.impl.SqlEntryManager)

Example 3 with SimpleClient

use of io.jans.orm.sql.model.SimpleClient in project jans by JanssenProject.

the class SqlSimpleClientWithDeleteNotifierSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SqlEntryManagerSample sqlEntryManagerSample = new SqlEntryManagerSample();
    // Create SQL entry manager
    SqlEntryManager sqlEntryManager = sqlEntryManagerSample.createSqlEntryManager();
    sqlEntryManager.addDeleteSubscriber(new DeleteNotifier() {

        @Override
        public void onBeforeRemove(String dn, String[] objectClasses) {
            System.out.println(Arrays.asList(objectClasses));
            System.out.println(sqlEntryManager.exportEntry(dn, objectClasses[0]));
        }

        @Override
        public void onAfterRemove(String dn, String[] objectClasses) {
            System.out.println(Arrays.asList(objectClasses));
        }
    });
    SimpleClient newClient = new SimpleClient();
    newClient.setDn("inum=test_clnt3,ou=client,o=gluu");
    newClient.setDefaultAcrValues(new String[] { "test_clnt3_acr" });
    newClient.setClientName("test_clnt3");
    sqlEntryManager.persist(newClient);
    Filter presenceFilter = Filter.createEqualityFilter("displayName", "test_clnt3");
    List<SimpleClient> results = sqlEntryManager.findEntries("ou=test_clnt3,o=gluu", SimpleClient.class, presenceFilter);
    for (SimpleClient client : results) {
        String[] acrs = client.getDefaultAcrValues();
        if (ArrayHelper.isNotEmpty(acrs)) {
            System.out.println(Arrays.toString(acrs));
        }
    }
    sqlEntryManager.remove(newClient.getDn(), SimpleClient.class);
}
Also used : Filter(io.jans.orm.search.filter.Filter) DeleteNotifier(io.jans.orm.event.DeleteNotifier) SimpleClient(io.jans.orm.sql.model.SimpleClient) SqlEntryManagerSample(io.jans.orm.sql.persistence.SqlEntryManagerSample) SqlEntryManager(io.jans.orm.sql.impl.SqlEntryManager)

Aggregations

Filter (io.jans.orm.search.filter.Filter)3 SqlEntryManager (io.jans.orm.sql.impl.SqlEntryManager)3 SimpleClient (io.jans.orm.sql.model.SimpleClient)3 SqlEntryManagerSample (io.jans.orm.sql.persistence.SqlEntryManagerSample)3 DeleteNotifier (io.jans.orm.event.DeleteNotifier)1 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)1 DefaultBatchOperation (io.jans.orm.model.DefaultBatchOperation)1 ProcessBatchOperation (io.jans.orm.model.ProcessBatchOperation)1 CustomAttribute (io.jans.orm.model.base.CustomAttribute)1 SimpleSession (io.jans.orm.sql.model.SimpleSession)1 SimpleToken (io.jans.orm.sql.model.SimpleToken)1 List (java.util.List)1