diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentPanel.java index e8ef66cab57..a34eaaa1520 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentPanel.java @@ -43,24 +43,24 @@ import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition; import com.evolveum.midpoint.common.refinery.RefinedResourceSchema; import com.evolveum.midpoint.gui.api.component.FocusBrowserPanel; -import com.evolveum.midpoint.gui.api.component.ObjectListPanel; import com.evolveum.midpoint.gui.api.component.result.OpResult; import com.evolveum.midpoint.gui.api.component.result.OperationResultPanel; import com.evolveum.midpoint.gui.api.model.LoadableModel; import com.evolveum.midpoint.gui.api.page.PageBase; import com.evolveum.midpoint.gui.api.util.WebComponentUtil; +import com.evolveum.midpoint.model.api.ModelExecuteOptions; import com.evolveum.midpoint.model.api.PolicyViolationException; import com.evolveum.midpoint.prism.PrismObject; import com.evolveum.midpoint.prism.PrismObjectDefinition; import com.evolveum.midpoint.prism.delta.ItemDelta; import com.evolveum.midpoint.prism.delta.ObjectDelta; import com.evolveum.midpoint.prism.delta.ReferenceDelta; -import com.evolveum.midpoint.prism.path.ItemPath; import com.evolveum.midpoint.prism.query.AndFilter; import com.evolveum.midpoint.prism.query.ObjectQuery; import com.evolveum.midpoint.schema.GetOperationOptions; import com.evolveum.midpoint.schema.RetrieveOption; import com.evolveum.midpoint.schema.SelectorOptions; +import com.evolveum.midpoint.schema.constants.SchemaConstants; import com.evolveum.midpoint.schema.processor.ResourceAttribute; import com.evolveum.midpoint.schema.result.OperationResult; import com.evolveum.midpoint.schema.util.ObjectQueryUtil; @@ -77,10 +77,8 @@ import com.evolveum.midpoint.util.logging.LoggingUtils; import com.evolveum.midpoint.util.logging.Trace; import com.evolveum.midpoint.util.logging.TraceManager; -import com.evolveum.midpoint.web.component.data.BaseSortableDataProvider; import com.evolveum.midpoint.web.component.data.BoxedTablePanel; import com.evolveum.midpoint.web.component.data.ObjectDataProvider2; -import com.evolveum.midpoint.web.component.data.Table; import com.evolveum.midpoint.web.component.data.column.CheckBoxColumn; import com.evolveum.midpoint.web.component.data.column.ColumnTypeDto; import com.evolveum.midpoint.web.component.data.column.ColumnUtils; @@ -88,7 +86,6 @@ import com.evolveum.midpoint.web.component.data.column.LinkColumn; import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem; import com.evolveum.midpoint.web.component.search.Search; -import com.evolveum.midpoint.web.component.search.SearchFactory; import com.evolveum.midpoint.web.component.search.SearchFormPanel; import com.evolveum.midpoint.web.component.util.SelectableBean; import com.evolveum.midpoint.web.page.admin.configuration.component.HeaderMenuAction; @@ -97,7 +94,7 @@ import com.evolveum.midpoint.web.page.admin.users.PageUser; import com.evolveum.midpoint.web.session.UserProfileStorage; import com.evolveum.midpoint.web.util.OnePageParameterEncoder; -import com.evolveum.midpoint.xml.ns._public.common.common_3.FailedOperationTypeType; +import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType; import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType; import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType; import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType; @@ -105,6 +102,12 @@ import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType; import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType; + +/** + * Implementation classes : ResourceContentResourcePanel, ResourceContentRepositoryPanel + * @author katka + * + */ public abstract class ResourceContentPanel extends Panel { /** @@ -117,6 +120,9 @@ public abstract class ResourceContentPanel extends Panel { private static final String DOT_CLASS = ResourceContentTabPanel.class.getName() + "."; private static final String OPERATION_CHANGE_OWNER = DOT_CLASS + "changeOwner"; private static final String OPERATION_LOAD_SHADOW_OWNER = DOT_CLASS + "loadOwner"; + private static final String OPERATION_UPDATE_STATUS = DOT_CLASS + "updateStatus"; + private static final String OPERATION_DELETE_OBJECT = DOT_CLASS + "deleteObject"; + private static final String OPERATION_IMPORT_OBJECT = DOT_CLASS + "importObject"; private static final String ID_TABLE = "table"; @@ -560,8 +566,7 @@ private List createHeaderMenuItems() { @Override public void onSubmit(AjaxRequestTarget target, Form form) { - // updateAccountStatusPerformed(target, null, true); - // TODO + updateResourceObjectStatusPerformed(target, true); } })); @@ -570,8 +575,7 @@ public void onSubmit(AjaxRequestTarget target, Form form) { @Override public void onSubmit(AjaxRequestTarget target, Form form) { - // updateAccountStatusPerformed(target, null, false); - // TODO + updateResourceObjectStatusPerformed(target, false); } })); @@ -580,7 +584,7 @@ public void onSubmit(AjaxRequestTarget target, Form form) { @Override public void onSubmit(AjaxRequestTarget target, Form form) { - // deleteAccountPerformed(target, null); TODO + deleteResourceObjectPerformed(target); } })); @@ -591,7 +595,7 @@ public void onSubmit(AjaxRequestTarget target, Form form) { @Override public void onSubmit(AjaxRequestTarget target, Form form) { - // importAccount(target, null); TODO + importResourceObject(target); } })); @@ -603,7 +607,6 @@ public void onSubmit(AjaxRequestTarget target, Form form) { @Override public void onSubmit(AjaxRequestTarget target, Form form) { changeOwner(target, null, Operation.REMOVE); - // removeOwnerPerformed(target, null); TODO } })); @@ -627,6 +630,114 @@ protected void onClick(AjaxRequestTarget target, UserType focus) { return items; } + + protected void importResourceObject(AjaxRequestTarget target){ + List> selectedShadow = WebComponentUtil.getSelectedData(getTable()); + + OperationResult result = new OperationResult(OPERATION_IMPORT_OBJECT); + Task task = pageBase.createSimpleTask(OPERATION_IMPORT_OBJECT); + + if (selectedShadow == null && selectedShadow.isEmpty()){ + result.recordWarning("Nothing select to import"); + getPageBase().showResult(result); + target.add(getPageBase().getFeedbackPanel()); + return; + } + + for (SelectableBean shadow : selectedShadow) { + try { + getPageBase().getModelService().importFromResource(shadow.getValue().getOid(), task, result); + } catch (ObjectNotFoundException | SchemaException | SecurityViolationException + | CommunicationException | ConfigurationException e) { + result.recordPartialError("Could not import account " + shadow.getValue(), e); + LOGGER.error("Could not import account {} ", shadow.getValue(), e); + continue; + } + } + + result.computeStatusIfUnknown(); + getPageBase().showResult(result); + target.add(getPageBase().getFeedbackPanel()); + } + + //TODO: as a task? + protected void deleteResourceObjectPerformed(AjaxRequestTarget target){ + List> selectedShadow = WebComponentUtil.getSelectedData(getTable()); + + + OperationResult result = new OperationResult(OPERATION_DELETE_OBJECT); + Task task = pageBase.createSimpleTask(OPERATION_DELETE_OBJECT); + + if (selectedShadow == null && selectedShadow.isEmpty()){ + result.recordWarning("Nothing selected to delete"); + getPageBase().showResult(result); + target.add(getPageBase().getFeedbackPanel()); + return; + } + + ModelExecuteOptions opts = createModelOptions(); + + for (SelectableBean shadow : selectedShadow){ + try { + ObjectDelta deleteDelta = ObjectDelta.createDeleteDelta(ShadowType.class, shadow.getValue().getOid(), getPageBase().getPrismContext()); + getPageBase().getModelService().executeChanges(WebComponentUtil.createDeltaCollection(deleteDelta), opts, task, result); + } catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException + | ExpressionEvaluationException | CommunicationException | ConfigurationException + | PolicyViolationException | SecurityViolationException e) { + // TODO Auto-generated catch block + result.recordPartialError("Could not delete object " + shadow.getValue(), e); + LOGGER.error("Could not delete {}, using option {}", shadow.getValue(), opts, e); + continue; + } + } + + result.computeStatusIfUnknown(); + getPageBase().showResult(result); + target.add(getPageBase().getFeedbackPanel()); + + } + + protected abstract ModelExecuteOptions createModelOptions(); + + protected void updateResourceObjectStatusPerformed(AjaxRequestTarget target, boolean enabled){ +List> selectedShadow = WebComponentUtil.getSelectedData(getTable()); + + + OperationResult result = new OperationResult(OPERATION_UPDATE_STATUS); + Task task = pageBase.createSimpleTask(OPERATION_UPDATE_STATUS); + + if (selectedShadow == null && selectedShadow.isEmpty()){ + result.recordWarning("Nothing selected to update status"); + getPageBase().showResult(result); + target.add(getPageBase().getFeedbackPanel()); + return; + } + + + + ModelExecuteOptions opts = createModelOptions(); + + for (SelectableBean shadow : selectedShadow){ + ActivationStatusType status = enabled ? ActivationStatusType.ENABLED : ActivationStatusType.DISABLED; + try { + ObjectDelta deleteDelta = ObjectDelta.createModificationReplaceProperty(ShadowType.class, shadow.getValue().getOid(), SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, getPageBase().getPrismContext(), status); + getPageBase().getModelService().executeChanges(WebComponentUtil.createDeltaCollection(deleteDelta), opts, task, result); + } catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException + | ExpressionEvaluationException | CommunicationException | ConfigurationException + | PolicyViolationException | SecurityViolationException e) { + // TODO Auto-generated catch block + result.recordPartialError("Could not update status (to " + status+ ") for " + shadow.getValue(), e); + LOGGER.error("Could not update status (to {}) for {}, using option {}", status, shadow.getValue(), opts, e); + continue; + } + } + + result.computeStatusIfUnknown(); + getPageBase().showResult(result); + target.add(getPageBase().getFeedbackPanel()); + + + } private PrismObjectDefinition getFocusDefinition() { return pageBase.getPrismContext().getSchemaRegistry() @@ -638,8 +749,7 @@ private BoxedTablePanel getTable() { } private void changeOwner(AjaxRequestTarget target, FocusType ownerToChange, Operation operation) { - BoxedTablePanel table = getTable(); - List> selectedShadow = WebComponentUtil.getSelectedData(table); + List> selectedShadow = WebComponentUtil.getSelectedData(getTable()); Collection modifications = new ArrayList<>(); diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentRepositoryPanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentRepositoryPanel.java index d665351c407..ad02df5f75c 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentRepositoryPanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentRepositoryPanel.java @@ -17,16 +17,13 @@ import javax.xml.namespace.QName; -import org.apache.commons.lang3.StringUtils; import org.apache.wicket.model.IModel; import com.evolveum.midpoint.gui.api.page.PageBase; +import com.evolveum.midpoint.model.api.ModelExecuteOptions; import com.evolveum.midpoint.prism.PrismObject; -import com.evolveum.midpoint.prism.query.ObjectQuery; import com.evolveum.midpoint.schema.GetOperationOptions; import com.evolveum.midpoint.schema.SelectorOptions; -import com.evolveum.midpoint.schema.util.ObjectQueryUtil; -import com.evolveum.midpoint.util.exception.SchemaException; import com.evolveum.midpoint.web.component.search.Search; import com.evolveum.midpoint.web.component.search.SearchFactory; import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType; @@ -43,28 +40,13 @@ public class ResourceContentRepositoryPanel extends ResourceContentPanel{ public ResourceContentRepositoryPanel(String id, IModel> resourceModel, QName objectClass, ShadowKindType kind, String intent, PageBase pageBase) { super(id, resourceModel, objectClass, kind, intent, pageBase); - // TODO Auto-generated constructor stub } @Override protected void initCustomLayout() { - // TODO Auto-generated method stub - + } -// -// @Override -// protected ObjectQuery createQuery() -// throws SchemaException { -// ObjectQuery baseQuery = null; -// if (StringUtils.isNotBlank(getIntent())) { -// baseQuery = ObjectQueryUtil.createResourceAndKindIntent(resourceModel.getObject().getOid(), -// getKind(), getIntent(), getPageBase().getPrismContext()); -// } else { -// baseQuery = ObjectQueryUtil.createResourceAndKind(resourceModel.getObject().getOid(), getKind(), -// getPageBase().getPrismContext()); -// } -// return baseQuery; -// } + @Override protected SelectorOptions addAdditionalOptions() { @@ -81,4 +63,9 @@ protected Search createSearch() { return SearchFactory.createSearch(ShadowType.class, getPageBase().getPrismContext()); } + @Override + protected ModelExecuteOptions createModelOptions() { + return ModelExecuteOptions.createRaw(); + } + } diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentResourcePanel.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentResourcePanel.java index 3b7eae05c66..d6b1f347d29 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentResourcePanel.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/admin/resources/ResourceContentResourcePanel.java @@ -36,6 +36,7 @@ import com.evolveum.midpoint.gui.api.component.button.DropdownButtonPanel; import com.evolveum.midpoint.gui.api.page.PageBase; import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils; +import com.evolveum.midpoint.model.api.ModelExecuteOptions; import com.evolveum.midpoint.prism.ItemDefinition; import com.evolveum.midpoint.prism.PrismContainerDefinition; import com.evolveum.midpoint.prism.PrismContext; @@ -307,4 +308,9 @@ private Map createAttributeDefi return map; } + @Override + protected ModelExecuteOptions createModelOptions() { + return null; + } + }