Search in sources :

Example 16 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class GroupMemberList method parse.

@Override
public void parse(String commandText) throws Exception {
    GNSClientCommands gnsClient = module.getGnsClient();
    try {
        StringTokenizer st = new StringTokenizer(commandText.trim());
        String groupGuid;
        switch(st.countTokens()) {
            case 0:
                groupGuid = module.getCurrentGuid().getGuid();
                break;
            case 1:
                groupGuid = st.nextToken();
                if (!StringUtil.isValidGuidString(groupGuid)) {
                    // We probably have an alias, lookup the GUID
                    groupGuid = gnsClient.lookupGuid(groupGuid);
                }
                break;
            default:
                wrongArguments();
                return;
        }
        console.printString("Members in group " + groupGuid);
        console.printNewline();
        JSONArray members = gnsClient.groupGetMembers(groupGuid, module.getCurrentGuid());
        for (int i = 0; i < members.length(); i++) {
            console.printString(i + ": " + members.getString(i));
            console.printNewline();
        }
    } catch (IOException | ClientException | JSONException e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 17 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class GroupMemberRemove method parse.

@Override
public void parse(String commandText) throws Exception {
    GNSClientCommands gnsClient = module.getGnsClient();
    try {
        StringTokenizer st = new StringTokenizer(commandText.trim());
        String groupGuid;
        switch(st.countTokens()) {
            case 1:
                groupGuid = module.getCurrentGuid().getGuid();
                break;
            case 2:
                groupGuid = st.nextToken();
                if (!StringUtil.isValidGuidString(groupGuid)) {
                    // We probably have an alias, lookup the GUID
                    groupGuid = gnsClient.lookupGuid(groupGuid);
                }
                break;
            default:
                wrongArguments();
                return;
        }
        String guidToRemove = st.nextToken();
        gnsClient.groupRemoveGuid(groupGuid, guidToRemove, module.getCurrentGuid());
        printString("GUID " + guidToRemove + " removed from group " + groupGuid + "\n");
    } catch (IOException | ClientException e) {
        printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 18 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class FieldRead method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        GNSClientCommands gnsClient = module.getGnsClient();
        StringTokenizer st = new StringTokenizer(commandText.trim());
        String guid;
        switch(st.countTokens()) {
            case 1:
                guid = module.getCurrentGuid().getGuid();
                break;
            case 2:
                guid = st.nextToken();
                if (!StringUtil.isValidGuidString(guid)) {
                    // We probably have an alias, lookup the GUID
                    guid = gnsClient.lookupGuid(guid);
                }
                break;
            default:
                wrongArguments();
                return;
        }
        String field = st.nextToken();
        String value = gnsClient.fieldRead(guid, field, module.getCurrentGuid());
        console.printString(value);
        console.printNewline();
    } catch (IOException | ClientException e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 19 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class FieldReadList method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        GNSClientCommands gnsClient = module.getGnsClient();
        StringTokenizer st = new StringTokenizer(commandText.trim());
        String guid;
        switch(st.countTokens()) {
            case 1:
                guid = module.getCurrentGuid().getGuid();
                break;
            case 2:
                guid = st.nextToken();
                if (!StringUtil.isValidGuidString(guid)) {
                    // We probably have an alias, lookup the GUID
                    guid = gnsClient.lookupGuid(guid);
                }
                break;
            default:
                wrongArguments();
                return;
        }
        String field = st.nextToken();
        JSONArray value = gnsClient.fieldReadArray(guid, field, module.getCurrentGuid());
        console.printString(value.toString());
        console.printNewline();
    } catch (IOException | ClientException e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) JSONArray(org.json.JSONArray) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Example 20 with GNSClientCommands

use of edu.umass.cs.gnsclient.client.GNSClientCommands in project GNS by MobilityFirst.

the class FieldUpdate method parse.

@Override
public void parse(String commandText) throws Exception {
    GNSClientCommands gnsClient = module.getGnsClient();
    try {
        StringTokenizer st = new StringTokenizer(commandText.trim());
        String guid;
        switch(st.countTokens()) {
            case 2:
                guid = module.getCurrentGuid().getGuid();
                break;
            case 3:
                guid = st.nextToken();
                if (!StringUtil.isValidGuidString(guid)) {
                    // We probably have an alias, lookup the GUID
                    guid = gnsClient.lookupGuid(guid);
                }
                break;
            default:
                wrongArguments();
                return;
        }
        String field = st.nextToken();
        String value = st.nextToken();
        gnsClient.fieldUpdate(guid, field, value, module.getCurrentGuid());
        console.printString("Value '" + value + "' written to field " + field + " for GUID " + guid);
        console.printNewline();
    } catch (IOException | ClientException e) {
        console.printString("Failed to access GNS ( " + e + ")\n");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) GNSClientCommands(edu.umass.cs.gnsclient.client.GNSClientCommands) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Aggregations

GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)70 IOException (java.io.IOException)55 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)50 StringTokenizer (java.util.StringTokenizer)35 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)28 JSONArray (org.json.JSONArray)13 JSONException (org.json.JSONException)11 DuplicateNameException (edu.umass.cs.gnscommon.exceptions.client.DuplicateNameException)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)10 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)9 JSONObject (org.json.JSONObject)9 InvalidKeyException (java.security.InvalidKeyException)8 SignatureException (java.security.SignatureException)8 GNSClient (edu.umass.cs.gnsclient.client.GNSClient)6 PublicKey (java.security.PublicKey)6 HashSet (java.util.HashSet)6 BeforeClass (org.junit.BeforeClass)6 RandomString (edu.umass.cs.gnscommon.utils.RandomString)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5