-
Notifications
You must be signed in to change notification settings - Fork 2
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
Compression Service #239
Compression Service #239
Conversation
…ruction, it's either naive or elegant.
…rd choice for these keys and perhaps ENUM them.
… remove no matter what.
… remove no matter what.
… remove no matter what.
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.
Commented only, since you said you were still running through it.
//Anything else has to be provided. Keys to keep can be provided. | ||
|
||
//These are keys that we want to make sure stay with the JSONObject. | ||
private final String[] primitiveKeys = |
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.
I think the compressed object is not going to have an allowlist for properties because it is too opinionated. MAybe we just need more use cases described for these all.
Map<String, String[]> parameters = request.getParameterMap(); //Get these from the URL | ||
System.out.println("Make a new controller..."); | ||
Controller c = new Controller(jo, parameters); | ||
//By passing in an object and the parameters of services to do to it, the controller now has the manipulated document. |
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.
This comment is not exactly right. The call right after this creates the manipulated document, since that may not be an instantaneous thing.
//By passing in an object and the parameters of services to do to it, the controller now has the manipulated document. | ||
jo = c.getServicedDocument(); | ||
System.out.println("JSON has been serviced..."); | ||
//Write that manipulated document out. |
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.
// or the original, if something went wrong
@@ -0,0 +1,41 @@ | |||
/* |
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.
This isn't really needed in this PR except to see where the rest of this fits together.
"name", | ||
"summary", | ||
"description", | ||
"@context" |
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.
maybe title
value
@value
and the itemList things like items
ItemListElement
members
? I'm not sure what fits best here.
*/ | ||
public JSONObject compress(JSONObject toCompress, Set<String> keysToKeep){ | ||
keysToKeep.addAll(primitiveKeys); | ||
Iterator<String> keys = toCompress.keySet().iterator(); |
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.
why not keys()
like above? That would solve the casting to Object and the operation error you had below, I am fairly sure.
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.
:60
* @return toCompress once the keys are removed, or the original if there was an error. | ||
*/ | ||
public JSONObject compress(JSONObject toCompress, Set<String> keysToKeep){ | ||
keysToKeep.addAll(primitiveKeys); |
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.
after this line, why is it any different than the method above?
.collect(Collectors.toSet()); | ||
System.out.println("Flags detected, see below"); | ||
System.out.println(validFlags.toString()); | ||
if (validFlags.size()>0) |
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.
Probably clearer to do this as !validFlags.isEmpty()
System.out.println("Controller detected the compress service"); | ||
Set<String> keysToKeep = new HashSet<>(Arrays.asList(params.get("keysToKeep[]"))); | ||
System.out.println("Checking for keysToKeep..."); | ||
System.out.println(keysToKeep.toString()); |
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.
This out doesn't error if there are no keysToKeep
?
|
||
public JSONObject getOriginalDocument(){ | ||
return serviced_document; |
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.
almost. This cut and paste needs one minor change.
Thinking the goal is JSON in, less JSON out. We have a default idea of what keys MUST be removed and an idea of what keys SHOULD be left alone. You can tell the class what keys to leave alone, not what keys to remove.