|
1 | 1 | package middle.director; |
2 | 2 |
|
3 | | -/** Final medium-range hops before national module delivery. */ |
| 3 | +import javax.xml.parsers.DocumentBuilderFactory; |
| 4 | +import org.w3c.dom.*; |
| 5 | +import java.io.File; |
| 6 | +import java.util.concurrent.CopyOnWriteArrayList; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +/** |
| 10 | + * Final medium-range hops before national module delivery. |
| 11 | + * Handles science conclusions, postulates, explorations, rich research, |
| 12 | + * and final commodities for grain review. |
| 13 | + * |
| 14 | + * IQ is forwarded as relevant — PhD-level structural methods (exact understanding) |
| 15 | + * are required for immediate approval; otherwise held for auditor review. |
| 16 | + */ |
4 | 17 | public class FinalMediumHopsModule implements DirectorModule |
5 | 18 | { |
| 19 | + private static final String CONFIG = "configuration/final-medium-hops-commodities.xml"; |
| 20 | + |
| 21 | + private final List<Commodity> commodities = new CopyOnWriteArrayList<>(); |
| 22 | + private int iqThreshold = 120; |
| 23 | + |
| 24 | + public FinalMediumHopsModule() |
| 25 | + { |
| 26 | + loadCommodities(); |
| 27 | + } |
| 28 | + |
6 | 29 | @Override public String name() { return "FinalMediumHops"; } |
7 | 30 |
|
8 | 31 | @Override |
9 | 32 | public String process(String input) |
10 | 33 | { |
| 34 | + String cmd = input.trim().toLowerCase(); |
| 35 | + for (Commodity c : commodities) |
| 36 | + { |
| 37 | + if (cmd.contains(c.name.toLowerCase())) |
| 38 | + return "[FinalMediumHop:" + c.name + "/" + c.type + "] " + input; |
| 39 | + } |
11 | 40 | return "[FinalMediumHop] " + input; |
12 | 41 | } |
13 | 42 |
|
| 43 | + /** |
| 44 | + * Process, evaluate (IQ + PhD required for structural sign-off), persist. |
| 45 | + */ |
14 | 46 | public String processAndRecord(String input, long nationalId, String ip, |
15 | 47 | String publicKey, long signatoryId, String signatoryKey, |
16 | 48 | boolean employed, boolean democrat, |
17 | | - int trustLevel, String educationLevel) |
| 49 | + int trustLevel, String educationLevel, int iq) |
18 | 50 | { |
19 | | - recordTrade("finalmedium", nationalId, ip, publicKey, signatoryId, signatoryKey, employed, democrat); |
20 | | - return evaluateAndProcess(input, "finalmedium", nationalId, trustLevel, educationLevel); |
| 51 | + String commodityType = resolveCommodity(input); |
| 52 | + recordTrade(commodityType, nationalId, ip, publicKey, signatoryId, signatoryKey, employed, democrat); |
| 53 | + |
| 54 | + // PhD + IQ threshold for structural method exact understanding |
| 55 | + boolean phdLevel = "phd".equalsIgnoreCase(educationLevel != null ? educationLevel.trim() : ""); |
| 56 | + boolean iqSufficient = iq >= iqThreshold; |
| 57 | + |
| 58 | + if (phdLevel && iqSufficient) |
| 59 | + return process(input) + " [APPROVED — PhD structural, IQ " + iq + "]"; |
| 60 | + else if (phdLevel) |
| 61 | + return process(input) + " [APPROVED — PhD structural, IQ forwarded]"; |
| 62 | + else |
| 63 | + { |
| 64 | + TradeEvaluator.evaluate(name(), commodityType, nationalId, trustLevel, educationLevel, input); |
| 65 | + return process(input) + " [HELD 48hrs — requires PhD-level exact understanding]"; |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + private String resolveCommodity(String input) |
| 70 | + { |
| 71 | + String cmd = input.trim().toLowerCase(); |
| 72 | + for (Commodity c : commodities) |
| 73 | + if (cmd.contains(c.name.toLowerCase())) return c.name; |
| 74 | + return "research"; |
| 75 | + } |
| 76 | + |
| 77 | + public List<Commodity> getCommodities() { return commodities; } |
| 78 | + |
| 79 | + private void loadCommodities() |
| 80 | + { |
| 81 | + try |
| 82 | + { |
| 83 | + File file = new File(CONFIG); |
| 84 | + if (!file.exists()) return; |
| 85 | + |
| 86 | + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file); |
| 87 | + |
| 88 | + // Load IQ threshold |
| 89 | + NodeList evalNodes = doc.getElementsByTagName("iq-threshold"); |
| 90 | + if (evalNodes.getLength() > 0) |
| 91 | + iqThreshold = Integer.parseInt(((Element) evalNodes.item(0)).getAttribute("value")); |
| 92 | + |
| 93 | + // Load commodities |
| 94 | + NodeList nodes = doc.getElementsByTagName("commodity"); |
| 95 | + for (int i = 0; i < nodes.getLength(); i++) |
| 96 | + { |
| 97 | + Element el = (Element) nodes.item(i); |
| 98 | + commodities.add(new Commodity( |
| 99 | + el.getAttribute("name"), |
| 100 | + el.getAttribute("type"), |
| 101 | + el.getAttribute("description") |
| 102 | + )); |
| 103 | + } |
| 104 | + |
| 105 | + commons.CommonRails.printSystemComponent(this, this.hashCode(), |
| 106 | + ". FinalMediumHopsModule loaded " + commodities.size() + " commodities, IQ threshold " + iqThreshold + " ."); |
| 107 | + } |
| 108 | + catch (Exception e) { exceptions.ExceptionHandler.dispatch(e); } |
| 109 | + } |
| 110 | + |
| 111 | + public static class Commodity |
| 112 | + { |
| 113 | + public final String name; |
| 114 | + public final String type; |
| 115 | + public final String description; |
| 116 | + |
| 117 | + public Commodity(String name, String type, String description) |
| 118 | + { |
| 119 | + this.name = name; |
| 120 | + this.type = type; |
| 121 | + this.description = description; |
| 122 | + } |
21 | 123 | } |
22 | 124 | } |
0 commit comments