Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented createFrom stream command and fixed bug with create permissions #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions src/multichain/command/StreamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,73 @@ 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
*/
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:
Expand Down
2 changes: 1 addition & 1 deletion src/multichain/command/builders/QueryBuilderGrant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(",");
}
Expand Down
29 changes: 29 additions & 0 deletions src/multichain/command/builders/QueryBuilderStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
32 changes: 30 additions & 2 deletions src/multichain/test/command/StreamCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class StreamCommandTest {
static MultiChainCommand multiChainCommand;

static String streamName = "";
static String fromAddress ="1TLRjnPGioxA6iH1avFGcyS7PKS4dnWREhYbNE";

/**
*
Expand Down Expand Up @@ -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 :");
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand Down