use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.
the class NamedViewResolverTest method shouldResolveNamedViewJsonWithParameters.
@Test
public void shouldResolveNamedViewJsonWithParameters() throws CacheOperationFailedException {
Map<String, Object> paramMap = Maps.newHashMap();
paramMap.put(IS_MORE_THAN_X_PARAM_KEY, 7L);
paramMap.put(SELECTION_PARAM_KEY, "VERTEX");
ViewParameterDetail param = new ViewParameterDetail.Builder().defaultValue(2L).description("more than filter").valueClass(Long.class).build();
ViewParameterDetail param2 = new ViewParameterDetail.Builder().description("selection filter").valueClass(String.class).required(true).build();
Map<String, ViewParameterDetail> paramDetailMap = Maps.newHashMap();
paramDetailMap.put(IS_MORE_THAN_X_PARAM_KEY, param);
paramDetailMap.put(SELECTION_PARAM_KEY, param2);
// real View json with a parameter
final String extendedViewString = "{\n" + " \"edges\" : {\n" + " \"BasicEdge\" : {\n" + " \"preAggregationFilterFunctions\" : [ {\n" + " \"predicate\" : {\n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.IsMoreThan\",\n" + " \"orEqualTo\" : false,\n" + " \"value\" : \"${IS_MORE_THAN_X}\"\n" + " },\n" + " \"selection\" : [ \"${SELECTION}\" ]\n" + " } ]\n" + " }\n" + " },\n" + " \"entities\" : { }\n" + "}\n";
final NamedViewDetail extendedNamedViewDetail = new NamedViewDetail.Builder().name(NAMED_VIEW_NAME).view(extendedViewString).parameters(paramDetailMap).build();
given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(extendedNamedViewDetail);
final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).parameters(paramMap).build()).build()).build();
// When
RESOLVER.preExecute(opChain, CONTEXT);
GetElements getElements = (GetElements) opChain.getOperations().get(0);
// Then
assertTrue(new String(getElements.getView().toCompactJson()).contains(VALUE_JSON_STRING + 7));
assertTrue(new String(getElements.getView().toCompactJson()).contains("VERTEX"));
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.
the class NamedViewCache method add.
private void add(final NamedViewDetail namedViewDetail, final boolean overwrite, final User user, final String adminAuth) throws CacheOperationFailedException {
if (null != namedViewDetail.getName()) {
namedViewDetail.getName();
} else {
throw new CacheOperationFailedException("NamedView name cannot be null");
}
if (!overwrite) {
addToCache(namedViewDetail, false);
return;
}
NamedViewDetail existing;
try {
existing = getFromCache(namedViewDetail.getName());
} catch (final CacheOperationFailedException e) {
// if there is no existing NamedView add one
addToCache(namedViewDetail, false);
return;
}
if (user != null) {
if (existing.hasWriteAccess(user, adminAuth)) {
addToCache(namedViewDetail, true);
} else {
throw new CacheOperationFailedException("User " + user.getUserId() + " does not have permission to overwrite");
}
}
addToCache(namedViewDetail, true);
}
Aggregations