Created
February 7, 2017 12:19
-
-
Save omindu/57a71774f7b2f53748a45955200744e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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