Skip to content

Commit

Permalink
[SYNCOPE-1831] Fixing Core and Console to save SCIM general conf
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Oct 18, 2024
1 parent 3fe21e0 commit 0302122
Show file tree
Hide file tree
Showing 21 changed files with 423 additions and 375 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.syncope.client.ui.commons.markup.html.form;

import com.googlecode.wicket.jquery.core.Options;
import com.googlecode.wicket.kendo.ui.form.NumberTextField;
import org.apache.syncope.client.ui.commons.Constants;
import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;

public final class AjaxNumberFieldPanel<T extends Number & Comparable<T>> extends FieldPanel<T> {

private static final long serialVersionUID = 6413819574530703577L;

private final IModel<T> model;

private final Options options;

private final boolean enableOnChange;

private AjaxNumberFieldPanel(
final String id,
final String name,
final IModel<T> model,
final Options options,
final boolean enableOnChange) {

super(id, name, model);

this.model = model;
this.options = options;
this.enableOnChange = enableOnChange;

field = new NumberTextField<>("numberTextField", model, options);

if (enableOnChange && !isReadOnly()) {
field.add(new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

private static final long serialVersionUID = -1107858522700306810L;

@Override
protected void onUpdate(final AjaxRequestTarget target) {
// nothing to do
}
});
}

add(field.setLabel(new ResourceModel(name, name)).setOutputMarkupId(true));
}

@Override
public FieldPanel<T> setReadOnly(final boolean readOnly) {
super.setReadOnly(readOnly);
AjaxNumberFieldPanel.class.cast(field).setEnabled(!readOnly);
return this;
}

@Override
public AjaxNumberFieldPanel<T> clone() {
AjaxNumberFieldPanel<T> panel = new AjaxNumberFieldPanel<>(
getId(), name, model, options, enableOnChange);

panel.setRequired(isRequired());
panel.setReadOnly(isReadOnly());
panel.setTitle(title);

if (isRequiredLabelAdded) {
panel.addRequiredLabel();
}

return panel;
}

public static class Builder<T extends Number & Comparable<T>> {

private final Options options;

private boolean enableOnChange = false;

public Builder() {
this(new Options().set("format", "'#'").set("step", "1"));
}

public Builder(final Options options) {
this.options = options;
options.set("format", "'#'");
options.set("step", "1");
}

public Builder<T> min(final T min) {
options.set("min", min);
return this;
}

public Builder<T> max(final T max) {
options.set("max", max);
return this;
}

public Builder<T> step(final T step) {
options.set("step", step);
return this;
}

public Builder<T> format(final String format) {
options.set("format", format);
return this;
}

public Builder<T> enableOnChange() {
enableOnChange = true;
return this;
}

public AjaxNumberFieldPanel<T> build(
final String id,
final String name,
final IModel<T> model) {

return new AjaxNumberFieldPanel<>(id, name, model, options, enableOnChange);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
<wicket:extend>
<wicket:enclosure child="field-label">
<label wicket:id="field-label">[LABEL]</label><span wicket:id="required"/>
<span wicket:id="externalAction"/>
</wicket:enclosure>

<input type="number" wicket:id="numberTextField"/>
</wicket:extend>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,12 @@
package org.apache.syncope.client.console.pages;

import com.fasterxml.jackson.databind.json.JsonMapper;
import java.io.Serializable;
import org.apache.syncope.client.console.BookmarkablePageLinkBuilder;
import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.client.console.panels.SCIMConfPanel;
import org.apache.syncope.client.console.rest.SCIMConfRestClient;
import org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
import org.apache.syncope.client.console.wizards.any.ResultPanel;
import org.apache.syncope.client.ui.commons.Constants;
import org.apache.syncope.client.ui.commons.annotations.ExtPage;
import org.apache.syncope.common.lib.scim.SCIMConf;
import org.apache.syncope.common.lib.scim.types.SCIMEntitlement;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;

Expand All @@ -45,52 +38,15 @@ public class SCIMConfPage extends BaseExtPage {
@SpringBean
protected SCIMConfRestClient scimConfRestClient;

protected final WebMarkupContainer content;

public SCIMConfPage(final PageParameters parameters) {
super(parameters);

body.add(BookmarkablePageLinkBuilder.build("dashboard", "dashboardBr", Dashboard.class));

content = new WebMarkupContainer("content");

content.add(new Label("body", "General"));
WebMarkupContainer content = new WebMarkupContainer("content");
content.setOutputMarkupId(true);
body.add(content);

updateSCIMGeneralConfContent(scimConfRestClient.get());
}

protected WebMarkupContainer updateSCIMGeneralConfContent(final SCIMConf scimConf) {
if (scimConf == null) {
return content;
}

content.addOrReplace(new SCIMConfPanel("body", scimConf, SCIMConfPage.this.getPageReference()) {

private static final long serialVersionUID = 8221398624379357183L;

@Override
protected void setWindowClosedReloadCallback(final BaseModal<?> modal) {
modal.setWindowClosedCallback(target -> {
if (modal.getContent() instanceof ResultPanel) {
Serializable result = ResultPanel.class.cast(modal.getContent()).getResult();
try {
scimConfRestClient.set(MAPPER.readValue(result.toString(), SCIMConf.class));

SyncopeConsoleSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
modal.show(false);
target.add(content);
} catch (Exception e) {
LOG.error("While setting SCIM configuration", e);
SyncopeConsoleSession.get().onException(e);
}
((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target);
}
});
}
});

return content;
content.add(new SCIMConfPanel("scimConf", scimConfRestClient.get(), SCIMConfPage.this.getPageReference()));
}
}
Loading

0 comments on commit 0302122

Please sign in to comment.