Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed May 23, 2022
2 parents ea4996f + e70ffcc commit 9a3cfc9
Show file tree
Hide file tree
Showing 156 changed files with 2,986 additions and 2,307 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3133,20 +3133,20 @@ public static void switchResourceMaintenance(@NotNull PrismObject<ResourceType>

public static void refreshResourceSchema(@NotNull PrismObject<ResourceType> resource, String operation, AjaxRequestTarget target, PageBase pageBase) {
Task task = pageBase.createSimpleTask(operation);
OperationResult parentResult = new OperationResult(operation);
OperationResult result = new OperationResult(operation);

try {
ResourceUtils.deleteSchema(resource, pageBase.getModelService(), pageBase.getPrismContext(), task, parentResult);
pageBase.getModelService().testResource(resource.getOid(), task); // try to load fresh scehma
ResourceUtils.deleteSchema(resource, pageBase.getModelService(), pageBase.getPrismContext(), task, result);
pageBase.getModelService().testResource(resource.getOid(), task, result); // try to load fresh schema
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
| PolicyViolationException | SecurityViolationException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Error refreshing resource schema", e);
parentResult.recordFatalError(pageBase.createStringResource("WebComponentUtil.message.refreshResourceSchema.fatalError").getString(), e);
result.recordFatalError(pageBase.createStringResource("WebComponentUtil.message.refreshResourceSchema.fatalError").getString(), e);
}

parentResult.computeStatus();
pageBase.showResult(parentResult, "pageResource.refreshSchema.failed");
result.computeStatus();
pageBase.showResult(result, "pageResource.refreshSchema.failed");
target.add(pageBase.getFeedbackPanel());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.*;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.web.component.data.column.ColumnMenuAction;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
Expand Down Expand Up @@ -671,7 +673,7 @@ protected List<InlineMenuItem> createRowActions() {
createRecomputeMemberRowAction(menu);

if (isAuthorized(GuiAuthorizationConstants.MEMBER_OPERATION_CREATE)) {
menu.add(new InlineMenuItem(createStringResource("abstractRoleMemberPanel.menu.create")) {
InlineMenuItem menuItem = new InlineMenuItem(createStringResource("abstractRoleMemberPanel.menu.create")) {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -685,20 +687,22 @@ public void onClick(AjaxRequestTarget target) {
}
};
}
});
};
menuItem.setVisibilityChecker((rowModel, isHeader) -> isHeader);
menu.add(menuItem);
}
if (isAuthorized(GuiAuthorizationConstants.MEMBER_OPERATION_DELETE)) {
menu.add(new InlineMenuItem(createStringResource("abstractRoleMemberPanel.menu.delete")) {
private static final long serialVersionUID = 1L;

@Override
public InlineMenuItemAction initAction() {
return new HeaderMenuAction(AbstractRoleMemberPanel.this) {
return new ColumnMenuAction() {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
deleteMembersPerformed(target);
deleteMembersPerformed(getRowModel(), target);
}
};
}
Expand All @@ -710,12 +714,12 @@ public void onClick(AjaxRequestTarget target) {

protected void createAssignMemberRowAction(List<InlineMenuItem> menu) {
if (isAuthorized(GuiAuthorizationConstants.MEMBER_OPERATION_ASSIGN)) {
menu.add(new InlineMenuItem(createStringResource("abstractRoleMemberPanel.menu.assign")) {
InlineMenuItem menuItem = new InlineMenuItem(createStringResource("abstractRoleMemberPanel.menu.assign")) {
private static final long serialVersionUID = 1L;

@Override
public InlineMenuItemAction initAction() {
return new HeaderMenuAction(AbstractRoleMemberPanel.this) {
return new ColumnMenuAction() {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -725,23 +729,25 @@ public void onClick(AjaxRequestTarget target) {
}
};
}
});
};
menuItem.setVisibilityChecker((rowModel, isHeader) -> isHeader);
menu.add(menuItem);
}
}

protected void createUnassignMemberRowAction(List<InlineMenuItem> menu) {
if (isAuthorized(GuiAuthorizationConstants.MEMBER_OPERATION_UNASSIGN)) {
menu.add(new ButtonInlineMenuItem(createStringResource("abstractRoleMemberPanel.menu.unassign")) {
InlineMenuItem menuItem = new ButtonInlineMenuItem(createStringResource("abstractRoleMemberPanel.menu.unassign")) {
private static final long serialVersionUID = 1L;

@Override
public InlineMenuItemAction initAction() {
return new HeaderMenuAction(AbstractRoleMemberPanel.this) {
return new ColumnMenuAction() {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
unassignMembersPerformed(target);
unassignMembersPerformed(getRowModel(), target);
}
};

Expand All @@ -751,8 +757,34 @@ public void onClick(AjaxRequestTarget target) {
public CompositedIconBuilder getIconCompositedBuilder() {
return getDefaultCompositedIconBuilder(GuiStyleConstants.CLASS_UNASSIGN);
}
});
};
menuItem.setVisibilityChecker((rowModel, isHeader) -> isHeader ? true : containsDirectAssignment(rowModel, isHeader));
menu.add(menuItem);
}
}

private boolean containsDirectAssignment(IModel<?> rowModel, boolean isHeader) {
AssignmentHolderType assignmentHolder = getAssignmetHolderFromRow(rowModel);

if (assignmentHolder == null) {
return isHeader;
}
R role = getModelObject();
List<AssignmentType> assignments = assignmentHolder.getAssignment();
for (AssignmentType assignment : assignments) {
if (assignment != null && assignment.getTargetRef() != null && assignment.getTargetRef().getOid().equals(role.getOid())) {
return true;
}
}
return false;
}

private AssignmentHolderType getAssignmetHolderFromRow(IModel<?> rowModel) {
if (rowModel != null && (rowModel.getObject() instanceof SelectableBean)
&& ((SelectableBean)rowModel.getObject()).getValue() instanceof AssignmentHolderType) {
return (AssignmentHolderType) ((SelectableBean)rowModel.getObject()).getValue();
}
return null;
}

protected void createRecomputeMemberRowAction(List<InlineMenuItem> menu) {
Expand All @@ -762,12 +794,12 @@ protected void createRecomputeMemberRowAction(List<InlineMenuItem> menu) {

@Override
public InlineMenuItemAction initAction() {
return new HeaderMenuAction(AbstractRoleMemberPanel.this) {
return new ColumnMenuAction() {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
recomputeMembersPerformed(target);
recomputeMembersPerformed(getRowModel(), target);
}
};
}
Expand Down Expand Up @@ -847,7 +879,7 @@ protected void assignMembers(AjaxRequestTarget target, RelationSearchItemConfigu
objectTypes, archetypeRefList, isOrgTreePanelVisible);
}

private void unassignMembersPerformed(AjaxRequestTarget target) {
private void unassignMembersPerformed(IModel rowModel, AjaxRequestTarget target) {
QueryScope scope = getQueryScope();

ChooseFocusTypeAndRelationDialogPanel chooseTypePopupContent = new ChooseFocusTypeAndRelationDialogPanel(getPageBase().getMainPopupBodyId(),
Expand All @@ -871,11 +903,11 @@ protected List<QName> getDefaultRelations() {

@Override
protected boolean isFocusTypeSelectorVisible() {
return !QueryScope.SELECTED.equals(scope);
return getAssignmetHolderFromRow(rowModel) == null && !QueryScope.SELECTED.equals(scope);
}

protected void okPerformed(QName type, Collection<QName> relations, AjaxRequestTarget target) {
unassignMembersPerformed(type, getSearchBoxConfiguration().isSearchScope(SearchBoxScopeType.SUBTREE)
unassignMembersPerformed(rowModel, type, getSearchBoxConfiguration().isSearchScope(SearchBoxScopeType.SUBTREE)
&& QueryScope.ALL.equals(scope) ? QueryScope.ALL_DIRECT : scope, relations, target);
}

Expand All @@ -888,7 +920,7 @@ protected PrismObject<TaskType> getTask(QName type, Collection<QName> relations,
AbstractRoleMemberPanel.this.getModelObject(),
scope,
type,
getActionQuery(scope, relations),
getActionQuery(rowModel, scope, relations),
relations,
target, getPageBase());

Expand Down Expand Up @@ -943,7 +975,7 @@ private List<QName> getDefaultRelationsForActions() {
return defaultRelations;
}

private void deleteMembersPerformed(AjaxRequestTarget target) {
private void deleteMembersPerformed(IModel rowModel, AjaxRequestTarget target) {
QueryScope scope = getQueryScope();
StringResourceModel confirmModel;
if (getSearchBoxConfiguration().isSearchScope(SearchBoxScopeType.SUBTREE)) {
Expand Down Expand Up @@ -973,12 +1005,12 @@ protected List<QName> getDefaultRelations() {
}

protected void okPerformed(QName type, Collection<QName> relations, AjaxRequestTarget target) {
deleteMembersPerformed(scope, relations, target);
deleteMembersPerformed(rowModel, scope, relations, target);
}

@Override
protected boolean isFocusTypeSelectorVisible() {
return !QueryScope.SELECTED.equals(scope);
return getAssignmetHolderFromRow(rowModel) == null && !QueryScope.SELECTED.equals(scope);
}

@Override
Expand Down Expand Up @@ -1075,14 +1107,14 @@ protected boolean isFocusTypeSelectorVisible() {
}
}

protected void deleteMembersPerformed(QueryScope scope, Collection<QName> relations, AjaxRequestTarget target) {
protected void deleteMembersPerformed(IModel rowModel, QueryScope scope, Collection<QName> relations, AjaxRequestTarget target) {
if (checkRelationNotSelected(relations, "No relation was selected. Cannot perform delete members", target)) {
return;
}
MemberOperationsHelper.createAndSubmitDeleteMembersTask(
getModelObject(),
scope,
getActionQuery(scope, relations),
getActionQuery(rowModel, scope, relations),
target, getPageBase());
}

Expand All @@ -1096,20 +1128,28 @@ private boolean checkRelationNotSelected(Collection<QName> relations, String mes
return true;
}

protected void unassignMembersPerformed(QName type, QueryScope scope, Collection<QName> relations, AjaxRequestTarget target) {
protected void unassignMembersPerformed(IModel rowModel, QName type, QueryScope scope, Collection<QName> relations, AjaxRequestTarget target) {
if (checkRelationNotSelected(relations, "No relation was selected. Cannot perform unassign members", target)) {
return;
}
MemberOperationsHelper.createAndSubmitUnassignMembersTask(
getModelObject(),
scope,
type,
getActionQuery(scope, relations),
getActionQuery(rowModel, scope, relations),
relations,
target, getPageBase());
target.add(this);
}

protected ObjectQuery getActionQuery(IModel rowModel, QueryScope scope, @NotNull Collection<QName> relations) {
AssignmentHolderType assignmentHolder = getAssignmetHolderFromRow(rowModel);
if (assignmentHolder == null) {
return getActionQuery(scope, relations);
}
return MemberOperationsHelper.createSelectedObjectsQuery(Collections.singletonList(assignmentHolder));
}

protected ObjectQuery getActionQuery(QueryScope scope, @NotNull Collection<QName> relations) {
switch (scope) {
case ALL:
Expand Down Expand Up @@ -1167,7 +1207,7 @@ private boolean isIndirect() {
return getSearchBoxConfiguration().isIndirect();
}

protected void recomputeMembersPerformed(AjaxRequestTarget target) {
protected void recomputeMembersPerformed(IModel rowModel, AjaxRequestTarget target) {

StringResourceModel confirmModel;
if (getSearchBoxConfiguration().isSearchScope(SearchBoxScopeType.SUBTREE)) {
Expand All @@ -1187,7 +1227,7 @@ protected PrismObject<TaskType> getTask(AjaxRequestTarget target) {
Task task = MemberOperationsHelper.createRecomputeMembersTask(
getModelObject(),
getQueryScope(),
getActionQuery(getQueryScope(), getRelationsForRecomputeTask()),
getActionQuery(rowModel, getQueryScope(), getRelationsForRecomputeTask()),
target, getPageBase());
if (task == null) {
return null;
Expand All @@ -1208,7 +1248,7 @@ public void yesPerformed(AjaxRequestTarget target) {
MemberOperationsHelper.createAndSubmitRecomputeMembersTask(
getModelObject(),
getQueryScope(),
getActionQuery(getQueryScope(), getRelationsForRecomputeTask()),
getActionQuery(rowModel, getQueryScope(), getRelationsForRecomputeTask()),
target, getPageBase());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private void testResourcePerformed(AjaxRequestTarget target, ResourceType resour

Task task = createSimpleTask(OPERATION_TEST_RESOURCE);
try {
result = getModelService().testResource(resourceType.getOid(), task);
getModelService().testResource(resourceType.getOid(), task, result);
// todo de-duplicate code (see the same operation in PageResource)
// this provides some additional tests, namely a test for schema
// handling section
Expand All @@ -462,18 +462,10 @@ private void testResourcePerformed(AjaxRequestTarget target, ResourceType resour
result.recordFatalError(createStringResource("PageResources.message.testResourcePerformed.fatalError").getString(), ex);
}

// a bit of hack: result of TestConnection contains a result of
// getObject as a subresult
// so in case of TestConnection succeeding we recompute the result to
// show any (potential) getObject problems
if (result.isSuccess()) {
result.recomputeStatus();
}
result.close();

// if (!result.isSuccess()) {
showResult(result);
target.add(getFeedbackPanel());
// }
target.add(getResourceTable());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import com.evolveum.midpoint.gui.api.component.result.OpResult;
import com.evolveum.midpoint.gui.api.component.result.OperationResultPanel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.schema.constants.ConnectorTestOperation;
import com.evolveum.midpoint.schema.constants.TestResourceOpNames;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -64,13 +63,15 @@ private void initResultsModel(String resourceOid) {
List<ConnectorStruct> connectorStructs = new ArrayList<>();
if (StringUtils.isNotEmpty(resourceOid)) {
Task task = parentPage.createSimpleTask(OPERATION_TEST_CONNECTION);
OperationResult testResult = new OperationResult("dummy"); // just to be non-null
try {
result = parentPage.getModelService().testResource(resourceOid, task);
} catch (ObjectNotFoundException e) {
testResult = parentPage.getModelService().testResource(resourceOid, task, result);
} catch (Exception e) {
// TODO how will this be displayed?
result.recordFatalError(getString("TestConnectionMessagesPanel.message.testConnection.fatalError"), e);
}

for (OperationResult subresult: result.getSubresults()) {
for (OperationResult subresult: testResult.getSubresults()) {
if (isConnectorResult(subresult)) {
ConnectorStruct connectorStruct = new ConnectorStruct();
connectorStruct.connectorName = subresult.getParamSingle(OperationResult.PARAM_NAME);
Expand All @@ -85,7 +86,7 @@ private void initResultsModel(String resourceOid) {
}
connectorStructs.add(connectorStruct);
} else if (isKnownResult(subresult)) {
// resource operation
// resource-level operation
resourceResultsDto.add(OpResult.getOpResult(parentPage, subresult));
}

Expand All @@ -100,11 +101,11 @@ private void initResultsModel(String resourceOid) {
}

private boolean isConnectorResult(OperationResult subresult) {
return subresult.getOperation().equals(ConnectorTestOperation.CONNECTOR_TEST.getOperation());
return subresult.getOperation().equals(TestResourceOpNames.CONNECTOR_TEST.getOperation());
}

private boolean isKnownResult(OperationResult subresult) {
for (ConnectorTestOperation connectorOperation : ConnectorTestOperation.values()) {
for (TestResourceOpNames connectorOperation : TestResourceOpNames.values()) {
if (connectorOperation.getOperation().equals(subresult.getOperation())) {
return true;
}
Expand Down

0 comments on commit 9a3cfc9

Please sign in to comment.