+ Reply to Thread
Results 1 to 7 of 7

Thread: Is there a way to determine if an extensionBoundUserServerVariable exists?

  1. #1
    Senior Member
    Join Date
    Aug 2010
    Posts
    223
    Thanks
    24
    Thanked 9 Times in 9 Posts

    Is there a way to determine if an extensionBoundUserServerVariable exists?

    There doesn't seem to be a doesExtensionBoundUserServerVariableExist function (Which would be a travesty of function naming in any case), so what is the way of determining if one exists? Is getExtensionBoundUserServerVariable's returned ExtensionBoundUserServerVariableResponse object's isSuccess() supposed to provide this functionality? I tried this, and got a lot of null pointer exceptions (Seemingly it returned isSuccess() == true, but getValue() == null...)
    I mean, sure, I can do a mess with try..catch, but a neater way would be cool...
    Last edited by tcarr; 07-06-2011 at 02:02 PM. Reason: fixed for next release, changed prefix

  2. #2
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,214
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    I'm going to add a ticket to our system and get back to you on this.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  3. #3
    Senior Member
    Join Date
    Aug 2010
    Posts
    223
    Thanks
    24
    Thanked 9 Times in 9 Posts
    Thanks.
    It very much looks like a problem in your API (Or my misunderstanding the purpose of the isSuccess() function of the ExtensionBoundUserServerVariableResponse class). I have this code:
    Code:
    userData stuff;
    ExtensionBoundUserServerVariableResponse r = getApi().getExtensionBoundUserServerVariable(userName, "Stuff");
    if(r.isSuccess()) {
          stuff = (userData) r.getValue();
    } else {
           System.out.println("Nope");
           return;
    }
    if(stuff == null) {
            System.out.println("Um...");
    }
    "Stuff" is a nonexistent ExtensionBoundUserServerVariable. r.isSuccess() returns true, and "Um..." is traced.
    I therefore am left wondering under what circumstances isSuccess() will return false? I suspect this is an API bug.

  4. #4
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,214
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    I have the same suspicion. Odds are good this will be a bug that I will be able to fix however, after I'm back at my desk.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  5. The Following User Says Thank You to tcarr For This Useful Post:

    joseph (07-05-2011)

  6. #5
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,214
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    I'm looking at this now, and the testing code I have for the various types of variables all uses this pattern:
    Code:
            UserServerVariableResponse rousv = getApi().getUserServerVariable(userName, "usv");
            if (rousv != null) {
                getApi().getLogger().debug("usv = " + rousv.getValue().toString());
            } else {
                getApi().getLogger().debug("usv is NULL!");
            }
    I don't think I've ever seen a case where the response is not null (so that I could use isSuccess) but the value is null. Can you give me a code snippet for how you are setting your variable?
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  7. #6
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,214
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    I found the ES5 code that sets isSuccess. What it does is set isSuccess if the user object is found. It doesn't check whether that user has THAT particular variable, which is why you are getting isSuccess = true but the value is null.

    I'll go ahead and add a check for the variable existing, since that seems to be more useful than returning a success when the value is null.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  8. #7
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,214
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    It's working now, and will be part of the next release. Example snippet from an extension for one of the tests (other one uses same pattern). We shouldn't need to test for the response itself being null, because it should never be null, but this is my "test to make sure the api works" code, so I'm leaving that in, just in case something breaks in the future. The testing code is from the userDidLogin method of a login event handler.
    Code:
            ExtensionBoundUserServerVariableResponse  er = getApi().getExtensionBoundUserServerVariable(userName, "null");
            if (er != null) {
                if (er.isSuccess()) {
                    getApi().getLogger().debug("er = " + er.getValue().toString());
                } else {
                    getApi().getLogger().debug("er success FALSE: ");
                    Collection<ErrorType> errors = er.getErrors();
                    for (ErrorType error : errors) {
                        getApi().getLogger().debug("\t" + error.toString());
                    }
                }
                
            } else {
                getApi().getLogger().debug("er is NULL!");
            }
    Example log:
    Code:
    2011-Jul-06 08:54:36:239 [worker-17 BinaryTCP-0] DEBUG Extensions.LoginEventHandler.EventHandlers.LoginEventHandlerExample  - rousv3 success FALSE: 
    2011-Jul-06 08:54:36:240 [worker-17 BinaryTCP-0] DEBUG Extensions.LoginEventHandler.EventHandlers.LoginEventHandlerExample  - 	UserVariableDoesNotExist
    2011-Jul-06 08:54:36:240 [worker-17 BinaryTCP-0] DEBUG Extensions.LoginEventHandler.EventHandlers.LoginEventHandlerExample  - er success FALSE: 
    2011-Jul-06 08:54:36:240 [worker-17 BinaryTCP-0] DEBUG Extensions.LoginEventHandler.EventHandlers.LoginEventHandlerExample  - 	UserVariableDoesNotExist
    I assume that it's better to just use UserVariableDoesNotExist for all of the various types of user variables than to have to add additional ErrorTypes.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts