From c6ce74fcf35cf9bcde473ed5daa9dc0fe5e70648 Mon Sep 17 00:00:00 2001 From: kate Date: Thu, 15 Feb 2018 13:23:19 +0100 Subject: [PATCH 1/7] construction details panel (simplified) --- .../AbstractAssignmentDetailsPanel.html | 123 +---------- .../assignment/ConstructionDetailsPanel.html | 55 +++++ .../assignment/ConstructionDetailsPanel.java | 203 ++++++++++++++++++ .../component/prism/PrismContainerPanel.java | 20 +- 4 files changed, 275 insertions(+), 126 deletions(-) create mode 100644 gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.html create mode 100644 gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.java diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AbstractAssignmentDetailsPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AbstractAssignmentDetailsPanel.html index e00782c8c0d..3a2ac935549 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AbstractAssignmentDetailsPanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AbstractAssignmentDetailsPanel.html @@ -21,127 +21,6 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.html new file mode 100644 index 00000000000..1d41071ab47 --- /dev/null +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.html @@ -0,0 +1,55 @@ + + + + + +
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ + + diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.java new file mode 100644 index 00000000000..47a6413a45f --- /dev/null +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.java @@ -0,0 +1,203 @@ +/** + * Copyright (c) 2015-2018 Evolveum + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.evolveum.midpoint.web.component.assignment; + +import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition; +import com.evolveum.midpoint.common.refinery.RefinedResourceSchema; +import com.evolveum.midpoint.gui.api.component.BasePanel; +import com.evolveum.midpoint.gui.api.model.LoadableModel; +import com.evolveum.midpoint.gui.api.util.WebComponentUtil; +import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils; +import com.evolveum.midpoint.prism.Containerable; +import com.evolveum.midpoint.prism.PrismObject; +import com.evolveum.midpoint.schema.result.OperationResult; +import com.evolveum.midpoint.task.api.Task; +import com.evolveum.midpoint.util.exception.SchemaException; +import com.evolveum.midpoint.util.logging.Trace; +import com.evolveum.midpoint.util.logging.TraceManager; +import com.evolveum.midpoint.web.component.input.DropDownChoicePanel; +import com.evolveum.midpoint.web.component.prism.ContainerValueWrapper; +import com.evolveum.midpoint.web.component.prism.ItemWrapper; +import com.evolveum.midpoint.web.component.prism.ValueWrapper; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType; +import org.apache.wicket.ajax.AjaxEventBehavior; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.LoadableDetachableModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import sun.security.provider.SHA; + +import javax.xml.namespace.QName; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by honchar. + */ +public class ConstructionDetailsPanel extends BasePanel> { + private static final long serialVersionUID = 1L; + + private static final String ID_KIND_FIELD = "kindField"; + private static final String ID_INTENT_FIELD = "intentField"; + + private static final Trace LOGGER = TraceManager.getTrace(ConstructionDetailsPanel.class); + private static final String DOT_CLASS = ConstructionDetailsPanel.class.getName() + "."; + private static final String OPERATION_LOAD_RESOURCE = DOT_CLASS + "loadResource"; + + private LoadableDetachableModel> resourceModel; + + public ConstructionDetailsPanel(String id, IModel> constructionWrapperModel){ + super(id, constructionWrapperModel); + } + + @Override + protected void onInitialize(){ + super.onInitialize(); + initModels(); + initLayout(); + } + + private void initModels(){ + resourceModel = new LoadableDetachableModel>() { + @Override + protected PrismObject load() { + ConstructionType construction = (ConstructionType)getModelObject().getContainerValue().asContainerable(); + ObjectReferenceType resourceRef = construction.getResourceRef(); + Task loadResourceTask = getPageBase().createSimpleTask(OPERATION_LOAD_RESOURCE); + OperationResult result = new OperationResult(OPERATION_LOAD_RESOURCE); + PrismObject resource = WebModelServiceUtils.loadObject(resourceRef, getPageBase(), loadResourceTask, result); + result.computeStatusIfUnknown(); + if (!result.isAcceptable()) { + LOGGER.error("Cannot find resource referenced from construction. {}", result.getMessage()); + result.recordPartialError("Could not find resource referenced from construction."); + return null; + } + return resource; + } + }; + } + + private void initLayout(){ + DropDownChoicePanel kindDropDown = WebComponentUtil.createEnumPanel(ShadowKindType.class, ID_KIND_FIELD, + getPropertyModelForConstructionAttribute(ConstructionType.F_KIND), ConstructionDetailsPanel.this); + kindDropDown.setOutputMarkupId(true); + kindDropDown.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") { + + @Override + protected void onUpdate(AjaxRequestTarget target) { + target.add(getKindDropdownComponent()); + target.add(getIntentDropdownComponent()); + } + }); + add(kindDropDown); + + DropDownChoicePanel intentDropDown = new DropDownChoicePanel(ID_INTENT_FIELD, + getPropertyModelForConstructionAttribute(ConstructionType.F_INTENT), getIntentAvailableValuesModel()); + intentDropDown.setOutputMarkupId(true); + add(intentDropDown); + } + + private IModel> getIntentAvailableValuesModel(){ + return new LoadableModel>(true){ + private static final long serialVersionUID = 1L; + + @Override + protected List load(){ + List availableIntentValues = new ArrayList<>(); + if (resourceModel.getObject() == null){ + return availableIntentValues; + } + try { + RefinedResourceSchema refinedSchema = RefinedResourceSchema.getRefinedSchema(resourceModel.getObject()); + if (refinedSchema != null){ + ShadowKindType kind = (ShadowKindType) ConstructionDetailsPanel.this.getKindDropdownComponent().getBaseFormComponent().getModelObject(); + List definitions = refinedSchema.getRefinedDefinitions(kind); + for (RefinedObjectClassDefinition def : definitions){ + availableIntentValues.add(def.getIntent()); + } + } + } catch (SchemaException ex){ + LOGGER.error("Cannot get refined resource schema for resource {}. {}", resourceModel.getObject().getName().getOrig(), ex.getLocalizedMessage()); + } + + return availableIntentValues; + } + }; + } + + private PropertyModel getPropertyModelForConstructionAttribute(QName attributeName){ + //todo should be refactored. 1) relocate 2) wrap by some new kind of model + PropertyModel> propertiesModel = new PropertyModel<>(getModel(), "properties"); + List propertiesList = propertiesModel.getObject(); + for (final IW property : propertiesList){ + if (property.getName().equals(attributeName)){ + IModel itemWrapperModel = new IModel() { + @Override + public IW getObject() { + return property; + } + + @Override + public void setObject(IW iw) { + propertiesList.set(propertiesList.indexOf(property), iw); + } + + @Override + public void detach() { + + } + }; + PropertyModel> valuesModel = new PropertyModel<>(itemWrapperModel, "values"); + List valuesList = valuesModel.getObject(); + if (valuesList.size() > 0) { + IModel valueWrapperModel = new IModel() { + @Override + public ValueWrapper getObject() { + return valuesList.get(0); + } + + @Override + public void setObject(ValueWrapper valueWrapper) { + valuesList.set(0, valueWrapper); + } + + @Override + public void detach() { + + } + }; + return new PropertyModel<>(valueWrapperModel, "value.value"); + } + + } + } + return null; + } + + private DropDownChoicePanel getKindDropdownComponent(){ + return (DropDownChoicePanel) get(ID_KIND_FIELD); + } + + private DropDownChoicePanel getIntentDropdownComponent(){ + return (DropDownChoicePanel) get(ID_INTENT_FIELD); + } +} diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/prism/PrismContainerPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/prism/PrismContainerPanel.java index 3ed2d5ae6a9..810226b1691 100755 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/prism/PrismContainerPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/prism/PrismContainerPanel.java @@ -18,12 +18,17 @@ import java.util.List; +import com.evolveum.midpoint.web.component.assignment.ConstructionDetailsPanel; +import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel; +import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.AbstractReadOnlyModel; import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; import org.apache.wicket.model.PropertyModel; import com.evolveum.midpoint.gui.api.page.PageBase; @@ -32,6 +37,8 @@ import com.evolveum.midpoint.util.logging.TraceManager; import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour; +import javax.xml.namespace.QName; + /** * @author lazyman * @author semancik @@ -119,10 +126,15 @@ private void addOrReplaceProperties(IModel> model, final For @Override protected void populateItem(ListItem> item) { - ContainerValuePanel containerPanel = new ContainerValuePanel("value", item.getModel(), true, form, isPanelVisible, pageBase); - containerPanel.setOutputMarkupId(true); - item.add(containerPanel); - + if (model.getObject().getName().equals(AssignmentType.F_CONSTRUCTION)){ + ConstructionDetailsPanel panel = new ConstructionDetailsPanel("value", item.getModel()); + panel.setOutputMarkupId(true); + item.add(panel); + } else { + ContainerValuePanel containerPanel = new ContainerValuePanel("value", item.getModel(), true, form, isPanelVisible, pageBase); + containerPanel.setOutputMarkupId(true); + item.add(containerPanel); + } } From cd811b24ca7ef0ad7e574df10d16dfcf7c45861e Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Thu, 15 Feb 2018 16:49:33 +0100 Subject: [PATCH 2/7] Fixing superfluous "not applicable" message in object lists (MID-4380) --- .../component/data/SelectableBeanObjectDataProvider.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/data/SelectableBeanObjectDataProvider.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/data/SelectableBeanObjectDataProvider.java index 16a47095798..ed3d510c867 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/data/SelectableBeanObjectDataProvider.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/data/SelectableBeanObjectDataProvider.java @@ -233,9 +233,9 @@ protected int internalSize() { return Integer.MAX_VALUE; } int count = 0; - OperationResult result = new OperationResult(OPERATION_COUNT_OBJECTS); + Task task = getPage().createSimpleTask(OPERATION_COUNT_OBJECTS); + OperationResult result = task.getResult(); try { - Task task = getPage().createSimpleTask(OPERATION_COUNT_OBJECTS); Integer counted = getModel().countObjects(type, getQuery(), options, task, result); count = defaultIfNull(counted, 0); } catch (Exception ex) { @@ -244,8 +244,8 @@ protected int internalSize() { } finally { result.computeStatusIfUnknown(); } - - if (!WebComponentUtil.isSuccessOrHandledError(result)) { + + if (!WebComponentUtil.isSuccessOrHandledError(result) && !result.isNotApplicable()) { getPage().showResult(result); // Let us do nothing. The error will be shown on the page and a count of 0 will be used. // Redirecting to the error page does more harm than good (see also MID-4306). From 67d86ce26fac46ba7afdfc05e5ff10b6b5485591 Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Thu, 15 Feb 2018 18:13:10 +0100 Subject: [PATCH 3/7] Audit log CSS fix (MID-4300) --- .../admin/reports/PageAuditLogDetails.html | 38 +++++++++---------- .../admin/reports/PageAuditLogDetails.java | 17 ++++++++- .../component/AuditLogViewerPanel.java | 19 +++++++++- .../resources/static/less/midpoint-theme.less | 9 +++++ 4 files changed, 62 insertions(+), 21 deletions(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/PageAuditLogDetails.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/PageAuditLogDetails.html index 208e91f519e..f6183536c7e 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/PageAuditLogDetails.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/PageAuditLogDetails.html @@ -25,84 +25,84 @@
- + - - + - + - - - + - - + - + - - + - + - + - + - + - + - + - +
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/PageAuditLogDetails.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/PageAuditLogDetails.java index 7866a70543c..a8024b970a7 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/PageAuditLogDetails.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/PageAuditLogDetails.java @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2010-2018 Evolveum + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.evolveum.midpoint.web.page.admin.reports; import java.util.*; @@ -54,10 +69,10 @@ label = "PageAuditLogViewer.auth.auditLogViewer.label", description = "PageAuditLogViewer.auth.auditLogViewer.description")}) public class PageAuditLogDetails extends PageBase { + private static final long serialVersionUID = 1L; private static final Trace LOGGER = TraceManager.getTrace(PageAuditLogDetails.class); - private static final long serialVersionUID = 1L; private static final String ID_EVENT_PANEL = "eventPanel"; private static final String ID_DELTA_LIST_PANEL = "deltaListPanel"; diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/AuditLogViewerPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/AuditLogViewerPanel.java index 0b22e3c2a66..61a73db3a29 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/AuditLogViewerPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/component/AuditLogViewerPanel.java @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2010-2018 Evolveum + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.evolveum.midpoint.web.page.admin.reports.component; import static java.util.stream.Collectors.toList; @@ -82,6 +97,7 @@ */ public class AuditLogViewerPanel extends BasePanel { private static final long serialVersionUID = 1L; + private static final String ID_PARAMETERS_PANEL = "parametersPanel"; private static final String ID_TABLE = "table"; private static final String ID_FROM = "fromField"; @@ -503,8 +519,9 @@ protected List> initColumns() { @Override protected IModel createLinkModel(final IModel rowModel){ return new AbstractReadOnlyModel() { + private static final long serialVersionUID = 1L; - @Override + @Override public String getObject() { XMLGregorianCalendar time = rowModel.getObject().getTimestamp(); return WebComponentUtil.formatDate(time); diff --git a/gui/admin-gui/src/main/resources/static/less/midpoint-theme.less b/gui/admin-gui/src/main/resources/static/less/midpoint-theme.less index e7da6fe235d..647cde47593 100644 --- a/gui/admin-gui/src/main/resources/static/less/midpoint-theme.less +++ b/gui/admin-gui/src/main/resources/static/less/midpoint-theme.less @@ -1273,4 +1273,13 @@ dd.stacktrace::before { .box-content { padding: 15px; } +} + +// Tables where the first column is the name of the property/attribute +// (e.g. audit log item details) +// see MID-4300 + +td.prop-name { + min-width: 90px; + font-weight: bold; } \ No newline at end of file From 8b8e5d87083807197957b10865675a924e3cd749 Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Fri, 16 Feb 2018 12:02:54 +0100 Subject: [PATCH 4/7] Fix midpoint.collectAssignedFocusMappingsResults We avoid collecting mappings from invalid assignments; and we cater for MID-4452 (re-evaluation of deleted assignments focus mappings in wave 1 and later). --- .../impl/expr/MidpointFunctionsImpl.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/expr/MidpointFunctionsImpl.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/expr/MidpointFunctionsImpl.java index e9ee9ca565c..6312695309b 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/expr/MidpointFunctionsImpl.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/expr/MidpointFunctionsImpl.java @@ -100,6 +100,7 @@ import static com.evolveum.midpoint.xml.ns._public.common.common_3.TaskExecutionStatusType.RUNNABLE; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; +import static org.apache.commons.collections4.CollectionUtils.emptyIfNull; /** * @author semancik @@ -1660,15 +1661,33 @@ public Collection collectAssignedFocusMappingsResults(@NotNull ItemP } Collection rv = new HashSet<>(); for (EvaluatedAssignmentImpl evaluatedAssignment : evaluatedAssignmentTriple.getNonNegativeValues()) { - for (Mapping mapping : evaluatedAssignment.getFocusMappings()) { - if (path.equivalent(mapping.getOutputPath())) { - PrismValueDeltaSetTriple outputTriple = mapping.getOutputTriple(); - if (outputTriple != null) { - rv.addAll(outputTriple.getNonNegativeValues()); + if (evaluatedAssignment.isValid()) { + for (Mapping mapping : evaluatedAssignment.getFocusMappings()) { + if (path.equivalent(mapping.getOutputPath())) { + PrismValueDeltaSetTriple outputTriple = mapping.getOutputTriple(); + if (outputTriple != null) { + rv.addAll(outputTriple.getNonNegativeValues()); + } } } } } + // Ugly hack - MID-4452 - When having an assignment giving focusMapping, and the assignment is being deleted, the + // focus mapping is evaluated in wave 0 (results correctly being pushed to the minus set), but also in wave 1. + // The results are sent to zero set; and they are not applied only because they are already part of a priori delta. + // This causes problems here. + // + // Until MID-4452 is fixed, here we manually delete the values from the result. + LensFocusContext focusContext = lensContext.getFocusContext(); + if (focusContext != null) { + ObjectDelta delta = focusContext.getDelta(); + if (delta != null) { + ItemDelta targetItemDelta = delta.findItemDelta(path); + if (targetItemDelta != null) { + rv.removeAll(emptyIfNull(targetItemDelta.getValuesToDelete())); + } + } + } return rv; } } \ No newline at end of file From 7052f9628a76815d27a119090a97ec57fbdebaec Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Fri, 16 Feb 2018 13:04:27 +0100 Subject: [PATCH 5/7] Fixing failing model-intest --- .../com/evolveum/midpoint/util/MiscUtil.java | 1 + .../model/impl/lens/ChangeExecutor.java | 2 + .../model/intest/TestStrangeCases.java | 53 ++++++----- .../intest/negative/TestAssignmentErrors.java | 95 +++++++++---------- .../src/test/resources/logback-test.xml | 2 +- 5 files changed, 79 insertions(+), 74 deletions(-) diff --git a/infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java b/infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java index 0a647a9785f..222be795b99 100644 --- a/infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java +++ b/infra/util/src/main/java/com/evolveum/midpoint/util/MiscUtil.java @@ -260,6 +260,7 @@ public static void copyDirectory(File src, File dst) throws IOException { } } + @SafeVarargs public static Collection createCollection(T... items) { Collection collection = new ArrayList(items.length); for (T item: items) { diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/ChangeExecutor.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/ChangeExecutor.java index e2feac16bd9..627e8c33810 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/ChangeExecutor.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/ChangeExecutor.java @@ -916,7 +916,9 @@ private void executeDelta(ObjectDel } finally { + LOGGER.info("RRRR1: {}", result); result.computeStatus(); + LOGGER.info("RRRR2: {}", result); if (objectContext != null) { if (!objectDelta.hasCompleteDefinition()) { throw new SchemaException("object delta does not have complete definition"); diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestStrangeCases.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestStrangeCases.java index a50d5a72026..8221f160203 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestStrangeCases.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestStrangeCases.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2017 Evolveum + * Copyright (c) 2010-2018 Evolveum * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -225,6 +225,10 @@ public void test060AddRoleStupidAssignment() throws Exception { assertObject(role); } + /** + * Attempt to add account (red) that already exists, but it is not linked. + * Account is added using linkRef with account object. + */ @Test public void test100ModifyUserGuybrushAddAccountDummyRedNoAttributesConflict() throws Exception { final String TEST_NAME = "test100ModifyUserGuybrushAddAccountDummyRedNoAttributesConflict"; @@ -234,34 +238,35 @@ public void test100ModifyUserGuybrushAddAccountDummyRedNoAttributesConflict() th Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE); + + PrismObject userBefore = getUser(USER_GUYBRUSH_OID); + display("User before", userBefore); PrismObject account = PrismTestUtil.parseObject(ACCOUNT_GUYBRUSH_DUMMY_RED_FILE); // Remove the attributes. This will allow outbound mapping to take place instead. account.removeContainer(ShadowType.F_ATTRIBUTES); + display("New account", account); ObjectDelta userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_GUYBRUSH_OID, prismContext); PrismReferenceValue accountRefVal = new PrismReferenceValue(); accountRefVal.setObject(account); ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal); userDelta.addModification(accountDelta); - Collection> deltas = (Collection)MiscUtil.createCollection(userDelta); dummyAuditService.clear(); - try { - - // WHEN - modelService.executeChanges(deltas, null, task, getCheckingProgressListenerCollection(), result); - - AssertJUnit.fail("Unexpected executeChanges success"); - } catch (ObjectAlreadyExistsException e) { - // This is expected - display("Expected exception", e); - } + // WHEN + displayWhen(TEST_NAME); + modelService.executeChanges(MiscUtil.createCollection(userDelta), null, task, getCheckingProgressListenerCollection(), result); + // THEN + displayThen(TEST_NAME); + assertPartialError(result); + // Check accountRef - PrismObject userGuybrush = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, null, task, result); - UserType userGuybrushType = userGuybrush.asObjectable(); + PrismObject userAfter = modelService.getObject(UserType.class, USER_GUYBRUSH_OID, null, task, result); + display("User after", userAfter); + UserType userGuybrushType = userAfter.asObjectable(); assertEquals("Unexpected number of accountRefs", 1, userGuybrushType.getLinkRef().size()); ObjectReferenceType accountRefType = userGuybrushType.getLinkRef().get(0); String accountOid = accountRefType.getOid(); @@ -281,19 +286,23 @@ public void test100ModifyUserGuybrushAddAccountDummyRedNoAttributesConflict() th // Check account in dummy resource assertDefaultDummyAccount(ACCOUNT_GUYBRUSH_DUMMY_USERNAME, "Guybrush Threepwood", true); - result.computeStatus(); - display("executeChanges result", result); - TestUtil.assertFailure("executeChanges result", result); - // Check audit display("Audit", dummyAuditService); - dummyAuditService.assertRecords(2); + // Strictly speaking, there should be just 2 records, not 3. + // But this is a strange case, not a common one. Midpoint does two attempts. + // We do not really mind about extra provisioning attempts. + dummyAuditService.assertRecords(3); dummyAuditService.assertSimpleRecordSanity(); dummyAuditService.assertAnyRequestDeltas(); + Collection> auditExecution0Deltas = dummyAuditService.getExecutionDeltas(0); - assertEquals("Wrong number of execution deltas", 0, auditExecution0Deltas.size()); - dummyAuditService.assertExecutionOutcome(OperationResultStatus.FATAL_ERROR); - + assertEquals("Wrong number of execution deltas", 3, auditExecution0Deltas.size()); + // SUCCESS because there is a handled error. Real error is in next audit record. + dummyAuditService.assertExecutionOutcome(0, OperationResultStatus.SUCCESS); + + auditExecution0Deltas = dummyAuditService.getExecutionDeltas(1); + assertEquals("Wrong number of execution deltas", 2, auditExecution0Deltas.size()); + dummyAuditService.assertExecutionOutcome(1, OperationResultStatus.PARTIAL_ERROR); } @Test diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/negative/TestAssignmentErrors.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/negative/TestAssignmentErrors.java index 0b597938414..550c35ff918 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/negative/TestAssignmentErrors.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/negative/TestAssignmentErrors.java @@ -175,10 +175,10 @@ public void test010RefinedSchemaWhite() throws Exception { @Test public void test100UserJackAssignBlankAccount() throws Exception { final String TEST_NAME = "test100UserJackAssignBlankAccount"; - TestUtil.displayTestTitle(this, TEST_NAME); + displayTestTitle(TEST_NAME); // GIVEN - Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL); @@ -218,10 +218,10 @@ public void test100UserJackAssignBlankAccount() throws Exception { @Test public void test101AddUserCharlesAssignBlankAccount() throws Exception { final String TEST_NAME = "test101AddUserCharlesAssignBlankAccount"; - TestUtil.displayTestTitle(this, TEST_NAME); + displayTestTitle(TEST_NAME); // GIVEN - Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL); dummyAuditService.clear(); @@ -260,10 +260,10 @@ public void test101AddUserCharlesAssignBlankAccount() throws Exception { @Test public void test200UserLemonheadAssignAccountBrokenNetwork() throws Exception { final String TEST_NAME = "test200UserLemonheadAssignAccountBrokenNetwork"; - TestUtil.displayTestTitle(this, TEST_NAME); + displayTestTitle(TEST_NAME); // GIVEN - Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL); @@ -307,7 +307,7 @@ public void test200UserLemonheadAssignAccountBrokenNetwork() throws Exception { // TestUtil.displayTestTile(this, TEST_NAME); // // // GIVEN -// Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); +// Task task = createTask(TEST_NAME); // OperationResult result = task.getResult(); // assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL); // @@ -338,10 +338,10 @@ public void test200UserLemonheadAssignAccountBrokenNetwork() throws Exception { @Test public void test210UserSharptoothAssignAccountBrokenGeneric() throws Exception { final String TEST_NAME = "test210UserSharptoothAssignAccountBrokenGeneric"; - TestUtil.displayTestTitle(this, TEST_NAME); + displayTestTitle(TEST_NAME); // GIVEN - Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL); @@ -407,10 +407,10 @@ public void test210UserSharptoothAssignAccountBrokenGeneric() throws Exception { @Test public void test212UserSharptoothAssignAccountRecovery() throws Exception { final String TEST_NAME = "test212UserSharptoothAssignAccountRecovery"; - TestUtil.displayTestTitle(this, TEST_NAME); + displayTestTitle(TEST_NAME); // GIVEN - Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL); @@ -457,10 +457,10 @@ public void test215UserSharptoothChangePasswordGenericError() throws Exception { } public void testUserSharptoothChangePasswordError(final String TEST_NAME, BreakMode breakMode, String oldPassword, String newPassword, OperationResultStatus expectedResultStatus) throws Exception { - TestUtil.displayTestTitle(this, TEST_NAME); + displayTestTitle(TEST_NAME); // GIVEN - Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL); @@ -495,13 +495,13 @@ public void testUserSharptoothChangePasswordError(final String TEST_NAME, BreakM @Test public void test220UserAssignAccountDeletedShadowRecomputeSync() throws Exception { final String TEST_NAME = "test220UserAssignAccountDeletedShadowRecomputeSync"; - TestUtil.displayTestTitle(this, TEST_NAME); + displayTestTitle(TEST_NAME); //GIVEN PrismObject user = setupUserAssignAccountDeletedShadowRecompute(TEST_NAME, RESOURCE_DUMMY_OID, null, USER_AFET_NAME, USER_AFET_FULLNAME); String shadowOidBefore = getSingleLinkOid(user); - Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); // WHEN @@ -523,7 +523,7 @@ public void test220UserAssignAccountDeletedShadowRecomputeSync() throws Exceptio // ... and again ... - task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + task = createTask(TEST_NAME); result = task.getResult(); // WHEN @@ -544,56 +544,49 @@ public void test220UserAssignAccountDeletedShadowRecomputeSync() throws Exceptio /** * Assign account to user, delete the account shadow (not the account), recompute the user. - * We expect ObjectAlreadyExistsException. + * We expect an error. * * This is tried on the red dummy resource where there is no synchronization. */ @Test public void test222UserAssignAccountDeletedShadowRecomputeNoSync() throws Exception { final String TEST_NAME = "test222UserAssignAccountDeletedShadowRecomputeNoSync"; - TestUtil.displayTestTitle(this, TEST_NAME); + displayTestTitle(TEST_NAME); //GIVEN - PrismObject user = setupUserAssignAccountDeletedShadowRecompute(TEST_NAME, RESOURCE_DUMMY_RED_OID, RESOURCE_DUMMY_RED_NAME, + PrismObject userBefore = setupUserAssignAccountDeletedShadowRecompute(TEST_NAME, RESOURCE_DUMMY_RED_OID, RESOURCE_DUMMY_RED_NAME, USER_BFET_NAME, USER_BFET_FULLNAME); - Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); - try { - // WHEN - recomputeUser(user.getOid(), task, result); + // WHEN + displayWhen(TEST_NAME); + recomputeUser(userBefore.getOid(), task, result); - AssertJUnit.fail("Unexpected success"); - } catch (ObjectAlreadyExistsException e) { - // this is expected - result.computeStatus(); - TestUtil.assertFailure(result); - } + // THEN + displayThen(TEST_NAME); + assertPartialError(result); - user = getUser(user.getOid()); - display("User after", user); - assertNoLinkedAccount(user); + PrismObject userAfter = getUser(userBefore.getOid()); + display("User after", userAfter); + assertNoLinkedAccount(userAfter); // and again ... - task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + task = createTask(TEST_NAME); result = task.getResult(); - try { - // WHEN - recomputeUser(user.getOid(), task, result); - - AssertJUnit.fail("Unexpected success"); - } catch (ObjectAlreadyExistsException e) { - // this is expected - result.computeStatus(); - TestUtil.assertFailure(result); - } - - user = getUser(user.getOid()); - display("User after", user); - assertNoLinkedAccount(user); - + // WHEN + displayWhen(TEST_NAME); + recomputeUser(userAfter.getOid(), task, result); + + // THEN + displayThen(TEST_NAME); + assertPartialError(result); + + userAfter = getUser(userAfter.getOid()); + display("User after", userAfter); + assertNoLinkedAccount(userAfter); } /** @@ -605,14 +598,14 @@ public void test222UserAssignAccountDeletedShadowRecomputeNoSync() throws Except @Test public void test224UserAssignAccountDeletedShadowRecomputeReducedSync() throws Exception { final String TEST_NAME = "test224UserAssignAccountDeletedShadowRecomputeReducedSync"; - TestUtil.displayTestTitle(this, TEST_NAME); + displayTestTitle(TEST_NAME); //GIVEN PrismObject user = setupUserAssignAccountDeletedShadowRecompute(TEST_NAME, RESOURCE_DUMMY_YELLOW_OID, RESOURCE_DUMMY_YELLOW_NAME, USER_CFET_NAME, USER_CFET_FULLNAME); String shadowOidBefore = getSingleLinkOid(user); - Task task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); // WHEN @@ -634,7 +627,7 @@ public void test224UserAssignAccountDeletedShadowRecomputeReducedSync() throws E // ... and again ... - task = taskManager.createTaskInstance(TestAssignmentErrors.class.getName() + "." + TEST_NAME); + task = createTask(TEST_NAME); result = task.getResult(); // WHEN diff --git a/model/model-intest/src/test/resources/logback-test.xml b/model/model-intest/src/test/resources/logback-test.xml index 4de62521a44..77b3539fdbc 100644 --- a/model/model-intest/src/test/resources/logback-test.xml +++ b/model/model-intest/src/test/resources/logback-test.xml @@ -68,7 +68,7 @@ - + From b933895e69a7c6f765006f89e8fecbb995fd8b13 Mon Sep 17 00:00:00 2001 From: kate Date: Fri, 16 Feb 2018 14:40:31 +0100 Subject: [PATCH 6/7] association panel simplified (but hidden for now) --- .../gui/api/util/WebComponentUtil.java | 20 +++- .../assignment/AssociationDetailsPanel.html | 61 +++++++++++ .../assignment/AssociationDetailsPanel.java | 102 ++++++++++++++++++ .../assignment/ConstructionDetailsPanel.html | 8 +- .../assignment/ConstructionDetailsPanel.java | 85 ++++++--------- .../component/prism/PrismContainerPanel.java | 13 +-- .../localization/Midpoint.properties | 2 + .../resources/localization/schema.properties | 1 + 8 files changed, 225 insertions(+), 67 deletions(-) create mode 100644 gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssociationDetailsPanel.html create mode 100644 gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssociationDetailsPanel.java diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebComponentUtil.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebComponentUtil.java index f0d7f91b310..57f8112b350 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebComponentUtil.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebComponentUtil.java @@ -53,9 +53,7 @@ import com.evolveum.midpoint.schema.util.LocalizationUtil; import com.evolveum.midpoint.util.*; import com.evolveum.midpoint.web.component.data.SelectableBeanObjectDataProvider; -import com.evolveum.midpoint.web.component.prism.InputPanel; -import com.evolveum.midpoint.web.component.prism.ItemWrapper; -import com.evolveum.midpoint.web.component.prism.ObjectWrapper; +import com.evolveum.midpoint.web.component.prism.*; import com.evolveum.midpoint.web.util.ObjectTypeGuiDescriptor; import com.evolveum.midpoint.xml.ns._public.common.common_3.*; import org.apache.commons.collections4.CollectionUtils; @@ -873,6 +871,22 @@ public List getObject() { } + public static PropertyModel createPrismPropertySingleValueModel(IModel> containerModel, + QName attributeName){ + //todo should be refactored: wrap with some new model + PropertyModel> propertiesModel = new PropertyModel<>(containerModel, "properties"); + List propertiesList = propertiesModel.getObject(); + for (final IW property : propertiesList){ + if (property.getName().equals(attributeName)){ + List valuesList = property.getValues(); + if (valuesList.size() == 1) { + return new PropertyModel<>(valuesList.get(0).getValue(), "value"); + } + + } + } + return null; + } private static List getDisplayableValues(PrismPropertyDefinition def) { List values = null; diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssociationDetailsPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssociationDetailsPanel.html new file mode 100644 index 00000000000..95d6fb44d30 --- /dev/null +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssociationDetailsPanel.html @@ -0,0 +1,61 @@ + + + + + +
+
+ +
+ + +
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ + diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssociationDetailsPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssociationDetailsPanel.java new file mode 100644 index 00000000000..8ed7e55c219 --- /dev/null +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/AssociationDetailsPanel.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2015-2018 Evolveum + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.evolveum.midpoint.web.component.assignment; + +import com.evolveum.midpoint.gui.api.GuiStyleConstants; +import com.evolveum.midpoint.gui.api.component.BasePanel; +import com.evolveum.midpoint.gui.api.component.togglebutton.ToggleIconButton; +import com.evolveum.midpoint.gui.api.util.WebComponentUtil; +import com.evolveum.midpoint.prism.path.ItemPath; +import com.evolveum.midpoint.web.component.input.ExpressionValuePanel; +import com.evolveum.midpoint.web.component.input.QNameEditorPanel; +import com.evolveum.midpoint.web.component.prism.ContainerValueWrapper; +import com.evolveum.midpoint.web.component.prism.ContainerWrapper; +import com.evolveum.midpoint.web.component.prism.PrismContainerValueHeaderPanel; +import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour; +import com.evolveum.midpoint.xml.ns._public.common.common_3.*; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.behavior.AttributeAppender; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.PropertyModel; + +import javax.xml.namespace.QName; +import java.util.List; + +/** + * Created by honchar + */ +public class AssociationDetailsPanel extends BasePanel>{ + private static final long serialVersionUID = 1L; + + private static final String ID_REF_FIELD = "refField"; + private static final String ID_EXPRESSION_PANEL = "expressionPanel"; + private static final String ID_REMOVE_ASSOCIATION = "removeAssociation"; + + private ConstructionType construction; + + public AssociationDetailsPanel(String id, IModel> associationWrapperModel, + ConstructionType construction){ + super(id, associationWrapperModel); + this.construction = construction; + } + + @Override + protected void onInitialize(){ + super.onInitialize(); + initLayout(); + } + + private void initLayout(){ + QNameEditorPanel refField = new QNameEditorPanel(ID_REF_FIELD, WebComponentUtil.createPrismPropertySingleValueModel(getModel(), ResourceObjectAssociationType.F_REF), + null, null, false, false){ + private static final long serialVersionUID = 1L; + @Override + protected AttributeAppender getSpecificLabelStyleAppender() { + return AttributeAppender.append("style", "font-weight: normal !important;"); + } + }; + refField.setOutputMarkupId(true); + add(refField); + + ResourceObjectAssociationType resourceObjectAssociationType = getModelObject().getContainerValue().asContainerable(); + MappingType outbound = resourceObjectAssociationType.getOutbound(); + ExpressionValuePanel expressionValuePanel = new ExpressionValuePanel(ID_EXPRESSION_PANEL, + new PropertyModel(outbound, MappingType.F_EXPRESSION.getLocalPart()), + construction, getPageBase()); + expressionValuePanel.setOutputMarkupId(true); + add(expressionValuePanel); + + ToggleIconButton removeAssociationButton = new ToggleIconButton(ID_REMOVE_ASSOCIATION, + GuiStyleConstants.CLASS_MINUS_CIRCLE_DANGER, GuiStyleConstants.CLASS_MINUS_CIRCLE_DANGER) { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) { +// isChildContainersSelectorPanelVisible = true; +// target.add(PrismContainerValueHeaderPanel.this); + } + + @Override + public boolean isOn() { + return true; + } + }; + add(removeAssociationButton); + + + } +} diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.html b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.html index 1d41071ab47..b49348a8b40 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.html +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.html @@ -26,7 +26,7 @@
-
+
@@ -36,7 +36,7 @@
-
+
@@ -50,6 +50,8 @@
- +
+
+
diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.java index 47a6413a45f..969ca57b570 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/assignment/ConstructionDetailsPanel.java @@ -32,14 +32,13 @@ import com.evolveum.midpoint.web.component.prism.ContainerValueWrapper; import com.evolveum.midpoint.web.component.prism.ItemWrapper; import com.evolveum.midpoint.web.component.prism.ValueWrapper; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType; -import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.*; import org.apache.wicket.ajax.AjaxEventBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.ListView; import org.apache.wicket.model.IModel; import org.apache.wicket.model.LoadableDetachableModel; import org.apache.wicket.model.Model; @@ -58,6 +57,8 @@ public class ConstructionDetailsPanel load() { private void initLayout(){ DropDownChoicePanel kindDropDown = WebComponentUtil.createEnumPanel(ShadowKindType.class, ID_KIND_FIELD, - getPropertyModelForConstructionAttribute(ConstructionType.F_KIND), ConstructionDetailsPanel.this); + WebComponentUtil.createPrismPropertySingleValueModel(getModel(), ConstructionType.F_KIND), ConstructionDetailsPanel.this); kindDropDown.setOutputMarkupId(true); kindDropDown.getBaseFormComponent().add(new AjaxFormComponentUpdatingBehavior("change") { @@ -111,9 +112,32 @@ protected void onUpdate(AjaxRequestTarget target) { add(kindDropDown); DropDownChoicePanel intentDropDown = new DropDownChoicePanel(ID_INTENT_FIELD, - getPropertyModelForConstructionAttribute(ConstructionType.F_INTENT), getIntentAvailableValuesModel()); + WebComponentUtil.createPrismPropertySingleValueModel(getModel(), ConstructionType.F_INTENT), getIntentAvailableValuesModel()); intentDropDown.setOutputMarkupId(true); add(intentDropDown); + + + ListView> associationDetailsPanel = + new ListView>(ID_ASSOCIATION_CONTAINER, getAssociationsModel()){ + @Override + protected void populateItem(ListItem> item) { + item.add(new AssociationDetailsPanel(ID_ASSOCIATION, item.getModel(), + (ConstructionType)ConstructionDetailsPanel.this.getModelObject().getContainerValue().asContainerable())); + } + }; + associationDetailsPanel.setOutputMarkupId(true); + add(associationDetailsPanel); + } + + private PropertyModel>> getAssociationsModel(){ +// PropertyModel> propertiesModel = new PropertyModel<>(get, "properties"); + List propertiesList = getModelObject().getItems(); + for (ItemWrapper property : propertiesList){ + if (property.getName().equals(ConstructionType.F_ASSOCIATION)){ + return new PropertyModel>>(property, "values"); + } + } + return null; } private IModel> getIntentAvailableValuesModel(){ @@ -144,55 +168,6 @@ protected List load(){ }; } - private PropertyModel getPropertyModelForConstructionAttribute(QName attributeName){ - //todo should be refactored. 1) relocate 2) wrap by some new kind of model - PropertyModel> propertiesModel = new PropertyModel<>(getModel(), "properties"); - List propertiesList = propertiesModel.getObject(); - for (final IW property : propertiesList){ - if (property.getName().equals(attributeName)){ - IModel itemWrapperModel = new IModel() { - @Override - public IW getObject() { - return property; - } - - @Override - public void setObject(IW iw) { - propertiesList.set(propertiesList.indexOf(property), iw); - } - - @Override - public void detach() { - - } - }; - PropertyModel> valuesModel = new PropertyModel<>(itemWrapperModel, "values"); - List valuesList = valuesModel.getObject(); - if (valuesList.size() > 0) { - IModel valueWrapperModel = new IModel() { - @Override - public ValueWrapper getObject() { - return valuesList.get(0); - } - - @Override - public void setObject(ValueWrapper valueWrapper) { - valuesList.set(0, valueWrapper); - } - - @Override - public void detach() { - - } - }; - return new PropertyModel<>(valueWrapperModel, "value.value"); - } - - } - } - return null; - } - private DropDownChoicePanel getKindDropdownComponent(){ return (DropDownChoicePanel) get(ID_KIND_FIELD); } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/prism/PrismContainerPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/prism/PrismContainerPanel.java index 810226b1691..30ffcc51263 100755 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/prism/PrismContainerPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/component/prism/PrismContainerPanel.java @@ -126,15 +126,16 @@ private void addOrReplaceProperties(IModel> model, final For @Override protected void populateItem(ListItem> item) { - if (model.getObject().getName().equals(AssignmentType.F_CONSTRUCTION)){ - ConstructionDetailsPanel panel = new ConstructionDetailsPanel("value", item.getModel()); - panel.setOutputMarkupId(true); - item.add(panel); - } else { + //todo simplified construction panel will be in the gui starting from 3.8 +// if (model.getObject().getName().equals(AssignmentType.F_CONSTRUCTION)){ +// ConstructionDetailsPanel panel = new ConstructionDetailsPanel("value", item.getModel()); +// panel.setOutputMarkupId(true); +// item.add(panel); +// } else { ContainerValuePanel containerPanel = new ContainerValuePanel("value", item.getModel(), true, form, isPanelVisible, pageBase); containerPanel.setOutputMarkupId(true); item.add(containerPanel); - } +// } } diff --git a/gui/admin-gui/src/main/resources/localization/Midpoint.properties b/gui/admin-gui/src/main/resources/localization/Midpoint.properties index 0475cc79975..2445749d6d0 100755 --- a/gui/admin-gui/src/main/resources/localization/Midpoint.properties +++ b/gui/admin-gui/src/main/resources/localization/Midpoint.properties @@ -3917,6 +3917,8 @@ TreeTablePanel.menu.unassignApproversSelected=Unassign selected approvers TreeTablePanel.menu.unassignOwnersSelected=Unassign selected owners TreeTablePanel.menu.unassignManagersSelected=Unassign selected managers Button.cancel=Cancel +AssociationDetailsPanel.expressionPanel=Outbound expression +AssociationDetailsPanel.AssociationHeader=Association RoleRelationSelectionPanel.select.relation=Select relations to process operation.com.evolveum.midpoint.web.page.admin.workflow.PageWorkItem.delegateWorkItem=Delegate work item AbstractRoleAssignmentPanel.relationLabel=Relation diff --git a/infra/schema/src/main/resources/localization/schema.properties b/infra/schema/src/main/resources/localization/schema.properties index fe7b0f34447..b40f1aaf6ed 100755 --- a/infra/schema/src/main/resources/localization/schema.properties +++ b/infra/schema/src/main/resources/localization/schema.properties @@ -680,6 +680,7 @@ MetadataType.certifierComment=Certifier comment MetadataType.originMappingName=Originating mapping name MetadataType.createTaskRef=Created by task MetadataType.modifyTaskRef=Modified by task +ResourceObjectAssociationType.ref=ref relation.default=default relation.manager=manager relation.meta=meta From 1e22a1fe4f0b190ceedcb4f5ff1f282f76b0baf2 Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Fri, 16 Feb 2018 15:26:25 +0100 Subject: [PATCH 7/7] Fix of task objectRef filter processing. (MID-4440) --- .../prism/query/builder/R_Filter.java | 5 + .../query/builder/S_AtomicFilterEntry.java | 7 +- .../AbstractGroupingManualResourceTest.java | 13 ++- .../manual/AbstractManualResourceTest.java | 10 +- .../TestSemiManualGroupingProposed.java | 64 ++++++++++++ .../src/test/resources/logback-test.xml | 9 +- ...resource-semi-manual-grouping-proposed.xml | 7 +- .../test/AbstractModelIntegrationTest.java | 99 ++++++++++++------- .../impl/tasks/WfTaskCreationInstruction.java | 2 +- .../AbstractSearchIterativeTaskHandler.java | 8 +- .../task/quartzimpl/TaskQuartzImpl.java | 9 +- 11 files changed, 169 insertions(+), 64 deletions(-) diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/R_Filter.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/R_Filter.java index 08f67fe9bdc..8e00ccd939b 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/R_Filter.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/R_Filter.java @@ -346,6 +346,11 @@ public S_AtomicFilterEntry not() { public S_ConditionEntry item(QName... names) { return item(new ItemPath(names)); } + + @Override + public S_ConditionEntry item(String... names) { + return item(new ItemPath(names)); + } @Override public S_ConditionEntry item(ItemPath itemPath) { diff --git a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/S_AtomicFilterEntry.java b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/S_AtomicFilterEntry.java index 063c95ca551..6d633a331ec 100644 --- a/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/S_AtomicFilterEntry.java +++ b/infra/prism/src/main/java/com/evolveum/midpoint/prism/query/builder/S_AtomicFilterEntry.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Evolveum + * Copyright (c) 2010-2018 Evolveum * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,9 @@ public interface S_AtomicFilterEntry { S_AtomicFilterExit all(); S_AtomicFilterExit none(); S_AtomicFilterExit undefined(); - S_ConditionEntry item(QName... names) ; - S_ConditionEntry item(ItemPath path) ; + S_ConditionEntry item(QName... names); + S_ConditionEntry item(String... names); + S_ConditionEntry item(ItemPath path); S_ConditionEntry item(ItemPath itemPath, ItemDefinition itemDefinition); S_ConditionEntry itemWithDef(ItemDefinition itemDefinition, QName... names); // experimental S_ConditionEntry item(PrismContainerDefinition containerDefinition, QName... names); diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/AbstractGroupingManualResourceTest.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/AbstractGroupingManualResourceTest.java index ef136e3d834..b5fa98f63c6 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/AbstractGroupingManualResourceTest.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/AbstractGroupingManualResourceTest.java @@ -72,6 +72,7 @@ import com.evolveum.midpoint.test.IntegrationTestTools; import com.evolveum.midpoint.test.util.ParallelTestThread; import com.evolveum.midpoint.test.util.TestUtil; +import com.evolveum.midpoint.util.exception.CommonException; import com.evolveum.midpoint.util.exception.SchemaException; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; @@ -165,13 +166,23 @@ protected void runPropagation() throws Exception { if (propagationTaskOid == null) { addTask(getPropagationTaskFile()); propagationTaskOid = getPropagationTaskOid(); + assertNewPropagationTask(); waitForTaskStart(propagationTaskOid, true); } else { restartTask(propagationTaskOid); } - waitForTaskFinish(propagationTaskOid, true); + Task finishedTask = waitForTaskFinish(propagationTaskOid, true); + assertFinishedPropagationTask(finishedTask); } + protected void assertNewPropagationTask() throws Exception { + + } + + protected void assertFinishedPropagationTask(Task finishedTask) { + + } + protected abstract String getPropagationTaskOid(); protected abstract File getPropagationTaskFile(); diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/AbstractManualResourceTest.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/AbstractManualResourceTest.java index 8efb0ff617c..41ae45fc191 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/AbstractManualResourceTest.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/AbstractManualResourceTest.java @@ -263,7 +263,7 @@ protected boolean hasMultivalueInterests() { @Test public void test000Sanity() throws Exception { final String TEST_NAME = "test000Sanity"; - TestUtil.displayTestTitle(TEST_NAME); + displayTestTitle(TEST_NAME); OperationResult result = new OperationResult(AbstractManualResourceTest.class.getName() + "." + TEST_NAME); @@ -291,7 +291,7 @@ public void test000Sanity() throws Exception { @Test public void test003Connection() throws Exception { final String TEST_NAME = "test003Connection"; - TestUtil.displayTestTitle(TEST_NAME); + displayTestTitle(TEST_NAME); // GIVEN Task task = createTask(TEST_NAME); OperationResult result = task.getResult(); @@ -344,7 +344,7 @@ public void test003Connection() throws Exception { @Test public void test004Configuration() throws Exception { final String TEST_NAME = "test004Configuration"; - TestUtil.displayTestTitle(TEST_NAME); + displayTestTitle(TEST_NAME); // GIVEN OperationResult result = new OperationResult(AbstractManualResourceTest.class.getName() + "." + TEST_NAME); @@ -369,7 +369,7 @@ public void test004Configuration() throws Exception { @Test public void test005ParsedSchema() throws Exception { final String TEST_NAME = "test005ParsedSchema"; - TestUtil.displayTestTitle(TEST_NAME); + displayTestTitle(TEST_NAME); // GIVEN OperationResult result = new OperationResult(AbstractManualResourceTest.class.getName() + "." + TEST_NAME); @@ -415,7 +415,7 @@ public void test005ParsedSchema() throws Exception { @Test public void test006Capabilities() throws Exception { final String TEST_NAME = "test006Capabilities"; - TestUtil.displayTestTitle(TEST_NAME); + displayTestTitle(TEST_NAME); // GIVEN OperationResult result = new OperationResult(AbstractManualResourceTest.class.getName()+"."+TEST_NAME); diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/TestSemiManualGroupingProposed.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/TestSemiManualGroupingProposed.java index eee3e3d0a61..48d448ae0e5 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/TestSemiManualGroupingProposed.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/manual/TestSemiManualGroupingProposed.java @@ -19,6 +19,7 @@ */ package com.evolveum.midpoint.model.intest.manual; +import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNotNull; import static org.testng.AssertJUnit.assertNull; @@ -32,16 +33,28 @@ import org.testng.annotations.Test; import com.evolveum.midpoint.prism.PrismObject; +import com.evolveum.midpoint.prism.query.FilterUtils; +import com.evolveum.midpoint.prism.query.ObjectQuery; +import com.evolveum.midpoint.prism.query.builder.QueryBuilder; +import com.evolveum.midpoint.schema.SearchResultList; import com.evolveum.midpoint.schema.constants.SchemaConstants; import com.evolveum.midpoint.schema.internals.InternalCounters; import com.evolveum.midpoint.schema.result.OperationResult; import com.evolveum.midpoint.task.api.Task; +import com.evolveum.midpoint.test.IntegrationTestTools; +import com.evolveum.midpoint.util.exception.CommonException; +import com.evolveum.midpoint.util.exception.ObjectNotFoundException; +import com.evolveum.midpoint.util.exception.SchemaException; import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType; import com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationExecutionStatusType; import com.evolveum.midpoint.xml.ns._public.common.common_3.PendingOperationType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType; import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType; import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType; import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType; +import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType; /** * MID-4347 @@ -65,6 +78,57 @@ protected File getResourceFile() { return RESOURCE_SEMI_MANUAL_GROUPING_PROPOSED_FILE; } + @Override + public void initSystem(Task initTask, OperationResult initResult) throws Exception { + super.initSystem(initTask, initResult); + + // More resources. Not really used. They are here just to confuse propagation task. + initDummyResourcePirate(RESOURCE_DUMMY_RED_NAME, + RESOURCE_DUMMY_RED_FILE, RESOURCE_DUMMY_RED_OID, initTask, initResult); + + initDummyResourcePirate(RESOURCE_DUMMY_BLUE_NAME, + RESOURCE_DUMMY_BLUE_FILE, RESOURCE_DUMMY_BLUE_OID, initTask, initResult); + } + + @Test + public void test020ResourcesSanity() throws Exception { + final String TEST_NAME = "test020ResourcesSanity"; + displayTestTitle(TEST_NAME); + + Task task = createTask(TEST_NAME); + OperationResult result = task.getResult(); + + SearchResultList> resources = repositoryService.searchObjects(ResourceType.class, null, null, result); + display("Resources", resources.size() + ": " + resources); + assertEquals("Unexpected number of resources", 3, resources.size()); + + ObjectQuery query = QueryBuilder.queryFor(ResourceType.class, prismContext) + .item("extension","provisioning").eq("propagated") + .build(); + SearchResultList> propagatedResources = repositoryService.searchObjects(ResourceType.class, query, null, result); + display("Propagated resources", propagatedResources.size() + ": " + propagatedResources); + assertEquals("Unexpected number of propagated resources", 1, propagatedResources.size()); + } + + @Override + protected void assertNewPropagationTask() throws Exception { + OperationResult result = new OperationResult("assertNewPropagationTask"); + PrismObject propTask = repositoryService.getObject(TaskType.class, getPropagationTaskOid(), null, result); + display("Propagation task (new)", propTask); + SearchFilterType filterType = propTask.asObjectable().getObjectRef().getFilter(); + display("Propagation task filter", filterType); + assertFalse("Empty filter in propagation task", FilterUtils.isFilterEmpty(filterType)); + } + + @Override + protected void assertFinishedPropagationTask(Task finishedTask) { + display("Propagation task (finished)", finishedTask); + SearchFilterType filterType = finishedTask.getTaskType().getObjectRef().getFilter(); + display("Propagation task filter", filterType); + + assertEquals("Unexpected propagation task progress", 1, finishedTask.getProgress()); + } + /** * The resource has caseIgnore matching rule for username. Make sure everything * works well wih uppercase username. diff --git a/model/model-intest/src/test/resources/logback-test.xml b/model/model-intest/src/test/resources/logback-test.xml index 77b3539fdbc..998c2d5fc39 100644 --- a/model/model-intest/src/test/resources/logback-test.xml +++ b/model/model-intest/src/test/resources/logback-test.xml @@ -1,6 +1,6 @@ - + @@ -68,7 +68,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -114,6 +114,7 @@ + diff --git a/model/model-intest/src/test/resources/manual/resource-semi-manual-grouping-proposed.xml b/model/model-intest/src/test/resources/manual/resource-semi-manual-grouping-proposed.xml index 8de2490749b..f4293ed8e11 100644 --- a/model/model-intest/src/test/resources/manual/resource-semi-manual-grouping-proposed.xml +++ b/model/model-intest/src/test/resources/manual/resource-semi-manual-grouping-proposed.xml @@ -25,10 +25,15 @@ xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3" xmlns:cap="http://midpoint.evolveum.com/xml/ns/public/resource/capabilities-3" xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3" - xmlns:mr="http://prism.evolveum.com/xml/ns/public/matching-rule-3"> + xmlns:mr="http://prism.evolveum.com/xml/ns/public/matching-rule-3" + xmlns:rext="http://midpoint.evolveum.com/xml/ns/samples/resource"> Semi-Manual Proposed Grouping CSV Resource + + propagated + + diff --git a/model/model-test/src/main/java/com/evolveum/midpoint/model/test/AbstractModelIntegrationTest.java b/model/model-test/src/main/java/com/evolveum/midpoint/model/test/AbstractModelIntegrationTest.java index 68222875e8e..cc6d4bbe7ef 100644 --- a/model/model-test/src/main/java/com/evolveum/midpoint/model/test/AbstractModelIntegrationTest.java +++ b/model/model-test/src/main/java/com/evolveum/midpoint/model/test/AbstractModelIntegrationTest.java @@ -2694,52 +2694,77 @@ public void timeout() { IntegrationTestTools.waitFor("Waiting for " + taskOid + " close/suspend", checker, timeout, sleepTime); } - protected void waitForTaskFinish(String taskOid, boolean checkSubresult) throws CommonException { - waitForTaskFinish(taskOid, checkSubresult, DEFAULT_TASK_WAIT_TIMEOUT); + protected Task waitForTaskFinish(String taskOid, boolean checkSubresult) throws CommonException { + return waitForTaskFinish(taskOid, checkSubresult, DEFAULT_TASK_WAIT_TIMEOUT); } - protected void waitForTaskFinish(final String taskOid, final boolean checkSubresult, final int timeout) throws CommonException { - waitForTaskFinish(taskOid, checkSubresult, timeout, false); + protected Task waitForTaskFinish(final String taskOid, final boolean checkSubresult, final int timeout) throws CommonException { + return waitForTaskFinish(taskOid, checkSubresult, timeout, false); } - protected void waitForTaskFinish(final String taskOid, final boolean checkSubresult, final int timeout, final boolean errorOk) throws CommonException { + protected Task waitForTaskFinish(final String taskOid, final boolean checkSubresult, final int timeout, final boolean errorOk) throws CommonException { final OperationResult waitResult = new OperationResult(AbstractIntegrationTest.class+".waitForTaskFinish"); - Checker checker = new Checker() { - @Override - public boolean check() throws CommonException { - Task freshTask = taskManager.getTask(taskOid, waitResult); - OperationResult result = freshTask.getResult(); - if (verbose) display("Check result", result); - if (isError(result, checkSubresult)) { - if (errorOk) { - return true; - } else { - AssertJUnit.fail("Error in "+freshTask+": "+TestUtil.getErrorMessage(result)); - } - } - if (isUnknown(result, checkSubresult)) { - return false; + TaskFinishChecker checker = new TaskFinishChecker(taskOid, waitResult, checkSubresult, errorOk, timeout); + IntegrationTestTools.waitFor("Waiting for task " + taskOid + " finish", checker, timeout, DEFAULT_TASK_SLEEP_TIME); + return checker.getLastTask(); + } + + private class TaskFinishChecker implements Checker { + private final String taskOid; + private final OperationResult waitResult; + private final boolean checkSubresult; + private final boolean errorOk; + private final int timeout; + private Task freshTask; + + public TaskFinishChecker(String taskOid, OperationResult waitResult, boolean checkSubresult, + boolean errorOk, int timeout) { + super(); + this.taskOid = taskOid; + this.waitResult = waitResult; + this.checkSubresult = checkSubresult; + this.errorOk = errorOk; + this.timeout = timeout; + } + + @Override + public boolean check() throws CommonException { + freshTask = taskManager.getTask(taskOid, waitResult); + OperationResult result = freshTask.getResult(); + if (verbose) display("Check result", result); + if (isError(result, checkSubresult)) { + if (errorOk) { + return true; + } else { + AssertJUnit.fail("Error in "+freshTask+": "+TestUtil.getErrorMessage(result)); } -// assert !isUnknown(result, checkSubresult) : "Unknown result in "+freshTask+": "+IntegrationTestTools.getErrorMessage(result); - return !isInProgress(result, checkSubresult); } - @Override - public void timeout() { - try { - Task freshTask = taskManager.getTask(taskOid, waitResult); - OperationResult result = freshTask.getResult(); - LOGGER.debug("Result of timed-out task:\n{}", result.debugDump()); - assert false : "Timeout ("+timeout+") while waiting for "+freshTask+" to finish. Last result "+result; - } catch (ObjectNotFoundException e) { - LOGGER.error("Exception during task refresh: {}", e,e); - } catch (SchemaException e) { - LOGGER.error("Exception during task refresh: {}", e,e); - } + if (isUnknown(result, checkSubresult)) { + return false; } - }; - IntegrationTestTools.waitFor("Waiting for task " + taskOid + " finish", checker, timeout, DEFAULT_TASK_SLEEP_TIME); +// assert !isUnknown(result, checkSubresult) : "Unknown result in "+freshTask+": "+IntegrationTestTools.getErrorMessage(result); + return !isInProgress(result, checkSubresult); + } + + @Override + public void timeout() { + try { + Task freshTask = taskManager.getTask(taskOid, waitResult); + OperationResult result = freshTask.getResult(); + LOGGER.debug("Result of timed-out task:\n{}", result.debugDump()); + assert false : "Timeout ("+timeout+") while waiting for "+freshTask+" to finish. Last result "+result; + } catch (ObjectNotFoundException e) { + LOGGER.error("Exception during task refresh: {}", e,e); + } catch (SchemaException e) { + LOGGER.error("Exception during task refresh: {}", e,e); + } + } + + public Task getLastTask() { + return freshTask; + } } - + protected void waitForTaskStart(String taskOid, boolean checkSubresult) throws Exception { waitForTaskStart(taskOid, checkSubresult, DEFAULT_TASK_WAIT_TIMEOUT); } diff --git a/model/workflow-impl/src/main/java/com/evolveum/midpoint/wf/impl/tasks/WfTaskCreationInstruction.java b/model/workflow-impl/src/main/java/com/evolveum/midpoint/wf/impl/tasks/WfTaskCreationInstruction.java index e986aeb6506..83a2f3b570d 100644 --- a/model/workflow-impl/src/main/java/com/evolveum/midpoint/wf/impl/tasks/WfTaskCreationInstruction.java +++ b/model/workflow-impl/src/main/java/com/evolveum/midpoint/wf/impl/tasks/WfTaskCreationInstruction.java @@ -374,7 +374,7 @@ public Task createTask(WfTaskController taskController, Task parentTask, WfConfi if (taskObject != null) { task.setObjectRef(taskObject.getOid(), taskObject.getDefinition().getTypeName()); } else if (parentTask != null && parentTask.getObjectRef() != null) { - task.setObjectRef(parentTask.getObjectRef()); + task.setObjectRef(parentTask.getObjectRef().clone()); } if (task.getName() == null || task.getName().toPolyString().isEmpty()) { task.setName(taskName); diff --git a/repo/repo-common/src/main/java/com/evolveum/midpoint/repo/common/task/AbstractSearchIterativeTaskHandler.java b/repo/repo-common/src/main/java/com/evolveum/midpoint/repo/common/task/AbstractSearchIterativeTaskHandler.java index 40111e7ed24..a08e751b5a5 100644 --- a/repo/repo-common/src/main/java/com/evolveum/midpoint/repo/common/task/AbstractSearchIterativeTaskHandler.java +++ b/repo/repo-common/src/main/java/com/evolveum/midpoint/repo/common/task/AbstractSearchIterativeTaskHandler.java @@ -463,14 +463,14 @@ protected ObjectQuery createQueryFromTask(H handler, TaskRunResult runResult, Ta } protected ObjectQuery createQueryFromTaskIfExists(H handler, TaskRunResult runResult, Task task, OperationResult opResult) throws SchemaException { - Class objectClass = getType(task); - LOGGER.trace("Object class = {}", objectClass); + Class objectType = getType(task); + LOGGER.trace("Object type = {}", objectType); QueryType queryFromTask = getObjectQueryTypeFromTask(task); if (queryFromTask != null) { - ObjectQuery query = QueryJaxbConvertor.createObjectQuery(objectClass, queryFromTask, prismContext); + ObjectQuery query = QueryJaxbConvertor.createObjectQuery(objectType, queryFromTask, prismContext); if (LOGGER.isTraceEnabled()) { - LOGGER.trace("Using object query from the task: {}", query.debugDump()); + LOGGER.trace("Using object query from the task:\n{}", query.debugDump(1)); } return query; } else { diff --git a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskQuartzImpl.java b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskQuartzImpl.java index 7d3acdcd845..065e9450157 100644 --- a/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskQuartzImpl.java +++ b/repo/task-quartz-impl/src/main/java/com/evolveum/midpoint/task/quartzimpl/TaskQuartzImpl.java @@ -1495,14 +1495,7 @@ private PropertyDelta setChannelAndPrepareDelta(String value) { @Override public ObjectReferenceType getObjectRef() { - PrismReference objectRef = taskPrism.findReference(TaskType.F_OBJECT_REF); - if (objectRef == null) { - return null; - } - ObjectReferenceType objRefType = new ObjectReferenceType(); - objRefType.setOid(objectRef.getOid()); - objRefType.setType(objectRef.getValue().getTargetType()); - return objRefType; + return taskPrism.asObjectable().getObjectRef(); } @Override