Commit 96dbd65f authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade esquema y métodos de avro

parent ed793a03
Loading
Loading
Loading
Loading
+58 −5
Original line number Diff line number Diff line
package es.redmic.vesselslib.dto.tracking;

import java.io.IOException;
import java.nio.ByteBuffer;

import org.apache.avro.Schema;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.vividsolutions.jts.geom.Point;

import es.redmic.brokerlib.avro.geodata.common.FeatureDTO;
@@ -13,7 +17,16 @@ public class VesselTrackingDTO extends FeatureDTO<VesselTrackingPropertiesDTO, P
	// @formatter:off

	@JsonIgnore
	public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("");
	public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse(
			"{\"type\":\"record\",\"name\":\"VesselTrackingDTO\",\"namespace\":\"es.redmic.vesselslib.dto.tracking\",\"fields\":["
				+ "{\"name\":\"uuid\",\"type\":[\"string\", \"null\"]},"
				+ "{\"name\":\"type\", \"type\": {"
					+ "\"namespace\":\"es.redmic.brokerlib.avro.geodata.common\",\"type\":\"enum\",\"name\":\"GeoJSONFeatureType\"," + 
						"\"symbols\":[\"FEATURE\"]}},"
				+ "{\"name\":\"properties\",\"type\":" + VesselTrackingPropertiesDTO.SCHEMA$.toString() + "},"
				+ "{\"name\":\"geometry\",\"type\":[\"bytes\", \"null\"]},"
				+ "{\"name\":\"id\",\"type\":\"string\"}"
			+ "]}");
	
	// @formatter:on

@@ -29,14 +42,54 @@ public class VesselTrackingDTO extends FeatureDTO<VesselTrackingPropertiesDTO, P

	@Override
	public Object get(int field) {
		// TODO Auto-generated method stub
		switch (field) {
		case 0:
			return getUuid();
		case 1:
			return getType();
		case 2:
			return getProperties();
		case 3:
			try {
				return ByteBuffer.wrap(mapper.writeValueAsBytes(getGeometry()));
			} catch (JsonProcessingException e) {
				e.printStackTrace();
				return null;
			}
		case 4:
			return getId();
		default:
			throw new org.apache.avro.AvroRuntimeException("Bad index");
		}
	}

	@Override
	public void put(int field, Object value) {
		// TODO Auto-generated method stub

		switch (field) {
		case 0:
			setUuid(value != null ? value.toString() : null);
			break;
		case 1:
			if (value != null) {
				setType(GeoJSONFeatureType.fromString(value.toString()));
			}
			break;
		case 2:
			setProperties((VesselTrackingPropertiesDTO) value);
			break;
		case 3:
			try {
				setGeometry(mapper.readValue(((ByteBuffer) value).array(), Point.class));
			} catch (IOException e) {
				e.printStackTrace();
			}
			break;
		case 4:
			setId(value != null ? value.toString() : null);
			break;
		default:
			throw new org.apache.avro.AvroRuntimeException("Bad index");
		}
	}

}
+165 −4
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import javax.validation.constraints.NotNull;

