From a9cb101ff6a5fb70aae740f5116e8304eab52141 Mon Sep 17 00:00:00 2001 From: "Brian M. Long" Date: Thu, 12 Sep 2024 09:48:28 -0400 Subject: [PATCH 1/3] throw tx exception if NOT_SUPPORTED is used with an active tx --- .../annotations/aspect/RetryingTransactionAspect.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/inteligr8/alfresco/annotations/aspect/RetryingTransactionAspect.java b/src/main/java/com/inteligr8/alfresco/annotations/aspect/RetryingTransactionAspect.java index 2e83d92..820c0c9 100644 --- a/src/main/java/com/inteligr8/alfresco/annotations/aspect/RetryingTransactionAspect.java +++ b/src/main/java/com/inteligr8/alfresco/annotations/aspect/RetryingTransactionAspect.java @@ -136,8 +136,14 @@ public class RetryingTransactionAspect { if (txl.isReadOnly()) throw new IllegalTransactionStateException("A read/write transaction exists where a read-only one is mandatory"); } + case NOT_SUPPORTED: + switch (AlfrescoTransactionSupport.getTransactionReadState()) { + case TXN_NONE: + return false; + default: + throw new IllegalTransactionStateException("A transaction exists and pausing it is not supported"); + } case SUPPORTS: - //case NOT_SUPPORTED: not supported; we would have to create another thread to simulate return false; case REQUIRED: switch (AlfrescoTransactionSupport.getTransactionReadState()) { From 83397e35787e9dec8336caf2b98282ab91da0b51 Mon Sep 17 00:00:00 2001 From: "Brian M. Long" Date: Thu, 12 Sep 2024 10:19:09 -0400 Subject: [PATCH 2/3] add marshal support for date/time --- .../service/impl/MqAsyncService.java | 52 ++++++++++++++++--- .../alfresco/annotations/util/MapUtils.java | 32 ++++++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/inteligr8/alfresco/annotations/util/MapUtils.java 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 14f8fa4..b01ddba 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 @@ -9,6 +9,15 @@ import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.net.InetAddress; import java.net.UnknownHostException; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.Temporal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -478,8 +487,29 @@ public class MqAsyncService extends AbstractLifecycleBean implements AsyncServic private Object unmarshal(Parameter param, Object arg) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { Class paramType = param.getType(); this.logger.trace("Unmarshaling parameter of type: {}", paramType); - - if (Version.class.isAssignableFrom(paramType)) { + + if (arg instanceof String || arg instanceof Number || arg instanceof Boolean) { + this.logger.trace("Unmarshaling primitive: {}", arg); + return arg; + } else if (Temporal.class.isAssignableFrom(paramType)) { + if (OffsetDateTime.class.isAssignableFrom(paramType)) { + return OffsetDateTime.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(arg.toString())); + } else if (ZonedDateTime.class.isAssignableFrom(paramType)) { + return ZonedDateTime.from(DateTimeFormatter.ISO_ZONED_DATE_TIME.parse(arg.toString())); + } else if (LocalDate.class.isAssignableFrom(paramType)) { + return LocalDate.from(DateTimeFormatter.ISO_LOCAL_DATE.parse(arg.toString())); + } else if (LocalDateTime.class.isAssignableFrom(paramType)) { + return LocalDateTime.from(DateTimeFormatter.ISO_LOCAL_DATE_TIME.parse(arg.toString())); + } else if (Instant.class.isAssignableFrom(paramType)) { + return Instant.from(DateTimeFormatter.ISO_INSTANT.parse(arg.toString())); + } else if (LocalTime.class.isAssignableFrom(paramType)) { + return LocalTime.from(DateTimeFormatter.ISO_LOCAL_TIME.parse(arg.toString())); + } else if (OffsetTime.class.isAssignableFrom(paramType)) { + return OffsetTime.from(DateTimeFormatter.ISO_OFFSET_TIME.parse(arg.toString())); + } else { + throw new UnsupportedOperationException(); + } + } else if (Version.class.isAssignableFrom(paramType)) { this.logger.trace("Unmarshaling as JSON object: {}", arg); Map argMap = (Map) this.om.convertValue(arg, Map.class); @@ -515,13 +545,22 @@ public class MqAsyncService extends AbstractLifecycleBean implements AsyncServic return cons.invoke(null, arg.toString()); } else { this.logger.trace("Unmarshaling as POJO: {}", arg); - Constructor cons = paramType.getConstructor(String.class); - return cons.newInstance(arg.toString()); + try { + Constructor cons = paramType.getConstructor(String.class); + return cons.newInstance(arg.toString()); + } catch (NoSuchMethodException nsme) { + Method method = paramType.getDeclaredMethod("valueOf", String.class); + return method.invoke(null, arg.toString()); + } } } private Object marshal(Object arg) { - if (arg instanceof Version) { + if (arg instanceof String || arg instanceof Number || arg instanceof Boolean) { + return arg; + } else if (arg instanceof Temporal) { + return arg.toString(); + } else if (arg instanceof Version) { Version version = (Version) arg; Map map = new HashMap<>(); map.put("nodeRef", version.getFrozenStateNodeRef()); @@ -555,7 +594,8 @@ public class MqAsyncService extends AbstractLifecycleBean implements AsyncServic this.logger.trace("Marshaling Java Map as JSON object: {}", map); return this.om.convertValue(map, String.class); } else { - return arg; + this.logger.trace("Marshaling Java object as JSON object: {}", arg); + return this.om.convertValue(arg, String.class); } } diff --git a/src/main/java/com/inteligr8/alfresco/annotations/util/MapUtils.java b/src/main/java/com/inteligr8/alfresco/annotations/util/MapUtils.java new file mode 100644 index 0000000..7b82e01 --- /dev/null +++ b/src/main/java/com/inteligr8/alfresco/annotations/util/MapUtils.java @@ -0,0 +1,32 @@ +package com.inteligr8.alfresco.annotations.util; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.util.Pair; + +public class MapUtils { + + public static Map build(Pair... pairs) { + Map map = new HashMap<>(); + for (Pair pair : pairs) { + map.put(pair.getFirst(), pair.getSecond()); + } + + return map; + } + + public static Map build(String... keyValuePairs) { + if (keyValuePairs.length % 2 == 1) + throw new IllegalArgumentException(); + + Map map = new HashMap<>(); + for (int pair = 0; pair < keyValuePairs.length / 2; pair++) { + int base = pair * 2; + map.put(keyValuePairs[base], keyValuePairs[base + 1]); + } + + return map; + } + +} From bca4c40131a02d2e8244928e8dfbf87427895dd0 Mon Sep 17 00:00:00 2001 From: "Brian M. Long" Date: Thu, 12 Sep 2024 10:21:01 -0400 Subject: [PATCH 3/3] changed module path to support i18n messages --- .../alfresco-global.properties | 0 .../log4j.properties | 0 .../log4j2.properties | 0 .../module-context.xml | 0 .../module.properties | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename src/main/resources/alfresco/module/{com.inteligr8.alfresco.annotations-platform-module => com_inteligr8_alfresco_annotations-platform-module}/alfresco-global.properties (100%) rename src/main/resources/alfresco/module/{com.inteligr8.alfresco.annotations-platform-module => com_inteligr8_alfresco_annotations-platform-module}/log4j.properties (100%) rename src/main/resources/alfresco/module/{com.inteligr8.alfresco.annotations-platform-module => com_inteligr8_alfresco_annotations-platform-module}/log4j2.properties (100%) rename src/main/resources/alfresco/module/{com.inteligr8.alfresco.annotations-platform-module => com_inteligr8_alfresco_annotations-platform-module}/module-context.xml (100%) rename src/main/resources/alfresco/module/{com.inteligr8.alfresco.annotations-platform-module => com_inteligr8_alfresco_annotations-platform-module}/module.properties (100%) 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 similarity index 100% rename from src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/alfresco-global.properties rename to src/main/resources/alfresco/module/com_inteligr8_alfresco_annotations-platform-module/alfresco-global.properties diff --git a/src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/log4j.properties b/src/main/resources/alfresco/module/com_inteligr8_alfresco_annotations-platform-module/log4j.properties similarity index 100% rename from src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/log4j.properties rename to src/main/resources/alfresco/module/com_inteligr8_alfresco_annotations-platform-module/log4j.properties diff --git a/src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/log4j2.properties b/src/main/resources/alfresco/module/com_inteligr8_alfresco_annotations-platform-module/log4j2.properties similarity index 100% rename from src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/log4j2.properties rename to src/main/resources/alfresco/module/com_inteligr8_alfresco_annotations-platform-module/log4j2.properties diff --git a/src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/module-context.xml b/src/main/resources/alfresco/module/com_inteligr8_alfresco_annotations-platform-module/module-context.xml similarity index 100% rename from src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/module-context.xml rename to src/main/resources/alfresco/module/com_inteligr8_alfresco_annotations-platform-module/module-context.xml diff --git a/src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/module.properties b/src/main/resources/alfresco/module/com_inteligr8_alfresco_annotations-platform-module/module.properties similarity index 100% rename from src/main/resources/alfresco/module/com.inteligr8.alfresco.annotations-platform-module/module.properties rename to src/main/resources/alfresco/module/com_inteligr8_alfresco_annotations-platform-module/module.properties