From 72b81525211ee45e29f63f12d7154b334daf46d7 Mon Sep 17 00:00:00 2001 From: Dan Dold Date: Sun, 11 Feb 2018 17:06:31 +0000 Subject: [PATCH] Implemented createFrom stream command and fixed bug with create permissions --- src/multichain/command/StreamCommand.java | 62 ++++++++++++++++++- .../command/builders/QueryBuilderGrant.java | 2 +- .../command/builders/QueryBuilderStream.java | 29 +++++++++ .../test/command/StreamCommandTest.java | 32 +++++++++- 4 files changed, 120 insertions(+), 5 deletions(-) diff --git a/src/multichain/command/StreamCommand.java b/src/multichain/command/StreamCommand.java index c72f3fa..78c4af1 100644 --- a/src/multichain/command/StreamCommand.java +++ b/src/multichain/command/StreamCommand.java @@ -73,8 +73,7 @@ public String create(String streamName, boolean open) throws MultichainException * Result: "transactionid" (string) The transaction id. * * @param streamName - * @param open - * = false + * @param open = false * @return TxId * @throws MultichainException */ @@ -82,6 +81,65 @@ public String create(String streamName) throws MultichainException { return create(streamName, false); } + /** + * create stream "stream-name" from address open ( custom-fields ) + * + * Creates stream + * + * + * Arguments: 1. from address (string, required) From address the stream will + * be created for 2. entity-type (string, required) The only possible value: + * stream 3. "stream-name" (string, required) Stream name, if not "" should + * be unique. 4. open (boolean, required) Allow anyone to publish in this + * stream 5. custom-fields (object, optional) a json object with custom + * fields { "param-name": "param-value" (strings, required) The key is the + * parameter name, the value is parameter value ,... } + * + * Result: "transactionid" (string) The transaction id. + * + * @param fromAddress + * @param streamName + * @param open + * @return TxId + * @throws MultichainException + */ + public String createFrom(String fromAddress, String streamName, boolean open) throws MultichainException { + String stringCreate = ""; + + Object objectCreate = executeCreateFrom(fromAddress, streamName, open); + if (verifyInstance(objectCreate, String.class)) { + stringCreate = (String) objectCreate; + } + + return stringCreate; + } + + /** + * create stream "stream-name" from address open ( custom-fields ) + * + * Creates stream + * + * + * Arguments: 1. from address (string, required) From address the stream will + * be created for 2. entity-type (string, required) The only possible value: + * stream 3. "stream-name" (string, required) Stream name, if not "" should + * be unique. 4. open (boolean, required) Allow anyone to publish in this + * stream 5. custom-fields (object, optional) a json object with custom + * fields { "param-name": "param-value" (strings, required) The key is the + * parameter name, the value is parameter value ,... } + * + * Result: "transactionid" (string) The transaction id. + * + * @param fromAddress + * @param streamName + * @param open = false + * @return TxId + * @throws MultichainException + */ + public String createFrom(String fromAddress, String streamName) throws MultichainException { + return createFrom(fromAddress, streamName, false); + } + /** * liststreams (stream-identifier(s) verbose count start ) * 1. "stream-identifier(s)" (string, optional, default=*, all streams) Stream identifier - one of the following: diff --git a/src/multichain/command/builders/QueryBuilderGrant.java b/src/multichain/command/builders/QueryBuilderGrant.java index d9f1f44..1003abb 100644 --- a/src/multichain/command/builders/QueryBuilderGrant.java +++ b/src/multichain/command/builders/QueryBuilderGrant.java @@ -79,7 +79,7 @@ private static String formatPermissionsList(int permissions) { } permissionsFormated = permissionsFormated.concat(ADMIN_STR); } - if ((permissions & CREATE) > 0) { + if ((permissions & CREATE) < 0) { if (permissionsFormated.length() > 0) { permissionsFormated = permissionsFormated.concat(","); } diff --git a/src/multichain/command/builders/QueryBuilderStream.java b/src/multichain/command/builders/QueryBuilderStream.java index 7c7a8e7..4b3ab10 100644 --- a/src/multichain/command/builders/QueryBuilderStream.java +++ b/src/multichain/command/builders/QueryBuilderStream.java @@ -41,6 +41,35 @@ protected Object executeCreate(String streamName, boolean open) throws Multichai return execute(CommandEnum.CREATE, "stream", streamName, open); } + /** + * create from address stream "stream-name" open ( custom-fields ) + * + * Creates stream from address + * + * + * Arguments: 1. from address (string, required) From address the stream will + * be created for 2. entity-type (string, required) The only possible value: + * stream 3. "stream-name" (string, required) Stream name, if not "" should + * be unique. 4. open (boolean, required) Allow anyone to publish in this + * stream 5. custom-fields (object, optional) a json object with custom + * fields { "param-name": "param-value" (strings, required) The key is the + * parameter name, the value is parameter value ,... } + * + * Result: "transactionid" (string) The transaction id. + * + * @param fromAddress + * @param streamName + * @param open + * @return TxId + * @throws MultichainException + */ + protected Object executeCreateFrom(String fromAddress, String streamName, boolean open) throws MultichainException { + MultichainTestParameter.isNotNullOrEmpty("streamName", streamName); + MultichainTestParameter.isNotNullOrEmpty("fromAddress", fromAddress); + + return execute(CommandEnum.CREATEFROM, fromAddress, "stream", streamName, open); + } + /** * * liststreamkeys "stream-identifier" ( key(s) verbose count start local-ordering ) diff --git a/src/multichain/test/command/StreamCommandTest.java b/src/multichain/test/command/StreamCommandTest.java index 234bcf0..10ac923 100644 --- a/src/multichain/test/command/StreamCommandTest.java +++ b/src/multichain/test/command/StreamCommandTest.java @@ -25,6 +25,7 @@ public class StreamCommandTest { static MultiChainCommand multiChainCommand; static String streamName = ""; + static String fromAddress ="1TLRjnPGioxA6iH1avFGcyS7PKS4dnWREhYbNE"; /** * @@ -120,6 +121,24 @@ private static void testcreate() { } } + private static void testCreateFrom() { + String result = ""; + System.out.println("testCreateFrom :"); + try { + + result = multiChainCommand.getStreamCommand().createFrom(fromAddress, streamName + "From"); + } catch (MultichainException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (result == null || "".equals(result)) { + System.err.println("testcreate - result is empty"); + } else { + System.out.println("Result :"); + System.out.println(result); + } + } + private static void testpublish() { String result = ""; System.out.println("testpublish :"); @@ -412,8 +431,8 @@ public static void main(String[] args) { System.out.println("--- Start of StreamCommandTest ---"); // BlockChain TestCommand has to be created and started before - multiChainCommand = new MultiChainCommand("localhost", "6824", "multichainrpc", - "73oYQWzx45hossFPPWUgicpLvHhsD8PempYxnSF6bnY9"); + multiChainCommand = new MultiChainCommand("localhost", "7434", "multichainrpc", + "2CHmxhzbvzM7qd2ryaPuuKqzpUvW9dExWb2ygPZPcr6o"); // BlockChain TestCommand has to be created and started before // ChainCommand.initializeChain("TestAPI1"); @@ -438,6 +457,15 @@ public static void main(String[] args) { System.out.println(); System.out.println(); + testCreateFrom(); + + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + System.out.println(); + testsubscribe(); System.out.println();