Search in sources :

Example 11 with Access

use of com.dexels.navajo.script.api.Access in project navajo by Dexels.

the class Dispatcher method getUsers.

public Access[] getUsers() {
    Set<Access> all = new HashSet<>(com.dexels.navajo.server.DispatcherFactory.getInstance().getAccessSet());
    Iterator<Access> iter = all.iterator();
    List<Access> d = new ArrayList<>();
    while (iter.hasNext()) {
        Access a = iter.next();
        d.add(a);
    }
    Access[] ams = new Access[d.size()];
    return d.toArray(ams);
}
Also used : Access(com.dexels.navajo.script.api.Access) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 12 with Access

use of com.dexels.navajo.script.api.Access in project navajo by Dexels.

the class SimpleNode method lazyBiFunction.

public ContextExpression lazyBiFunction(List<String> problems, String expression, BinaryOperator<Operand> func, BiFunction<Optional<String>, Optional<String>, Boolean> acceptTypes, BiFunction<Optional<String>, Optional<String>, Optional<String>> returnTypeResolver, Function<String, FunctionClassification> functionClassifier, Function<String, Optional<Node>> mapResolver) {
    ContextExpression expA = jjtGetChild(0).interpretToLambda(problems, expression, functionClassifier, mapResolver);
    ContextExpression expB = jjtGetChild(1).interpretToLambda(problems, expression, functionClassifier, mapResolver);
    Optional<String> aType = expA.returnType();
    Optional<String> bType = expB.returnType();
    boolean inputTypesValid = acceptTypes.apply(aType, bType);
    if (!inputTypesValid) {
        problems.add("Invalid input types in node: " + aType.orElse("unknown") + " and " + bType.orElse("unknown") + " in node type: " + this.getClass());
    }
    Optional<String> returnType = returnTypeResolver.apply(aType, bType);
    return new ContextExpression() {

        @Override
        public Operand apply(Navajo doc, Message parentMsg, Message parentParamMsg, Selection parentSel, MappableTreeNode mapNode, TipiLink tipiLink, Access access, Optional<ImmutableMessage> immutableMessage, Optional<ImmutableMessage> paramMessage) {
            Operand a = expA.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage);
            Operand b = expB.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage);
            return func.apply(a, b);
        }

        @Override
        public boolean isLiteral() {
            return expA.isLiteral() && expB.isLiteral();
        }

        @Override
        public Optional<String> returnType() {
            return returnType;
        }

        @Override
        public String expression() {
            return expression;
        }
    };
}
Also used : MappableTreeNode(com.dexels.navajo.script.api.MappableTreeNode) TipiLink(com.dexels.navajo.expression.api.TipiLink) Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Optional(java.util.Optional) Selection(com.dexels.navajo.document.Selection) Operand(com.dexels.navajo.document.Operand) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) Access(com.dexels.navajo.script.api.Access) Navajo(com.dexels.navajo.document.Navajo)

Example 13 with Access

use of com.dexels.navajo.script.api.Access in project navajo by Dexels.

the class TestHttpResource method setUp.

@Before
public void setUp() throws Exception {
    this.access = new Access();
    access.setTenant("MYTENANT");
    factory = new HttpResourceFactory();
    component = new ResourceComponent();
    RepositoryInstance instance = createStubInstance("test");
    component.setRepositoryInstance(instance);
    Map<String, Object> settings = new HashMap<String, Object>();
    String url = TestConfig.HTTP_TEST_URL.getValue();
    Assert.assertNotNull(url);
    settings.put("url", url);
    settings.put("name", "binstore");
    settings.put("authorization", TestConfig.HTTP_TEST_TOKEN.getValue());
    settings.put("secret", TestConfig.HTTP_TEST_SECRET.getValue());
    settings.put("expire", "120");
    component.activate(settings);
    factory.addHttpResource(component, settings);
    factory.activate();
}
Also used : ResourceComponent(com.dexels.navajo.resource.http.impl.ResourceComponent) HashMap(java.util.HashMap) RepositoryInstance(com.dexels.navajo.repository.api.RepositoryInstance) Access(com.dexels.navajo.script.api.Access) Before(org.junit.Before)

