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

Fixed the object mask to work with result limit. #54

Closed
Closed
Changes from 1 commit
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
22 changes: 21 additions & 1 deletion src/main/java/com/softlayer/api/Mask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be "builtMask"

if(builtedMask.contains("[")){
Copy link
Member

Choose a reason for hiding this comment

The 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 if(builtedMask.contains("[")){ branch and the else branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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();
accountService.withMask().blockDeviceTemplateGroups().blockDevices().diskImage().type();
accountService.withMask().blockDeviceTemplateGroups().status().keyName();

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that helps me understand what is going on a lot better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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){
Copy link
Member

Choose a reason for hiding this comment

The 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("."));
Copy link
Member

Choose a reason for hiding this comment

The 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 */
Expand Down