Issue 208 project submissions scoring ui#218
Issue 208 project submissions scoring ui#218susham wants to merge 5 commits intoJoyOfCodingPDX:issue-208-project-submissions-scoring-uifrom susham:issue-208-project-submissions-scoring-ui
Conversation
…s-scoring-ui Issue 208 project submissions scoring ui
…s-scoring-ui Get upstream changes from Dave
…s-scoring-ui Get latest changes from DavidWhitlock's issue 208 branch
DavidWhitlock
left a comment
There was a problem hiding this comment.
Thank you for making these changes, @susham. Overall, they are very good. I have some suggestions that I think would improve the code. After we discuss those some more, I'd be happy to merge this code into my repository.
| private Double score; | ||
| private String studentName; | ||
| private Date submissionTime; | ||
| private Date gradedTime; |
There was a problem hiding this comment.
Oh. Good call. Thank you for adding this.
| public ProjectSubmissionOutputFileParser(Reader source) { | ||
|
|
||
| public ProjectSubmissionOutputFileParser(Reader source) { | ||
| if(source != null) { |
There was a problem hiding this comment.
If source is null, it's probably better to throw a NullPointerException.
| return date; | ||
| } | ||
|
|
||
| private BufferedReader bufferedReader=null; |
There was a problem hiding this comment.
Please declare field at the beginning of the class before the constructor and methods.
There was a problem hiding this comment.
Also, since bufferedReader is always initialized in the constructor and is never modified, you can make the field final.
| } | ||
|
|
||
| private BufferedReader bufferedReader=null; | ||
| private ProjectSubmission projectSubmission=null; |
There was a problem hiding this comment.
You don't need to initial this field to null. That is the default value it will receive.
| } | ||
|
|
||
| } catch (IOException e) { | ||
| e.printStackTrace(); |
There was a problem hiding this comment.
Please don't "swallow" this exception. Instead, declare that this method throws an IOException and let the calling code deal with it.
| projectSubmission = new ProjectSubmission(); | ||
| String fileContents=null; | ||
|
|
||
| try { |
There was a problem hiding this comment.
You want to be sure to close the BufferedReader when your done with it. I recommend using the "enhanced try/catch" syntax described here:
https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
| try { | ||
| while((fileContents= bufferedReader.readLine()) !=null) { | ||
| fileContents=fileContents.trim(); | ||
| if(fileContents.contains("CS410J")){ // fileContents has the student Id and Project Name. |
There was a problem hiding this comment.
At the moment, my grading scripts don't differentiate between the undergraduate and graduate sections of the course. So, it is fine to have this hard-coded "magic string" of "CS410J".
| fileContents=fileContents.trim(); | ||
| if(fileContents.contains("CS410J")){ // fileContents has the student Id and Project Name. | ||
| String[] splitContent=fileContents.split(Pattern.quote(".")); | ||
| projectSubmission.setProjectName(splitContent[splitContent.length -1]); |
There was a problem hiding this comment.
If the output file being parsed is bogus, we'll end up with ArrayIndexOutOfBoundsExceptions, but I don't know what we could do about it. Maybe an answer will be become apparent later as we build more of the class..
There was a problem hiding this comment.
Yes, bogus output file is always going to be an issue. probably I can write a test case to handle the bogus output file.
As of the first iteration, handling this scenario should help to move on. But, we need to find out a better way or use a different type.
|
|
||
| } | ||
|
|
||
| if(fileContents.contains("Submitted by")){ //fileContents has StudentName |
There was a problem hiding this comment.
I recommend that you move "Submitted by" into a constant (a private static final field whose name is ALL_CAPS) so that this "magic" string doesn't appear twice.
There was a problem hiding this comment.
Do you think, its better to create final fields whose names are ALL_CAPS, so that the magic string doesn't appear twice?
There was a problem hiding this comment.
Yes. That way, if the "magic" string ever changes in the output file, we only need to change one place in the code.
| projectSubmission.setGradedTime(parseGradingTime(splitContent[splitContent.length -1].trim())); | ||
| } | ||
| if(fileContents.contains("out of")){ //fileContents has Total Points and Awarded Points | ||
| String [] splitContent=fileContents.split("out of"); |
There was a problem hiding this comment.
This works, but you might also want to consider using two "capturing groups" in a regular expression:
https://alvinalexander.com/blog/post/java/how-extract-multiple-groups-patterns-string-regex
There was a problem hiding this comment.
Is it possible to create a regexp to get the left and right side of the matched string? Right now, I am able to get both the left and right sub string of the matched string using a separate Regexp
|
I have made changes as per the code review. Do I have to raise another pull request, to reflect my changes? |
DavidWhitlock
left a comment
There was a problem hiding this comment.
Thank you for addressing my earlier feedback. I had some questions about the most recent changes, though.
| * Created by sushamkumar on 9/1/17. | ||
| */ | ||
| public class InvalidFileContentException extends Exception { | ||
| public InvalidFileContentException() { super("Out file is corrupted"); } |
There was a problem hiding this comment.
Is this constructor ever called? If not, let's delete it.
There was a problem hiding this comment.
No, this constructor is never called for now. But, I have kept this so that If there isn't any message to provide then we could use this constructor. I will remove this, so that custom message makes more sense.
|
|
||
| if(fileContents.contains("out of")){ //fileContents has Total Points and Awarded Points | ||
|
|
||
| Pattern rightpattern = Pattern.compile("(?<=out of).*"); |
There was a problem hiding this comment.
I thought there was a way to go this with a single regular expression. But maybe not.
|
|
||
| private void convertOutFileToXml(File outFile) { | ||
|
|
||
| File xmlFile = null; |
There was a problem hiding this comment.
Is the only change that you made to this method is to move this variable declaration to the top? If so, I'm not sure if that's necessary. This isn't C where you need to declare all variables at the beginning of a function. In Java, it's preferred to declare variables close to where they are used.
There was a problem hiding this comment.
I had to move the variable declaration to the top, because the variable scope wasn't sufficient. That was because of the try, catch block. I think, I have to refactor the code to make the unit test cases pass.
| submission = parser.parse(); | ||
|
|
||
| } catch (FileNotFoundException e) { | ||
| logger.error("Could not file file " + outFile, e); |
There was a problem hiding this comment.
I liked having this specific error message when the file could not be found.
| file.line("***** Test 1: No arguments"); | ||
|
|
||
| ProjectSubmission submission = parse(file); | ||
| ProjectSubmission submission = null; |
There was a problem hiding this comment.
Do you think that splitting the declaration and assignment make the code easier to read? I'm not so sure.
| projectSubmission= parser.parse(); | ||
|
|
||
| parser.parse(); | ||
| } catch (ParseException e) { |
There was a problem hiding this comment.
You might as well have the parse() method declare that it should throw the ParseException.
| parser.parse(); | ||
| } catch (ParseException e) { | ||
| e.printStackTrace(); | ||
| } catch (IOException e) { |
There was a problem hiding this comment.
I'm not sure that this is what you want to do. Yes, the stack trace will be printed, but null will be returned from the method. That will probably cause the test to fail, but perhaps not in the way that anyone would expect.
|
Also, @susham, I noticed that the Travis build failed. It looks like there was a problem with the |
For retrieving the student Id and Project Name, I think method I have written checks for the string CS410. I think, this should be changed. As the summer term had both CS410 and CS510.