Example 14 with Access

use of com.dexels.navajo.script.api.Access in project navajo by Dexels.

the class GetBinaryFromStore method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    String resource = (String) getOperand(0);
    if (resource == null) {
        throw new TMLExpressionException("No resource defined in GetBinaryFromStore");
    }
    String bucket = (String) getOperand(1);
    if (bucket == null) {
        throw new TMLExpressionException("No bucket defined in GetBinaryFromStore");
    }
    Object idObj = getOperand(2);
    String id = null;
    if (idObj instanceof String) {
        id = (String) idObj;
    } else {
        id = idObj.toString();
    }
    if (id == null) {
        throw new TMLExpressionException("No id defined in GetBinaryFromStore");
    }
    Integer expiration = (Integer) super.getOperand(3);
    if (expiration == null) {
        throw new TMLExpressionException("No expiration defined in GetBinaryFromStore");
    }
    Access access = this.getAccess();
    String tenant = access.getTenant();
    HttpResourceFactory instance = HttpResourceFactory.getInstance();
    if (instance == null) {
        throw new TMLExpressionException("No HttpResourceFactory found in GetBinaryFromStore");
    }
    HttpResource httpResource = instance.getHttpResource(resource);
    if (httpResource == null) {
        throw new TMLExpressionException("HttpResource: " + resource + " not found in GetBinaryFromStore");
    }
    return httpResource.expiringURL(tenant, bucket, id, expiration);
}
Also used : HttpResourceFactory(com.dexels.navajo.resource.http.HttpResourceFactory) HttpResource(com.dexels.navajo.resource.http.HttpResource) Access(com.dexels.navajo.script.api.Access) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 15 with Access

use of com.dexels.navajo.script.api.Access in project navajo by Dexels.

the class AsyncMappable method log.

private final void log() {
    if (DispatcherFactory.getInstance().getNavajoConfig().getStatisticsRunner() != null && !logged) {
        Access a = AsyncStore.getInstance().getAccessObject(this.pointer);
        if (a != null) {
            // determine total time.
            a.setFinished();
            UserException ue = null;
            if (isKilled()) {
                ue = new UserException(-1, "Killed by client");
                if (caught != null) {
                    a.setException(caught);
                } else {
                    a.setException(ue);
                }
            }
            logged = true;
            DispatcherFactory.getInstance().getNavajoConfig().getStatisticsRunner().addAccess(a, this);
        } else {
            AuditLog.log(AuditLog.AUDIT_MESSAGE_ASYNC_RUNNER, "Warning: could not log async access due to missing access object!");
        }
    }
}
Also used : Access(com.dexels.navajo.script.api.Access) UserException(com.dexels.navajo.script.api.UserException)

Aggregations

Access (com.dexels.navajo.script.api.Access)45 Navajo (com.dexels.navajo.document.Navajo)29 Message (com.dexels.navajo.document.Message)27 Test (org.junit.Test)18 Property (com.dexels.navajo.document.Property)15 Selection (com.dexels.navajo.document.Selection)14 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)12 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)12 TipiLink (com.dexels.navajo.expression.api.TipiLink)12 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)12 Optional (java.util.Optional)12 Operand (com.dexels.navajo.document.Operand)10 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)10 ArrayList (java.util.ArrayList)8 UserException (com.dexels.navajo.script.api.UserException)6 ResultMessage (com.dexels.navajo.adapter.messagemap.ResultMessage)5 Binary (com.dexels.navajo.document.types.Binary)4 HttpResource (com.dexels.navajo.resource.http.HttpResource)4 HttpResourceFactory (com.dexels.navajo.resource.http.HttpResourceFactory)4 Dispatcher (com.dexels.navajo.server.Dispatcher)4