Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e1e1b33
Enable chunking for messages.
saschadoemer Apr 6, 2021
de162a8
Add testcase for sending chunks.
saschadoemer Apr 6, 2021
d2c876e
Add testcase for sending chunks.
saschadoemer Apr 6, 2021
b1b2c1e
Format.
saschadoemer Apr 6, 2021
b37564f
Merge branch 'main' of https://github.com/DKE-Data/agrirouter-sdk-jav…
saschadoemer Nov 26, 2021
2b94e36
Merge latest `master` and adapt implementation.
saschadoemer Nov 26, 2021
35d4119
Adapt implementation for chunking.
saschadoemer Nov 26, 2021
81fc0e6
Adapt wait time to handle agrirouter response time.
saschadoemer Nov 26, 2021
2a8e4ef
Adapt wait time to handle agrirouter response time.
saschadoemer Nov 26, 2021
9a86e46
Fix business validation for parameters.
saschadoemer Dec 8, 2021
4e68e74
Fix comment.
saschadoemer Dec 8, 2021
692190c
Additional `null` value check.
saschadoemer Dec 8, 2021
2c4e643
Rename method.
saschadoemer Dec 8, 2021
5ed9666
Remove test case.
saschadoemer Dec 8, 2021
bd774f9
Adapt the chunking - chunk raw content and then Base64 each chunk of it.
saschadoemer Dec 10, 2021
2c5811f
Format.
saschadoemer Dec 10, 2021
0f7b61a
Adapt comment.
saschadoemer Dec 10, 2021
84dfb40
Bump log4j version to fix vulnerability.
saschadoemer Dec 14, 2021
1ebfd52
Update timeout due to some network problems.
saschadoemer Dec 14, 2021
ab97a4a
Fix typo.
saschadoemer Dec 16, 2021
5cc596a
Fix typo.
saschadoemer Dec 16, 2021
9e5bb33
Fix typo.
saschadoemer Dec 16, 2021
fd22398
Fix typo.
saschadoemer Dec 16, 2021
94be681
Adapt comment.
saschadoemer Dec 16, 2021
1b30cf6
Adapt test cases and fix encoding mechanism.
saschadoemer Dec 16, 2021
2999dbf
Fix typo.
saschadoemer Dec 20, 2021
18a6e53
Fix typo.
saschadoemer Dec 20, 2021
728f860
Changed the log message to a more meaningful one.
saschadoemer Dec 20, 2021
a42d92d
Adapt position of the log message.
saschadoemer Dec 20, 2021
7bb8311
Remove null check that was not necessary.
saschadoemer Dec 20, 2021
c90f9c4
Adapt test case.
saschadoemer Dec 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
/** Common Environment, holds some default methods pointing to the QA. */
public interface Environment {

String AGRIROUTER_LOGIN_URL = "/app";

/** Template for MQTT connections. */
String MQTT_URL_TEMPLATE = "ssl://%s:%s";

/** Link template for the secured onboarding process. */
String SECURED_ONBOARDING_AUTHORIZATION_LINK_TEMPLATE =
"/application/%s/authorize?response_type=%s&state=%s&redirect_uri=%s";

Expand Down Expand Up @@ -68,16 +69,6 @@ default String getRevokeUrl() {
return getRegistrationServiceUrl() + getApiPrefix() + "/registration/onboard/revoke";
}

/**
* Returning the URL to login into the AR. This is necessary, because there are services within
* the UI whiche are only avalailable if the user is logged in.
*
* @return -
*/
default String getAgrirouterLoginUrl() {
return this.getEnvironmentBaseUrl() + AGRIROUTER_LOGIN_URL;
}

/**
* Returning the authorization URL for secured onboarding.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,28 @@ default void businessValidation() {
//
}

/** Rise an exception if the parameter was not valid. */
default void rise() {
throw new IllegalParameterDefinitionException(
"Parameter was not defined correctly, please check the values.");
}

/**
* Rise an exception if the parameter was not valid.
* Rise an exception if there has to be at least one valid parameter.
*
* @param message -
*/
default void rise(String message) {
default void rise(String message, String... parameterNames) {
final String joinedParametersNames = String.join(",", parameterNames);
throw new IllegalParameterDefinitionException(
String.format(
"Parameter was not defined correctly, please check the values. Error message is '%s'.",
message));
"At least one of the following parameters has to be defined [%s] was not defined correctly, please check the values. '%s'.",
joinedParametersNames, message));
}

