Search in sources :

Example 6 with SpannerEntryManager

use of io.jans.orm.cloud.spanner.impl.SpannerEntryManager in project jans by JanssenProject.

the class SpannerUpateMissingEntrySample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SpannerEntryManagerSample sqlEntryManagerSample = new SpannerEntryManagerSample();
    // Create SQL entry manager
    SpannerEntryManager sqlEntryManager = sqlEntryManagerSample.createSpannerEntryManager();
    String sessionId = UUID.randomUUID().toString();
    final String sessionDn = "uniqueIdentifier=" + sessionId + ",ou=session,o=jans";
    final SimpleSessionState simpleSessionState = new SimpleSessionState();
    simpleSessionState.setDn(sessionDn);
    simpleSessionState.setId(sessionId);
    simpleSessionState.setLastUsedAt(new Date());
    try {
        sqlEntryManager.merge(simpleSessionState);
        System.out.println("Updated");
    } catch (EntryPersistenceException ex) {
        LOG.info("Failed to update, root case exception: {}", ex.getCause().getClass(), ex);
    }
}
Also used : SimpleSessionState(io.jans.orm.cloud.spanner.model.SimpleSessionState) SpannerEntryManagerSample(io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) Date(java.util.Date) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Example 7 with SpannerEntryManager

use of io.jans.orm.cloud.spanner.impl.SpannerEntryManager in project jans by JanssenProject.

the class SpannerCustomMultiValuedTypesSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SpannerEntryManagerSample sqlEntryManagerSample = new SpannerEntryManagerSample();
    // Create SQL entry manager
    SpannerEntryManager sqlEntryManager = sqlEntryManagerSample.createSpannerEntryManager();
    // 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("jansOptOuts", Arrays.asList("London", "Texas", "Kiev")));
    newUser.getCustomAttributes().add(new CustomObjectAttribute("jansExtUid", "test_value").multiValued());
    newUser.getCustomAttributes().add(new CustomObjectAttribute("jansPPID", "test_value").multiValued());
    newUser.setMemberOf(Arrays.asList("group_1", "group_2", "group_3"));
    newUser.setAttributeValue("givenName", "john");
    sqlEntryManager.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 = sqlEntryManager.find(SimpleUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUser, foundUser.getUserId(), foundUser.getDn());
    LOG.info("Custom attributes '{}'", foundUser.getCustomAttributes());
    // Dump custom attributes
    for (CustomObjectAttribute attr : foundUser.getCustomAttributes()) {
        System.out.println(attr.getName() + " - " + attr.getValues());
    }
    // Update custom attributes
    foundUser.setAttributeValues("jansOptOuts", Arrays.asList("London", "Texas", "Kiev", "Dublin"));
    foundUser.setAttributeValues("jansExtUid", Arrays.asList("test_value_11", "test_value_22", "test_value_33", "test_value_44"));
    foundUser.setAttributeValues("jansExtUid", Arrays.asList(11, 22, 33, 44));
    foundUser.setAttributeValues("jansPPID", Arrays.asList("fuzzy_value_1", "fuzzy_value_2"));
    foundUser.setAttributeValue("jansGuid", "simple");
    CustomObjectAttribute multiValuedSingleValue = new CustomObjectAttribute("jansAssociatedClnt", "multivalued_single_valued");
    multiValuedSingleValue.setMultiValued(true);
    foundUser.getCustomAttributes().add(multiValuedSingleValue);
    sqlEntryManager.merge(foundUser);
    LOG.info("Updated custom attributes '{}'", foundUser.getCustomAttributes());
    // Find updated dummy user
    SimpleUser foundUpdatedUser = sqlEntryManager.find(SimpleUser.class, newUser.getDn());
    LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUpdatedUser, foundUpdatedUser.getUserId(), foundUpdatedUser.getDn());
    LOG.info("Cusom attributes '{}'", foundUpdatedUser.getCustomAttributes());
    // Dump custom attributes
    for (CustomObjectAttribute attr : foundUser.getCustomAttributes()) {
        System.out.println(attr.getName() + " - " + attr.getValues());
    }
    Filter filter = Filter.createEqualityFilter(Filter.createLowercaseFilter("givenName"), StringHelper.toLowerCase("john"));
    List<SimpleUser> foundUpdatedUsers = sqlEntryManager.findEntries("o=jans", SimpleUser.class, filter);
    System.out.println(foundUpdatedUsers);
}
Also used : CustomObjectAttribute(io.jans.orm.model.base.CustomObjectAttribute) SimpleUser(io.jans.orm.cloud.spanner.model.SimpleUser) Filter(io.jans.orm.search.filter.Filter) SpannerEntryManagerSample(io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Example 8 with SpannerEntryManager

use of io.jans.orm.cloud.spanner.impl.SpannerEntryManager in project jans by JanssenProject.

the class SpannerBatchJobSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SpannerEntryManagerSample sqlEntryManagerSample = new SpannerEntryManagerSample();
    // Create SQL entry manager
    final SpannerEntryManager sqlEntryManager = sqlEntryManagerSample.createSpannerEntryManager();
    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) Filter(io.jans.orm.search.filter.Filter) SpannerEntryManagerSample(io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample) ProcessBatchOperation(io.jans.orm.model.ProcessBatchOperation) List(java.util.List) SimpleClient(io.jans.orm.cloud.spanner.model.SimpleClient) SimpleSession(io.jans.orm.cloud.spanner.model.SimpleSession) SimpleToken(io.jans.orm.cloud.spanner.model.SimpleToken) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Example 9 with SpannerEntryManager

