Search in sources :

Example 1 with CouchbaseEntryManager

use of io.jans.orm.couchbase.impl.CouchbaseEntryManager in project jans by JanssenProject.

the class CouchbaseNativeBenchmarkCacheTest method createCouchbaseEntryManager.

private CouchbaseEntryManager createCouchbaseEntryManager() {
    CouchbaseEntryManagerFactory couchbaseEntryManagerFactory = new CouchbaseEntryManagerFactory();
    couchbaseEntryManagerFactory.create();
    Properties connectionProperties = getSampleConnectionProperties();
    CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerFactory.createEntryManager(connectionProperties);
    System.out.println("Created CouchbaseEntryManager: " + couchbaseEntryManager);
    return couchbaseEntryManager;
}
Also used : CouchbaseEntryManagerFactory(io.jans.orm.couchbase.impl.CouchbaseEntryManagerFactory) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager)

Example 2 with CouchbaseEntryManager

use of io.jans.orm.couchbase.impl.CouchbaseEntryManager in project jans by JanssenProject.

the class CouchbaseBatchJobSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
    // Create Couchbase entry manager
    final CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
    BatchOperation<SimpleTokenCouchbase> tokenCouchbaseBatchOperation = new ProcessBatchOperation<SimpleTokenCouchbase>() {

        private int processedCount = 0;

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

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleSession> objects) {
            for (SimpleSession simpleSession : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(couchbaseEntryManager, simpleSession.getDn(), "jansLastAccessTime", simpleSession.getAttribute("jansLastAccessTime"));
                    simpleSession.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    couchbaseEntryManager.merge(simpleSession);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter2 = Filter.createPresenceFilter("jansLastAccessTime");
    couchbaseEntryManager.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: " + processedCount);
        }
    };
    final Filter filter3 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result3 = couchbaseEntryManager.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: " + processedCount);
        }
    };
    final Filter filter4 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result4 = couchbaseEntryManager.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 : SimpleTokenCouchbase(io.jans.orm.couchbase.model.SimpleTokenCouchbase) CustomAttribute(io.jans.orm.model.base.CustomAttribute) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) DefaultBatchOperation(io.jans.orm.model.DefaultBatchOperation) Filter(io.jans.orm.search.filter.Filter) ProcessBatchOperation(io.jans.orm.model.ProcessBatchOperation) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) List(java.util.List) SimpleClient(io.jans.orm.couchbase.model.SimpleClient) SimpleSession(io.jans.orm.couchbase.model.SimpleSession)

Example 3 with CouchbaseEntryManager

use of io.jans.orm.couchbase.impl.CouchbaseEntryManager in project jans by JanssenProject.

the class CouchbaseCustomMultiValuedTypesSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
    // Create Couchbase entry manager
    CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
    // Add dummy user
    SimpleUser newUser = new SimpleUser();
    newUser.setDn(String.format("inum=%s,ou=people,o=jans", System.currentTimeMillis()));
    newUser.setUserId("sample_user_" + System.currentTimeMillis());
    newUser.setUserPassword("test");
    newUser.getCustomAttributes().add(new CustomObjectAttribute("streetAddress", Arrays.asList("London", "Texas", "Kiev")));
    newUser.getCustomAttributes().add(new CustomObjectAttribute("test", "test_value"));
    newUser.getCustomAttributes().add(new CustomObjectAttribute("fuzzy", "test_value"));
    newUser.setMemberOf(Arrays.asList("group_1", "group_2", "group_3"));
    newUser.setAttributeValue("givenName", "john");
    couchbaseEntryManager.persist(newUser);
    LOG.info("Added User '{}' with uid '{}' and key '{}'", newUser, newUser.getUserId(), newUser.getDn());
    LOG.info("Persisted custom attributes '{}'", newUser.getCustomAttributes());
    // Find added dummy user
    SimpleUser foundUser = couchbaseEntryManager.find(SimpleUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUser, foundUser.getUserId(), foundUser.getDn());
    LOG.info("Custom attributes '{}'", foundUser.getCustomAttributes());
    // Update custom attributes
    foundUser.setAttributeValues("streetAddress", Arrays.asList("London", "Texas", "Kiev", "Dublin"));
    foundUser.setAttributeValues("test", Arrays.asList("test_value_1", "test_value_2", "test_value_3", "test_value_4"));
    foundUser.setAttributeValues("fuzzy", Arrays.asList("fuzzy_value_1", "fuzzy_value_2"));
    foundUser.setAttributeValue("simple", "simple");
    CustomObjectAttribute multiValuedSingleValue = new CustomObjectAttribute("multivalued", "multivalued_single_valued");
    multiValuedSingleValue.setMultiValued(true);
    foundUser.getCustomAttributes().add(multiValuedSingleValue);
    couchbaseEntryManager.merge(foundUser);
    LOG.info("Updated custom attributes '{}'", foundUser.getCustomAttributes());
    // Find updated dummy user
    SimpleUser foundUpdatedUser = couchbaseEntryManager.find(SimpleUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUpdatedUser, foundUpdatedUser.getUserId(), foundUpdatedUser.getDn());
    LOG.info("Cusom attributes '{}'", foundUpdatedUser.getCustomAttributes());
    Filter filter = Filter.createEqualityFilter(Filter.createLowercaseFilter("givenName"), StringHelper.toLowerCase("jon"));
    List<SimpleUser> foundUpdatedUsers = couchbaseEntryManager.findEntries("o=jans", SimpleUser.class, filter);
    System.out.println(foundUpdatedUsers);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) SimpleUser(io.jans.orm.couchbase.model.SimpleUser) Filter(io.jans.orm.search.filter.Filter) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager)

