Search in sources :

Example 6 with ClockTime

use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.

the class TestProperty method tesSetAnyValue.

@Test
public void tesSetAnyValue() {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Property p1 = NavajoFactory.getInstance().createProperty(n, "Aap", "", "", "");
    // String
    p1.setAnyValue("Apenoot");
    assertEquals("string", p1.getType());
    assertEquals("Apenoot", p1.getValue());
    assertTrue(p1.getTypedValue().equals("Apenoot"));
    // Integer
    p1.setAnyValue(Integer.valueOf(50));
    assertEquals("integer", p1.getType());
    assertEquals("50", p1.getValue());
    assertTrue(p1.getTypedValue().equals(Integer.valueOf(50)));
    // Double
    p1.setAnyValue(Double.valueOf(50));
    assertEquals("float", p1.getType());
    assertEquals("50.0", p1.getValue());
    assertTrue(p1.getTypedValue().equals(Double.valueOf(50)));
    // Float
    p1.setAnyValue(Float.valueOf(50));
    assertEquals("float", p1.getType());
    assertEquals("50.0", p1.getValue());
    assertTrue(p1.getTypedValue().equals(Double.valueOf(50)));
    // Date
    Date d = new java.util.Date();
    p1.setAnyValue(d);
    String expectedFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS").format(d);
    assertEquals("date", p1.getType());
    assertEquals(expectedFormat, p1.getValue());
    assertTrue(p1.getTypedValue().equals(d));
    // Long
    p1.setAnyValue(Long.valueOf(10));
    assertEquals("long", p1.getType());
    assertEquals("10", p1.getValue());
    assertTrue(p1.getTypedValue().equals(Long.valueOf(10)));
    // Boolean
    p1.setAnyValue(Boolean.TRUE);
    assertEquals("boolean", p1.getType());
    assertEquals("true", p1.getValue());
    assertTrue(p1.getTypedValue().equals(Boolean.TRUE));
    // Binary
    Binary b = new Binary("Mooie array".getBytes());
    p1.setAnyValue(b);
    assertEquals("binary", p1.getType());
    Binary b1 = (Binary) p1.getTypedValue();
    String expected = new String(b1.getData());
    assertEquals("Mooie array", expected);
    // Money
    p1.setAnyValue(new Money(5000));
    assertEquals("money", p1.getType());
    assertEquals("5000.00", p1.getValue());
    assertTrue(p1.getTypedValue().equals(new Money(5000)));
    // ClockTime
    Date d1 = new java.util.Date();
    ClockTime ct = new ClockTime(d1);
    String expectedFormat2 = ct.toString();
    p1.setAnyValue(ct);
    assertEquals("clocktime", p1.getType());
    assertEquals(expectedFormat2, p1.getValue());
    assertTrue(p1.getTypedValue().equals(new ClockTime(d1)));
    // StopwatchTime
    Date d2 = new java.util.Date();
    String format = new SimpleDateFormat("HH:mm:ss:SSS").format(d2);
    StopwatchTime swt = new StopwatchTime(format);
    p1.setAnyValue(swt);
    assertEquals("stopwatchtime", p1.getType());
    logger.info("FORM: {} val: {}", format, p1.getValue());
    assertEquals(format, p1.getValue());
    assertTrue(p1.getTypedValue().equals(new StopwatchTime(format)));
    // Percentage
    Percentage p = new Percentage(50);
    p1.setAnyValue(p);
    assertEquals("percentage", p1.getType());
    assertEquals("50.0", p1.getValue());
    assertTrue(p1.getTypedValue().equals(new Percentage(50)));
}
Also used : StopwatchTime(com.dexels.navajo.document.types.StopwatchTime) Money(com.dexels.navajo.document.types.Money) Percentage(com.dexels.navajo.document.types.Percentage) Navajo(com.dexels.navajo.document.Navajo) Binary(com.dexels.navajo.document.types.Binary) ClockTime(com.dexels.navajo.document.types.ClockTime) Property(com.dexels.navajo.document.Property) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 7 with ClockTime

use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.

the class DateAppendClockTime method evaluate.

