Search in sources :

Example 21 with NamedViewDetail

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"));
}
Also used : ViewParameterDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) Test(org.junit.jupiter.api.Test)

Example 22 with NamedViewDetail

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);
}
Also used : CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)

Aggregations

NamedViewDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)22 Test (org.junit.jupiter.api.Test)16 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)10 NamedView (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView)9 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)7 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)7 CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException)5 ViewParameterDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail)4 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)3 AccessPredicate (uk.gov.gchq.gaffer.access.predicate.AccessPredicate)2 UnrestrictedAccessPredicate (uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate)2 NamedViewWriteAccessPredicate (uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate)2 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)2 GetAllNamedViews (uk.gov.gchq.gaffer.named.view.GetAllNamedViews)2 HashSet (java.util.HashSet)1 CustomUserPredicate (uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate)1 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)1 RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator (uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 AddNamedView (uk.gov.gchq.gaffer.named.view.AddNamedView)1