Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Sep 28, 2023
2 parents fcefddb + 6ad172b commit ac8d81b
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<wicket:message key="SaveSearchPanel.enterSearchNameLabel"/>
</label>
<input type="text" class="pull-right form-control form-control-sm" wicket:id="searchName"/>
<div wicket:id="feedbackLabel"></div>
</div>
<div wicket:id="buttonsPanel" class="main-button-bar justify-content-end">
<a wicket:id="saveButton" class="btn btn-group btn-sm btn-default"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
*/
package com.evolveum.midpoint.gui.impl.component.search.panel;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.feedback.ContainerFeedbackMessageFilter;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;
Expand All @@ -24,6 +26,7 @@
import com.evolveum.midpoint.gui.api.component.result.MessagePanel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.component.message.FeedbackLabels;
import com.evolveum.midpoint.gui.impl.component.search.Search;
import com.evolveum.midpoint.gui.impl.component.search.wrapper.FilterableSearchItemWrapper;
import com.evolveum.midpoint.gui.impl.component.search.wrapper.OidSearchItemWrapper;
Expand All @@ -46,15 +49,17 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

public class SaveSearchPanel<C extends Serializable> extends BasePanel<Search<C>> implements Popupable {

private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

private static final String DOT_CLASS = SaveSearchPanel.class.getName() + ".";
private static final String OPERATION_SAVE_FILTER = DOT_CLASS + "saveFilter";
private static final Trace LOGGER = TraceManager.getTrace(SaveSearchPanel.class);
private static final String ID_FEEDBACK_MESSAGE = "feedbackMessage";
private static final String ID_FEEDBACK_LABEL_MESSAGE = "feedbackLabel";
private static final String ID_SAVE_SEARCH_FORM = "saveSearchForm";
private static final String ID_SEARCH_NAME = "searchName";
private static final String ID_BUTTONS_PANEL = "buttonsPanel";
Expand All @@ -81,7 +86,7 @@ protected void onInitialize() {
private void initLayout() {
setOutputMarkupId(true);

MidpointForm form = new MidpointForm(ID_SAVE_SEARCH_FORM);
MidpointForm<?> form = new MidpointForm<>(ID_SAVE_SEARCH_FORM);
form.setOutputMarkupId(true);
add(form);

Expand All @@ -90,8 +95,19 @@ private void initLayout() {
feedbackMessage.setOutputMarkupId(true);
form.add(feedbackMessage);

FeedbackLabels feedbackLabel = new FeedbackLabels(ID_FEEDBACK_LABEL_MESSAGE);
feedbackLabel.setFilter(new ContainerFeedbackMessageFilter(form));
feedbackLabel.setOutputMarkupPlaceholderTag(true);
form.add(feedbackLabel);

TextField<String> nameField = new TextField<>(ID_SEARCH_NAME, queryNameModel);
nameField.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
nameField.add(new EmptyOnBlurAjaxFormUpdatingBehaviour() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
validateNameField(target);
target.add(getComponentFeedback());
}
});
nameField.setOutputMarkupId(true);
form.add(nameField);

Expand All @@ -105,8 +121,8 @@ private void initLayout() {
@Override
public void onSubmit(AjaxRequestTarget ajaxRequestTarget) {
if (StringUtils.isEmpty(queryNameModel.getObject())) {
feedbackMessageModel = createStringResource("SaveSearchPanel.enterQueryNameWarning");
ajaxRequestTarget.add(feedbackMessage);
getComponentFeedback().error(createStringResource("SaveSearchPanel.enterQueryNameWarning").getString());
ajaxRequestTarget.add(getComponentFeedback());
return;
}
saveCustomQuery(ajaxRequestTarget);
Expand Down Expand Up @@ -217,7 +233,7 @@ private SearchItemType createAdvancedSearchItem() {
private SearchItemType createFulltextSearchItem() {
try {
SearchItemType fulltextSearchItem = new SearchItemType();
ObjectFilter filter = PrismContext.get().queryFor((Class<Containerable>)getModelObject().getTypeClass())
ObjectFilter filter = PrismContext.get().queryFor((Class<Containerable>) getModelObject().getTypeClass())
.fullText(getModelObject().getFullText())
.buildFilter();
fulltextSearchItem.setFilter(PrismContext.get().getQueryConverter().createSearchFilterType(filter));
Expand Down Expand Up @@ -275,7 +291,6 @@ private void saveSearchItemToAdminConfig(AvailableFilterType availableFilter, Aj
addItemToPath = false;
}


StringValue collectionViewParameter = WebComponentUtil.getCollectionNameParameterValue(getPageBase());
String viewName = collectionViewParameter == null || collectionViewParameter.isNull() ? defaultCollectionViewIdentifier
: collectionViewParameter.toString();
Expand Down Expand Up @@ -349,6 +364,34 @@ private void saveSearchItemToAdminConfig(AvailableFilterType availableFilter, Aj
ajaxRequestTarget.add(getPageBase().getFeedbackPanel());
}

public void validateNameField(AjaxRequestTarget target) {
getComponentFeedback().getFeedbackMessages().clear();

if (queryNameModel == null) {
getComponentFeedback().error(createStringResource("SaveSearchPanel.enterQueryNameWarning").getString());
} else {

List<AvailableFilterType> availableSearchFilters = getAvailableSearchFilters();
for (AvailableFilterType availableSearchFilter : availableSearchFilters) {
PolyStringType label = availableSearchFilter.getDisplay().getLabel();
if (label != null && String.valueOf(label).equals(queryNameModel.getObject())) {
getComponentFeedback().error(createStringResource("SaveSearchPanel.filter.name.already.exists",
queryNameModel.getObject()).getString());
target.add(getComponentFeedback());
break;
}
}
}
}

public List<AvailableFilterType> getAvailableSearchFilters() {
return getModelObject().getAvailableFilterTypes();
}

private FeedbackLabels getComponentFeedback() {
return (FeedbackLabels) get(createComponentPath(ID_SAVE_SEARCH_FORM, ID_FEEDBACK_LABEL_MESSAGE));
}

@Override
public int getWidth() {
return 500;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ protected TableId getTableId() {
protected List<InlineMenuItem> createInlineMenu() {
List<InlineMenuItem> menuItems = new ArrayList<>();
menuItems.add(PageArchetypes.this.createDeleteInlineMenu());
menuItems.add(createEditMenuItem());
return menuItems;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.component.util.SelectableBeanImpl;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
Expand Down Expand Up @@ -311,6 +312,14 @@ public InlineMenuItemAction initAction() {
@Override
public void onSubmit(AjaxRequestTarget target) {

var selected = getSelectedShadowsList(getRowModel());

if (selected.isEmpty()) {
warn(getString("pageContentAccounts.message.noAccountSelected"));
target.add(getPageBase().getFeedbackPanel());
return;
}

ObjectFilter marksFilter = PrismContext.get().queryFor(MarkType.class)
.item(MarkType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF)
.ref(SystemObjectsType.ARCHETYPE_OBJECT_MARK.value())
Expand Down Expand Up @@ -351,8 +360,21 @@ public InlineMenuItemAction initAction() {
public void onSubmit(AjaxRequestTarget target) {

var selected = getSelectedShadowsList(getRowModel());

if (selected.isEmpty()) {
warn(getString("pageContentAccounts.message.noAccountSelected"));
target.add(getPageBase().getFeedbackPanel());
return;
}

var selectedMarks = collectExistingMarks(selected);

if (selectedMarks.length == 0) {
warn(getString("pageContentAccounts.message.noMarkOnSelectedAccount"));
target.add(getPageBase().getFeedbackPanel());
return;
}

ObjectFilter marksFilter = PrismContext.get().queryFor(MarkType.class)
.item(MarkType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF)
.ref(SystemObjectsType.ARCHETYPE_OBJECT_MARK.value())
Expand All @@ -378,7 +400,9 @@ public org.apache.wicket.model.StringResourceModel getTitle() {

protected org.apache.wicket.model.StringResourceModel getAddButtonTitle() {
return createStringResource("pageContentAccounts.menu.mark.remove");
};
}

;
};

getPageBase().showMainPopup(browser, target);
Expand Down Expand Up @@ -459,7 +483,7 @@ private List<IColumn<SelectableBean<ShadowType>, String>> initColumns() {

@Override
public void populateItem(Item<ICellPopulator<SelectableBean<ShadowType>>> cellItem,
String componentId, IModel<SelectableBean<ShadowType>> rowModel) {
String componentId, IModel<SelectableBean<ShadowType>> rowModel) {

SelectableBean<ShadowType> dto = rowModel.getObject();
RepeatingView repeater = new RepeatingView(componentId);
Expand Down Expand Up @@ -500,7 +524,7 @@ public FocusType getObject() {

@Override
public void onClick(AjaxRequestTarget target, IModel<SelectableBean<ShadowType>> rowModel,
ObjectType targetObjectType) {
ObjectType targetObjectType) {
ownerDetailsPerformed((FocusType) targetObjectType);
}

Expand All @@ -518,7 +542,7 @@ public boolean isEnabled(IModel<SelectableBean<ShadowType>> rowModel) {

@Override
public void populateItem(Item<ICellPopulator<SelectableBean<ShadowType>>> cellItem,
String componentId, IModel<SelectableBean<ShadowType>> rowModel) {
String componentId, IModel<SelectableBean<ShadowType>> rowModel) {
cellItem.add(new PendingOperationPanel(componentId,
new PropertyModel<>(rowModel, SelectableBeanImpl.F_VALUE + "." + ShadowType.F_PENDING_OPERATION.getLocalPart())));
}
Expand Down Expand Up @@ -664,7 +688,7 @@ protected void importResourceObject(ShadowType selected, AjaxRequestTarget targe
}

protected void updateResourceObjectStatusPerformed(IModel<SelectableBean<ShadowType>> selected, AjaxRequestTarget target,
boolean enabled) {
boolean enabled) {
List<SelectableBean<ShadowType>> selectedShadow = getSelectedShadowsList(selected);

OperationResult result = new OperationResult(OPERATION_UPDATE_STATUS);
Expand All @@ -689,8 +713,8 @@ protected void updateResourceObjectStatusPerformed(IModel<SelectableBean<ShadowT
getPageBase().getModelService().executeChanges(
MiscUtil.createCollection(deleteDelta), null, task, result);
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
| PolicyViolationException | SecurityViolationException e) {
| ExpressionEvaluationException | CommunicationException | ConfigurationException
| PolicyViolationException | SecurityViolationException e) {
result.recordPartialError(
createStringResource(
"ResourceContentPanel.message.updateResourceObjectStatusPerformed.partialError", status, shadow)
Expand Down Expand Up @@ -758,7 +782,7 @@ private void deleteAccountsConfirmedPerformed(
result.setUserFriendlyMessage(
new SingleLocalizableMessage(
"ShadowTablePanel.message.deletionForbidden",
new Object[]{shadow.getName()}));
new Object[] { shadow.getName() }));
}
} catch (Throwable e) {
result.recordPartialError("Could not delete " + shadow + ", reason: " + e.getMessage(), e);
Expand Down Expand Up @@ -793,7 +817,7 @@ private IModel<String> createDeleteConfirmString(List<SelectableBean<ShadowType>
}

private void changeOwner(IModel<SelectableBean<ShadowType>> selected, AjaxRequestTarget target, FocusType ownerToChange,
boolean remove) {
boolean remove) {

getPageBase().hideMainPopup(target);

Expand Down Expand Up @@ -885,9 +909,8 @@ private void removeShadowMarks(IModel<SelectableBean<ShadowType>> rowModel, List
target.add(getPageBase().getFeedbackPanel());
}


private void markShadows(IModel<SelectableBean<ShadowType>> rowModel, List<String> markOids,
AjaxRequestTarget target) {
AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_MARK_SHADOW);
Task task = getPageBase().createSimpleTask(OPERATION_MARK_SHADOW);

Expand All @@ -914,8 +937,8 @@ private void markShadows(IModel<SelectableBean<ShadowType>> rowModel, List<Strin
statements.toArray(new PolicyStatementType[0]));
getPageBase().getModelService().executeChanges(MiscUtil.createCollection(delta), null, task, result);
} catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException
| ExpressionEvaluationException | CommunicationException | ConfigurationException
| PolicyViolationException | SecurityViolationException e) {
| ExpressionEvaluationException | CommunicationException | ConfigurationException
| PolicyViolationException | SecurityViolationException e) {
result.recordPartialError(
createStringResource(
"ResourceContentPanel.message.markShadowPerformed.partialError", shadow)
Expand Down Expand Up @@ -950,7 +973,7 @@ private boolean isSatisfyConstraints(List selected) {
}

private void changeOwnerInternal(String ownerOid, Class<? extends FocusType> ownerType, Collection<? extends ItemDelta> modifications,
AjaxRequestTarget target) {
AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_CHANGE_OWNER);
Task task = getPageBase().createSimpleTask(OPERATION_CHANGE_OWNER);
ObjectDelta<? extends ObjectType> objectDelta =
Expand Down Expand Up @@ -985,7 +1008,6 @@ private PrismObjectDefinition<FocusType> getFocusDefinition() {
.findObjectDefinitionByCompileTimeClass(FocusType.class);
}


private String[] collectExistingMarks(List<SelectableBean<ShadowType>> selected) {
Set<String> marks = new HashSet<>();
for (SelectableBean<ShadowType> shadow : selected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum ObjectTypeGuiDescriptor {

GENERIC_OBJECT(ObjectTypes.GENERIC_OBJECT, "ObjectTypeGuiDescriptor.genericObject", "silk-page_white_code", "silk-page_white_code"),

TAG(ObjectTypes.MARK, "ObjectTypeGuiDescriptor.tag", "silk-page_white_code", "silk-page_white_code"),
MARK(ObjectTypes.MARK, "ObjectTypeGuiDescriptor.mark", "silk-page_white_code", "silk-page_white_code"),

RESOURCE(ObjectTypes.RESOURCE, "ObjectTypeGuiDescriptor.resource", GuiStyleConstants.CLASS_OBJECT_RESOURCE_ICON_COLORED, GuiStyleConstants.CLASS_OBJECT_RESOURCE_ICON),

Expand All @@ -45,7 +45,7 @@ public enum ObjectTypeGuiDescriptor {

ROLE(ObjectTypes.ROLE, "ObjectTypeGuiDescriptor.role", GuiStyleConstants.CLASS_OBJECT_ROLE_ICON_COLORED, GuiStyleConstants.CLASS_OBJECT_ROLE_ICON),

VALUE_POLICY(ObjectTypes.PASSWORD_POLICY, "ObjectTypeGuiDescriptor.valuePolicy", "silk-lock", "silk-lock"),
VALUE_POLICY(ObjectTypes.PASSWORD_POLICY, "ObjectTypeGuiDescriptor.passwordPolicy", "silk-lock", "silk-lock"),

NODE(ObjectTypes.NODE, "ObjectTypeGuiDescriptor.node", "silk-computer", "silk-computer"),

Expand Down

0 comments on commit ac8d81b

Please sign in to comment.