-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt to reworked configuration sources (6.3 change)
- Loading branch information
eschleb
committed
Sep 25, 2024
1 parent
b917f57
commit 84b2ad8
Showing
9 changed files
with
233 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/com/namics/oss/magnolia/appbuilder/AppConfigurationSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.namics.oss.magnolia.appbuilder; | ||
|
||
import static com.google.common.base.CaseFormat.*; | ||
|
||
import info.magnolia.config.registry.DefinitionMetadata; | ||
import info.magnolia.config.registry.DefinitionProvider; | ||
import info.magnolia.config.registry.DefinitionType; | ||
import info.magnolia.config.registry.RegistryMap; | ||
import info.magnolia.config.source.ConfigurationSource; | ||
import info.magnolia.config.source.ConfigurationSourceType; | ||
import info.magnolia.config.source.ConfigurationSourceTypes; | ||
import info.magnolia.objectfactory.Components; | ||
import info.magnolia.ui.api.app.AppDescriptor; | ||
import info.magnolia.ui.api.app.registry.DefinitionTypes; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.util.Collection; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.namics.oss.magnolia.appbuilder.annotations.AppFactories; | ||
|
||
public class AppConfigurationSource implements ConfigurationSource<AppDescriptor> { | ||
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
private final RegistryMap<AppDescriptor> registryMap = new RegistryMap<>(); | ||
private final Set<Class<?>> appFactories; | ||
private final LegacyAppDescriptorProvider.ColumnDefinitionFilter legacyAppColumnDefinitionFilter; | ||
|
||
@Inject | ||
public AppConfigurationSource( | ||
@AppFactories final Set<Class<?>> appFactories, | ||
final LegacyAppDescriptorProvider.ColumnDefinitionFilter legacyAppColumnDefinitionFilter | ||
) { | ||
this.appFactories = appFactories; | ||
this.legacyAppColumnDefinitionFilter = legacyAppColumnDefinitionFilter; | ||
} | ||
|
||
@Override | ||
public ConfigurationSourceType type() { | ||
return ConfigurationSourceTypes.code; | ||
} | ||
|
||
@Override | ||
public DefinitionType getDefinitionType() { | ||
return DefinitionTypes.APP; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
LOG.info("Setting up {} for {} definitions", getClass().getSimpleName(), LOWER_CAMEL.to(LOWER_HYPHEN, getDefinitionType().getName())); | ||
registryMap.removeAndPutAll( | ||
registryMap.keySet(), | ||
appFactories.stream() | ||
.flatMap(this::definitionProviders) | ||
.collect(Collectors.toSet()) | ||
); | ||
} | ||
|
||
private Stream<DefinitionProvider<AppDescriptor>> definitionProviders(final Class<?> factoryClass) { | ||
LOG.info("Registered app '{}' from {}", factoryClass.getSimpleName(), factoryClass.getName()); | ||
final Object factory = Components.newInstance(factoryClass); | ||
return Stream.concat( | ||
Stream.of(new AppDescriptorProvider(factory)), | ||
Stream.of(new LegacyAppDescriptorProvider(factory, legacyAppColumnDefinitionFilter)).filter(LegacyAppDescriptorProvider::shouldRegister) | ||
); | ||
} | ||
|
||
@Override | ||
public DefinitionProvider<AppDescriptor> getProvider(final DefinitionMetadata id) { | ||
return registryMap.get(id); | ||
} | ||
|
||
@Override | ||
public DefinitionProvider<AppDescriptor> getProvider(final String id) { | ||
return registryMap.getByStringKey(id); | ||
} | ||
|
||
@Override | ||
public Collection<DefinitionMetadata> getAllMetadata() { | ||
return registryMap.keySet(); | ||
} | ||
|
||
@Override | ||
public Collection<DefinitionProvider<AppDescriptor>> getAllProviders() { | ||
return registryMap.values(); | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
src/main/java/com/namics/oss/magnolia/appbuilder/AppRegistrar.java
This file was deleted.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
src/main/java/com/namics/oss/magnolia/appbuilder/ChooserDialogConfigurationSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.namics.oss.magnolia.appbuilder; | ||
|
||
import static com.google.common.base.CaseFormat.*; | ||
|
||
import info.magnolia.config.registry.DefinitionMetadata; | ||
import info.magnolia.config.registry.DefinitionProvider; | ||
import info.magnolia.config.registry.DefinitionType; | ||
import info.magnolia.config.registry.RegistryMap; | ||
import info.magnolia.config.source.ConfigurationSource; | ||
import info.magnolia.config.source.ConfigurationSourceType; | ||
import info.magnolia.config.source.ConfigurationSourceTypes; | ||
import info.magnolia.objectfactory.Components; | ||
import info.magnolia.ui.dialog.DefinitionTypes; | ||
import info.magnolia.ui.dialog.DialogDefinition; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.util.Collection; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.namics.oss.magnolia.appbuilder.annotations.ChooserDialogFactories; | ||
|
||
public class ChooserDialogConfigurationSource implements ConfigurationSource<DialogDefinition> { | ||
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
private final RegistryMap<DialogDefinition> registryMap = new RegistryMap<>(); | ||
private final Set<Class<?>> chooserDialogFactories; | ||
|
||
@Inject | ||
public ChooserDialogConfigurationSource(@ChooserDialogFactories final Set<Class<?>> chooserDialogFactories) { | ||
this.chooserDialogFactories = chooserDialogFactories; | ||
} | ||
|
||
@Override | ||
public ConfigurationSourceType type() { | ||
return ConfigurationSourceTypes.code; | ||
} | ||
|
||
@Override | ||
public DefinitionType getDefinitionType() { | ||
return DefinitionTypes.DIALOG; | ||
} | ||
|
||
@Override | ||
public void start() { | ||
LOG.info("Setting up {} for {} definitions", getClass().getSimpleName(), LOWER_CAMEL.to(LOWER_HYPHEN, getDefinitionType().getName())); | ||
registryMap.removeAndPutAll( | ||
registryMap.keySet(), | ||
chooserDialogFactories.stream() | ||
.flatMap(this::definitionProviders) | ||
.collect(Collectors.toSet()) | ||
); | ||
} | ||
|
||
private Stream<DefinitionProvider<DialogDefinition>> definitionProviders(final Class<?> factoryClass) { | ||
LOG.info("Registered dialog '{}' from {}", factoryClass.getSimpleName(), factoryClass.getName()); | ||
final Object factory = Components.newInstance(factoryClass); | ||
return Stream.of(new ChooserDialogDefinitionProvider<>(factory)); | ||
} | ||
|
||
@Override | ||
public DefinitionProvider<DialogDefinition> getProvider(final DefinitionMetadata id) { | ||
return registryMap.get(id); | ||
} | ||
|
||
@Override | ||
public DefinitionProvider<DialogDefinition> getProvider(final String id) { | ||
return registryMap.getByStringKey(id); | ||
} | ||
|
||
@Override | ||
public Collection<DefinitionMetadata> getAllMetadata() { | ||
return registryMap.keySet(); | ||
} | ||
|
||
@Override | ||
public Collection<DefinitionProvider<DialogDefinition>> getAllProviders() { | ||
return registryMap.values(); | ||
} | ||
|
||
} |
52 changes: 0 additions & 52 deletions
52
src/main/java/com/namics/oss/magnolia/appbuilder/ChooserDialogRegistrar.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/main/java/com/namics/oss/magnolia/appbuilder/annotations/AppFactories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.namics.oss.magnolia.appbuilder.annotations; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import com.google.inject.BindingAnnotation; | ||
|
||
@BindingAnnotation | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.PARAMETER }) | ||
public @interface AppFactories {} |
Oops, something went wrong.