Skip to content

Commit ed8b39a

Browse files
committed
✨ feat: add custom annotation #2
1 parent 91e0cb2 commit ed8b39a

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.clarify4j.common.annotation;
2+
3+
import org.clarify4j.config.validator.UrlValidator;
4+
5+
import javax.validation.Constraint;
6+
import javax.validation.Payload;
7+
import java.lang.annotation.*;
8+
9+
@Documented
10+
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.FIELD})
11+
@Retention(RetentionPolicy.RUNTIME)
12+
@Constraint(validatedBy = UrlValidator.class)
13+
public @interface IsUrl {
14+
String message() default "invalid URL";
15+
16+
Class<?>[] groups() default {};
17+
18+
Class<? extends Payload>[] payload() default {};
19+
}

plugin/src/main/groovy/org/clarify4j/config/handler/ExecutorSinceHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public Object execute(ProceedingJoinPoint joinPoint) throws Throwable {
2424
Signature signature = joinPoint.getSignature();
2525
String clazz = joinPoint.getTarget().getClass().getSimpleName();
2626
String method = signature.getName();
27-
logger.info("Execution of method '{}' in class '{}' completed in {}", method, clazz, since);
27+
logger.info("Clarify4j, execution of method '{}' in class '{}' completed in {}", method, clazz, since);
2828
return proceed;
2929
}
3030
}

plugin/src/main/groovy/org/clarify4j/config/handler/SagaHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void controller() {
2929
}
3030

3131
@Before(value = "controller()")
32-
public void handle(JoinPoint joinPoint) throws Throwable {
32+
public void execute(JoinPoint joinPoint) throws Throwable {
3333
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
3434
Method method = signature.getMethod();
3535
Saga saga = method.getAnnotation(Saga.class);
@@ -44,6 +44,6 @@ public void handle(JoinPoint joinPoint) throws Throwable {
4444
context.setVariable(parameters[i], args[i]);
4545
}
4646
String value = EXPRESSION_PARSER.parseExpression(saga.expression(), TEMPLATE_PARSER_CONTEXT).getValue(context, String.class);
47-
logger.info(value);
47+
logger.info(String.format("Clarify4j, %s", value));
4848
}
4949
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.clarify4j.config.validator;
2+
3+
import org.clarify4j.common.annotation.IsUrl;
4+
import org.unify4j.common.Regex4j;
5+
6+
import javax.validation.ConstraintValidator;
7+
import javax.validation.ConstraintValidatorContext;
8+
9+
public class UrlValidator implements ConstraintValidator<IsUrl, String> {
10+
11+
@Override
12+
public boolean isValid(String url, ConstraintValidatorContext context) {
13+
return Regex4j.isURL(url);
14+
}
15+
}

plugin/src/test/groovy/org/clarify4j/SagaAspectTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void testSaga() throws Throwable {
4343
when(methodSignature.getParameterNames()).thenReturn(new String[]{"userId", "newName"});
4444

4545
// Call the aspect method
46-
sagaHandler.handle(joinPoint);
46+
sagaHandler.execute(joinPoint);
4747

4848
// Verify that the logging occurred (you might mock the logging framework to assert this)
4949
// Here, we are just verifying that the method ran without exceptions

0 commit comments

Comments
 (0)