@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    // Arguments number check
    if (this.getOperands().size() != 2) {
        throw new TMLExpressionException(this, "error: arguements missing. Please provide a valid Date and a valid ClockTime object.");
    }
    Object arg0 = this.getOperand(0);
    Object arg1 = this.getOperand(1);
    // Arguments type checks
    if (!(arg0 instanceof Date)) {
        throw new TMLExpressionException(this, "error: arguement 0 must be a Date object. The argument you supplied is : " + this.getOperand(0).getClass());
    }
    if (!(arg1 instanceof ClockTime)) {
        throw new TMLExpressionException(this, "error: argument 1 must be a ClockTime. The argument you supplied is : " + this.getOperand(1).getClass());
    }
    Date date = (Date) arg0;
    ClockTime cTime = (ClockTime) arg1;
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.SECOND, cTime.getSeconds());
    calendar.set(Calendar.MINUTE, cTime.getMinutes());
    calendar.set(Calendar.HOUR, cTime.getHours());
    return calendar.getTime();
}
Also used : Calendar(java.util.Calendar) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) ClockTime(com.dexels.navajo.document.types.ClockTime) Date(java.util.Date)

Example 8 with ClockTime

use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.

the class NavajoLaszloConverter method appendProperties.

private static void appendProperties(Message m, Element e, Document d) {
    try {
        List<Property> allProp = m.getAllProperties();
        for (int i = 0; i < allProp.size(); i++) {
            Property current = allProp.get(i);
            Element prop = d.createElement("p_" + current.getName());
            if (current.getType().equals(Property.DATE_PROPERTY)) {
                DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                if (current.getTypedValue() != null) {
                    prop.setAttribute("value", df.format((Date) current.getTypedValue()));
                } else {
                    prop.setAttribute("value", current.getValue());
                }
            } else if (current.getType().equals(Property.CLOCKTIME_PROPERTY)) {
                ClockTime ct = (ClockTime) current.getTypedValue();
                if (ct != null) {
                    Date dv = ct.dateValue();
                    DateFormat dfct = new SimpleDateFormat("HH:mm");
                    prop.setAttribute("value", dfct.format(dv));
                } else {
                    prop.setAttribute("value", current.getValue());
                }
            } else {
                prop.setAttribute("value", current.getValue());
            }
            prop.setAttribute("description", current.getDescription());
            prop.setAttribute("direction", current.getDirection());
            prop.setAttribute("type", current.getType());
            prop.setAttribute("subtype", current.getSubType());
            prop.setAttribute("length", "" + current.getLength());
            if (current.getType().equals(Property.SELECTION_PROPERTY)) {
                List<Selection> sel = current.getAllSelections();
                for (int j = 0; j < sel.size(); j++) {
                    Selection s = sel.get(j);
                    Element option = d.createElement("option");
                    option.setAttribute("value", s.getValue());
                    option.setAttribute("name", s.getName());
                    option.setAttribute("selected", "" + s.isSelected());
                    prop.appendChild(option);
                }
            }
            e.appendChild(prop);
        }
    } catch (Exception ex) {
        logger.error("Error: ", ex);
    }
}
Also used : Element(org.w3c.dom.Element) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ClockTime(com.dexels.navajo.document.types.ClockTime) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 9 with ClockTime

use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.

the class JsonTmlConverterImpl method toMessage.

@Override
public Message toMessage(String messageName, ImmutableMessage message, Navajo rootNavajo) {
    Message cV = NavajoFactory.getInstance().createMessage(rootNavajo, messageName);
    for (String columnName : message.columnNames()) {
        String type = message.columnType(columnName);
        Object value = message.value(columnName).orElse(null);
        Property colProp = NavajoFactory.getInstance().createProperty(rootNavajo, columnName, type, null, 0, "", Property.DIR_OUT);
        switch(type) {
            case Property.CLOCKTIME_PROPERTY:
                if (value != null) {
                    ClockTime ct = new ClockTime((Date) value);
                    colProp.setAnyValue(ct);
                }
                colProp.setType(type);
                break;
            default:
                colProp.setAnyValue(value);
                colProp.setType(type);
                break;
        }
        cV.addProperty(colProp);
    }
    for (Entry<String, List<ImmutableMessage>> e : message.subMessageListMap().entrySet()) {
        Message subArrayMessage = NavajoFactory.getInstance().createMessage(rootNavajo, e.getKey(), Message.MSG_TYPE_ARRAY);
        cV.addMessage(subArrayMessage);
        for (ImmutableMessage elt : e.getValue()) {
            Message msgElt = toMessage(e.getKey(), elt, rootNavajo);
            subArrayMessage.addElement(msgElt);
        }
    }
    for (Entry<String, ImmutableMessage> e : message.subMessageMap().entrySet()) {
        Message msgElt = toMessage(e.getKey(), e.getValue(), rootNavajo);
        cV.addMessage(msgElt);
    }
    return cV;
}
Also used : Message(com.dexels.navajo.document.Message) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) List(java.util.List) ClockTime(com.dexels.navajo.document.types.ClockTime) Property(com.dexels.navajo.document.Property)

