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
katkav committed Mar 18, 2020
2 parents 268c258 + 61a612a commit 4ae8de7
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 35 deletions.
Expand Up @@ -12,25 +12,33 @@
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.web.component.data.column.IconColumn;
import com.evolveum.midpoint.web.component.data.column.LinkColumn;
import com.evolveum.midpoint.web.component.data.column.LinkPanel;
import com.evolveum.midpoint.web.page.admin.certification.dto.CertCaseOrWorkItemDto;
import com.evolveum.midpoint.web.page.admin.certification.dto.CertWorkItemDto;
import com.evolveum.midpoint.web.page.admin.certification.dto.SearchingUtils;
import com.evolveum.midpoint.web.page.admin.certification.handlers.CertGuiHandler;
import com.evolveum.midpoint.web.page.admin.certification.handlers.CertGuiHandlerRegistry;
import com.evolveum.midpoint.web.page.admin.home.dto.AssignmentItemDto;
import com.evolveum.midpoint.web.util.ObjectTypeGuiDescriptor;
import com.evolveum.midpoint.web.util.TooltipBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DisplayType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

import org.apache.commons.collections.CollectionUtils;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.List;

import static com.evolveum.midpoint.gui.api.util.WebComponentUtil.dispatchToObjectDetailsPage;

Expand Down Expand Up @@ -104,15 +112,33 @@ public void onClick(AjaxRequestTarget target, IModel<CertCaseOrWorkItemDto> rowM

public <T extends CertCaseOrWorkItemDto> IColumn<T, String> createReviewerNameColumn(final PageBase page, final String headerKey) {
IColumn column;
column = new LinkColumn<CertCaseOrWorkItemDto>(page.createStringResource(headerKey), CertWorkItemDto.F_REVIEWER_NAME) {
column = new AbstractColumn<T, String>(page.createStringResource(headerKey)) {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target, IModel<CertCaseOrWorkItemDto> rowModel) {
public void populateItem(Item<ICellPopulator<T>> cellItem, String componentId,
final IModel<T> rowModel) {
CertCaseOrWorkItemDto dto = rowModel.getObject();
RepeatingView reviewersPanel = new RepeatingView(componentId);
if (dto instanceof CertWorkItemDto) {
dispatchToObjectDetailsPage(((CertWorkItemDto) dto).getReviewerRef(), page, false);
List<ObjectReferenceType> reviewersList = ((CertWorkItemDto) dto).getReviewerRefList();
if (CollectionUtils.isNotEmpty(reviewersList)){
for (ObjectReferenceType reviewer : reviewersList){
reviewersPanel.add(new LinkPanel(reviewersPanel.newChildId(),
Model.of(WebComponentUtil.getDisplayNameOrName(reviewer))) {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
dispatchToObjectDetailsPage(reviewer, page, false);
}
});
}
}
}
cellItem.add(reviewersPanel);
}

};
return column;
}
Expand Down
Expand Up @@ -19,6 +19,9 @@

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
* DTO representing a particular workItem.
*
Expand All @@ -34,15 +37,15 @@ public class CertWorkItemDto extends CertCaseOrWorkItemDto {
public static final String F_REVIEWER_NAME = "reviewerName";

@NotNull private final AccessCertificationWorkItemType workItem;
private ObjectReferenceType reviewerRef;
private String reviewerName;
private List<ObjectReferenceType> reviewerRefList;
private List<String> reviewerNameList = new ArrayList<>();

CertWorkItemDto(@NotNull AccessCertificationWorkItemType workItem, @NotNull PageBase page) {
//noinspection ConstantConditions
super(CertCampaignTypeUtil.getCase(workItem), page);
this.workItem = workItem;
this.reviewerRef = workItem.getOriginalAssigneeRef();
this.reviewerName = computeReviewerName();
this.reviewerRefList = workItem.getAssigneeRef();
computeReviewerNameList();
}

public String getComment() {
Expand Down Expand Up @@ -74,26 +77,28 @@ public String getEscalationLevelInfo() {
return ApprovalContextUtil.getEscalationLevelInfo(workItem);
}

public String computeReviewerName(){
if (reviewerRef == null){
return null;
public void computeReviewerNameList(){
if (reviewerRefList == null){
return;
}
return WebComponentUtil.getDisplayNameAndName(reviewerRef);
reviewerRefList.forEach(reviewerRef -> {
reviewerNameList.add(WebComponentUtil.getDisplayNameAndName(reviewerRef));
});
}

public String getReviewerName() {
return reviewerName;
public List<String> getReviewerNameList() {
return reviewerNameList;
}

public void setReviewerName(String reviewerName) {
this.reviewerName = reviewerName;
public void setReviewerName(List<String> reviewerNameList) {
this.reviewerNameList = reviewerNameList;
}

public ObjectReferenceType getReviewerRef() {
return reviewerRef;
public List<ObjectReferenceType> getReviewerRefList() {
return reviewerRefList;
}

public void setReviewerRef(ObjectReferenceType reviewerRef) {
this.reviewerRef = reviewerRef;
public void setReviewerRefList(List<ObjectReferenceType> reviewerRefList) {
this.reviewerRefList = reviewerRefList;
}
}
Expand Up @@ -3574,7 +3574,7 @@ public void test990SpecialTimedMapping() throws Exception {

clock.resetOverride();

XMLGregorianCalendar firstTriggerTime = XmlTypeConverter.fromNow("PT1M");
XMLGregorianCalendar firstTriggerTime = XmlTypeConverter.fromNow("PT20M");

UserType user = new UserType(prismContext)
.name("test990SpecialTimedMapping")
Expand Down
Expand Up @@ -8,8 +8,18 @@
package com.evolveum.midpoint.notifications.impl.notifiers;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import com.evolveum.midpoint.common.Clock;
import com.evolveum.midpoint.model.api.ModelService;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

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

import com.evolveum.midpoint.model.api.context.ModelElementContext;
Expand All @@ -18,13 +28,13 @@
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccountActivationNotifierType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

@Component
public class AccountActivationNotifier extends ConfirmationNotifier<AccountActivationNotifierType> {

@Autowired Clock clock;
@Autowired private ModelService modelService;

private static final Trace LOGGER = TraceManager.getTrace(AccountActivationNotifier.class);

@Override
Expand Down Expand Up @@ -70,14 +80,74 @@ protected String getSubject(ModelEvent event, AccountActivationNotifierType conf
protected String getBody(ModelEvent event, AccountActivationNotifierType configuration, String transport,
Task task, OperationResult result) {

StringBuilder body = new StringBuilder();
String message = "Your accounts was successfully created. To activate your accounts, please click on the link bellow.";
body.append(message).append("\n\n").append(createConfirmationLink(getUser(event), configuration, result)).append("\n\n");

FocusType owner = (FocusType) event.getRequesteeObject();
String userOrOwner = owner instanceof UserType ? "User" : "Owner";
if (owner != null) {
body.append(userOrOwner).append(": ").append(event.getRequesteeDisplayName());
body.append(" (").append(owner.getName()).append(", oid ").append(owner.getOid()).append(")\n");
} else {
body.append(userOrOwner).append(": unknown\n");
}
body.append("Notification created on: ").append(new Date(clock.currentTimeMillis())).append("\n\n");

StringBuilder accountsToActivate = new StringBuilder("Shadow to be activated: \n");
body.append("Account to be activated: \n");
for (ShadowType shadow : getShadowsToActivate(event)) {
accountsToActivate.append(shadow.asPrismObject().debugDump()).append("\n");
String resourceOid = shadow.getResourceRef() != null ? shadow.getResourceRef().getOid() : null;
body.append(" Resource: ");
if (StringUtils.isNotBlank(resourceOid)) {
PrismObject<ResourceType> resource;
try {
resource = modelService.getObject(ResourceType.class, resourceOid, null, task, result);
} catch (ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException
| ExpressionEvaluationException | SchemaException e) {
getLogger().error("Could't get Resource with oid " + resourceOid, e);
throw new SystemException("Couldn't get resource " + resourceOid, e);
}
body.append(StringUtils.isNotBlank(resource.getDisplayName()) ? resource.getDisplayName() : resource.getName());
body.append(" (").append("oid ").append(resourceOid).append(")\n");

} else {
body.append("unknown\n");
}
for (Object att : shadow.getAttributes().asPrismContainerValue().getItems()) {
if (att instanceof ResourceAttribute) {
ResourceAttribute attribute = (ResourceAttribute) att;
body.append(" - ").append(attribute.getDisplayName()).append(": ");
if (attribute.isSingleValue()) {
body.append(attribute.getRealValue()).append("\n");
} else {
body.append("\n");
for (Object value : attribute.getRealValues()) {
body.append(" - ").append(value).append("\n");
}
}
}
}
}

return message + "\n\n" + createConfirmationLink(getUser(event), configuration, result) + "\n\n" + accountsToActivate;
ObjectType requester = event.getRequester() != null ? event.getRequester().getObjectType() : null;
if (requester != null) {
body.append("\nRequester: ").append(getRequestorDisplayName(requester));
body.append(" (").append(requester.getName()).append(", oid ").append(requester.getOid()).append(")\n");
}
return body.toString();
}

private String getRequestorDisplayName(ObjectType requester) {
String name = requester.getName().getOrig();
if (requester.asPrismObject().getDisplayName() != null) {
name = requester.asPrismObject().getDisplayName();
}
if (requester instanceof UserType){
if (((UserType) requester).getFullName() != null) {
name = ((UserType) requester).getFullName().getOrig();
}
}
return name;
}

private List<ShadowType> getShadowsToActivate(ModelEvent modelEvent) {
Expand Down
Expand Up @@ -121,11 +121,7 @@ public static S_AtomicFilterExit filterForMyRequests(S_FilterEntryOrEmpty q, Str
.ref(principalUserOid)
.and()
.item(CaseType.F_ARCHETYPE_REF)
.ref(SystemObjectsType.ARCHETYPE_OPERATION_REQUEST.value())
.and()
.not()
.item(CaseType.F_STATE)
.eq(SchemaConstants.CASE_STATE_CLOSED);
.ref(SystemObjectsType.ARCHETYPE_OPERATION_REQUEST.value());
}

public static S_AtomicFilterExit filterForCasesOverUser(S_FilterEntryOrEmpty q, String userOid){
Expand Down
Expand Up @@ -130,12 +130,15 @@ default void displayTestTitle(String testTitle) {
*/
default void displayTestFooter(String testTitle, ITestResult testResult) {
if (testResult.getThrowable() != null) {
displayException(testTitle + " thrown unexpected exception", testResult.getThrowable());
displayException(testTitle + " threw unexpected exception", testResult.getThrowable());
}

long testMsDuration = testResult.getEndMillis() - testResult.getStartMillis();
System.out.println(TEST_OUT_FOOTER_PREFIX + testTitle + " FINISHED in " + testMsDuration + " ms" + TEST_OUT_FOOTER_SUFFIX);
logger().info(TEST_LOG_PREFIX + testTitle + " FINISHED in " + testMsDuration + " ms" + TEST_LOG_SUFFIX);
String finishedLabel = testResult.isSuccess()
? " FINISHED in "
: " FINISHED with FAILURE in ";
System.out.println(TEST_OUT_FOOTER_PREFIX + testTitle + finishedLabel + testMsDuration + " ms" + TEST_OUT_FOOTER_SUFFIX);
logger().info(TEST_LOG_PREFIX + testTitle + finishedLabel + testMsDuration + " ms" + TEST_LOG_SUFFIX);
}

default void display(String text) {
Expand All @@ -158,7 +161,7 @@ default void displayValue(String title, Object value) {
default void displayException(String title, Throwable e) {
System.out.println(DISPLAY_OUT_PREFIX + title + ":");
e.printStackTrace(System.out);
logger().debug(DISPLAY_LOG_FORMAT1, title, e);
logger().warn(DISPLAY_LOG_FORMAT1, title, e);
}

/**
Expand Down

0 comments on commit 4ae8de7

Please sign in to comment.