@Test public void updateFields() throws Exception { ZonedDateTime zdt = ZonedDateTime.now().plusHours(1); String field1 = "definition.issuer"; String value1 = "<definition.issuer>\n" + " <SimpleRole>\n" + " <keys isArray=\"true\">\n" + " <item>\n" + " <KeyRecord>\n" + " <name>Universa</name>\n" + " <key>\n" + " <RSAPublicKey>\n" + " <packed>\n" + " <binary>\n" + " <base64>HggcAQABxAACzHE9ibWlnK4RzpgFIB4jIg3WcXZSKXNAqOTYUtGXY03xJSwpqE+y/HbqqE0W\n" + "smcAt5a0F5H7bz87Uy8Me1UdIDcOJgP8HMF2M0I/kkT6d59ZhYH/TlpDcpLvnJWElZAfOyta\n" + "ICE01bkOkf6Mz5egpToDEEPZH/RXigj9wkSXkk43WZSxVY5f2zaVmibUZ9VLoJlmjNTZ+utJ\n" + "UZi66iu9e0SXupOr/+BJL1Gm595w32Fd0141kBvAHYDHz2K3x4m1oFAcElJ83ahSl1u85/na\n" + "Iaf2yuxiQNz3uFMTn0IpULCMvLMvmE+L9io7+KWXld2usujMXI1ycDRw85h6IJlPcKHVQKnJ\n" + "/4wNBUveBDLFLlOcMpCzWlO/D7M2IyNa8XEvwPaFJlN1UN/9eVpaRUBEfDq6zi+RC8MaVWzF\n" + "bNi913suY0Q8F7ejKR6aQvQPuNN6bK6iRYZchxe/FwWIXOr0C0yA3NFgxKLiKZjkd5eJ84GL\n" + "y+iD00Rzjom+GG4FDQKr2HxYZDdDuLE4PEpYSzEB/8LyIqeM7dSyaHFTBII/sLuFru6ffoKx\n" + "BNk/cwAGZqOwD3fkJjNq1R3h6QylWXI/cSO9yRnRMmMBJwalMexOc3/kPEEdfjH/GcJU0Mw6\n" + "DgoY8QgfaNwXcFbBUvf3TwZ5Mysf21OLHH13g8gzREm+h8c=</base64>\n" + " </binary>\n" + " </packed>\n" + " </RSAPublicKey>\n" + " </key>\n" + " </KeyRecord>\n" + " </item>\n" + " </keys>\n" + " <name>issuer</name>\n" + " </SimpleRole>\n" + " </definition.issuer>"; String field2 = "definition.expires_at"; String value2 = "<definition.expires__at>\n" + " <unixtime>" + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss [XXX]").format(zdt) + "</unixtime>\n" + "</definition.expires__at>"; callMain( "-e", basePath + "contract_to_export.unicon", "-set", field1, "-value", value1, "-set", field2, "-value", value2); System.out.println(output); assertTrue (output.indexOf("update field " + field2 + " ok") >= 0); assertTrue (output.indexOf("contract expires at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(zdt)) >= 0); assertEquals(0, errors.size()); }
private static void updateFields(Contract contract, HashMap<String, String> fields) throws IOException { for (String fieldName : fields.keySet()) { report("update field: " + fieldName + " -> " + fields.get(fieldName)); Binder data = null; Object obj = null; try { XStream xstream = new XStream(new DomDriver()); xstream.registerConverter(new MapEntryConverter()); xstream.alias(fieldName, Binder.class); data = Binder.convertAllMapsToBinders(xstream.fromXML(fields.get(fieldName))); } catch (Exception xmlEx) { try { Gson gson = new GsonBuilder().create(); data = Binder.convertAllMapsToBinders(gson.fromJson(fields.get(fieldName), Binder.class)); if (data.containsKey(fieldName)) data = (Binder) data.get(fieldName); } catch (Exception jsonEx) { try { Yaml yaml = new Yaml(); Object loaded = Binder.convertAllMapsToBinders(yaml.load(fields.get(fieldName))); if (loaded.getClass().equals(Binder.class)) { data = (Binder) loaded; if (data.containsKey(fieldName)) data = (Binder) data.get(fieldName); } else obj = loaded; } catch (Exception yamlEx) { try { obj = fields.get(fieldName); } catch (Exception ex) { ex.printStackTrace(); xmlEx.printStackTrace(); jsonEx.printStackTrace(); yamlEx.printStackTrace(); } } } } if ((data != null) || (obj != null)) { Binder binder = new Binder(); if (data != null) { BiDeserializer bm = DefaultBiMapper.getInstance().newDeserializer(); binder.put("data", bm.deserialize(data)); } else binder.put("data", obj); contract.set(fieldName, binder); report("update field " + fieldName + " ok"); } else { report("update field " + fieldName + " error: no valid data"); } } report("contract expires at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(contract.getExpiresAt())); }
CLIMain { private static void updateFields(Contract contract, HashMap<String, String> fields) throws IOException { for (String fieldName : fields.keySet()) { report("update field: " + fieldName + " -> " + fields.get(fieldName)); Binder data = null; Object obj = null; try { XStream xstream = new XStream(new DomDriver()); xstream.registerConverter(new MapEntryConverter()); xstream.alias(fieldName, Binder.class); data = Binder.convertAllMapsToBinders(xstream.fromXML(fields.get(fieldName))); } catch (Exception xmlEx) { try { Gson gson = new GsonBuilder().create(); data = Binder.convertAllMapsToBinders(gson.fromJson(fields.get(fieldName), Binder.class)); if (data.containsKey(fieldName)) data = (Binder) data.get(fieldName); } catch (Exception jsonEx) { try { Yaml yaml = new Yaml(); Object loaded = Binder.convertAllMapsToBinders(yaml.load(fields.get(fieldName))); if (loaded.getClass().equals(Binder.class)) { data = (Binder) loaded; if (data.containsKey(fieldName)) data = (Binder) data.get(fieldName); } else obj = loaded; } catch (Exception yamlEx) { try { obj = fields.get(fieldName); } catch (Exception ex) { ex.printStackTrace(); xmlEx.printStackTrace(); jsonEx.printStackTrace(); yamlEx.printStackTrace(); } } } } if ((data != null) || (obj != null)) { Binder binder = new Binder(); if (data != null) { BiDeserializer bm = DefaultBiMapper.getInstance().newDeserializer(); binder.put("data", bm.deserialize(data)); } else binder.put("data", obj); contract.set(fieldName, binder); report("update field " + fieldName + " ok"); } else { report("update field " + fieldName + " error: no valid data"); } } report("contract expires at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(contract.getExpiresAt())); } }
CLIMain { private static void updateFields(Contract contract, HashMap<String, String> fields) throws IOException { for (String fieldName : fields.keySet()) { report("update field: " + fieldName + " -> " + fields.get(fieldName)); Binder data = null; Object obj = null; try { XStream xstream = new XStream(new DomDriver()); xstream.registerConverter(new MapEntryConverter()); xstream.alias(fieldName, Binder.class); data = Binder.convertAllMapsToBinders(xstream.fromXML(fields.get(fieldName))); } catch (Exception xmlEx) { try { Gson gson = new GsonBuilder().create(); data = Binder.convertAllMapsToBinders(gson.fromJson(fields.get(fieldName), Binder.class)); if (data.containsKey(fieldName)) data = (Binder) data.get(fieldName); } catch (Exception jsonEx) { try { Yaml yaml = new Yaml(); Object loaded = Binder.convertAllMapsToBinders(yaml.load(fields.get(fieldName))); if (loaded.getClass().equals(Binder.class)) { data = (Binder) loaded; if (data.containsKey(fieldName)) data = (Binder) data.get(fieldName); } else obj = loaded; } catch (Exception yamlEx) { try { obj = fields.get(fieldName); } catch (Exception ex) { ex.printStackTrace(); xmlEx.printStackTrace(); jsonEx.printStackTrace(); yamlEx.printStackTrace(); } } } } if ((data != null) || (obj != null)) { Binder binder = new Binder(); if (data != null) { BiDeserializer bm = DefaultBiMapper.getInstance().newDeserializer(); binder.put("data", bm.deserialize(data)); } else binder.put("data", obj); contract.set(fieldName, binder); report("update field " + fieldName + " ok"); } else { report("update field " + fieldName + " error: no valid data"); } } report("contract expires at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(contract.getExpiresAt())); }  }
CLIMain { private static void updateFields(Contract contract, HashMap<String, String> fields) throws IOException { for (String fieldName : fields.keySet()) { report("update field: " + fieldName + " -> " + fields.get(fieldName)); Binder data = null; Object obj = null; try { XStream xstream = new XStream(new DomDriver()); xstream.registerConverter(new MapEntryConverter()); xstream.alias(fieldName, Binder.class); data = Binder.convertAllMapsToBinders(xstream.fromXML(fields.get(fieldName))); } catch (Exception xmlEx) { try { Gson gson = new GsonBuilder().create(); data = Binder.convertAllMapsToBinders(gson.fromJson(fields.get(fieldName), Binder.class)); if (data.containsKey(fieldName)) data = (Binder) data.get(fieldName); } catch (Exception jsonEx) { try { Yaml yaml = new Yaml(); Object loaded = Binder.convertAllMapsToBinders(yaml.load(fields.get(fieldName))); if (loaded.getClass().equals(Binder.class)) { data = (Binder) loaded; if (data.containsKey(fieldName)) data = (Binder) data.get(fieldName); } else obj = loaded; } catch (Exception yamlEx) { try { obj = fields.get(fieldName); } catch (Exception ex) { ex.printStackTrace(); xmlEx.printStackTrace(); jsonEx.printStackTrace(); yamlEx.printStackTrace(); } } } } if ((data != null) || (obj != null)) { Binder binder = new Binder(); if (data != null) { BiDeserializer bm = DefaultBiMapper.getInstance().newDeserializer(); binder.put("data", bm.deserialize(data)); } else binder.put("data", obj); contract.set(fieldName, binder); report("update field " + fieldName + " ok"); } else { report("update field " + fieldName + " error: no valid data"); } } report("contract expires at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(contract.getExpiresAt())); }  static void main(String[] args); static PrivateKey getPrivateKey(); static BasicHttpClientSession getSession(int nodeNumber); static void breakSession(int nodeNumber); static void clearSession(); static void clearSession(boolean full); static void saveSession(); static void setVerboseMode(boolean verboseMode); static Contract loadContract(String fileName, Boolean fromPackedTransaction); static Parcel loadParcel(String fileName); static Contract loadContract(String fileName); static void exportContract(Contract contract, String fileName, String format, Boolean jsonPretty); static boolean saveContract(Contract contract, String fileName, Boolean fromPackedTransaction, Boolean addSigners); static boolean saveContract(Contract contract, String fileName, Boolean fromPackedTransaction, Boolean addSigners, Set<Contract> referencedItems); static boolean saveParcel(Parcel parcel, String fileName); static void saveContract(Contract contract, String fileName); static List<Wallet> findWallets(String path); static HashMap<String, Contract> findContracts(String path); static HashMap<String, Contract> findContracts(String path, Boolean recursively); static List<File> findFiles(String path, Boolean recursively); static Contract downloadContract(String url); static Parcel revokeContract(Contract contract, Contract u, int amount, Set<PrivateKey> uKeys, boolean withTestPayment, PrivateKey... key); @Deprecated static Contract revokeContract(Contract contract, PrivateKey... key); @Deprecated static void registerContract(Contract contract, int waitTime, Boolean fromPackedTransaction); static Parcel prepareForRegisterContract(Contract contract, Contract u, int amount, Set<PrivateKey> uKeys, boolean withTestPayment); static Parcel prepareForRegisterPayingParcel(Contract contract, Contract u, int amount, int amountStorage, Set<PrivateKey> uKeys, boolean withTestPayment); static ItemResult registerParcel(Parcel parcel, int waitTime); static void registerContract(Contract contract); static void registerContract(Contract contract, int waitTime); static void setTestMode(); static void setTestRootPath(String rootPath); static void setNodeNumber(int number); static void setNodeUrl(String url); static void setTopologyFileName(String filename); static void setPrivateKey(PrivateKey key); static Reporter getReporter(); static synchronized ClientNetwork getClientNetwork(); static synchronized Map<String, PrivateKey> keysMap(); static synchronized Map<String, PrivateKey> keysMapContract(); }
CLIMain { private static void updateFields(Contract contract, HashMap<String, String> fields) throws IOException { for (String fieldName : fields.keySet()) { report("update field: " + fieldName + " -> " + fields.get(fieldName)); Binder data = null; Object obj = null; try { XStream xstream = new XStream(new DomDriver()); xstream.registerConverter(new MapEntryConverter()); xstream.alias(fieldName, Binder.class); data = Binder.convertAllMapsToBinders(xstream.fromXML(fields.get(fieldName))); } catch (Exception xmlEx) { try { Gson gson = new GsonBuilder().create(); data = Binder.convertAllMapsToBinders(gson.fromJson(fields.get(fieldName), Binder.class)); if (data.containsKey(fieldName)) data = (Binder) data.get(fieldName); } catch (Exception jsonEx) { try { Yaml yaml = new Yaml(); Object loaded = Binder.convertAllMapsToBinders(yaml.load(fields.get(fieldName))); if (loaded.getClass().equals(Binder.class)) { data = (Binder) loaded; if (data.containsKey(fieldName)) data = (Binder) data.get(fieldName); } else obj = loaded; } catch (Exception yamlEx) { try { obj = fields.get(fieldName); } catch (Exception ex) { ex.printStackTrace(); xmlEx.printStackTrace(); jsonEx.printStackTrace(); yamlEx.printStackTrace(); } } } } if ((data != null) || (obj != null)) { Binder binder = new Binder(); if (data != null) { BiDeserializer bm = DefaultBiMapper.getInstance().newDeserializer(); binder.put("data", bm.deserialize(data)); } else binder.put("data", obj); contract.set(fieldName, binder); report("update field " + fieldName + " ok"); } else { report("update field " + fieldName + " error: no valid data"); } } report("contract expires at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(contract.getExpiresAt())); }  static void main(String[] args); static PrivateKey getPrivateKey(); static BasicHttpClientSession getSession(int nodeNumber); static void breakSession(int nodeNumber); static void clearSession(); static void clearSession(boolean full); static void saveSession(); static void setVerboseMode(boolean verboseMode); static Contract loadContract(String fileName, Boolean fromPackedTransaction); static Parcel loadParcel(String fileName); static Contract loadContract(String fileName); static void exportContract(Contract contract, String fileName, String format, Boolean jsonPretty); static boolean saveContract(Contract contract, String fileName, Boolean fromPackedTransaction, Boolean addSigners); static boolean saveContract(Contract contract, String fileName, Boolean fromPackedTransaction, Boolean addSigners, Set<Contract> referencedItems); static boolean saveParcel(Parcel parcel, String fileName); static void saveContract(Contract contract, String fileName); static List<Wallet> findWallets(String path); static HashMap<String, Contract> findContracts(String path); static HashMap<String, Contract> findContracts(String path, Boolean recursively); static List<File> findFiles(String path, Boolean recursively); static Contract downloadContract(String url); static Parcel revokeContract(Contract contract, Contract u, int amount, Set<PrivateKey> uKeys, boolean withTestPayment, PrivateKey... key); @Deprecated static Contract revokeContract(Contract contract, PrivateKey... key); @Deprecated static void registerContract(Contract contract, int waitTime, Boolean fromPackedTransaction); static Parcel prepareForRegisterContract(Contract contract, Contract u, int amount, Set<PrivateKey> uKeys, boolean withTestPayment); static Parcel prepareForRegisterPayingParcel(Contract contract, Contract u, int amount, int amountStorage, Set<PrivateKey> uKeys, boolean withTestPayment); static ItemResult registerParcel(Parcel parcel, int waitTime); static void registerContract(Contract contract); static void registerContract(Contract contract, int waitTime); static void setTestMode(); static void setTestRootPath(String rootPath); static void setNodeNumber(int number); static void setNodeUrl(String url); static void setTopologyFileName(String filename); static void setPrivateKey(PrivateKey key); static Reporter getReporter(); static synchronized ClientNetwork getClientNetwork(); static synchronized Map<String, PrivateKey> keysMap(); static synchronized Map<String, PrivateKey> keysMapContract(); static String DEFAULT_WALLET_PATH; static final String AMOUNT_FIELD_NAME; }