add participants to event

BUGGGGG and CRASH
This commit is contained in:
ff2009 2015-11-14 21:06:35 +00:00
parent 7eca928e13
commit 17f6402710
7 changed files with 113 additions and 33 deletions

View File

@ -5,7 +5,6 @@
*/ */
package dtos; package dtos;
import entity.Responsible;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -22,13 +21,13 @@ public class EventDTO implements Serializable {
private String local; private String local;
private int responsible_id; private int responsible_id;
private String responsible_name; private String responsible_name;
private boolean openInscrptions; private boolean openInscriptions;
public EventDTO() { public EventDTO() {
} }
public EventDTO(int id, Date date, String name, String type, String local, int responsible_id, String responsible_name) { public EventDTO(int id, Date date, String name, String type, String local, int responsible_id, String responsible_name, boolean openInscriptions) {
this.id = id; this.id = id;
this.date = date; this.date = date;
this.name = name; this.name = name;
@ -36,6 +35,9 @@ public class EventDTO implements Serializable {
this.local = local; this.local = local;
this.responsible_id = responsible_id; this.responsible_id = responsible_id;
this.responsible_name = responsible_name; this.responsible_name = responsible_name;
this.openInscriptions = openInscriptions;
} }
public void reset(){ public void reset(){
@ -104,6 +106,14 @@ public class EventDTO implements Serializable {
public void setResponsible_name(String responsible_name) { public void setResponsible_name(String responsible_name) {
this.responsible_name = responsible_name; this.responsible_name = responsible_name;
} }
public boolean isOpenInscriptions() {
return openInscriptions;
}
public void setOpenInscriptions(boolean openInscrptions) {
this.openInscriptions = openInscrptions;
}

View File

@ -129,8 +129,8 @@ public class EventBean {
if (event == null) { if (event == null) {
throw new EntityDoesNotExistsException("There is no event with that id."); throw new EntityDoesNotExistsException("There is no event with that id.");
} }
event.setOpenInscriptions(false);
em.remove(event);
} catch (EntityDoesNotExistsException e) { } catch (EntityDoesNotExistsException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
@ -179,7 +179,8 @@ public class EventBean {
event.getType(), event.getType(),
event.getLocal(), event.getLocal(),
event.getResponsible().getId(), event.getResponsible().getId(),
event.getResponsible().getName()); event.getResponsible().getName(),
event.isOpenInscriptions());
} }
List<EventDTO> eventsToDTOs(List<Event> events) { List<EventDTO> eventsToDTOs(List<Event> events) {

View File

@ -47,7 +47,7 @@ public class Event implements Serializable {
private String type; private String type;
@NotNull @NotNull
private String local; private String local;
private boolean openInscriptions;
@ManyToMany @ManyToMany
@JoinTable(name = "EVENT_PARTICIPANT", @JoinTable(name = "EVENT_PARTICIPANT",
@ -61,7 +61,7 @@ public class Event implements Serializable {
@JoinColumn(name = "RESPONSIBLE_ID") @JoinColumn(name = "RESPONSIBLE_ID")
@NotNull @NotNull
private Responsible responsible; private Responsible responsible;
private boolean openInscriptions;
// Add business logic below. (Right-click in editor and choose // Add business logic below. (Right-click in editor and choose

View File

@ -16,6 +16,8 @@ import ejbs.ParticipantBean;
import ejbs.ResponsibleBean; import ejbs.ResponsibleBean;
import ejbs.SubjectBean; import ejbs.SubjectBean;
import exceptions.EntityDoesNotExistsException; import exceptions.EntityDoesNotExistsException;
import exceptions.ParticipantEnrolledException;
import exceptions.ParticipantNotEnrolledException;
import java.util.List; import java.util.List;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
@ -49,6 +51,7 @@ public class AdministratorManager {
private ResponsibleDTO currentResponsible; private ResponsibleDTO currentResponsible;
private ParticipantDTO newParticipant; private ParticipantDTO newParticipant;
private ParticipantDTO currentParticipant; private ParticipantDTO currentParticipant;
private List<ParticipantDTO> listParticipants;
private EventDTO newEvent; private EventDTO newEvent;
private EventDTO currentEvent; private EventDTO currentEvent;
private UIComponent component; private UIComponent component;
@ -204,6 +207,12 @@ public class AdministratorManager {
logger.warning("Problem removing user in method removeUser()."); logger.warning("Problem removing user in method removeUser().");
} }
} }
public void printToScreen() {
System.out.println("participant: " + listParticipants);
//System.out.println("event: " + currentEvent.getName());
}
public List<ParticipantDTO> getAllParticipants() { public List<ParticipantDTO> getAllParticipants() {
return participantBean.getAllParticipants(); return participantBean.getAllParticipants();
@ -219,12 +228,12 @@ public class AdministratorManager {
} }
//////////////////////////// Event \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //////////////////////////// Event \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
public void openInscriptions(int eventId) throws EntityDoesNotExistsException { public void openInscriptions() throws EntityDoesNotExistsException {
eventBean.openInscriptions(eventId); eventBean.openInscriptions(currentEvent.getId());
} }
public void closeInscriptions(int eventId) throws EntityDoesNotExistsException { public void closeInscriptions() throws EntityDoesNotExistsException {
eventBean.closeInscriptions(eventId); eventBean.closeInscriptions(currentEvent.getId());
} }
public String createEvent() { public String createEvent() {
@ -281,7 +290,32 @@ public class AdministratorManager {
} }
public List<ParticipantDTO> getUnrolledParticipants() throws EntityDoesNotExistsException { public List<ParticipantDTO> getUnrolledParticipants() throws EntityDoesNotExistsException {
return participantBean.getUnrolledParticipants(currentEvent.getId()); return participantBean.getUnrolledParticipants(currentEvent.getId());
}
public void enrollParticipants(ActionEvent event) throws EntityDoesNotExistsException, ParticipantEnrolledException {
try{
UIParameter param = (UIParameter) event.getComponent().findComponent("participantId");
int id = Integer.parseInt(param.getValue().toString());
System.out.println("Participant Id: " + currentParticipant.getId() + "Event Id: " + currentEvent.getId());
participantBean.enrollParticipant(currentParticipant.getId(), currentEvent.getId());
} catch (Exception e) {
logger.warning("Problem enrolling participant in method enrollParticipants().");
}
}
public void unrollParticipants(ActionEvent event) throws EntityDoesNotExistsException, ParticipantNotEnrolledException {
try{
UIParameter param = (UIParameter) event.getComponent().findComponent("participantId");
int id = Integer.parseInt(param.getValue().toString());
participantBean.unrollParticipant(currentParticipant.getId(), currentEvent.getId());
} catch (Exception e) {
logger.warning("Problem enrolling participant in method enrollParticipants().");
}
} }
public AdministratorBean getAdministratorBean() { public AdministratorBean getAdministratorBean() {
@ -396,4 +430,19 @@ public class AdministratorManager {
this.currentEvent = currentEvent; this.currentEvent = currentEvent;
} }
public List<ParticipantDTO> getListParticipants() {
return listParticipants;
}
public void setListParticipants(List<ParticipantDTO> listParticipants) {
this.listParticipants = listParticipants;
}
} }

View File

@ -14,15 +14,14 @@ and open the template in the editor.
</head> </head>
<body> <body>
<div>Lista de Utilizadores / Participantes : </div> <div>Lista de Utilizadores / Participantes : </div>
<br></br>
<h:form> <h:form>
<h:column> <h:column>
<h:selectManyMenu <h:selectManyListbox
id="participant" id="participant"
value="#{administratorManager.currentParticipant.id}" value="#{administratorManager.listParticipants}"
style="height: 500px"
title="Add participants to Event" title="Add participants to Event"
> >
<f:selectItems <f:selectItems
value="#{administratorManager.allParticipants}" value="#{administratorManager.allParticipants}"
@ -30,9 +29,22 @@ and open the template in the editor.
itemValue="#{participant.id}" itemValue="#{participant.id}"
itemLabel="#{participant.name}" itemLabel="#{participant.name}"
/> />
</h:selectManyMenu> </h:selectManyListbox >
</h:column> </h:column>
<br></br>
<h:commandButton value="Submit" action="result" />
<h:commandButton value="Reset" type="reset" />
<h:panelGrid>
<h:commandButton
id="submit"
value="Submit"
action="#{administratorManager.printToScreen}">
</h:commandButton>
<h:message for="submit" />
</h:panelGrid>
</h:form> </h:form>
</body> </body>

View File

@ -13,8 +13,6 @@ and open the template in the editor.
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head> </head>
<body> <body>
<div>Event Details</div>
<h:dataTable value="#{administratorManager.currentEvent}" var="event">
<div>Event Details:</div> <div>Event Details:</div>
<h:dataTable value="#{administratorManager.currentEvent}" <h:dataTable value="#{administratorManager.currentEvent}"
var="event" var="event"
@ -81,15 +79,14 @@ and open the template in the editor.
<h:outputText value="#{participant.email}"/> <h:outputText value="#{participant.email}"/>
</h:column> </h:column>
<h:column>
<h:form> <h:form>
<h:commandLink value="Add participant" action="event_detais?faces-redirect=true"> <h:commandLink value="Add participant" actionListener="#{administratorManager.unrollParticipants}">
<f:setPropertyActionListener target="#{administratorManager.currentParticipant}" value="#{participant}" /> <f:param name="participantId" id="participantId" value="#{participant}"/>
</h:commandLink>
<h:commandLink value="Add participant" actionListener="#{administratorManager.enrollParticipant}">
<f:param name="administratorID" id="administratorID" value="#{administrator.id}"/>
</h:commandLink> </h:commandLink>
</h:form> </h:form>
</h:column>
</h:dataTable> </h:dataTable>
<br></br> <br></br>
@ -115,6 +112,15 @@ and open the template in the editor.
<h:outputText value="#{participant.email}"/> <h:outputText value="#{participant.email}"/>
</h:column> </h:column>
<h:column>
<h:form>
<h:commandLink value="Add participant" actionListener="#{administratorManager.enrollParticipants}">
<f:param name="participantId" id="participantId" value="#{participant}"/>
</h:commandLink>
</h:form>
</h:column>
</h:dataTable> </h:dataTable>
<br></br> <br></br>

View File

@ -35,7 +35,7 @@ and open the template in the editor.
<h:form> <h:form>
<h:commandLink action="admin_responsible_update" value="Criar Responsavel"></h:commandLink> <h:commandLink action="admin_responsible_update" value="Criar Responsavel"></h:commandLink>
</h:form> </h:form>
<br></br><br></br> <br></br><br></br>
<div>Responsible Events</div> <div>Responsible Events</div>
<h:dataTable value="#{administratorManager.currentResponsibleEvents}" <h:dataTable value="#{administratorManager.currentResponsibleEvents}"
@ -68,15 +68,17 @@ and open the template in the editor.
<f:facet name="header"> <f:facet name="header">
<h:outputText value="Actions" /> <h:outputText value="Actions" />
</f:facet> </f:facet>
<h:form>
<h:commandLink value="Open inscriptions" action="responsible_details?faces-redirect=true"> <h:commandLink value="Open inscriptions" action="responsible_details?faces-redirect=true">
<f:setPropertyActionListener target="#{administratorManager.openInscriptions(event.id)}" value="#{responsible}" /> <f:setPropertyActionListener target="#{administratorManager.openInscriptions}" value="#{event}" />
</h:commandLink> </h:commandLink>
</h:form>
<div></div>
<h:form rendered="#{event.openInscriptions}">
<h:commandLink value="Close inscriptions" action="responsible_details?faces-redirect=true"> <h:commandLink value="Close inscriptions" action="responsible_details?faces-redirect=true">
<f:setPropertyActionListener target="#{administratorManager.closeInscriptions(event.id)}" value="#{responsible}" /> <f:setPropertyActionListener target="#{administratorManager.closeInscriptions}" value="#{event}" />
</h:commandLink> </h:commandLink>
<f:facet name="header">Responsible</f:facet> </h:form>
<h:outputText value="#{event.responsible_name}"/>
</h:column> </h:column>
<h:column> <h:column>
<f:facet name="header">Add Participants</f:facet> <f:facet name="header">Add Participants</f:facet>