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);
}
}
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);
}
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());
}
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;
}
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);
}
Aggregations