Skip to content

Commit

Permalink
First attempt at custom forms in work items (showing empty form only …
Browse files Browse the repository at this point in the history
…now). Limited ability to merge approval schema levels. Functionality to merge PCVs.
  • Loading branch information
mederly committed Jan 28, 2017
1 parent c9b08ac commit 7673c36
Show file tree
Hide file tree
Showing 24 changed files with 495 additions and 289 deletions.
Expand Up @@ -91,7 +91,7 @@ private PrismObject<O> instantiateObject(QName objectType, PageBase parentPage)
try {
prismObject = objectDef.instantiate();
} catch (SchemaException e) {
LoggingUtils.logException(LOGGER, "Could not initalize model for forgot password", e);
LoggingUtils.logException(LOGGER, "Could not initialize model for forgot password", e);
throw new RestartResponseException(getPageBase());
}
return prismObject;
Expand Down Expand Up @@ -143,7 +143,7 @@ private void initLayout(String formOid, boolean runPrivileged, Form<?> mainForm)
getPageBase(), task, result);

if (prismForm == null) {
LOGGER.trace("No form defined, skipping denerating GUI form");
LOGGER.trace("No form defined, skipping generating GUI form");
return;
}

Expand Down
Expand Up @@ -175,7 +175,7 @@ private void initLayout() {
mainForm.setMultiPart(true);
add(mainForm);

mainForm.add(new WorkItemPanel(ID_WORK_ITEM_PANEL, workItemDtoModel, this));
mainForm.add(new WorkItemPanel(ID_WORK_ITEM_PANEL, workItemDtoModel, mainForm, this));

initButtons(mainForm);
}
Expand Down
Expand Up @@ -96,6 +96,9 @@ <h3 class="box-title"><wicket:message key="workItemPanel.relatedRequests"/></h3>

<div style="margin-top:20px" wicket:id="additionalInformation"/>

<!-- TODO more forms -->
<div wicket:id="customForm" />

<h3><wicket:message key="workItemPanel.approverComment"/></h3>
<textarea wicket:id="approverComment" class="form-control input-sm" rows="2"></textarea>
<p/>
Expand Down
Expand Up @@ -18,8 +18,11 @@
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.util.WfContextUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.prism.DynamicFormPanel;
import com.evolveum.midpoint.web.component.util.ListDataProvider;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
Expand All @@ -31,12 +34,15 @@
import com.evolveum.midpoint.web.page.admin.workflow.dto.WorkItemDto;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalLevelType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
Expand Down Expand Up @@ -74,16 +80,17 @@ public class WorkItemPanel extends BasePanel<WorkItemDto> {
private static final String ID_RELATED_REQUESTS = "relatedRequests";
private static final String ID_RELATED_REQUESTS_HELP = "relatedRequestsHelp";
private static final String ID_ADDITIONAL_INFORMATION = "additionalInformation";
private static final String ID_CUSTOM_FORM = "customForm";
private static final String ID_APPROVER_COMMENT = "approverComment";
private static final String ID_SHOW_REQUEST = "showRequest";
private static final String ID_SHOW_REQUEST_HELP = "showRequestHelp";

public WorkItemPanel(String id, IModel<WorkItemDto> model, PageBase pageBase) {
public WorkItemPanel(String id, IModel<WorkItemDto> model, Form mainForm, PageBase pageBase) {
super(id, model);
initLayout(pageBase);
initLayout(mainForm, pageBase);
}

protected void initLayout(PageBase pageBase) {
protected void initLayout(Form mainForm, PageBase pageBase) {
WebMarkupContainer additionalInfoColumn = new WebMarkupContainer(ID_ADDITIONAL_INFO_COLUMN);

WebMarkupContainer historyContainer = new WebMarkupContainer(ID_HISTORY_CONTAINER);
Expand Down Expand Up @@ -181,6 +188,18 @@ public void onClick(AjaxRequestTarget target) {
new PropertyModel<>(getModel(), WorkItemDto.F_ADDITIONAL_INFORMATION));
add(additionalInformation);

WorkItemDto dto = getModelObject();
ApprovalLevelType level = WfContextUtil.getCurrentApprovalLevel(dto.getWorkflowContext());
if (level != null && level.getFormRef() != null && level.getFormRef().getOid() != null) {
String formOid = level.getFormRef().getOid();
DynamicFormPanel<UserType> customForm = new DynamicFormPanel<>(ID_CUSTOM_FORM,
(PrismObject<UserType>) new UserType(pageBase.getPrismContext()).asPrismObject(),
formOid, mainForm, false, pageBase);
add(customForm);
} else {
add(new Label(ID_CUSTOM_FORM));
}

add(new TextArea<>(ID_APPROVER_COMMENT, new PropertyModel<String>(getModel(), WorkItemDto.F_APPROVER_COMMENT)));
}

Expand Down
Expand Up @@ -273,10 +273,7 @@ public boolean isSingleValue() {
return false;
}
}
if (values == null || values.size() < 2) {
return true;
}
return false;
return values.size() <= 1;
}

/**
Expand Down
Expand Up @@ -1270,7 +1270,8 @@ public void assertDefinitions(boolean tolerateRaw, String sourceDescription) thr
}

public PrismContainerValue<C> clone() { // TODO resolve also the definition?
PrismContainerValue<C> clone = new PrismContainerValue<C>(getOriginType(), getOriginObject(), getParent(), getId(), this.complexTypeDefinition, this.prismContext);
PrismContainerValue<C> clone = new PrismContainerValue<>(getOriginType(), getOriginObject(), getParent(), getId(),
this.complexTypeDefinition, this.prismContext);
copyValues(clone);
return clone;
}
Expand Down Expand Up @@ -1578,4 +1579,22 @@ public PrismContainer<C> asSingleValuedContainer(@NotNull QName itemName) throws
pc.add(clone());
return pc;
}

// EXPERIMENTAL. TODO write some tests
// BEWARE, it expects that definitions for items are present. Otherwise definition-less single valued items will get overwritten.
@SuppressWarnings("unchecked")
public void mergeContent(PrismContainerValue<?> other, List<QName> overwrite) throws SchemaException {
List<QName> remainingToOverwrite = new ArrayList<>(overwrite);
if (other.getItems() != null) {
for (Item<?, ?> otherItem : other.getItems()) {
Item<?, ?> existingItem = findItem(otherItem.elementName);
if (QNameUtil.remove(remainingToOverwrite, otherItem.getElementName())
|| existingItem != null && existingItem.isSingleValue()) {
remove(existingItem);
}
merge(otherItem.clone());
}
}
remainingToOverwrite.forEach(name -> removeItem(new ItemPath(name), Item.class));
}
}
Expand Up @@ -123,4 +123,19 @@ public static SchemaAttachedPolicyRuleType getAttachedPolicyRule(WfContextType w
&& order >= e.getLevelMin() && order <= e.getLevelMax())
.findFirst().orElse(null);
}

public static ApprovalLevelType getCurrentApprovalLevel(WfContextType wfc) {
if (wfc == null || wfc.getStageNumber() == null) {
return null;
}
ItemApprovalProcessStateType info = getItemApprovalProcessInfo(wfc);
if (info == null || info.getApprovalSchema() == null) {
return null;
}
int level = wfc.getStageNumber()-1;
if (level < 0 || level >= info.getApprovalSchema().getLevel().size()) {
return null; // TODO log something here? or leave it to the caller?
}
return info.getApprovalSchema().getLevel().get(level);
}
}

0 comments on commit 7673c36

Please sign in to comment.