Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Softa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Meißner
Softa
Compare revisions
3d271a62d9d1113006aedf0aa6044d4778bf3308 to 7653d0380cd55590b7b7d904dd872a51279e7f97
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
meissnerfl73755/softa
Select target project
No results found
7653d0380cd55590b7b7d904dd872a51279e7f97
Select Git revision
Branches
master
musterloesung
Swap
Target
meissnerfl73755/softa
Select target project
meissnerfl73755/softa
1 result
3d271a62d9d1113006aedf0aa6044d4778bf3308
Select Git revision
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
finished printCanteens
· 11f797d0
Florian Meissner
authored
1 year ago
11f797d0
finished printMeals
· 7653d038
Florian Meissner
authored
1 year ago
7653d038
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/ohm/softa/a11/App.java
+52
-11
52 additions, 11 deletions
src/main/java/ohm/softa/a11/App.java
with
52 additions
and
11 deletions
src/main/java/ohm/softa/a11/App.java
View file @
7653d038
...
...
@@ -4,6 +4,7 @@ import ohm.softa.a11.openmensa.OpenMensaAPI;
import
ohm.softa.a11.openmensa.OpenMensaAPIService
;
import
ohm.softa.a11.openmensa.model.Canteen
;
import
ohm.softa.a11.openmensa.model.PageInfo
;
import
retrofit2.HttpException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
...
...
@@ -53,27 +54,52 @@ public class App {
}
private
static
void
printCanteens
()
{
System
.
out
.
print
(
"Fetching canteens ["
);
/* TODO fetch all canteens and print them to STDOUT
/* fetch all canteens and print them to STDOUT
* at first get a page without an index to be able to extract the required pagination information
* afterwards you can iterate the remaining pages
* keep in mind that you should await the process as the user has to select canteen with a specific id */
OpenMensaAPI
api
=
OpenMensaAPIService
.
getInstance
().
getOpenMensaAPI
();
var
response
=
api
.
getCanteens
();
var
response
=
openMensaAPI
.
getCanteens
();
try
{
var
pageInfo
=
PageInfo
.
extractFromResponse
(
response
.
get
());
var
first
Canteen
Page
=
response
.
get
().
body
();
var
firstPage
=
response
.
get
().
body
();
var
N
=
pageInfo
.
getTotalCountOfPages
();
var
canteens
=
IntStream
.
range
(
2
,
N
).
parallel
()
/*
var canteens = IntStream.range(2, N).parallel()
.mapToObj((n) -> api.getCanteens(n).join())
.flatMap(Collection::stream)
.
collect
(
Collectors
.
toList
());
canteens
.
addAll
(
0
,
firstCanteenPage
);
canteens
.
sort
(
Comparator
.
comparingInt
(
Canteen:
:
getId
));
//canteens = canteens.thenCombine(api.getCanteens(Integer.parseInt(pageN.get())), (l1, l2) -> Stream.concat(l1.parallelStream(), l2.parallelStream()))
canteens
.
forEach
((
c
)
->
System
.
out
.
println
(
c
.
toString
()));
.collect(Collectors.toList());*/
final
var
id
=
CompletableFuture
.
completedFuture
(
firstPage
);
var
request
=
IntStream
.
range
(
2
,
N
+
1
)
// one-indexed
.
mapToObj
(
openMensaAPI:
:
getCanteens
)
.
reduce
(
id
,
(
f1
,
f2
)
->
f1
.
thenCombine
(
f2
,
// lambda combining two lists
// cannot move to variable, because no templating and no type inference for lambdas
// fuck java
(
l1
,
l2
)
->
Stream
.
concat
(
l1
.
stream
(),
l2
.
stream
())
.
collect
(
Collectors
.
toList
()))
)
.
thenAccept
(
canteens
->
{
canteens
.
stream
()
.
sorted
(
Comparator
.
comparingInt
(
Canteen:
:
getId
))
.
forEach
(
System
.
out
::
println
);
System
.
out
.
println
(
pageInfo
.
getTotalCountOfItems
()
+
" <- Header | actual -> "
+
canteens
.
size
());
})
.
exceptionally
(
e
->
{
do
{
System
.
out
.
println
(
e
.
getMessage
());
e
=
e
.
getCause
();
}
while
(
e
!=
null
);
return
null
;
});
// lazy -> eager
request
.
join
();
}
catch
(
InterruptedException
|
ExecutionException
|
NumberFormatException
e
)
{
e
.
printStackTrace
();
System
.
out
.
println
(
"WHYYYYYYYYYYy!!!!"
);
...
...
@@ -84,6 +110,21 @@ public class App {
/* TODO fetch all meals for the currently selected canteen
* to avoid errors retrieve at first the state of the canteen and check if the canteen is opened at the selected day
* don't forget to check if a canteen was selected previously! */
if
(
currentCanteenId
==
-
1
)
{
System
.
out
.
println
(
"Error: no canteen selected"
);
return
;
}
openMensaAPI
.
getMeals
(
currentCanteenId
,
dateFormat
.
format
(
currentDate
.
getTime
()))
.
exceptionally
((
e
)
->
{
System
.
out
.
println
(
e
.
getMessage
());
if
(
e
instanceof
HttpException
)
System
.
out
.
println
(((
HttpException
)
e
).
response
());
return
List
.
of
();
})
.
thenAccept
(
meals
->
meals
.
forEach
(
System
.
out
::
println
))
.
join
();
}
/**
...
...
This diff is collapsed.
Click to expand it.