Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add temp logs #360

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public class InvitationCoreServiceImpl implements InvitationCoreService {
@Override
public List<InvitationResult> createInvitations(InvitationDO invitationDO) throws UserInvitationMgtException {

LOG.info("[INVITATION_LOG] Creating invitations for the users: " + invitationDO.getUsernamesList());
List<InvitationResult> createdInvitationsList = new ArrayList<>();
Invitation invitation = new Invitation();
String orgId = Utils.getOrganizationId();
Expand All @@ -147,6 +148,7 @@ public List<InvitationResult> createInvitations(InvitationDO invitationDO) throw
int parentTenantId = IdentityTenantUtil.getTenantId(parentTenantDomain);
AbstractUserStoreManager userStoreManager = getAbstractUserStoreManager(parentTenantId);
for (String username : invitationDO.getUsernamesList()) {
LOG.info("[INVITATION_LOG] Creating invitation for the user: " + username);
String userDomainQualifiedUserName = UserCoreUtil
.addDomainToName(username, invitationDO.getUserDomain());
String invitedUserId = userStoreManager.getUserIDFromUserName(userDomainQualifiedUserName);
Expand Down Expand Up @@ -181,14 +183,21 @@ public List<InvitationResult> createInvitations(InvitationDO invitationDO) throw
invitation.setConfirmationCode(confirmationCode);
Map<String, String> invitationProperties = invitationDO.getInvitationProperties();
invitation.setInvitationProperties(invitationProperties);
LOG.info("[INVITATION_LOG] Storing the invitation for the user: " + username);
userInvitationDAO.createInvitation(invitation);
Invitation createdInvitationInfo =
userInvitationDAO.getInvitationByInvitationId(invitation.getInvitationId());
LOG.info("[INVITATION_LOG] Invitation created for user: " + username + " with the invitation id: " +
invitation.getInvitationId());
if (isNotificationsInternallyManaged(orgId, invitationProperties)) {
// Trigger the event for invitation creation to send notification internally.
LOG.info("[INVITATION_LOG] Triggering the event for invitation creation for the user: "
+ username);
triggerInvitationAddNotification(createdInvitationInfo);
} else {
// Send the confirmation code via the response to manage notification externally.
LOG.info("[INVITATION_LOG] Sending the confirmation code in the response for the user: "
+ username);
validationResult.setConfirmationCode(confirmationCode);
}
}
Expand Down Expand Up @@ -472,9 +481,13 @@ private void triggerInvitationAddNotification(Invitation invitation)
properties.put(EVENT_PROP_TENANT_DOMAIN, invitation.getInvitedOrganizationId());
properties.put(EVENT_PROP_REDIRECT_URL, invitation.getUserRedirectUrl());
properties.put(EVENT_PROP_PROPERTIES, invitation.getInvitationProperties());

LOG.info("[INVITATION_LOG] Triggering the event for invitation creation for the user: "
+ invitation.getUsername());
LOG.info("[INVITATION_LOG] Invitation properties: " + properties);
Event invitationEvent = new Event(EVENT_NAME_POST_ADD_INVITATION, properties);
try {
LOG.info("[INVITATION_LOG] Handling the event for invitation creation for the user: "
+ invitation.getUsername());
UserInvitationMgtDataHolder.getInstance().getIdentityEventService().handleEvent(invitationEvent);
} catch (IdentityEventException e) {
throw new UserInvitationMgtServerException(ERROR_CODE_EVENT_HANDLE.getCode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public boolean canHandle(MessageContext messageContext) throws IdentityRuntimeEx
if (LOG.isDebugEnabled()) {
LOG.debug("canHandle() returning True for the event: " + eventName);
}
LOG.info("[INVITATION_LOG] Can handle the invitation event: " + eventName);
return true;
}
return false;
Expand All @@ -78,12 +79,13 @@ public boolean canHandle(MessageContext messageContext) throws IdentityRuntimeEx
public void handleEvent(Event event) throws IdentityEventException {

String eventName = event.getEventName();

LOG.info("[INVITATION_LOG] Handling event: " + eventName);
if (EVENT_NAME_POST_ADD_INVITATION.equals(eventName)) {
// Trigger the email notification
String redirectUrl = event.getEventProperties().get(EVENT_PROP_REDIRECT_URL) + "?code=" +
event.getEventProperties().get(EVENT_PROP_CONFIRMATION_CODE);
event.getEventProperties().put(EVENT_PROP_REDIRECT_URL, redirectUrl);
LOG.info("[INVITATION_LOG] Triggering email notification for the event: " + eventName);
triggerEmailNotification(event);
}
}
Expand All @@ -104,12 +106,13 @@ private void triggerEmailNotification(Event event) throws IdentityEventException
HashMap<String, Object> properties = new HashMap<>();
properties.put(EVENT_PROP_SEND_TO, event.getEventProperties().get(EVENT_PROP_EMAIL_ADDRESS));
properties.put(EVENT_PROP_TEMPLATE_TYPE, ORGANIZATION_USER_INVITATION_EMAIL_TEMPLATE_TYPE);

LOG.info("[INVITATION_LOG] Invite event properties: " + event.getEventProperties());
if (CollectionUtils.size(event.getEventProperties()) > 0) {
properties.putAll(event.getEventProperties());
}
Event identityMgtEvent = new Event(IdentityEventConstants.Event.TRIGGER_NOTIFICATION, properties);
try {
LOG.info("[INVITATION_LOG] Triggering the notification for invite event : " + event.getEventProperties());
UserInvitationMgtDataHolder.getInstance().getIdentityEventService().handleEvent(identityMgtEvent);
} catch (IdentityEventException e) {
throw new IdentityEventException("Error while sending notification for user", e);
Expand Down
Loading