117 lines
4.0 KiB
Java
117 lines
4.0 KiB
Java
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;
|
|
}
|
|
|
|
}
|