Commit f4d8f93b by Antti Jaakkola

Merge branch 'devel' of codecrew.fi:bortal into devel

2 parents e95be4fc c5592bac
package fi.codecrew.moya.beans;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import fi.codecrew.moya.facade.TournamentGameFacade;
import fi.codecrew.moya.facade.TournamentRuleFacade;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentRule;
/**
* Session Bean implementation class TournamentBean
*/
......@@ -10,11 +19,43 @@ import javax.ejb.Stateless;
@LocalBean
public class TournamentBean implements TournamentBeanLocal {
@EJB private TournamentRuleFacade tournamentRuleFacade;
@EJB private TournamentGameFacade tournamentGameFacade;
/**
* Default constructor.
*/
public TournamentBean() {
// TODO Auto-generated constructor stub
}
@Override
public List<TournamentRule> getRulesByGame(TournamentGame tg) {
return tournamentRuleFacade.getRulesByGame(tg);
}
@Override
public List<TournamentGame> getGames() {
return tournamentGameFacade.getGames();
}
@Override
public void createGame(TournamentGame tg) {
tournamentGameFacade.create(tg);
}
@Override
public void createRule(TournamentRule tr) {
tournamentRuleFacade.create(tr);
}
@Override
public TournamentGame findGame(Integer id) {
return tournamentGameFacade.find(id);
}
@Override
public TournamentRule findRule(Integer id) {
return tournamentRuleFacade.find(id);
}
}
package fi.codecrew.moya.facade;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import fi.codecrew.moya.beans.EventBean;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentGame_;
import fi.codecrew.moya.model.TournamentRule;
import fi.codecrew.moya.model.TournamentRule_;
@Stateless
@LocalBean
public class TournamentGameFacade extends IntegerPkGenericFacade<TournamentGame> {
@EJB private EventBean eventBean;
public TournamentGameFacade() {
super(TournamentGame.class);
}
public List<TournamentGame> getGames() {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<TournamentGame> cq = cb.createQuery(TournamentGame.class);
Root<TournamentGame> root = cq.from(TournamentGame.class);
cq.where(cb.equal(root.get(TournamentGame_.lanEvent), eventBean.getCurrentEvent()));
return getEm().createQuery(cq).getResultList();
}
}
package fi.codecrew.moya.facade;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import fi.codecrew.moya.beans.EventBean;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.Role_;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentRule;
import fi.codecrew.moya.model.TournamentRule_;
@Stateless
@LocalBean
public class TournamentRuleFacade extends IntegerPkGenericFacade<TournamentRule> {
public TournamentRuleFacade() {
super(TournamentRule.class);
}
public List<TournamentRule> getRulesByGame(TournamentGame tg) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<TournamentRule> cq = cb.createQuery(TournamentRule.class);
Root<TournamentRule> root = cq.from(TournamentRule.class);
cq.where(cb.equal(root.get(TournamentRule_.tournamentGame), tg));
return getEm().createQuery(cq).getResultList();
}
}
package fi.codecrew.moya.beans;
import java.util.List;
import javax.ejb.Local;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentRule;
@Local
public interface TournamentBeanLocal {
List<TournamentGame> getGames();
List<TournamentRule> getRulesByGame(TournamentGame tg);
void createGame(TournamentGame tg);
void createRule(TournamentRule tr);
TournamentGame findGame(Integer id);
TournamentRule findRule(Integer id);
}
......@@ -59,4 +59,20 @@ public class TournamentGame extends GenericEntity implements Serializable {
public void setAvailableRules(List<TournamentRule> availableRules) {
this.availableRules = availableRules;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public LanEvent getLanEvent() {
return lanEvent;
}
public void setLanEvent(LanEvent lanEvent) {
this.lanEvent = lanEvent;
}
}
......@@ -9,82 +9,78 @@
</f:metadata>
<ui:define name="content">
<h1>#{i18n['actionlog.tournaments.admin.create_tournament']}</h1>
<h1>#{i18n['tournaments.admin.create_tournament']}</h1>
<h:form>
<p:wizard widgetVar="wiz" flowListener="#{tournamentCreateView.onFlowProcess}">
<p:tab id="selectGame" title="#{i18n['actionlog.tournaments.admin.select_a_game']}">
<p:tab id="selectGame" title="#{i18n['tournaments.admin.select_a_game']}">
<p:panel>
<h:messages errorClass="error" />
<h2>#{i18n['actionlog.tournaments.admin.select_a_game']}</h2>
<p:selectOneMenu>
<f:selectItem itemLabel="" />
<f:selectItem itemLabel="spurdo spärde" />
<f:selectItem itemLabel="cockmaster" />
</p:selectOneMenu>
<h:panelGroup rendered="#{tournamentCreateView.tournamentGames.isEmpty() eq false}">
<h2>#{i18n['tournaments.admin.select_a_game']}</h2>
<h:selectOneMenu value="#{tournamentCreateView.game}" converter="#{tournamentGameConverter}">
<f:selectItems var="game" itemLabel="#{game.name}" value="#{tournamentCreateView.tournamentGames}" itemValue="#{game.id}" />
</h:selectOneMenu>
</h:panelGroup>
<h2>#{i18n['actionlog.tournaments.admin.create_a_game']}</h2>
<h2>#{i18n['tournaments.admin.create_a_game']}</h2>
<h:panelGrid columns="2">
<h:outputText value="#{i18n['actionlog.tournaments.admin.game_name']}" />
<h:outputText value="#{i18n['actionlog.tournaments.admin.game_description']}" />
<h:outputText value="#{i18n['tournaments.admin.game_name']}" />
<h:outputText value="#{i18n['tournaments.admin.game_description']}" />
<p:inputText />
<p:inputText />
<h:outputText value="#{i18n['actionlog.tournaments.admin.upload_game_image']}" />
<h:outputText value="" />
<p:fileUpload mode="simple" />
<p:inputText value="#{tournamentCreateView.tournamentGameName}" />
<p:inputText value="#{tournamentCreateView.tournamentGameDescription}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="selectRuleset" title="#{i18n['actionlog.tournaments.admin.rules']}">
<p:tab id="selectRuleset" title="#{i18n['tournaments.admin.rules']}">
<p:panel>
<h:messages errorClass="error" />
<h2>#{i18n['actionlog.tournaments.admin.select_a_ruleset']}</h2>
<p:selectOneMenu>
<f:selectItem itemLabel="" />
<f:selectItem itemLabel="Pro-rules" />
<f:selectItem itemLabel="N00b-rules" />
</p:selectOneMenu>
<h:panelGroup rendered="#{tournamentCreateView.tournamentRules.isEmpty() eq false}">
<h2>#{i18n['tournaments.admin.select_a_ruleset']}</h2>
<h:selectOneMenu value="#{tournamentCreateView.rules}" converter="#{tournamentRuleConverter}">
<f:selectItems var="rule" itemLabel="#{rule.name}" value="#{tournamentCreateView.tournamentRules}" itemValue="#{rule.id}" />
</h:selectOneMenu>
</h:panelGroup>
<br />
<h2>#{i18n['actionlog.tournaments.admin.create_new_ruleset']}</h2>
<h:outputText value="#{i18n['actionlog.tournaments.ruleset_name']}" />
<h2>#{i18n['tournaments.admin.create_new_ruleset']}</h2>
<h:outputText value="#{i18n['tournaments.ruleset_name']}" />
<br />
<p:inputText />
<p:inputText value="#{tournamentCreateView.rulesetName}" />
<br />
<h:outputText value="#{i18n['actionlog.tournaments.ruleset_description']}" />
<h:outputText value="#{i18n['tournaments.ruleset_description']}" />
<br />
<p:inputTextarea />
<p:inputTextarea value="#{tournamentCreateView.rulesetDescription}"/>
</p:panel>
</p:tab>
<p:tab id="selectRegTimes" title="#{i18n['actionlog.tournaments.admin.set_time_constraints']}">
<p:tab id="selectRegTimes" title="#{i18n['tournaments.admin.set_time_constraints']}">
<p:panel>
<h:messages errorClass="error" />
<h2>#{i18n['actionlog.tournaments.admin.registration_time_constraints']}</h2>
<h2>#{i18n['tournaments.admin.registration_time_constraints']}</h2>
<h:panelGrid columns="2">
<h:outputText value="#{i18n['actionlog.tournaments.registration_opens']}" />
<h:outputText value="#{i18n['actionlog.tournaments.registration_closes']}" />
<h:outputText value="#{i18n['tournaments.registration_opens']}" />
<h:outputText value="#{i18n['tournaments.registration_closes']}" />
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" />
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" />
</h:panelGrid>
<h2>#{i18n['actionlog.tournaments.admin.begin_time_constraints']}</h2>
<h2>#{i18n['tournaments.admin.begin_time_constraints']}</h2>
<h:panelGrid>
<h:outputText value="Start time" />
<p:calendar stepHour="1" stepMinute="10" pattern="dd.MM.yyyy hh:mm" />
</h:panelGrid>
</p:panel>
<div style="float: right;">
<p:commandButton icon="apply" value="#{i18n['actionlog.tournaments.admin.create_tournament']}" />
<p:commandButton icon="apply" value="#{i18n['tournaments.admin.create_tournament']}" />
</div>
</p:tab>
</p:wizard>
......
package fi.codecrew.moya.web.cdiview.tournaments;
import java.io.Serializable;
import java.util.List;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.Tournament;
......@@ -21,26 +23,121 @@ import org.primefaces.event.FlowEvent;
public class TournamentCreateView extends GenericCDIView {
private static final long serialVersionUID = 2547358764980373797L;
private List<TournamentGame> tournamentGames;
private List<TournamentRule> tournamentRules;
private TournamentRule rules = null;
private TournamentGame game = null;
private Tournament tournament = null;
private String tournamentGameName;
private String tournamentGameDescription;
private String rulesetName;
private String rulesetDescription;
@EJB TournamentBeanLocal tournamentBean;
@EJB EventBeanLocal eventBean;
public void initView() {
if(tournament == null) {
this.beginConversation();
tournament = new Tournament();
tournamentGames = tournamentBean.getGames();
}
}
public void save(ActionEvent actionEvent) {
}
public List<TournamentGame> getTournamentGames() {
return tournamentGames;
}
public List<TournamentRule> getTournamentRules() {
return tournamentRules;
}
public void uploadListener(org.primefaces.event.FileUploadEvent event) {
System.out.println("ZZ");
}
public String onFlowProcess(FlowEvent event) {
switch(event.getOldStep()) {
case "selectGame":
if(tournamentGameName.length() > 0) {
// oh lurd, we want to create a new gamy now
TournamentGame tg = new TournamentGame();
tg.setName(tournamentGameName);
tg.setDescription(tournamentGameDescription);
tg.setLanEvent(eventBean.getCurrentEvent());
tournamentBean.createGame(tg);
}
tournamentRules = tournamentBean.getRulesByGame(this.getGame());
break;
case "selectRuleset":
if(rulesetName != null && rulesetName.length() > 0) {
TournamentRule tr = new TournamentRule();
tr.setName(rulesetName);
tr.setDescription(rulesetDescription);
tournamentBean.createRule(tr);
}
break;
}
System.out.println(event.getOldStep());
return event.getNewStep();
}
public TournamentGame getGame() {
return game;
}
public void setGame(TournamentGame game) {
this.game = game;
}
public TournamentRule getRules() {
return rules;
}
public void setRules(TournamentRule rules) {
this.rules = rules;
}
public String getTournamentGameName() {
return tournamentGameName;
}
public void setTournamentGameName(String tournamentGameName) {
this.tournamentGameName = tournamentGameName;
}
public String getTournamentGameDescription() {
return tournamentGameDescription;
}
public void setTournamentGameDescription(String tournamentGameDescription) {
this.tournamentGameDescription = tournamentGameDescription;
}
public String getRulesetName() {
return rulesetName;
}
public void setRulesetName(String rulesetName) {
this.rulesetName = rulesetName;
}
public String getRulesetDescription() {
return rulesetDescription;
}
public void setRulesetDescription(String rulesetDescription) {
this.rulesetDescription = rulesetDescription;
}
}
package fi.codecrew.moya.web.converter;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.utilities.jsf.GenericIntegerEntityConverter;
@Named
@RequestScoped
public class TournamentGameConverter extends GenericIntegerEntityConverter<TournamentGame> {
@EJB private TournamentBeanLocal tournamentBean;
@Override
protected TournamentGame find(Integer id) {
return tournamentBean.findGame(id);
}
}
package fi.codecrew.moya.web.converter;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.TournamentGame;
import fi.codecrew.moya.model.TournamentRule;
import fi.codecrew.moya.utilities.jsf.GenericIntegerEntityConverter;
@Named
@RequestScoped
public class TournamentRuleConverter extends GenericIntegerEntityConverter<TournamentRule> {
@EJB private TournamentBeanLocal tournamentBean;
@Override
protected TournamentRule find(Integer id) {
return tournamentBean.findRule(id);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!