Search in sources :

Example 41 with Access

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

the class TestNavajoMap method testSendThroughSetFalse.

@Test
public void testSendThroughSetFalse() throws MappableException, UserException {
    Navajo inDoc = NavajoFactory.getInstance().createNavajo();
    Property property = NavajoFactory.getInstance().createProperty(inDoc, "Meaning", INTEGER_PROPERTY, "42", 0, "", "out");
    Message message = NavajoFactory.getInstance().createMessage(inDoc, "SendThrough");
    message.addProperty(property);
    inDoc.addMessage(message);
    Message global = NavajoFactory.getInstance().createMessage(inDoc, "Global");
    global.setScope(Message.MSG_SCOPE_GLOBAL);
    inDoc.addMessage(global);
    Message local = NavajoFactory.getInstance().createMessage(inDoc, "Local");
    local.setScope(Message.MSG_SCOPE_LOCAL);
    inDoc.addMessage(local);
    // Initialize the navajomap.
    DispatcherFactory.createDispatcher(new Dispatcher());
    Access access = new Access();
    access.setInDoc(inDoc);
    access.setOutputDoc(outDoc);
    map.load(access);
    map.setSendThrough(false);
    map.prepareOutDoc();
    assertFalse(map.getSendThrough());
    assertNull(map.outDoc.getMessage("SendThrough"));
    assertEquals(Message.MSG_SCOPE_GLOBAL, map.outDoc.getMessage("Global").getScope());
    assertNull(map.outDoc.getMessage("Local"));
}
Also used : Message(com.dexels.navajo.document.Message) Access(com.dexels.navajo.script.api.Access) Navajo(com.dexels.navajo.document.Navajo) Dispatcher(com.dexels.navajo.server.Dispatcher) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 42 with Access

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

the class ExistsBinaryInStore method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    String resource = (String) super.getOperand(0);
    if (resource == null) {
        throw new TMLExpressionException("No resource defined in ExistsBinaryInStore");
    }
    String bucket = (String) super.getOperand(1);
    if (bucket == null) {
        throw new TMLExpressionException("No bucket defined in ExistsBinaryInStore");
    }
    String id = (String) super.getOperand(2);
    if (id == null) {
        throw new TMLExpressionException("No id defined in ExistsBinaryInStore");
    }
    Access access = this.getAccess();
    if (access == null) {
        throw new TMLExpressionException("No access defined in ExistsBinaryInStore");
    }
    String tenant = access.getTenant();
    if (tenant == null) {
        throw new TMLExpressionException("No tenant defined in ExistsBinaryInStore");
    }
    HttpResourceFactory instance = HttpResourceFactory.getInstance();
    if (instance == null) {
        throw new TMLExpressionException("No HttpResourceFactory found in ExistsBinaryInStore");
    }
    HttpResource httpResource = instance.getHttpResource(resource);
    if (httpResource == null) {
        throw new TMLExpressionException("HttpResource: " + resource + " found in ExistsBinaryInStore");
    }
    return httpResource.head(tenant, bucket, id).blockingGet().status() < 400;
}
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 43 with Access

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

the class StoreBinary method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    String resource = (String) super.getOperand(0);
    if (resource == null) {
        throw new TMLExpressionException("No resource defined in PutBinary");
    }
    String bucket = (String) super.getOperand(1);
    if (bucket == null) {
        throw new TMLExpressionException("No bucket defined in PutBinary");
    }
    Binary binary = (Binary) super.getOperand(2);
    if (binary == null) {
        throw new TMLExpressionException("No binary defined in PutBinary");
    }
    Access access = this.getAccess();
    if (access == null) {
        throw new TMLExpressionException("No access defined in PutBinary");
    }
    String tenant = access.getTenant();
    if (tenant == null) {
        throw new TMLExpressionException("No tenant defined in PutBinary");
    }
    HttpResourceFactory instance = HttpResourceFactory.getInstance();
    if (instance == null) {
        throw new TMLExpressionException("No HttpResourceFactory found in PutBinary");
    }
    HttpResource httpResource = instance.getHttpResource(resource);
    if (httpResource == null) {
        throw new TMLExpressionException("HttpResource: " + resource + " found in PutBinary");
    }
    return httpResource.put(tenant, bucket, binary.getHexDigest(), binary).blockingGet().status();
}
Also used : HttpResourceFactory(com.dexels.navajo.resource.http.HttpResourceFactory) HttpResource(com.dexels.navajo.resource.http.HttpResource) Access(com.dexels.navajo.script.api.Access) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 44 with Access

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

the class DeleteBinary method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    String resource = (String) super.getOperand(0);
    if (resource == null) {
        throw new TMLExpressionException("No resource defined in DeleteBinary");
    }
    String bucket = (String) super.getOperand(1);
    if (bucket == null) {
        throw new TMLExpressionException("No bucket defined in DeleteBinary");
    }
    String id = (String) super.getOperand(2);
    if (id == null) {
        throw new TMLExpressionException("No id defined in GetBinary");
    }
    Access access = this.getAccess();
    if (access == null) {
        throw new TMLExpressionException("No access defined in DeleteBinary");
    }
    String tenant = access.getTenant();
    if (tenant == null) {
        throw new TMLExpressionException("No tenant defined in DeleteBinary");
    }
    HttpResourceFactory instance = HttpResourceFactory.getInstance();
    if (instance == null) {
        throw new TMLExpressionException("No HttpResourceFactory found in DeleteBinary");
    }
    HttpResource httpResource = instance.getHttpResource(resource);
    if (httpResource == null) {
        throw new TMLExpressionException("HttpResource: " + resource + " found in DeleteBinary");
    }
    return httpResource.delete(tenant, bucket, id).blockingGet().status();
}
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 45 with Access

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

the class TestMailResource method testAttach.

@Test
@Ignore
public void testAttach() throws MappableException, UserException {
    ResourceMailAdapter rma = new ResourceMailAdapter();
    try {
        rma.load(new Access());
        rma.setRecipients("dexels@gmail.com");
        rma.setSender("dexels@gmail.com");
        rma.setSubject("Attachment at " + new Date());
        AttachementMap am = new AttachementMap();
        am.setAttachContentType("image/jpeg");
        am.setAttachContentDisposition("inline");
        am.setAttachFileContent(new Binary(getClass().getResourceAsStream("monkey.jpeg")));
        rma.setAttachment(am);
        rma.setResourceName("junit.mail");
        rma.store();
    } catch (UserException e) {
        Assert.assertEquals("javax.mail.AuthenticationFailedException", e.getCause().toString());
    }
}
Also used : Access(com.dexels.navajo.script.api.Access) AttachementMap(com.dexels.navajo.adapter.mailmap.AttachementMap) Binary(com.dexels.navajo.document.types.Binary) UserException(com.dexels.navajo.script.api.UserException) Date(java.util.Date) Ignore(org.junit.Ignore) Test(org.junit.Test)

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