changes
This commit is contained in:
		| @@ -18,16 +18,8 @@ import java.util.*; | ||||
|  | ||||
| public class DAO { | ||||
|  | ||||
|     static List<Material> materials = new ArrayList<>(); | ||||
|     static List<Package> packages = new ArrayList<>(); | ||||
|  | ||||
|     public String test(LinkedHashMap materialMap) throws Exception { | ||||
|         Material material = mapToMaterial(materialMap); | ||||
|         String xml = singleXML(material); | ||||
|         return xml; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public void getId(Exchange exchange) throws InterruptedException { | ||||
|  | ||||
|         MaterialType tmp = (MaterialType) exchange.getIn().getBody(); | ||||
| @@ -42,7 +34,7 @@ public class DAO { | ||||
|         MaterialType materialType = new MaterialType(); | ||||
|         materialType.setId((Integer) map.get("id")); | ||||
|         materialType.setMaterialNumber((String) map.get("number")); | ||||
|         materialType.getMaterialType(map.get("type")); | ||||
|        // materialType.getMaterialType(map.get("type")); | ||||
|         materialType.setMaterialName((String) map.get("name")); | ||||
|         materialType.setDescription((String) map.get("description")); | ||||
|         materialType.setIsDeleted((Boolean) map.get("is_deleted")); | ||||
| @@ -53,7 +45,7 @@ public class DAO { | ||||
|         exchange.getIn().setBody(materialType); | ||||
|     } | ||||
|  | ||||
|  | ||||
| /* | ||||
|     public void splitPackage(LinkedHashMap packageMap) { | ||||
|         Package pack = new Package(); | ||||
|         pack.setId((Integer) packageMap.get("id")); | ||||
| @@ -158,4 +150,6 @@ public class DAO { | ||||
|         } | ||||
|         return material; | ||||
|     } | ||||
|  | ||||
|  */ | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,8 @@ | ||||
| package com.release11; | ||||
|  | ||||
| import com.mysql.cj.jdbc.MysqlDataSource; | ||||
| import generated.MaterialType; | ||||
| import generated.MaterialTypeType; | ||||
| import org.apache.activemq.ActiveMQConnectionFactory; | ||||
| import org.apache.camel.*; | ||||
| import org.apache.camel.builder.RouteBuilder; | ||||
| @@ -11,16 +13,13 @@ import org.apache.log4j.BasicConfigurator; | ||||
| import org.apache.camel.converter.jaxb.JaxbDataFormat; | ||||
|  | ||||
| import javax.xml.bind.*; | ||||
| import java.util.HashMap; | ||||
|  | ||||
|  | ||||
| public class Main { | ||||
|  | ||||
|     public static void main(String[] args) throws Exception { | ||||
|  | ||||
|         //MyBuilder myBuilder = new MyBuilder(); | ||||
|         //myBuilder.doRandomMaterials(); | ||||
|         //myBuilder.doRandomPackage(); | ||||
|  | ||||
|         //to("log:?level=INFO&showHeaders=true&showBody=true") | ||||
|  | ||||
|         MysqlDataSource source = new MysqlDataSource(); | ||||
| @@ -31,23 +30,6 @@ public class Main { | ||||
|         SimpleRegistry registry = new SimpleRegistry(); | ||||
|         registry.bind("source", MysqlDataSource.class, source); | ||||
|  | ||||
|  | ||||
|         //jax.marshal(Exchange ,jax,); | ||||
|         //registry.bind("jax", JaxbDataFormat.class, XMLDataFormat); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|         CamelContext context = new DefaultCamelContext(registry); | ||||
|         BasicConfigurator.configure(); | ||||
|         ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://10.101.111.19:8088"); | ||||
| @@ -59,11 +41,10 @@ public class Main { | ||||
|             @Override | ||||
|             public void configure() throws Exception { | ||||
|  | ||||
|                 JaxbDataFormat XMLDataFormat = new JaxbDataFormat(); | ||||
|                 //XMLDataFormat.setSchemaLocation("/home/igor/Documents/Jacek/jacek-and-igor/src/main/resources/material.xsd"); | ||||
|                 XMLDataFormat.setContextPath("generated"); | ||||
|                 JaxbDataFormat xmlDataFormat = new JaxbDataFormat(); | ||||
|                 xmlDataFormat.setContextPath("generated"); | ||||
|                 JAXBContext jaxbContext = JAXBContext.newInstance(generated.MaterialType.class); | ||||
|                 XMLDataFormat.setContext(jaxbContext); | ||||
|                 xmlDataFormat.setContext(jaxbContext); | ||||
|  | ||||
|                 from("direct:start") | ||||
|                         .setBody(constant("SELECT * FROM material")) | ||||
| @@ -78,69 +59,17 @@ public class Main { | ||||
|  | ||||
|                 from("activemq:queue:material") | ||||
|                         .enrich("direct:getPackages", new MyAggregator()) | ||||
|                         .marshal(xmlDataFormat) | ||||
|                         .to("activemq:queue:materialPackage") | ||||
|                         .to("log:?level=INFO&showBody=true"); | ||||
|  | ||||
|                 from("direct:test") | ||||
|                         .setBody(constant("SELECT * FROM material LIMIT 1")) | ||||
|                         .to("jdbc:source") | ||||
|                         .split(body()) | ||||
|                         .to("activemq:queue:materialTest"); | ||||
|  | ||||
|                 from("activemq:queue:materialTest") | ||||
|                         .bean(new DAO(), "test") | ||||
|                         .marshal(XMLDataFormat) | ||||
|                         .to("activemq:queue:test"); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|                 from("direct:pretty") | ||||
|                         .setBody(constant("<?xml version='1.0'?>" + | ||||
|                                 "<material>\n" + | ||||
|                                 "    <material_number>7</material_number>\n" + | ||||
|                                 "    <material_type>A1</material_type>\n" + | ||||
|                                 "    <material_name>LEGO 17272</material_name>\n" + | ||||
|                                 "    <description>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</description>\n" + | ||||
|                                 "    <is_deleted>false</is_deleted>\n" + | ||||
|                                 "    <packages>\n" + | ||||
|                                 "        <package_number>11988</package_number>\n" + | ||||
|                                 "        <ean>80975098498590834</ean>\n" + | ||||
|                                 "        <unit_of_measure>pcs</unit_of_measure>\n" + | ||||
|                                 "        <dimension>17x17x17</dimension>\n" + | ||||
|                                 "        <description>Lorem ipsum dolor sit amet, consectetur adipiscing elit</description>\n" + | ||||
|                                 "    </packages>\n" + | ||||
|                                 "    <packages>\n" + | ||||
|                                 "        <package_number>118</package_number>\n" + | ||||
|                                 "        <ean>877854875843774</ean>\n" + | ||||
|                                 "        <unit_of_measure>pcs</unit_of_measure>\n" + | ||||
|                                 "        <dimension>20x20x20</dimension>\n" + | ||||
|                                 "    </packages>\n" + | ||||
|                                 "</material>\n")) | ||||
|                         .unmarshal() | ||||
|                         .jaxb("generated") | ||||
|                         .bean(new DAO(), "getId") | ||||
|                         .to("activemq:queue:test") | ||||
|                         .to("log:?level=INFO&showBody=true"); | ||||
|  | ||||
|  | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         context.start(); | ||||
|         ProducerTemplate template = context.createProducerTemplate(); | ||||
|         template.sendBody("direct:test", null); | ||||
|         template.sendBody("direct:start", null); | ||||
|         Thread.sleep(1000); | ||||
|         //template.setDefaultEndpointUri("activemq:queue:material"); | ||||
|  | ||||
|         context.stop(); | ||||
|     } | ||||
|   | ||||
| @@ -1,77 +0,0 @@ | ||||
| package com.release11; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| public class Material { | ||||
|  | ||||
|     public int getId() { | ||||
|         return id; | ||||
|     } | ||||
|  | ||||
|     public void setId(int id) { | ||||
|         this.id = id; | ||||
|     } | ||||
|  | ||||
|     public String getNumber() { | ||||
|         return number; | ||||
|     } | ||||
|  | ||||
|     public void setNumber(String number) { | ||||
|         this.number = number; | ||||
|     } | ||||
|  | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
|     public String getDescription() { | ||||
|         return description; | ||||
|     } | ||||
|  | ||||
|     public void setDescription(String description) { | ||||
|         this.description = description; | ||||
|     } | ||||
|  | ||||
|     public Boolean getIs_deleted() { | ||||
|         return is_deleted; | ||||
|     } | ||||
|  | ||||
|     public void setIs_deleted(Boolean is_deleted) { | ||||
|         this.is_deleted = is_deleted; | ||||
|     } | ||||
|  | ||||
|     public enumType getType() { | ||||
|         return type; | ||||
|     } | ||||
|  | ||||
|     public void setType(enumType type) { | ||||
|         this.type = type; | ||||
|     } | ||||
|  | ||||
|     public List<Package> getPackageList() { | ||||
|         return packageList; | ||||
|     } | ||||
|  | ||||
|     public void setPackageList(List<Package> packageList) { | ||||
|         this.packageList = packageList; | ||||
|     } | ||||
|  | ||||
|     public enum enumType { | ||||
|         A1, A2, A3, B1, B2, B3, Z1, Z2, Z3; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     private int id; | ||||
|     private String number; | ||||
|     private enumType type; | ||||
|     private String name; | ||||
|     private String description; | ||||
|     private Boolean is_deleted; | ||||
|     private List<Package> packageList = new ArrayList<>(); | ||||
|  | ||||
| } | ||||
| @@ -1,11 +1,13 @@ | ||||
| package com.release11; | ||||
|  | ||||
| import generated.MaterialType; | ||||
| import generated.MaterialTypeType; | ||||
| import generated.Package; | ||||
| import org.apache.camel.AggregationStrategy; | ||||
| import org.apache.camel.Exchange; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
|  | ||||
| public class MyAggregator implements AggregationStrategy { | ||||
|     @Override | ||||
| @@ -15,12 +17,30 @@ public class MyAggregator implements AggregationStrategy { | ||||
|         System.out.println(oldEx); | ||||
|         ArrayList<HashMap> newEx = (ArrayList) newExchange.getIn().getBody(); | ||||
|         System.out.println(newEx); | ||||
|  | ||||
|  | ||||
|         oldEx.put("packages", newEx); | ||||
|  | ||||
|         MaterialType material = new MaterialType(); | ||||
|         material.setId((Integer) oldEx.get("id")); | ||||
|         material.setMaterialNumber((String) oldEx.get("number")); | ||||
|         material.setMaterialType(MaterialTypeType.fromValue((String) oldEx.get("type"))); | ||||
|         material.setMaterialName((String) oldEx.get("name")); | ||||
|         material.setDescription((String) oldEx.get("description")); | ||||
|         material.setIsDeleted((Boolean) oldEx.get("is_deleted")); | ||||
|  | ||||
|         for (int i = 0; i < newEx.size(); i++) { | ||||
|             Package p = new Package(); | ||||
|             p.setId((Integer) newEx.get(i).get("id")); | ||||
|             p.setPackageNumber((String) newEx.get(i).get("number")); | ||||
|             p.setMaterialId((Integer) newEx.get(i).get("material_id")); | ||||
|             p.setEan((String.valueOf(newEx.get(i).get("ean")))); | ||||
|             p.setUnitOfMeasure((String) newEx.get(i).get("unit_of_measure")); | ||||
|             p.setDimension((String) newEx.get(i).get("dimension")); | ||||
|             p.setDescription((String) newEx.get(i).get("description")); | ||||
|             material.getPackages().add(p); | ||||
|         } | ||||
|  | ||||
|         Exchange result = oldExchange; | ||||
|         result.getIn().setBody(oldEx); | ||||
|         //result.getIn().setBody(body); | ||||
|         result.getIn().setBody(material); | ||||
|         System.out.println(result.getIn().getBody()); | ||||
|  | ||||
|         return result; | ||||
|   | ||||
| @@ -1,69 +0,0 @@ | ||||
| package com.release11; | ||||
|  | ||||
| public class Package { | ||||
|  | ||||
|     public int getId() { | ||||
|         return id; | ||||
|     } | ||||
|  | ||||
|     public void setId(int id) { | ||||
|         this.id = id; | ||||
|     } | ||||
|  | ||||
|     public String getNumber() { | ||||
|         return number; | ||||
|     } | ||||
|  | ||||
|     public void setNumber(String number) { | ||||
|         this.number = number; | ||||
|     } | ||||
|  | ||||
|     public int getMaterial_id() { | ||||
|         return material_id; | ||||
|     } | ||||
|  | ||||
|     public void setMaterial_id(int material_id) { | ||||
|         this.material_id = material_id; | ||||
|     } | ||||
|  | ||||
|     public String getEan() { | ||||
|         return ean; | ||||
|     } | ||||
|  | ||||
|     public void setEan(String ean) { | ||||
|         this.ean = ean; | ||||
|     } | ||||
|  | ||||
|     public String getUnit_of_measure() { | ||||
|         return unit_of_measure; | ||||
|     } | ||||
|  | ||||
|     public void setUnit_of_measure(String unit_of_measure) { | ||||
|         this.unit_of_measure = unit_of_measure; | ||||
|     } | ||||
|  | ||||
|     public String getDimension() { | ||||
|         return dimension; | ||||
|     } | ||||
|  | ||||
|     public void setDimension(String dimension) { | ||||
|         this.dimension = dimension; | ||||
|     } | ||||
|  | ||||
|     public String getDescription() { | ||||
|         return description; | ||||
|     } | ||||
|  | ||||
|     public void setDescription(String description) { | ||||
|         this.description = description; | ||||
|     } | ||||
|  | ||||
|     int id; | ||||
|     String number; | ||||
|     int material_id; | ||||
|     String ean; | ||||
|     String unit_of_measure; | ||||
|     String dimension; | ||||
|     String description; | ||||
|  | ||||
| } | ||||
| @@ -5,7 +5,7 @@ | ||||
|         <xs:sequence> | ||||
|             <xs:element name="id" type="xs:int"/> | ||||
|             <xs:element name="material_id" type="xs:int"/> | ||||
|             <xs:element name="package_number" type="xs:int"/> | ||||
|             <xs:element name="package_number" type="xs:string"/> | ||||
|             <xs:element name="ean" type="xs:string"/> | ||||
|             <xs:element name="unit_of_measure" type="xs:string"/> | ||||
|             <xs:element name="dimension" type="xs:string"/> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user