Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Antti Väyrynen
/
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 055e367f
authored
Sep 13, 2013
by
Antti Tonkyra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More tournament stuff
1 parent
7245a590
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
188 additions
and
23 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/TournamentBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/TournamentFacade.java
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/TournamentBeanLocal.java
code/MoyaDatabase/src/fi/codecrew/moya/model/Tournament.java
code/MoyaDatabase/src/fi/codecrew/moya/model/TournamentMatch.java
code/MoyaDatabase/src/fi/codecrew/moya/model/TournamentParticipant.java
code/MoyaWeb/WebContent/tournaments/admin/createwizard.xhtml
code/MoyaWeb/WebContent/tournaments/index.xhtml
code/MoyaWeb/WebContent/tournaments/participate_single.xhtml
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/tournaments/TournamentListView.java
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/tournaments/TournamentParticipateView.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/TournamentBean.java
View file @
055e367
...
@@ -9,9 +9,12 @@ import javax.ejb.Stateless;
...
@@ -9,9 +9,12 @@ import javax.ejb.Stateless;
import
fi.codecrew.moya.enums.TournamentStatus
;
import
fi.codecrew.moya.enums.TournamentStatus
;
import
fi.codecrew.moya.facade.TournamentFacade
;
import
fi.codecrew.moya.facade.TournamentFacade
;
import
fi.codecrew.moya.facade.TournamentGameFacade
;
import
fi.codecrew.moya.facade.TournamentGameFacade
;
import
fi.codecrew.moya.facade.TournamentParticipantFacade
;
import
fi.codecrew.moya.facade.TournamentRuleFacade
;
import
fi.codecrew.moya.facade.TournamentRuleFacade
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Tournament
;
import
fi.codecrew.moya.model.Tournament
;
import
fi.codecrew.moya.model.TournamentGame
;
import
fi.codecrew.moya.model.TournamentGame
;
import
fi.codecrew.moya.model.TournamentParticipant
;
import
fi.codecrew.moya.model.TournamentRule
;
import
fi.codecrew.moya.model.TournamentRule
;
/**
/**
...
@@ -24,6 +27,7 @@ public class TournamentBean implements TournamentBeanLocal {
...
@@ -24,6 +27,7 @@ public class TournamentBean implements TournamentBeanLocal {
@EJB
private
TournamentRuleFacade
tournamentRuleFacade
;
@EJB
private
TournamentRuleFacade
tournamentRuleFacade
;
@EJB
private
TournamentGameFacade
tournamentGameFacade
;
@EJB
private
TournamentGameFacade
tournamentGameFacade
;
@EJB
private
TournamentFacade
tournamentFacade
;
@EJB
private
TournamentFacade
tournamentFacade
;
@EJB
private
TournamentParticipantFacade
tournamentParticipantFacade
;
/**
/**
* Default constructor.
* Default constructor.
...
@@ -92,4 +96,29 @@ public class TournamentBean implements TournamentBeanLocal {
...
@@ -92,4 +96,29 @@ public class TournamentBean implements TournamentBeanLocal {
tournament
=
tournamentFacade
.
merge
(
tournament
);
tournament
=
tournamentFacade
.
merge
(
tournament
);
tournamentFacade
.
remove
(
tournament
);
tournamentFacade
.
remove
(
tournament
);
}
}
@Override
public
void
createParticipation
(
TournamentParticipant
tournamentParticipant
)
throws
Exception
{
Tournament
t
=
tournamentFacade
.
find
(
tournamentParticipant
.
getTournament
().
getId
());
if
(
t
.
getParticipants
().
size
()
<
t
.
getMaxParticipants
())
{
tournamentParticipant
=
tournamentParticipantFacade
.
create
(
tournamentParticipant
);
t
.
getParticipants
().
add
(
tournamentParticipant
);
}
else
{
throw
new
Exception
(
"tournament.participation_full"
);
}
}
@Override
public
boolean
hasParticipations
(
EventUser
currentUser
,
Tournament
tournament
)
{
for
(
TournamentParticipant
tp
:
tournament
.
getParticipants
())
{
for
(
EventUser
eu
:
tp
.
getTeamMembers
())
{
System
.
out
.
println
(
eu
.
getNick
());
if
(
eu
.
equals
(
currentUser
))
{
return
true
;
}
}
}
return
false
;
}
}
}
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/TournamentFacade.java
View file @
055e367
...
@@ -9,7 +9,9 @@ import javax.persistence.criteria.CriteriaQuery;
...
@@ -9,7 +9,9 @@ import javax.persistence.criteria.CriteriaQuery;
import
javax.persistence.criteria.Root
;
import
javax.persistence.criteria.Root
;
import
fi.codecrew.moya.enums.TournamentStatus
;
import
fi.codecrew.moya.enums.TournamentStatus
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Tournament
;
import
fi.codecrew.moya.model.Tournament
;
import
fi.codecrew.moya.model.TournamentParticipant
;
import
fi.codecrew.moya.model.Tournament_
;
import
fi.codecrew.moya.model.Tournament_
;
import
fi.codecrew.moya.model.User
;
import
fi.codecrew.moya.model.User
;
import
fi.codecrew.moya.model.User_
;
import
fi.codecrew.moya.model.User_
;
...
...
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/TournamentBeanLocal.java
View file @
055e367
...
@@ -5,8 +5,10 @@ import java.util.List;
...
@@ -5,8 +5,10 @@ import java.util.List;
import
javax.ejb.Local
;
import
javax.ejb.Local
;
import
fi.codecrew.moya.enums.TournamentStatus
;
import
fi.codecrew.moya.enums.TournamentStatus
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Tournament
;
import
fi.codecrew.moya.model.Tournament
;
import
fi.codecrew.moya.model.TournamentGame
;
import
fi.codecrew.moya.model.TournamentGame
;
import
fi.codecrew.moya.model.TournamentParticipant
;
import
fi.codecrew.moya.model.TournamentRule
;
import
fi.codecrew.moya.model.TournamentRule
;
@Local
@Local
...
@@ -24,5 +26,7 @@ public interface TournamentBeanLocal {
...
@@ -24,5 +26,7 @@ public interface TournamentBeanLocal {
Tournament
getTournamentById
(
Integer
tournamentId
);
Tournament
getTournamentById
(
Integer
tournamentId
);
void
editTournament
(
Tournament
tournament
);
void
editTournament
(
Tournament
tournament
);
void
deleteTournament
(
Tournament
tournament
);
void
deleteTournament
(
Tournament
tournament
);
void
createParticipation
(
TournamentParticipant
tournamentParticipant
)
throws
Exception
;
boolean
hasParticipations
(
EventUser
currentUser
,
Tournament
tournament
);
}
}
code/MoyaDatabase/src/fi/codecrew/moya/model/Tournament.java
View file @
055e367
...
@@ -72,11 +72,15 @@ public class Tournament extends GenericEntity implements Serializable {
...
@@ -72,11 +72,15 @@ public class Tournament extends GenericEntity implements Serializable {
@JoinColumn
(
name
=
"rules"
,
nullable
=
false
)
@JoinColumn
(
name
=
"rules"
,
nullable
=
false
)
private
TournamentRule
rules
;
private
TournamentRule
rules
;
@OneToMany
@ManyToOne
@JoinColumn
(
name
=
"parent_tournament"
)
private
Tournament
parentTournament
;
@OneToMany
(
mappedBy
=
"parentTournament"
)
@OrderBy
(
"id ASC"
)
@OrderBy
(
"id ASC"
)
private
List
<
Tournament
>
subTournaments
;
private
List
<
Tournament
>
subTournaments
;
@OneToMany
@OneToMany
(
mappedBy
=
"tournament"
)
private
List
<
TournamentParticipant
>
participants
;
private
List
<
TournamentParticipant
>
participants
;
public
Tournament
()
{
super
();
}
public
Tournament
()
{
super
();
}
...
...
code/MoyaDatabase/src/fi/codecrew/moya/model/TournamentMatch.java
View file @
055e367
...
@@ -43,7 +43,6 @@ public class TournamentMatch extends GenericEntity implements Serializable {
...
@@ -43,7 +43,6 @@ public class TournamentMatch extends GenericEntity implements Serializable {
@Temporal
(
TemporalType
.
TIMESTAMP
)
@Temporal
(
TemporalType
.
TIMESTAMP
)
private
Date
endTime
;
private
Date
endTime
;
@OneToMany
@OrderBy
(
"rank"
)
@OrderBy
(
"rank"
)
private
List
<
TournamentMatchResult
>
matchResults
;
private
List
<
TournamentMatchResult
>
matchResults
;
...
...
code/MoyaDatabase/src/fi/codecrew/moya/model/TournamentParticipant.java
View file @
055e367
...
@@ -32,4 +32,29 @@ public class TournamentParticipant extends GenericEntity implements Serializable
...
@@ -32,4 +32,29 @@ public class TournamentParticipant extends GenericEntity implements Serializable
public
TournamentParticipant
()
{
public
TournamentParticipant
()
{
super
();
super
();
}
}
public
EventUser
getParticipator
()
{
return
participator
;
}
public
void
setParticipator
(
EventUser
participator
)
{
this
.
participator
=
participator
;
}
public
List
<
EventUser
>
getTeamMembers
()
{
return
teamMembers
;
}
public
void
setTeamMembers
(
List
<
EventUser
>
teamMembers
)
{
this
.
teamMembers
=
teamMembers
;
}
public
Tournament
getTournament
()
{
return
tournament
;
}
public
void
setTournament
(
Tournament
tournament
)
{
this
.
tournament
=
tournament
;
}
}
}
code/MoyaWeb/WebContent/tournaments/admin/createwizard.xhtml
View file @
055e367
...
@@ -81,7 +81,7 @@
...
@@ -81,7 +81,7 @@
</h:selectOneMenu>
</h:selectOneMenu>
<br
/>
<br
/>
<h:outputText
value=
"#{i18n['tournaments.
players_per_match
']}"
/>
<h:outputText
value=
"#{i18n['tournaments.
max_participants
']}"
/>
<h:panelGrid
columns=
"1"
style=
"margin-bottom:10px"
>
<h:panelGrid
columns=
"1"
style=
"margin-bottom:10px"
>
<p:inputText
id=
"maxPartSlider"
value=
"#{tournamentCreateView.tournament.maxParticipants}"
/>
<p:inputText
id=
"maxPartSlider"
value=
"#{tournamentCreateView.tournament.maxParticipants}"
/>
<p:slider
for=
"maxPartSlider"
/>
<p:slider
for=
"maxPartSlider"
/>
...
...
code/MoyaWeb/WebContent/tournaments/index.xhtml
View file @
055e367
...
@@ -5,14 +5,13 @@
...
@@ -5,14 +5,13 @@
<h:body>
<h:body>
<ui:composition
template=
"#{sessionHandler.template}"
>
<ui:composition
template=
"#{sessionHandler.template}"
>
<f:metadata>
<f:metadata>
<f:event
type=
"preRenderView"
listener=
"#{tournamentListView.initView()}"
/>
</f:metadata>
</f:metadata>
<ui:define
name=
"content"
>
<ui:define
name=
"content"
>
<h
1>
#{i18n['tournaments.title']}
</h1
>
<h
:form
>
<p>
#{i18n['tournaments.description']}
</p
>
<p:messages
autoUpdate=
"true"
redisplay=
"false"
></p:messages
>
<h1>
#{i18n['tournaments.title']}
</h1>
<h:panelGroup
rendered=
"#{not empty tournamentListView.setupPhaseTournaments}"
>
<p>
#{i18n['tournaments.description']}
</p
>
<h2>
#{i18n['tournaments.open_tournaments']}
</h2>
<h2>
#{i18n['tournaments.open_tournaments']}
</h2>
<p:dataTable
value=
"#{tournamentListView.setupPhaseTournaments}"
var=
"tournament"
>
<p:dataTable
value=
"#{tournamentListView.setupPhaseTournaments}"
var=
"tournament"
>
<p:column>
<p:column>
...
@@ -51,8 +50,17 @@
...
@@ -51,8 +50,17 @@
</f:facet>
</f:facet>
<h:outputText
value=
"#{tournament.rules.name}"
/>
<h:outputText
value=
"#{tournament.rules.name}"
/>
</p:column>
</p:column>
<p:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"#{i18n['tournament.control']}"
/>
</f:facet>
<h:panelGroup>
<p:commandButton
value=
"#{i18n['tournament.participate']}"
action=
"#{tournamentParticipateView.participate(tournament.id)}"
rendered=
"#{tournament.participants.size() lt tournament.maxParticipants}"
ajax=
"false"
/>
<h:outputText
value=
"#{i18n['tournament.full']}"
rendered=
"#{tournament.participants.size() ge tournament.maxParticipants}"
/>
</h:panelGroup>
</p:column>
</p:dataTable>
</p:dataTable>
</h:panelGroup
>
</h:form
>
</ui:define>
</ui:define>
</ui:composition>
</ui:composition>
</h:body>
</h:body>
...
...
code/MoyaWeb/WebContent/tournaments/participate_single.xhtml
0 → 100644
View file @
055e367
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:users=
"http://java.sun.com/jsf/composite/cditools/user"
xmlns:tools=
"http://java.sun.com/jsf/composite/cditools"
xmlns:p=
"http://primefaces.org/ui"
xmlns:f=
"http://java.sun.com/jsf/core"
>
<h:body>
<ui:composition
template=
"#{sessionHandler.template}"
>
<f:metadata>
</f:metadata>
<ui:define
name=
"content"
>
<h1>
#{i18n['tournaments.participate_title']} #{tournamentParticipateView.tournament.tournamentName}
</h1>
<p>
#{i18n['tournaments.participate_description']}
</p>
<h2>
#{i18n['tournaments.participate_rules']}
</h2>
<p><h:outputText
value=
"#{tournamentParticipateView.tournament.rules.rules}"
escape=
"false"
/></p>
<h:form>
<p:commandButton
value=
"#{i18n['tournaments.cancel_participation']}"
action=
"#{tournamentParticipateView.cancelParticipation}"
/>
<p:commandButton
value=
"#{i18n['tournaments.accept_rules_and_participate']}"
action=
"#{tournamentParticipateView.saveParticipation}"
/>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/tournaments/TournamentListView.java
View file @
055e367
...
@@ -15,26 +15,16 @@ import fi.codecrew.moya.model.Tournament;
...
@@ -15,26 +15,16 @@ import fi.codecrew.moya.model.Tournament;
public
class
TournamentListView
{
public
class
TournamentListView
{
@EJB
private
TournamentBeanLocal
tournamentBean
;
@EJB
private
TournamentBeanLocal
tournamentBean
;
private
List
<
Tournament
>
setupPhaseTournaments
;
private
List
<
Tournament
>
inProgressTournaments
;
private
List
<
Tournament
>
completedTournaments
;
public
void
initView
()
{
setupPhaseTournaments
=
tournamentBean
.
getTournamentsInStatus
(
TournamentStatus
.
SETUP
);
inProgressTournaments
=
tournamentBean
.
getTournamentsInStatus
(
TournamentStatus
.
IN_PROGRESS
);
completedTournaments
=
tournamentBean
.
getTournamentsInStatus
(
TournamentStatus
.
COMPLETED
);
}
public
List
<
Tournament
>
getSetupPhaseTournaments
()
{
public
List
<
Tournament
>
getSetupPhaseTournaments
()
{
return
setupPhaseTournaments
;
return
tournamentBean
.
getTournamentsInStatus
(
TournamentStatus
.
SETUP
)
;
}
}
public
List
<
Tournament
>
getInProgressTournaments
()
{
public
List
<
Tournament
>
getInProgressTournaments
()
{
return
inProgressTournaments
;
return
tournamentBean
.
getTournamentsInStatus
(
TournamentStatus
.
IN_PROGRESS
)
;
}
}
public
List
<
Tournament
>
getCompletedTournaments
()
{
public
List
<
Tournament
>
getCompletedTournaments
()
{
return
completedTournaments
;
return
tournamentBean
.
getTournamentsInStatus
(
TournamentStatus
.
COMPLETED
)
;
}
}
}
}
code/MoyaWeb/src/fi/codecrew/moya/web/cdiview/tournaments/TournamentParticipateView.java
0 → 100644
View file @
055e367
package
fi
.
codecrew
.
moya
.
web
.
cdiview
.
tournaments
;
import
java.util.ArrayList
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.ConversationScoped
;
import
javax.inject.Named
;
import
fi.codecrew.moya.beans.PermissionBeanLocal
;
import
fi.codecrew.moya.beans.TournamentBeanLocal
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Tournament
;
import
fi.codecrew.moya.model.TournamentParticipant
;
import
fi.codecrew.moya.utilities.I18n
;
import
fi.codecrew.moya.utilities.jsf.MessageHelper
;
import
fi.codecrew.moya.web.cdiview.GenericCDIView
;
@Named
@ConversationScoped
public
class
TournamentParticipateView
extends
GenericCDIView
{
private
static
final
long
serialVersionUID
=
8002140932622853455L
;
private
Tournament
tournament
;
private
TournamentParticipant
tournamentParticipant
;
@EJB
private
TournamentBeanLocal
tournamentBean
;
@EJB
private
PermissionBeanLocal
permissionBean
;
public
String
participate
(
Integer
tournamentId
)
{
tournament
=
tournamentBean
.
getTournamentById
(
tournamentId
);
if
(
tournamentBean
.
hasParticipations
(
permissionBean
.
getCurrentUser
(),
tournament
))
{
MessageHelper
.
err
(
I18n
.
get
(
"tournament.already_participated_into_tournament"
));
return
"/tournaments/index.xhtml"
;
}
this
.
beginConversation
();
if
(
tournament
!=
null
)
{
tournamentParticipant
=
new
TournamentParticipant
();
tournamentParticipant
.
setTournament
(
tournament
);
tournamentParticipant
.
setParticipator
(
permissionBean
.
getCurrentUser
());
tournamentParticipant
.
setTeamMembers
(
new
ArrayList
<
EventUser
>());
tournamentParticipant
.
getTeamMembers
().
add
(
permissionBean
.
getCurrentUser
());
if
(
tournament
.
getPlayersPerTeam
()
==
1
)
{
return
"/tournaments/participate_single.xhtml"
;
}
else
{
return
"/tournaments/index.xhtml"
;
}
}
else
{
return
"/tournaments/index.xhtml"
;
}
}
public
String
saveParticipation
()
{
if
(
tournamentParticipant
!=
null
)
{
try
{
tournamentBean
.
createParticipation
(
tournamentParticipant
);
MessageHelper
.
info
(
I18n
.
get
(
"tournament.admin.tournament_participation_success"
));
}
catch
(
Exception
e
)
{
MessageHelper
.
err
(
I18n
.
get
(
e
.
getMessage
()));
}
}
else
{
MessageHelper
.
err
(
I18n
.
get
(
"tournament.admin.tournament_participation_failed"
));
}
this
.
endConversation
();
return
"/tournaments/index.xhtml"
;
}
public
String
cancelParticipation
()
{
this
.
endConversation
();
return
"/tournaments/index.xhtml"
;
}
public
Tournament
getTournament
()
{
return
tournament
;
}
public
void
setTournament
(
Tournament
tournament
)
{
this
.
tournament
=
tournament
;
}
}
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