Commit 9c15227b by Antti Tonkyra

Tournament shenanigans

1 parent 863ae773
...@@ -6,6 +6,7 @@ import javax.ejb.EJB; ...@@ -6,6 +6,7 @@ import javax.ejb.EJB;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
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.TournamentRuleFacade; import fi.codecrew.moya.facade.TournamentRuleFacade;
...@@ -65,4 +66,9 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -65,4 +66,9 @@ public class TournamentBean implements TournamentBeanLocal {
public void createTournament(Tournament tournament) { public void createTournament(Tournament tournament) {
tournamentFacade.create(tournament); tournamentFacade.create(tournament);
} }
@Override
public List<Tournament> getActiveTournaments() {
return tournamentFacade.getTournamentsNotInStatus(TournamentStatus.COMPLETED);
}
} }
package fi.codecrew.moya.facade; package fi.codecrew.moya.facade;
import java.util.List;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import fi.codecrew.moya.enums.TournamentStatus;
import fi.codecrew.moya.model.Tournament; import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.Tournament_;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.model.User_;
@Stateless @Stateless
@LocalBean @LocalBean
...@@ -11,5 +20,15 @@ public class TournamentFacade extends IntegerPkGenericFacade<Tournament> { ...@@ -11,5 +20,15 @@ public class TournamentFacade extends IntegerPkGenericFacade<Tournament> {
public TournamentFacade() { public TournamentFacade() {
super(Tournament.class); super(Tournament.class);
} }
public List<Tournament> getTournamentsNotInStatus(TournamentStatus status) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Tournament> cq = cb.createQuery(Tournament.class);
Root<Tournament> root = cq.from(Tournament.class);
cq.where(cb.notEqual(root.get(Tournament_.tournamentStatus), status));
return getEm().createQuery(cq).getResultList();
}
} }
...@@ -18,5 +18,6 @@ public interface TournamentBeanLocal { ...@@ -18,5 +18,6 @@ public interface TournamentBeanLocal {
TournamentGame findGame(Integer id); TournamentGame findGame(Integer id);
TournamentRule findRule(Integer id); TournamentRule findRule(Integer id);
void createTournament(Tournament tournament); void createTournament(Tournament tournament);
List<Tournament> getActiveTournaments();
} }
...@@ -65,14 +65,6 @@ public class Tournament extends GenericEntity implements Serializable { ...@@ -65,14 +65,6 @@ public class Tournament extends GenericEntity implements Serializable {
@JoinColumn(name="rules", nullable=false) @JoinColumn(name="rules", nullable=false)
private TournamentRule rules; private TournamentRule rules;
public TournamentRule getRules() {
return rules;
}
public void setRules(TournamentRule rules) {
this.rules = rules;
}
@OneToMany @OneToMany
@OrderBy("id ASC") @OrderBy("id ASC")
...@@ -183,4 +175,11 @@ public class Tournament extends GenericEntity implements Serializable { ...@@ -183,4 +175,11 @@ public class Tournament extends GenericEntity implements Serializable {
public void setSubTournaments(List<Tournament> subTournaments) { public void setSubTournaments(List<Tournament> subTournaments) {
this.subTournaments = subTournaments; this.subTournaments = subTournaments;
} }
public TournamentRule getRules() {
return rules;
}
public void setRules(TournamentRule rules) {
this.rules = rules;
}
} }
...@@ -13,7 +13,44 @@ ...@@ -13,7 +13,44 @@
<h1>#{i18n['tournaments.admin.title']}</h1> <h1>#{i18n['tournaments.admin.title']}</h1>
<p>#{i18n['tournaments.admin.description']}</p> <p>#{i18n['tournaments.admin.description']}</p>
<h2>#{i18n['tournaments.active_tournaments']}</h2> <h2>#{i18n['tournaments.active_tournaments']}</h2>
<!-- <p:dataTable styleClass="bordertable" id="actionlogtable" value="#{actionLogMessageView.messages}" var="message" paginator="true" rows="30" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="10,20,30,50,100" > --> <p:dataTable value="#{tournamentAdminView.activeTournaments}" var="tournament">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.name']}" />
</f:facet>
<h:outputText value="#{tournament.tournamentName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.status']}" />
</f:facet>
<h:outputText value="#{tournament.tournamentStatus}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.type']}" />
</f:facet>
<h:outputText value="#{tournament.tournamentType}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.playerspermatch_slash_teamsize']}" />
</f:facet>
<h:outputText value="#{tournament.playersPerMatch}/#{tournament.playersPerTeam}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.game']}" />
</f:facet>
<h:outputText value="#{tournament.tournamentGame.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['tournament.rules']}" />
</f:facet>
<h:outputText value="#{tournament.rules.name}" />
</p:column>
</p:dataTable>
</ui:define> </ui:define>
......
...@@ -15,6 +15,7 @@ public class TournamentAdminView { ...@@ -15,6 +15,7 @@ public class TournamentAdminView {
@EJB private TournamentBeanLocal tournamentBean; @EJB private TournamentBeanLocal tournamentBean;
public List<Tournament> getActiveTournaments() { public List<Tournament> getActiveTournaments() {
return null; List<Tournament> tl = tournamentBean.getActiveTournaments();
return tl;
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!