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

Java Lab: add helper to get all project files #44871

Merged
merged 5 commits into from Feb 18, 2022
Merged

Conversation

molly-moen
Copy link
Contributor

@molly-moen molly-moen commented Feb 16, 2022

As part of the decoupling Javabuilder from Dashboard work, we will be sending all files relating to a Java Lab project before we run student code. While the exact format of this request has not been decided, we know we want to gather all the files in order to send them over. This PR adds a helper module which gets all the files and returns them as a hash. The format of the hash is:

{
  "sources": {"main.json": <main source file for a project>, "grid.txt": <serialized maze if it exists>},
  "assets": {"asset_name_1": <asset_value>, ...}
  "validation": <all validation code for a project, in json format>
}

Links

Testing story

I tested this using the ruby console against java lab projects that had assets, validation and/or a maze. I did not add a unit test for this, as this helper just calls out to different existing Buckets and basic level operations. In order to unit test this we would need to write a lot of mocked code and all we would be testing is that the different mocks got called, which didn't seem worth it. It also didn't seem worth it to verify the format of the result, since that format will most likely change.

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@molly-moen molly-moen requested a review from a team February 16, 2022 19:45
Copy link
Contributor

@sanchitmalhotra126 sanchitmalhotra126 left a comment

Choose a reason for hiding this comment

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

Nice, this looks good! A few comments, but this approach should work well for either solution we end up using (uploading files separately or as a single zip file)

all_files = {}
# get sources file
source_data = SourceBucket.new.get(channel_id, "main.json")
# Note: we can call .string on this value (and all other values for files) to get the raw string.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice - for reference, I'm looking into zipping files in rails right now, and passing a string value for each file seems to be the easiest option, so this will work well!

assets[friendly_name] = asset.get.body
end
end
# get level assets
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we may want to switch the order here and fetch starter assets after user assets - we currently have logic (both in Javabuilder and in the asset manager I believe) that if a starter asset file and a user asset file have the same name, we use the starter asset file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call out, will reverse this

# "main.json": <main source file for a project>
# "assets": {"asset_name_1": <asset_value>, ...}
# "validation": <all validation code for a project, in json format>
# "maze": <serialized maze if it exists>
Copy link
Contributor

Choose a reason for hiding this comment

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

So I was originally thinking that we'd store both main.json and the maze file in the same sources/ folder. My thinking was that if we eventually have other level content, then it could all just reside in sources. That being said though, the maze file isn't really a source file so I can also see a case for it being in its own directory. I'm fine with this being separate, we'll just have to fetch it accordingly in Javabuilder.

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 don't have a strong preference here. Would it be better to do the below? That way we have 3 clear categories instead of main.json being an outlier:

{
  "sources": {"main.json": "...", "grid.txt": "..."},
  "assets": {...},
  "validation": {...}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm yeah, I think having three categories is clearer and more extensible if we want to add more to sources down the line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 will update

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

# get maze file
serialized_maze = level.try(:get_serialized_maze)
if serialized_maze
all_files["maze"] = StringIO.new(serialized_maze.to_s)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to call to_json first on the maze file? That's what I was doing in my prototype, but not sure if it's necessary for javabuilder to parse it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like both to_json and to_s do the same thing. The maze is an array so it seems it works either way.

Copy link
Contributor

@sanchitmalhotra126 sanchitmalhotra126 left a comment

Choose a reason for hiding this comment

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

LGTM!

@molly-moen molly-moen merged commit 13cec30 into staging Feb 18, 2022
@molly-moen molly-moen deleted the javalab-get-files branch February 18, 2022 19:06
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.

None yet

2 participants