Skip to content

Commit

Permalink
#332 Add Files Modified To Solve Exception
Browse files Browse the repository at this point in the history
Added a trim statement to avoid problem when cast the schemas from classpath
  • Loading branch information
AdrianLagartera committed Feb 22, 2023
1 parent 86bd05e commit b21e311
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static Descriptors.Descriptor buildProtoDescriptor(final ProtoFileElement

final DynamicSchema.Builder schemaBuilder = DynamicSchema.newBuilder();
final List<String> imports = schema.getImports();
for (String importedClass : imports) {
for (final String importedClass : imports) {
try (final InputStream resourceStream = SchemaProcessorUtils.class.getClassLoader().getResourceAsStream(importedClass)) {
if (null != resourceStream) {
final String schemaToString = new String(resourceStream.readAllBytes());
Expand Down Expand Up @@ -181,7 +181,7 @@ private static DynamicSchema processImported(final List<String> importedLines) t
String packageName = "";
final var linesIterator = importedLines.listIterator();
while (linesIterator.hasNext()) {
final var fileLine = linesIterator.next();
final var fileLine = linesIterator.next().trim();

if (fileLine.startsWith("package")) {
packageName = StringUtils.chop(fileLine.substring(7).trim());
Expand Down Expand Up @@ -238,7 +238,7 @@ private static MessageDefinition buildProtoMessageDefinition(
final MessageDefinition.Builder msgDef = MessageDefinition.newBuilder(fieldName);
final var element = (MessageElement) messageElement;
extracted(globalNestedTypesByLevelAndMessage, msgDef, element.getFields(), nextDeepLevel, fieldName);
for (var optionalField : element.getOneOfs()) {
for (final var optionalField : element.getOneOfs()) {
extracted(globalNestedTypesByLevelAndMessage, msgDef, optionalField.getFields(), nextDeepLevel, fieldName);
}
return msgDef.build();
Expand All @@ -251,7 +251,7 @@ private static void extracted(
final HashMap<String, TypeElement> nestedTypes = processLevelTypes(globalNestedTypesByLevelAndMessage, msgDef, fieldElementList, deepLevel,
messageName);

for (var elementField : fieldElementList) {
for (final var elementField : fieldElementList) {
final var elementFieldType = elementField.getType();
final var dotType = checkDotType(elementFieldType);
if (nestedTypes.containsKey(elementFieldType)) {
Expand Down Expand Up @@ -343,7 +343,7 @@ private static void addDefinition(
if (typeElement instanceof EnumElement) {
final var enumElement = (EnumElement) typeElement;
final EnumDefinition.Builder builder = EnumDefinition.newBuilder(enumElement.getName());
for (var constant : enumElement.getConstants()) {
for (final var constant : enumElement.getConstants()) {
builder.addValue(constant.getName(), constant.getTag());
}
msgDef.addEnumDefinition(builder.build());
Expand Down
218 changes: 218 additions & 0 deletions src/test/resources/proto-files/messaging_intra_order.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
syntax = "proto3";

package demo;

option java_package = "com.demo.unmanaged.order.proto";
option java_outer_classname = "IntraOrder";
option java_multiple_files = true;

message Order {

message Address {
int32 address_id = 1;
string address_line_one = 2;
}

message Contact {
int32 contact_id = 1;
string first_name = 2;
string last_name = 3;
}

message Dimension {
string unit_of_measure = 1;
int32 value = 2;
}

message CustomerAccount {
demo.Order.CustomerAccount.BillingParty billing_party = 1;
string name = 2;

message BillingParty {
string p_name = 1;
repeated demo.Order.Contact p_contact = 2;
}
}

message LogisticsProviderDetails {
demo.Order.LogisticsProviderDetails.ManagedBy managed_by = 1;

message ManagedBy {
string organization_name = 1;
string organization_id = 2;
}
}

message MarketingAreaDetails {
string origin_marketing_area = 1;
string origin_area_name = 2;
}

message ServiceOfferingDetails {
string business_unit_code = 1;
string service_offering = 2;
}

message Currency {
string currency_code = 1;
double value = 2;
}

message OperationalRequirements {
string code = 1;
string type = 2;
demo.Order.OperationalRequirements.IntendedCarrier carrier = 3;

message IntendedCarrier {
string id = 4;
}
}

message RatingDetails {
string terms = 1;
string status = 2;
demo.Order.RatingDetails.RateSheets sheets = 3;

message RateSheets {
repeated demo.Order.RatingDetails.RateSheets.RateSheet in_sheet = 1;
repeated demo.Order.RatingDetails.RateSheets.RateSheet es_sheet = 2;

message RateSheet {
int32 id = 4;
}
}
}

message OrderDetails {
repeated demo.Order.OrderDetails.OrderRequirements order_requirements = 1;
demo.Order.OrderDetails.InternationalDetails international_details = 2;

message OrderRequirements {
string requirement = 1;
}
message InternationalDetails {
demo.Order.OrderDetails.InternationalDetails.CustomsDetails customs_details = 1;
repeated demo.Order.OrderDetails.InternationalDetails.InternationalServices international_services = 2;
demo.Order.OrderDetails.InternationalDetails.InbondDetails inbond_details = 3;
demo.Order.OrderDetails.InternationalDetails.PortDetails port_of_exit_location = 4;
demo.Order.OrderDetails.InternationalDetails.PortDetails port_of_entry_location = 5;

message InternationalServices {
string service = 1;
}

message PortDetails {
string location_id = 1;
string location_name = 2;
demo.Order.Address location_address = 3;
}

message CustomsDetails {
demo.Order.OrderDetails.InternationalDetails.CustomsDetails.CustomsBroker customs_broker = 1;
string clearing_customs_country = 2;

message CustomsBroker {
string party_name = 1;
demo.Order.Address party_address = 2;
repeated demo.Order.Contact party_contact = 3;
}
}

message InbondDetails {
string bond_holder_role = 1;
demo.Order.OrderDetails.InternationalDetails.InbondDetails.BondHolderParty bond_holder_party = 2;

message BondHolderParty {
string party_name = 3;
demo.Order.Address party_address = 4;
repeated demo.Order.Contact party_contact = 5;
}
}
}
}

message RequestedOperationalServices {
string service_type = 1;
}

message ReferenceNumbers {
int32 reference_number_id = 1;
string reference_number = 2;
}

message Appointments {
int32 appointment_id = 1;
string appointment_type_code = 2;
repeated demo.Order.Appointments.AppointmentRequirements appointment_requirements = 3;
repeated demo.Order.Appointments.AppointmentNumbers appointment_numbers = 4;

message AppointmentRequirements {
string requirement = 5;
}

message AppointmentNumbers {
string appointment_number = 6;
}
}

message AdditionalInstructions {
string instruction_type = 1;
string instruction_text = 2;
}

message Comments {
string comment_type = 1;
string comment = 2;
}

message Stops {
demo.Order.Stops.StopLocation stop_location = 1;
repeated demo.Order.Stops.ItemHandlingDetails item_handling_details = 2;

message StopLocation {
string location_id = 1;
demo.Order.Address address = 2;
}
message ItemHandlingDetails {
int32 item_handling_detail_id = 3;
demo.Order.ItemUnit item_handling_unit = 4;
demo.Order.Dimension item_handling_unit_height = 5;
repeated demo.Order.Stops.ItemHandlingDetails.ItemDetails item_details = 6;

message ItemDetails {
int32 stop_item_id = 7;
demo.Order.ItemUnit packaging_unit = 8;
demo.Order.Dimension item_density = 9;
demo.Order.Dimension item_height = 10;
repeated demo.Order.ReferenceNumbers reference_numbers = 11;
}
}
}

message EquipmentRequirements {
demo.Order.EquipmentRequirements.EquipmentCharacteristics characteristics = 1;

message EquipmentCharacteristics {
repeated demo.Order.EquipmentRequirements.EquipmentCharacteristics.EquipmentOptions e_options = 2;

message EquipmentOptions {
string option = 3;
}
}
}

message ItemUnit {
int32 quantity = 1;
string type = 2;
}

message UserDetails {
string person_id = 1;
string first_name = 2;
}

message SystemDetails {
string order_system = 1;
demo.Order.UserDetails created_by = 2;
}
}
66 changes: 66 additions & 0 deletions src/test/resources/proto-files/messaging_unified_order.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
syntax = "proto3";
package demo;

import "messaging_intra_order.proto";

option java_package = "com.demo.unified.aggregator.proto";
option java_outer_classname = "UnifiedAggregator";
option java_multiple_files = true;

message UnifiedOrder {
int32 order_id = 1;
string order_number = 2;
Order.CustomerAccount customer_account = 3;
Order.RatingDetails rating_details = 4;
Order.LogisticsProviderDetails logistics_provider_details = 5;
Order.MarketingAreaDetails marketing_area_details = 6;
Order.ServiceOfferingDetails service_offering_details = 7;
string order_type = 8;
string order_status = 9;
demo.UnifiedOrder.OrderDetails order_details = 10;
Order.OperationalRequirements operational_requirements = 11;
Order.EquipmentRequirements equipment_requirements = 12;
repeated demo.UnifiedOrder.Stops stops = 13;
repeated Order.ReferenceNumbers reference_numbers = 14;
Order.Contact solicitor_contact = 15;
Order.SystemDetails system_details = 16;
repeated Order.AdditionalInstructions additional_instructions = 17;
repeated Order.Comments comments = 18;

message OrderDetails {
Order.Dimension total_weight = 1;
Order.Currency order_value = 2;
Order.Dimension estimated_distance = 3;
string shipping_option_date = 4;
bool comingle_flag = 5;
bool consolidated_flag = 6;
repeated Order.OrderDetails.OrderRequirements order_requirements = 7;
Order.Currency customer_tendered_rate = 8;
Order.OrderDetails.InternationalDetails international_details = 9;
Order.UserDetails order_owner = 10;
string shipment_identification_number = 11;
string order_tracking_number = 12;
string order_tracking_status = 13;
}
message Stops {
string stop_id = 1;
string stop_reason_code = 2;
string stop_type = 3;
string stop_status = 4;
string customer_provided_date_time = 5;
Order.Stops.StopLocation stop_location = 6;
Order.Contact stop_contact = 7;
repeated Order.Stops.ItemHandlingDetails item_handling_details = 8;
repeated Order.ReferenceNumbers reference_numbers = 9;
repeated Order.Appointments appointments = 10;
Order.Dimension stop_weight = 11;
int32 stop_quantity = 12;
int32 route_stop_id = 13;
Order.Dimension distance_to_next_stop = 14;
string rail_service_level = 15;
string rail_transit_mode = 16;
repeated Order.RequestedOperationalServices requested_operational_services = 17;
repeated Order.AdditionalInstructions additional_instructions = 18;
repeated Order.Comments comments = 19;
}
}

0 comments on commit b21e311

Please sign in to comment.