Search in sources :

Example 1 with DeleteNotifier

use of io.jans.orm.event.DeleteNotifier 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

DeleteNotifier (io.jans.orm.event.DeleteNotifier)1 Filter (io.jans.orm.search.filter.Filter)1 SqlEntryManager (io.jans.orm.sql.impl.SqlEntryManager)1 SimpleClient (io.jans.orm.sql.model.SimpleClient)1 SqlEntryManagerSample (io.jans.orm.sql.persistence.SqlEntryManagerSample)1