use of io.jans.orm.cloud.spanner.impl.SpannerEntryManager in project jans by JanssenProject.

the class SpannerEntryManagerSample method createSpannerEntryManager.

public SpannerEntryManager createSpannerEntryManager() {
    SpannerEntryManagerFactory sqlEntryManagerFactory = new SpannerEntryManagerFactory();
    sqlEntryManagerFactory.create();
    Properties connectionProperties = getSampleConnectionProperties();
    SpannerEntryManager sqlEntryManager = sqlEntryManagerFactory.createEntryManager(connectionProperties);
    LOG.debug("Created SpannerEntryManager: " + sqlEntryManager);
    return sqlEntryManager;
}
Also used : SpannerEntryManagerFactory(io.jans.orm.cloud.spanner.impl.SpannerEntryManagerFactory) Properties(java.util.Properties) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Example 10 with SpannerEntryManager

use of io.jans.orm.cloud.spanner.impl.SpannerEntryManager in project jans by JanssenProject.

the class SpannerDeleteSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    SpannerEntryManagerSample sqlEntryManagerSample = new SpannerEntryManagerSample();
    // Create SQL entry manager
    SpannerEntryManager sqlEntryManager = sqlEntryManagerSample.createSpannerEntryManager();
    String baseDn = "ou=people,o=jans";
    Filter filter = Filter.createANDFilter(Filter.createEqualityFilter("del", true), Filter.createLessOrEqualFilter("exp", sqlEntryManager.encodeTime(baseDn, new Date())));
    int result = sqlEntryManager.remove(baseDn, SimpleSession.class, filter, 5);
    System.out.println(result);
}
Also used : Filter(io.jans.orm.search.filter.Filter) SpannerEntryManagerSample(io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample) Date(java.util.Date) SpannerEntryManager(io.jans.orm.cloud.spanner.impl.SpannerEntryManager)

Aggregations

SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)14 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)12 Filter (io.jans.orm.search.filter.Filter)8 Date (java.util.Date)5 SimpleUser (io.jans.orm.cloud.spanner.model.SimpleUser)4 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)3 SpannerEntryManagerFactory (io.jans.orm.cloud.spanner.impl.SpannerEntryManagerFactory)2 SimpleSession (io.jans.orm.cloud.spanner.model.SimpleSession)2 SimpleSessionState (io.jans.orm.cloud.spanner.model.SimpleSessionState)2 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)2 CustomAttribute (io.jans.orm.model.base.CustomAttribute)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 JansConfiguration (io.jans.orm.cloud.spanner.model.JansConfiguration)1 SimpleAttribute (io.jans.orm.cloud.spanner.model.SimpleAttribute)1 SimpleCacheEntry (io.jans.orm.cloud.spanner.model.SimpleCacheEntry)1 SimpleClient (io.jans.orm.cloud.spanner.model.SimpleClient)1 SimpleCustomStringUser (io.jans.orm.cloud.spanner.model.SimpleCustomStringUser)1 SimpleGrant (io.jans.orm.cloud.spanner.model.SimpleGrant)1 SimpleToken (io.jans.orm.cloud.spanner.model.SimpleToken)1