Skip to content

Commit

Permalink
Fix for execution an action in the org table section
Browse files Browse the repository at this point in the history
1. Synchronization with the search panel (scope, relation, type)
2. Fix for incorrect behavior of actions above the Subtree filter
3. Fix for closing the warning window
4. Fix for tooltips localization messages
  • Loading branch information
tchrapovic committed Oct 12, 2022
1 parent 1768820 commit ac71b4e
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ private void initHeader(WebMarkupContainer box) {

@Override
public void onClick(AjaxRequestTarget target) {
close(target);
if (this.getParent() != null) {
target.add(this.getParent().setVisible(false));
}
// close(target);
}
};
close.setOutputMarkupId(true);
close.setVisible(closeVisible);

box.add(close);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,15 @@ private AssignmentCandidatesSpecification loadCandidateSpecification() {

private List<QName> getDefaultRelationsForActions() {
List<QName> defaultRelations = new ArrayList<>();
QName defaultRelation = AbstractRoleMemberPanel.this.getSearchBoxConfiguration().getDefaultRelation();
QName defaultRelation = getRelationValue();

if (isSubtreeScope()) {
defaultRelations.add(RelationTypes.MEMBER.getRelation());
return defaultRelations;
}

if (defaultRelation != null) {
defaultRelations.add(AbstractRoleMemberPanel.this.getSearchBoxConfiguration().getDefaultRelation());
defaultRelations.add(getRelationValue());
} else {
defaultRelations.add(RelationTypes.MEMBER.getRelation());
}
Expand All @@ -916,8 +921,7 @@ private void deleteMembersPerformed(IModel<?> rowModel, AjaxRequestTarget target

executeSimpleDeleteOperation(rowModel, confirmModel, target);
} else {
confirmModel = createStringResource("abstractRoleMemberPanel.deleteAllSubTree." +
getSearchBoxConfiguration().isSearchScope(SearchBoxScopeType.SUBTREE));
confirmModel = createStringResource("abstractRoleMemberPanel.deleteAllMembersConfirmationLabel");

QueryScope scope = getQueryScope();
ChooseFocusTypeAndRelationDialogPanel chooseTypePopupContent = new ChooseFocusTypeAndRelationDialogPanel(
Expand All @@ -931,6 +935,9 @@ protected List<QName> getSupportedObjectTypes() {

@Override
protected List<QName> getSupportedRelations() {
if (isSubtreeScope()) {
return getDefaultRelationsForActions();
}
return AbstractRoleMemberPanel.this.getSearchBoxConfiguration().getSupportedRelations();
}

Expand All @@ -939,8 +946,16 @@ protected List<QName> getDefaultRelations() {
return getDefaultRelationsForActions();
}

@Override
protected IModel<String> getWarningMessageModel() {
if (isSubtreeScope()) {
return getPageBase().createStringResource("abstractRoleMemberPanel.delete.warning.subtree");
}
return null;
}

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

@Override
Expand All @@ -961,29 +976,39 @@ protected QName getDefaultObjectType() {
private void recomputeMembersPerformed(IModel<?> rowModel, AjaxRequestTarget target) {
StringResourceModel confirmModel;

if (rowModel != null) {
confirmModel = createStringResource("abstractRoleMemberPanel.message.confirmationMessageForSingleObject",
"recompute", ((ObjectType) ((SelectableBean<?>) rowModel.getObject()).getValue()).getName());
if (rowModel != null || getMemberTable().getSelectedObjectsCount() > 0) {

confirmModel = rowModel != null
? createStringResource("abstractRoleMemberPanel.message.confirmationMessageForSingleObject",
"recompute", ((ObjectType) ((SelectableBean<?>) rowModel.getObject()).getValue()).getName())
: createStringResource("abstractRoleMemberPanel.recomputeSelectedMembersConfirmationLabel",
getMemberTable().getSelectedObjectsCount());

executeSimpleRecomputeOperation(rowModel, confirmModel, target);
return;
}

confirmModel = getMemberTable().getSelectedObjectsCount() > 0
? createStringResource("abstractRoleMemberPanel.recomputeSelectedMembersConfirmationLabel",
getMemberTable().getSelectedObjectsCount())
: createStringResource("abstractRoleMemberPanel.recomputeAllSubTree." +
getSearchBoxConfiguration().isSearchScope(SearchBoxScopeType.SUBTREE));
confirmModel = createStringResource("abstractRoleMemberPanel.recomputeAllMembersConfirmationLabel");

ConfirmationPanel dialog = new ConfigureTaskConfirmationPanel(((PageBase) getPage()).getMainPopupBodyId(),
confirmModel) {

private static final long serialVersionUID = 1L;

@Override
protected IModel<String> getWarningMessageModel() {
if (isSubtreeScope()) {
return createStringResource("abstractRoleMemberPanel.recompute.warning.subtree");
}
return null;
}

@Override
protected PrismObject<TaskType> getTask(AjaxRequestTarget target) {
Task task = MemberOperationsHelper.createRecomputeMembersTask(
AbstractRoleMemberPanel.this.getModelObject(),
getQueryScope(),
getSearchType(),
getActionQuery(rowModel, getQueryScope(), getRelationsForRecomputeTask()),
target, getPageBase());
if (task == null) {
Expand All @@ -1006,6 +1031,7 @@ public void yesPerformed(AjaxRequestTarget target) {
MemberOperationsHelper.createAndSubmitRecomputeMembersTask(
AbstractRoleMemberPanel.this.getModelObject(),
getQueryScope(),
getSearchType(),
getActionQuery(rowModel, getQueryScope(), getRelationsForRecomputeTask()),
target, getPageBase());
}
Expand Down Expand Up @@ -1040,6 +1066,9 @@ protected List<QName> getSupportedObjectTypes() {

@Override
protected List<QName> getSupportedRelations() {
if (isSubtreeScope()) {
return getDefaultRelationsForActions();
}
return AbstractRoleMemberPanel.this.getSearchBoxConfiguration().getSupportedRelations();
}

Expand All @@ -1054,7 +1083,7 @@ protected boolean isFocusTypeSelectorVisible() {
}

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

Expand Down Expand Up @@ -1094,7 +1123,7 @@ protected QName getDefaultObjectType() {

@Override
protected IModel<String> getWarningMessageModel() {
if (getSearchBoxConfiguration().isSearchScope(SearchBoxScopeType.SUBTREE)) {
if (isSubtreeScope()) {
return getPageBase().createStringResource("abstractRoleMemberPanel.unassign.warning.subtree");
}
return null;
Expand Down Expand Up @@ -1125,6 +1154,7 @@ public void yesPerformed(AjaxRequestTarget target) {
MemberOperationsHelper.createAndSubmitRecomputeMembersTask(
AbstractRoleMemberPanel.this.getModelObject(),
getQueryScope(),
getSearchType(),
getActionQuery(rowModel, getQueryScope(), getSearchBoxConfiguration().getSupportedRelations()),
target, getPageBase());
}
Expand All @@ -1146,6 +1176,7 @@ public void yesPerformed(AjaxRequestTarget target) {
MemberOperationsHelper.createAndSubmitDeleteMembersTask(
AbstractRoleMemberPanel.this.getModelObject(),
getQueryScope(),
getSearchType(),
getActionQuery(rowModel, getQueryScope(), getSearchBoxConfiguration().getSupportedRelations()),
target, getPageBase());
}
Expand All @@ -1154,15 +1185,30 @@ public void yesPerformed(AjaxRequestTarget target) {
getPageBase().showMainPopup(dialog, target);
}

private void executeSimpleUnassignedOperation(IModel rowModel, StringResourceModel confirmModel, AjaxRequestTarget target) {
ConfirmationPanel dialog = new ConfirmationPanel(getPageBase().getMainPopupBodyId(), confirmModel) {
private void executeSimpleUnassignedOperation(IModel<?> rowModel, StringResourceModel confirmModel, AjaxRequestTarget target) {
ConfirmationPanel dialog = new ConfigureTaskConfirmationPanel(getPageBase().getMainPopupBodyId(), confirmModel) {

@Override
protected IModel<String> getWarningMessageModel() {
if (isSubtreeScope()) {
return createStringResource("abstractRoleMemberPanel.unassign.warning.subtree");
}
return null;
}

@Override
public boolean isConfigurationTaskVisible() {
return false;
}

@Override
public void yesPerformed(AjaxRequestTarget target) {
AssignmentHolderType object = getAssignmetHolderFromRow(rowModel);
if (object != null) {
executeUnassign(object, target);

} else {

MemberOperationsHelper.createAndSubmitUnassignMembersTask(
AbstractRoleMemberPanel.this.getModelObject(),
getQueryScope(),
Expand Down Expand Up @@ -1285,6 +1331,9 @@ protected List<QName> getSupportedObjectTypes() {

@Override
protected List<QName> getSupportedRelations() {
if (isSubtreeScope()) {
return getDefaultRelationsForActions();
}
return AbstractRoleMemberPanel.this.getSearchBoxConfiguration().getSupportedRelations();
}

Expand Down Expand Up @@ -1334,18 +1383,19 @@ protected boolean isFocusTypeSelectorVisible() {
}
}

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

protected void unassignMembersPerformed(IModel rowModel, 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;
}
Expand All @@ -1370,6 +1420,9 @@ private boolean checkRelationNotSelected(Collection<QName> relations, String mes
}

protected @NotNull List<QName> getRelationsForRecomputeTask() {
if (isSubtreeScope()) {
return getDefaultRelationsForActions();
}
return getSearchBoxConfiguration().getSupportedRelations();
}

Expand Down Expand Up @@ -1427,7 +1480,7 @@ protected QueryScope getQueryScope() {
}

private boolean isSubtreeScope() {
return getSearchBoxConfiguration().isSearchScope(SearchBoxScopeType.SUBTREE);
return SearchBoxScopeType.SUBTREE == getScopeValue();
}

private boolean isIndirect() {
Expand All @@ -1440,6 +1493,40 @@ private boolean isIndirect() {
.getTypeQName();
}

protected ScopeSearchItemWrapper getSearchScope() {
List<AbstractSearchItemWrapper> items = getMemberPanelStorage().getSearch().getItems();
for (AbstractSearchItemWrapper item : items) {
if (item instanceof ScopeSearchItemWrapper) {
return (ScopeSearchItemWrapper) item;
}
}
return null;
}

protected SearchBoxScopeType getScopeValue() {
if (getSearchScope() != null) {
return getSearchScope().getValue().getValue();
}
return null;
}

protected RelationSearchItemWrapper getSearchRelation() {
List<AbstractSearchItemWrapper> items = getMemberPanelStorage().getSearch().getItems();
for (AbstractSearchItemWrapper item : items) {
if (item instanceof RelationSearchItemWrapper) {
return (RelationSearchItemWrapper) item;
}
}
return null;
}

protected QName getRelationValue() {
if (getSearchRelation() != null) {
return getSearchRelation().getValue().getValue();
}
return null;
}

protected ObjectQuery createAllMemberQuery(Collection<QName> relations) {
return getPrismContext().queryFor(FocusType.class)
.item(FocusType.F_ROLE_MEMBERSHIP_REF).ref(MemberOperationsHelper.createReferenceValuesList(getModelObject(), relations))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class MemberOperationsHelper {
* @param memberType Type of members to be processed
* @param memberQuery Query selecting members that are to be processed
* @param relations Relations to unassign. Not null, not empty.
*
*/
public static void createAndSubmitUnassignMembersTask(AbstractRoleType targetObject, QueryScope scope, QName memberType,
ObjectQuery memberQuery, Collection<QName> relations, AjaxRequestTarget target, PageBase pageBase) {
Expand All @@ -90,10 +89,9 @@ public static void createAndSubmitUnassignMembersTask(AbstractRoleType targetObj
/**
* Creates the member unassignment task.
*
* @return null if there's an error; the error is shown in such a case
* @see #createAndSubmitUnassignMembersTask(AbstractRoleType, QueryScope, QName, ObjectQuery, Collection,
* AjaxRequestTarget, PageBase)
*
* @return null if there's an error; the error is shown in such a case
*/
public static @Nullable Task createUnassignMembersTask(AbstractRoleType targetObject, QueryScope scope, QName memberType,
ObjectQuery memberQuery, @NotNull Collection<QName> relations, AjaxRequestTarget target, PageBase pageBase) {
Expand Down Expand Up @@ -189,7 +187,7 @@ public static void createAndSubmitAssignMembersTask(AbstractRoleType targetObjec
//endregion

//region Deleting members
public static void createAndSubmitDeleteMembersTask(AbstractRoleType targetObject, QueryScope scope, ObjectQuery memberQuery,
public static void createAndSubmitDeleteMembersTask(AbstractRoleType targetObject, QueryScope scope, QName memberType, ObjectQuery memberQuery,
AjaxRequestTarget target, PageBase pageBase) {

ExecuteScriptType script = createDeleteBulkAction();
Expand All @@ -201,7 +199,7 @@ public static void createAndSubmitDeleteMembersTask(AbstractRoleType targetObjec
new MemberOpTaskSpec(
getOperationName(taskName),
taskName,
AssignmentHolderType.COMPLEX_TYPE,
memberType,
memberQuery,
null),
script,
Expand All @@ -221,15 +219,16 @@ private static ExecuteScriptType createDeleteBulkAction() {
//endregion

//region Recomputing members

/** Creates and submits a task that recomputes the role members. */
public static void createAndSubmitRecomputeMembersTask(AbstractRoleType targetObject, QueryScope scope,
public static void createAndSubmitRecomputeMembersTask(AbstractRoleType targetObject, QueryScope scope, QName memberType,
ObjectQuery memberQuery, AjaxRequestTarget target, PageBase pageBase) {
Task task = createRecomputeMembersTask(targetObject, scope, memberQuery, target, pageBase);
Task task = createRecomputeMembersTask(targetObject, scope, memberType, memberQuery, target, pageBase);
submitTaskIfPossible(task, target, pageBase);
}

/** Creates a task that recomputes the role members. */
public static Task createRecomputeMembersTask(AbstractRoleType targetObject, QueryScope scope, ObjectQuery memberQuery,
public static Task createRecomputeMembersTask(AbstractRoleType targetObject, QueryScope scope, QName memberType, ObjectQuery memberQuery,
AjaxRequestTarget target, PageBase pageBase) {

String operationKey = getOperationKey(OP_KEY_RECOMPUTE, scope, targetObject, "of");
Expand All @@ -239,14 +238,15 @@ public static Task createRecomputeMembersTask(AbstractRoleType targetObject, Que
new MemberOpTaskSpec(
getOperationName(taskName),
taskName,
AssignmentHolderType.COMPLEX_TYPE,
memberType,
memberQuery,
null),
target, pageBase);
}
//endregion

//region Query formulation

/**
* Creates a query covering all direct (assigned) members of an abstract role.
*
Expand Down Expand Up @@ -325,6 +325,7 @@ public static Task createRecomputeMembersTask(AbstractRoleType targetObject, Que
//endregion

//region Task preparation and submission for execution

/**
* Creates a localization key for task name in the form of `operation.OPERATION.SCOPE.members.PREPOSITION.TARGET-TYPE`.
* It is also the operation name for tasks being created.
Expand Down Expand Up @@ -363,7 +364,6 @@ private static <R extends AbstractRoleType> String getOperationKey(String operat
*
* @param taskSpec Specification of the member operation task
* @param script Script to be executed on individual members
*
* @return null if there's an error
*/
private static @Nullable Task createScriptingMemberOperationTask(@NotNull MemberOpTaskSpec taskSpec,
Expand Down Expand Up @@ -410,7 +410,6 @@ private static ObjectSetType createObjectSetBean(@NotNull MemberOpTaskSpec taskS
* ExecuteScriptType, PageBase, AjaxRequestTarget)}.
*
* @param taskSpec Specification of the member operation task
*
* @return null if there's an error
*/
@SuppressWarnings("SameParameterValue")
Expand Down

0 comments on commit ac71b4e

Please sign in to comment.