From b116adeaa98147a20f2a19dca18fa8fda7de7eb2 Mon Sep 17 00:00:00 2001 From: "Brian M. Long" Date: Wed, 5 Apr 2023 16:19:44 -0400 Subject: [PATCH] added README; minor fixes --- README.md | 33 +++++++++++++++++++ .../alfresco/annotations/BehaviorBean.java | 16 --------- .../service/impl/MqAsyncService.java | 6 ++++ .../alfresco-global.properties | 1 + 4 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 README.md delete mode 100644 src/main/java/com/inteligr8/alfresco/annotations/BehaviorBean.java diff --git a/README.md b/README.md new file mode 100644 index 0000000..bbd5626 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ + +# Generic Annotations Module for Alfresco Content Services + +This module provides several annotations that help a developer create modules for Alfresco Content Services. + +## Design + +### AspectJ + +This module relies on AspectJ. It uses it so that code can be wrapped around methods and parameters where annotations are used. This is known as the Aspect-Oriented Programming (AOP) model. The inclusion of AspectJ in ACS is not trivial, but it is mostly handled by the [`aspectj-platform-module`](https://bitbucket.org/inteligr8/aspectj-platform-module) project. See that project for details. + +> When including the `aspectj-platform-module` AMP, remember to add the `-javaagent:...` argument in the JEE web container. + +### Annotations + +| Annotation | Purpose | +| ------------------------- | ------- | +| `@Authorized` | Wraps the method in the Alfresco API `AuthenticationUtil.runAs()`. It only does this if the authorized user should be changed. Use the annotation `value` field or the `Authorizable` interface. Using neither will authorize the non-authorized as the system user. | +| `@AuthorizedAsSystem` | Wraps the method in the Alfresco API `AuthenticationUtil.runAsSystem()`. It only does this if the authorized user is not already the system user. | +| `@Transactional` | Wraps the method in the Alfresco API `RetryingTransactionHelper.doInTransaction()`. It only does this per the normal expectation of `@Transactional`. This is the *Spring Framework* annotation being made usable by this library. | +| `@TransactionalRetryable` | If `@Transactional` deems a new transaction is needed, this allows for the overridding of retrying parameters. Without this annotation, all transactions are still retried with default parameters. | +| `@Asynchronous` | Redirects calls to the method to put a message in MQ for asynchronous queuing and execution. The message is then discovered by this or another clustered instance and executed asynchronously in a separate transaction. | +| `@IfNodeExists` | Skips the method if a node parameter does not exist. This includes child, source, and target nodes of associations, but not parent nodes. This may be applied to specific parameters or the whole method (all node parameters). | +| `@IfNodeOfType` | Skips the method if a node parameter is not of the configured type. This includes child, source, and target nodes of associations, but not parent nodes. This may be applied to specific parameters or the whole method (all node parameters). Use the annotation `type` field or the `NodeTypeConstrainable` interface. | +| `@IfNodeHasAspect` | Skips the method if a node parameter does not have the configured aspect. This includes child, source, and target nodes of associations, but not parent nodes. This may be applied to specific parameters or the whole method (all node parameters). Use the annotation `aspect` field or the `NodeAspectConstrainable` interface. | +| `@IfChildAssociationIsPrimary` | Skips the method if a child association parameter is not considered *primary*. This may be applied to specific parameters or the whole method (all node parameters). | + +## Install + +Install this as any other ACS Platform module. It is of the JAR type, so it just needs to be in the same classpath as the application. + +In addition, make sure to follow the instructions for installing `aspectj-platform-module`, specifically the `javaagent` argument. + diff --git a/src/main/java/com/inteligr8/alfresco/annotations/BehaviorBean.java b/src/main/java/com/inteligr8/alfresco/annotations/BehaviorBean.java deleted file mode 100644 index 1169a9b..0000000 --- a/src/main/java/com/inteligr8/alfresco/annotations/BehaviorBean.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.inteligr8.alfresco.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface BehaviorBean { - - String defaultType() default "sys:base"; - - String defaultAssocType() default ""; - -} diff --git a/src/main/java/com/inteligr8/alfresco/annotations/service/impl/MqAsyncService.java b/src/main/java/com/inteligr8/alfresco/annotations/service/impl/MqAsyncService.java index 25e667c..d576374 100644 --- a/src/main/java/com/inteligr8/alfresco/annotations/service/impl/MqAsyncService.java +++ b/src/main/java/com/inteligr8/alfresco/annotations/service/impl/MqAsyncService.java @@ -88,6 +88,9 @@ public class MqAsyncService extends AbstractLifecycleBean implements AsyncServic @Value("${inteligr8.async.mq.enabled}") protected boolean enabled; + @Value("${inteligr8.async.mq.worker}") + protected boolean workerEnabled; + @Value("${inteligr8.async.mq.url:#{null}}") protected String url; @@ -152,6 +155,9 @@ public class MqAsyncService extends AbstractLifecycleBean implements AsyncServic pool.start(); this.factory = pool; + + if (!this.workerEnabled) + return; JobKey jobKey = new JobKey("behaviour-async", "inteligr8-annotations"); diff --git a/src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/alfresco-global.properties b/src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/alfresco-global.properties index e1bcec9..2dcd89c 100644 --- a/src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/alfresco-global.properties +++ b/src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/alfresco-global.properties @@ -2,6 +2,7 @@ inteligr8.annotations.aspectj.scanPackages=com.inteligr8.alfresco.annotations inteligr8.async.mq.enabled=false +inteligr8.async.mq.worker=true inteligr8.async.mq.url=${messaging.broker.url} inteligr8.async.mq.username=${messaging.broker.username} inteligr8.async.mq.password=${messaging.broker.password}