Example 4 with CouchbaseEntryManager

use of io.jans.orm.couchbase.impl.CouchbaseEntryManager in project jans by JanssenProject.

the class CouchbaseCustomStringAttributesSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    CouchbaseEntryManagerSample couchbaseEntryManagerSample = new CouchbaseEntryManagerSample();
    // Create Couchbase entry manager
    CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerSample.createCouchbaseEntryManager();
    String randomExternalUid = "otp:" + System.currentTimeMillis();
    // Add dummy user
    SimpleCustomStringUser newUser = new SimpleCustomStringUser();
    newUser.setDn(String.format("inum=%s,ou=people,o=jans", System.currentTimeMillis()));
    newUser.setUserId("sample_user_" + System.currentTimeMillis());
    newUser.setUserPassword("test");
    newUser.getCustomAttributes().add(new CustomAttribute("streetAddress", Arrays.asList("London", "Texas", "Kiev")));
    newUser.getCustomAttributes().add((new CustomAttribute("jansExternalUid", randomExternalUid)).setMultiValued(true));
    newUser.setUserRole(UserRole.ADMIN);
    newUser.setNotes(Arrays.asList("note 1", "note 2", "note 3"));
    couchbaseEntryManager.persist(newUser);
    LOG.info("Added User '{}' with uid '{}' and key '{}'", newUser, newUser.getUserId(), newUser.getDn());
    // Find added dummy user but use custom class with String values
    SimpleCustomStringUser foundUser = couchbaseEntryManager.find(SimpleCustomStringUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUser, foundUser.getUserId(), foundUser.getDn());
    LOG.info("Custom attributes '{}'", foundUser.getCustomAttributes());
    for (CustomAttribute customAttribute : foundUser.getCustomAttributes()) {
        LOG.info("Found custom attribute '{}' with value '{}'", customAttribute.getName(), customAttribute.getValue());
    }
    // Find by jsExternalUid
    Filter jsExternalUidFilter = Filter.createEqualityFilter("jansExternalUid", randomExternalUid).multiValued();
    List<SimpleCustomStringUser> foundUsers = couchbaseEntryManager.findEntries("ou=people,o=jans", SimpleCustomStringUser.class, jsExternalUidFilter);
    for (SimpleCustomStringUser foundUser2 : foundUsers) {
        LOG.info("Found User '{}' by jsExternalUid with uid '{}' and key '{}'", foundUser2, foundUser2.getUserId(), foundUser2.getDn());
    }
}
Also used : Filter(io.jans.orm.search.filter.Filter) CustomAttribute(io.jans.orm.model.base.CustomAttribute) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) SimpleCustomStringUser(io.jans.orm.couchbase.model.SimpleCustomStringUser)

Example 5 with CouchbaseEntryManager

use of io.jans.orm.couchbase.impl.CouchbaseEntryManager in project jans by JanssenProject.

the class CouchbaseEntryManagerSample method createCouchbaseEntryManager.

public CouchbaseEntryManager createCouchbaseEntryManager() {
    CouchbaseEntryManagerFactory couchbaseEntryManagerFactory = new CouchbaseEntryManagerFactory();
    couchbaseEntryManagerFactory.create();
    Properties connectionProperties = getSampleConnectionProperties();
    CouchbaseEntryManager couchbaseEntryManager = couchbaseEntryManagerFactory.createEntryManager(connectionProperties);
    LOG.debug("Created CouchbaseEntryManager: " + couchbaseEntryManager);
    return couchbaseEntryManager;
}
Also used : CouchbaseEntryManagerFactory(io.jans.orm.couchbase.impl.CouchbaseEntryManagerFactory) CouchbaseEntryManager(io.jans.orm.couchbase.impl.CouchbaseEntryManager) Properties(java.util.Properties)

Aggregations

CouchbaseEntryManager (io.jans.orm.couchbase.impl.CouchbaseEntryManager)16 Filter (io.jans.orm.search.filter.Filter)8 SimpleUser (io.jans.orm.couchbase.model.SimpleUser)5 Date (java.util.Date)5 CouchbaseEntryManagerFactory (io.jans.orm.couchbase.impl.CouchbaseEntryManagerFactory)3 CustomAttribute (io.jans.orm.model.base.CustomAttribute)3 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)3 SimpleClient (io.jans.orm.couchbase.model.SimpleClient)2 SimpleSession (io.jans.orm.couchbase.model.SimpleSession)2 SimpleSessionState (io.jans.orm.couchbase.model.SimpleSessionState)2 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 Test (org.testng.annotations.Test)2 Lookup (com.couchbase.client.core.message.kv.subdoc.multi.Lookup)1 Bucket (com.couchbase.client.java.Bucket)1 JsonDocument (com.couchbase.client.java.document.JsonDocument)1 SubdocOptionsBuilder (com.couchbase.client.java.subdoc.SubdocOptionsBuilder)1 SimpleAttribute (io.jans.orm.couchbase.model.SimpleAttribute)1 SimpleCustomStringUser (io.jans.orm.couchbase.model.SimpleCustomStringUser)1