Skip to content

Commit

Permalink
#451 - remove delegate copy
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidast committed Aug 8, 2024
1 parent ca8e682 commit 77a3544
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class Delegate {
private static final String PAYLOAD = "payload";
private static final String URI = "uri";
private static final String METHOD = "method";
private static final String COPY = "copy";
private static final int FIRST = 0;
private static final int STATUS_CODE_2XX = 2;

Expand Down Expand Up @@ -240,9 +239,7 @@ private Future<String> extractDelegateExecutionRequestJsonPayload(HttpServerRequ
private Future<Buffer> generatePayload(String delegateExecutionRequestJsonPayload, MultiMap headers, DelegateRequest requestContainer, final Matcher matcher) {
Promise<Buffer> promise = Promise.promise();

if (requestContainer.isCopy()) {
promise.complete(Buffer.buffer(delegateExecutionRequestJsonPayload));
} else if (requestContainer.getJoltSpec() != null) {
if (requestContainer.getJoltSpec() != null) {
try {
if (delegateExecutionRequestJsonPayload != null) {

Expand Down Expand Up @@ -272,7 +269,7 @@ private Future<Buffer> generatePayload(String delegateExecutionRequestJsonPayloa
} else {
// matcher to replace wildcards with matching groups
final JsonObject requestObject = requestContainer.getRequest();
// get the string representation of the payload object
// get the string represantion of the payload object
String payloadStr;
payloadStr = requestObject.getJsonObject(PAYLOAD).encode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

/**
* DelegateFactory is used to create delegate objects from their text representation.
*
* @author https://github.com/ljucam [Mario Ljuca]
*/
public class DelegateFactory {
private static final Logger LOG = LoggerFactory.getLogger(DelegateFactory.class);
Expand All @@ -34,7 +36,6 @@ public class DelegateFactory {
private static final String DYNAMIC_HEADERS = "dynamicHeaders";
private static final String TRANSFORM = "transform";
private static final String TRANSFORM_WITH_METADATA = "transformWithMetadata";
private static final String COPY = "copy";

private final ClientRequestCreator clientRequestCreator;

Expand All @@ -45,6 +46,11 @@ public class DelegateFactory {

/**
* Creates a new instance of the DelegateFactory.
*
* @param clientRequestCreator
* @param properties
* @param delegatesSchema
* @param unmatchedDelegateStatusCode
*/
public DelegateFactory(final ClientRequestCreator clientRequestCreator, final Map<String, Object> properties,
final String delegatesSchema, @Nullable StatusCode unmatchedDelegateStatusCode) {
Expand All @@ -55,7 +61,12 @@ public DelegateFactory(final ClientRequestCreator clientRequestCreator, final Ma
}

/**
* Tries to create a Delegate object out of the buffer.
* Tries to create a Delegate object out of the
* buffer.
*
* @param delegateName name of the delegate
* @param buffer buffer of the delegate
* @return a Delegate object
*/
public Delegate parseDelegate(final String delegateName, final Buffer buffer) throws ValidationException {
final String configString;
Expand All @@ -79,6 +90,11 @@ public Delegate parseDelegate(final String delegateName, final Buffer buffer) th

/**
* Create the delegate out of the prepared string.
*
* @param delegateName name of the delegate
* @param configString the string rep. of the delegate
* @return the new delegate
* @throws ValidationException
*/
private Delegate createDelegate(final String delegateName, final String configString) throws ValidationException {
JsonObject delegateObject = new JsonObject(configString);
Expand All @@ -103,11 +119,7 @@ private Delegate createDelegate(final String delegateName, final String configSt
LOG.trace("request of [{}] #: {}", delegateName, i);
}
JsonObject requestJsonObject = (JsonObject) delegateObject.getJsonArray(REQUESTS).getValue(i);
boolean copy = requestJsonObject.getBoolean(COPY, false);
JoltSpec joltSpec = null;
if (!copy) {
joltSpec = parsePayloadTransformSpec(requestJsonObject, delegateName);
}
JoltSpec joltSpec = parsePayloadTransformSpec(requestJsonObject, delegateName);

HeaderFunction headerFunction;
final JsonArray headerFunctionsArray = requestJsonObject.getJsonArray(DYNAMIC_HEADERS);
Expand All @@ -117,7 +129,7 @@ private Delegate createDelegate(final String delegateName, final String configSt
headerFunction = HeaderFunctions.DO_NOTHING;
}

requests.add(new DelegateRequest(requestJsonObject, joltSpec, headerFunction, copy));
requests.add(new DelegateRequest(requestJsonObject, joltSpec, headerFunction));
}

return new Delegate(clientRequestCreator, delegateName, pattern, methods, requests, unmatchedDelegateStatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@
* delegate.<br>
* <code>PUT /gateleen/server/delegate/v1/delegates/user-zip-copy/definition</code>
* <pre>
{
"methods": [ "PUT", "DELETE" ],
"pattern": "([^/]*)/(.*)",
"requests": [
{
"headers" : [],
"uri": "/gateleen/server/copy",
"method": "POST",
"payload": {
"source": "/gateleen/$1?expand=100&amp;zip=true",
"destination": "/gateleen/zips/users/$1.zip"
}
}
]
}
{
"methods": [ "PUT", "DELETE" ],
"pattern": "([^/]*)/(.*)",
"requests": [
{
"headers" : [],
"uri": "/gateleen/server/copy",
"method": "POST",
"payload": {
"source": "/gateleen/$1?expand=100&amp;zip=true",
"destination": "/gateleen/zips/users/$1.zip"
}
}
]
}
* </pre>
* To trigger an execution, it suffice to perform a PUT request on the virtual collection <code>execution</code> within
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ public class DelegateRequest {
private final JsonObject request;
private final JoltSpec joltSpec;
private final HeaderFunction headerFunction;
private final boolean copy;

public DelegateRequest(JsonObject request, JoltSpec joltSpec, HeaderFunction headerFunction, boolean copy) {
public DelegateRequest(JsonObject request, JoltSpec joltSpec, HeaderFunction headerFunction) {
this.request = request;
this.joltSpec = joltSpec;
this.headerFunction = headerFunction;
this.copy = copy;
}

public JsonObject getRequest() {
Expand All @@ -34,8 +32,4 @@ public JoltSpec getJoltSpec() {
public HeaderFunction getHeaderFunction() {
return headerFunction;
}

public boolean isCopy() {
return copy;
}
}

0 comments on commit 77a3544

Please sign in to comment.