Rename variable

This commit is contained in:
Brendan Le Ny 2024-06-12 17:40:01 +02:00
parent 2ed6f1a16d
commit f2464bbc00

View file

@ -99,19 +99,19 @@ public class ScimClient {
return session.getContext().getRealm().getId(); return session.getContext().getRealm().getId();
} }
protected <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> A getAdapter( protected <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> A newAdapter(
Class<A> aClass) { Class<A> adapterClass) {
try { try {
return aClass.getDeclaredConstructor(KeycloakSession.class, String.class) return adapterClass.getDeclaredConstructor(KeycloakSession.class, String.class)
.newInstance(session, this.model.getId()); .newInstance(session, this.model.getId());
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void create(Class<A> aClass, public <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void create(Class<A> adapterClass,
M kcModel) { M kcModel) {
A adapter = getAdapter(aClass); A adapter = newAdapter(adapterClass);
adapter.apply(kcModel); adapter.apply(kcModel);
if (adapter.skip) if (adapter.skip)
return; return;
@ -141,9 +141,9 @@ public class ScimClient {
adapter.saveMapping(); adapter.saveMapping();
} }
public <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void replace(Class<A> aClass, public <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void replace(Class<A> adapterClass,
M kcModel) { M kcModel) {
A adapter = getAdapter(aClass); A adapter = newAdapter(adapterClass);
try { try {
adapter.apply(kcModel); adapter.apply(kcModel);
if (adapter.skip) if (adapter.skip)
@ -172,9 +172,9 @@ public class ScimClient {
} }
} }
public <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void delete(Class<A> aClass, public <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void delete(Class<A> adapterClass,
String id) { String id) {
A adapter = getAdapter(aClass); A adapter = newAdapter(adapterClass);
adapter.setId(id); adapter.setId(id);
try { try {
@ -205,21 +205,21 @@ public class ScimClient {
} }
public <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void refreshResources( public <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void refreshResources(
Class<A> aClass, Class<A> adapterClass,
SynchronizationResult syncRes) { SynchronizationResult syncRes) {
LOGGER.info("Refresh resources"); LOGGER.info("Refresh resources");
getAdapter(aClass).getResourceStream().forEach(resource -> { newAdapter(adapterClass).getResourceStream().forEach(resource -> {
A adapter = getAdapter(aClass); A adapter = newAdapter(adapterClass);
adapter.apply(resource); adapter.apply(resource);
LOGGER.infof("Reconciling local resource %s", adapter.getId()); LOGGER.infof("Reconciling local resource %s", adapter.getId());
if (!adapter.skipRefresh()) { if (!adapter.skipRefresh()) {
ScimResource mapping = adapter.getMapping(); ScimResource mapping = adapter.getMapping();
if (mapping == null) { if (mapping == null) {
LOGGER.info("Creating it"); LOGGER.info("Creating it");
this.create(aClass, resource); this.create(adapterClass, resource);
} else { } else {
LOGGER.info("Replacing it"); LOGGER.info("Replacing it");
this.replace(aClass, resource); this.replace(adapterClass, resource);
} }
syncRes.increaseUpdated(); syncRes.increaseUpdated();
} }
@ -228,17 +228,17 @@ public class ScimClient {
} }
public <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void importResources( public <M extends RoleMapperModel, S extends ResourceNode, A extends Adapter<M, S>> void importResources(
Class<A> aClass, SynchronizationResult syncRes) { Class<A> adapterClass, SynchronizationResult syncRes) {
LOGGER.info("Import"); LOGGER.info("Import");
try { try {
A adapter = getAdapter(aClass); A adapter = newAdapter(adapterClass);
ServerResponse<ListResponse<S>> response = scimRequestBuilder.list(adapter.getResourceClass(), adapter.getScimEndpoint()).get().sendRequest(); ServerResponse<ListResponse<S>> response = scimRequestBuilder.list(adapter.getResourceClass(), adapter.getScimEndpoint()).get().sendRequest();
ListResponse<S> resourceTypeListResponse = response.getResource(); ListResponse<S> resourceTypeListResponse = response.getResource();
for (S resource : resourceTypeListResponse.getListedResources()) { for (S resource : resourceTypeListResponse.getListedResources()) {
try { try {
LOGGER.infof("Reconciling remote resource %s", resource); LOGGER.infof("Reconciling remote resource %s", resource);
adapter = getAdapter(aClass); adapter = newAdapter(adapterClass);
adapter.apply(resource); adapter.apply(resource);
ScimResource mapping = adapter.getMapping(); ScimResource mapping = adapter.getMapping();