Commit 04e15be0 by Tuomas Riihimäki

Refactory EventOrganizer entity to not hold all events

1 parent a12010d9
......@@ -71,4 +71,6 @@ public interface EventBeanLocal {
List<LanEvent> findFutureAndRunningEventsForCurrentUser();
List<LanEvent> findFutureEvents();
List<LanEvent> findAllEventsForOrganizer(EventOrganiser organiser);
}
/*
* Copyright Codecrew Ry
*
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.beans;
......@@ -289,7 +289,7 @@ public class EventBean implements EventBeanLocal {
public LanEventPrivateProperty saveOrCreatePrivateProperty(LanEventPrivateProperty privateProperty) {
LanEventPrivateProperty ret = null;
logger.info("Saving property {}, eventorg {}, key {}", new Object[] { privateProperty.getEvent(), privateProperty.getEventorg(), privateProperty.getKey() });
if (privateProperty.getId() == null) {
ret = privateProperty;
eventPrivatePropertyFacade.create(privateProperty);
......@@ -373,4 +373,10 @@ public class EventBean implements EventBeanLocal {
return eventFacade.findFutureEvents();
}
@Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT)
public List<LanEvent> findAllEventsForOrganizer(EventOrganiser organiser) {
return eventFacade.findForOrganizer(organiser);
}
}
......@@ -128,4 +128,13 @@ public class EventFacade extends IntegerPkGenericFacade<LanEvent> {
return getEm().createQuery(cq).getResultList();
}
public List<LanEvent> findForOrganizer(EventOrganiser organizer) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<LanEvent> cq = cb.createQuery(LanEvent.class);
Root<LanEvent> root = cq.from(LanEvent.class);
cq.where(cb.equal(root.get(LanEvent_.organiser), organizer));
return getEm().createQuery(cq).getResultList();
}
}
......@@ -42,10 +42,6 @@ public class EventOrganiser extends GenericEntity {
@Column(name = "bundle_country")
private String bundleCountry;
@OrderBy
@OneToMany(cascade = CascadeType.ALL, mappedBy = "organiser")
private List<LanEvent> events;
@Column(nullable = false, name = "bill_address1")
private String billAddress1 = "";
@Column(nullable = false, name = "bill_address2")
......@@ -63,14 +59,6 @@ public class EventOrganiser extends GenericEntity {
@Column(nullable = false, name = "bank_name2")
private String bankName2 = "";
public List<LanEvent> getEvents() {
return events;
}
public void setEvents(List<LanEvent> eventList) {
this.events = eventList;
}
/**
* @return the organisation
*/
......
......@@ -70,7 +70,7 @@
</h:form>
<h2>#{i18n['eventorg.events']}</h2>
<h:dataTable border="1" id="org" value="#{eventorgView.eventorg.events}" var="event">
<h:dataTable border="1" id="org" value="#{eventorgView.organizersEvents}" var="event">
<h:column>
<f:facet name="header">
<h:outputText value="${i18n['event.name']}" />
......
......@@ -129,7 +129,7 @@
<p:fieldset legend="Tools" toggleable="true" collapsed="true">
<h:form>
<p:selectOneMenu value="#{eventorgView.copyParty}" converter="#{lanEventConverter}">
<f:selectItems value="#{eventorgView.event.organiser.events}" var="e" itemLabel="#{e.name}" />
<f:selectItems value="#{eventorgView.organizersEvents}" var="e" itemLabel="#{e.name}" />
</p:selectOneMenu>
<h:commandButton action="#{eventorgView.copySiteContent}" value="#{i18n['event.copySiteContent']}" />
......
......@@ -70,6 +70,7 @@ public class EventOrgView extends GenericCDIView {
private String eventname;
private List<EventOrganiser> organisations;
private List<LanEvent> oragnizersEvents;
private Integer eventid;
......@@ -86,28 +87,38 @@ public class EventOrgView extends GenericCDIView {
ScheduleModel eventsCalendar = null;
public void initCreate()
{
public void initCreate() {
if (super.requirePermissions(user.getUser().isSuperadmin())) {
super.beginConversation();
}
}
public String removeDomain()
{
public String removeDomain() {
event.getDomains().remove(eventdomains.getRowData());
setEvent(eventbean.mergeChanges(event));
return null;
}
public String saveEvent()
{
public List<LanEvent> getOrganizersEvents() {
if (oragnizersEvents == null) {
EventOrganiser org = eventorg;
if (org == null && event != null) {
org = event.getOrganiser();
}
if (org != null) {
oragnizersEvents = eventbean.findAllEventsForOrganizer(org);
}
}
return oragnizersEvents;
}
public String saveEvent() {
setEvent(eventbean.mergeChanges(event));
return null;
}
public String saveEventorg()
{
public String saveEventorg() {
setEventorg(eventbean.mergeChanges(eventorg));
return null;
}
......@@ -145,39 +156,29 @@ public class EventOrgView extends GenericCDIView {
}
}
public void initEditEvent()
{
if (eventid != null && super.requirePermissions(user.getUser().isSuperadmin() || eventorgbean.hasEventPermission(eventid)) && getEvent() == null)
{
public void initEditEvent() {
if (eventid != null && super.requirePermissions(user.getUser().isSuperadmin() || eventorgbean.hasEventPermission(eventid)) && getEvent() == null) {
setEvent(eventorgbean.findEvent(eventid));
super.beginConversation();
} else if (super.requirePermissions(EventPermission.MANAGE_PROPERTIES) && getEvent() == null)
{
} else if (super.requirePermissions(EventPermission.MANAGE_PROPERTIES) && getEvent() == null) {
setEvent(eventbean.getCurrentEvent());
super.beginConversation();
}
}
public String createEvent()
{
if (eventorg.getEvents() == null) {
eventorg.setEvents(new ArrayList<LanEvent>());
}
public String createEvent() {
event = new LanEvent();
event.setName(eventname);
event.setOrganiser(eventorg);
eventname = "";
eventorg.getEvents().add(getEvent());
eventbean.create(event);
//eventorg = eventorgbean.save(eventorg);
return "/eventorg/editEvent";
}
public String create()
{
public String create() {
eventorg = eventorgbean.create(createorgname);
createorgname = "";
......@@ -314,7 +315,7 @@ public class EventOrgView extends GenericCDIView {
public List<User> getSuperUsers() {
if(!permbean.getCurrentUser().isSuperadmin())
if (!permbean.getCurrentUser().isSuperadmin())
return new ArrayList<User>();
return userBean.findSuperusers();
......
......@@ -61,8 +61,7 @@ public class CreditTransferView extends GenericCDIView {
wrap.add(new EventUserWrapper(u));
}
this.users = wrap;
events = eventbean.getCurrentEvent().getOrganiser().getEvents();
events = eventbean.findAllEventsForOrganizer(eventbean.getCurrentEvent().getOrganiser());
}
public String selectEvent() {
......
......@@ -37,14 +37,11 @@ public class CurrentEventorgEventConverter extends GenericIntegerEntityConverter
protected LanEvent find(Integer id) {
LanEvent ret = null;
LanEvent curr = eventbean.getCurrentEvent();
if (curr.getId().equals(id))
{
if (curr.getId().equals(id)) {
ret = curr;
} else {
for (LanEvent e : curr.getOrganiser().getEvents())
{
if (e.getId().equals(id))
{
for (LanEvent e : eventbean.findAllEventsForOrganizer(curr.getOrganiser())) {
if (e.getId().equals(id)) {
ret = e;
break;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!