Example 10 with ClockTime

use of com.dexels.navajo.document.types.ClockTime in project navajo by Dexels.

the class SPMap method getOutputParameter.

public Object getOutputParameter(Integer i) throws UserException {
    int index = i.intValue();
    // logger.info("in getOutputParameter("+index+")");
    Object value = null;
    if (callStatement != null) {
        try {
            // logger.info("parameters = " + parameters);
            if (index > parameters.size()) {
                throw new UserException(-1, "Outputparameter index out of range: " + i.intValue());
            }
            String type = (String) parameters.get(index - 1);
            if (lookupTable.get(type) == null) {
                throw new UserException(-1, "Outputparameter index out of range, trying to read a normal parameter as an output parameter: " + i.intValue());
            }
            int sqlType = ((Integer) lookupTable.get(type)).intValue();
            java.util.Calendar c = java.util.Calendar.getInstance();
            switch(sqlType) {
                case Types.VARCHAR:
                case Types.CHAR:
                    value = callStatement.getString(index);
                    break;
                case Types.BIT:
                    value = Boolean.valueOf(callStatement.getBoolean(index));
                    break;
                case Types.DATE:
                    if (callStatement.getDate(index) != null) {
                        Date d = callStatement.getDate(index, c);
                        long l = d.getTime();
                        value = new java.util.Date(l);
                    }
                    break;
                case // For Oracle; timestamp with timezone, treat this as clocktime.
                -101:
                    if (callStatement.getTimestamp(index) != null) {
                        Timestamp ts = callStatement.getTimestamp(index, c);
                        long l = ts.getTime();
                        value = new ClockTime(new java.util.Date(l));
                    }
                    break;
                case Types.TIMESTAMP:
                    if (callStatement.getTimestamp(index) != null) {
                        Timestamp ts = callStatement.getTimestamp(index, c);
                        long l = ts.getTime();
                        value = new java.util.Date(l);
                    }
                    break;
                case Types.INTEGER:
                    value = Integer.valueOf(callStatement.getInt(index));
                    break;
                case Types.NUMERIC:
                    ResultSetMetaData meta = callStatement.getMetaData();
                    int prec = meta.getPrecision(index);
                    int scale = meta.getScale(index);
                    if (scale == 0) {
                        value = Integer.valueOf(callStatement.getInt(index));
                    } else {
                        value = Double.valueOf(callStatement.getString(index));
                    }
                    break;
                case Types.SMALLINT:
                case Types.TINYINT:
                    value = Integer.valueOf(callStatement.getInt(index));
                    break;
                case Types.DOUBLE:
                case Types.FLOAT:
                    value = Double.valueOf(callStatement.getDouble(index));
                    break;
                default:
                    value = callStatement.getString(index);
                    break;
            }
        } catch (SQLException sqle) {
            AuditLog.log("SPMap", sqle.getLocalizedMessage() + "/" + sqle.getSQLState(), sqle, Level.SEVERE, myAccess.accessID);
            throw new UserException(-1, sqle.getMessage(), sqle);
        }
        return value;
    } else {
        return "";
    }
}
Also used : SQLException(java.sql.SQLException) ClockTime(com.dexels.navajo.document.types.ClockTime) Timestamp(java.sql.Timestamp) Date(java.sql.Date) ResultSetMetaData(java.sql.ResultSetMetaData) UserException(com.dexels.navajo.script.api.UserException)

Aggregations

ClockTime (com.dexels.navajo.document.types.ClockTime)24 Date (java.util.Date)14 Test (org.junit.Test)8 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)7 Money (com.dexels.navajo.document.types.Money)6 Percentage (com.dexels.navajo.document.types.Percentage)6 StopwatchTime (com.dexels.navajo.document.types.StopwatchTime)5 Calendar (java.util.Calendar)5 Navajo (com.dexels.navajo.document.Navajo)4 Property (com.dexels.navajo.document.Property)4 Binary (com.dexels.navajo.document.types.Binary)4 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)3 Message (com.dexels.navajo.document.Message)3 Date (java.sql.Date)3 SQLException (java.sql.SQLException)3 Timestamp (java.sql.Timestamp)3 NavajoException (com.dexels.navajo.document.NavajoException)2 Operand (com.dexels.navajo.document.Operand)2 DatePattern (com.dexels.navajo.document.types.DatePattern)2 NavajoType (com.dexels.navajo.document.types.NavajoType)2