Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Queue
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EIP
Labrador
Queue
Commits
feda079e
Verified
Commit
feda079e
authored
Oct 31, 2019
by
Otto Visser
Browse files
Options
Downloads
Patches
Plain Diff
Attempt at refactoring/bugfixing for
#264
parent
d87a4299
No related branches found
No related tags found
2 merge requests
!201
Development
,
!195
Resolve "ArrayIndexOutOfBoundsException with incorrect CSV input"
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/nl/tudelft/ewi/queue/helper/CsvUserHelper.java
+10
-13
10 additions, 13 deletions
src/main/java/nl/tudelft/ewi/queue/helper/CsvUserHelper.java
src/main/java/nl/tudelft/ewi/queue/service/CourseService.java
+3
-0
3 additions, 0 deletions
...main/java/nl/tudelft/ewi/queue/service/CourseService.java
with
13 additions
and
13 deletions
src/main/java/nl/tudelft/ewi/queue/helper/CsvUserHelper.java
+
10
−
13
View file @
feda079e
...
@@ -15,8 +15,7 @@
...
@@ -15,8 +15,7 @@
*/
*/
package
nl.tudelft.ewi.queue.helper
;
package
nl.tudelft.ewi.queue.helper
;
import
java.io.IOException
;
import
java.io.*
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Scanner
;
import
java.util.Scanner
;
...
@@ -45,20 +44,18 @@ public class CsvUserHelper {
...
@@ -45,20 +44,18 @@ public class CsvUserHelper {
}
}
public
static
ArrayList
<
CsvUserHelper
>
readCsv
(
MultipartFile
csvFile
)
throws
IOException
{
public
static
ArrayList
<
CsvUserHelper
>
readCsv
(
MultipartFile
csvFile
)
throws
IOException
{
if
(
csvFile
.
isEmpty
())
return
null
;
InputStream
content
=
csvFile
.
getInputStream
();
InputStream
content
=
csvFile
.
getInputStream
();
Scanner
scanner
=
new
Scanner
(
content
).
useDelimiter
(
"\\A"
);
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
content
)
);
ArrayList
<
CsvUserHelper
>
csvUserHelpersSet
=
new
ArrayList
<>();
ArrayList
<
CsvUserHelper
>
csvUserHelpersSet
=
new
ArrayList
<>();
String
csv
=
""
;
String
line
;
if
(
scanner
.
hasNext
())
{
while
((
line
=
reader
.
readLine
())
!=
null
)
{
csv
=
scanner
.
next
();
// not accepting comma as we have students with a comma in their last name...
}
String
[]
currLine
=
line
.
split
(
"[;\t]"
);
String
[]
lines
=
csv
.
split
(
"\n"
);
for
(
String
line
:
lines
)
{
String
[]
currLine
=
line
.
split
(
","
);
if
(
currLine
[
1
].
contains
(
"\r"
))
{
currLine
[
1
]
=
currLine
[
1
].
substring
(
0
,
currLine
[
1
].
length
()
-
1
);
}
csvUserHelpersSet
.
add
(
new
CsvUserHelper
(
currLine
[
0
],
csvUserHelpersSet
.
add
(
new
CsvUserHelper
(
currLine
[
0
],
DefaultRole
.
valueOfExt
(
currLine
[
1
])));
DefaultRole
.
valueOfExt
(
currLine
[
1
])));
}
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/nl/tudelft/ewi/queue/service/CourseService.java
+
3
−
0
View file @
feda079e
...
@@ -95,6 +95,9 @@ public class CourseService {
...
@@ -95,6 +95,9 @@ public class CourseService {
public
void
addCourseStaff
(
MultipartFile
csv
,
Course
course
)
throws
IOException
{
public
void
addCourseStaff
(
MultipartFile
csv
,
Course
course
)
throws
IOException
{
ArrayList
<
CsvUserHelper
>
users
=
CsvUserHelper
.
readCsv
(
csv
);
ArrayList
<
CsvUserHelper
>
users
=
CsvUserHelper
.
readCsv
(
csv
);
if
(
null
==
users
)
return
;
for
(
CsvUserHelper
csvUser
:
users
)
{
for
(
CsvUserHelper
csvUser
:
users
)
{
User
staff
=
findUser
(
csvUser
.
getNetId
());
User
staff
=
findUser
(
csvUser
.
getNetId
());
Optional
<
Role
>
oldRole
=
staff
.
getRole
(
course
);
Optional
<
Role
>
oldRole
=
staff
.
getRole
(
course
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment