use of com.dexels.navajo.document.types.NavajoExpression in project navajo by Dexels.
the class MessageMap method setJoinCondition.
public void setJoinCondition(Object jco) throws UserException {
if (jco instanceof String) {
String c = (String) jco;
String[] conditions = c.split(",");
for (int i = 0; i < conditions.length; i++) {
if (conditions[i].split("=").length != 2) {
throw new UserException(-1, "Exception joining messages " + joinMessage1 + " and " + joinMessage2 + ": invalid join condition: " + c);
}
String prop1 = conditions[i].split("=")[0];
String prop2 = conditions[i].split("=")[1];
JoinCondition jc = new JoinCondition();
jc.property1 = prop1;
jc.property2 = prop2;
joinConditions.add(jc);
}
} else if (jco instanceof NavajoExpression) {
joinExpression = (NavajoExpression) jco;
} else {
throw new UserException(-1, "Invalid joincondition type: " + jco);
}
}
use of com.dexels.navajo.document.types.NavajoExpression in project navajo by Dexels.
the class MappingUtils method setProperty.
public static final Property setProperty(boolean parameter, Message msg, String name, Object value, String type, String subtype, String direction, String description, int length, Navajo outputDoc, Navajo tmlDoc, boolean remove) throws MappingException {
Message ref = null;
if (parameter) {
if (msg == null) {
msg = tmlDoc.getMessage("__parms__");
if (msg == null) {
// Create __parms__ message.
msg = NavajoFactory.getInstance().createMessage(tmlDoc, "__parms__");
tmlDoc.addMessage(msg);
}
}
ref = getMessageObject(name, msg, false, tmlDoc, false, "", -1);
if (ref == null) {
// Can be null due to absolute param name (starting with '/'). In this case use
// __parms__ as parent.
ref = tmlDoc.getMessage("__parms__");
}
} else {
ref = getMessageObject(name, msg, false, outputDoc, false, "", -1);
}
if (ref == null) {
ref = msg;
}
String actualName = getStrippedPropertyName(name);
if (ref == null) {
throw new MappingException("Property can only be created under a message");
}
// with ../ constructions in the name of the new property, it is possible to create a property at the rootMessage of a NavajoDoc but that will never be serialized. Logger message to see how often it happens
if (ref.equals(ref.getRootDoc().getRootMessage())) {
logger.warn("WARNING - Adding property to rootMessage of NavajoDoc - property will not be findable");
}
Property prop = ref.getProperty(actualName);
// Remove a parameter if remove flag is set.
if (remove && prop != null && parameter) {
ref.removeProperty(prop);
return null;
}
if (prop == null && remove && parameter) {
return null;
}
if (prop == null) {
// Property does not exist.
if (!parameter) {
if (value instanceof Property) {
// Value is a property itself!
prop = (Property) ((Property) value).clone(name);
} else if (Property.SELECTION_PROPERTY.equals(type)) {
prop = ref.getRootDoc().getNavajoFactory().createProperty(outputDoc, actualName, "1", description, direction);
if (value instanceof Selection[]) {
prop.setCardinality("+");
prop.setValue((Selection[]) value);
}
} else if (Property.BINARY_PROPERTY.equals(type)) {
prop = ref.getRootDoc().getNavajoFactory().createProperty(outputDoc, actualName, type, "", length, description, direction);
if (value instanceof Binary) {
prop.setValue((Binary) value);
}
} else {
// Legacy mode hack, many scripts do not expect null valued string properties.
if (Property.STRING_PROPERTY.equals(type) && value == null) {
value = "";
}
prop = ref.getRootDoc().getNavajoFactory().createProperty(outputDoc, actualName, type, "", length, description, direction);
if ((value instanceof StringLiteral)) {
value = value.toString();
}
prop.setAnyValue(value);
prop.setType(type);
}
} else {
if (Property.EXPRESSION_LITERAL_PROPERTY.equals(type)) {
prop = ref.getRootDoc().getNavajoFactory().createProperty(tmlDoc, actualName, type, "", length, description, direction);
prop.setValue(new NavajoExpression(value.toString()));
prop.setType(type);
} else if (Property.SELECTION_PROPERTY.equals(type)) {
prop = ref.getRootDoc().getNavajoFactory().createProperty(tmlDoc, actualName, "1", description, direction);
if (value instanceof Selection[]) {
prop.setCardinality("+");
prop.setValue((Selection[]) value);
}
} else if (Property.BINARY_PROPERTY.equals(type)) {
prop = ref.getRootDoc().getNavajoFactory().createProperty(tmlDoc, actualName, type, "", length, description, direction);
if (value instanceof Binary) {
prop.setValue((Binary) value);
}
} else {
prop = ref.getRootDoc().getNavajoFactory().createProperty(tmlDoc, actualName, type, "", length, description, direction);
if ((value instanceof StringLiteral)) {
value = value.toString();
}
prop.setAnyValue(value);
prop.setType(type);
}
}
ref.addProperty(prop);
} else {
// Existing property.
prop.clearValue();
if (value instanceof Property) {
// Value is a property itself!
prop = (Property) ((Property) value).clone(name);
} else if (Property.BINARY_PROPERTY.equals(type)) {
if (value instanceof Binary) {
prop.setValue((Binary) value);
} else {
prop.clearValue();
}
} else if (Property.SELECTION_PROPERTY.equals(type) && value != null && value instanceof Selection[]) {
prop.setCardinality("+");
prop.setValue((Selection[]) value);
} else if (!Property.SELECTION_PROPERTY.equals(type)) {
if (value != null) {
if ((value instanceof StringLiteral)) {
prop.setUnCheckedStringAsValue(((StringLiteral) value).toString());
} else {
prop.setAnyValue(value);
}
} else {
prop.clearValue();
}
}
if (Property.DIR_IN.equals(direction) || Property.DIR_OUT.equals(direction)) {
prop.setDirection(direction);
}
prop.setType(type);
// Should not matter ;)
prop.setName(actualName);
}
// Set subtype if not empty.
if (subtype != null && !subtype.equals("")) {
prop.setSubType(subtype);
}
// Set description if not empty.
if (description != null && !description.equals("")) {
prop.setDescription(description);
}
// Set length if not empty ( = -1) .
if (length != -1) {
prop.setLength(length);
}
return prop;
}
use of com.dexels.navajo.document.types.NavajoExpression in project navajo by Dexels.
the class BasePropertyImpl method getTypedValue.
/**
* Get the value of a property as a Java object.
*
* @return
*/
@Override
public final Object getTypedValue() {
if (getType().equals(Property.STRING_PROPERTY)) {
return getValue();
}
if (getType().equals(Property.BOOLEAN_PROPERTY)) {
if (getValue() != null && !getValue().equals("")) {
return Boolean.valueOf(getValue().equalsIgnoreCase("true"));
} else {
return null;
}
}
if (getType().equals(EXPRESSION_LITERAL_PROPERTY)) {
if (getValue() != null && !getValue().equals("")) {
return new NavajoExpression(getValue());
} else {
return null;
}
}
if (getType().equals(EXPRESSION_PROPERTY)) {
if (evaluatedValue == null) {
evaluatedValue = getEvaluatedValue();
return evaluatedValue;
} else {
return evaluatedValue;
}
}
if (getType().equals(Property.PERCENTAGE_PROPERTY)) {
if (getValue() != null) {
return new Percentage(getValue());
} else {
return null;
}
}
if (getType().equals(Property.MONEY_PROPERTY)) {
if (getValue() == null || "".equals(getValue())) {
return new Money((Double) null, getSubType());
}
String val = getValue();
NumberFormat fn = NumberFormat.getNumberInstance(Locale.US);
Number parse;
try {
parse = fn.parse(val);
} catch (ParseException e) {
return null;
}
return new Money(parse.doubleValue(), getSubType());
} else if (getType().equals(Property.CLOCKTIME_PROPERTY)) {
if (getValue() == null || getValue().equals("")) {
return null;
}
try {
return new ClockTime(getValue(), getSubType());
} catch (Exception e) {
logger.error("Error: ", e);
}
} else if (getType().equals(Property.STOPWATCHTIME_PROPERTY)) {
try {
return new StopwatchTime(getValue(), getSubType());
} catch (Exception e) {
logger.error("Error: ", e);
}
} else if (getType().equals(Property.DATE_PROPERTY) || getType().equals(Property.TIMESTAMP_PROPERTY)) {
if (getValue() == null || getValue().equals("") || getValue().equals("null")) {
return null;
}
if (myDate != null) {
return myDate;
}
// Try in order from most specific to least specific
try {
return timestampFormat.get().parse(getValue());
} catch (Exception ex) {
try {
return dateFormat4.get().parse(getValue());
} catch (Exception ex2) {
try {
return dateFormat1.get().parse(getValue());
} catch (Exception ex3) {
try {
return dateFormat2.get().parse(getValue());
} catch (Exception ex4) {
try {
Long l = Long.parseLong(getValue());
Date d = new java.util.Date();
d.setTime(l);
return d;
} catch (Exception e5) {
logger.info("Sorry I really can't parse that date: {}", getValue());
return null;
}
}
}
}
}
} else if (getType().equals(Property.INTEGER_PROPERTY)) {
if (getValue() == null || getValue().equals("") || getValue().trim().equals("null")) {
return null;
}
try {
return Integer.valueOf(Integer.parseInt(getValue().trim()));
} catch (NumberFormatException ex3) {
logger.info("Numberformat exception...: {}", getValue().trim());
return null;
}
} else if (getType().equals(Property.LONG_PROPERTY)) {
if (getValue() == null || getValue().equals("")) {
return null;
}
try {
// Added a trim. Frank.
return Long.valueOf(Long.parseLong(getValue().trim()));
} catch (NumberFormatException ex3) {
logger.info("Numberformat exception...");
return null;
}
} else if (getType().equals(Property.FLOAT_PROPERTY)) {
if (getValue() == null || getValue().equals("")) {
return null;
}
String v = getValue();
String w = v;
// Sometimes the number formatting creates
if (v.indexOf(',') != -1) {
w = v.replaceAll(",", "");
}
Double d;
try {
d = Double.valueOf(Double.parseDouble(w));
} catch (NumberFormatException ex) {
logger.info("Can not format double with: {}", w);
return null;
}
return d;
} else if (getType().equals(Property.BINARY_PROPERTY)) {
try {
return myBinary;
} catch (Exception e) {
logger.error("Error: ", e);
}
} else if (getType().equals(Property.SELECTION_PROPERTY)) {
return getAllSelectedSelections();
} else if (getType().equals(Property.TIPI_PROPERTY)) {
return tipiProperty;
} else if (getType().equals(Property.LIST_PROPERTY)) {
if (tipiProperty != null || myValue == null) {
return tipiProperty;
}
try {
if (myValue.indexOf('[') == 0) {
// Parse back into a list
String stripped = myValue.substring(1, myValue.length() - 1);
tipiProperty = Arrays.asList(stripped.split(", "));
return tipiProperty;
} else if (myValue.length() > 0) {
logger.info("Failed to parse {} as a list!", myValue);
}
} catch (Exception e) {
logger.warn("Exception on parsing {} as a list!", myValue, e);
}
return null;
} else if (getType().equals(Property.BINARY_DIGEST_PROPERTY)) {
return new BinaryDigest(getValue());
} else if (getType().equals(Property.COORDINATE_PROPERTY)) {
try {
return new Coordinate(myValue);
} catch (Exception e) {
logger.error("Cannot create Coordinate Property: ", e);
}
}
return getValue();
}
Aggregations