working project
This commit is contained in:
		
							
								
								
									
										2
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							| @@ -8,5 +8,5 @@ | ||||
|       </list> | ||||
|     </option> | ||||
|   </component> | ||||
|   <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="openjdk-17" project-jdk-type="JavaSDK" /> | ||||
|   <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="corretto-11" project-jdk-type="JavaSDK" /> | ||||
| </project> | ||||
							
								
								
									
										8
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -9,8 +9,8 @@ | ||||
|     <version>1.0-SNAPSHOT</version> | ||||
|  | ||||
|     <properties> | ||||
|         <maven.compiler.source>17</maven.compiler.source> | ||||
|         <maven.compiler.target>17</maven.compiler.target> | ||||
|         <maven.compiler.source>11</maven.compiler.source> | ||||
|         <maven.compiler.target>11</maven.compiler.target> | ||||
|     </properties> | ||||
|  | ||||
|     <dependencies> | ||||
| @@ -109,8 +109,8 @@ | ||||
|                 <groupId>org.apache.maven.plugins</groupId> | ||||
|                 <artifactId>maven-compiler-plugin</artifactId> | ||||
|                 <configuration> | ||||
|                     <source>17</source> | ||||
|                     <target>17</target> | ||||
|                     <source>11</source> | ||||
|                     <target>11</target> | ||||
|                 </configuration> | ||||
|             </plugin> | ||||
|         </plugins> | ||||
|   | ||||
| @@ -59,11 +59,26 @@ public class Main { | ||||
|  | ||||
|                 from("activemq:queue:RawMaterial") | ||||
|                         .enrich("direct:getPackages", new MyAggregator()) | ||||
|                         .process(new Processor(){ | ||||
|  | ||||
|                             @Override | ||||
|                             public void process(Exchange exchange) throws Exception { | ||||
|                                 MaterialType material = (MaterialType) exchange.getIn().getBody(); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|                             } | ||||
|                         }) | ||||
|  | ||||
|  | ||||
|                         .choice() | ||||
|                             .when(simple("${header.ean} == 'false'")) | ||||
|                         .when(simple("${header.ean} == false")) | ||||
|                         .marshal(xmlDataFormat) | ||||
|                         .to("activemq:queue:BadEan") | ||||
|                             .when(simple("${header.dimension} == 'false'")) | ||||
|                         .when(simple("${header.dimension} == false")) | ||||
|                         .marshal(xmlDataFormat) | ||||
|                         .to("activemq:queue:BadDimension") | ||||
|                         .otherwise() | ||||
| @@ -71,20 +86,21 @@ public class Main { | ||||
|                         .to("activemq:queue:ValidMaterial") | ||||
|                         .to("log:?level=INFO&showBody=true"); | ||||
|  | ||||
|                 /* | ||||
|                 from("activemq:queue:ValidMaterial") | ||||
|                         .process(new MyProcess()) | ||||
|                         .unmarshal(xmlDataFormat) | ||||
|                         .process(exchange -> { | ||||
|                             MaterialType material = (MaterialType) exchange.getIn().getBody(); | ||||
|                             //MaterialTypeType type = material.getMaterialType(); | ||||
|                             //exchange.getIn().setHeader("type", true); | ||||
|                             //if (!(type.equals("A1") || type.equals("A2") || type.equals("A3"))) | ||||
|                             //    exchange.getIn().setHeader("type", false); | ||||
|                             //if(exchange.getIn().getHeader("type").equals(true)) | ||||
|                             System.out.println(material.toString()); | ||||
|  | ||||
|                         }); | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| */ | ||||
|  | ||||
|             } | ||||
|         }); | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package com.release11; | ||||
|  | ||||
|  | ||||
| import generated.MaterialType; | ||||
| import generated.MaterialTypeType; | ||||
| import generated.Package; | ||||
| @@ -28,8 +29,8 @@ public class MyAggregator implements AggregationStrategy { | ||||
|         material.setIsDeleted((Boolean) oldEx.get("is_deleted")); | ||||
|  | ||||
|  | ||||
|         oldExchange.getIn().setHeader("dimension", "true"); | ||||
|         oldExchange.getIn().setHeader("ean", "true"); | ||||
|         oldExchange.getIn().setHeader("dimension", true); | ||||
|         oldExchange.getIn().setHeader("ean", true); | ||||
|  | ||||
|         for (int i = 0; i < newEx.size(); i++) { | ||||
|             Package p = new Package(); | ||||
| @@ -46,9 +47,9 @@ public class MyAggregator implements AggregationStrategy { | ||||
|             Pattern pattern = Pattern.compile("\\d\\dx\\d\\dx\\d\\d"); | ||||
|             Matcher matcher = pattern.matcher(p.getDimension()); | ||||
|             if (!matcher.matches()) | ||||
|                 oldExchange.getIn().setHeader("dimension", "false"); | ||||
|                 oldExchange.getIn().setHeader("dimension", false); | ||||
|             if(!isEanGood(p.getEan())) | ||||
|                 oldExchange.getIn().setHeader("ean", "false"); | ||||
|                 oldExchange.getIn().setHeader("ean", false); | ||||
|         } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -1,116 +0,0 @@ | ||||
| package com.release11; | ||||
|  | ||||
| import org.apache.camel.CamelContext; | ||||
| import org.apache.camel.ProducerTemplate; | ||||
| import org.apache.camel.builder.RouteBuilder; | ||||
| import org.apache.camel.impl.DefaultCamelContext; | ||||
| import org.apache.camel.support.SimpleRegistry; | ||||
|  | ||||
| import java.io.BufferedWriter; | ||||
| import java.io.File; | ||||
| import java.io.FileWriter; | ||||
| import java.io.IOException; | ||||
| import java.util.Random; | ||||
|  | ||||
| public class MyBuilder extends RouteBuilder { | ||||
|  | ||||
|     //MyBuilder myBuilder = new MyBuilder(); | ||||
|     //context.addRoutes(myBuilder); | ||||
|  | ||||
|     @Override | ||||
|     public void configure() throws Exception { | ||||
|         from("timer:foo?fixedRate=true&period=400") | ||||
|                 .log("Hello Camel"); | ||||
|     } | ||||
|  | ||||
|     public enum enumType { | ||||
|         A1, A2, A3, B1, B2, B3, Z1, Z2, Z3; | ||||
|     } | ||||
|  | ||||
|     public void doRandomMaterials() throws IOException { | ||||
|  | ||||
|         File fileName = new File("/home/igor/Documents/XML_Tasks/Camel/sql_script/sql.dml"); | ||||
|  | ||||
|         BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); | ||||
|         Random random = new Random(); | ||||
|         for (int i = 1; i <= 100; i++) { | ||||
|             String number = "number" + random.nextInt(1000, 10000); | ||||
|             String name = "name" + random.nextInt(1000, 10000); | ||||
|             String description = "description" + random.nextInt(1000, 10000); | ||||
|             String is_deleted = ""; | ||||
|             if (random.nextInt() % 2 == 0) | ||||
|                 is_deleted = "true"; | ||||
|             else | ||||
|                 is_deleted = "false"; | ||||
|  | ||||
|             enumType[] x = enumType.values(); | ||||
|             String type = x[random.nextInt(x.length)].toString(); | ||||
|             writer.write("INSERT INTO material VALUES(" + | ||||
|                     i + ", '" + number + "', '" + type + "', '" + name + "', '" + description + "', " + is_deleted + ");\n"); | ||||
|         } | ||||
|         writer.close(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public void doRandomPackage() throws IOException { | ||||
|  | ||||
|         File fileName = new File("/home/igor/Documents/XML_Tasks/Camel/sql_script/sql.dml"); | ||||
|  | ||||
|         BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true)); | ||||
|         Random random = new Random(); | ||||
|         for (int i = 1; i <= 100; i++) { | ||||
|             String number = "number" + random.nextInt(1000, 10000); | ||||
|             Integer material_id = i; | ||||
|             String ean = eanGenerator(); | ||||
|             String unit_of_measure = "unit" + random.nextInt(1000, 10000); | ||||
|             String dimension = random.nextInt(5, 35) + "x" + random.nextInt(5, 35) + "x" + random.nextInt(5, 35); | ||||
|             String description = "description" + random.nextInt(1000, 10000); | ||||
|  | ||||
|             writer.write("INSERT INTO package VALUES(" + | ||||
|                     i + ", '" + number + "', '" + material_id + "', '" + ean + "', '" | ||||
|                     + unit_of_measure + "', '" + dimension + "', '" + description + "');\n"); | ||||
|         } | ||||
|  | ||||
|         for (int i = 101; i <= 200; i++) { | ||||
|             String number = "number" + random.nextInt(1000, 10000); | ||||
|             Integer material_id = random.nextInt(1, 101); | ||||
|             String ean = eanGenerator(); | ||||
|             String unit_of_measure = "unit" + random.nextInt(1000, 10000); | ||||
|             String dimension = random.nextInt(5, 35) + "x" + random.nextInt(5, 35) + "x" + random.nextInt(5, 35); | ||||
|             String description = "description" + random.nextInt(1000, 10000); | ||||
|  | ||||
|             writer.write("INSERT INTO package VALUES(" + | ||||
|                     i + ", '" + number + "', '" + material_id + "', '" + ean + "', '" | ||||
|                     + unit_of_measure + "', '" + dimension + "', '" + description + "');\n"); | ||||
|         } | ||||
|  | ||||
|  | ||||
|         writer.close(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public String eanGenerator() { | ||||
|  | ||||
|         String result = "590"; | ||||
|         Random random = new Random(); | ||||
|         while (result.length() < 12) { | ||||
|             result += random.nextInt(10); | ||||
|         } | ||||
|  | ||||
|         int sum = 0; | ||||
|         for (int i = 0; i < result.length(); i++) { | ||||
|             if (i % 2 == 1) | ||||
|                 sum += (result.charAt(i) - '0') * 3; | ||||
|             else | ||||
|                 sum += (int) result.charAt(i) - '0'; | ||||
|         } | ||||
|  | ||||
|         sum = sum - (sum / 10) * (10); | ||||
|         if (sum != 0) | ||||
|             sum = 10 - sum; | ||||
|         result += sum; | ||||
|  | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
| } | ||||
							
								
								
									
										16
									
								
								src/main/java/com/release11/MyProcess.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/main/java/com/release11/MyProcess.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| package com.release11; | ||||
|  | ||||
| import org.apache.camel.Exchange; | ||||
| import org.apache.camel.Processor; | ||||
|  | ||||
| public class MyProcess implements Processor { | ||||
|     @Override | ||||
|     public void process(Exchange exchange) throws Exception { | ||||
|         System.out.println("SIEMAAAAAAAAAAA"); | ||||
|         String tmp = (String) exchange.getIn().getBody(); | ||||
|         System.out.println(tmp); | ||||
|         System.out.println("SIEMAAAAAAAAAAA"); | ||||
|         Thread.sleep(100000); | ||||
|  | ||||
|     } | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -5,7 +5,7 @@ | ||||
| This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.2  | ||||
| See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>  | ||||
| Any modifications to this file will be lost upon recompilation of the source schema.  | ||||
| Generated on: 2021.11.18 at 03:03:29 PM CET  | ||||
| Generated on: 2021.11.18 at 04:43:50 PM CET  | ||||
|  | ||||
|   --> | ||||
|   <jaxb:bindings scd="x-schema::"> | ||||
|   | ||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								target/classes/com/release11/Main$1$1.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								target/classes/com/release11/Main$1$1.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								target/classes/com/release11/MyProcess.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								target/classes/com/release11/MyProcess.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -5,7 +5,7 @@ | ||||
| This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.2  | ||||
| See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>  | ||||
| Any modifications to this file will be lost upon recompilation of the source schema.  | ||||
| Generated on: 2021.11.18 at 03:03:29 PM CET  | ||||
| Generated on: 2021.11.18 at 04:43:50 PM CET  | ||||
|  | ||||
|   --> | ||||
|   <jaxb:bindings scd="x-schema::"> | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.2  | ||||
| // See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>  | ||||
| // Any modifications to this file will be lost upon recompilation of the source schema.  | ||||
| // Generated on: 2021.11.18 at 03:03:29 PM CET  | ||||
| // Generated on: 2021.11.18 at 04:43:50 PM CET  | ||||
| // | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.2  | ||||
| // See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>  | ||||
| // Any modifications to this file will be lost upon recompilation of the source schema.  | ||||
| // Generated on: 2021.11.18 at 03:03:29 PM CET  | ||||
| // Generated on: 2021.11.18 at 04:43:50 PM CET  | ||||
| // | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.2  | ||||
| // See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>  | ||||
| // Any modifications to this file will be lost upon recompilation of the source schema.  | ||||
| // Generated on: 2021.11.18 at 03:03:29 PM CET  | ||||
| // Generated on: 2021.11.18 at 04:43:50 PM CET  | ||||
| // | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.2  | ||||
| // See <a href="https://javaee.github.io/jaxb-v2/">https://javaee.github.io/jaxb-v2/</a>  | ||||
| // Any modifications to this file will be lost upon recompilation of the source schema.  | ||||
| // Generated on: 2021.11.18 at 03:03:29 PM CET  | ||||
| // Generated on: 2021.11.18 at 04:43:50 PM CET  | ||||
| // | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -1,5 +0,0 @@ | ||||
| #Generated by Maven | ||||
| #Thu Nov 18 15:35:05 CET 2021 | ||||
| groupId=org.example | ||||
| artifactId=Camel | ||||
| version=1.0-SNAPSHOT | ||||
| @@ -0,0 +1,4 @@ | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/DAO.java | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/MyProcess.java | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/MyAggregator.java | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/Main.java | ||||
| @@ -0,0 +1,10 @@ | ||||
| com/release11/Main$1.class | ||||
| com/release11/Main$1$1.class | ||||
| generated/MaterialTypeType.class | ||||
| com/release11/Main.class | ||||
| com/release11/DAO.class | ||||
| com/release11/MyProcess.class | ||||
| generated/Package.class | ||||
| com/release11/MyAggregator.class | ||||
| generated/MaterialType.class | ||||
| generated/ObjectFactory.class | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/DAO.java | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/target/generated-sources/jaxb/generated/MaterialType.java | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/target/generated-sources/jaxb/generated/Package.java | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/MyBuilder.java | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/MyProcess.java | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/target/generated-sources/jaxb/generated/ObjectFactory.java | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/target/generated-sources/jaxb/generated/MaterialTypeType.java | ||||
| /home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/MyAggregator.java | ||||
|   | ||||
		Reference in New Issue
	
	Block a user