Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Linnea Samila
/
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 ccf864d4
authored
Dec 08, 2014
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes placecount for products that has been given by hand
1 parent
2465b0a9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
6 deletions
code/moya-beans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/ProductBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceFacade.java
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceSlotFacade.java
code/moya-web/src/main/java/fi/codecrew/moya/web/cdiview/map/PlaceView.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
View file @
ccf864d
...
...
@@ -260,7 +260,7 @@ public class PlaceBean implements PlaceBeanLocal {
logger
.
warn
(
"Reserving place {} with placeslot {}"
,
place
,
slot
);
slot
.
setPlace
(
place
);
slot
.
setUsed
(
new
Date
());
}
else
{
}
else
if
(!
permbean
.
hasPermission
(
MapPermission
.
MANAGE_OTHERS
))
{
// we still can reserve places to other people
logger
.
warn
(
"Not enough slots to reserve place {}"
,
place
);
// Not enough slots to reserve place
return
false
;
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/beans/ProductBean.java
View file @
ccf864d
...
...
@@ -215,10 +215,12 @@ public class ProductBean implements ProductBeanLocal {
if
(!
prod
.
getProductFlags
().
contains
(
ProductFlag
.
PREPAID_CREDIT
))
{
if
(
prod
.
getPlaces
()
!=
null
&&
!
prod
.
getPlaces
().
isEmpty
())
{
int
totalcount
=
prod
.
getPlaces
().
size
();
Long
boughtSlots
=
slotfacade
.
totalSlotcount
(
prod
);
int
freeCount
=
totalcount
-
boughtSlots
.
intValue
();
logger
.
info
(
"Prodlimit totcnt {}, bought {}, free {}, prod {}"
,
totalcount
,
boughtSlots
,
freeCount
,
prod
);
Long
selectableCount
=
placeFacade
.
countSelectable
(
prod
);
Long
unusedSlots
=
slotfacade
.
findUnusedSlotsCount
(
prod
);
int
freeCount
=
selectableCount
.
intValue
()
-
unusedSlots
.
intValue
();
logger
.
info
(
"Prodlimit selectable {}, unused {}, free {}, prod {}"
,
selectableCount
,
unusedSlots
,
freeCount
,
prod
);
ret
.
put
(
prod
.
getId
(),
BigDecimal
.
valueOf
(
freeCount
));
}
}
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceFacade.java
View file @
ccf864d
...
...
@@ -158,6 +158,22 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
return
getEm
().
createQuery
(
cq
).
getResultList
();
}
public
Long
countSelectable
(
Product
product
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
Long
>
cq
=
cb
.
createQuery
(
Long
.
class
);
Root
<
Place
>
root
=
cq
.
from
(
Place
.
class
);
cq
.
select
(
cb
.
count
(
root
));
cq
.
where
(
cb
.
equal
(
root
.
get
(
Place_
.
product
),
product
),
cb
.
isNull
(
root
.
get
(
Place_
.
releaseTime
)),
cb
.
isNull
(
root
.
get
(
Place_
.
group
)),
cb
.
isFalse
(
root
.
get
(
Place_
.
disabled
))
);
return
super
.
getSingleNullableResult
(
getEm
().
createQuery
(
cq
));
}
public
Long
findCountForProduct
(
Product
product
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
Long
>
cq
=
cb
.
createQuery
(
Long
.
class
);
...
...
@@ -167,10 +183,14 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
cq
.
where
(
cb
.
equal
(
root
.
get
(
Place_
.
product
),
product
),
cb
.
isFalse
(
root
.
get
(
Place_
.
disabled
))
);
);
return
super
.
getSingleNullableResult
(
getEm
().
createQuery
(
cq
));
}
public
Long
countAvailable
(
EventMap
map
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
Long
>
cq
=
cb
.
createQuery
(
Long
.
class
);
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceSlotFacade.java
View file @
ccf864d
...
...
@@ -92,6 +92,27 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
return
slot
;
}
public
Long
findUnusedSlotsCount
(
Product
prod
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
Long
>
q
=
cb
.
createQuery
(
Long
.
class
);
Root
<
PlaceSlot
>
root
=
q
.
from
(
PlaceSlot
.
class
);
q
.
select
(
cb
.
count
(
root
));
Path
<
Bill
>
bill
=
root
.
get
(
PlaceSlot_
.
bill
);
Path
<
Calendar
>
billexp
=
bill
.
get
(
Bill_
.
expires
);
q
.
where
(
cb
.
equal
(
root
.
get
(
PlaceSlot_
.
product
),
prod
),
cb
.
or
(
cb
.
isNull
(
billexp
),
cb
.
greaterThan
(
billexp
,
Calendar
.
getInstance
())
),
cb
.
isNull
(
root
.
get
(
PlaceSlot_
.
place
))
);
Long
count
=
super
.
getSingleNullableResult
(
getEm
().
createQuery
(
q
));
return
count
;
}
public
Long
totalSlotcount
(
Product
prod
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
Long
>
q
=
cb
.
createQuery
(
Long
.
class
);
...
...
code/moya-web/src/main/java/fi/codecrew/moya/web/cdiview/map/PlaceView.java
View file @
ccf864d
...
...
@@ -178,6 +178,8 @@ public class PlaceView extends GenericCDIView {
place
=
p
;
}
}
}
else
{
super
.
addFaceMessage
(
"Cannot reserve place for user"
);
}
}
catch
(
BortalCatchableException
e
)
{
...
...
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