Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-2669: Added new aggregation function endpoints #2670

Merged
merged 1 commit into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -39,6 +39,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;

Expand Down Expand Up @@ -83,6 +84,13 @@ public Response getFilterFunction() {
.build();
}

@Override
public Response getAggregationFunctions() {
return Response.ok(ReflectionUtil.getSubTypes(BinaryOperator.class))
.header(GAFFER_MEDIA_TYPE_HEADER, GAFFER_MEDIA_TYPE)
.build();
}

@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "Need to wrap all runtime exceptions before they are given to the user")
@Override
public Response getFilterFunction(final String inputClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ public interface IGraphConfigurationServiceV2 {
@ApiResponse(code = 500, message = INTERNAL_SERVER_ERROR)})
Response getTransformFunctions();

@GET
@Path("/aggregationFunctions")
@ApiOperation(value = "Gets available aggregation functions",
notes = "Returns a list of the fully qualified classpaths of all available aggregation functions, in no particular order.",
response = String.class,
responseContainer = "list",
produces = APPLICATION_JSON,
responseHeaders = {
@ResponseHeader(name = GAFFER_MEDIA_TYPE_HEADER, description = GAFFER_MEDIA_TYPE_HEADER_DESCRIPTION)
})
@ApiResponses(value = {@ApiResponse(code = 200, message = OK),
@ApiResponse(code = 500, message = INTERNAL_SERVER_ERROR)})
Response getAggregationFunctions();

@GET
@Path("/elementGenerators")
@ApiOperation(value = "Gets available element generators",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ public void shouldGetTransformFunctions() {
assertFalse(classes.isEmpty());
}

@Test
public void shouldGetAggregationFunctions() {
// When
final Set<Class> classes = (Set<Class>) service.getAggregationFunctions().getEntity();

// Then
assertFalse(classes.isEmpty());
}

@Test
public void shouldGetElementGenerators() {
// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;

Expand Down Expand Up @@ -140,4 +141,9 @@ public Set<StoreTrait> getStoreTraits() {
public Set<Class> getTransformFunctions() {
return ReflectionUtil.getSubTypes(Function.class);
}

@Override
public Set<Class> getAggregationFunctions() {
return ReflectionUtil.getSubTypes(BinaryOperator.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,16 @@ public interface IGraphConfigurationController {
responseContainer = "Set"
)
Set<Class> getTransformFunctions();

@RequestMapping(
path = "/aggregationFunctions",
method = GET,
produces = APPLICATION_JSON_VALUE
)
@ApiOperation(
value = "Gets the available aggregation functions",
response = Class.class,
responseContainer = "Set"
)
Set<Class> getAggregationFunctions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ public void shouldGetTransformFunctions() {
assertFalse(classes.isEmpty());
}

@Test
public void shouldGetAggregationFunctions() {
// Given
GraphConfigurationController controller = new GraphConfigurationController(graphFactory);

// When
final Set<Class> classes = controller.getAggregationFunctions();

// Then
assertFalse(classes.isEmpty());
}

@Test
public void shouldGetElementGenerators() {
// Given
Expand Down