@Test() public void testConvertValidDate() throws Exception { Date date = DataTypes.DATE_TYPE.convert(TEST_DATE_STRING, Multiplicity.OPTIONAL); Assert.assertEquals(date, new Date(TEST_DATE_IN_LONG)); StringBuilder buf = new StringBuilder(); DataTypes.DATE_TYPE.output(new Date(TEST_DATE_IN_LONG), buf, "", new HashSet<Date>()); Assert.assertEquals(buf.toString(), TEST_DATE_STRING); } }
@Override public Date convert(Object val, Multiplicity m) throws AtlasException { if (val != null) { if (val instanceof Date) { return (Date) val; } else if (val instanceof String) { try { return utcDateFormat.parseDateTime((String)val).toDate(); } catch (Exception ne) { throw new ValueConversionException(this, val, ne); } } else if (val instanceof Number) { return new Date(((Number) val).longValue()); } else { throw new ValueConversionException(this, val); } } return convertNull(m); }
public void setDate(String attrName, Date val) throws AtlasException { AttributeInfo i = fieldMapping.fields.get(attrName); if (i == null) { throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName())); } if (i.dataType() != DataTypes.DATE_TYPE) { throw new AtlasException( String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.DATE_TYPE.getName())); } int pos = fieldMapping.fieldPos.get(attrName); int nullPos = fieldMapping.fieldNullPos.get(attrName); nullFlags[nullPos] = val == null; dates[pos] = val; explicitSets[nullPos] = true; }
@Override public Date convert(Object val, Multiplicity m) throws AtlasException { if (val != null) { if (val instanceof Date) { return (Date) val; } else if (val instanceof String) { try { return utcDateFormat.parseDateTime((String)val).toDate(); } catch (Exception ne) { throw new ValueConversionException(this, val, ne); } } else if (val instanceof Number) { return new Date(((Number) val).longValue()); } else { throw new ValueConversionException(this, val); } } return convertNull(m); }
public void setDate(String attrName, Date val) throws AtlasException { AttributeInfo i = fieldMapping.fields.get(attrName); if (i == null) { throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName())); } if (i.dataType() != DataTypes.DATE_TYPE) { throw new AtlasException( String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.DATE_TYPE.getName())); } int pos = fieldMapping.fieldPos.get(attrName); int nullPos = fieldMapping.fieldNullPos.get(attrName); nullFlags[nullPos] = val == null; dates[pos] = val; explicitSets[nullPos] = true; }
public Date getDate(String attrName) throws AtlasException { AttributeInfo i = fieldMapping.fields.get(attrName); if (i == null) { throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName())); } if (i.dataType() != DataTypes.DATE_TYPE) { throw new AtlasException( String.format("Field %s for Struct %s is not a %s, call generic get method", attrName, getTypeName(), DataTypes.DATE_TYPE.getName())); } int pos = fieldMapping.fieldPos.get(attrName); int nullPos = fieldMapping.fieldNullPos.get(attrName); if (nullFlags[nullPos]) { return DataTypes.DATE_TYPE.nullValue(); } return dates[pos]; }
public Date getDate(String attrName) throws AtlasException { AttributeInfo i = fieldMapping.fields.get(attrName); if (i == null) { throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName())); } if (i.dataType() != DataTypes.DATE_TYPE) { throw new AtlasException( String.format("Field %s for Struct %s is not a %s, call generic get method", attrName, getTypeName(), DataTypes.DATE_TYPE.getName())); } int pos = fieldMapping.fieldPos.get(attrName); int nullPos = fieldMapping.fieldNullPos.get(attrName); if (nullFlags[nullPos]) { return DataTypes.DATE_TYPE.nullValue(); } return dates[pos]; }
@Test(expectedExceptions = ValueConversionException.class) public void testConvertInvalidDate() throws Exception { DataTypes.DATE_TYPE.convert("", Multiplicity.OPTIONAL); }
private void registerPrimitiveTypes() { coreTypes.put(DataTypes.BOOLEAN_TYPE.getName(), DataTypes.BOOLEAN_TYPE); coreTypes.put(DataTypes.BYTE_TYPE.getName(), DataTypes.BYTE_TYPE); coreTypes.put(DataTypes.SHORT_TYPE.getName(), DataTypes.SHORT_TYPE); coreTypes.put(DataTypes.INT_TYPE.getName(), DataTypes.INT_TYPE); coreTypes.put(DataTypes.LONG_TYPE.getName(), DataTypes.LONG_TYPE); coreTypes.put(DataTypes.FLOAT_TYPE.getName(), DataTypes.FLOAT_TYPE); coreTypes.put(DataTypes.DOUBLE_TYPE.getName(), DataTypes.DOUBLE_TYPE); coreTypes.put(DataTypes.BIGINTEGER_TYPE.getName(), DataTypes.BIGINTEGER_TYPE); coreTypes.put(DataTypes.BIGDECIMAL_TYPE.getName(), DataTypes.BIGDECIMAL_TYPE); coreTypes.put(DataTypes.DATE_TYPE.getName(), DataTypes.DATE_TYPE); coreTypes.put(DataTypes.STRING_TYPE.getName(), DataTypes.STRING_TYPE); }
private void registerPrimitiveTypes() { coreTypes.put(DataTypes.BOOLEAN_TYPE.getName(), DataTypes.BOOLEAN_TYPE); coreTypes.put(DataTypes.BYTE_TYPE.getName(), DataTypes.BYTE_TYPE); coreTypes.put(DataTypes.SHORT_TYPE.getName(), DataTypes.SHORT_TYPE); coreTypes.put(DataTypes.INT_TYPE.getName(), DataTypes.INT_TYPE); coreTypes.put(DataTypes.LONG_TYPE.getName(), DataTypes.LONG_TYPE); coreTypes.put(DataTypes.FLOAT_TYPE.getName(), DataTypes.FLOAT_TYPE); coreTypes.put(DataTypes.DOUBLE_TYPE.getName(), DataTypes.DOUBLE_TYPE); coreTypes.put(DataTypes.BIGINTEGER_TYPE.getName(), DataTypes.BIGINTEGER_TYPE); coreTypes.put(DataTypes.BIGDECIMAL_TYPE.getName(), DataTypes.BIGDECIMAL_TYPE); coreTypes.put(DataTypes.DATE_TYPE.getName(), DataTypes.DATE_TYPE); coreTypes.put(DataTypes.STRING_TYPE.getName(), DataTypes.STRING_TYPE); }
@Test() public void testConvertValidDate() throws Exception { Date date = DataTypes.DATE_TYPE.convert(TEST_DATE_STRING, Multiplicity.OPTIONAL); Assert.assertEquals(date, new Date(TEST_DATE_IN_LONG)); StringBuilder buf = new StringBuilder(); DataTypes.DATE_TYPE.output(new Date(TEST_DATE_IN_LONG), buf, "", new HashSet<Date>()); Assert.assertEquals(buf.toString(), TEST_DATE_STRING); } }
@Test(expectedExceptions = ValueConversionException.class) public void testConvertInvalidDate() throws Exception { DataTypes.DATE_TYPE.convert("", Multiplicity.OPTIONAL); }