Skip to content

Instantly share code, notes, and snippets.

@omindu
Created February 7, 2017 12:19
Show Gist options
  • Save omindu/57a71774f7b2f53748a45955200744e9 to your computer and use it in GitHub Desktop.
Save omindu/57a71774f7b2f53748a45955200744e9 to your computer and use it in GitHub Desktop.
public User getUser(String uniqueUserId) throws IdentityStoreException, UserNotFoundException {
//Pre handler
Map<String, Object> eventProperties = new HashMap<>();
eventProperties.put(IdentityStoreConstants.UNIQUE_USED_ID, uniqueUserId);
Event event = new Event(IdentityStoreInterceptorConstants.PRE_GET_USER_BY_ID, eventProperties);
IdentityMgtMessageContext messageContext = new IdentityMgtMessageContext(event);
try {
eventService.handleEvent(messageContext);
} catch (EventException e) {
String message = String.format("Error while handling %s event.", IdentityStoreInterceptorConstants
.PRE_GET_USER_BY_ID);
throw new IdentityStoreException(message, e);
}
User user;
try {
user = identityStore.getUser(uniqueUserId);
} catch (IdentityStoreException e) {
String message = String.format("Error during rollback operation of %s event", IdentityStoreInterceptorConstants
.PRE_GET_USER_BY_ID);
try {
eventService.rollbackEvent(messageContext);
} catch (EventException e1) {
IdentityStoreException ex = new IdentityStoreException(message, e1);
e.addSuppressed(ex);
}
throw e;
}
//Post handler
eventProperties = new HashMap<>();
eventProperties.put(IdentityStoreConstants.UNIQUE_USED_ID, uniqueUserId);
eventProperties.put(IdentityStoreConstants.USER, user);
event = new Event(IdentityStoreInterceptorConstants.POST_GET_USER_BY_ID, eventProperties);
messageContext.setEvent(event);
try {
eventService.handleEvent(messageContext);
} catch (EventException e) {
String message = String.format("Error while handling %s event.", IdentityStoreInterceptorConstants
.POST_GET_USER_BY_ID);
try {
eventService.rollbackEvent(messageContext);
} catch (EventException e1) {
IdentityStoreException ex = new IdentityStoreException(message, e1);
e.addSuppressed(ex);
}
throw new IdentityStoreException(message, e);
}
return user;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment