From: Kai Moritz Date: Sun, 7 Jun 2020 11:13:55 +0000 (+0200) Subject: TMP X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=a4954bc66ddc26c5eae70a1f3bc482aa61114ed9;p=demos%2Fmicroservices TMP --- diff --git a/README.sh b/README.sh index c6d4d41..2e665fb 100755 --- a/README.sh +++ b/README.sh @@ -15,6 +15,8 @@ docker build -t trion/take-order-service:01 take-order docker build -t trion/details-service:02 details docker build -t trion/validate-order-service:03 validate-order docker build -t trion/validation-results-service:03 validation-results +docker build -t trion/validate-user-service:04 validate-user +docker build -t trion/validation-results-service:04 validation-results docker-compose up -d zookeeper kafka schema-registry diff --git a/docker-compose.yml b/docker-compose.yml index bc88907..27763e4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -52,6 +52,16 @@ services: - kafka - schema-registry + validate-user: + image: trion/validate-user-service:04 + hostname: validate-user + ports: + - "8072:8080" + depends_on: + - zookeeper + - kafka + - schema-registry + validation-results: image: trion/validation-results-service:03 hostname: validation-results diff --git a/validate-user/Dockerfile b/validate-user/Dockerfile new file mode 100644 index 0000000..ddf2072 --- /dev/null +++ b/validate-user/Dockerfile @@ -0,0 +1,4 @@ +FROM openjdk:8-jre-slim +COPY target/validate-user-04-0-SNAPSHOT.jar /opt/ +EXPOSE 8080 +CMD ["java", "-jar", "/opt/validate-user-04-0-SNAPSHOT.jar"] diff --git a/validate-user/order-validation.avsc b/validate-user/order-validation.avsc new file mode 100644 index 0000000..9db183d --- /dev/null +++ b/validate-user/order-validation.avsc @@ -0,0 +1,31 @@ +[ +{ + "namespace": "de.trion.microservices.avro", + "type": "enum", + "name": "OrderValidationType", + "symbols" : [ "ORDER_DETAILS_CHECK" ] +}, +{ + "namespace": "de.trion.microservices.avro", + "type": "enum", + "name": "OrderValidationResult", + "symbols" : [ "PASS", "FAIL" ] +}, +{ + "namespace": "de.trion.microservices.avro", + "type": "record", + "name": "OrderValidation", + "fields": [ + { "name": "orderId", "type": "string" }, + { "name": "checkType", "type": "OrderValidationType" }, + { "name": "validationResult", "type": "OrderValidationResult" }, + { + "name": "messages", + "type": + { + "type": "array", + "items": "string" + } + } + ] +}] diff --git a/validate-user/order.avsc b/validate-user/order.avsc new file mode 100644 index 0000000..d066bd1 --- /dev/null +++ b/validate-user/order.avsc @@ -0,0 +1,22 @@ +[ + { + "namespace": "de.trion.microservices.avro", + "type": "enum", + "name": "OrderState", + "symbols" : [ "CREATED", "APPROVED", "DECLINED" ], + "default": "CREATED" + }, + { + "namespace": "de.trion.microservices.avro", + "type": "record", + "name": "Order", + "fields": [ + { "name": "id", "type": "string" }, + { "name": "state", "type": "OrderState" }, + { "name": "customerId", "type": "long" }, + { "name": "orderId", "type": "long" }, + { "name": "productId", "type": "long" }, + { "name": "quantity", "type": "int" } + ] + } +] diff --git a/validate-user/pom.xml b/validate-user/pom.xml new file mode 100644 index 0000000..85e9b1d --- /dev/null +++ b/validate-user/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + + + de.trion.kafka.microservices + order-example-04 + 0-SNAPSHOT + + + de.trion.kafka.microservices + validate-user-04 + User Validation Service - Schritt 04 + 0-SNAPSHOT + + + 1.9.0 + 5.3.0 + 2.3.0 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.apache.kafka + kafka-streams + + + org.apache.avro + avro + ${avro.version} + + + io.confluent + kafka-streams-avro-serde + ${confluent.version} + + + + + + confluent + https://packages.confluent.io/maven/ + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.avro + avro-maven-plugin + ${avro.version} + + + generate-sources + + schema + + + ${project.basedir}/ + ${project.basedir}/src/main/java/ + + + + + + + + diff --git a/validate-user/src/main/java/de/trion/microservices/avro/CustomerLevel.java b/validate-user/src/main/java/de/trion/microservices/avro/CustomerLevel.java new file mode 100644 index 0000000..9abd09b --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/avro/CustomerLevel.java @@ -0,0 +1,13 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package de.trion.microservices.avro; +@org.apache.avro.specific.AvroGenerated +public enum CustomerLevel implements org.apache.avro.generic.GenericEnumSymbol { + BRONZE, SILVER, GOLD, UNWANTED ; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"CustomerLevel\",\"namespace\":\"de.trion.microservices.avro\",\"symbols\":[\"BRONZE\",\"SILVER\",\"GOLD\",\"UNWANTED\"]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + public org.apache.avro.Schema getSchema() { return SCHEMA$; } +} diff --git a/validate-user/src/main/java/de/trion/microservices/avro/Order.java b/validate-user/src/main/java/de/trion/microservices/avro/Order.java new file mode 100644 index 0000000..f1dc56d --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/avro/Order.java @@ -0,0 +1,706 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package de.trion.microservices.avro; + +import org.apache.avro.generic.GenericArray; +import org.apache.avro.specific.SpecificData; +import org.apache.avro.util.Utf8; +import org.apache.avro.message.BinaryMessageEncoder; +import org.apache.avro.message.BinaryMessageDecoder; +import org.apache.avro.message.SchemaStore; + +@org.apache.avro.specific.AvroGenerated +public class Order extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + private static final long serialVersionUID = 6161645617080332601L; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Order\",\"namespace\":\"de.trion.microservices.avro\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"state\",\"type\":{\"type\":\"enum\",\"name\":\"OrderState\",\"symbols\":[\"CREATED\",\"APPROVED\",\"DECLINED\"],\"default\":\"CREATED\"}},{\"name\":\"customerId\",\"type\":\"long\"},{\"name\":\"orderId\",\"type\":\"long\"},{\"name\":\"productId\",\"type\":\"long\"},{\"name\":\"quantity\",\"type\":\"int\"}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + + private static SpecificData MODEL$ = new SpecificData(); + + private static final BinaryMessageEncoder ENCODER = + new BinaryMessageEncoder(MODEL$, SCHEMA$); + + private static final BinaryMessageDecoder DECODER = + new BinaryMessageDecoder(MODEL$, SCHEMA$); + + /** + * Return the BinaryMessageEncoder instance used by this class. + * @return the message encoder used by this class + */ + public static BinaryMessageEncoder getEncoder() { + return ENCODER; + } + + /** + * Return the BinaryMessageDecoder instance used by this class. + * @return the message decoder used by this class + */ + public static BinaryMessageDecoder getDecoder() { + return DECODER; + } + + /** + * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}. + * @param resolver a {@link SchemaStore} used to find schemas by fingerprint + * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore + */ + public static BinaryMessageDecoder createDecoder(SchemaStore resolver) { + return new BinaryMessageDecoder(MODEL$, SCHEMA$, resolver); + } + + /** + * Serializes this Order to a ByteBuffer. + * @return a buffer holding the serialized data for this instance + * @throws java.io.IOException if this instance could not be serialized + */ + public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { + return ENCODER.encode(this); + } + + /** + * Deserializes a Order from a ByteBuffer. + * @param b a byte buffer holding serialized data for an instance of this class + * @return a Order instance decoded from the given buffer + * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class + */ + public static Order fromByteBuffer( + java.nio.ByteBuffer b) throws java.io.IOException { + return DECODER.decode(b); + } + + @Deprecated public java.lang.CharSequence id; + @Deprecated public de.trion.microservices.avro.OrderState state; + @Deprecated public long customerId; + @Deprecated public long orderId; + @Deprecated public long productId; + @Deprecated public int quantity; + + /** + * Default constructor. Note that this does not initialize fields + * to their default values from the schema. If that is desired then + * one should use newBuilder(). + */ + public Order() {} + + /** + * All-args constructor. + * @param id The new value for id + * @param state The new value for state + * @param customerId The new value for customerId + * @param orderId The new value for orderId + * @param productId The new value for productId + * @param quantity The new value for quantity + */ + public Order(java.lang.CharSequence id, de.trion.microservices.avro.OrderState state, java.lang.Long customerId, java.lang.Long orderId, java.lang.Long productId, java.lang.Integer quantity) { + this.id = id; + this.state = state; + this.customerId = customerId; + this.orderId = orderId; + this.productId = productId; + this.quantity = quantity; + } + + public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; } + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return id; + case 1: return state; + case 2: return customerId; + case 3: return orderId; + case 4: return productId; + case 5: return quantity; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: id = (java.lang.CharSequence)value$; break; + case 1: state = (de.trion.microservices.avro.OrderState)value$; break; + case 2: customerId = (java.lang.Long)value$; break; + case 3: orderId = (java.lang.Long)value$; break; + case 4: productId = (java.lang.Long)value$; break; + case 5: quantity = (java.lang.Integer)value$; break; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'id' field. + * @return The value of the 'id' field. + */ + public java.lang.CharSequence getId() { + return id; + } + + + /** + * Sets the value of the 'id' field. + * @param value the value to set. + */ + public void setId(java.lang.CharSequence value) { + this.id = value; + } + + /** + * Gets the value of the 'state' field. + * @return The value of the 'state' field. + */ + public de.trion.microservices.avro.OrderState getState() { + return state; + } + + + /** + * Sets the value of the 'state' field. + * @param value the value to set. + */ + public void setState(de.trion.microservices.avro.OrderState value) { + this.state = value; + } + + /** + * Gets the value of the 'customerId' field. + * @return The value of the 'customerId' field. + */ + public long getCustomerId() { + return customerId; + } + + + /** + * Sets the value of the 'customerId' field. + * @param value the value to set. + */ + public void setCustomerId(long value) { + this.customerId = value; + } + + /** + * Gets the value of the 'orderId' field. + * @return The value of the 'orderId' field. + */ + public long getOrderId() { + return orderId; + } + + + /** + * Sets the value of the 'orderId' field. + * @param value the value to set. + */ + public void setOrderId(long value) { + this.orderId = value; + } + + /** + * Gets the value of the 'productId' field. + * @return The value of the 'productId' field. + */ + public long getProductId() { + return productId; + } + + + /** + * Sets the value of the 'productId' field. + * @param value the value to set. + */ + public void setProductId(long value) { + this.productId = value; + } + + /** + * Gets the value of the 'quantity' field. + * @return The value of the 'quantity' field. + */ + public int getQuantity() { + return quantity; + } + + + /** + * Sets the value of the 'quantity' field. + * @param value the value to set. + */ + public void setQuantity(int value) { + this.quantity = value; + } + + /** + * Creates a new Order RecordBuilder. + * @return A new Order RecordBuilder + */ + public static de.trion.microservices.avro.Order.Builder newBuilder() { + return new de.trion.microservices.avro.Order.Builder(); + } + + /** + * Creates a new Order RecordBuilder by copying an existing Builder. + * @param other The existing builder to copy. + * @return A new Order RecordBuilder + */ + public static de.trion.microservices.avro.Order.Builder newBuilder(de.trion.microservices.avro.Order.Builder other) { + if (other == null) { + return new de.trion.microservices.avro.Order.Builder(); + } else { + return new de.trion.microservices.avro.Order.Builder(other); + } + } + + /** + * Creates a new Order RecordBuilder by copying an existing Order instance. + * @param other The existing instance to copy. + * @return A new Order RecordBuilder + */ + public static de.trion.microservices.avro.Order.Builder newBuilder(de.trion.microservices.avro.Order other) { + if (other == null) { + return new de.trion.microservices.avro.Order.Builder(); + } else { + return new de.trion.microservices.avro.Order.Builder(other); + } + } + + /** + * RecordBuilder for Order instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private java.lang.CharSequence id; + private de.trion.microservices.avro.OrderState state; + private long customerId; + private long orderId; + private long productId; + private int quantity; + + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$); + } + + /** + * Creates a Builder by copying an existing Builder. + * @param other The existing Builder to copy. + */ + private Builder(de.trion.microservices.avro.Order.Builder other) { + super(other); + if (isValidValue(fields()[0], other.id)) { + this.id = data().deepCopy(fields()[0].schema(), other.id); + fieldSetFlags()[0] = other.fieldSetFlags()[0]; + } + if (isValidValue(fields()[1], other.state)) { + this.state = data().deepCopy(fields()[1].schema(), other.state); + fieldSetFlags()[1] = other.fieldSetFlags()[1]; + } + if (isValidValue(fields()[2], other.customerId)) { + this.customerId = data().deepCopy(fields()[2].schema(), other.customerId); + fieldSetFlags()[2] = other.fieldSetFlags()[2]; + } + if (isValidValue(fields()[3], other.orderId)) { + this.orderId = data().deepCopy(fields()[3].schema(), other.orderId); + fieldSetFlags()[3] = other.fieldSetFlags()[3]; + } + if (isValidValue(fields()[4], other.productId)) { + this.productId = data().deepCopy(fields()[4].schema(), other.productId); + fieldSetFlags()[4] = other.fieldSetFlags()[4]; + } + if (isValidValue(fields()[5], other.quantity)) { + this.quantity = data().deepCopy(fields()[5].schema(), other.quantity); + fieldSetFlags()[5] = other.fieldSetFlags()[5]; + } + } + + /** + * Creates a Builder by copying an existing Order instance + * @param other The existing instance to copy. + */ + private Builder(de.trion.microservices.avro.Order other) { + super(SCHEMA$); + if (isValidValue(fields()[0], other.id)) { + this.id = data().deepCopy(fields()[0].schema(), other.id); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.state)) { + this.state = data().deepCopy(fields()[1].schema(), other.state); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.customerId)) { + this.customerId = data().deepCopy(fields()[2].schema(), other.customerId); + fieldSetFlags()[2] = true; + } + if (isValidValue(fields()[3], other.orderId)) { + this.orderId = data().deepCopy(fields()[3].schema(), other.orderId); + fieldSetFlags()[3] = true; + } + if (isValidValue(fields()[4], other.productId)) { + this.productId = data().deepCopy(fields()[4].schema(), other.productId); + fieldSetFlags()[4] = true; + } + if (isValidValue(fields()[5], other.quantity)) { + this.quantity = data().deepCopy(fields()[5].schema(), other.quantity); + fieldSetFlags()[5] = true; + } + } + + /** + * Gets the value of the 'id' field. + * @return The value. + */ + public java.lang.CharSequence getId() { + return id; + } + + + /** + * Sets the value of the 'id' field. + * @param value The value of 'id'. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder setId(java.lang.CharSequence value) { + validate(fields()[0], value); + this.id = value; + fieldSetFlags()[0] = true; + return this; + } + + /** + * Checks whether the 'id' field has been set. + * @return True if the 'id' field has been set, false otherwise. + */ + public boolean hasId() { + return fieldSetFlags()[0]; + } + + + /** + * Clears the value of the 'id' field. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder clearId() { + id = null; + fieldSetFlags()[0] = false; + return this; + } + + /** + * Gets the value of the 'state' field. + * @return The value. + */ + public de.trion.microservices.avro.OrderState getState() { + return state; + } + + + /** + * Sets the value of the 'state' field. + * @param value The value of 'state'. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder setState(de.trion.microservices.avro.OrderState value) { + validate(fields()[1], value); + this.state = value; + fieldSetFlags()[1] = true; + return this; + } + + /** + * Checks whether the 'state' field has been set. + * @return True if the 'state' field has been set, false otherwise. + */ + public boolean hasState() { + return fieldSetFlags()[1]; + } + + + /** + * Clears the value of the 'state' field. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder clearState() { + state = null; + fieldSetFlags()[1] = false; + return this; + } + + /** + * Gets the value of the 'customerId' field. + * @return The value. + */ + public long getCustomerId() { + return customerId; + } + + + /** + * Sets the value of the 'customerId' field. + * @param value The value of 'customerId'. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder setCustomerId(long value) { + validate(fields()[2], value); + this.customerId = value; + fieldSetFlags()[2] = true; + return this; + } + + /** + * Checks whether the 'customerId' field has been set. + * @return True if the 'customerId' field has been set, false otherwise. + */ + public boolean hasCustomerId() { + return fieldSetFlags()[2]; + } + + + /** + * Clears the value of the 'customerId' field. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder clearCustomerId() { + fieldSetFlags()[2] = false; + return this; + } + + /** + * Gets the value of the 'orderId' field. + * @return The value. + */ + public long getOrderId() { + return orderId; + } + + + /** + * Sets the value of the 'orderId' field. + * @param value The value of 'orderId'. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder setOrderId(long value) { + validate(fields()[3], value); + this.orderId = value; + fieldSetFlags()[3] = true; + return this; + } + + /** + * Checks whether the 'orderId' field has been set. + * @return True if the 'orderId' field has been set, false otherwise. + */ + public boolean hasOrderId() { + return fieldSetFlags()[3]; + } + + + /** + * Clears the value of the 'orderId' field. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder clearOrderId() { + fieldSetFlags()[3] = false; + return this; + } + + /** + * Gets the value of the 'productId' field. + * @return The value. + */ + public long getProductId() { + return productId; + } + + + /** + * Sets the value of the 'productId' field. + * @param value The value of 'productId'. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder setProductId(long value) { + validate(fields()[4], value); + this.productId = value; + fieldSetFlags()[4] = true; + return this; + } + + /** + * Checks whether the 'productId' field has been set. + * @return True if the 'productId' field has been set, false otherwise. + */ + public boolean hasProductId() { + return fieldSetFlags()[4]; + } + + + /** + * Clears the value of the 'productId' field. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder clearProductId() { + fieldSetFlags()[4] = false; + return this; + } + + /** + * Gets the value of the 'quantity' field. + * @return The value. + */ + public int getQuantity() { + return quantity; + } + + + /** + * Sets the value of the 'quantity' field. + * @param value The value of 'quantity'. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder setQuantity(int value) { + validate(fields()[5], value); + this.quantity = value; + fieldSetFlags()[5] = true; + return this; + } + + /** + * Checks whether the 'quantity' field has been set. + * @return True if the 'quantity' field has been set, false otherwise. + */ + public boolean hasQuantity() { + return fieldSetFlags()[5]; + } + + + /** + * Clears the value of the 'quantity' field. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder clearQuantity() { + fieldSetFlags()[5] = false; + return this; + } + + @Override + @SuppressWarnings("unchecked") + public Order build() { + try { + Order record = new Order(); + record.id = fieldSetFlags()[0] ? this.id : (java.lang.CharSequence) defaultValue(fields()[0]); + record.state = fieldSetFlags()[1] ? this.state : (de.trion.microservices.avro.OrderState) defaultValue(fields()[1]); + record.customerId = fieldSetFlags()[2] ? this.customerId : (java.lang.Long) defaultValue(fields()[2]); + record.orderId = fieldSetFlags()[3] ? this.orderId : (java.lang.Long) defaultValue(fields()[3]); + record.productId = fieldSetFlags()[4] ? this.productId : (java.lang.Long) defaultValue(fields()[4]); + record.quantity = fieldSetFlags()[5] ? this.quantity : (java.lang.Integer) defaultValue(fields()[5]); + return record; + } catch (org.apache.avro.AvroMissingFieldException e) { + throw e; + } catch (java.lang.Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumWriter + WRITER$ = (org.apache.avro.io.DatumWriter)MODEL$.createDatumWriter(SCHEMA$); + + @Override public void writeExternal(java.io.ObjectOutput out) + throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumReader + READER$ = (org.apache.avro.io.DatumReader)MODEL$.createDatumReader(SCHEMA$); + + @Override public void readExternal(java.io.ObjectInput in) + throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + + @Override protected boolean hasCustomCoders() { return true; } + + @Override public void customEncode(org.apache.avro.io.Encoder out) + throws java.io.IOException + { + out.writeString(this.id); + + out.writeEnum(this.state.ordinal()); + + out.writeLong(this.customerId); + + out.writeLong(this.orderId); + + out.writeLong(this.productId); + + out.writeInt(this.quantity); + + } + + @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in) + throws java.io.IOException + { + org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); + if (fieldOrder == null) { + this.id = in.readString(this.id instanceof Utf8 ? (Utf8)this.id : null); + + this.state = de.trion.microservices.avro.OrderState.values()[in.readEnum()]; + + this.customerId = in.readLong(); + + this.orderId = in.readLong(); + + this.productId = in.readLong(); + + this.quantity = in.readInt(); + + } else { + for (int i = 0; i < 6; i++) { + switch (fieldOrder[i].pos()) { + case 0: + this.id = in.readString(this.id instanceof Utf8 ? (Utf8)this.id : null); + break; + + case 1: + this.state = de.trion.microservices.avro.OrderState.values()[in.readEnum()]; + break; + + case 2: + this.customerId = in.readLong(); + break; + + case 3: + this.orderId = in.readLong(); + break; + + case 4: + this.productId = in.readLong(); + break; + + case 5: + this.quantity = in.readInt(); + break; + + default: + throw new java.io.IOException("Corrupt ResolvingDecoder."); + } + } + } + } +} + + + + + + + + + + diff --git a/validate-user/src/main/java/de/trion/microservices/avro/OrderAndUser.java b/validate-user/src/main/java/de/trion/microservices/avro/OrderAndUser.java new file mode 100644 index 0000000..d3b9cfb --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/avro/OrderAndUser.java @@ -0,0 +1,516 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package de.trion.microservices.avro; + +import org.apache.avro.generic.GenericArray; +import org.apache.avro.specific.SpecificData; +import org.apache.avro.util.Utf8; +import org.apache.avro.message.BinaryMessageEncoder; +import org.apache.avro.message.BinaryMessageDecoder; +import org.apache.avro.message.SchemaStore; + +@org.apache.avro.specific.AvroGenerated +public class OrderAndUser extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + private static final long serialVersionUID = 6432660008992245598L; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"OrderAndUser\",\"namespace\":\"de.trion.microservices.avro\",\"fields\":[{\"name\":\"order\",\"type\":{\"type\":\"record\",\"name\":\"Order\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"state\",\"type\":{\"type\":\"enum\",\"name\":\"OrderState\",\"symbols\":[\"CREATED\",\"APPROVED\",\"DECLINED\"],\"default\":\"CREATED\"}},{\"name\":\"customerId\",\"type\":\"long\"},{\"name\":\"orderId\",\"type\":\"long\"},{\"name\":\"productId\",\"type\":\"long\"},{\"name\":\"quantity\",\"type\":\"int\"}]}},{\"name\":\"user\",\"type\":[\"null\",{\"type\":\"record\",\"name\":\"User\",\"fields\":[{\"name\":\"id\",\"type\":\"long\"},{\"name\":\"level\",\"type\":{\"type\":\"enum\",\"name\":\"CustomerLevel\",\"symbols\":[\"BRONZE\",\"SILVER\",\"GOLD\",\"UNWANTED\"]}},{\"name\":\"name\",\"type\":\"string\"}]}]}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + + private static SpecificData MODEL$ = new SpecificData(); + + private static final BinaryMessageEncoder ENCODER = + new BinaryMessageEncoder(MODEL$, SCHEMA$); + + private static final BinaryMessageDecoder DECODER = + new BinaryMessageDecoder(MODEL$, SCHEMA$); + + /** + * Return the BinaryMessageEncoder instance used by this class. + * @return the message encoder used by this class + */ + public static BinaryMessageEncoder getEncoder() { + return ENCODER; + } + + /** + * Return the BinaryMessageDecoder instance used by this class. + * @return the message decoder used by this class + */ + public static BinaryMessageDecoder getDecoder() { + return DECODER; + } + + /** + * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}. + * @param resolver a {@link SchemaStore} used to find schemas by fingerprint + * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore + */ + public static BinaryMessageDecoder createDecoder(SchemaStore resolver) { + return new BinaryMessageDecoder(MODEL$, SCHEMA$, resolver); + } + + /** + * Serializes this OrderAndUser to a ByteBuffer. + * @return a buffer holding the serialized data for this instance + * @throws java.io.IOException if this instance could not be serialized + */ + public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { + return ENCODER.encode(this); + } + + /** + * Deserializes a OrderAndUser from a ByteBuffer. + * @param b a byte buffer holding serialized data for an instance of this class + * @return a OrderAndUser instance decoded from the given buffer + * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class + */ + public static OrderAndUser fromByteBuffer( + java.nio.ByteBuffer b) throws java.io.IOException { + return DECODER.decode(b); + } + + @Deprecated public de.trion.microservices.avro.Order order; + @Deprecated public de.trion.microservices.avro.User user; + + /** + * Default constructor. Note that this does not initialize fields + * to their default values from the schema. If that is desired then + * one should use newBuilder(). + */ + public OrderAndUser() {} + + /** + * All-args constructor. + * @param order The new value for order + * @param user The new value for user + */ + public OrderAndUser(de.trion.microservices.avro.Order order, de.trion.microservices.avro.User user) { + this.order = order; + this.user = user; + } + + public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; } + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return order; + case 1: return user; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: order = (de.trion.microservices.avro.Order)value$; break; + case 1: user = (de.trion.microservices.avro.User)value$; break; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'order' field. + * @return The value of the 'order' field. + */ + public de.trion.microservices.avro.Order getOrder() { + return order; + } + + + /** + * Sets the value of the 'order' field. + * @param value the value to set. + */ + public void setOrder(de.trion.microservices.avro.Order value) { + this.order = value; + } + + /** + * Gets the value of the 'user' field. + * @return The value of the 'user' field. + */ + public de.trion.microservices.avro.User getUser() { + return user; + } + + + /** + * Sets the value of the 'user' field. + * @param value the value to set. + */ + public void setUser(de.trion.microservices.avro.User value) { + this.user = value; + } + + /** + * Creates a new OrderAndUser RecordBuilder. + * @return A new OrderAndUser RecordBuilder + */ + public static de.trion.microservices.avro.OrderAndUser.Builder newBuilder() { + return new de.trion.microservices.avro.OrderAndUser.Builder(); + } + + /** + * Creates a new OrderAndUser RecordBuilder by copying an existing Builder. + * @param other The existing builder to copy. + * @return A new OrderAndUser RecordBuilder + */ + public static de.trion.microservices.avro.OrderAndUser.Builder newBuilder(de.trion.microservices.avro.OrderAndUser.Builder other) { + if (other == null) { + return new de.trion.microservices.avro.OrderAndUser.Builder(); + } else { + return new de.trion.microservices.avro.OrderAndUser.Builder(other); + } + } + + /** + * Creates a new OrderAndUser RecordBuilder by copying an existing OrderAndUser instance. + * @param other The existing instance to copy. + * @return A new OrderAndUser RecordBuilder + */ + public static de.trion.microservices.avro.OrderAndUser.Builder newBuilder(de.trion.microservices.avro.OrderAndUser other) { + if (other == null) { + return new de.trion.microservices.avro.OrderAndUser.Builder(); + } else { + return new de.trion.microservices.avro.OrderAndUser.Builder(other); + } + } + + /** + * RecordBuilder for OrderAndUser instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private de.trion.microservices.avro.Order order; + private de.trion.microservices.avro.Order.Builder orderBuilder; + private de.trion.microservices.avro.User user; + private de.trion.microservices.avro.User.Builder userBuilder; + + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$); + } + + /** + * Creates a Builder by copying an existing Builder. + * @param other The existing Builder to copy. + */ + private Builder(de.trion.microservices.avro.OrderAndUser.Builder other) { + super(other); + if (isValidValue(fields()[0], other.order)) { + this.order = data().deepCopy(fields()[0].schema(), other.order); + fieldSetFlags()[0] = other.fieldSetFlags()[0]; + } + if (other.hasOrderBuilder()) { + this.orderBuilder = de.trion.microservices.avro.Order.newBuilder(other.getOrderBuilder()); + } + if (isValidValue(fields()[1], other.user)) { + this.user = data().deepCopy(fields()[1].schema(), other.user); + fieldSetFlags()[1] = other.fieldSetFlags()[1]; + } + if (other.hasUserBuilder()) { + this.userBuilder = de.trion.microservices.avro.User.newBuilder(other.getUserBuilder()); + } + } + + /** + * Creates a Builder by copying an existing OrderAndUser instance + * @param other The existing instance to copy. + */ + private Builder(de.trion.microservices.avro.OrderAndUser other) { + super(SCHEMA$); + if (isValidValue(fields()[0], other.order)) { + this.order = data().deepCopy(fields()[0].schema(), other.order); + fieldSetFlags()[0] = true; + } + this.orderBuilder = null; + if (isValidValue(fields()[1], other.user)) { + this.user = data().deepCopy(fields()[1].schema(), other.user); + fieldSetFlags()[1] = true; + } + this.userBuilder = null; + } + + /** + * Gets the value of the 'order' field. + * @return The value. + */ + public de.trion.microservices.avro.Order getOrder() { + return order; + } + + + /** + * Sets the value of the 'order' field. + * @param value The value of 'order'. + * @return This builder. + */ + public de.trion.microservices.avro.OrderAndUser.Builder setOrder(de.trion.microservices.avro.Order value) { + validate(fields()[0], value); + this.orderBuilder = null; + this.order = value; + fieldSetFlags()[0] = true; + return this; + } + + /** + * Checks whether the 'order' field has been set. + * @return True if the 'order' field has been set, false otherwise. + */ + public boolean hasOrder() { + return fieldSetFlags()[0]; + } + + /** + * Gets the Builder instance for the 'order' field and creates one if it doesn't exist yet. + * @return This builder. + */ + public de.trion.microservices.avro.Order.Builder getOrderBuilder() { + if (orderBuilder == null) { + if (hasOrder()) { + setOrderBuilder(de.trion.microservices.avro.Order.newBuilder(order)); + } else { + setOrderBuilder(de.trion.microservices.avro.Order.newBuilder()); + } + } + return orderBuilder; + } + + /** + * Sets the Builder instance for the 'order' field + * @param value The builder instance that must be set. + * @return This builder. + */ + public de.trion.microservices.avro.OrderAndUser.Builder setOrderBuilder(de.trion.microservices.avro.Order.Builder value) { + clearOrder(); + orderBuilder = value; + return this; + } + + /** + * Checks whether the 'order' field has an active Builder instance + * @return True if the 'order' field has an active Builder instance + */ + public boolean hasOrderBuilder() { + return orderBuilder != null; + } + + /** + * Clears the value of the 'order' field. + * @return This builder. + */ + public de.trion.microservices.avro.OrderAndUser.Builder clearOrder() { + order = null; + orderBuilder = null; + fieldSetFlags()[0] = false; + return this; + } + + /** + * Gets the value of the 'user' field. + * @return The value. + */ + public de.trion.microservices.avro.User getUser() { + return user; + } + + + /** + * Sets the value of the 'user' field. + * @param value The value of 'user'. + * @return This builder. + */ + public de.trion.microservices.avro.OrderAndUser.Builder setUser(de.trion.microservices.avro.User value) { + validate(fields()[1], value); + this.userBuilder = null; + this.user = value; + fieldSetFlags()[1] = true; + return this; + } + + /** + * Checks whether the 'user' field has been set. + * @return True if the 'user' field has been set, false otherwise. + */ + public boolean hasUser() { + return fieldSetFlags()[1]; + } + + /** + * Gets the Builder instance for the 'user' field and creates one if it doesn't exist yet. + * @return This builder. + */ + public de.trion.microservices.avro.User.Builder getUserBuilder() { + if (userBuilder == null) { + if (hasUser()) { + setUserBuilder(de.trion.microservices.avro.User.newBuilder(user)); + } else { + setUserBuilder(de.trion.microservices.avro.User.newBuilder()); + } + } + return userBuilder; + } + + /** + * Sets the Builder instance for the 'user' field + * @param value The builder instance that must be set. + * @return This builder. + */ + public de.trion.microservices.avro.OrderAndUser.Builder setUserBuilder(de.trion.microservices.avro.User.Builder value) { + clearUser(); + userBuilder = value; + return this; + } + + /** + * Checks whether the 'user' field has an active Builder instance + * @return True if the 'user' field has an active Builder instance + */ + public boolean hasUserBuilder() { + return userBuilder != null; + } + + /** + * Clears the value of the 'user' field. + * @return This builder. + */ + public de.trion.microservices.avro.OrderAndUser.Builder clearUser() { + user = null; + userBuilder = null; + fieldSetFlags()[1] = false; + return this; + } + + @Override + @SuppressWarnings("unchecked") + public OrderAndUser build() { + try { + OrderAndUser record = new OrderAndUser(); + if (orderBuilder != null) { + try { + record.order = this.orderBuilder.build(); + } catch (org.apache.avro.AvroMissingFieldException e) { + e.addParentField(record.getSchema().getField("order")); + throw e; + } + } else { + record.order = fieldSetFlags()[0] ? this.order : (de.trion.microservices.avro.Order) defaultValue(fields()[0]); + } + if (userBuilder != null) { + try { + record.user = this.userBuilder.build(); + } catch (org.apache.avro.AvroMissingFieldException e) { + e.addParentField(record.getSchema().getField("user")); + throw e; + } + } else { + record.user = fieldSetFlags()[1] ? this.user : (de.trion.microservices.avro.User) defaultValue(fields()[1]); + } + return record; + } catch (org.apache.avro.AvroMissingFieldException e) { + throw e; + } catch (java.lang.Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumWriter + WRITER$ = (org.apache.avro.io.DatumWriter)MODEL$.createDatumWriter(SCHEMA$); + + @Override public void writeExternal(java.io.ObjectOutput out) + throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumReader + READER$ = (org.apache.avro.io.DatumReader)MODEL$.createDatumReader(SCHEMA$); + + @Override public void readExternal(java.io.ObjectInput in) + throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + + @Override protected boolean hasCustomCoders() { return true; } + + @Override public void customEncode(org.apache.avro.io.Encoder out) + throws java.io.IOException + { + this.order.customEncode(out); + + if (this.user == null) { + out.writeIndex(0); + out.writeNull(); + } else { + out.writeIndex(1); + this.user.customEncode(out); + } + + } + + @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in) + throws java.io.IOException + { + org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); + if (fieldOrder == null) { + if (this.order == null) { + this.order = new de.trion.microservices.avro.Order(); + } + this.order.customDecode(in); + + if (in.readIndex() != 1) { + in.readNull(); + this.user = null; + } else { + if (this.user == null) { + this.user = new de.trion.microservices.avro.User(); + } + this.user.customDecode(in); + } + + } else { + for (int i = 0; i < 2; i++) { + switch (fieldOrder[i].pos()) { + case 0: + if (this.order == null) { + this.order = new de.trion.microservices.avro.Order(); + } + this.order.customDecode(in); + break; + + case 1: + if (in.readIndex() != 1) { + in.readNull(); + this.user = null; + } else { + if (this.user == null) { + this.user = new de.trion.microservices.avro.User(); + } + this.user.customDecode(in); + } + break; + + default: + throw new java.io.IOException("Corrupt ResolvingDecoder."); + } + } + } + } +} + + + + + + + + + + diff --git a/validate-user/src/main/java/de/trion/microservices/avro/OrderState.java b/validate-user/src/main/java/de/trion/microservices/avro/OrderState.java new file mode 100644 index 0000000..e06d650 --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/avro/OrderState.java @@ -0,0 +1,13 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package de.trion.microservices.avro; +@org.apache.avro.specific.AvroGenerated +public enum OrderState implements org.apache.avro.generic.GenericEnumSymbol { + CREATED, APPROVED, DECLINED ; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"OrderState\",\"namespace\":\"de.trion.microservices.avro\",\"symbols\":[\"CREATED\",\"APPROVED\",\"DECLINED\"],\"default\":\"CREATED\"}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + public org.apache.avro.Schema getSchema() { return SCHEMA$; } +} diff --git a/validate-user/src/main/java/de/trion/microservices/avro/OrderValidation.java b/validate-user/src/main/java/de/trion/microservices/avro/OrderValidation.java new file mode 100644 index 0000000..c15f3af --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/avro/OrderValidation.java @@ -0,0 +1,587 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package de.trion.microservices.avro; + +import org.apache.avro.generic.GenericArray; +import org.apache.avro.specific.SpecificData; +import org.apache.avro.util.Utf8; +import org.apache.avro.message.BinaryMessageEncoder; +import org.apache.avro.message.BinaryMessageDecoder; +import org.apache.avro.message.SchemaStore; + +@org.apache.avro.specific.AvroGenerated +public class OrderValidation extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + private static final long serialVersionUID = 8233123483892962178L; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"OrderValidation\",\"namespace\":\"de.trion.microservices.avro\",\"fields\":[{\"name\":\"orderId\",\"type\":\"string\"},{\"name\":\"checkType\",\"type\":{\"type\":\"enum\",\"name\":\"OrderValidationType\",\"symbols\":[\"ORDER_DETAILS_CHECK\",\"ORDER_USER_CHECK\"]}},{\"name\":\"validationResult\",\"type\":{\"type\":\"enum\",\"name\":\"OrderValidationResult\",\"symbols\":[\"PASS\",\"FAIL\"]}},{\"name\":\"messages\",\"type\":{\"type\":\"array\",\"items\":\"string\"}}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + + private static SpecificData MODEL$ = new SpecificData(); + + private static final BinaryMessageEncoder ENCODER = + new BinaryMessageEncoder(MODEL$, SCHEMA$); + + private static final BinaryMessageDecoder DECODER = + new BinaryMessageDecoder(MODEL$, SCHEMA$); + + /** + * Return the BinaryMessageEncoder instance used by this class. + * @return the message encoder used by this class + */ + public static BinaryMessageEncoder getEncoder() { + return ENCODER; + } + + /** + * Return the BinaryMessageDecoder instance used by this class. + * @return the message decoder used by this class + */ + public static BinaryMessageDecoder getDecoder() { + return DECODER; + } + + /** + * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}. + * @param resolver a {@link SchemaStore} used to find schemas by fingerprint + * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore + */ + public static BinaryMessageDecoder createDecoder(SchemaStore resolver) { + return new BinaryMessageDecoder(MODEL$, SCHEMA$, resolver); + } + + /** + * Serializes this OrderValidation to a ByteBuffer. + * @return a buffer holding the serialized data for this instance + * @throws java.io.IOException if this instance could not be serialized + */ + public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { + return ENCODER.encode(this); + } + + /** + * Deserializes a OrderValidation from a ByteBuffer. + * @param b a byte buffer holding serialized data for an instance of this class + * @return a OrderValidation instance decoded from the given buffer + * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class + */ + public static OrderValidation fromByteBuffer( + java.nio.ByteBuffer b) throws java.io.IOException { + return DECODER.decode(b); + } + + @Deprecated public java.lang.CharSequence orderId; + @Deprecated public de.trion.microservices.avro.OrderValidationType checkType; + @Deprecated public de.trion.microservices.avro.OrderValidationResult validationResult; + @Deprecated public java.util.List messages; + + /** + * Default constructor. Note that this does not initialize fields + * to their default values from the schema. If that is desired then + * one should use newBuilder(). + */ + public OrderValidation() {} + + /** + * All-args constructor. + * @param orderId The new value for orderId + * @param checkType The new value for checkType + * @param validationResult The new value for validationResult + * @param messages The new value for messages + */ + public OrderValidation(java.lang.CharSequence orderId, de.trion.microservices.avro.OrderValidationType checkType, de.trion.microservices.avro.OrderValidationResult validationResult, java.util.List messages) { + this.orderId = orderId; + this.checkType = checkType; + this.validationResult = validationResult; + this.messages = messages; + } + + public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; } + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return orderId; + case 1: return checkType; + case 2: return validationResult; + case 3: return messages; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: orderId = (java.lang.CharSequence)value$; break; + case 1: checkType = (de.trion.microservices.avro.OrderValidationType)value$; break; + case 2: validationResult = (de.trion.microservices.avro.OrderValidationResult)value$; break; + case 3: messages = (java.util.List)value$; break; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'orderId' field. + * @return The value of the 'orderId' field. + */ + public java.lang.CharSequence getOrderId() { + return orderId; + } + + + /** + * Sets the value of the 'orderId' field. + * @param value the value to set. + */ + public void setOrderId(java.lang.CharSequence value) { + this.orderId = value; + } + + /** + * Gets the value of the 'checkType' field. + * @return The value of the 'checkType' field. + */ + public de.trion.microservices.avro.OrderValidationType getCheckType() { + return checkType; + } + + + /** + * Sets the value of the 'checkType' field. + * @param value the value to set. + */ + public void setCheckType(de.trion.microservices.avro.OrderValidationType value) { + this.checkType = value; + } + + /** + * Gets the value of the 'validationResult' field. + * @return The value of the 'validationResult' field. + */ + public de.trion.microservices.avro.OrderValidationResult getValidationResult() { + return validationResult; + } + + + /** + * Sets the value of the 'validationResult' field. + * @param value the value to set. + */ + public void setValidationResult(de.trion.microservices.avro.OrderValidationResult value) { + this.validationResult = value; + } + + /** + * Gets the value of the 'messages' field. + * @return The value of the 'messages' field. + */ + public java.util.List getMessages() { + return messages; + } + + + /** + * Sets the value of the 'messages' field. + * @param value the value to set. + */ + public void setMessages(java.util.List value) { + this.messages = value; + } + + /** + * Creates a new OrderValidation RecordBuilder. + * @return A new OrderValidation RecordBuilder + */ + public static de.trion.microservices.avro.OrderValidation.Builder newBuilder() { + return new de.trion.microservices.avro.OrderValidation.Builder(); + } + + /** + * Creates a new OrderValidation RecordBuilder by copying an existing Builder. + * @param other The existing builder to copy. + * @return A new OrderValidation RecordBuilder + */ + public static de.trion.microservices.avro.OrderValidation.Builder newBuilder(de.trion.microservices.avro.OrderValidation.Builder other) { + if (other == null) { + return new de.trion.microservices.avro.OrderValidation.Builder(); + } else { + return new de.trion.microservices.avro.OrderValidation.Builder(other); + } + } + + /** + * Creates a new OrderValidation RecordBuilder by copying an existing OrderValidation instance. + * @param other The existing instance to copy. + * @return A new OrderValidation RecordBuilder + */ + public static de.trion.microservices.avro.OrderValidation.Builder newBuilder(de.trion.microservices.avro.OrderValidation other) { + if (other == null) { + return new de.trion.microservices.avro.OrderValidation.Builder(); + } else { + return new de.trion.microservices.avro.OrderValidation.Builder(other); + } + } + + /** + * RecordBuilder for OrderValidation instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private java.lang.CharSequence orderId; + private de.trion.microservices.avro.OrderValidationType checkType; + private de.trion.microservices.avro.OrderValidationResult validationResult; + private java.util.List messages; + + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$); + } + + /** + * Creates a Builder by copying an existing Builder. + * @param other The existing Builder to copy. + */ + private Builder(de.trion.microservices.avro.OrderValidation.Builder other) { + super(other); + if (isValidValue(fields()[0], other.orderId)) { + this.orderId = data().deepCopy(fields()[0].schema(), other.orderId); + fieldSetFlags()[0] = other.fieldSetFlags()[0]; + } + if (isValidValue(fields()[1], other.checkType)) { + this.checkType = data().deepCopy(fields()[1].schema(), other.checkType); + fieldSetFlags()[1] = other.fieldSetFlags()[1]; + } + if (isValidValue(fields()[2], other.validationResult)) { + this.validationResult = data().deepCopy(fields()[2].schema(), other.validationResult); + fieldSetFlags()[2] = other.fieldSetFlags()[2]; + } + if (isValidValue(fields()[3], other.messages)) { + this.messages = data().deepCopy(fields()[3].schema(), other.messages); + fieldSetFlags()[3] = other.fieldSetFlags()[3]; + } + } + + /** + * Creates a Builder by copying an existing OrderValidation instance + * @param other The existing instance to copy. + */ + private Builder(de.trion.microservices.avro.OrderValidation other) { + super(SCHEMA$); + if (isValidValue(fields()[0], other.orderId)) { + this.orderId = data().deepCopy(fields()[0].schema(), other.orderId); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.checkType)) { + this.checkType = data().deepCopy(fields()[1].schema(), other.checkType); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.validationResult)) { + this.validationResult = data().deepCopy(fields()[2].schema(), other.validationResult); + fieldSetFlags()[2] = true; + } + if (isValidValue(fields()[3], other.messages)) { + this.messages = data().deepCopy(fields()[3].schema(), other.messages); + fieldSetFlags()[3] = true; + } + } + + /** + * Gets the value of the 'orderId' field. + * @return The value. + */ + public java.lang.CharSequence getOrderId() { + return orderId; + } + + + /** + * Sets the value of the 'orderId' field. + * @param value The value of 'orderId'. + * @return This builder. + */ + public de.trion.microservices.avro.OrderValidation.Builder setOrderId(java.lang.CharSequence value) { + validate(fields()[0], value); + this.orderId = value; + fieldSetFlags()[0] = true; + return this; + } + + /** + * Checks whether the 'orderId' field has been set. + * @return True if the 'orderId' field has been set, false otherwise. + */ + public boolean hasOrderId() { + return fieldSetFlags()[0]; + } + + + /** + * Clears the value of the 'orderId' field. + * @return This builder. + */ + public de.trion.microservices.avro.OrderValidation.Builder clearOrderId() { + orderId = null; + fieldSetFlags()[0] = false; + return this; + } + + /** + * Gets the value of the 'checkType' field. + * @return The value. + */ + public de.trion.microservices.avro.OrderValidationType getCheckType() { + return checkType; + } + + + /** + * Sets the value of the 'checkType' field. + * @param value The value of 'checkType'. + * @return This builder. + */ + public de.trion.microservices.avro.OrderValidation.Builder setCheckType(de.trion.microservices.avro.OrderValidationType value) { + validate(fields()[1], value); + this.checkType = value; + fieldSetFlags()[1] = true; + return this; + } + + /** + * Checks whether the 'checkType' field has been set. + * @return True if the 'checkType' field has been set, false otherwise. + */ + public boolean hasCheckType() { + return fieldSetFlags()[1]; + } + + + /** + * Clears the value of the 'checkType' field. + * @return This builder. + */ + public de.trion.microservices.avro.OrderValidation.Builder clearCheckType() { + checkType = null; + fieldSetFlags()[1] = false; + return this; + } + + /** + * Gets the value of the 'validationResult' field. + * @return The value. + */ + public de.trion.microservices.avro.OrderValidationResult getValidationResult() { + return validationResult; + } + + + /** + * Sets the value of the 'validationResult' field. + * @param value The value of 'validationResult'. + * @return This builder. + */ + public de.trion.microservices.avro.OrderValidation.Builder setValidationResult(de.trion.microservices.avro.OrderValidationResult value) { + validate(fields()[2], value); + this.validationResult = value; + fieldSetFlags()[2] = true; + return this; + } + + /** + * Checks whether the 'validationResult' field has been set. + * @return True if the 'validationResult' field has been set, false otherwise. + */ + public boolean hasValidationResult() { + return fieldSetFlags()[2]; + } + + + /** + * Clears the value of the 'validationResult' field. + * @return This builder. + */ + public de.trion.microservices.avro.OrderValidation.Builder clearValidationResult() { + validationResult = null; + fieldSetFlags()[2] = false; + return this; + } + + /** + * Gets the value of the 'messages' field. + * @return The value. + */ + public java.util.List getMessages() { + return messages; + } + + + /** + * Sets the value of the 'messages' field. + * @param value The value of 'messages'. + * @return This builder. + */ + public de.trion.microservices.avro.OrderValidation.Builder setMessages(java.util.List value) { + validate(fields()[3], value); + this.messages = value; + fieldSetFlags()[3] = true; + return this; + } + + /** + * Checks whether the 'messages' field has been set. + * @return True if the 'messages' field has been set, false otherwise. + */ + public boolean hasMessages() { + return fieldSetFlags()[3]; + } + + + /** + * Clears the value of the 'messages' field. + * @return This builder. + */ + public de.trion.microservices.avro.OrderValidation.Builder clearMessages() { + messages = null; + fieldSetFlags()[3] = false; + return this; + } + + @Override + @SuppressWarnings("unchecked") + public OrderValidation build() { + try { + OrderValidation record = new OrderValidation(); + record.orderId = fieldSetFlags()[0] ? this.orderId : (java.lang.CharSequence) defaultValue(fields()[0]); + record.checkType = fieldSetFlags()[1] ? this.checkType : (de.trion.microservices.avro.OrderValidationType) defaultValue(fields()[1]); + record.validationResult = fieldSetFlags()[2] ? this.validationResult : (de.trion.microservices.avro.OrderValidationResult) defaultValue(fields()[2]); + record.messages = fieldSetFlags()[3] ? this.messages : (java.util.List) defaultValue(fields()[3]); + return record; + } catch (org.apache.avro.AvroMissingFieldException e) { + throw e; + } catch (java.lang.Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumWriter + WRITER$ = (org.apache.avro.io.DatumWriter)MODEL$.createDatumWriter(SCHEMA$); + + @Override public void writeExternal(java.io.ObjectOutput out) + throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumReader + READER$ = (org.apache.avro.io.DatumReader)MODEL$.createDatumReader(SCHEMA$); + + @Override public void readExternal(java.io.ObjectInput in) + throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + + @Override protected boolean hasCustomCoders() { return true; } + + @Override public void customEncode(org.apache.avro.io.Encoder out) + throws java.io.IOException + { + out.writeString(this.orderId); + + out.writeEnum(this.checkType.ordinal()); + + out.writeEnum(this.validationResult.ordinal()); + + long size0 = this.messages.size(); + out.writeArrayStart(); + out.setItemCount(size0); + long actualSize0 = 0; + for (java.lang.CharSequence e0: this.messages) { + actualSize0++; + out.startItem(); + out.writeString(e0); + } + out.writeArrayEnd(); + if (actualSize0 != size0) + throw new java.util.ConcurrentModificationException("Array-size written was " + size0 + ", but element count was " + actualSize0 + "."); + + } + + @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in) + throws java.io.IOException + { + org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); + if (fieldOrder == null) { + this.orderId = in.readString(this.orderId instanceof Utf8 ? (Utf8)this.orderId : null); + + this.checkType = de.trion.microservices.avro.OrderValidationType.values()[in.readEnum()]; + + this.validationResult = de.trion.microservices.avro.OrderValidationResult.values()[in.readEnum()]; + + long size0 = in.readArrayStart(); + java.util.List a0 = this.messages; + if (a0 == null) { + a0 = new SpecificData.Array((int)size0, SCHEMA$.getField("messages").schema()); + this.messages = a0; + } else a0.clear(); + SpecificData.Array ga0 = (a0 instanceof SpecificData.Array ? (SpecificData.Array)a0 : null); + for ( ; 0 < size0; size0 = in.arrayNext()) { + for ( ; size0 != 0; size0--) { + java.lang.CharSequence e0 = (ga0 != null ? ga0.peek() : null); + e0 = in.readString(e0 instanceof Utf8 ? (Utf8)e0 : null); + a0.add(e0); + } + } + + } else { + for (int i = 0; i < 4; i++) { + switch (fieldOrder[i].pos()) { + case 0: + this.orderId = in.readString(this.orderId instanceof Utf8 ? (Utf8)this.orderId : null); + break; + + case 1: + this.checkType = de.trion.microservices.avro.OrderValidationType.values()[in.readEnum()]; + break; + + case 2: + this.validationResult = de.trion.microservices.avro.OrderValidationResult.values()[in.readEnum()]; + break; + + case 3: + long size0 = in.readArrayStart(); + java.util.List a0 = this.messages; + if (a0 == null) { + a0 = new SpecificData.Array((int)size0, SCHEMA$.getField("messages").schema()); + this.messages = a0; + } else a0.clear(); + SpecificData.Array ga0 = (a0 instanceof SpecificData.Array ? (SpecificData.Array)a0 : null); + for ( ; 0 < size0; size0 = in.arrayNext()) { + for ( ; size0 != 0; size0--) { + java.lang.CharSequence e0 = (ga0 != null ? ga0.peek() : null); + e0 = in.readString(e0 instanceof Utf8 ? (Utf8)e0 : null); + a0.add(e0); + } + } + break; + + default: + throw new java.io.IOException("Corrupt ResolvingDecoder."); + } + } + } + } +} + + + + + + + + + + diff --git a/validate-user/src/main/java/de/trion/microservices/avro/OrderValidationResult.java b/validate-user/src/main/java/de/trion/microservices/avro/OrderValidationResult.java new file mode 100644 index 0000000..879e136 --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/avro/OrderValidationResult.java @@ -0,0 +1,13 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package de.trion.microservices.avro; +@org.apache.avro.specific.AvroGenerated +public enum OrderValidationResult implements org.apache.avro.generic.GenericEnumSymbol { + PASS, FAIL ; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"OrderValidationResult\",\"namespace\":\"de.trion.microservices.avro\",\"symbols\":[\"PASS\",\"FAIL\"]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + public org.apache.avro.Schema getSchema() { return SCHEMA$; } +} diff --git a/validate-user/src/main/java/de/trion/microservices/avro/OrderValidationType.java b/validate-user/src/main/java/de/trion/microservices/avro/OrderValidationType.java new file mode 100644 index 0000000..cdd7147 --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/avro/OrderValidationType.java @@ -0,0 +1,13 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package de.trion.microservices.avro; +@org.apache.avro.specific.AvroGenerated +public enum OrderValidationType implements org.apache.avro.generic.GenericEnumSymbol { + ORDER_DETAILS_CHECK, ORDER_USER_CHECK ; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"OrderValidationType\",\"namespace\":\"de.trion.microservices.avro\",\"symbols\":[\"ORDER_DETAILS_CHECK\",\"ORDER_USER_CHECK\"]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + public org.apache.avro.Schema getSchema() { return SCHEMA$; } +} diff --git a/validate-user/src/main/java/de/trion/microservices/avro/User.java b/validate-user/src/main/java/de/trion/microservices/avro/User.java new file mode 100644 index 0000000..c745e7a --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/avro/User.java @@ -0,0 +1,469 @@ +/** + * Autogenerated by Avro + * + * DO NOT EDIT DIRECTLY + */ +package de.trion.microservices.avro; + +import org.apache.avro.generic.GenericArray; +import org.apache.avro.specific.SpecificData; +import org.apache.avro.util.Utf8; +import org.apache.avro.message.BinaryMessageEncoder; +import org.apache.avro.message.BinaryMessageDecoder; +import org.apache.avro.message.SchemaStore; + +@org.apache.avro.specific.AvroGenerated +public class User extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { + private static final long serialVersionUID = 2154150202977610190L; + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"User\",\"namespace\":\"de.trion.microservices.avro\",\"fields\":[{\"name\":\"id\",\"type\":\"long\"},{\"name\":\"level\",\"type\":{\"type\":\"enum\",\"name\":\"CustomerLevel\",\"symbols\":[\"BRONZE\",\"SILVER\",\"GOLD\",\"UNWANTED\"]}},{\"name\":\"name\",\"type\":\"string\"}]}"); + public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } + + private static SpecificData MODEL$ = new SpecificData(); + + private static final BinaryMessageEncoder ENCODER = + new BinaryMessageEncoder(MODEL$, SCHEMA$); + + private static final BinaryMessageDecoder DECODER = + new BinaryMessageDecoder(MODEL$, SCHEMA$); + + /** + * Return the BinaryMessageEncoder instance used by this class. + * @return the message encoder used by this class + */ + public static BinaryMessageEncoder getEncoder() { + return ENCODER; + } + + /** + * Return the BinaryMessageDecoder instance used by this class. + * @return the message decoder used by this class + */ + public static BinaryMessageDecoder getDecoder() { + return DECODER; + } + + /** + * Create a new BinaryMessageDecoder instance for this class that uses the specified {@link SchemaStore}. + * @param resolver a {@link SchemaStore} used to find schemas by fingerprint + * @return a BinaryMessageDecoder instance for this class backed by the given SchemaStore + */ + public static BinaryMessageDecoder createDecoder(SchemaStore resolver) { + return new BinaryMessageDecoder(MODEL$, SCHEMA$, resolver); + } + + /** + * Serializes this User to a ByteBuffer. + * @return a buffer holding the serialized data for this instance + * @throws java.io.IOException if this instance could not be serialized + */ + public java.nio.ByteBuffer toByteBuffer() throws java.io.IOException { + return ENCODER.encode(this); + } + + /** + * Deserializes a User from a ByteBuffer. + * @param b a byte buffer holding serialized data for an instance of this class + * @return a User instance decoded from the given buffer + * @throws java.io.IOException if the given bytes could not be deserialized into an instance of this class + */ + public static User fromByteBuffer( + java.nio.ByteBuffer b) throws java.io.IOException { + return DECODER.decode(b); + } + + @Deprecated public long id; + @Deprecated public de.trion.microservices.avro.CustomerLevel level; + @Deprecated public java.lang.CharSequence name; + + /** + * Default constructor. Note that this does not initialize fields + * to their default values from the schema. If that is desired then + * one should use newBuilder(). + */ + public User() {} + + /** + * All-args constructor. + * @param id The new value for id + * @param level The new value for level + * @param name The new value for name + */ + public User(java.lang.Long id, de.trion.microservices.avro.CustomerLevel level, java.lang.CharSequence name) { + this.id = id; + this.level = level; + this.name = name; + } + + public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; } + public org.apache.avro.Schema getSchema() { return SCHEMA$; } + // Used by DatumWriter. Applications should not call. + public java.lang.Object get(int field$) { + switch (field$) { + case 0: return id; + case 1: return level; + case 2: return name; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + // Used by DatumReader. Applications should not call. + @SuppressWarnings(value="unchecked") + public void put(int field$, java.lang.Object value$) { + switch (field$) { + case 0: id = (java.lang.Long)value$; break; + case 1: level = (de.trion.microservices.avro.CustomerLevel)value$; break; + case 2: name = (java.lang.CharSequence)value$; break; + default: throw new org.apache.avro.AvroRuntimeException("Bad index"); + } + } + + /** + * Gets the value of the 'id' field. + * @return The value of the 'id' field. + */ + public long getId() { + return id; + } + + + /** + * Sets the value of the 'id' field. + * @param value the value to set. + */ + public void setId(long value) { + this.id = value; + } + + /** + * Gets the value of the 'level' field. + * @return The value of the 'level' field. + */ + public de.trion.microservices.avro.CustomerLevel getLevel() { + return level; + } + + + /** + * Sets the value of the 'level' field. + * @param value the value to set. + */ + public void setLevel(de.trion.microservices.avro.CustomerLevel value) { + this.level = value; + } + + /** + * Gets the value of the 'name' field. + * @return The value of the 'name' field. + */ + public java.lang.CharSequence getName() { + return name; + } + + + /** + * Sets the value of the 'name' field. + * @param value the value to set. + */ + public void setName(java.lang.CharSequence value) { + this.name = value; + } + + /** + * Creates a new User RecordBuilder. + * @return A new User RecordBuilder + */ + public static de.trion.microservices.avro.User.Builder newBuilder() { + return new de.trion.microservices.avro.User.Builder(); + } + + /** + * Creates a new User RecordBuilder by copying an existing Builder. + * @param other The existing builder to copy. + * @return A new User RecordBuilder + */ + public static de.trion.microservices.avro.User.Builder newBuilder(de.trion.microservices.avro.User.Builder other) { + if (other == null) { + return new de.trion.microservices.avro.User.Builder(); + } else { + return new de.trion.microservices.avro.User.Builder(other); + } + } + + /** + * Creates a new User RecordBuilder by copying an existing User instance. + * @param other The existing instance to copy. + * @return A new User RecordBuilder + */ + public static de.trion.microservices.avro.User.Builder newBuilder(de.trion.microservices.avro.User other) { + if (other == null) { + return new de.trion.microservices.avro.User.Builder(); + } else { + return new de.trion.microservices.avro.User.Builder(other); + } + } + + /** + * RecordBuilder for User instances. + */ + public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase + implements org.apache.avro.data.RecordBuilder { + + private long id; + private de.trion.microservices.avro.CustomerLevel level; + private java.lang.CharSequence name; + + /** Creates a new Builder */ + private Builder() { + super(SCHEMA$); + } + + /** + * Creates a Builder by copying an existing Builder. + * @param other The existing Builder to copy. + */ + private Builder(de.trion.microservices.avro.User.Builder other) { + super(other); + if (isValidValue(fields()[0], other.id)) { + this.id = data().deepCopy(fields()[0].schema(), other.id); + fieldSetFlags()[0] = other.fieldSetFlags()[0]; + } + if (isValidValue(fields()[1], other.level)) { + this.level = data().deepCopy(fields()[1].schema(), other.level); + fieldSetFlags()[1] = other.fieldSetFlags()[1]; + } + if (isValidValue(fields()[2], other.name)) { + this.name = data().deepCopy(fields()[2].schema(), other.name); + fieldSetFlags()[2] = other.fieldSetFlags()[2]; + } + } + + /** + * Creates a Builder by copying an existing User instance + * @param other The existing instance to copy. + */ + private Builder(de.trion.microservices.avro.User other) { + super(SCHEMA$); + if (isValidValue(fields()[0], other.id)) { + this.id = data().deepCopy(fields()[0].schema(), other.id); + fieldSetFlags()[0] = true; + } + if (isValidValue(fields()[1], other.level)) { + this.level = data().deepCopy(fields()[1].schema(), other.level); + fieldSetFlags()[1] = true; + } + if (isValidValue(fields()[2], other.name)) { + this.name = data().deepCopy(fields()[2].schema(), other.name); + fieldSetFlags()[2] = true; + } + } + + /** + * Gets the value of the 'id' field. + * @return The value. + */ + public long getId() { + return id; + } + + + /** + * Sets the value of the 'id' field. + * @param value The value of 'id'. + * @return This builder. + */ + public de.trion.microservices.avro.User.Builder setId(long value) { + validate(fields()[0], value); + this.id = value; + fieldSetFlags()[0] = true; + return this; + } + + /** + * Checks whether the 'id' field has been set. + * @return True if the 'id' field has been set, false otherwise. + */ + public boolean hasId() { + return fieldSetFlags()[0]; + } + + + /** + * Clears the value of the 'id' field. + * @return This builder. + */ + public de.trion.microservices.avro.User.Builder clearId() { + fieldSetFlags()[0] = false; + return this; + } + + /** + * Gets the value of the 'level' field. + * @return The value. + */ + public de.trion.microservices.avro.CustomerLevel getLevel() { + return level; + } + + + /** + * Sets the value of the 'level' field. + * @param value The value of 'level'. + * @return This builder. + */ + public de.trion.microservices.avro.User.Builder setLevel(de.trion.microservices.avro.CustomerLevel value) { + validate(fields()[1], value); + this.level = value; + fieldSetFlags()[1] = true; + return this; + } + + /** + * Checks whether the 'level' field has been set. + * @return True if the 'level' field has been set, false otherwise. + */ + public boolean hasLevel() { + return fieldSetFlags()[1]; + } + + + /** + * Clears the value of the 'level' field. + * @return This builder. + */ + public de.trion.microservices.avro.User.Builder clearLevel() { + level = null; + fieldSetFlags()[1] = false; + return this; + } + + /** + * Gets the value of the 'name' field. + * @return The value. + */ + public java.lang.CharSequence getName() { + return name; + } + + + /** + * Sets the value of the 'name' field. + * @param value The value of 'name'. + * @return This builder. + */ + public de.trion.microservices.avro.User.Builder setName(java.lang.CharSequence value) { + validate(fields()[2], value); + this.name = value; + fieldSetFlags()[2] = true; + return this; + } + + /** + * Checks whether the 'name' field has been set. + * @return True if the 'name' field has been set, false otherwise. + */ + public boolean hasName() { + return fieldSetFlags()[2]; + } + + + /** + * Clears the value of the 'name' field. + * @return This builder. + */ + public de.trion.microservices.avro.User.Builder clearName() { + name = null; + fieldSetFlags()[2] = false; + return this; + } + + @Override + @SuppressWarnings("unchecked") + public User build() { + try { + User record = new User(); + record.id = fieldSetFlags()[0] ? this.id : (java.lang.Long) defaultValue(fields()[0]); + record.level = fieldSetFlags()[1] ? this.level : (de.trion.microservices.avro.CustomerLevel) defaultValue(fields()[1]); + record.name = fieldSetFlags()[2] ? this.name : (java.lang.CharSequence) defaultValue(fields()[2]); + return record; + } catch (org.apache.avro.AvroMissingFieldException e) { + throw e; + } catch (java.lang.Exception e) { + throw new org.apache.avro.AvroRuntimeException(e); + } + } + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumWriter + WRITER$ = (org.apache.avro.io.DatumWriter)MODEL$.createDatumWriter(SCHEMA$); + + @Override public void writeExternal(java.io.ObjectOutput out) + throws java.io.IOException { + WRITER$.write(this, SpecificData.getEncoder(out)); + } + + @SuppressWarnings("unchecked") + private static final org.apache.avro.io.DatumReader + READER$ = (org.apache.avro.io.DatumReader)MODEL$.createDatumReader(SCHEMA$); + + @Override public void readExternal(java.io.ObjectInput in) + throws java.io.IOException { + READER$.read(this, SpecificData.getDecoder(in)); + } + + @Override protected boolean hasCustomCoders() { return true; } + + @Override public void customEncode(org.apache.avro.io.Encoder out) + throws java.io.IOException + { + out.writeLong(this.id); + + out.writeEnum(this.level.ordinal()); + + out.writeString(this.name); + + } + + @Override public void customDecode(org.apache.avro.io.ResolvingDecoder in) + throws java.io.IOException + { + org.apache.avro.Schema.Field[] fieldOrder = in.readFieldOrderIfDiff(); + if (fieldOrder == null) { + this.id = in.readLong(); + + this.level = de.trion.microservices.avro.CustomerLevel.values()[in.readEnum()]; + + this.name = in.readString(this.name instanceof Utf8 ? (Utf8)this.name : null); + + } else { + for (int i = 0; i < 3; i++) { + switch (fieldOrder[i].pos()) { + case 0: + this.id = in.readLong(); + break; + + case 1: + this.level = de.trion.microservices.avro.CustomerLevel.values()[in.readEnum()]; + break; + + case 2: + this.name = in.readString(this.name instanceof Utf8 ? (Utf8)this.name : null); + break; + + default: + throw new java.io.IOException("Corrupt ResolvingDecoder."); + } + } + } + } +} + + + + + + + + + + diff --git a/validate-user/src/main/java/de/trion/microservices/validateuser/Application.java b/validate-user/src/main/java/de/trion/microservices/validateuser/Application.java new file mode 100644 index 0000000..bfdde7a --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/validateuser/Application.java @@ -0,0 +1,22 @@ +package de.trion.microservices.validateorder; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; + + +@SpringBootApplication +@EnableConfigurationProperties(ApplicationProperties.class) +public class Application +{ + private final static Logger LOG = LoggerFactory.getLogger(Application.class); + + + public static void main(String[] args) + { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/validate-user/src/main/java/de/trion/microservices/validateuser/ApplicationProperties.java b/validate-user/src/main/java/de/trion/microservices/validateuser/ApplicationProperties.java new file mode 100644 index 0000000..c632eef --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/validateuser/ApplicationProperties.java @@ -0,0 +1,55 @@ +package de.trion.microservices.validateorder; + + +import org.springframework.boot.context.properties.ConfigurationProperties; + + +@ConfigurationProperties("take-order") +public class ApplicationProperties +{ + String bootstrapServers = "kafka:9092"; + String schemaRegistryUrl = "http://schema-registry:8081"; + String ordersTopic = "orders"; + String validationTopic = "validation"; + + + public String getBootstrapServers() + { + return bootstrapServers; + } + + public void setBootstrapServers(String bootstrapServers) + { + this.bootstrapServers = bootstrapServers; + } + + public String getSchemaRegistryUrl() + { + return schemaRegistryUrl; + } + + public void setSchemaRegistryUrl(String schemaRegistryUrl) + { + this.schemaRegistryUrl = schemaRegistryUrl; + } + + public String getOrdersTopic() + { + return ordersTopic; + } + + public void setOrdersTopic(String topic) + { + this.ordersTopic = topic; + } + + public String getValidationTopic() + { + return validationTopic; + } + + public void setValidationTopic(String topic) + { + this.validationTopic = topic; + } +} diff --git a/validate-user/src/main/java/de/trion/microservices/validateuser/ValidateUserService.java b/validate-user/src/main/java/de/trion/microservices/validateuser/ValidateUserService.java new file mode 100644 index 0000000..479cf7e --- /dev/null +++ b/validate-user/src/main/java/de/trion/microservices/validateuser/ValidateUserService.java @@ -0,0 +1,77 @@ +package de.trion.microservices.validateorder; + + +import de.trion.microservices.avro.Order; +import de.trion.microservices.avro.OrderState; +import de.trion.microservices.avro.OrderValidation; +import static de.trion.microservices.avro.OrderValidationResult.FAIL; +import static de.trion.microservices.avro.OrderValidationResult.PASS; +import static de.trion.microservices.avro.OrderValidationType.ORDER_DETAILS_CHECK; +import io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import org.apache.kafka.common.serialization.Serdes; +import org.apache.kafka.streams.KafkaStreams; +import org.apache.kafka.streams.StreamsBuilder; +import org.apache.kafka.streams.Topology; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + + +@Component +public class ValidateUserService +{ + final static Logger LOG = LoggerFactory.getLogger(ValidateUserService.class); + + private final String orders; + private final String validation; + private final KafkaStreams streams; + + + public ValidateUserService(ApplicationProperties config) + { + orders = config.ordersTopic; + validation = config.validationTopic; + + Properties properties = new Properties(); + properties.put("bootstrap.servers", config.bootstrapServers); + properties.put("application.id", "validate-user"); + properties.put("schema.registry.url", config.schemaRegistryUrl); + properties.put("default.key.serde", Serdes.String().getClass()); + properties.put("default.value.serde", SpecificAvroSerde.class); + + StreamsBuilder builder = new StreamsBuilder(); + + Topology topology = builder.build(); + streams = new KafkaStreams(topology, properties); + streams.setUncaughtExceptionHandler((Thread t, Throwable e) -> + { + LOG.error("Unexpected error in thread {}: {}", t, e.toString()); + try + { + streams.close(); + } + catch (Exception ex) + { + LOG.error("Could not close KafkaStreams!", ex); + } + }); + } + + + @PostConstruct + public void start() + { + streams.start(); + } + + @PreDestroy + public void stop() + { + streams.close(); + } +} diff --git a/validate-user/src/main/resources/application.properties b/validate-user/src/main/resources/application.properties new file mode 100644 index 0000000..ce81378 --- /dev/null +++ b/validate-user/src/main/resources/application.properties @@ -0,0 +1 @@ +logging.level.de.trion=debug diff --git a/validate-user/target/BUILD b/validate-user/target/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/validate-user/target/classes/application.properties b/validate-user/target/classes/application.properties new file mode 100644 index 0000000..ce81378 --- /dev/null +++ b/validate-user/target/classes/application.properties @@ -0,0 +1 @@ +logging.level.de.trion=debug diff --git a/validate-user/target/classes/de/trion/microservices/avro/CustomerLevel.class b/validate-user/target/classes/de/trion/microservices/avro/CustomerLevel.class new file mode 100644 index 0000000..e654c3d Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/CustomerLevel.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/Order$1.class b/validate-user/target/classes/de/trion/microservices/avro/Order$1.class new file mode 100644 index 0000000..075025d Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/Order$1.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/Order$Builder.class b/validate-user/target/classes/de/trion/microservices/avro/Order$Builder.class new file mode 100644 index 0000000..976ff64 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/Order$Builder.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/Order.class b/validate-user/target/classes/de/trion/microservices/avro/Order.class new file mode 100644 index 0000000..f81490d Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/Order.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/OrderAndUser$1.class b/validate-user/target/classes/de/trion/microservices/avro/OrderAndUser$1.class new file mode 100644 index 0000000..2612024 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/OrderAndUser$1.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/OrderAndUser$Builder.class b/validate-user/target/classes/de/trion/microservices/avro/OrderAndUser$Builder.class new file mode 100644 index 0000000..5642bd4 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/OrderAndUser$Builder.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/OrderAndUser.class b/validate-user/target/classes/de/trion/microservices/avro/OrderAndUser.class new file mode 100644 index 0000000..75ede8b Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/OrderAndUser.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/OrderState.class b/validate-user/target/classes/de/trion/microservices/avro/OrderState.class new file mode 100644 index 0000000..257cbdf Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/OrderState.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/OrderValidation$1.class b/validate-user/target/classes/de/trion/microservices/avro/OrderValidation$1.class new file mode 100644 index 0000000..d38aead Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/OrderValidation$1.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/OrderValidation$Builder.class b/validate-user/target/classes/de/trion/microservices/avro/OrderValidation$Builder.class new file mode 100644 index 0000000..d7ac546 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/OrderValidation$Builder.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/OrderValidation.class b/validate-user/target/classes/de/trion/microservices/avro/OrderValidation.class new file mode 100644 index 0000000..2660f76 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/OrderValidation.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/OrderValidationResult.class b/validate-user/target/classes/de/trion/microservices/avro/OrderValidationResult.class new file mode 100644 index 0000000..2ef8b00 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/OrderValidationResult.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/OrderValidationType.class b/validate-user/target/classes/de/trion/microservices/avro/OrderValidationType.class new file mode 100644 index 0000000..3b0a9c0 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/OrderValidationType.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/User$1.class b/validate-user/target/classes/de/trion/microservices/avro/User$1.class new file mode 100644 index 0000000..a6d2bb7 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/User$1.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/User$Builder.class b/validate-user/target/classes/de/trion/microservices/avro/User$Builder.class new file mode 100644 index 0000000..dac5e71 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/User$Builder.class differ diff --git a/validate-user/target/classes/de/trion/microservices/avro/User.class b/validate-user/target/classes/de/trion/microservices/avro/User.class new file mode 100644 index 0000000..1810ed6 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/avro/User.class differ diff --git a/validate-user/target/classes/de/trion/microservices/validateuser/Application.class b/validate-user/target/classes/de/trion/microservices/validateuser/Application.class new file mode 100644 index 0000000..462040e Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/validateuser/Application.class differ diff --git a/validate-user/target/classes/de/trion/microservices/validateuser/ApplicationProperties.class b/validate-user/target/classes/de/trion/microservices/validateuser/ApplicationProperties.class new file mode 100644 index 0000000..6a08621 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/validateuser/ApplicationProperties.class differ diff --git a/validate-user/target/classes/de/trion/microservices/validateuser/ValidateUserService.class b/validate-user/target/classes/de/trion/microservices/validateuser/ValidateUserService.class new file mode 100644 index 0000000..75688d3 Binary files /dev/null and b/validate-user/target/classes/de/trion/microservices/validateuser/ValidateUserService.class differ diff --git a/validate-user/target/maven-archiver/pom.properties b/validate-user/target/maven-archiver/pom.properties new file mode 100644 index 0000000..91a14e0 --- /dev/null +++ b/validate-user/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +version=0-SNAPSHOT +groupId=de.trion.kafka.microservices +artifactId=validate-user-04 diff --git a/validate-user/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/validate-user/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..4697b16 --- /dev/null +++ b/validate-user/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,19 @@ +de/trion/microservices/avro/OrderValidation$Builder.class +de/trion/microservices/avro/Order$Builder.class +de/trion/microservices/avro/OrderValidationType.class +de/trion/microservices/validateuser/ApplicationProperties.class +de/trion/microservices/avro/User$1.class +de/trion/microservices/validateuser/ValidateUserService.class +de/trion/microservices/avro/Order.class +de/trion/microservices/avro/OrderAndUser.class +de/trion/microservices/avro/User$Builder.class +de/trion/microservices/avro/Order$1.class +de/trion/microservices/avro/OrderAndUser$1.class +de/trion/microservices/avro/OrderValidation$1.class +de/trion/microservices/avro/User.class +de/trion/microservices/validateuser/Application.class +de/trion/microservices/avro/OrderValidation.class +de/trion/microservices/avro/OrderState.class +de/trion/microservices/avro/CustomerLevel.class +de/trion/microservices/avro/OrderValidationResult.class +de/trion/microservices/avro/OrderAndUser$Builder.class diff --git a/validate-user/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/validate-user/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..65fe1d5 --- /dev/null +++ b/validate-user/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,11 @@ +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/validateuser/ValidateUserService.java +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/avro/OrderValidation.java +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/avro/OrderValidationType.java +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/avro/OrderState.java +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/validateuser/Application.java +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/avro/OrderValidationResult.java +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/avro/User.java +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/avro/CustomerLevel.java +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/avro/Order.java +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/validateuser/ApplicationProperties.java +/home/kai/trion/kafka/exercises/08-streams/microservices-04/validate-user/src/main/java/de/trion/microservices/avro/OrderAndUser.java diff --git a/validate-user/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/validate-user/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/validate-user/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/validate-user/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/validate-user/target/validate-user-04-0-SNAPSHOT.jar b/validate-user/target/validate-user-04-0-SNAPSHOT.jar new file mode 100644 index 0000000..21eb3b6 Binary files /dev/null and b/validate-user/target/validate-user-04-0-SNAPSHOT.jar differ diff --git a/validate-user/target/validate-user-04-0-SNAPSHOT.jar.original b/validate-user/target/validate-user-04-0-SNAPSHOT.jar.original new file mode 100644 index 0000000..da5dd29 Binary files /dev/null and b/validate-user/target/validate-user-04-0-SNAPSHOT.jar.original differ