Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c31ee26f
authored
Jun 07, 2014
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add comments and remove return from GenericFacade.create() function
1 parent
8557d61a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
127 additions
and
79 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/ActionLogBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/CardTemplateBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/MenuBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/ReaderBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/TournamentBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/UserBean.java
code/MoyaUtilities/src/main/java/fi/codecrew/moya/utilities/jpa/GenericFacade.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/ActionLogBean.java
View file @
c31ee26
...
@@ -2,7 +2,6 @@ package fi.codecrew.moya.beans;
...
@@ -2,7 +2,6 @@ package fi.codecrew.moya.beans;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
javax.annotation.security.DeclareRoles
;
import
javax.annotation.security.DeclareRoles
;
...
@@ -10,13 +9,10 @@ import javax.annotation.security.RolesAllowed;
...
@@ -10,13 +9,10 @@ import javax.annotation.security.RolesAllowed;
import
javax.ejb.EJB
;
import
javax.ejb.EJB
;
import
javax.ejb.Stateless
;
import
javax.ejb.Stateless
;
import
fi.codecrew.moya.facade.ActionLogFacade
;
import
fi.codecrew.moya.facade.ActionLogMessageTagFacade
;
import
fi.codecrew.moya.beans.ActionLogBeanLocal
;
import
fi.codecrew.moya.beans.PermissionBeanLocal
;
import
fi.codecrew.moya.beans.RoleBeanLocal
;
import
fi.codecrew.moya.enums.ActionLogMessageState
;
import
fi.codecrew.moya.enums.ActionLogMessageState
;
import
fi.codecrew.moya.enums.apps.ContentPermission
;
import
fi.codecrew.moya.enums.apps.ContentPermission
;
import
fi.codecrew.moya.facade.ActionLogFacade
;
import
fi.codecrew.moya.facade.ActionLogMessageTagFacade
;
import
fi.codecrew.moya.model.ActionLogMessage
;
import
fi.codecrew.moya.model.ActionLogMessage
;
import
fi.codecrew.moya.model.ActionLogMessageResponse
;
import
fi.codecrew.moya.model.ActionLogMessageResponse
;
import
fi.codecrew.moya.model.ActionLogMessageTag
;
import
fi.codecrew.moya.model.ActionLogMessageTag
;
...
@@ -79,7 +75,7 @@ public class ActionLogBean implements ActionLogBeanLocal {
...
@@ -79,7 +75,7 @@ public class ActionLogBean implements ActionLogBeanLocal {
@Override
@Override
@RolesAllowed
(
ContentPermission
.
S_MANAGE_ACTIONLOG
)
@RolesAllowed
(
ContentPermission
.
S_MANAGE_ACTIONLOG
)
public
List
<
ActionLogMessage
>
getAllActionLogEventsByFilter
(
List
<
ActionLogMessageTag
>
filterTags
)
{
public
List
<
ActionLogMessage
>
getAllActionLogEventsByFilter
(
List
<
ActionLogMessageTag
>
filterTags
)
{
if
(
filterTags
.
size
()
==
0
)
if
(
filterTags
.
size
()
==
0
)
return
actionLogFacade
.
getAllSortedByTimestamp
(
permissionBean
.
getCurrentUser
().
getEvent
());
return
actionLogFacade
.
getAllSortedByTimestamp
(
permissionBean
.
getCurrentUser
().
getEvent
());
else
else
return
actionLogFacade
.
getAllSortedByTimestampFiltered
(
permissionBean
.
getCurrentUser
().
getEvent
(),
filterTags
);
return
actionLogFacade
.
getAllSortedByTimestampFiltered
(
permissionBean
.
getCurrentUser
().
getEvent
(),
filterTags
);
...
@@ -92,7 +88,8 @@ public class ActionLogBean implements ActionLogBeanLocal {
...
@@ -92,7 +88,8 @@ public class ActionLogBean implements ActionLogBeanLocal {
@RolesAllowed
(
ContentPermission
.
S_MANAGE_ACTIONLOG
)
@RolesAllowed
(
ContentPermission
.
S_MANAGE_ACTIONLOG
)
public
List
<
ActionLogMessageResponse
>
getActionLogMessageResponses
(
ActionLogMessage
alm
)
{
public
List
<
ActionLogMessageResponse
>
getActionLogMessageResponses
(
ActionLogMessage
alm
)
{
if
(!
alm
.
getLanEvent
().
equals
(
permissionBean
.
getCurrentUser
().
getEvent
()))
return
null
;
if
(!
alm
.
getLanEvent
().
equals
(
permissionBean
.
getCurrentUser
().
getEvent
()))
return
null
;
return
actionLogFacade
.
getActionLogMessageResponses
(
alm
);
return
actionLogFacade
.
getActionLogMessageResponses
(
alm
);
}
}
...
@@ -104,7 +101,8 @@ public class ActionLogBean implements ActionLogBeanLocal {
...
@@ -104,7 +101,8 @@ public class ActionLogBean implements ActionLogBeanLocal {
@RolesAllowed
(
ContentPermission
.
S_MANAGE_ACTIONLOG
)
@RolesAllowed
(
ContentPermission
.
S_MANAGE_ACTIONLOG
)
public
void
addActionLogMessageResponse
(
ActionLogMessage
alm
,
String
message
,
ActionLogMessageState
state
)
{
public
void
addActionLogMessageResponse
(
ActionLogMessage
alm
,
String
message
,
ActionLogMessageState
state
)
{
if
(!
alm
.
getLanEvent
().
equals
(
permissionBean
.
getCurrentUser
().
getEvent
()))
return
;
if
(!
alm
.
getLanEvent
().
equals
(
permissionBean
.
getCurrentUser
().
getEvent
()))
return
;
if
(
alm
.
getState
()
!=
state
&&
state
!=
null
)
{
if
(
alm
.
getState
()
!=
state
&&
state
!=
null
)
{
alm
=
actionLogFacade
.
merge
(
alm
);
alm
=
actionLogFacade
.
merge
(
alm
);
...
@@ -124,8 +122,10 @@ public class ActionLogBean implements ActionLogBeanLocal {
...
@@ -124,8 +122,10 @@ public class ActionLogBean implements ActionLogBeanLocal {
@RolesAllowed
(
ContentPermission
.
S_MANAGE_ACTIONLOG
)
@RolesAllowed
(
ContentPermission
.
S_MANAGE_ACTIONLOG
)
public
ActionLogMessage
find
(
Integer
id
)
{
public
ActionLogMessage
find
(
Integer
id
)
{
ActionLogMessage
alm
=
actionLogFacade
.
find
(
id
);
ActionLogMessage
alm
=
actionLogFacade
.
find
(
id
);
if
(!
alm
.
getLanEvent
().
equals
(
permissionBean
.
getCurrentUser
().
getEvent
()))
return
null
;
if
(!
alm
.
getLanEvent
().
equals
(
permissionBean
.
getCurrentUser
().
getEvent
()))
else
return
alm
;
return
null
;
else
return
alm
;
}
}
private
ArrayList
<
ActionLogMessageTag
>
resolveTags
(
String
message
)
{
private
ArrayList
<
ActionLogMessageTag
>
resolveTags
(
String
message
)
{
...
@@ -134,14 +134,14 @@ public class ActionLogBean implements ActionLogBeanLocal {
...
@@ -134,14 +134,14 @@ public class ActionLogBean implements ActionLogBeanLocal {
boolean
rflag
=
false
;
boolean
rflag
=
false
;
char
ch
;
char
ch
;
for
(
int
i
=
0
;
i
<
message
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
message
.
length
();
i
++)
{
if
(
rflag
)
{
if
(
rflag
)
{
if
((
ch
=
message
.
charAt
(
i
))
!=
' '
)
{
if
((
ch
=
message
.
charAt
(
i
))
!=
' '
)
{
sb
.
append
(
ch
);
sb
.
append
(
ch
);
}
else
{
}
else
{
if
(
sb
.
length
()
>
0
)
{
if
(
sb
.
length
()
>
0
)
{
ActionLogMessageTag
almt
=
getActionLogMessageTagByString
(
sb
.
toString
());
ActionLogMessageTag
almt
=
getActionLogMessageTagByString
(
sb
.
toString
());
if
(!
almts
.
contains
(
almt
))
{
if
(!
almts
.
contains
(
almt
))
{
almts
.
add
(
almt
);
almts
.
add
(
almt
);
}
}
}
}
...
@@ -149,17 +149,17 @@ public class ActionLogBean implements ActionLogBeanLocal {
...
@@ -149,17 +149,17 @@ public class ActionLogBean implements ActionLogBeanLocal {
rflag
=
false
;
rflag
=
false
;
sb
=
null
;
sb
=
null
;
}
}
}
else
if
(!
rflag
)
{
}
else
if
(!
rflag
)
{
if
(
message
.
charAt
(
i
)
==
'#'
)
{
if
(
message
.
charAt
(
i
)
==
'#'
)
{
rflag
=
true
;
rflag
=
true
;
sb
=
new
StringBuilder
();
sb
=
new
StringBuilder
();
}
}
}
}
}
}
if
(
sb
!=
null
&&
sb
.
length
()
>
0
)
{
if
(
sb
!=
null
&&
sb
.
length
()
>
0
)
{
ActionLogMessageTag
almt
=
getActionLogMessageTagByString
(
sb
.
toString
());
ActionLogMessageTag
almt
=
getActionLogMessageTagByString
(
sb
.
toString
());
if
(!
almts
.
contains
(
almt
))
{
if
(!
almts
.
contains
(
almt
))
{
almts
.
add
(
almt
);
almts
.
add
(
almt
);
}
}
}
}
...
@@ -173,18 +173,17 @@ public class ActionLogBean implements ActionLogBeanLocal {
...
@@ -173,18 +173,17 @@ public class ActionLogBean implements ActionLogBeanLocal {
s
=
s
.
toLowerCase
();
s
=
s
.
toLowerCase
();
ActionLogMessageTag
almt
=
null
;
ActionLogMessageTag
almt
=
null
;
if
((
almt
=
actionLogMessageTagFacade
.
findByTagStringInEvent
(
s
,
eventBean
.
getCurrentEvent
()))
==
null
)
{
if
((
almt
=
actionLogMessageTagFacade
.
findByTagStringInEvent
(
s
,
eventBean
.
getCurrentEvent
()))
==
null
)
{
almt
=
new
ActionLogMessageTag
();
almt
=
new
ActionLogMessageTag
();
almt
.
setEvent
(
eventBean
.
getCurrentEvent
());
almt
.
setEvent
(
eventBean
.
getCurrentEvent
());
almt
.
setTag
(
s
);
almt
.
setTag
(
s
);
a
lmt
=
a
ctionLogMessageTagFacade
.
create
(
almt
);
actionLogMessageTagFacade
.
create
(
almt
);
System
.
out
.
println
(
"creating tag: "
+
s
);
System
.
out
.
println
(
"creating tag: "
+
s
);
return
almt
;
return
almt
;
}
else
{
}
else
{
System
.
out
.
println
(
"re-using tag: "
+
s
);
System
.
out
.
println
(
"re-using tag: "
+
s
);
return
almt
;
return
almt
;
}
}
}
}
}
}
\ No newline at end of file
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/CardTemplateBean.java
View file @
c31ee26
...
@@ -274,18 +274,20 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -274,18 +274,20 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
@Override
@Override
public
CardTextData
save
(
CardTextData
textData
)
{
public
CardTextData
save
(
CardTextData
textData
)
{
if
(
textData
.
getId
()
!=
null
&&
textData
.
getId
()
!=
0
)
if
(
textData
.
getId
()
!=
null
&&
textData
.
getId
()
!=
0
)
return
ctdFacade
.
merge
(
textData
);
textData
=
ctdFacade
.
merge
(
textData
);
else
else
return
ctdFacade
.
create
(
textData
);
ctdFacade
.
create
(
textData
);
return
textData
;
}
}
@RolesAllowed
(
UserPermission
.
S_WRITE_ROLES
)
@RolesAllowed
(
UserPermission
.
S_WRITE_ROLES
)
@Override
@Override
public
CardObjectData
save
(
CardObjectData
objectData
)
{
public
CardObjectData
save
(
CardObjectData
objectData
)
{
if
(
objectData
.
getId
()
!=
null
&&
objectData
.
getId
()
!=
0
)
if
(
objectData
.
getId
()
!=
null
&&
objectData
.
getId
()
!=
0
)
return
codFacade
.
merge
(
objectData
);
objectData
=
codFacade
.
merge
(
objectData
);
else
else
return
codFacade
.
create
(
objectData
);
codFacade
.
create
(
objectData
);
return
objectData
;
}
}
@Override
@Override
...
@@ -375,7 +377,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -375,7 +377,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
card
.
setCardState
(
CardState
.
DELIVERED
);
card
.
setCardState
(
CardState
.
DELIVERED
);
}
else
{
}
else
{
logger
.
info
(
"Not marking card to delivered: "
+
card
.
getCardState
()
+
" : "
+
card
.
getId
());
logger
.
info
(
"Not marking card to delivered: "
+
card
.
getCardState
()
+
" : "
+
card
.
getId
());
}
}
if
(
markUserPlacesDelivered
)
{
if
(
markUserPlacesDelivered
)
{
for
(
GroupMembership
membership
:
gmFacade
.
findMemberships
(
user
))
{
for
(
GroupMembership
membership
:
gmFacade
.
findMemberships
(
user
))
{
...
...
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/MenuBean.java
View file @
c31ee26
...
@@ -35,6 +35,9 @@ import fi.codecrew.moya.model.MenuNavigation;
...
@@ -35,6 +35,9 @@ import fi.codecrew.moya.model.MenuNavigation;
/**
/**
*
*
* HUOM! JOS POISTAT SIVUN, PITÄÄ VIITTAUS POISTAA MYÖS KANNASTA! MUUTEN
* GALAKSIT RÄJÄHTÄÄ! (jsf ei löydä viittausta sivuun ja heittää poikkeuksen)
*
* Kaikki sivut pitää olla jossain menussa, muuten menu häviää näkyvistä ko.
* Kaikki sivut pitää olla jossain menussa, muuten menu häviää näkyvistä ko.
* sivulla kokonaan. Älä siis poista sivua vaaan aseta sivu näkymättömäksi:
* sivulla kokonaan. Älä siis poista sivua vaaan aseta sivu näkymättömäksi:
* .setVisible(false).
* .setVisible(false).
...
@@ -154,7 +157,6 @@ public class MenuBean implements MenuBeanLocal {
...
@@ -154,7 +157,6 @@ public class MenuBean implements MenuBeanLocal {
MenuNavigation
createuser
=
usermenu
.
addPage
(
null
,
null
);
MenuNavigation
createuser
=
usermenu
.
addPage
(
null
,
null
);
createuser
.
setKey
(
"topnavi.createuser"
);
createuser
.
setKey
(
"topnavi.createuser"
);
createuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/user/create"
),
UserPermission
.
CREATE_NEW
).
setVisible
(
false
);
createuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/user/create"
),
UserPermission
.
CREATE_NEW
).
setVisible
(
false
);
;
navifacade
.
create
(
usermenu
);
navifacade
.
create
(
usermenu
);
...
@@ -168,7 +170,8 @@ public class MenuBean implements MenuBeanLocal {
...
@@ -168,7 +170,8 @@ public class MenuBean implements MenuBeanLocal {
MenuNavigation
adminuser
=
adminmenu
.
addPage
(
null
,
null
);
MenuNavigation
adminuser
=
adminmenu
.
addPage
(
null
,
null
);
adminuser
.
setKey
(
"topnavi.usermgmt"
);
adminuser
.
setKey
(
"topnavi.usermgmt"
);
adminuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/useradmin/list"
),
UserPermission
.
VIEW_ALL
);
adminuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/useradmin/list"
),
UserPermission
.
VIEW_ALL
);
adminuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/useradmin/overview"
),
UserPermission
.
VIEW_ALL
).
setVisible
(
false
);;
adminuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/useradmin/overview"
),
UserPermission
.
VIEW_ALL
).
setVisible
(
false
);
adminuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/useradmin/create"
),
UserPermission
.
VIEW_ALL
);
adminuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/useradmin/create"
),
UserPermission
.
VIEW_ALL
);
adminuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/useradmin/sendPicture"
),
UserPermission
.
VIEW_ALL
).
setVisible
(
false
);
adminuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/useradmin/sendPicture"
),
UserPermission
.
VIEW_ALL
).
setVisible
(
false
);
adminuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/place/adminGroups"
),
UserPermission
.
VIEW_ALL
).
setVisible
(
false
);
adminuser
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/place/adminGroups"
),
UserPermission
.
VIEW_ALL
).
setVisible
(
false
);
...
...
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/ReaderBean.java
View file @
c31ee26
...
@@ -164,7 +164,7 @@ public class ReaderBean implements ReaderBeanLocal {
...
@@ -164,7 +164,7 @@ public class ReaderBean implements ReaderBeanLocal {
}
}
}
}
event
=
readerEventFacade
.
create
(
event
);
readerEventFacade
.
create
(
event
);
return
event
;
return
event
;
...
@@ -173,11 +173,9 @@ public class ReaderBean implements ReaderBeanLocal {
...
@@ -173,11 +173,9 @@ public class ReaderBean implements ReaderBeanLocal {
@Override
@Override
public
ReaderEvent
assocCodeToCard
(
ReaderEvent
readerEvent
,
PrintedCard
card
)
{
public
ReaderEvent
assocCodeToCard
(
ReaderEvent
readerEvent
,
PrintedCard
card
)
{
card
=
cardfacade
.
reload
(
card
);
CardCode
code
=
new
CardCode
(
card
,
readerEvent
.
getReader
().
getType
(),
readerEvent
.
getValue
());
CardCode
code
=
new
CardCode
(
card
,
readerEvent
.
getReader
().
getType
(),
readerEvent
.
getValue
(),
eventbean
.
getCurrentEvent
());
code
=
cardCodeFacade
.
create
(
code
);
cardCodeFacade
.
create
(
code
);
card
.
getCardCodes
().
add
(
code
);
return
readerEvent
;
return
readerEvent
;
}
}
...
...
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/TournamentBean.java
View file @
c31ee26
...
@@ -70,13 +70,15 @@ public class TournamentBean implements TournamentBeanLocal {
...
@@ -70,13 +70,15 @@ public class TournamentBean implements TournamentBeanLocal {
@Override
@Override
@RolesAllowed
(
TournamentPermission
.
S_MANAGE_ALL
)
@RolesAllowed
(
TournamentPermission
.
S_MANAGE_ALL
)
public
TournamentGame
createGame
(
TournamentGame
tg
)
{
public
TournamentGame
createGame
(
TournamentGame
tg
)
{
return
tournamentGameFacade
.
create
(
tg
);
tournamentGameFacade
.
create
(
tg
);
return
tg
;
}
}
@Override
@Override
@RolesAllowed
(
TournamentPermission
.
S_MANAGE_ALL
)
@RolesAllowed
(
TournamentPermission
.
S_MANAGE_ALL
)
public
TournamentRule
createRule
(
TournamentRule
tr
)
{
public
TournamentRule
createRule
(
TournamentRule
tr
)
{
return
tournamentRuleFacade
.
create
(
tr
);
tournamentRuleFacade
.
create
(
tr
);
return
tr
;
}
}
@Override
@Override
...
@@ -105,7 +107,7 @@ public class TournamentBean implements TournamentBeanLocal {
...
@@ -105,7 +107,7 @@ public class TournamentBean implements TournamentBeanLocal {
@RolesAllowed
(
TournamentPermission
.
S_MANAGE_ALL
)
@RolesAllowed
(
TournamentPermission
.
S_MANAGE_ALL
)
public
void
updateTournamentRules
(
TournamentRule
tr
)
throws
Exception
{
public
void
updateTournamentRules
(
TournamentRule
tr
)
throws
Exception
{
// Assert correct event
// Assert correct event
if
(
eventBean
.
getCurrentEvent
().
equals
(
tr
.
getTournamentGame
().
getLanEvent
()))
{
if
(
eventBean
.
getCurrentEvent
().
equals
(
tr
.
getTournamentGame
().
getLanEvent
()))
{
tournamentRuleFacade
.
merge
(
tr
);
tournamentRuleFacade
.
merge
(
tr
);
}
else
{
}
else
{
throw
new
Exception
(
"tournament.invalid_event"
);
throw
new
Exception
(
"tournament.invalid_event"
);
...
@@ -115,8 +117,8 @@ public class TournamentBean implements TournamentBeanLocal {
...
@@ -115,8 +117,8 @@ public class TournamentBean implements TournamentBeanLocal {
@Override
@Override
@RolesAllowed
(
TournamentPermission
.
S_VIEW
)
@RolesAllowed
(
TournamentPermission
.
S_VIEW
)
public
List
<
Tournament
>
getTournamentsInStatus
(
TournamentStatus
status
,
boolean
useTimeConstraints
,
boolean
invertMatch
)
{
public
List
<
Tournament
>
getTournamentsInStatus
(
TournamentStatus
status
,
boolean
useTimeConstraints
,
boolean
invertMatch
)
{
if
(
useTimeConstraints
)
if
(
useTimeConstraints
)
if
(!
invertMatch
)
if
(!
invertMatch
)
return
tournamentFacade
.
getTournamentsInStatusWithParticipationTimeIn
(
status
,
eventBean
.
getCurrentEvent
());
return
tournamentFacade
.
getTournamentsInStatusWithParticipationTimeIn
(
status
,
eventBean
.
getCurrentEvent
());
else
else
return
tournamentFacade
.
getTournamentsInStatusWithParticipationTimeNotIn
(
status
,
eventBean
.
getCurrentEvent
());
return
tournamentFacade
.
getTournamentsInStatusWithParticipationTimeNotIn
(
status
,
eventBean
.
getCurrentEvent
());
...
@@ -170,7 +172,7 @@ public class TournamentBean implements TournamentBeanLocal {
...
@@ -170,7 +172,7 @@ public class TournamentBean implements TournamentBeanLocal {
// Assert team has the correct number of players for a match
// Assert team has the correct number of players for a match
if
(
tournamentParticipant
.
getTeamMembers
().
size
()
>=
tournamentParticipant
.
getTournament
().
getPlayersPerMatch
())
{
if
(
tournamentParticipant
.
getTeamMembers
().
size
()
>=
tournamentParticipant
.
getTournament
().
getPlayersPerMatch
())
{
tournamentParticipant
=
tournamentParticipant
Facade
.
create
(
tournamentParticipant
);
tournamentParticipantFacade
.
create
(
tournamentParticipant
);
t
.
getParticipants
().
add
(
tournamentParticipant
);
t
.
getParticipants
().
add
(
tournamentParticipant
);
}
else
{
}
else
{
throw
new
Exception
(
"tournament.not_enough_players"
);
throw
new
Exception
(
"tournament.not_enough_players"
);
...
@@ -233,18 +235,18 @@ public class TournamentBean implements TournamentBeanLocal {
...
@@ -233,18 +235,18 @@ public class TournamentBean implements TournamentBeanLocal {
// Assert we have permission to remove participant
// Assert we have permission to remove participant
// TODO: this will include check for remove any participation too!
// TODO: this will include check for remove any participation too!
if
(!
permissionBean
.
hasPermission
(
TournamentPermission
.
REMOVE_OWN_PARTICIPATION
)
||
!
tp
.
getParticipator
().
equals
(
executor
))
{
if
(!
permissionBean
.
hasPermission
(
TournamentPermission
.
REMOVE_OWN_PARTICIPATION
)
||
!
tp
.
getParticipator
().
equals
(
executor
))
{
throw
new
Exception
(
"tournaments.can_only_remove_own_participations"
);
throw
new
Exception
(
"tournaments.can_only_remove_own_participations"
);
}
}
// Assert that tournament has not closed participation
// Assert that tournament has not closed participation
// TODO: admin exception!
// TODO: admin exception!
if
(!
tp
.
getTournament
().
getRegistrationClosesAt
().
after
(
new
Date
()))
{
if
(!
tp
.
getTournament
().
getRegistrationClosesAt
().
after
(
new
Date
()))
{
throw
new
Exception
(
"tournaments.cannot_remove_participation_from_closed_tournament"
);
throw
new
Exception
(
"tournaments.cannot_remove_participation_from_closed_tournament"
);
}
}
// All ok, do nukage
// All ok, do nukage
for
(
TournamentTeamMember
ttm
:
tp
.
getTeamMembers
())
{
for
(
TournamentTeamMember
ttm
:
tp
.
getTeamMembers
())
{
tournamentTeamMemberFacade
.
remove
(
ttm
);
tournamentTeamMemberFacade
.
remove
(
ttm
);
}
}
...
...
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/UserBean.java
View file @
c31ee26
...
@@ -339,10 +339,10 @@ public class UserBean implements UserBeanLocal {
...
@@ -339,10 +339,10 @@ public class UserBean implements UserBeanLocal {
int
sourceCenterY
=
sourceHeight
/
2
;
int
sourceCenterY
=
sourceHeight
/
2
;
int
sourceTop
,
sourceLeft
,
sourceRight
,
sourceBottom
;
int
sourceTop
,
sourceLeft
,
sourceRight
,
sourceBottom
;
double
sourceRatio
=
(
double
)
sourceWidth
/
(
double
)
sourceHeight
;
double
sourceRatio
=
(
double
)
sourceWidth
/
(
double
)
sourceHeight
;
if
(
sourceRatio
>
targetRatio
)
{
if
(
sourceRatio
>
targetRatio
)
{
// the pic is too wide - reduce width
// the pic is too wide - reduce width
targetWidth
=
(
int
)
((
double
)
sourceHeight
*
targetRatio
);
targetWidth
=
(
int
)
((
double
)
sourceHeight
*
targetRatio
);
targetHeight
=
sourceHeight
;
targetHeight
=
sourceHeight
;
// crop box coords - calculate left and right
// crop box coords - calculate left and right
...
@@ -353,7 +353,7 @@ public class UserBean implements UserBeanLocal {
...
@@ -353,7 +353,7 @@ public class UserBean implements UserBeanLocal {
}
else
{
}
else
{
// the pic is too tall - reduce height
// the pic is too tall - reduce height
targetWidth
=
sourceWidth
;
targetWidth
=
sourceWidth
;
targetHeight
=
(
int
)
((
double
)
sourceWidth
/
targetRatio
);
targetHeight
=
(
int
)
((
double
)
sourceWidth
/
targetRatio
);
// crop box coords - calculate top and bottom
// crop box coords - calculate top and bottom
sourceLeft
=
0
;
sourceLeft
=
0
;
...
@@ -478,27 +478,27 @@ public class UserBean implements UserBeanLocal {
...
@@ -478,27 +478,27 @@ public class UserBean implements UserBeanLocal {
public
PrintedCard
rejectPrintedCard
(
PrintedCard
card
,
MailMessage
mail
)
{
public
PrintedCard
rejectPrintedCard
(
PrintedCard
card
,
MailMessage
mail
)
{
if
(
card
!=
null
)
{
if
(
card
!=
null
)
{
card
.
setCardState
(
CardState
.
REJECTED
);
card
.
setCardState
(
CardState
.
REJECTED
);
card
=
printedcardfacade
.
merge
(
card
);
card
=
printedcardfacade
.
merge
(
card
);
logger
.
info
(
"rejectPrintedCard(): Rejected card {}, state {}"
,
card
,
card
.
getCardState
()
);
logger
.
info
(
"rejectPrintedCard(): Rejected card {}, state {}"
,
card
,
card
.
getCardState
());
User
user
=
null
;
User
user
=
null
;
if
(
card
.
getUser
()
!=
null
&&
card
.
getUser
().
getUser
()
!=
null
)
if
(
card
.
getUser
()
!=
null
&&
card
.
getUser
().
getUser
()
!=
null
)
user
=
card
.
getUser
().
getUser
();
user
=
card
.
getUser
().
getUser
();
LanEvent
event
=
card
.
getEvent
();
LanEvent
event
=
card
.
getEvent
();
if
(
mail
!=
null
)
{
if
(
mail
!=
null
)
{
if
(!
utilbean
.
sendMail
(
mail
))
{
if
(!
utilbean
.
sendMail
(
mail
))
{
logger
.
info
(
"Sending mail failed"
);
logger
.
info
(
"Sending mail failed"
);
}
else
}
else
logger
.
info
(
"Sending mail succeeded"
);
logger
.
info
(
"Sending mail succeeded"
);
}
else
{
}
else
{
if
(
user
==
null
)
if
(
user
==
null
)
logger
.
info
(
"user is null"
);
logger
.
info
(
"user is null"
);
if
(
event
==
null
)
if
(
event
==
null
)
logger
.
info
(
"event is null"
);
logger
.
info
(
"event is null"
);
}
}
}
}
...
@@ -663,7 +663,7 @@ public class UserBean implements UserBeanLocal {
...
@@ -663,7 +663,7 @@ public class UserBean implements UserBeanLocal {
gid
.
setGame
(
game
);
gid
.
setGame
(
game
);
gid
.
setUser
(
u
);
gid
.
setUser
(
u
);
g
id
=
g
ameIDFacade
.
create
(
gid
);
gameIDFacade
.
create
(
gid
);
u
.
getGameIDs
().
add
(
gid
);
u
.
getGameIDs
().
add
(
gid
);
}
}
...
@@ -952,14 +952,15 @@ public class UserBean implements UserBeanLocal {
...
@@ -952,14 +952,15 @@ public class UserBean implements UserBeanLocal {
String
hex
=
Integer
.
toHexString
(
user
.
getId
());
String
hex
=
Integer
.
toHexString
(
user
.
getId
());
logger
.
info
(
"Hex code {} for id {}"
,
hex
,
user
.
getId
());
logger
.
info
(
"Hex code {} for id {}"
,
hex
,
user
.
getId
());
//padding hex string to 5 characters by adding Xs to the beginning
//
padding hex string to 5 characters by adding Xs to the beginning
if
(
hex
.
length
()
<
5
)
{
if
(
hex
.
length
()
<
5
)
{
logger
.
info
(
"Padding hex ({}) with X."
,
hex
.
length
());
logger
.
info
(
"Padding hex ({}) with X."
,
hex
.
length
());
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
if
(
hex
.
length
()
<
5
)
{
if
(
hex
.
length
()
<
5
)
{
hex
=
"X"
+
hex
;
hex
=
"X"
+
hex
;
}
}
else
break
;
else
break
;
}
}
}
else
}
else
logger
.
info
(
"Hex string too long ({}), no padding needed"
,
hex
.
length
());
logger
.
info
(
"Hex string too long ({}), no padding needed"
,
hex
.
length
());
...
@@ -971,16 +972,17 @@ public class UserBean implements UserBeanLocal {
...
@@ -971,16 +972,17 @@ public class UserBean implements UserBeanLocal {
byte
[]
array
=
md
.
digest
(
hex
.
getBytes
());
byte
[]
array
=
md
.
digest
(
hex
.
getBytes
());
hash
=
new
String
(
Hex
.
encodeHex
(
array
));
hash
=
new
String
(
Hex
.
encodeHex
(
array
));
logger
.
info
(
"Hash {}"
,
hash
);
logger
.
info
(
"Hash {}"
,
hash
);
}
catch
(
NoSuchAlgorithmException
ex
)
{
}
catch
(
NoSuchAlgorithmException
ex
)
{
logger
.
info
(
"Catched exeption {}"
,
ex
.
getMessage
());
logger
.
info
(
"Catched exeption {}"
,
ex
.
getMessage
());
}
}
if
(
hash
!=
""
&&
hash
.
length
()
>
2
)
{
if
(
hash
!=
""
&&
hash
.
length
()
>
2
)
{
//Generating code by concatenating hex string and first 3 characters from hash
// Generating code by concatenating hex string and first 3
// characters from hash
code
=
code
.
concat
(
hex
);
code
=
code
.
concat
(
hex
);
code
=
code
.
concat
(
hash
.
substring
(
0
,
3
));
code
=
code
.
concat
(
hash
.
substring
(
0
,
3
));
logger
.
info
(
"Code for user is {}"
,
code
);
logger
.
info
(
"Code for user is {}"
,
code
);
}
else
}
else
logger
.
info
(
"No code generated: hash.length() {}"
,
hash
.
length
());
logger
.
info
(
"No code generated: hash.length() {}"
,
hash
.
length
());
return
code
.
toUpperCase
();
return
code
.
toUpperCase
();
...
@@ -992,7 +994,7 @@ public class UserBean implements UserBeanLocal {
...
@@ -992,7 +994,7 @@ public class UserBean implements UserBeanLocal {
logger
.
info
(
"getUser({})"
,
authcode
);
logger
.
info
(
"getUser({})"
,
authcode
);
EventUser
user
=
null
;
EventUser
user
=
null
;
if
(
authcode
.
length
()
==
8
)
{
if
(
authcode
.
length
()
==
8
)
{
logger
.
info
(
"authcode length is 8"
);
logger
.
info
(
"authcode length is 8"
);
// First 5 characters are the hex
// First 5 characters are the hex
String
paddedHex
=
authcode
.
substring
(
0
,
5
);
String
paddedHex
=
authcode
.
substring
(
0
,
5
);
...
@@ -1004,28 +1006,28 @@ public class UserBean implements UserBeanLocal {
...
@@ -1004,28 +1006,28 @@ public class UserBean implements UserBeanLocal {
int
id
=
0
;
int
id
=
0
;
try
{
try
{
id
=
Integer
.
decode
(
"0x"
+
hex
.
toLowerCase
());
id
=
Integer
.
decode
(
"0x"
+
hex
.
toLowerCase
());
}
catch
(
NumberFormatException
ex
)
{
}
catch
(
NumberFormatException
ex
)
{
logger
.
info
(
"NumberFormatException was thrown"
);
logger
.
info
(
"NumberFormatException was thrown"
);
}
}
logger
.
info
(
"Id {}"
,
id
);
logger
.
info
(
"Id {}"
,
id
);
if
(
id
!=
0
)
{
if
(
id
!=
0
)
{
user
=
eventUserFacade
.
find
(
id
);
user
=
eventUserFacade
.
find
(
id
);
}
}
if
(
user
!=
null
)
{
if
(
user
!=
null
)
{
// Testing if the user is correct
// Testing if the user is correct
logger
.
info
(
"User {} found with id {}"
,
user
,
id
);
logger
.
info
(
"User {} found with id {}"
,
user
,
id
);
String
testCode
=
getAuthCode
(
user
);
String
testCode
=
getAuthCode
(
user
);
logger
.
info
(
"Testcode {}"
,
testCode
);
logger
.
info
(
"Testcode {}"
,
testCode
);
if
(
testCode
==
null
||
testCode
.
equals
(
""
)
||
!
authcode
.
equals
(
testCode
))
{
if
(
testCode
==
null
||
testCode
.
equals
(
""
)
||
!
authcode
.
equals
(
testCode
))
{
user
=
null
;
user
=
null
;
logger
.
info
(
"User set to null, test code not the same as user that was found."
);
logger
.
info
(
"User set to null, test code not the same as user that was found."
);
}
}
}
else
}
else
logger
.
info
(
"User not found with id {}"
,
id
);
logger
.
info
(
"User not found with id {}"
,
id
);
}
else
}
else
logger
.
info
(
"authcode length not 8!, length {}"
,
authcode
.
length
());
logger
.
info
(
"authcode length not 8!, length {}"
,
authcode
.
length
());
return
user
;
return
user
;
...
...
code/MoyaUtilities/src/main/java/fi/codecrew/moya/utilities/jpa/GenericFacade.java
View file @
c31ee26
...
@@ -38,10 +38,19 @@ public abstract class GenericFacade<C extends ModelInterface> {
...
@@ -38,10 +38,19 @@ public abstract class GenericFacade<C extends ModelInterface> {
protected
abstract
EntityManager
getEm
();
protected
abstract
EntityManager
getEm
();
public
C
create
(
C
entity
)
{
/*
* This function does not need to return the persisted entity. All changes are made to the parameter.
*
*/
/**
* Persists the entity into database. After calling this function the entity
* is attached and all changes are persisted to database
*
* @param entity
* Entity to be created and attached to database.
*/
public
void
create
(
C
entity
)
{
getEm
().
persist
(
entity
);
getEm
().
persist
(
entity
);
return
entity
;
}
}
public
void
remove
(
C
entity
)
{
public
void
remove
(
C
entity
)
{
...
@@ -49,11 +58,28 @@ public abstract class GenericFacade<C extends ModelInterface> {
...
@@ -49,11 +58,28 @@ public abstract class GenericFacade<C extends ModelInterface> {
getEm
().
remove
(
entity
);
getEm
().
remove
(
entity
);
}
}
/**
* Merge changes from a detached entity to the database.
*
* This function does nothing if entity is already attached.
*
* @param entity
* Detached entity to be merged into database
* @return Attached entity with changes merged
*/
public
C
merge
(
C
entity
)
{
public
C
merge
(
C
entity
)
{
return
getEm
().
merge
(
entity
);
return
getEm
().
merge
(
entity
);
}
}
/**
* Refresh the state of the instance from the database, overwriting changes
* made to the entity, if any.
*
* ENTITY MUST BE ATTACHED!
*
* @param entity
*/
public
void
refresh
(
C
entity
)
{
public
void
refresh
(
C
entity
)
{
getEm
().
refresh
(
entity
);
getEm
().
refresh
(
entity
);
}
}
...
@@ -282,14 +308,31 @@ public abstract class GenericFacade<C extends ModelInterface> {
...
@@ -282,14 +308,31 @@ public abstract class GenericFacade<C extends ModelInterface> {
// return q.getResultList();
// return q.getResultList();
// }
// }
/**
* Synchronize the persistence context to the underlying database.
*
* This gives to newly created entities ID, etc.
*/
public
void
flush
()
{
public
void
flush
()
{
getEm
().
flush
();
getEm
().
flush
();
}
}
/**
* Remove the given entity from cache.
*
* @param entity
*/
public
void
evict
(
C
entity
)
{
public
void
evict
(
C
entity
)
{
getEm
().
getEntityManagerFactory
().
getCache
().
evict
(
getEntityClass
(),
entity
.
getId
());
getEm
().
getEntityManagerFactory
().
getCache
().
evict
(
getEntityClass
(),
entity
.
getId
());
}
}
/**
* Tells wether the entity is attached to this transaction. ie. Changes to
* this object are automatically propagated to the database
*
* @param entity
* @return
*/
public
boolean
isAttached
(
ModelInterface
entity
)
{
public
boolean
isAttached
(
ModelInterface
entity
)
{
return
getEm
().
contains
(
entity
);
return
getEm
().
contains
(
entity
);
}
}
...
...
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