@Override public JsonElement serialize(RyaType src, Type typeOfSrc, JsonSerializationContext context) { JsonObject result = new JsonObject(); result.add("type", new JsonPrimitive(src.getClass().getName())); StringBuilder builder = new StringBuilder(); builder.append(src.getData()).append("\u0000").append(src.getDataType().toString()); result.add("properties", new JsonPrimitive(builder.toString())); return result; }
@Override public JsonElement serialize(RyaType src, Type typeOfSrc, JsonSerializationContext context) { JsonObject result = new JsonObject(); result.add("type", new JsonPrimitive(src.getClass().getName())); StringBuilder builder = new StringBuilder(); builder.append(src.getData()).append("\u0000").append(src.getDataType().toString()); result.add("properties", new JsonPrimitive(builder.toString())); return result; }
public byte[][] serializeType(final RyaType ryaType) throws RyaTypeResolverException { final RyaTypeResolver ryaTypeResolver = retrieveResolver(ryaType.getDataType()); if (ryaTypeResolver != null) { return ryaTypeResolver.serializeType(ryaType); } return null; }
public byte[] serialize(final RyaType ryaType) throws RyaTypeResolverException { final RyaTypeResolver ryaTypeResolver = retrieveResolver(ryaType.getDataType()); if (ryaTypeResolver != null) { return ryaTypeResolver.serialize(ryaType); } return null; }
public byte[][] serializeType(final RyaType ryaType) throws RyaTypeResolverException { final RyaTypeResolver ryaTypeResolver = retrieveResolver(ryaType.getDataType()); if (ryaTypeResolver != null) { return ryaTypeResolver.serializeType(ryaType); } return null; }
@Override public Document toDocument(final RyaType ryaType) { requireNonNull(ryaType); return new Document() .append(DATA_TYPE, ryaType.getDataType().toString()) .append(VALUE, ryaType.getData()); }
public static Literal convertLiteral(RyaType literal) { if (XMLSchema.STRING.equals(literal.getDataType())) { return new LiteralImpl(literal.getData()); } else { return new LiteralImpl(literal.getData(), literal.getDataType()); } //TODO: No Language support yet }
@Override public Document toDocument(final RyaType ryaType) { requireNonNull(ryaType); return new Document() .append(DATA_TYPE, ryaType.getDataType().toString()) .append(VALUE, ryaType.getData()); }
/** * Converts a {@link RyaType} into a {@link Value} representation of the * {@code ryaType}. * @param ryaType the {@link RyaType} to convert. * @return the {@link Value} representation of the {@code ryaType}. */ public static Value convertValue(final RyaType ryaType) { //assuming either IRI or Literal here return (ryaType instanceof RyaIRI || ryaType.getDataType().equals(XMLSchema.ANYURI)) ? convertIRI(ryaType) : convertLiteral(ryaType); }
public RyaRange transformRange(final RyaRange range) throws RyaTypeResolverException { final RyaTypeResolver ryaTypeResolver = retrieveResolver(range.getStart().getDataType()); if (ryaTypeResolver != null) { return ryaTypeResolver.transformRange(range); } return range; }
public RyaRange transformRange(final RyaRange range) throws RyaTypeResolverException { final RyaTypeResolver ryaTypeResolver = retrieveResolver(range.getStart().getDataType()); if (ryaTypeResolver != null) { return ryaTypeResolver.transformRange(range); } return range; }
@Override public void write(DataOutput dataOutput) throws IOException { dataOutput.writeChars(ryatype.getData()); dataOutput.writeChars(ryatype.getDataType().toString()); }
public static String getTripleString(final RyaStatement rs) { checkNotNull(rs); final String subj = rs.getSubject().getData() + TYPE_DELIM + URI_TYPE; final String pred = rs.getPredicate().getData() + TYPE_DELIM + URI_TYPE; final String objData = rs.getObject().getData(); final String objDataType = rs.getObject().getDataType().stringValue(); return subj + DELIM + pred + DELIM + objData + TYPE_DELIM + objDataType; }
public static String getTripleString(final RyaStatement rs) { checkNotNull(rs); final String subj = rs.getSubject().getData() + TYPE_DELIM + URI_TYPE; final String pred = rs.getPredicate().getData() + TYPE_DELIM + URI_TYPE; final String objData = rs.getObject().getData(); final String objDataType = rs.getObject().getDataType().stringValue(); return subj + DELIM + pred + DELIM + objData + TYPE_DELIM + objDataType; }
@Override public void write(final DataOutput dataOutput) throws IOException { dataOutput.writeChars(ryatype.getData()); dataOutput.writeChars(ryatype.getDataType().toString()); dataOutput.writeChars(ryatype.getLanguage()); }
@Test public void testDateNoTimeNoZone() throws Exception { String beforeDate = "2000-02-02"; String afterDate="2000-02-0(1|2|3)T\\d\\d:\\d\\d:00\\.000Z"; RyaType deserialize = serializeAndDeserialize(beforeDate, XMLSchema.DATE); final String afterActual = deserialize.getData(); assertTrue("Before='"+beforeDate+"'; Expected should match actual regex after='"+afterDate+"' deserialized:"+afterActual, afterActual.matches(afterDate)); assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); } @Test
@Test public void testMilliSecondsNoZone() throws Exception { String beforeDate="2002-02-02T02:02:02.222"; String afterDate="2002-02-0(1|2|3)T\\d\\d:\\d\\d:02\\.222.*"; RyaType deserialize = serializeAndDeserialize(beforeDate, XMLSchema.DATETIME); final String afterActual = deserialize.getData(); assertTrue("Before='"+beforeDate+"'; Expected should match actual regex after='"+afterDate+"' deserialized:"+afterActual, afterActual.matches(afterDate)); assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); } @Test
@Test public void testNoZone() throws Exception { String beforeDate = "2000-01-02T00:00:01"; String afterDate="2000-01-0(1|2|3)T\\d\\d:\\d\\d:01\\.000Z"; RyaType deserialize = serializeAndDeserialize(beforeDate, XMLSchema.DATE); final String afterActual = deserialize.getData(); assertTrue("Before='"+beforeDate+"'; Expected should match actual regex after='"+afterDate+"' deserialized:"+afterActual, afterActual.matches(afterDate)); assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); } @Test
@Test public void testDateZoneNoTime() throws Exception { // if you see this: //java.lang.IllegalArgumentException: Invalid format: "2000-02-02Z" is malformed at "Z" // use this: "2000-02-02TZ"; String currentTime = "2000-02-02TZ"; RyaType deserialize = serializeAndDeserialize(currentTime, XMLSchema.DATE); assertEquals("Before expected should match after actual deserialized:","2000-02-02T00:00:00.000Z", deserialize.getData()); assertEquals(XMLSchema.DATETIME, deserialize.getDataType()); } @Test
@Test public void testConvertLiteral_normalString() { final String expectedData = "Hello"; final Literal literal = VF.createLiteral(expectedData); final RyaType ryaType = RdfToRyaConversions.convertLiteral(literal); assertEquals(XMLSchema.STRING, ryaType.getDataType()); assertEquals(expectedData, ryaType.getData()); final RyaType expectedRyaType = new RyaType(XMLSchema.STRING, expectedData); assertEquals(expectedRyaType, ryaType); assertNull(ryaType.getLanguage()); } }