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
Conversation
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.
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. |
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.
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 |
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 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.
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.
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> |
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.
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.
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 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": {...}
}
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.
Hmm yeah, I think having three categories is clearer and more extensible if we want to add more to sources down the line.
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.
👍 will update
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.
done!
# get maze file | ||
serialized_maze = level.try(:get_serialized_maze) | ||
if serialized_maze | ||
all_files["maze"] = StringIO.new(serialized_maze.to_s) |
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.
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.
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.
Looks like both to_json
and to_s
do the same thing. The maze is an array so it seems it works either way.
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.
LGTM!
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:
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: