Skip to content

Commit

Permalink
Allowing for easier AnyPanel subclassing
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed Aug 31, 2023
1 parent ec54d59 commit b1b3ed0
Showing 1 changed file with 95 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
*/
package org.apache.syncope.client.console.panels;

import static org.apache.syncope.common.lib.types.AnyTypeKind.ANY_OBJECT;
import static org.apache.syncope.common.lib.types.AnyTypeKind.GROUP;
import static org.apache.syncope.common.lib.types.AnyTypeKind.USER;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -119,7 +123,7 @@ public Builder(
}

public AP build() {
return build(instance.defaultDirectoryPanelSupplier);
return build(instance.getDefaultDirectoryPanelSupplier());
}

public AP build(final DirectoryPanelSupplier directoryPanelSupplier) {
Expand Down Expand Up @@ -158,95 +162,6 @@ public AP build(final DirectoryPanelSupplier directoryPanelSupplier) {

protected Panel directoryPanel;

protected final DirectoryPanelSupplier defaultDirectoryPanelSupplier =
(id, anyTypeTO, realmTO, anyLayout, pageRef) -> {

Panel panel;
String fiql;

String realm;
String dynRealm;
if (StringUtils.startsWith(realmTO.getFullPath(), SyncopeConstants.ROOT_REALM)) {
realm = RealmsUtils.getFullPath(realmTO.getFullPath());
dynRealm = null;
} else {
realm = SyncopeConstants.ROOT_REALM;
dynRealm = realmTO.getKey();
}

switch (anyTypeTO.getKind()) {
case USER:
fiql = dynRealm == null
? SyncopeClient.getUserSearchConditionBuilder().
is(Constants.KEY_FIELD_NAME).notNullValue().query()
: SyncopeClient.getUserSearchConditionBuilder().
inDynRealms(dynRealm).query();

UserTO user = new UserTO();
user.setRealm(RealmsUtils.getFullPath(realmTO.getFullPath()));
panel = new UserDirectoryPanel.Builder(
anyTypeClassRestClient.list(anyTypeTO.getClasses()),
userRestClient,
anyTypeTO.getKey(),
pageRef).setRealm(realm).setDynRealm(dynRealm).setFiltered(true).
setFiql(fiql).setWizardInModal(true).addNewItemPanelBuilder(
AnyLayoutUtils.newLayoutInfo(
user, anyTypeTO.getClasses(), anyLayout.getUser(), userRestClient, pageRef)).
build(id);
MetaDataRoleAuthorizationStrategy.authorize(panel, WebPage.RENDER,
IdRepoEntitlement.USER_SEARCH);
break;

case GROUP:
fiql = dynRealm == null
? SyncopeClient.getGroupSearchConditionBuilder().
is(Constants.KEY_FIELD_NAME).notNullValue().query()
: SyncopeClient.getGroupSearchConditionBuilder().inDynRealms(dynRealm).query();

GroupTO group = new GroupTO();
group.setRealm(RealmsUtils.getFullPath(realmTO.getFullPath()));
panel = new GroupDirectoryPanel.Builder(
anyTypeClassRestClient.list(anyTypeTO.getClasses()),
groupRestClient,
anyTypeTO.getKey(),
pageRef).setRealm(realm).setDynRealm(dynRealm).setFiltered(true).
setFiql(fiql).setWizardInModal(true).addNewItemPanelBuilder(
AnyLayoutUtils.newLayoutInfo(
group, anyTypeTO.getClasses(), anyLayout.getGroup(), groupRestClient, pageRef)).
build(id);
// list of group is available to all authenticated users
break;

case ANY_OBJECT:
fiql = dynRealm == null
? SyncopeClient.getAnyObjectSearchConditionBuilder(anyTypeTO.getKey()).
is(Constants.KEY_FIELD_NAME).notNullValue().query()
: SyncopeClient.getAnyObjectSearchConditionBuilder(anyTypeTO.getKey()).
inDynRealms(dynRealm).query();

AnyObjectTO anyObject = new AnyObjectTO();
anyObject.setRealm(RealmsUtils.getFullPath(realmTO.getFullPath()));
anyObject.setType(anyTypeTO.getKey());
panel = new AnyObjectDirectoryPanel.Builder(
anyTypeClassRestClient.list(anyTypeTO.getClasses()),
anyObjectRestClient,
anyTypeTO.getKey(),
pageRef).setRealm(realm).setDynRealm(dynRealm).setFiltered(true).
setFiql(fiql).setWizardInModal(true).addNewItemPanelBuilder(
AnyLayoutUtils.newLayoutInfo(anyObject, anyTypeTO.getClasses(),
anyLayout.getAnyObjects().get(anyTypeTO.getKey()),
anyObjectRestClient, pageRef)).
build(id);
MetaDataRoleAuthorizationStrategy.authorize(
panel, WebPage.RENDER, AnyEntitlement.SEARCH.getFor(anyTypeTO.getKey()));
break;

default:
panel = new LabelPanel(id, null);
}
return panel;
};

protected AnyPanel(
final String id,
final AnyTypeTO anyTypeTO,
Expand Down Expand Up @@ -298,6 +213,96 @@ public void onClick(final AjaxRequestTarget target) {
// ------------------------
}

protected DirectoryPanelSupplier getDefaultDirectoryPanelSupplier() {
return (id, anyType, r, layout, pr) -> {
Panel panel;
String fiql;

String realm;
String dynRealm;
if (StringUtils.startsWith(r.getFullPath(), SyncopeConstants.ROOT_REALM)) {
realm = RealmsUtils.getFullPath(r.getFullPath());
dynRealm = null;
} else {
realm = SyncopeConstants.ROOT_REALM;
dynRealm = r.getKey();
}

switch (anyType.getKind()) {
case USER:
fiql = dynRealm == null
? SyncopeClient.getUserSearchConditionBuilder().
is(Constants.KEY_FIELD_NAME).notNullValue().query()
: SyncopeClient.getUserSearchConditionBuilder().
inDynRealms(dynRealm).query();

UserTO user = new UserTO();
user.setRealm(RealmsUtils.getFullPath(r.getFullPath()));
panel = new UserDirectoryPanel.Builder(
anyTypeClassRestClient.list(anyType.getClasses()),
userRestClient,
anyType.getKey(),
pr).setRealm(realm).setDynRealm(dynRealm).setFiltered(true).
setFiql(fiql).setWizardInModal(true).addNewItemPanelBuilder(
AnyLayoutUtils.newLayoutInfo(
user, anyType.getClasses(), layout.getUser(), userRestClient, pr)).
build(id);
MetaDataRoleAuthorizationStrategy.authorize(panel, WebPage.RENDER,
IdRepoEntitlement.USER_SEARCH);
break;

case GROUP:
fiql = dynRealm == null
? SyncopeClient.getGroupSearchConditionBuilder().
is(Constants.KEY_FIELD_NAME).notNullValue().query()
: SyncopeClient.getGroupSearchConditionBuilder().
inDynRealms(dynRealm).query();

GroupTO group = new GroupTO();
group.setRealm(RealmsUtils.getFullPath(r.getFullPath()));
panel = new GroupDirectoryPanel.Builder(
anyTypeClassRestClient.list(anyType.getClasses()),
groupRestClient,
anyType.getKey(),
pr).setRealm(realm).setDynRealm(dynRealm).setFiltered(true).
setFiql(fiql).setWizardInModal(true).addNewItemPanelBuilder(
AnyLayoutUtils.newLayoutInfo(
group, anyType.getClasses(), layout.getGroup(), groupRestClient, pr)).
build(id);
// list of group is available to all authenticated users
break;

case ANY_OBJECT:
fiql = dynRealm == null
? SyncopeClient.getAnyObjectSearchConditionBuilder(anyType.getKey()).
is(Constants.KEY_FIELD_NAME).notNullValue().query()
: SyncopeClient.getAnyObjectSearchConditionBuilder(anyType.getKey()).
inDynRealms(dynRealm).query();

AnyObjectTO anyObject = new AnyObjectTO();
anyObject.setRealm(RealmsUtils.getFullPath(r.getFullPath()));
anyObject.setType(anyType.getKey());
panel = new AnyObjectDirectoryPanel.Builder(
anyTypeClassRestClient.list(anyType.getClasses()),
anyObjectRestClient,
anyType.getKey(),
pr).setRealm(realm).setDynRealm(dynRealm).setFiltered(true).
setFiql(fiql).setWizardInModal(true).addNewItemPanelBuilder(
AnyLayoutUtils.newLayoutInfo(anyObject, anyType.getClasses(),
layout.getAnyObjects().get(anyType.getKey()),
anyObjectRestClient, pr)).
build(id);
MetaDataRoleAuthorizationStrategy.authorize(
panel, WebPage.RENDER, AnyEntitlement.SEARCH.getFor(anyType.getKey()));
break;

default:
panel = new LabelPanel(id, null);
}
return panel;
};
}

protected Panel createDirectoryPanel(
final AnyTypeTO anyTypeTO,
final RealmTO realmTO,
Expand Down

0 comments on commit b1b3ed0

Please sign in to comment.