works
This commit is contained in:
		@@ -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 -> {
 | 
			
		||||
                            
 | 
			
		||||
                        });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user