This commit is contained in:
2021-11-18 15:35:17 +01:00
parent e941c241fc
commit 8dd10daa69
18 changed files with 81 additions and 23 deletions

View File

@@ -9,8 +9,8 @@
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>

View File

@@ -59,10 +59,33 @@ public class Main {
from("activemq:queue:RawMaterial")
.enrich("direct:getPackages", new MyAggregator())
.marshal(xmlDataFormat)
.to("activemq:queue:MaterialPackage")
.choice()
.when(simple("${header.ean} == 'false'"))
.marshal(xmlDataFormat)
.to("activemq:queue:BadEan")
.when(simple("${header.dimension} == 'false'"))
.marshal(xmlDataFormat)
.to("activemq:queue:BadDimension")
.otherwise()
.marshal(xmlDataFormat)
.to("activemq:queue:ValidMaterial")
.to("log:?level=INFO&showBody=true");
from("activemq:queue:ValidMaterial")
.process(exchange -> {
});
}
});

View File

@@ -27,6 +27,10 @@ public class MyAggregator implements AggregationStrategy {
material.setDescription((String) oldEx.get("description"));
material.setIsDeleted((Boolean) oldEx.get("is_deleted"));
oldExchange.getIn().setHeader("dimension", "true");
oldExchange.getIn().setHeader("ean", "true");
for (int i = 0; i < newEx.size(); i++) {
Package p = new Package();
p.setId((Integer) newEx.get(i).get("id"));
@@ -41,21 +45,39 @@ public class MyAggregator implements AggregationStrategy {
//validation
Pattern pattern = Pattern.compile("\\d\\dx\\d\\dx\\d\\d");
Matcher matcher = pattern.matcher(p.getDimension());
if(matcher.matches()){
System.out.println("maczuje");
}
else{
System.out.println("nieeeeeeeee");
}
if (!matcher.matches())
oldExchange.getIn().setHeader("dimension", "false");
if(!isEanGood(p.getEan()))
oldExchange.getIn().setHeader("ean", "false");
}
Exchange result = oldExchange;
result.getIn().setBody(material);
return result;
oldExchange.getIn().setBody(material);
return oldExchange;
}
boolean isEanGood(String ean) {
int sum = 0;
for (int i = 0; i < ean.length() - 1; i++) {
if (i % 2 == 1)
sum += (ean.charAt(i) - '0') * 3;
else
sum += (int) ean.charAt(i) - '0';
}
sum = sum - (sum / 10) * (10);
if (sum != 0)
sum = 10 - sum;
int tmp1 = Integer.valueOf(sum);
int tmp2 = Integer.valueOf(ean.charAt(ean.length()-1)-'0');
if(tmp1 == tmp2)
return true;
return false;
}
}

Binary file not shown.

View File

@@ -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 02:34:17 PM CET
Generated on: 2021.11.18 at 03:03:29 PM CET
-->
<jaxb:bindings scd="x-schema::">

View File

@@ -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 02:34:17 PM CET
Generated on: 2021.11.18 at 03:03:29 PM CET
-->
<jaxb:bindings scd="x-schema::">

View File

@@ -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 02:34:17 PM CET
// Generated on: 2021.11.18 at 03:03:29 PM CET
//

View File

@@ -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 02:34:17 PM CET
// Generated on: 2021.11.18 at 03:03:29 PM CET
//

View File

@@ -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 02:34:17 PM CET
// Generated on: 2021.11.18 at 03:03:29 PM CET
//

View File

@@ -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 02:34:17 PM CET
// Generated on: 2021.11.18 at 03:03:29 PM CET
//

View File

View File

@@ -0,0 +1,5 @@
#Generated by Maven
#Thu Nov 18 15:35:05 CET 2021
groupId=org.example
artifactId=Camel
version=1.0-SNAPSHOT

View File

@@ -0,0 +1,8 @@
/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/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
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/Main.java