Skip to content

Commit

Permalink
Merge pull request #29 from apptreesoftware/release/5.5.5.1
Browse files Browse the repository at this point in the history
Release/5.5.5.1
  • Loading branch information
matthewtsmith committed May 10, 2017
2 parents 0c29247 + ca61278 commit 162fbe7
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions app/sdk/controllers/DataSetController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.commons.lang3.StringUtils;
import play.libs.Json;
import play.mvc.BodyParser;
import play.mvc.Http;
Expand Down Expand Up @@ -94,6 +95,28 @@ private void generateDataSourceSearchResponse(DataSource_Internal dataSource, Da
});
}

private void generateDataSourceCreateResponse(DataSource_Internal dataSource, DataSetItem dataSetItem, String callbackURL, AuthenticationInfo authenticationInfo, Parameters parameters) {
dataSource.createDataSetItem(dataSetItem, authenticationInfo, parameters)
.whenComplete(((dataSet, throwable) -> {
if ( throwable != null ) {
sendDataSetExceptionCallback(throwable, callbackURL);
} else {
sendDataSetResponse(dataSet, callbackURL);
}
}));
}

private void generateDataSourceUpdateResponse(DataSource_Internal dataSource, DataSetItem dataSetItem, String callbackURL, AuthenticationInfo authenticationInfo, Parameters parameters) {
dataSource.updateDataSetItem(dataSetItem, authenticationInfo, parameters)
.whenComplete(((dataSet, throwable) -> {
if ( throwable != null ) {
sendDataSetExceptionCallback(throwable, callbackURL);
} else {
sendDataSetResponse(dataSet, callbackURL);
}
}));
}

public CompletionStage<Result> getDataConfiguration(String dataSetName) {
DataSource_Internal dataSource = AppTree.lookupDataSetHandler(dataSetName);
if ( dataSource == null ) return CompletableFuture.completedFuture(notFound());
Expand All @@ -107,31 +130,45 @@ public CompletionStage<Result> getDataConfiguration(String dataSetName) {
@With({ValidateRequestAction.class})
public CompletionStage<Result> createDataSetItem(String dataSetName) {
Http.Request request = request();
String callbackURL = request.getHeader(Constants.CORE_CALLBACK_URL);
AuthenticationInfo authenticationInfo = new AuthenticationInfo(request.headers());
Parameters parameters = new Parameters(request.queryString());
DataSource_Internal dataSource = AppTree.lookupDataSetHandler(dataSetName);
if ( dataSource == null ) return CompletableFuture.completedFuture(notFound());

return getServiceConfiguration(dataSource, request)
.thenCompose(configuration -> dataSetItemFromRequest(configuration, request, false))
.thenCompose(dataSetItem -> dataSource.createDataSetItem(dataSetItem, authenticationInfo, parameters))
.thenApply(dataSet -> ok(dataSet.toJSON()))
.exceptionally(ResponseExceptionHandler::handleException);
.thenCompose(dataSetItem -> {
if ( !StringUtils.isEmpty(callbackURL) ) {
generateDataSourceCreateResponse(dataSource, dataSetItem, callbackURL, authenticationInfo, parameters);
return CompletableFuture.completedFuture(ok(JsonUtils.toJson(Response.asyncSuccess())));
} else {
return dataSource.createDataSetItem(dataSetItem, authenticationInfo, parameters).thenApply(dataSet -> ok(dataSet.toJSON()));
}
})
.exceptionally(throwable -> ResponseExceptionHandler.handleException(throwable, callbackURL != null));
}

@With({ValidateRequestAction.class})
public CompletionStage<Result> updateDataSetItem(String dataSetName) {
Http.Request request = request();
String callbackURL = request.getHeader(Constants.CORE_CALLBACK_URL);
AuthenticationInfo authenticationInfo = new AuthenticationInfo(request.headers());
Parameters parameters = new Parameters(request.queryString());
DataSource_Internal dataSource = AppTree.lookupDataSetHandler(dataSetName);
if ( dataSource == null ) return CompletableFuture.completedFuture(notFound());

return getServiceConfiguration(dataSource, request)
.thenCompose(configuration -> dataSetItemFromRequest(configuration, request, false))
.thenCompose(dataSetItem -> dataSource.updateDataSetItem(dataSetItem, authenticationInfo, parameters))
.thenApply(dataSet -> ok(dataSet.toJSON()))
.exceptionally(ResponseExceptionHandler::handleException);
.thenCompose(dataSetItem -> {
if ( !StringUtils.isEmpty(callbackURL) ) {
generateDataSourceUpdateResponse(dataSource, dataSetItem, callbackURL, authenticationInfo, parameters);
return CompletableFuture.completedFuture(ok(JsonUtils.toJson(Response.asyncSuccess())));
} else {
return dataSource.updateDataSetItem(dataSetItem, authenticationInfo, parameters).thenApply(dataSet -> ok(dataSet.toJSON()));
}
})
.exceptionally(throwable -> ResponseExceptionHandler.handleException(throwable, callbackURL != null));
}

@With({ValidateRequestAction.class})
Expand Down

0 comments on commit 162fbe7

Please sign in to comment.