-
Notifications
You must be signed in to change notification settings - Fork 26
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
Fixed the object mask to work with result limit. #54
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
/** Object mask parameter. See http://sldn.softlayer.com/article/Object-Masks */ | ||
public class Mask { | ||
|
@@ -44,7 +45,26 @@ protected String getMask() { | |
|
||
@Override | ||
public String toString() { | ||
return toString(new StringBuilder()).toString(); | ||
String objectMask = new String(); | ||
String builtedMask = toString(new StringBuilder()).toString(); | ||
if(builtedMask.contains("[")){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand what this code is trying to do, can you provide an example Mask that would trigger the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I´m using this example code: Account.Service accountService = Account.service(client); accountService.withMask().blockDeviceTemplateGroups().id(); List result = accountService.getBlockDeviceTemplateGroups(); For the conditional if(builtedMask.contains("["))is when I use more than one mask like above objectMask example. The method toString() of the class Mask return the value like this: blockDeviceTemplateGroups[id, blockDevices.diskImage.type, status.keyName] with this data the objectMask will be building to send the request, when the request is sending like this without to put the getObject option between the accountService and getBlockDeviceTemplateGroups() method the response will be that the blockDeviceTemplateGroups is not recognized as a value for the objectMask and the service. It is for that I implemented this code to remove the value blockDeviceTemplateGroups to send the correct objectMask without using getObject for the method getBlockDeviceTemplateGroups(). The result for the conditional if() will be: id, blockDevices.diskImage.type, status.keyName For the else branch is for one mask, like this example: accountService.withMask().blockDeviceTemplateGroups().status().keyName(); The method toString() will return like this: blockDeviceTemplateGroups.status.keyName And with this branch else the result will be: status.keyName There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, that helps me understand what is going on a lot better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm glad to hear that, now we can do the request using objectMask and resultLimit at the same time. |
||
String [] mask = builtedMask.split(Pattern.quote("[")); | ||
for (int count = 0; count < mask.length; count ++ ) { | ||
if (count != 0){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could change the for loop to just start at 1 instead of 0, and remove this if statement |
||
objectMask = new StringBuilder().append(objectMask).append(mask[count]).toString(); | ||
} | ||
} | ||
} | ||
else { | ||
String [] mask = builtedMask.split(Pattern.quote(".")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this doesn't quite work when there is only 1 item in the mask, as seen in the failed unit test. |
||
for (int count = 0; count < mask.length; count ++ ) { | ||
if (count != 0){ | ||
objectMask = new StringBuilder().append(objectMask).append(mask[count]).append(".").toString(); | ||
} | ||
} | ||
} | ||
String resultMask = objectMask.substring(0, objectMask.length()-1); | ||
return resultMask; | ||
} | ||
|
||
/** Append this mask's string representation to the given builder and return it */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be "builtMask"