Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Sep 24, 2020
2 parents b8f2c4a + c5f76eb commit 988add4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 18 deletions.
Expand Up @@ -553,7 +553,7 @@ public void test212ModifyUserAddAccountRed() throws Exception {

/**
* Cause schema violation on the account during a provisioning operation. This should fail
* the operation, but other operations should proceed and the account should definitelly NOT
* the operation, but other operations should proceed and the account should definitely NOT
* be unlinked.
* MID-2134
*/
Expand Down Expand Up @@ -595,7 +595,7 @@ public void test212ModifyUserJackBrokenSchemaViolationPolyString() throws Except

/**
* Cause schema violation on the account during a provisioning operation. This should fail
* the operation, but other operations should proceed and the account should definitelly NOT
* the operation, but other operations should proceed and the account should definitely NOT
* be unlinked.
* MID-2134
*/
Expand Down Expand Up @@ -637,7 +637,7 @@ public void test214ModifyUserJackBrokenPassword() throws Exception {

/**
* Cause modification that will be mapped to the account and that will cause
* conflict (AlreadyExistsException). Make sure that midpoint does not end up
* conflict (AlreadyExistsException). Make sure that midPoint does not end up
* in endless loop.
* MID-3451
*/
Expand Down Expand Up @@ -719,7 +719,7 @@ public void test230ModifyUserJackUserTemplatePolicyViolation() throws Exception

}

// Lets test various extension magic and border cases now. This is maybe quite hight in the architecture for
// Lets test various extension magic and border cases now. This is maybe quite high in the architecture for
// this test, but we want to make sure that none of the underlying components will screw the things up.

@Test
Expand Down Expand Up @@ -1546,6 +1546,39 @@ public void test610GetAccountGuybrushRogueAttribute() throws Exception {
assertDummyAccountAttribute(null, USER_GUYBRUSH_USERNAME, "rogue", "habakuk");
}

/**
* Adds existing assignment (phantom change) and looks how audit and notifications look like.
* MID-6370
*/
@Test
public void test700AddExistingAssignment() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();

UserType user = new UserType(prismContext)
.name("user700")
.beginAssignment()
.targetRef(ROLE_SUPERUSER_OID, RoleType.COMPLEX_TYPE)
.end();

addObject(user.asPrismObject(), task, result);

dummyTransport.clearMessages();
notificationManager.setDisabled(false);
dummyAuditService.clear();

when();
assignRole(user.getOid(), ROLE_SUPERUSER_OID, task, result);

then();
displayDumpable("dummy transport", dummyTransport);
displayDumpable("dummy audit", dummyAuditService);

// TODO some asserts here - currently there is an ADD audit record and ADD notification
// In the future we can think of indicating that these adds are - in fact - phantom ones.
}

private <O extends ObjectType, T> void assertExtension(
PrismObject<O> object, QName propName, T... expectedValues) {
PrismContainer<Containerable> extensionContainer = object.findContainer(ObjectType.F_EXTENSION);
Expand Down
Expand Up @@ -30,15 +30,6 @@
</appender>
</logging>
<notificationConfiguration>
<!-- <handler>-->
<!-- <simpleCaseManagementNotifier>-->
<!-- <recipientExpression>-->
<!-- <value>recipient@evolveum.com</value>-->
<!-- </recipientExpression>-->
<!-- <showTechnicalInformation>true</showTechnicalInformation>-->
<!-- <transport>dummy:caseNotifier</transport>-->
<!-- </simpleCaseManagementNotifier>-->
<!-- </handler>-->
<handler>
<simplePolicyRuleNotifier>
<recipientExpression>
Expand Down
4 changes: 4 additions & 0 deletions model/notifications-impl/pom.xml
Expand Up @@ -113,6 +113,10 @@
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
Expand Up @@ -18,8 +18,11 @@
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.PrismReference;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -57,6 +60,19 @@ public Class<SimpleReportNotifierType> getEventHandlerConfigurationType() {
return SimpleReportNotifierType.class;
}

@Override
protected boolean checkApplicability(TaskEvent event, SimpleReportNotifierType generalNotifierType, OperationResult result) {
if (!event.isSuccess()) {
LOGGER.trace("Operation was not successful, exiting.");
return false;
} else if (!event.isFinished()){
LOGGER.trace("No report output oid present in task. Skip sending notifications.");
return false;
}

return true;
}

@Override
protected boolean quickCheckApplicability(TaskEvent event, SimpleReportNotifierType configuration, OperationResult result) {
if (!event.getTask().getHandlerUri().equals(REPORT_TASK_URI) && !event.getTask().getHandlerUri().equals(REPORT_CREATE_TASK_URI)) {
Expand Down Expand Up @@ -96,14 +112,23 @@ protected List<NotificationMessageAttachmentType> getAttachment(TaskEvent event,
reportOutput = modelService.getObject(ReportDataType.class, outputOid, null, task, result);
} catch (ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException
| ExpressionEvaluationException | SchemaException e) {
getLogger().error("Could't get Report output with oid " + outputOid, e);
getLogger().error("Couldn't get Report output with oid " + outputOid, e);
throw new SystemException("Couldn't get report output " + outputOid, e);
}

NotificationMessageAttachmentType attachment = new NotificationMessageAttachmentType();
String type = reportOutput.asObjectable().getFileFormat().value().toLowerCase();
String type;
String filePath = reportOutput.asObjectable().getFilePath();
if (reportOutput.asObjectable().getFileFormat() != null) {
type = reportOutput.asObjectable().getFileFormat().value().toLowerCase();
} else {
type = FilenameUtils.getExtension(filePath);
}
if (StringUtils.isBlank(type)) {
type = "plain";
}
attachment.setContentType("text/" + type);
attachment.setContentFromFile(reportOutput.asObjectable().getFilePath());
attachment.setContentFromFile(filePath);
List attachments = new ArrayList();
attachments.add(attachment);
return attachments;
Expand Down Expand Up @@ -132,11 +157,11 @@ protected String getBody(TaskEvent event, SimpleReportNotifierType configuration
private String getReportDataOid(Task task) {
PrismReference reportData = task.getExtensionReferenceOrClone(ReportConstants.REPORT_DATA_PROPERTY_NAME);
if (reportData == null || reportData.getRealValue() == null) {
PrismProperty<String> reportOutputOid = task.getExtensionPropertyRealValue(ReportConstants.REPORT_OUTPUT_OID_PROPERTY_NAME);
String reportOutputOid = task.getExtensionPropertyRealValue(ReportConstants.REPORT_OUTPUT_OID_PROPERTY_NAME);
if (reportOutputOid == null){
return null;
}
return reportOutputOid.getRealValue();
return reportOutputOid;
}

return reportData.getRealValue().getOid();
Expand Down

0 comments on commit 988add4

Please sign in to comment.