Search in sources :

Example 71 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException 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 72 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException 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 73 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException 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 74 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException 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)

Example 75 with ClientException

use of edu.umass.cs.gnscommon.exceptions.client.ClientException in project GNS by MobilityFirst.

the class AliasLookup method parse.

@Override
public void parse(String commandText) throws Exception {
    try {
        StringTokenizer st = new StringTokenizer(commandText.trim());
        if (st.countTokens() != 1) {
            wrongArguments();
            return;
        }
        String guid = st.nextToken();
        GNSClientCommands gnsClient = module.getGnsClient();
        JSONObject entityInfo = gnsClient.lookupGuidRecord(guid);
        String alias = entityInfo.getString(GNSProtocol.GUID_RECORD_NAME.toString());
        console.printString(guid + " has alias " + alias);
        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) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) IOException(java.io.IOException) ClientException(edu.umass.cs.gnscommon.exceptions.client.ClientException)

Aggregations

ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)239 IOException (java.io.IOException)215 Test (org.junit.Test)134 JSONException (org.json.JSONException)126 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)125 RandomString (edu.umass.cs.gnscommon.utils.RandomString)113 JSONArray (org.json.JSONArray)74 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)71 JSONObject (org.json.JSONObject)59 GNSClientCommands (edu.umass.cs.gnsclient.client.GNSClientCommands)40 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)37 StringTokenizer (java.util.StringTokenizer)30 EncryptionException (edu.umass.cs.gnscommon.exceptions.client.EncryptionException)23 BasicGuidEntry (edu.umass.cs.gnsclient.client.util.BasicGuidEntry)20 FieldNotFoundException (edu.umass.cs.gnscommon.exceptions.client.FieldNotFoundException)19 FileNotFoundException (java.io.FileNotFoundException)18 InternalRequestException (edu.umass.cs.gnscommon.exceptions.server.InternalRequestException)15 ResponseCode (edu.umass.cs.gnscommon.ResponseCode)13 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)13 InvalidKeyException (java.security.InvalidKeyException)12