use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class CallService method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
Operand result = null;
String serviceName = getStringOperand(0);
String expression = getOperands().size() == 1 ? null : getStringOperand(1);
if (getNavajo() == null) {
throw new TMLExpressionException("No Navajo Request object available.");
}
if (getOperands().size() > 2) {
throw new TMLExpressionException("Invalid number of parameters.");
}
try {
Navajo response = getNavajo().getNavajo(serviceName);
if (response == null) {
DispatcherInterface dispatcher = DispatcherFactory.getInstance();
Navajo input = getNavajo().copy();
input.getHeader().setRPCName(serviceName);
response = dispatcher.handle(input, this.getAccess().getTenant(), true);
getNavajo().addNavajo(serviceName, response);
}
if (expression == null) {
Binary bbb = new Binary();
OutputStream os = bbb.getOutputStream();
response.write(os);
os.flush();
os.close();
return bbb;
} else {
result = Expression.evaluate(expression, response);
}
} catch (Exception ex) {
logger.error("Error: ", ex);
}
if (result != null) {
return result.value;
} else {
return null;
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class Base64Encode method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
Object o = operand(0).value;
String data = null;
if (o instanceof Binary) {
Binary b = (Binary) o;
data = Base64.getEncoder().encodeToString(b.getData());
} else if (o instanceof String) {
data = Base64.getEncoder().encodeToString(((String) o).getBytes(StandardCharsets.UTF_8));
} else if (o instanceof Property && ((Property) o).getType() == Property.BINARY_PROPERTY) {
data = ((Property) o).getValue();
} else {
throw new TMLExpressionException("Can not Base64Encode null data");
}
return data;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetSelectedName method evaluate.
@Override
@SuppressWarnings("unchecked")
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() != 1) {
throw new TMLExpressionException(this, "Invalid function call, need one parameter");
}
Object o = operand(0).value;
if (o == null) {
throw new TMLExpressionException(this, "Invalid function call in GetSelectedName: Parameter null");
}
if (o instanceof Property) {
Property p = (Property) o;
if (p.getSelected() != null) {
return (p.getAllSelectedSelections().size() > 0 ? p.getSelected().getName() : null);
} else {
return null;
}
}
if (!(o instanceof List)) {
throw new TMLExpressionException(this, "Invalid function call in GetSelectedName: Not a selection property, but (" + o.getClass() + ")");
}
List<Selection> l = (List<Selection>) o;
for (Selection selection : l) {
if (selection.isSelected()) {
return selection.getName();
}
}
return null;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetUrlModificationTime method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
// input (ArrayList, Object).
if (this.getOperands().size() != 1)
throw new TMLExpressionException("GetUrlModificationTime(String) expected");
Object a = this.getOperands().get(0);
if (a == null) {
return null;
}
if (!(a instanceof String))
throw new TMLExpressionException("GetUrlModificationTime(String) expected");
URL u;
try {
u = new URL((String) a);
} catch (MalformedURLException e) {
throw new TMLExpressionException("CheckUrl: bad url: " + a);
}
return getUrlDate(u);
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetValue method evaluate.
@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() != 1) {
throw new TMLExpressionException(this, "Invalid function call, need one parameter");
}
Object o = getOperand(0);
if (o == null) {
throw new TMLExpressionException(this, "Invalid function call in GetSelectedValue: Parameter null");
}
if (!(o instanceof Property)) {
throw new TMLExpressionException(this, "Invalid function call in GetValue: Not a property, this is a: " + o.getClass() + " and it goes like this: " + o);
}
Property p = (Property) o;
return p.getTypedValue();
}
Aggregations