Skip to content

Commit

Permalink
Change IdPrefix to IdRegexp to allow key generation for blossom inlin…
Browse files Browse the repository at this point in the history
…e @TabFactory dialogs
  • Loading branch information
eschleb committed Jul 12, 2024
1 parent cf2eb3f commit 914500b
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion custom-definitions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.namics.oss.magnolia</groupId>
<artifactId>magnolia-definition-builders-parent</artifactId>
<version>1.0.27-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>custom-definition-builders</artifactId>
Expand Down
31 changes: 16 additions & 15 deletions key-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,25 @@ public class SomeModule implements ModuleLifecycle {

```java
import info.magnolia.objectfactory.guice.AbstractGuiceComponentConfigurer;
import com.merkle.oss.magnolia.definition.key.generator.configuration.IdPrefix;

import com.merkle.oss.magnolia.definition.key.generator.configuration.IdRegexp;
import com.merkle.oss.magnolia.definition.key.generator.configuration.FallbackDialogName;

public class GuiceComponentConfigurer extends AbstractGuiceComponentConfigurer {
@Override
protected void configure() {
binder().bind(String.class)
.annotatedWith(IdPrefix.class)
.toInstance("SomeModule");

binder().bind(String.class)
.annotatedWith(FallbackDialogName.class)
.toInstance("CommonDialog");

//Optional
final Multibinder<Class<?>> excludedAncestorsMultibinder = Multibinder.newSetBinder(binder(), new TypeLiteral<Class<?>>(){}, ExcludedAncestors.class);
excludedAncestorsMultibinder.addBinding().toInstance(SomeDefinitionOfAncestorThatShouldBeExcluded.class);
}
@Override
protected void configure() {
binder().bind(String.class)
.annotatedWith(IdRegexp.class)
.toInstance("^SomeModule|blossom-area-dialog:com.some.package");

binder().bind(String.class)
.annotatedWith(FallbackDialogName.class)
.toInstance("CommonDialog");

//Optional
final Multibinder<Class<?>> excludedAncestorsMultibinder = Multibinder.newSetBinder(binder(), new TypeLiteral<Class<?>>() {}, ExcludedAncestors.class);
excludedAncestorsMultibinder.addBinding().toInstance(SomeDefinitionOfAncestorThatShouldBeExcluded.class);
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion key-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.namics.oss.magnolia</groupId>
<artifactId>magnolia-definition-builders-parent</artifactId>
<version>1.0.27-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>magnolia-definition-keyGenerators</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
package com.merkle.oss.magnolia.definition.key.generator;

import com.merkle.oss.magnolia.definition.key.generator.configuration.ExcludedAncestors;
import com.merkle.oss.magnolia.definition.key.generator.configuration.FallbackDialogName;
import com.merkle.oss.magnolia.definition.key.generator.configuration.IdPrefix;
import info.magnolia.i18nsystem.AbstractI18nKeyGenerator;
import org.apache.commons.lang3.StringUtils;

import javax.inject.Inject;
import java.lang.reflect.AnnotatedElement;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;

import com.merkle.oss.magnolia.definition.key.generator.configuration.ExcludedAncestors;
import com.merkle.oss.magnolia.definition.key.generator.configuration.FallbackDialogName;
import com.merkle.oss.magnolia.definition.key.generator.configuration.IdRegexp;

public class KeyGeneratorUtil extends AbstractI18nKeyGenerator<Object> {
private final String fallbackDialogName;
private final String idPrefix;
private final Pattern idPattern;
private final Set<Class<?>> excludedAncestors;

@Inject
public KeyGeneratorUtil(
@FallbackDialogName final String fallbackDialogName,
@IdPrefix final String idPrefix,
@IdRegexp final String idRegexp,
@ExcludedAncestors final Set<Class<?>> excludedAncestors
) {
this.fallbackDialogName = fallbackDialogName;
this.idPrefix = idPrefix;
this.excludedAncestors = excludedAncestors;
this.idPattern = Pattern.compile(idRegexp);
}

public boolean isMagnoliaModule(final Object definition) {
return !StringUtils.startsWith(getIdOrNameForUnknownRoot(definition, false), idPrefix);
return !idPattern.matcher(getIdOrNameForUnknownRoot(definition, false)).find();
}

public String getDialogName(final Object definition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER})
@BindingAnnotation
public @interface IdPrefix {
public @interface IdRegexp {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EditorPropertyDefinitionKeyGeneratorTest extends AbstractKeyGeneratorTest
@BeforeEach
void setUp() {
keyGenerator = new EditorPropertyDefinitionKeyGenerator(
new KeyGeneratorUtil("FallbackDialog", "idPrefix", Set.of(ConfiguredFormDefinition.class)),
new KeyGeneratorUtil("FallbackDialog", "^idPrefix", Set.of(ConfiguredFormDefinition.class)),
new FieldDefinitionKeyGenerator(),
new KeyPrefixer()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FieldValidatorDefinitionKeyGeneratorTest extends AbstractKeyGeneratorTest
@BeforeEach
void setUp() {
keyGenerator = new FieldValidatorDefinitionKeyGenerator(
new KeyGeneratorUtil("FallbackDialog", "idPrefix", Set.of(ConfiguredFormDefinition.class)),
new KeyGeneratorUtil("FallbackDialog", "^idPrefix", Set.of(ConfiguredFormDefinition.class)),
new FieldDefinitionKeyGenerator(),
new KeyPrefixer()
);
Expand Down
2 changes: 1 addition & 1 deletion magnolia-builders/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.namics.oss.magnolia</groupId>
<artifactId>magnolia-definition-builders-parent</artifactId>
<version>1.0.27-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>magnolia-definition-builders</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.namics.oss.magnolia</groupId>
<artifactId>magnolia-definition-builders-parent</artifactId>
<version>1.0.27-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>${project.artifactId}</name>
Expand Down

0 comments on commit 914500b

Please sign in to comment.