Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Riina Antikainen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 63e26a5f
authored
Dec 20, 2015
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Entering queue with all reserved but unlocked slots
1 parent
4c2e05a7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
8 deletions
code/moya-beans/ejbModule/fi/codecrew/moya/beans/map/QueueBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceSlotFacade.java
code/moya-database/src/main/java/fi/codecrew/moya/model/PlaceSlot.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/map/QueueBean.java
View file @
63e26a5
...
@@ -202,8 +202,11 @@ public class QueueBean implements QueueBeanLocal {
...
@@ -202,8 +202,11 @@ public class QueueBean implements QueueBeanLocal {
ret
=
queue
.
getEntry
(
user
);
ret
=
queue
.
getEntry
(
user
);
}
else
{
}
else
{
List
<
PlaceSlot
>
slots
=
slotfacade
.
findFreePlaceSlots
(
user
,
map
);
List
<
PlaceSlot
>
slots
=
slotfacade
.
findFreePlaceSlots
(
user
,
map
);
List
<
PlaceSlot
>
unlocked
=
slotfacade
.
findUnlockedPlaceslots
(
user
,
map
);
int
total
=
slots
.
size
()
+
unlocked
.
size
();
logger
.
info
(
"User {} not yet in queue. User has {} slots"
,
user
,
slots
.
size
());
logger
.
info
(
"User {} not yet in queue. User has {} slots"
,
user
,
slots
.
size
());
if
(
!
slots
.
isEmpty
()
&&
slots
.
size
()
>=
queue
.
getMinimumSlotsInQueue
())
{
if
(
total
>=
queue
.
getMinimumSlotsInQueue
())
{
ret
=
queue
.
enter
(
user
,
slots
);
ret
=
queue
.
enter
(
user
,
slots
);
}
}
}
}
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceSlotFacade.java
View file @
63e26a5
...
@@ -19,7 +19,6 @@
...
@@ -19,7 +19,6 @@
package
fi
.
codecrew
.
moya
.
facade
;
package
fi
.
codecrew
.
moya
.
facade
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
...
@@ -131,8 +130,7 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
...
@@ -131,8 +130,7 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
}
}
private
static
List
<
Predicate
>
getUnusedSlotPredicates
(
CriteriaBuilder
cb
,
Root
<
PlaceSlot
>
root
,
Product
prod
,
boolean
paidOnly
)
private
static
List
<
Predicate
>
getUnusedSlotPredicates
(
CriteriaBuilder
cb
,
Root
<
PlaceSlot
>
root
,
Product
prod
,
boolean
paidOnly
)
{
{
Path
<
Bill
>
bill
=
root
.
get
(
PlaceSlot_
.
bill
);
Path
<
Bill
>
bill
=
root
.
get
(
PlaceSlot_
.
bill
);
List
<
Predicate
>
preds
=
new
ArrayList
<>();
List
<
Predicate
>
preds
=
new
ArrayList
<>();
...
@@ -146,8 +144,7 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
...
@@ -146,8 +144,7 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
Path
<
Date
>
billexp
=
bill
.
get
(
Bill_
.
expires
);
Path
<
Date
>
billexp
=
bill
.
get
(
Bill_
.
expires
);
preds
.
add
(
cb
.
or
(
preds
.
add
(
cb
.
or
(
cb
.
isNull
(
billexp
),
cb
.
isNull
(
billexp
),
cb
.
greaterThan
(
billexp
,
new
Date
())
cb
.
greaterThan
(
billexp
,
new
Date
())));
));
}
}
// Check that slot is not used
// Check that slot is not used
...
@@ -185,8 +182,7 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
...
@@ -185,8 +182,7 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
Path
<
Date
>
billexp
=
bill
.
get
(
Bill_
.
expires
);
Path
<
Date
>
billexp
=
bill
.
get
(
Bill_
.
expires
);
preds
.
add
(
cb
.
or
(
preds
.
add
(
cb
.
or
(
cb
.
isNull
(
billexp
),
cb
.
isNull
(
billexp
),
cb
.
greaterThan
(
billexp
,
new
Date
())
cb
.
greaterThan
(
billexp
,
new
Date
())));
));
}
}
q
.
where
(
preds
.
toArray
(
new
Predicate
[
preds
.
size
()]));
q
.
where
(
preds
.
toArray
(
new
Predicate
[
preds
.
size
()]));
...
@@ -195,6 +191,30 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
...
@@ -195,6 +191,30 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
return
count
;
return
count
;
}
}
public
List
<
PlaceSlot
>
findUnlockedPlaceslots
(
EventUser
user
,
EventMap
map
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
PlaceSlot
>
q
=
cb
.
createQuery
(
PlaceSlot
.
class
);
Root
<
PlaceSlot
>
root
=
q
.
from
(
PlaceSlot
.
class
);
Path
<
Bill
>
bill
=
root
.
get
(
PlaceSlot_
.
bill
);
final
List
<
Predicate
>
preds
=
new
ArrayList
<>();
preds
.
add
(
cb
.
equal
(
bill
.
get
(
Bill_
.
user
),
user
));
preds
.
add
(
cb
.
isNotNull
(
bill
.
get
(
Bill_
.
paidDate
)));
preds
.
add
(
cb
.
isNotNull
(
root
.
get
(
PlaceSlot_
.
used
)));
preds
.
add
(
cb
.
isNull
(
root
.
get
(
PlaceSlot_
.
place
).
get
(
Place_
.
group
)));
Subquery
<
Integer
>
mapProdq
=
q
.
subquery
(
Integer
.
class
);
Root
<
EventMap
>
mapProdqRoot
=
mapProdq
.
from
(
EventMap
.
class
);
mapProdq
.
select
(
mapProdqRoot
.
join
(
EventMap_
.
places
).
get
(
Place_
.
product
).
get
(
Product_
.
id
));
mapProdq
.
where
(
cb
.
equal
(
mapProdqRoot
,
map
));
mapProdq
.
distinct
(
true
);
preds
.
add
(
root
.
get
(
PlaceSlot_
.
product
).
get
(
Product_
.
id
).
in
(
mapProdq
));
q
.
where
(
preds
.
toArray
(
new
Predicate
[
preds
.
size
()]));
return
getEm
().
createQuery
(
q
).
getResultList
();
}
public
List
<
PlaceSlot
>
findFreePlaceSlots
(
EventUser
user
,
EventMap
map
)
{
public
List
<
PlaceSlot
>
findFreePlaceSlots
(
EventUser
user
,
EventMap
map
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
PlaceSlot
>
q
=
cb
.
createQuery
(
PlaceSlot
.
class
);
CriteriaQuery
<
PlaceSlot
>
q
=
cb
.
createQuery
(
PlaceSlot
.
class
);
...
...
code/moya-database/src/main/java/fi/codecrew/moya/model/PlaceSlot.java
View file @
63e26a5
...
@@ -51,6 +51,14 @@ public class PlaceSlot extends GenericEntity {
...
@@ -51,6 +51,14 @@ public class PlaceSlot extends GenericEntity {
this
.
created
=
Calendar
.
getInstance
().
getTime
();
this
.
created
=
Calendar
.
getInstance
().
getTime
();
}
}
public
boolean
isUsed
()
{
return
used
!=
null
||
place
!=
null
;
}
public
boolean
isLocked
()
{
return
place
!=
null
&&
place
.
getGroup
()
!=
null
;
}
public
Date
getCreated
()
{
public
Date
getCreated
()
{
return
created
;
return
created
;
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment