some changes
This commit is contained in:
33
pom.xml
33
pom.xml
@@ -81,6 +81,28 @@
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.springboot</groupId>
|
||||
<artifactId>camel-jackson-starter</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-http</artifactId>
|
||||
<version>3.12.0</version>
|
||||
<!-- use the same version as your Camel core version -->
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-ftp</artifactId>
|
||||
<version>3.12.0</version>
|
||||
<!-- use the same version as your Camel core version -->
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -113,6 +135,17 @@
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<configuration>
|
||||
<mainClass>com.release11.Main</mainClass>
|
||||
<arguments>
|
||||
<argument>arg1</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
package com.release11;
|
||||
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
import com.release11.Processors.*;
|
||||
import generated.ObjectFactory;
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.camel.*;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.component.jackson.JacksonDataFormat;
|
||||
import org.apache.camel.component.jms.JmsComponent;
|
||||
import org.apache.camel.impl.DefaultCamelContext;
|
||||
import org.apache.camel.support.SimpleRegistry;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.camel.converter.jaxb.JaxbDataFormat;
|
||||
import javax.xml.bind.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Main {
|
||||
@@ -47,7 +41,9 @@ public class Main {
|
||||
|
||||
JaxbDataFormat xmlDataFormat = new JaxbDataFormat();
|
||||
xmlDataFormat.setContextPath("generated");
|
||||
//xmlDataFormat.setSchemaLocation("/home/igor/Documents/Jacek/jacek-and-igor/src/main/resources/material.xsd");
|
||||
JacksonDataFormat jacksonDataFormat = new JacksonDataFormat(ObjectFactory.class);
|
||||
jacksonDataFormat.setPrettyPrint(true);
|
||||
errorHandler(deadLetterChannel("activemq:queue:dead"));
|
||||
|
||||
from("direct:start")
|
||||
.setBody(constant("SELECT * FROM material"))
|
||||
@@ -60,46 +56,46 @@ public class Main {
|
||||
.setBody(simple("SELECT * FROM package WHERE material_id = :?material_id"))
|
||||
.to("jdbc:source?useHeadersAsParameters=true");
|
||||
|
||||
from("activemq:queue:RawMaterial")
|
||||
from("activemq:queue:RawMaterial")//subskruypcja
|
||||
.enrich("direct:getPackages", new MergeAggregator())
|
||||
.process(new ValidatorProcess())
|
||||
.choice()
|
||||
.when(simple("${exchangeProperty[dimension]}"+" == false"))
|
||||
.marshal(xmlDataFormat)
|
||||
.to("activemq:queue:BadEan")
|
||||
.when(simple("${exchangeProperty[ean]}"+" == false"))
|
||||
.marshal(xmlDataFormat)
|
||||
.to("activemq:queue:BadDimension")
|
||||
.otherwise()
|
||||
.marshal(xmlDataFormat)
|
||||
.to("activemq:queue:ValidMaterial")
|
||||
.when(simple("${exchangeProperty[ean]}"+" == false")).marshal(xmlDataFormat).to("activemq:queue:BadEan")
|
||||
.when(simple("${exchangeProperty[dimension]}"+" == false")).marshal(xmlDataFormat).to("activemq:queue:BadDimension")
|
||||
.otherwise().marshal(xmlDataFormat).to("activemq:topic:Material")
|
||||
.to("log:?level=INFO&showBody=true");
|
||||
|
||||
|
||||
from("activemq:topic:Material?clientId=1&durableSubscriptionName=FilteredType")
|
||||
.filter().xpath("//material_type='A1' or //material_type='A2' or //material_type='A3'")
|
||||
.to("activemq:queue:FilteredType");
|
||||
|
||||
|
||||
from("activemq:queue:siema")
|
||||
.process(new XMLProcess())
|
||||
from("activemq:queue:FilteredType")
|
||||
.unmarshal(xmlDataFormat)
|
||||
.process(new XMLProcess())
|
||||
.to("activemq:queue:test");
|
||||
.marshal(jacksonDataFormat)
|
||||
.to("http:10.101.111.19:1080/api/json/material");
|
||||
|
||||
|
||||
|
||||
|
||||
from("activemq:topic:Material?clientId=2&durableSubscriptionName=FilteredIsDeleted&acknowledgementModeName=CLIENT_ACKNOWLEDGE")
|
||||
.filter().xpath("//is_deleted='false'")
|
||||
.to("activemq:queue:FilteredIsDeleted");
|
||||
|
||||
from("activemq:queue:FilteredIsDeleted")
|
||||
.unmarshal(xmlDataFormat)
|
||||
.process(new CSVProcess())
|
||||
.to("sftp:test@10.101.111.19:2222/upload/test?password=admin");
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
context.start();
|
||||
ProducerTemplate template = context.createProducerTemplate();
|
||||
|
||||
Path path = Paths.get("/home/igor/Documents/Jacek/jacek-and-igor/src/main/resources/test.xml");
|
||||
ArrayList<String> readAllLines = (ArrayList<String>) Files.readAllLines(path);
|
||||
String allFile = "";
|
||||
for (int i = 0; i < readAllLines.size(); i++) {
|
||||
allFile+=readAllLines.get(i);
|
||||
}
|
||||
|
||||
//template.sendBody("direct:start", null);
|
||||
template.sendBody("activemq:queue:siema", allFile);
|
||||
|
||||
template.sendBody("direct:start", null);
|
||||
context.stop();
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,8 @@ 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.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MergeAggregator implements AggregationStrategy {
|
||||
@Override
|
||||
@@ -28,10 +25,6 @@ public class MergeAggregator 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"));
|
||||
|
||||
34
src/main/java/com/release11/Processors/CSVProcess.java
Normal file
34
src/main/java/com/release11/Processors/CSVProcess.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package com.release11.Processors;
|
||||
|
||||
import generated.MaterialType;
|
||||
import generated.Package;
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
|
||||
public class CSVProcess implements Processor {
|
||||
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
MaterialType material = exchange.getIn().getBody(MaterialType.class);
|
||||
String result = "";
|
||||
result+=material.getId()+",";
|
||||
result+=material.getMaterialNumber()+",";
|
||||
result+=material.getMaterialType()+",";
|
||||
result+=material.getMaterialName()+",";
|
||||
result+=material.getDescription()+";";
|
||||
|
||||
for (Package p: material.getPackages()) {
|
||||
String pack = "";
|
||||
pack+=p.getId()+",";
|
||||
pack+=p.getPackageNumber()+",";
|
||||
pack+=p.getMaterialId()+",";
|
||||
pack+=p.getEan()+",";
|
||||
pack+=p.getUnitOfMeasure()+",";
|
||||
pack+=p.getDimension()+",";
|
||||
pack+=p.getDescription()+";";
|
||||
result+=pack;
|
||||
}
|
||||
|
||||
exchange.getIn().setBody(result);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.release11;
|
||||
package com.release11.Processors;
|
||||
|
||||
import generated.MaterialType;
|
||||
import generated.Package;
|
||||
@@ -15,10 +15,14 @@ public class ValidatorProcess implements Processor {
|
||||
Pattern pattern = Pattern.compile("\\d\\dx\\d\\dx\\d\\d");
|
||||
for (Package p: material.getPackages()) {
|
||||
Matcher matcher = pattern.matcher(p.getDimension());
|
||||
if (!matcher.matches())
|
||||
if (!matcher.matches()) {
|
||||
exchange.setProperty("dimension", false);
|
||||
if(!isEanGood(p.getEan()))
|
||||
break;
|
||||
}
|
||||
if (!isEanGood(p.getEan())) {
|
||||
exchange.setProperty("ean", false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
src/main/java/com/release11/Processors/XMLProcess.java
Normal file
16
src/main/java/com/release11/Processors/XMLProcess.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.release11.Processors;
|
||||
|
||||
import generated.MaterialType;
|
||||
import generated.MaterialTypeType;
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
|
||||
public class XMLProcess implements Processor {
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
|
||||
MaterialType material = exchange.getIn().getBody(MaterialType.class);
|
||||
System.out.println(material.toString());
|
||||
exchange.getIn().setBody(material);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.release11;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
|
||||
public class XMLProcess implements Processor {
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
String tmp = exchange.getIn().getBody(String.class);
|
||||
System.out.println(tmp);
|
||||
exchange.getIn().setBody(tmp);
|
||||
|
||||
}
|
||||
}
|
||||
BIN
target/Camel-1.0-SNAPSHOT.jar
Normal file
BIN
target/Camel-1.0-SNAPSHOT.jar
Normal file
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 04:43:50 PM CET
|
||||
Generated on: 2021.11.19 at 01:42:55 PM CET
|
||||
|
||||
-->
|
||||
<jaxb:bindings scd="x-schema::">
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/classes/com/release11/Processors/CSVProcess.class
Normal file
BIN
target/classes/com/release11/Processors/CSVProcess.class
Normal file
Binary file not shown.
BIN
target/classes/com/release11/Processors/ValidatorProcess.class
Normal file
BIN
target/classes/com/release11/Processors/ValidatorProcess.class
Normal file
Binary file not shown.
BIN
target/classes/com/release11/Processors/XMLProcess.class
Normal file
BIN
target/classes/com/release11/Processors/XMLProcess.class
Normal file
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 04:43:50 PM CET
|
||||
Generated on: 2021.11.19 at 01:42:55 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 04:43:50 PM CET
|
||||
// Generated on: 2021.11.19 at 01:42:55 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 04:43:50 PM CET
|
||||
// Generated on: 2021.11.19 at 01:42:55 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 04:43:50 PM CET
|
||||
// Generated on: 2021.11.19 at 01:42:55 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 04:43:50 PM CET
|
||||
// Generated on: 2021.11.19 at 01:42:55 PM CET
|
||||
//
|
||||
|
||||
|
||||
|
||||
5
target/maven-archiver/pom.properties
Normal file
5
target/maven-archiver/pom.properties
Normal file
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Fri Nov 19 13:44:30 CET 2021
|
||||
groupId=org.example
|
||||
artifactId=Camel
|
||||
version=1.0-SNAPSHOT
|
||||
@@ -1,4 +0,0 @@
|
||||
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/Main.java
|
||||
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/MergeAggregator.java
|
||||
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/ValidatorProcess.java
|
||||
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/XMLProcess.java
|
||||
@@ -1,6 +0,0 @@
|
||||
com/release11/Main$1.class
|
||||
generated/MaterialTypeType.class
|
||||
com/release11/Main.class
|
||||
generated/Package.class
|
||||
generated/MaterialType.class
|
||||
generated/ObjectFactory.class
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/Processors/ValidatorProcess.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/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/Main.java
|
||||
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/MergeAggregator.java
|
||||
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/ValidatorProcess.java
|
||||
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/XMLProcess.java
|
||||
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/Processors/XMLProcess.java
|
||||
/home/igor/Documents/Jacek/jacek-and-igor/src/main/java/com/release11/Processors/CSVProcess.java
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
-->
|
||||
|
||||
<!DOCTYPE web-app PUBLIC
|
||||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||
"http://java.sun.com/dtd/web-app_2_3.dtd" >
|
||||
|
||||
<web-app>
|
||||
<filter>
|
||||
<filter-name>doxia</filter-name>
|
||||
<filter-class>org.apache.maven.plugins.site.webapp.DoxiaFilter</filter-class>
|
||||
</filter>
|
||||
|
||||
<filter-mapping>
|
||||
<filter-name>doxia</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
||||
Reference in New Issue
Block a user