import org.apache.avro.Schema;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -23,7 +24,39 @@ public class VesselTrackingPropertiesDTO extends PropertiesDTO {
	// @formatter:off

	@JsonIgnore
	public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("");
	public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse(
			"{\"type\":\"record\",\"name\":\"VesselTrackingPropertiesDTO\",\"namespace\":\"es.redmic.vesselslib.dto.tracking\",\"fields\":["
					+ "{\"name\":\"vessel\",\"type\":[{\"type\":\"record\",\"name\":\"VesselDTO\",\"namespace\":\"es.redmic.vesselslib.dto.vessel\",\"fields\":["
						+ "{\"name\":\"mmsi\",\"type\":\"int\"},"
						+ "{\"name\":\"imo\",\"type\":[\"int\", \"null\"]},"
						+ "{\"name\":\"type\",\"type\":[{ \"name\":\"VesselTypeDTO\", \"type\":\"record\","
								+ "\"namespace\":\"es.redmic.vesselslib.dto.vesseltype\",\"fields\":["
							+ "{\"name\":\"code\",\"type\":\"string\"},"
							+ "{\"name\":\"name\",\"type\":[\"string\", \"null\"]},"
							+ "{\"name\":\"name_en\",\"type\":[\"string\", \"null\"]},"
							+ "{\"name\":\"id\",\"type\":\"string\"}]}, \"null\"]},"
						+ "{\"name\":\"name\",\"type\":[\"string\", \"null\"]},"
						+ "{\"name\":\"callSign\",\"type\":[\"string\", \"null\"]},"
						+ "{\"name\":\"length\",\"type\":[\"double\", \"null\"]},"
						+ "{\"name\":\"beam\",\"type\":[\"double\", \"null\"]},"
						+ "{\"name\":\"inserted\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}],"
							+ "\"default\": null},"
						+ "{\"name\":\"updated\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}],"
							+ "\"default\": null},"
						+ "{\"name\":\"id\",\"type\":\"string\"}]}]},"
						
					+ "{\"name\":\"date\",\"type\":{ \"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},"
					+ "{\"name\":\"cog\",\"type\":[\"double\", \"null\"]},"
					+ "{\"name\":\"sog\",\"type\":[\"double\", \"null\"]},"
					+ "{\"name\":\"heading\",\"type\":[\"int\", \"null\"]},"
					+ "{\"name\":\"navStat\",\"type\":[\"int\", \"null\"]},"
					+ "{\"name\":\"dest\",\"type\":[\"string\", \"null\"]},"
					+ "{\"name\":\"eta\",\"type\":[\"string\", \"null\"]},"
					+ "{\"name\":\"activityId\",\"type\":\"string\"},"
					+ "{\"name\":\"inserted\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}],"
						+ "\"default\": null},"
					+ "{\"name\":\"updated\",\"type\":[\"null\",{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}],"
						+ "\"default\": null}]}");
	
	// @formatter:on

@@ -114,21 +147,149 @@ public class VesselTrackingPropertiesDTO extends PropertiesDTO {
		this.eta = eta;
	}

	@JsonIgnore
	@Override
	public Schema getSchema() {
		return SCHEMA$;
	}

	@JsonIgnore
	@Override
	public Object get(int field) {
		// TODO Auto-generated method stub
		return null;
		switch (field) {
		case 0:
			return vessel;
		case 1:
			return date.getMillis();
		case 2:
			return cog;
		case 3:
			return sog;
		case 4:
			return heading;
		case 5:
			return navStat;
		case 6:
			return dest;
		case 7:
			return eta;
		case 8:
			return getActivityId();
		case 9:
			return getInserted() != null ? getInserted().getMillis() : null;
		case 10:
			return getUpdated() != null ? getUpdated().getMillis() : null;
		default:
			throw new org.apache.avro.AvroRuntimeException("Bad index");
		}
	}

	@JsonIgnore
	@Override
	public void put(int field, Object value) {
		// TODO Auto-generated method stub
		switch (field) {
		case 0:
			vessel = (VesselDTO) value;
			break;
		case 1:
			date = new DateTime(value, DateTimeZone.UTC);
			break;
		case 2:
			cog = (java.lang.Double) value;
			break;
		case 3:
			sog = (java.lang.Double) value;
			break;
		case 4:
			heading = (java.lang.Integer) value;
			break;
		case 5:
			navStat = (java.lang.Integer) value;
			break;
		case 6:
			dest = value != null ? value.toString() : null;
			break;
		case 7:
			eta = value != null ? value.toString() : null;
			break;
		case 8:
			setActivityId(value.toString());
			break;
		case 9:
			setInserted(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null);
			break;
		case 10:
			setUpdated(value != null ? new DateTime(value, DateTimeZone.UTC).toDateTime() : null);
			break;
		default:
			throw new org.apache.avro.AvroRuntimeException("Bad index");
		}
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((cog == null) ? 0 : cog.hashCode());
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result + ((dest == null) ? 0 : dest.hashCode());
		result = prime * result + ((eta == null) ? 0 : eta.hashCode());
		result = prime * result + ((heading == null) ? 0 : heading.hashCode());
		result = prime * result + ((navStat == null) ? 0 : navStat.hashCode());
		result = prime * result + ((sog == null) ? 0 : sog.hashCode());
		result = prime * result + ((vessel == null) ? 0 : vessel.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		VesselTrackingPropertiesDTO other = (VesselTrackingPropertiesDTO) obj;
		if (cog == null) {
			if (other.cog != null)
				return false;
		} else if (!cog.equals(other.cog))
			return false;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (dest == null) {
			if (other.dest != null)
				return false;
		} else if (!dest.equals(other.dest))
			return false;
		if (eta == null) {
			if (other.eta != null)
				return false;
		} else if (!eta.equals(other.eta))
			return false;
		if (heading == null) {
			if (other.heading != null)
				return false;
		} else if (!heading.equals(other.heading))
			return false;
		if (navStat == null) {
			if (other.navStat != null)
				return false;
		} else if (!navStat.equals(other.navStat))
			return false;
		if (sog == null) {
			if (other.sog != null)
				return false;
		} else if (!sog.equals(other.sog))
			return false;
		if (vessel == null) {
			if (other.vessel != null)
				return false;
		} else if (!vessel.equals(other.vessel))
			return false;
		return true;
	}
}
 No newline at end of file