-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added UUID expression function for thymeleaf templating
- Loading branch information
Showing
6 changed files
with
69 additions
and
2 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
4 changes: 2 additions & 2 deletions
4
src/main/java/ai/labs/eddi/modules/templating/impl/TemplatingEngine.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
16 changes: 16 additions & 0 deletions
16
src/main/java/ai/labs/eddi/modules/templating/impl/dialects/uuid/UUIDDialect.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,16 @@ | ||
package ai.labs.eddi.modules.templating.impl.dialects.uuid; | ||
|
||
import org.thymeleaf.dialect.AbstractDialect; | ||
import org.thymeleaf.dialect.IExpressionObjectDialect; | ||
import org.thymeleaf.expression.IExpressionObjectFactory; | ||
|
||
public class UUIDDialect extends AbstractDialect implements IExpressionObjectDialect { | ||
public UUIDDialect() { | ||
super("UUIDDialect"); | ||
} | ||
|
||
@Override | ||
public IExpressionObjectFactory getExpressionObjectFactory() { | ||
return new UUIDExpressionObjectFactory(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../java/ai/labs/eddi/modules/templating/impl/dialects/uuid/UUIDExpressionObjectFactory.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,30 @@ | ||
package ai.labs.eddi.modules.templating.impl.dialects.uuid; | ||
|
||
import org.thymeleaf.context.IExpressionContext; | ||
import org.thymeleaf.expression.IExpressionObjectFactory; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class UUIDExpressionObjectFactory implements IExpressionObjectFactory { | ||
private static final String UUID_OBJECT_NAME = "uuidUtils"; | ||
|
||
@Override | ||
public Set<String> getAllExpressionObjectNames() { | ||
return Collections.singleton(UUID_OBJECT_NAME); | ||
} | ||
|
||
@Override | ||
public Object buildObject(IExpressionContext context, String expressionObjectName) { | ||
if (UUID_OBJECT_NAME.equals(expressionObjectName)) { | ||
return new UUIDWrapper(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isCacheable(String expressionObjectName) { | ||
return true; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/ai/labs/eddi/modules/templating/impl/dialects/uuid/UUIDWrapper.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,7 @@ | ||
package ai.labs.eddi.modules.templating.impl.dialects.uuid; | ||
|
||
public class UUIDWrapper { | ||
public String generateUUID() { | ||
return java.util.UUID.randomUUID().toString(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/java/ai/labs/eddi/modules/templating/impl/dialects/uuid/UUIDWrapperTest.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,12 @@ | ||
package ai.labs.eddi.modules.templating.impl.dialects.uuid; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class UUIDWrapperTest { | ||
@Test | ||
public void testGenerateUUID() { | ||
assertEquals(36, new UUIDWrapper().generateUUID().length()); | ||
} | ||
} |