This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch camel-3.21.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.21.x by this push:
new 38e5226af75 chore: backport fixes and other changes from camel-3.x
branch (#11901)
38e5226af75 is described below
commit 38e5226af7587d394f3590672f6ad862f6844b14
Author: Claude Mamo <[email protected]>
AuthorDate: Fri Nov 3 14:54:19 2023 +0100
chore: backport fixes and other changes from camel-3.x branch (#11901)
---
.../apache/camel/component/dhis2/api/Dhis2Get.java | 22 +--
.../camel/component/dhis2/api/Dhis2Resource.java | 22 +++
.../component/dhis2/api/Dhis2GetTestCase.java | 66 +++++--
.../camel-dhis2/camel-dhis2-component/pom.xml | 1 -
.../component/dhis2/Dhis2ConvertersLoader.java | 51 ++++++
.../component/dhis2/Dhis2EndpointUriFactory.java | 2 +-
.../dhis2/Dhis2GetEndpointConfiguration.java | 24 +--
.../Dhis2GetEndpointConfigurationConfigurer.java | 14 +-
.../dhis2/internal/Dhis2ApiCollection.java | 2 +-
.../dhis2/internal/Dhis2GetApiMethod.java | 2 +-
.../services/org/apache/camel/TypeConverterLoader | 2 +
.../org/apache/camel/component/dhis2/dhis2.json | 4 +-
.../src/main/docs/dhis2-component.adoc | 192 +++------------------
.../camel/component/dhis2/Dhis2Converters.java | 41 +++++
.../camel/component/dhis2/Dhis2DeleteIT.java | 2 +-
.../apache/camel/component/dhis2/Dhis2GetIT.java | 39 ++---
.../apache/camel/component/dhis2/Dhis2PostIT.java | 2 +-
.../apache/camel/component/dhis2/Dhis2PutIT.java | 9 +-
.../component/dhis2/Dhis2ResourceTablesIT.java | 5 +-
.../apache/camel/component/dhis2/Environment.java | 11 +-
components/camel-dhis2/pom.xml | 2 +-
21 files changed, 250 insertions(+), 265 deletions(-)
diff --git
a/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Get.java
b/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Get.java
index fcefb54a9eb..6103359c71f 100644
---
a/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Get.java
+++
b/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Get.java
@@ -75,32 +75,20 @@ public class Dhis2Get {
return getOperation;
}
- public <T> Iterator<T> collection(
- String path, String itemType, Boolean paging, String fields,
String filter, RootJunctionEnum rootJunction,
+ public Iterator<Dhis2Resource> collection(
+ String path, String arrayName, Boolean paging, String fields,
String filter,
+ RootJunctionEnum rootJunction,
Map<String, Object> queryParams) {
GetOperation getOperation = newGetOperation(path, fields, filter,
rootJunction, queryParams);
- Iterable<T> iterable;
IterableDhis2Response iteratorDhis2Response;
- if (paging == null || paging) {
+ if (paging != null && paging) {
iteratorDhis2Response = getOperation.withPaging().transfer();
} else {
iteratorDhis2Response = getOperation.withoutPaging().transfer();
}
- if (itemType == null) {
- iterable = (Iterable<T>) iteratorDhis2Response
- .returnAs(Map.class, path);
- } else {
- try {
- iterable = (Iterable<T>) iteratorDhis2Response
- .returnAs(Class.forName(itemType), path);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
-
- return iterable.iterator();
+ return iteratorDhis2Response.returnAs(Dhis2Resource.class,
arrayName).iterator();
}
}
diff --git
a/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Resource.java
b/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Resource.java
new file mode 100644
index 00000000000..3ea72de30c7
--- /dev/null
+++
b/components/camel-dhis2/camel-dhis2-api/src/main/java/org/apache/camel/component/dhis2/api/Dhis2Resource.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dhis2.api;
+
+import java.util.HashMap;
+
+public class Dhis2Resource extends HashMap<String, Object> {
+}
diff --git
a/components/camel-dhis2/camel-dhis2-api/src/test/java/org/apache/camel/component/dhis2/api/Dhis2GetTestCase.java
b/components/camel-dhis2/camel-dhis2-api/src/test/java/org/apache/camel/component/dhis2/api/Dhis2GetTestCase.java
index 325a4f692ec..9cb958021bf 100644
---
a/components/camel-dhis2/camel-dhis2-api/src/test/java/org/apache/camel/component/dhis2/api/Dhis2GetTestCase.java
+++
b/components/camel-dhis2/camel-dhis2-api/src/test/java/org/apache/camel/component/dhis2/api/Dhis2GetTestCase.java
@@ -28,6 +28,7 @@ import org.hisp.dhis.integration.sdk.api.Dhis2Client;
import org.hisp.dhis.integration.sdk.api.Dhis2Response;
import org.hisp.dhis.integration.sdk.api.operation.GetOperation;
import
org.hisp.dhis.integration.sdk.internal.converter.JacksonConverterFactory;
+import
org.hisp.dhis.integration.sdk.internal.operation.DefaultSimpleCollectOperation;
import
org.hisp.dhis.integration.sdk.internal.operation.page.DefaultPagingCollectOperation;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -72,6 +73,7 @@ public class Dhis2GetTestCase {
}
};
+ when(getOperation.withParameter(any(),
any())).thenReturn(getOperation);
when(getOperation.transfer()).thenReturn(dhis2Response);
Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
dhis2Get.resource(null, null, null, null, Map.of("foo",
List.of("bar")));
@@ -96,6 +98,7 @@ public class Dhis2GetTestCase {
}
};
+ when(getOperation.withParameter(any(),
any())).thenReturn(getOperation);
when(getOperation.transfer()).thenReturn(dhis2Response);
Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
dhis2Get.resource(null, null, null, null, Map.of("foo", "bar"));
@@ -153,11 +156,7 @@ public class Dhis2GetTestCase {
}
@Test
- public void testCollectionGivenMapOfStringsQueryParams() {
- DefaultPagingCollectOperation defaultPagingCollectOperation = new
DefaultPagingCollectOperation(
- "https://play.dhis2.org/2.39.0.1", "", null, new
JacksonConverterFactory(),
- getOperation);
-
+ public void testCollectionGivenPagingIsTrue() {
Dhis2Response dhis2Response = new Dhis2Response() {
@Override
public <T> T returnAs(Class<T> responseType) {
@@ -178,25 +177,55 @@ public class Dhis2GetTestCase {
}
};
+ when(getOperation.withParameter(any(),
any())).thenReturn(getOperation);
+ when(getOperation.withParameter(any(),
any())).thenReturn(getOperation);
when(getOperation.transfer()).thenReturn(dhis2Response);
when(getOperation.withPaging()).thenReturn(
new DefaultPagingCollectOperation(
"https://play.dhis2.org/2.39.0.1", "", null, new
JacksonConverterFactory(), getOperation));
Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
- dhis2Get.collection("bunnies", null, null, null, null, null,
Map.of("foo", "bar"));
+ dhis2Get.collection("bunnies", "bunnies", true, null, null, null,
Map.of("foo", "bar"));
verify(getOperation, times(1)).withParameter("foo", "bar");
}
@Test
- public void testCollectionGivenOrRootJunction() {
+ public void testCollectionGivenMapOfStringsQueryParams() {
Dhis2Response dhis2Response = new Dhis2Response() {
@Override
public <T> T returnAs(Class<T> responseType) {
- Page page = new Page();
- page.setAdditionalProperty("bunnies", new ArrayList<>());
+ return (T) Map.of("bunnies", new ArrayList<>());
+ }
- return (T) page;
+ @Override
+ public InputStream read() {
+ return new ByteArrayInputStream(new byte[] {});
+ }
+
+ @Override
+ public void close()
+ throws IOException {
+
+ }
+ };
+ when(getOperation.withParameter(any(),
any())).thenReturn(getOperation);
+ when(getOperation.withParameter(any(),
any())).thenReturn(getOperation);
+ when(getOperation.transfer()).thenReturn(dhis2Response);
+ when(getOperation.withoutPaging()).thenReturn(
+ new DefaultSimpleCollectOperation(
+ "https://play.dhis2.org/2.39.0.1", "", null, new
JacksonConverterFactory(), getOperation));
+
+ Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
+ dhis2Get.collection("bunnies", "bunnies", null, null, null, null,
Map.of("foo", "bar"));
+ verify(getOperation, times(1)).withParameter("foo", "bar");
+ }
+
+ @Test
+ public void testCollectionGivenOrRootJunction() {
+ Dhis2Response dhis2Response = new Dhis2Response() {
+ @Override
+ public <T> T returnAs(Class<T> responseType) {
+ return (T) Map.of("bunnies", new ArrayList<>());
}
@Override
@@ -209,14 +238,15 @@ public class Dhis2GetTestCase {
}
};
+ when(getOperation.withParameter(any(),
any())).thenReturn(getOperation);
when(getOperation.transfer()).thenReturn(dhis2Response);
- when(getOperation.withPaging()).thenReturn(
- new DefaultPagingCollectOperation(
+ when(getOperation.withoutPaging()).thenReturn(
+ new DefaultSimpleCollectOperation(
"https://play.dhis2.org/2.39.0.1", "", null,
new JacksonConverterFactory(), getOperation));
Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
- dhis2Get.collection("bunnies", null, null, null, null,
RootJunctionEnum.OR, null);
+ dhis2Get.collection("bunnies", "bunnies", null, null, null,
RootJunctionEnum.OR, null);
verify(getOperation, times(1)).withOrRootJunction();
}
@@ -225,10 +255,7 @@ public class Dhis2GetTestCase {
Dhis2Response dhis2Response = new Dhis2Response() {
@Override
public <T> T returnAs(Class<T> responseType) {
- Page page = new Page();
- page.setAdditionalProperty("bunnies", new ArrayList<>());
-
- return (T) page;
+ return (T) Map.of("bunnies", new ArrayList<>());
}
@Override
@@ -241,12 +268,13 @@ public class Dhis2GetTestCase {
}
};
+ when(getOperation.withParameter(any(),
any())).thenReturn(getOperation);
when(getOperation.transfer()).thenReturn(dhis2Response);
- when(getOperation.withPaging()).thenReturn(new
DefaultPagingCollectOperation(
+ when(getOperation.withoutPaging()).thenReturn(new
DefaultSimpleCollectOperation(
"https://play.dhis2.org/2.39.0.1", "", null, new
JacksonConverterFactory(), getOperation));
Dhis2Get dhis2Get = new Dhis2Get(dhis2Client);
- dhis2Get.collection("bunnies", null, null, null, null,
RootJunctionEnum.AND, null);
+ dhis2Get.collection("bunnies", "bunnies", null, null, null,
RootJunctionEnum.AND, null);
verify(getOperation, times(1)).withAndRootJunction();
}
}
diff --git a/components/camel-dhis2/camel-dhis2-component/pom.xml
b/components/camel-dhis2/camel-dhis2-component/pom.xml
index c151f45a5fb..2b38337267c 100644
--- a/components/camel-dhis2/camel-dhis2-component/pom.xml
+++ b/components/camel-dhis2/camel-dhis2-component/pom.xml
@@ -110,7 +110,6 @@
<proxyClass>org.apache.camel.component.dhis2.api.Dhis2Get</proxyClass>
<fromJavasource />
<nullableOptions>
-
<nullableOption>itemType</nullableOption>
<nullableOption>paging</nullableOption>
<nullableOption>fields</nullableOption>
<nullableOption>filter</nullableOption>
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2ConvertersLoader.java
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2ConvertersLoader.java
new file mode 100644
index 00000000000..c8b67855fa6
--- /dev/null
+++
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2ConvertersLoader.java
@@ -0,0 +1,51 @@
+/* Generated by camel build tools - do NOT edit this file! */
+package org.apache.camel.component.dhis2;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.DeferredContextBinding;
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConversionException;
+import org.apache.camel.TypeConverterLoaderException;
+import org.apache.camel.spi.TypeConverterLoader;
+import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.support.SimpleTypeConverter;
+import org.apache.camel.support.TypeConverterSupport;
+import org.apache.camel.util.DoubleMap;
+
+/**
+ * Generated by camel build tools - do NOT edit this file!
+ */
+@SuppressWarnings("unchecked")
+@DeferredContextBinding
+public final class Dhis2ConvertersLoader implements TypeConverterLoader,
CamelContextAware {
+
+ private CamelContext camelContext;
+
+ public Dhis2ConvertersLoader() {
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void load(TypeConverterRegistry registry) throws
TypeConverterLoaderException {
+ registerFallbackConverters(registry);
+ }
+
+ private void registerFallbackConverters(TypeConverterRegistry registry) {
+ addFallbackTypeConverter(registry, false, false, (type, exchange,
value) -> org.apache.camel.component.dhis2.Dhis2Converters.convertTo(type,
exchange, value, registry));
+ }
+
+ private static void addFallbackTypeConverter(TypeConverterRegistry
registry, boolean allowNull, boolean canPromote,
SimpleTypeConverter.ConversionMethod method) {
+ registry.addFallbackTypeConverter(new SimpleTypeConverter(allowNull,
method), canPromote);
+ }
+
+}
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2EndpointUriFactory.java
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2EndpointUriFactory.java
index 4a7b44074cd..5f91905e363 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2EndpointUriFactory.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2EndpointUriFactory.java
@@ -23,6 +23,7 @@ public class Dhis2EndpointUriFactory extends
org.apache.camel.support.component.
static {
Set<String> props = new HashSet<>(39);
props.add("apiName");
+ props.add("arrayName");
props.add("backoffErrorThreshold");
props.add("backoffIdleThreshold");
props.add("backoffMultiplier");
@@ -38,7 +39,6 @@ public class Dhis2EndpointUriFactory extends
org.apache.camel.support.component.
props.add("inBody");
props.add("initialDelay");
props.add("interval");
- props.add("itemType");
props.add("lastYears");
props.add("lazyStartProducer");
props.add("methodName");
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfiguration.java
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfiguration.java
index 9ec1227a69f..7e2e9db6900 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfiguration.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfiguration.java
@@ -16,10 +16,13 @@ import org.apache.camel.spi.UriParams;
*/
@ApiParams(apiName = "get",
description = "",
- apiMethods = {@ApiMethod(methodName = "collection",
signatures={"java.util.Iterator collection(String path, String itemType,
Boolean paging, String fields, String filter,
org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction,
java.util.Map<String, Object> queryParams)"}), @ApiMethod(methodName =
"resource", signatures={"java.io.InputStream resource(String path, String
fields, String filter, org.apache.camel.component.dhis2.api.RootJunctionEnum
rootJunction, java.u [...]
+ apiMethods = {@ApiMethod(methodName = "collection",
signatures={"java.util.Iterator<org.apache.camel.component.dhis2.api.Dhis2Resource>
collection(String path, String arrayName, Boolean paging, String fields,
String filter, org.apache.camel.component.dhis2.api.RootJunctionEnum
rootJunction, java.util.Map<String, Object> queryParams)"}),
@ApiMethod(methodName = "resource", signatures={"java.io.InputStream
resource(String path, String fields, String filter, org.apache.camel.comp [...]
@UriParams
@Configurer(extended = true)
public final class Dhis2GetEndpointConfiguration extends Dhis2Configuration {
+ @UriParam
+ @ApiParam(optional = false, apiMethods = {@ApiMethod(methodName =
"collection")})
+ private String arrayName;
@UriParam
@ApiParam(optional = true, apiMethods = {@ApiMethod(methodName =
"collection"), @ApiMethod(methodName = "resource")})
private String fields;
@@ -28,9 +31,6 @@ public final class Dhis2GetEndpointConfiguration extends
Dhis2Configuration {
private String filter;
@UriParam
@ApiParam(optional = true, apiMethods = {@ApiMethod(methodName =
"collection")})
- private String itemType;
- @UriParam
- @ApiParam(optional = true, apiMethods = {@ApiMethod(methodName =
"collection")})
private Boolean paging;
@UriParam
@ApiParam(optional = false, apiMethods = {@ApiMethod(methodName =
"collection"), @ApiMethod(methodName = "resource")})
@@ -42,6 +42,14 @@ public final class Dhis2GetEndpointConfiguration extends
Dhis2Configuration {
@ApiParam(optional = true, apiMethods = {@ApiMethod(methodName =
"collection"), @ApiMethod(methodName = "resource")})
private org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction;
+ public String getArrayName() {
+ return arrayName;
+ }
+
+ public void setArrayName(String arrayName) {
+ this.arrayName = arrayName;
+ }
+
public String getFields() {
return fields;
}
@@ -58,14 +66,6 @@ public final class Dhis2GetEndpointConfiguration extends
Dhis2Configuration {
this.filter = filter;
}
- public String getItemType() {
- return itemType;
- }
-
- public void setItemType(String itemType) {
- this.itemType = itemType;
- }
-
public Boolean getPaging() {
return paging;
}
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfigurationConfigurer.java
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfigurationConfigurer.java
index d68646f3074..e11ca4c17b4 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfigurationConfigurer.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/Dhis2GetEndpointConfigurationConfigurer.java
@@ -21,11 +21,11 @@ public class Dhis2GetEndpointConfigurationConfigurer
extends org.apache.camel.su
static {
Map<String, Object> map = new CaseInsensitiveMap();
map.put("ApiName",
org.apache.camel.component.dhis2.internal.Dhis2ApiName.class);
+ map.put("ArrayName", java.lang.String.class);
map.put("BaseApiUrl", java.lang.String.class);
map.put("Client", org.hisp.dhis.integration.sdk.api.Dhis2Client.class);
map.put("Fields", java.lang.String.class);
map.put("Filter", java.lang.String.class);
- map.put("ItemType", java.lang.String.class);
map.put("MethodName", java.lang.String.class);
map.put("Paging", java.lang.Boolean.class);
map.put("Password", java.lang.String.class);
@@ -42,6 +42,8 @@ public class Dhis2GetEndpointConfigurationConfigurer extends
org.apache.camel.su
switch (ignoreCase ? name.toLowerCase() : name) {
case "apiname":
case "ApiName": target.setApiName(property(camelContext,
org.apache.camel.component.dhis2.internal.Dhis2ApiName.class, value)); return
true;
+ case "arrayname":
+ case "ArrayName": target.setArrayName(property(camelContext,
java.lang.String.class, value)); return true;
case "baseapiurl":
case "BaseApiUrl": target.setBaseApiUrl(property(camelContext,
java.lang.String.class, value)); return true;
case "client":
@@ -50,8 +52,6 @@ public class Dhis2GetEndpointConfigurationConfigurer extends
org.apache.camel.su
case "Fields": target.setFields(property(camelContext,
java.lang.String.class, value)); return true;
case "filter":
case "Filter": target.setFilter(property(camelContext,
java.lang.String.class, value)); return true;
- case "itemtype":
- case "ItemType": target.setItemType(property(camelContext,
java.lang.String.class, value)); return true;
case "methodname":
case "MethodName": target.setMethodName(property(camelContext,
java.lang.String.class, value)); return true;
case "paging":
@@ -80,6 +80,8 @@ public class Dhis2GetEndpointConfigurationConfigurer extends
org.apache.camel.su
switch (ignoreCase ? name.toLowerCase() : name) {
case "apiname":
case "ApiName": return
org.apache.camel.component.dhis2.internal.Dhis2ApiName.class;
+ case "arrayname":
+ case "ArrayName": return java.lang.String.class;
case "baseapiurl":
case "BaseApiUrl": return java.lang.String.class;
case "client":
@@ -88,8 +90,6 @@ public class Dhis2GetEndpointConfigurationConfigurer extends
org.apache.camel.su
case "Fields": return java.lang.String.class;
case "filter":
case "Filter": return java.lang.String.class;
- case "itemtype":
- case "ItemType": return java.lang.String.class;
case "methodname":
case "MethodName": return java.lang.String.class;
case "paging":
@@ -114,6 +114,8 @@ public class Dhis2GetEndpointConfigurationConfigurer
extends org.apache.camel.su
switch (ignoreCase ? name.toLowerCase() : name) {
case "apiname":
case "ApiName": return target.getApiName();
+ case "arrayname":
+ case "ArrayName": return target.getArrayName();
case "baseapiurl":
case "BaseApiUrl": return target.getBaseApiUrl();
case "client":
@@ -122,8 +124,6 @@ public class Dhis2GetEndpointConfigurationConfigurer
extends org.apache.camel.su
case "Fields": return target.getFields();
case "filter":
case "Filter": return target.getFilter();
- case "itemtype":
- case "ItemType": return target.getItemType();
case "methodname":
case "MethodName": return target.getMethodName();
case "paging":
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2ApiCollection.java
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2ApiCollection.java
index bf703853d72..9354860c8d8 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2ApiCollection.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2ApiCollection.java
@@ -46,7 +46,7 @@ public final class Dhis2ApiCollection extends
ApiCollection<Dhis2ApiName, Dhis2C
apiMethods.put(Dhis2ResourceTablesApiMethod.class,
Dhis2ApiName.RESOURCE_TABLES);
aliases.clear();
- nullableArgs = Arrays.asList("itemType", "paging", "fields", "filter",
"rootJunction", "queryParams");
+ nullableArgs = Arrays.asList("paging", "fields", "filter",
"rootJunction", "queryParams");
apiHelpers.put(Dhis2ApiName.GET, new
ApiMethodHelper<Dhis2GetApiMethod>(Dhis2GetApiMethod.class, aliases,
nullableArgs));
apiMethods.put(Dhis2GetApiMethod.class, Dhis2ApiName.GET);
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2GetApiMethod.java
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2GetApiMethod.java
index 66cca60bd5c..eee822d4272 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2GetApiMethod.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/generated/java/org/apache/camel/component/dhis2/internal/Dhis2GetApiMethod.java
@@ -24,7 +24,7 @@ public enum Dhis2GetApiMethod implements ApiMethod {
java.util.Iterator.class,
"collection",
arg("path", String.class),
- arg("itemType", String.class),
+ arg("arrayName", String.class),
arg("paging", Boolean.class),
arg("fields", String.class),
arg("filter", String.class),
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
b/components/camel-dhis2/camel-dhis2-component/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
new file mode 100644
index 00000000000..c5620f6c98c
--- /dev/null
+++
b/components/camel-dhis2/camel-dhis2-component/src/generated/resources/META-INF/services/org/apache/camel/TypeConverterLoader
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+org.apache.camel.component.dhis2.Dhis2ConvertersLoader
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/generated/resources/org/apache/camel/component/dhis2/dhis2.json
b/components/camel-dhis2/camel-dhis2-component/src/generated/resources/org/apache/camel/component/dhis2/dhis2.json
index 3f9cb998851..6f7832160ea 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/generated/resources/org/apache/camel/component/dhis2/dhis2.json
+++
b/components/camel-dhis2/camel-dhis2-component/src/generated/resources/org/apache/camel/component/dhis2/dhis2.json
@@ -63,14 +63,14 @@
},
"apis": {
"delete": { "consumerOnly": false, "producerOnly": false, "description":
"", "methods": { "resource": { "description": "", "signatures": [
"java.io.InputStream resource(String path, Object resource,
java.util.Map<String, Object> queryParams)" ] } } },
- "get": { "consumerOnly": false, "producerOnly": false, "description": "",
"methods": { "collection": { "description": "", "signatures": [
"java.util.Iterator collection(String path, String itemType, Boolean paging,
String fields, String filter,
org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction,
java.util.Map<String, Object> queryParams)" ] }, "resource": { "description":
"", "signatures": [ "java.io.InputStream resource(String path, String fields,
String filter, org. [...]
+ "get": { "consumerOnly": false, "producerOnly": false, "description": "",
"methods": { "collection": { "description": "", "signatures": [
"java.util.Iterator<org.apache.camel.component.dhis2.api.Dhis2Resource>
collection(String path, String arrayName, Boolean paging, String fields, String
filter, org.apache.camel.component.dhis2.api.RootJunctionEnum rootJunction,
java.util.Map<String, Object> queryParams)" ] }, "resource": { "description":
"", "signatures": [ "java.io.InputStream res [...]
"post": { "consumerOnly": false, "producerOnly": false, "description": "",
"methods": { "resource": { "description": "", "signatures": [
"java.io.InputStream resource(String path, Object resource,
java.util.Map<String, Object> queryParams)" ] } } },
"put": { "consumerOnly": false, "producerOnly": false, "description": "",
"methods": { "resource": { "description": "", "signatures": [
"java.io.InputStream resource(String path, Object resource,
java.util.Map<String, Object> queryParams)" ] } } },
"resourceTables": { "consumerOnly": false, "producerOnly": false,
"description": "", "methods": { "analytics": { "description": "", "signatures":
[ "void analytics(Boolean skipAggregate, Boolean skipEvents, Integer lastYears,
Integer interval)" ] } } }
},
"apiProperties": {
"delete": { "methods": { "resource": { "properties": { "path": { "kind":
"parameter", "displayName": "Path", "group": "common", "label": "", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "", "optional": false },
"queryParams": { "kind": "parameter", "displayName": "Query Params", "group":
"common", "label": "", "required": false, "type": "object", "javaType":
"java.util.Map<java.lang.Strin [...]
- "get": { "methods": { "collection": { "properties": { "fields": { "kind":
"parameter", "displayName": "Fields", "group": "common", "label": "",
"required": false, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description": "",
"optional": true }, "filter": { "kind": "parameter", "displayName": "Filter",
"group": "common", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated": false [...]
+ "get": { "methods": { "collection": { "properties": { "arrayName": {
"kind": "parameter", "displayName": "Array Name", "group": "common", "label":
"", "required": false, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description": "",
"optional": false }, "fields": { "kind": "parameter", "displayName": "Fields",
"group": "common", "label": "", "required": false, "type": "string",
"javaType": "java.lang.String", "deprecated [...]
"post": { "methods": { "resource": { "properties": { "path": { "kind":
"parameter", "displayName": "Path", "group": "common", "label": "", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "", "optional": false },
"queryParams": { "kind": "parameter", "displayName": "Query Params", "group":
"common", "label": "", "required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, [...]
"put": { "methods": { "resource": { "properties": { "path": { "kind":
"parameter", "displayName": "Path", "group": "common", "label": "", "required":
false, "type": "string", "javaType": "java.lang.String", "deprecated": false,
"autowired": false, "secret": false, "description": "", "optional": false },
"queryParams": { "kind": "parameter", "displayName": "Query Params", "group":
"common", "label": "", "required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, [...]
"resourceTables": { "methods": { "analytics": { "properties": {
"interval": { "kind": "parameter", "displayName": "Interval", "group":
"common", "label": "", "required": false, "type": "integer", "javaType":
"java.lang.Integer", "deprecated": false, "autowired": false, "secret": false,
"description": "", "optional": true }, "lastYears": { "kind": "parameter",
"displayName": "Last Years", "group": "common", "label": "", "required": false,
"type": "integer", "javaType": "java.lang.Inte [...]
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/main/docs/dhis2-component.adoc
b/components/camel-dhis2/camel-dhis2-component/src/main/docs/dhis2-component.adoc
index d02c0bd4e06..b55d85aec1c 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/main/docs/dhis2-component.adoc
+++
b/components/camel-dhis2/camel-dhis2-component/src/main/docs/dhis2-component.adoc
@@ -47,7 +47,7 @@ include::partial$component-endpoint-options.adoc[]
== Examples
* Fetch an organisation unit by ID:
-
++
[source,java]
----
package org.camel.dhis2.example;
@@ -68,7 +68,7 @@ public class MyRouteBuilder extends RouteBuilder {
----
* Fetch an organisation unit code by ID:
-
++
[source,java]
----
package org.camel.dhis2.example;
@@ -87,29 +87,8 @@ public class MyRouteBuilder extends RouteBuilder {
}
----
-== METHOD collection
-
-Signatures:
-
-* java.util.Iterator collection(java.lang.String path, java.lang.String
itemType, java.lang.Boolean paging, java.lang.String fields, java.lang.String
filter, java.util.Map<String, Object> queryParams)
-
-The get/collection API method has the parameters listed in the table below:
-
-[width="100%",cols="17%,72%,11%",options="header",]
-|===
-| Parameter | Description | Type
-| path | Resource URL path | String
-| itemType | Fully-qualified Java class name to deserialise items into| String
-| paging | Turn paging on/off | Boolean
-| fields | Comma-delimited list of fields to fetch | String
-| filter | Search criteria | String
-| queryParams |Custom query parameters | Map
-|===
-
-Any of the parameters can be provided in either the endpoint URI, or
dynamically in a message header. The message header name must be of the format
CamelDhis2.parameter. The inBody parameter overrides message header, i.e. the
endpoint parameter inBody=myParameterNameHere would override a
CamelDhis2.myParameterNameHere header.
-
* Fetch all organisation units:
-
++
[source,java]
----
package org.camel.dhis2.example;
@@ -120,14 +99,15 @@ public class MyRouteBuilder extends RouteBuilder {
public void configure() {
from("direct:getCollection")
-
.to("dhis2://get/collection?path=organisationUnits&itemType=org.hisp.dhis.api.model.v2_39_1.OrganisationUnit&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
- .split().body().log("${body}");
+
.to("dhis2://get/collection?path=organisationUnits&arrayName=organisationUnits&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
+ .split().body()
+
.convertBody(org.hisp.dhis.api.model.v2_39_1.OrganisationUnit.class).log("${body}");
}
}
----
* Fetch all organisation unit codes:
-
++
[source,java]
----
package org.camel.dhis2.example;
@@ -138,14 +118,16 @@ public class MyRouteBuilder extends RouteBuilder {
public void configure() {
from("direct:getCollection")
-
.to("dhis2://get/collection?path=organisationUnits&fields=code&itemType=org.hisp.dhis.api.model.v2_39_1.OrganisationUnit&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
- .split().body().log("${body}");
+
.to("dhis2://get/collection?path=organisationUnits&fields=code&arrayName=organisationUnits&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
+ .split().body()
+
.convertBody(org.hisp.dhis.api.model.v2_39_1.OrganisationUnit.class)
+ .log("${body}");
}
}
----
* Fetch users with a phone number:
-
++
[source,java]
----
package org.camel.dhis2.example;
@@ -156,45 +138,16 @@ public class MyRouteBuilder extends RouteBuilder {
public void configure() {
from("direct:getCollection")
-
.to("dhis2://get/collection?path=users&filter=phoneNumber:!null:&itemType=org.hisp.dhis.api.model.v2_39_1.User&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
- .split().body().log("${body}");
+
.to("dhis2://get/collection?path=users&filter=phoneNumber:!null:&arrayName=users&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
+ .split().body()
+ .convertBody(org.hisp.dhis.api.model.v2_39_1.User.class)
+ .log("${body}");
}
}
----
-== API: post
-
-*Both producer and consumer are supported*
-
-The post API is defined in the syntax as follows:
-
-....
-dhis2:post/methodName?[parameters]
-....
-
-== METHOD resource
-
-Signatures:
-
-* java.io.InputStream resource(java.lang.String path, java.lang.Object
resource, java.util.Map<String, Object queryParams)
-
-The post/resource API method has the parameters listed in the table
-below:
-
-[cols=",,",options="header",]
-|===
-| Parameter | Description | Type
-| path | Resource URL path | String
-| resource | New resource | Object
-| queryParams | Custom query parameters | Map
-|===
-
-Any of the parameters can be provided in either the endpoint URI, or
dynamically in a message header. The message header name must be of the format
CamelDhis2.parameter. The inBody parameter overrides message header, i.e. the
endpoint parameter inBody=myParameterNameHere would override a
CamelDhis2.myParameterNameHere header.
-
-== Examples
-
* Save a data value set
-
++
[source,java]
----
package org.camel.dhis2.example;
@@ -217,13 +170,13 @@ public class MyRouteBuilder extends RouteBuilder {
public void configure() {
from("direct:postResource")
- .process(exchange -> exchange.getMessage().setBody(new
DataValueSet().withCompleteDate(
+ .setBody(exchange -> new DataValueSet().withCompleteDate(
ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT))
.withOrgUnit("O6uvpzGd5pu")
.withDataSet("lyLU2wR22tC").withPeriod(PeriodBuilder.monthOf(new Date(), -1))
.withDataValues(
-
List.of(new DataValue__1().withDataElement("aIJZ2d2QgVV").withValue("20")))))
-
.to("dhis2://post/resource?path=dataValueSets&inBody=resource&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
+
List.of(new DataValue__1().withDataElement("aIJZ2d2QgVV").withValue("20"))))
+
.to("dhis2://post/resource?path=dataValueSets&username=admin&password=district&baseApiUrl=https://play.dhis2.org/2.39.1/api")
.unmarshal().json(ImportReportWebMessageResponse.class)
.choice()
.when(exchange ->
!exchange.getMessage().getBody(ImportReportWebMessageResponse.class).getStatus().get().equals(DescriptiveWebMessage.Status.OK))
@@ -233,37 +186,6 @@ public class MyRouteBuilder extends RouteBuilder {
}
----
-== API: put
-
-*Both producer and consumer are supported*
-
-The post API is defined in the syntax as follows:
-
-....
-dhis2:put/methodName?[parameters]
-....
-
-== METHOD resource
-
-Signatures:
-
-* java.io.InputStream resource(java.lang.String path, java.lang.Object
resource, java.util.Map<String, Object queryParams)
-
-The put/resource API method has the parameters listed in the table
-below:
-
-[cols=",,",options="header",]
-|===
-| Parameter | Description | Type
-| path | Resource URL path | String
-| resource | Updated resource | Object
-| queryParams | Custom query parameters | Map
-|===
-
-In addition to the parameters above, the put/resource API can also use any of
the query parameters.
-
-Any of the parameters can be provided in either the endpoint URI, or
dynamically in a message header. The message header name must be of the format
CamelDhis2.parameter. The inBody parameter overrides message header, i.e. the
endpoint parameter inBody=myParameterNameHere would override a
CamelDhis2.myParameterNameHere header.
-
* Update an organisation unit
+
[source,java]
@@ -298,39 +220,8 @@ public class MyRouteBuilder extends RouteBuilder {
}
----
-== API: delete
-
-*Both producer and consumer are supported*
-
-The delete API is defined in the syntax as follows:
-
-....
-dhis2:delete/methodName?[parameters]
-....
-
-== METHOD resource
-
-Signatures:
-
-* java.io.InputStream resource(java.lang.String path, java.lang.Object
resource, java.util.Map<String, Object queryParams)
-
-The delete/resource API method has the parameters listed in the table
-below:
-
-[cols=",,",options="header",]
-|===
-| Parameter | Description | Type
-| path | Resource URL path | String
-| resource | Deleted resource | Object
-| queryParams | Custom query parameters | Map
-|===
-
-In addition to the parameters above, the delete/resource API can also use any
of the query parameters.
-
-Any of the parameters can be provided in either the endpoint URI, or
dynamically in a message header. The message header name must be of the format
CamelDhis2.parameter. The inBody parameter overrides message header, i.e. the
endpoint parameter inBody=myParameterNameHere would override a
CamelDhis2.myParameterNameHere header.
-
* Delete an organisation unit
-
++
[source,java]
----
package org.camel.dhis2.example;
@@ -361,41 +252,8 @@ public class MyRouteBuilder extends RouteBuilder {
}
----
-== API: resourceTables
-
-*Both producer and consumer are supported*
-
-The resourceTables API is defined in the syntax as follows:
-
-....
-dhis2:resourceTables/methodName?[parameters]
-....
-
-== METHOD analytics
-
-Signatures:
-
-* void analytics(java.lang.Boolean skipAggregate, java.lang.Boolean
skipEvents, java.lang.Integer lastYears, java.lang.Integer, interval)
-
-The post/resource API method has the parameters listed in the table below:
-
-The resourceTables/analytics API method has the parameters listed in the table
below:
-
-[width="100%",cols="19%,70%,11%",options="header",]
-|===
-| Parameter | Description | Type
-| skipAggregate | Skip generation of aggregate data and completeness data|
Boolean
-| skipEvents | Skip generation of event data | Boolean
-| lastYears | Number of last years of data to include | Integer
-| interval | Duration in milliseconds between completeness checks | Integer
-|===
-
-In addition to the parameters above, the resourceTables/analytics API can also
use any of the query parameters.
-
-Any of the parameters can be provided in either the endpoint URI, or
dynamically in a message header. The message header name must be of the format
CamelDhis2.parameter. The inBody parameter overrides message header, i.e. the
endpoint parameter inBody=myParameterNameHere would override a
CamelDhis2.myParameterNameHere header.
-
* Run analytics
-
++
[source,java]
----
package org.camel.dhis2.example;
@@ -411,10 +269,8 @@ public class MyRouteBuilder extends RouteBuilder {
}
----
-== Usage Examples
-
* Reference DHIS2 client
-
++
[source,java]
----
package org.camel.dhis2.example;
@@ -436,7 +292,7 @@ public class MyRouteBuilder extends RouteBuilder {
----
* Set custom query parameters
-
++
[source,java]
----
package org.camel.dhis2.example;
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/main/java/org/apache/camel/component/dhis2/Dhis2Converters.java
b/components/camel-dhis2/camel-dhis2-component/src/main/java/org/apache/camel/component/dhis2/Dhis2Converters.java
new file mode 100644
index 00000000000..e7ae5e6a455
--- /dev/null
+++
b/components/camel-dhis2/camel-dhis2-component/src/main/java/org/apache/camel/component/dhis2/Dhis2Converters.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dhis2;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dhis2.api.Dhis2Resource;
+import org.apache.camel.spi.TypeConverterRegistry;
+
+@Converter(generateLoader = true)
+public final class Dhis2Converters {
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private Dhis2Converters() {
+
+ }
+
+ @Converter(fallback = true)
+ public static <T> T convertTo(Class<T> type, Exchange exchange, Object
resource, TypeConverterRegistry registry) {
+ if (resource instanceof Dhis2Resource &&
type.getName().startsWith("org.hisp.dhis.api.model")) {
+ return OBJECT_MAPPER.convertValue(resource, type);
+ } else {
+ return null;
+ }
+ }
+}
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2DeleteIT.java
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2DeleteIT.java
index 76c79d09097..d9bcb32f362 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2DeleteIT.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2DeleteIT.java
@@ -66,7 +66,7 @@ public class Dhis2DeleteIT extends AbstractDhis2TestSupport {
assertEquals(404, remoteDhis2ClientException.getHttpStatusCode());
assertNotNull(result, "resource result");
- LOG.debug("resource: " + result);
+ LOG.debug("Result: {}", result);
}
@Override
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2GetIT.java
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2GetIT.java
index db2e47ac047..101dc3f281c 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2GetIT.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2GetIT.java
@@ -20,15 +20,19 @@
package org.apache.camel.component.dhis2;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.dhis2.internal.Dhis2ApiCollection;
import org.apache.camel.component.dhis2.internal.Dhis2GetApiMethod;
+import org.apache.camel.processor.aggregate.GroupedBodyAggregationStrategy;
+import org.hisp.dhis.api.model.v2_39_1.OrganisationUnit;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
@@ -40,43 +44,33 @@ public class Dhis2GetIT extends AbstractDhis2TestSupport {
private static final String PATH_PREFIX =
Dhis2ApiCollection.getCollection().getApiName(Dhis2GetApiMethod.class).getName();
@Test
- public void testCollection() throws Exception {
- final Map<String, Object> headers = new HashMap<String, Object>();
- // parameter type is String
+ public void testCollection() {
+ final Map<String, Object> headers = new HashMap<>();
headers.put("CamelDhis2.path", "organisationUnits");
- // parameter type is String
- headers.put("CamelDhis2.itemType",
"org.hisp.dhis.api.model.v2_39_1.OrganisationUnit");
- // parameter type is Boolean
+ headers.put("CamelDhis2.arrayName", "organisationUnits");
headers.put("CamelDhis2.paging", true);
- // parameter type is String
headers.put("CamelDhis2.fields", null);
- // parameter type is String
headers.put("CamelDhis2.filter", null);
- // parameter type is java.util.Map
headers.put("CamelDhis2.queryParams", new HashMap<>());
- final java.util.Iterator result =
requestBodyAndHeaders("direct://COLLECTION", null, headers);
+ final List<OrganisationUnit> result =
requestBodyAndHeaders("direct://COLLECTION", null, headers);
- assertNotNull(result, "collection result");
- LOG.debug("collection: " + result);
+ assertEquals(2, result.size());
+ LOG.debug("collection: {}", result);
}
@Test
- public void testResource() throws Exception {
- final Map<String, Object> headers = new HashMap<String, Object>();
- // parameter type is String
- headers.put("CamelDhis2.path", String.format("organisationUnits/%s",
Environment.ORG_UNIT_ID));
- // parameter type is String
+ public void testResource() {
+ final Map<String, Object> headers = new HashMap<>();
+ headers.put("CamelDhis2.path", String.format("organisationUnits/%s",
Environment.ORG_UNIT_ID_UNDER_TEST));
headers.put("CamelDhis2.fields", null);
- // parameter type is String
headers.put("CamelDhis2.filter", null);
- // parameter type is java.util.Map
headers.put("CamelDhis2.queryParams", null);
final java.io.InputStream result =
requestBodyAndHeaders("direct://RESOURCE", null, headers);
assertNotNull(result, "resource result");
- LOG.debug("resource: " + result);
+ LOG.debug("Result: {}", result);
}
@Override
@@ -85,12 +79,13 @@ public class Dhis2GetIT extends AbstractDhis2TestSupport {
public void configure() {
// test route for collection
from("direct://COLLECTION")
- .to("dhis2://" + PATH_PREFIX + "/collection");
+ .to("dhis2://" + PATH_PREFIX + "/collection")
+ .split().body().aggregationStrategy(new
GroupedBodyAggregationStrategy())
+ .convertBodyTo(OrganisationUnit.class);
// test route for resource
from("direct://RESOURCE")
.to("dhis2://" + PATH_PREFIX + "/resource");
-
}
};
}
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PostIT.java
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PostIT.java
index 96b610ad862..6526debc6f4 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PostIT.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PostIT.java
@@ -63,7 +63,7 @@ public class Dhis2PostIT extends AbstractDhis2TestSupport {
headers);
assertNotNull(result, "resource result");
- LOG.debug("resource: " + result);
+ LOG.debug("Result: {}", result);
}
@Override
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PutIT.java
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PutIT.java
index b0289b20639..9b7faaa3f1a 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PutIT.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2PutIT.java
@@ -56,19 +56,20 @@ public class Dhis2PutIT extends AbstractDhis2TestSupport {
private void putResource(String endpointUri) {
final Map<String, Object> headers = new HashMap<>();
// parameter type is String
- headers.put("CamelDhis2.path", String.format("organisationUnits/%s",
Environment.ORG_UNIT_ID));
+ headers.put("CamelDhis2.path", String.format("organisationUnits/%s",
Environment.ORG_UNIT_ID_UNDER_TEST));
// parameter type is java.util.Map
headers.put("CamelDhis2.queryParams", new HashMap<>());
String name = RandomStringUtils.randomAlphabetic(8);
final java.io.InputStream result = requestBodyAndHeaders(endpointUri,
new
OrganisationUnit().withName(name).withShortName(name).withOpeningDate(new
Date()), headers);
- OrganisationUnit organisationUnit =
Environment.DHIS2_CLIENT.get("organisationUnits/{id}", Environment.ORG_UNIT_ID)
- .transfer().returnAs(OrganisationUnit.class);
+ OrganisationUnit organisationUnit
+ = Environment.DHIS2_CLIENT.get("organisationUnits/{id}",
Environment.ORG_UNIT_ID_UNDER_TEST)
+ .transfer().returnAs(OrganisationUnit.class);
assertEquals(name, organisationUnit.getName().get());
assertNotNull(result, "resource result");
- LOG.debug("resource: " + result);
+ LOG.debug("Result: {}", result);
}
@Override
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2ResourceTablesIT.java
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2ResourceTablesIT.java
index 8ee0cc686d9..7c8f52b6d01 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2ResourceTablesIT.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Dhis2ResourceTablesIT.java
@@ -25,6 +25,7 @@ import java.util.Map;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.dhis2.internal.Dhis2ApiCollection;
import org.apache.camel.component.dhis2.internal.Dhis2ResourceTablesApiMethod;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,7 +40,7 @@ public class Dhis2ResourceTablesIT extends
AbstractDhis2TestSupport {
=
Dhis2ApiCollection.getCollection().getApiName(Dhis2ResourceTablesApiMethod.class).getName();
@Test
- public void testAnalytics() throws Exception {
+ public void testAnalytics() {
final Map<String, Object> headers = new HashMap<String, Object>();
// parameter type is Boolean
headers.put("CamelDhis2.skipAggregate", false);
@@ -50,7 +51,7 @@ public class Dhis2ResourceTablesIT extends
AbstractDhis2TestSupport {
// parameter type is Integer
headers.put("CamelDhis2.interval", 10000);
- requestBodyAndHeaders("direct://ANALYTICS", null, headers);
+ Assertions.assertDoesNotThrow(() ->
requestBodyAndHeaders("direct://ANALYTICS", null, headers));
}
@Override
diff --git
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Environment.java
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Environment.java
index 13470815a5d..2a8f48eb204 100644
---
a/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Environment.java
+++
b/components/camel-dhis2/camel-dhis2-component/src/test/java/org/apache/camel/component/dhis2/Environment.java
@@ -36,7 +36,7 @@ public final class Environment {
public static final Dhis2Client DHIS2_CLIENT;
- public static final String ORG_UNIT_ID;
+ public static final String ORG_UNIT_ID_UNDER_TEST;
private static final Network NETWORK = Network.newNetwork();
@@ -74,13 +74,14 @@ public final class Environment {
.getFirstMappedPort() + "/api",
"admin", "district").build();
- ORG_UNIT_ID = createOrgUnit();
+ createOrgUnit("EvilCorp");
+ ORG_UNIT_ID_UNDER_TEST = createOrgUnit("Acme");
createOrgUnitLevel();
- addOrgUnitToUser(ORG_UNIT_ID);
+ addOrgUnitToUser(ORG_UNIT_ID_UNDER_TEST);
}
- private static String createOrgUnit() {
- OrganisationUnit organisationUnit = new
OrganisationUnit().withName("Acme").withShortName("Acme")
+ private static String createOrgUnit(String name) {
+ OrganisationUnit organisationUnit = new
OrganisationUnit().withName(name).withShortName(name)
.withOpeningDate(new Date());
return (String) ((Map<String, Object>)
DHIS2_CLIENT.post("organisationUnits").withResource(organisationUnit)
diff --git a/components/camel-dhis2/pom.xml b/components/camel-dhis2/pom.xml
index 4a5c78bf7ab..4e38e50b320 100644
--- a/components/camel-dhis2/pom.xml
+++ b/components/camel-dhis2/pom.xml
@@ -34,7 +34,7 @@
<description>Camel DHIS2 Component</description>
<properties>
- <dhis2-java-sdk.version>2.0.0</dhis2-java-sdk.version>
+ <dhis2-java-sdk.version>2.1.0</dhis2-java-sdk.version>
</properties>
<modules>