Skip to content

Commit

Permalink
Putting requester+channel to all notifications, except for workflows.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Oct 9, 2015
1 parent 2cfe097 commit 286f55b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 18 deletions.
Expand Up @@ -60,6 +60,8 @@ public abstract class BaseEvent implements Event {

private SimpleObjectRef requestee;

private String channel;

public BaseEvent(LightweightIdentifierGenerator lightweightIdentifierGenerator) {
id = lightweightIdentifierGenerator.generate();
}
Expand Down Expand Up @@ -291,5 +293,12 @@ private ItemPath pathTail(ItemPath itemPath) {
return itemPath;
}

@Override
public String getChannel() {
return channel;
}

public void setChannel(String channel) {
this.channel = channel;
}
}
Expand Up @@ -101,4 +101,6 @@ public interface Event {
* @return
*/
boolean isRelatedToItem(ItemPath itemPath);

String getChannel();
}
Expand Up @@ -179,6 +179,11 @@ private ResourceObjectEvent createRequest(OperationStatus status,
} else {
LOGGER.warn("No owner for task " + task + ", therefore no requester will be set for event " + event.getId());
}

if (task != null) {
event.setChannel(task.getChannel());
}

return event;
}

Expand Down
Expand Up @@ -137,6 +137,8 @@ private Event createRequest(PrismObject<? extends ObjectType> object, Task task,

ModelEvent event = new ModelEvent(lightweightIdentifierGenerator);
event.setModelContext(modelContext);
// TODO or take channel from modelContext?
event.setChannel(task.getChannel());

if (task.getOwner() != null) {
event.setRequester(new SimpleObjectRefImpl(notificationsUtil, task.getOwner().asObjectable()));
Expand Down
Expand Up @@ -16,13 +16,15 @@

package com.evolveum.midpoint.notifications.impl;

import com.evolveum.midpoint.notifications.api.events.Event;
import com.evolveum.midpoint.notifications.api.events.SimpleObjectRef;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ShadowUtil;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -133,4 +135,25 @@ public String getShadowName(PrismObject<? extends ShadowType> shadow) {
}
}
}

// TODO move to some other class?
public void addRequesterAndChannelInformation(StringBuilder body, Event event, OperationResult result) {
if (event.getRequester() != null) {
body.append("Requester: ");
try {
ObjectType requester = event.getRequester().resolveObjectType(result);
if (requester instanceof UserType) {
UserType requesterUser = (UserType) requester;
body.append(requesterUser.getFullName()).append(" (").append(requester.getName()).append(")");
} else {
body.append(ObjectTypeUtil.toShortString(requester));
}
} catch (RuntimeException e) {
body.append("couldn't be determined: ").append(e.getMessage());
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't determine requester for a notification", e);
}
body.append("\n");
}
body.append("Channel: ").append(event.getChannel()).append("\n\n");
}
}
Expand Up @@ -54,7 +54,10 @@ public CertCampaignEvent createOnCampaignStartEvent(AccessCertificationCampaignT

protected void fillInEvent(AccessCertificationCampaignType campaign, Task task, AccessCertificationEvent event) {
event.setRequestee(new SimpleObjectRefImpl(notificationsUtil, campaign.getOwnerRef()));
event.setRequester(new SimpleObjectRefImpl(notificationsUtil, task.getOwner()));
if (task != null) {
event.setRequester(new SimpleObjectRefImpl(notificationsUtil, task.getOwner()));
event.setChannel(task.getChannel());
}
}

protected void fillInReviewerRelatedEvent(ObjectReferenceType reviewerRef, Task task, AccessCertificationEvent event) {
Expand Down
Expand Up @@ -107,6 +107,9 @@ protected String getBody(Event event, GeneralNotifierType generalNotifierType, S
body.append("\n\n");
certHelper.appendStatistics(body, campaign, task, result);

body.append("\n\n");
notificationsUtil.addRequesterAndChannelInformation(body, event, result);

return body.toString();
}

Expand Down
Expand Up @@ -132,6 +132,9 @@ protected String getBody(Event event, GeneralNotifierType generalNotifierType, S
body.append("\n");
certHelper.appendStatistics(body, campaign, task, result);

body.append("\n\n");
notificationsUtil.addRequesterAndChannelInformation(body, event, result);

return body.toString();
}

Expand Down
Expand Up @@ -178,23 +178,7 @@ protected String getBody(Event event, GeneralNotifierType generalNotifierType, S
body.append("More information about the status of the request was displayed and/or is present in log files.\n\n");
}

if (event.getRequester() != null) {
body.append("Requester: ");
try {
ObjectType requester = event.getRequester().resolveObjectType(result);
if (requester instanceof UserType) {
UserType requesterUser = (UserType) requester;
body.append(requesterUser.getFullName()).append(" (").append(requester.getName()).append(")");
} else {
body.append(ObjectTypeUtil.toShortString(requester));
}
} catch (RuntimeException e) {
body.append("couldn't be determined: ").append(e.getMessage());
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't determine requester for a notification", e);
}
body.append("\n");
}
body.append("Channel: ").append(modelContext.getChannel()).append("\n\n");
notificationsUtil.addRequesterAndChannelInformation(body, event, result);

if (techInfo) {
body.append("----------------------------------------\n");
Expand Down
Expand Up @@ -231,6 +231,9 @@ protected String getBody(Event event, GeneralNotifierType generalNotifierType, S
body.append("Error: " + resourceObjectEvent.getAccountOperationDescription().getResult().getMessage() + "\n\n");
}

body.append("\n\n");
notificationsUtil.addRequesterAndChannelInformation(body, event, result);

if (techInfo) {
body.append("----------------------------------------\n");
body.append("Technical information:\n\n");
Expand Down

0 comments on commit 286f55b

Please sign in to comment.