/**
* Check for null values.
*
* @param o -
*/
default void nullCheck(Object o) {
default void nullCheck(String parameterName, Object o) {
if (null == o) {
this.rise("The parameter should not have been null, please check your values.");
this.rise(
"The parameter '%s' should not have been null, please check your values.", parameterName);
}
}

Expand All @@ -69,9 +65,11 @@ default void nullCheck(Object o) {
*
* @param s -
*/
default void isBlank(String s) {
default void isBlank(String parameterName, String s) {
if (StringUtils.isBlank(s)) {
this.rise("The parameter should not have been blank, please check your values.");
this.rise(
"The parameter '%s' should not have been blank, please check your values.",
parameterName);
}
}

Expand All @@ -80,10 +78,12 @@ default void isBlank(String s) {
*
* @param c -
*/
default void nullOrEmpty(Collection<?> c) {
nullCheck(c);
default void nullOrEmpty(String parameterName, Collection<?> c) {
nullCheck(parameterName, c);
if (c.isEmpty()) {
this.rise("The parameter should not have been empty, please check your values.");
this.rise(
"The parameter '%s' should not have been empty, please check your values.",
parameterName);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.dke.data.agrirouter.api.service.messaging.encoding;

import com.dke.data.agrirouter.api.dto.onboard.OnboardingResponse;
import com.dke.data.agrirouter.api.service.parameters.MessageHeaderParameters;
import com.dke.data.agrirouter.api.service.parameters.MessageParameterTuple;
import com.dke.data.agrirouter.api.service.parameters.PayloadParameters;
import java.util.List;

/** Encoding of messages. */
public interface EncodeMessageService {
Expand All @@ -15,4 +18,25 @@ public interface EncodeMessageService {
*/
String encode(
MessageHeaderParameters messageHeaderParameters, PayloadParameters payloadParameters);

/**
* Encode a number of messages.
*
* @param messageParameterTuples -
* @return -
*/
List<String> encode(List<MessageParameterTuple> messageParameterTuples);

/**
* Chunk a raw message if necessary. The chunk information and all IDs will be set by the SDK and
* are no longer in control of the application.
*
* @param messageHeaderParameters -
* @param payloadParameters -
* @return -
*/
List<MessageParameterTuple> chunkAndEncode(
MessageHeaderParameters messageHeaderParameters,
PayloadParameters payloadParameters,
OnboardingResponse onboardingResponse);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import agrirouter.technicalmessagetype.Gps
/**
* Enum containing all the content message types the AR is supporting.
*/
enum class ContentMessageType(private val key: String, private val typeUrl: String) : TechnicalMessageType {
ISO_11783_TASKDATA_ZIP("iso:11783:-10:taskdata:zip", ""),
@Suppress("unused")
enum class ContentMessageType(private val key: String, private val typeUrl: String, private val needsChunkinng: Boolean, private val needsBase64Encoding: Boolean) : TechnicalMessageType {
ISO_11783_TASKDATA_ZIP("iso:11783:-10:taskdata:zip", "", true, true),
SHP_SHAPE_ZIP("shp:shape:zip", "", true, true),
DOC_PDF("doc:pdf", "", true, true),
IMG_JPEG("img:jpeg", "", true, true),
IMG_PNG("img:png", "", true, true),
IMG_BMP("img:bmp", "", true, true),
VID_AVI("vid:avi", "", true, true),
VID_MP4("vid:mp4", "", true, true),
VID_WMV("vid:wmv", "", true, true),
GPS_INFO("gps:info", Gps.GPSList.getDescriptor().fullName, false, false),

//FIXME Since the spec is not public, we can only use those literals.
ISO_11783_DEVICE_DESCRIPTION("iso:11783:-10:device_description:protobuf", "types.agrirouter.com\\efdi.ISO11783_TaskData"),
ISO_11783_TIME_LOG("iso:11783:-10:time_log:protobuf", "types.agrirouter.com\\efdi.TimeLog"),

SHP_SHAPE_ZIP("shp:shape:zip", ""),
DOC_PDF("doc:pdf", ""),
IMG_JPEG("img:jpeg", ""),
IMG_PNG("img:png", ""),
IMG_BMP("img:bmp", ""),
VID_AVI("vid:avi", ""),
VID_MP4("vid:mp4", ""),
VID_WMV("vid:wmv", ""),
GPS_INFO("gps:info", Gps.GPSList.getDescriptor().fullName);
ISO_11783_DEVICE_DESCRIPTION("iso:11783:-10:device_description:protobuf", "types.agrirouter.com\\efdi.ISO11783_TaskData", false, false),
ISO_11783_TIME_LOG("iso:11783:-10:time_log:protobuf", "types.agrirouter.com\\efdi.TimeLog", false, false);

override fun getKey(): String {
return key
Expand All @@ -29,4 +29,13 @@ enum class ContentMessageType(private val key: String, private val typeUrl: Stri
override fun getTypeUrl(): String {
return typeUrl
}

override fun getNeedsChunking(): Boolean {
return needsChunkinng
}

override fun getNeedsBase64Encoding(): Boolean {
return needsBase64Encoding
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import agrirouter.request.payload.endpoint.SubscriptionOuterClass
/**
* Enum containing all the content message types the AR is supporting.
*/
@Suppress("unused")
enum class SystemMessageType(private val key: String, private val typeUrl: String) : TechnicalMessageType {
EMPTY("", ""),
DKE_CLOUD_ONBOARD_ENDPOINTS("dke:cloud_onboard_endpoints", CloudVirtualizedAppRegistration.OnboardingRequest.getDescriptor().fullName),
Expand All @@ -30,4 +31,11 @@ enum class SystemMessageType(private val key: String, private val typeUrl: Strin
return typeUrl
}

override fun getNeedsChunking(): Boolean {
return false
}

override fun getNeedsBase64Encoding(): Boolean {
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ interface TechnicalMessageType {
*/
fun getTypeUrl(): String

/**
* Indicates whether the technical message type needs chunking or not.
*/
fun getNeedsChunking(): Boolean

/**
* Indicates whether the technical message type needs base64 encoding or not.
*/
fun getNeedsBase64Encoding(): Boolean;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AuthorizationRequestParameters : AbstractParameterBase(), ParameterValidat
var responseType: SecuredOnboardingResponseType = SecuredOnboardingResponseType.ONBOARD

override fun technicalValidation() {
isBlank(applicationId)
isBlank("applicationId",applicationId)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class CloudOffboardingParameters : AbstractParameterBase(), ParameterValidation
var endpointIds: List<String>? = null

override fun technicalValidation() {
nullCheck(onboardingResponse)
nullCheck(endpointIds)
nullCheck("onboardingResponse",onboardingResponse)
nullCheck("endpointIds",endpointIds)
}

override fun businessValidation() {
nullOrEmpty(endpointIds)
nullOrEmpty("endpointIds",endpointIds)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class CloudOnboardingParameters : AbstractParameterBase(), ParameterValidation {
var endpointDetails: List<EndpointDetailsParameters>? = null

override fun technicalValidation() {
nullCheck(onboardingResponse)
nullCheck(endpointDetails)
nullCheck("onboardingResponse",onboardingResponse)
nullCheck("endpointDetails",endpointDetails)
}

override fun businessValidation() {
nullOrEmpty(endpointDetails)
nullOrEmpty("endpointDetails",endpointDetails)
endpointDetails?.forEach {
it.validate()
}
Expand All @@ -32,8 +32,8 @@ class CloudOnboardingParameters : AbstractParameterBase(), ParameterValidation {
var endpointName: String? = null

override fun technicalValidation() {
isBlank(endpointId)
isBlank(endpointName)
isBlank("endpointId",endpointId)
isBlank("endpointName",endpointName)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class DeleteMessageParameters : AbstractParameterBase(), ParameterValidation {
var sentToInSeconds: Long? = null

override fun technicalValidation() {
nullCheck(onboardingResponse)
nullCheck("onboardingResponse", onboardingResponse)
}

override fun businessValidation() {
if (null == messageIds && null == senderIds && null == sentFromInSeconds && null == sentToInSeconds) {
rise("There has to be a filter criteria for the query.")
rise("There has to be a filter criteria for the query.", "messageIds", "senderIds", "sentFromInSeconds & sendToInSeconds", "")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ open class FetchMessageParameters : AbstractParameterBase(), ParameterValidation
var onboardingResponse: OnboardingResponse? = null

override fun technicalValidation() {
nullCheck(onboardingResponse)
nullCheck("onboardingResponse",onboardingResponse)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class ListEndpointsParameters : AbstractParameterBase(), ParameterValidation {
var unfilteredList: Boolean = false

override fun technicalValidation() {
nullCheck(onboardingResponse)
nullCheck(technicalMessageType)
nullCheck(direction)
nullCheck("onboardingResponse",onboardingResponse)
nullCheck("technicalMessageType",technicalMessageType)
nullCheck("direction",direction)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MessageConfirmationForAllPendingMessagesParameters : AbstractParameterBase
var onboardingResponse: OnboardingResponse? = null

override fun technicalValidation() {
nullCheck(onboardingResponse)
nullCheck("onboardingResponse",onboardingResponse)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class MessageConfirmationParameters : AbstractParameterBase(), ParameterValidati
var messageIds: List<String>? = null

override fun technicalValidation() {
nullCheck(onboardingResponse)
nullCheck(messageIds)
nullCheck("onboardingResponse",onboardingResponse)
nullCheck("messageIds",messageIds)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.*
/**
* Parameters class. Encapsulation for the services.
*/
class MessageHeaderParameters : ParameterValidation {
class MessageHeaderParameters : ParameterValidation {

var applicationMessageId: String? = null

Expand All @@ -29,9 +29,23 @@ class MessageHeaderParameters : ParameterValidation {
var metadata: MessageOuterClass.Metadata? = null

override fun technicalValidation() {
isBlank(applicationMessageId)
nullCheck(technicalMessageType)
nullCheck(mode)
isBlank("applicationMessageId",applicationMessageId)
nullCheck("technicalMessageType",technicalMessageType)
nullCheck("mode",mode)
}

/**
* Copy the content of the message header parameters into this class.
*/
fun copy(messageHeaderParameters: MessageHeaderParameters) {
applicationMessageId = messageHeaderParameters.applicationMessageId
applicationMessageSeqNo = messageHeaderParameters.applicationMessageSeqNo
technicalMessageType = messageHeaderParameters.technicalMessageType
teamSetContextId = messageHeaderParameters.teamSetContextId
mode = messageHeaderParameters.mode
recipients = messageHeaderParameters.recipients
chunkInfo = messageHeaderParameters.chunkInfo
metadata = messageHeaderParameters.metadata
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.dke.data.agrirouter.api.service.parameters

/**
* Containing a tuple for message sending, i.e. used after chunking the messages.
*/
class MessageParameterTuple(var messageHeaderParameters: MessageHeaderParameters, var payloadParameters: PayloadParameters) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class MessageQueryParameters : AbstractParameterBase(), ParameterValidation {
var sentToInSeconds: Long? = null

override fun technicalValidation() {
nullCheck(onboardingResponse)
nullCheck("onboardingResponse", onboardingResponse)
}

override fun businessValidation() {
if (null == messageIds && null == senderIds && null == sentFromInSeconds && null == sentToInSeconds) {
this.rise("There has to be a filter criteria for the query.")
rise("There has to be a filter criteria for the query.", "messageIds", "senderIds", "sentFromInSeconds & sendToInSeconds", "")
}
}

Expand Down
Loading