use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheBackwardCompatibilityTest method shouldReturnExpectedNamedOperationDetailUsingCacheDataFromVersion1_12.
@Test
public void shouldReturnExpectedNamedOperationDetailUsingCacheDataFromVersion1_12() throws Exception {
final NamedOperationDetail namedOperationDetail = new NamedOperationDetail.Builder().operationName(OPERATION_NAME).description("standard operation").creatorId(ADDING_USER.getUserId()).readers(asList("readerAuth1", "readerAuth2")).writers(asList("writerAuth1", "writerAuth2")).operationChain(new OperationChain.Builder().first(new AddElements()).build()).build();
final NamedOperationDetail namedOperationDetailFromCacheVersion1_12 = operationCache.getNamedOperation(OPERATION_NAME, ADDING_USER);
assertEquals(namedOperationDetail.getReadAccessPredicate(), namedOperationDetailFromCacheVersion1_12.getReadAccessPredicate());
assertEquals(namedOperationDetail.getWriteAccessPredicate(), namedOperationDetailFromCacheVersion1_12.getWriteAccessPredicate());
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheTest method shouldAllowUsersReadAccessToTheirOwnNamedOperations.
@Test
public void shouldAllowUsersReadAccessToTheirOwnNamedOperations() throws CacheOperationFailedException {
NamedOperationDetail op = new NamedOperationDetail.Builder().operationName(OPERATION_NAME).creatorId(standardUser.getUserId()).operationChain(standardOpChain).readers(new ArrayList<>()).writers(writers).build();
cache.addNamedOperation(op, false, standardUser);
assertEquals(op, cache.getNamedOperation(OPERATION_NAME, standardUser));
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class NamedOperationCacheTest method shouldAllowUsersWriteAccessToTheirOwnOperations.
@Test
public void shouldAllowUsersWriteAccessToTheirOwnOperations() throws CacheOperationFailedException {
NamedOperationDetail op = new NamedOperationDetail.Builder().operationName(OPERATION_NAME).creatorId(standardUser.getUserId()).operationChain(standardOpChain).readers(readers).writers(new ArrayList<>()).build();
cache.addNamedOperation(op, false, standardUser);
cache.addNamedOperation(standard, true, standardUser);
assertEquals(standard, cache.getNamedOperation(OPERATION_NAME, standardUser));
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class OperationServiceIT method shouldReturnNamedOpDetailWithLabelWhenLabelIsAddedToNamedOp.
@Test
public void shouldReturnNamedOpDetailWithLabelWhenLabelIsAddedToNamedOp() throws Exception {
// Given
final AddNamedOperation namedOperation = new AddNamedOperation.Builder().name("My Operation With Label").labels(Arrays.asList("test label")).operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}").build();
client.executeOperation(namedOperation);
// When
final Response response = client.executeOperation(new GetAllNamedOperations());
final List<NamedOperationDetail> namedOperationDetails = response.readEntity(new GenericType<List<NamedOperationDetail>>() {
});
// Then
final NamedOperationDetail expected = new NamedOperationDetail.Builder().operationName("My Operation With Label").labels(Arrays.asList("test label")).operationChain("{\"operations\":[{\"class\":\"uk.gov.gchq.gaffer.operation.impl.add.AddElements\",\"skipInvalidElements\":false,\"validate\":true}]}").inputType("uk.gov.gchq.gaffer.data.element.Element[]").creatorId("UNKNOWN").parameters(null).build();
assertThat(namedOperationDetails.iterator().next()).isEqualTo(expected);
}
use of uk.gov.gchq.gaffer.named.operation.NamedOperationDetail in project Gaffer by gchq.
the class AddNamedOperationHandler method doOperation.
/**
* Adds a NamedOperation to a cache which must be specified in the operation declarations file. An
* NamedOperationDetail is built using the fields on the AddNamedOperation. The operation name and operation chain
* fields must be set and cannot be left empty, or the build() method will fail and a runtime exception will be
* thrown. The handler then adds/overwrites the NamedOperation according toa an overwrite flag.
*
* @param operation the {@link Operation} to be executed
* @param context the operation chain context, containing the user who executed the operation
* @param store the {@link Store} the operation should be run on
* @return null (since the output is void)
* @throws OperationException if the operation on the cache fails
*/
@Override
public Void doOperation(final AddNamedOperation operation, final Context context, final Store store) throws OperationException {
try {
final NamedOperationDetail namedOperationDetail = new NamedOperationDetail.Builder().operationChain(operation.getOperationChainAsString()).operationName(operation.getOperationName()).labels(operation.getLabels()).creatorId(context.getUser().getUserId()).readers(operation.getReadAccessRoles()).writers(operation.getWriteAccessRoles()).description(operation.getDescription()).parameters(operation.getParameters()).score(operation.getScore()).readAccessPredicate(operation.getReadAccessPredicate()).writeAccessPredicate(operation.getWriteAccessPredicate()).build();
validate(namedOperationDetail.getOperationChainWithDefaultParams(), namedOperationDetail);
cache.addNamedOperation(namedOperationDetail, operation.isOverwriteFlag(), context.getUser(), store.getProperties().getAdminAuth());
} catch (final CacheOperationFailedException e) {
throw new OperationException(e.getMessage(), e);
}
return null;
}
Aggregations