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

Compression Service #239

Closed
wants to merge 22 commits into from
Closed

Compression Service #239

wants to merge 22 commits into from

Conversation

thehabes
Copy link
Member

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.

@thehabes thehabes linked an issue Jan 31, 2022 that may be closed by this pull request
@thehabes thehabes self-assigned this Jan 31, 2022
Copy link
Member

@cubap cubap left a 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 =
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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 @@
/*
Copy link
Member

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"
Copy link
Member

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

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.

Copy link
Member

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

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

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

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;
Copy link
Member

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.

@cubap cubap closed this Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

?compress (efficient document)
2 participants