Commit 5cc92394 by Tuukka Kivilahti

Merge remote-tracking branch 'origin' into user_selectable_groups

2 parents 715d68ad 9366fc3c
...@@ -50,6 +50,10 @@ import fi.codecrew.moya.util.MailMessage; ...@@ -50,6 +50,10 @@ import fi.codecrew.moya.util.MailMessage;
@DeclareRoles({ UserPermission.S_WRITE_ROLES }) @DeclareRoles({ UserPermission.S_WRITE_ROLES })
public class CardTemplateBean implements CardTemplateBeanLocal { public class CardTemplateBean implements CardTemplateBeanLocal {
private static final Logger logger = LoggerFactory.getLogger(CardTemplateBean.class); private static final Logger logger = LoggerFactory.getLogger(CardTemplateBean.class);
/** /**
......
...@@ -38,7 +38,9 @@ public class LectureBean implements LectureBeanLocal { ...@@ -38,7 +38,9 @@ public class LectureBean implements LectureBeanLocal {
@Override @Override
public List<Lecture> getLecturesByLectureGroup(LectureGroup group) { public List<Lecture> getLecturesByLectureGroup(LectureGroup group) {
return new ArrayList<Lecture>(); LectureGroup sourceGroup = lectureGroupFacade.reload(group);
return sourceGroup.getLectures();
} }
@Override @Override
...@@ -55,7 +57,7 @@ public class LectureBean implements LectureBeanLocal { ...@@ -55,7 +57,7 @@ public class LectureBean implements LectureBeanLocal {
if (group.getEvent() == null) if (group.getEvent() == null)
group.setEvent(eventBean.getCurrentEvent()); group.setEvent(eventBean.getCurrentEvent());
group = lectureGroupFacade.create(group); lectureGroupFacade.create(group);
} else { } else {
group = lectureGroupFacade.merge(group); group = lectureGroupFacade.merge(group);
...@@ -83,7 +85,7 @@ public class LectureBean implements LectureBeanLocal { ...@@ -83,7 +85,7 @@ public class LectureBean implements LectureBeanLocal {
lecture.setLectureGroup(group); lecture.setLectureGroup(group);
if (lecture.getId() == null) { if (lecture.getId() == null) {
lecture = lectureFacade.create(lecture); lectureFacade.create(lecture);
if (!lecture.getLectureGroup().getLectures().contains(lecture)) if (!lecture.getLectureGroup().getLectures().contains(lecture))
lecture.getLectureGroup().getLectures().add(lecture); lecture.getLectureGroup().getLectures().add(lecture);
...@@ -133,7 +135,7 @@ public class LectureBean implements LectureBeanLocal { ...@@ -133,7 +135,7 @@ public class LectureBean implements LectureBeanLocal {
lecture.getParticipants().add(targetUser); lecture.getParticipants().add(targetUser);
lectureFacade.merge(lecture); lecture = lectureFacade.merge(lecture);
targetUser.getLectures().add(lecture); targetUser.getLectures().add(lecture);
...@@ -148,7 +150,7 @@ public class LectureBean implements LectureBeanLocal { ...@@ -148,7 +150,7 @@ public class LectureBean implements LectureBeanLocal {
lecture.getParticipants().remove(targetUser); lecture.getParticipants().remove(targetUser);
targetUser.getLectures().remove(lecture); targetUser.getLectures().remove(lecture);
lectureFacade.merge(lecture); lecture = lectureFacade.merge(lecture);
return lecture; return lecture;
......
...@@ -261,7 +261,7 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal { ...@@ -261,7 +261,7 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
} }
// Finally persist the association and return // Finally persist the association and return
na = networkAssociationFacade.create(na); networkAssociationFacade.create(na);
return na; return na;
} }
......
...@@ -172,10 +172,18 @@ public class ReaderBean implements ReaderBeanLocal { ...@@ -172,10 +172,18 @@ public class ReaderBean implements ReaderBeanLocal {
@Override @Override
public ReaderEvent assocCodeToCard(ReaderEvent readerEvent, PrintedCard card) { public ReaderEvent assocCodeToCard(ReaderEvent readerEvent, PrintedCard card) {
// you can select between this and flushCache.
card = cardfacade.reload(card);
CardCode code = new CardCode(card, readerEvent.getReader().getType(), readerEvent.getValue(), eventbean.getCurrentEvent());
CardCode code = new CardCode(card, readerEvent.getReader().getType(), readerEvent.getValue());
cardCodeFacade.create(code); cardCodeFacade.create(code);
card.getCardCodes().add(code);
return readerEvent; return readerEvent;
} }
......
...@@ -25,80 +25,71 @@ import org.eclipse.persistence.annotations.OptimisticLocking; ...@@ -25,80 +25,71 @@ import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType; import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Group for lectures, so you can set limits how many of these the user can choose * Group for lectures, so you can set limits how many of these the user can
* choose
*/ */
@Entity @Entity
@Table(name = "lectures") @Table(name = "lectures")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS) @OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class Lecture extends GenericEntity { public class Lecture extends GenericEntity {
private static final long serialVersionUID = 3L;
private static final long serialVersionUID = 3L; @Column(name = "name")
private String name;
@Column(name = "name")
private String name; @Lob
@Column(name = "description")
private String description;
@Lob
@Column(name = "description") @ManyToOne
private String description; @JoinColumn(name = "lecture_group_id", referencedColumnName = LectureGroup.ID_COLUMN)
private LectureGroup lectureGroup;
@ManyToOne @ManyToMany()
@JoinColumn(name = "lecture_group_id", referencedColumnName = LectureGroup.ID_COLUMN) @JoinTable(name = "lecture_participants",
private LectureGroup lectureGroup; joinColumns = { @JoinColumn(name = "lecture_id", referencedColumnName = Lecture.ID_COLUMN) },
inverseJoinColumns = { @JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN) })
private List<EventUser> participants;
@ManyToMany()
@JoinTable(name = "lecture_participants", @ManyToMany()
joinColumns = { @JoinColumn(name = "lecture_id", referencedColumnName = Lecture.ID_COLUMN) }, @JoinTable(name = "lecture_roles",
inverseJoinColumns = { @JoinColumn(name = "eventuser_id", referencedColumnName = EventUser.ID_COLUMN) }) joinColumns = { @JoinColumn(name = "lecture_id", referencedColumnName = Lecture.ID_COLUMN) },
private List<EventUser> participants; inverseJoinColumns = { @JoinColumn(name = "role_id", referencedColumnName = Role.ID_COLUMN) })
private List<Role> openForRoles;
@ManyToMany() @Column(name = "max_participants_count")
@JoinTable(name = "lecture_roles", private Integer maxParticipantsCount;
joinColumns = { @JoinColumn(name = "lecture_id", referencedColumnName = Lecture.ID_COLUMN) },
inverseJoinColumns = { @JoinColumn(name = "role_id", referencedColumnName = Role.ID_COLUMN) }) @Temporal(TemporalType.TIMESTAMP)
private List<Role> openForRoles; @Column(name = "start_time")
private Calendar startTime;
@Column(name = "max_participants_count")
private Integer maxParticipantsCount; @Column(name = "hours", precision = 10, scale = 2)
private BigDecimal hours;
@Temporal(TemporalType.TIMESTAMP) public Lecture() {
@Column(name = "start_time") super();
private Calendar startTime; }
@Column(name = "hours", precision = 10, scale = 2) public Lecture(LectureGroup group) {
private BigDecimal hours; this();
setLectureGroup(group);
public Lecture() { }
super();
}
public Lecture(LectureGroup group) {
this();
setLectureGroup(group);
}
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
...@@ -112,9 +103,9 @@ public class Lecture extends GenericEntity { ...@@ -112,9 +103,9 @@ public class Lecture extends GenericEntity {
} }
public List<EventUser> getParticipants() { public List<EventUser> getParticipants() {
if(participants == null) if (participants == null)
participants = new ArrayList<EventUser>(); participants = new ArrayList<EventUser>();
return participants; return participants;
} }
...@@ -123,10 +114,10 @@ public class Lecture extends GenericEntity { ...@@ -123,10 +114,10 @@ public class Lecture extends GenericEntity {
} }
public List<Role> getOpenForRoles() { public List<Role> getOpenForRoles() {
if(openForRoles == null) if (openForRoles == null)
openForRoles = new ArrayList<Role>(); openForRoles = new ArrayList<Role>();
return openForRoles; return openForRoles;
} }
...@@ -143,7 +134,7 @@ public class Lecture extends GenericEntity { ...@@ -143,7 +134,7 @@ public class Lecture extends GenericEntity {
} }
public Calendar getStartTime() { public Calendar getStartTime() {
if(startTime == null) { if (startTime == null) {
startTime = Calendar.getInstance(); startTime = Calendar.getInstance();
} }
return startTime; return startTime;
...@@ -154,30 +145,25 @@ public class Lecture extends GenericEntity { ...@@ -154,30 +145,25 @@ public class Lecture extends GenericEntity {
} }
public Calendar getEndTime() { public Calendar getEndTime() {
if (getStartTime() == null || getHours() == null)
if(getStartTime() == null || getHours() == null)
return getStartTime(); return getStartTime();
Calendar endTime = (Calendar) getStartTime().clone();
Calendar endTime = (Calendar) getStartTime().clone();
endTime.add(Calendar.MINUTE, getHours().multiply(new BigDecimal(60)).intValue()); endTime.add(Calendar.MINUTE, getHours().multiply(new BigDecimal(60)).intValue());
return endTime; return endTime;
} }
public void setEndTime(Calendar endTime) { public void setEndTime(Calendar endTime) {
if(endTime == null || getStartTime() == null) { if (endTime == null || getStartTime() == null) {
hours = BigDecimal.ZERO; hours = BigDecimal.ZERO;
} }
setHours(new BigDecimal((int) endTime.compareTo(getStartTime()) / 1000 / 60 / 60)); setHours(new BigDecimal((int) endTime.compareTo(getStartTime()) / 1000 / 60 / 60));
} }
public BigDecimal getHours() { public BigDecimal getHours() {
return hours; return hours;
...@@ -193,44 +179,30 @@ public class Lecture extends GenericEntity { ...@@ -193,44 +179,30 @@ public class Lecture extends GenericEntity {
@Override @Override
public Object clone() { public Object clone() {
Lecture newLecture = new Lecture(this.getLectureGroup()); Lecture newLecture = new Lecture(this.getLectureGroup());
newLecture.setDescription(getDescription()); newLecture.setDescription(getDescription());
newLecture.setName(getName()); newLecture.setName(getName());
newLecture.setHours(getHours()); newLecture.setHours(getHours());
newLecture.setMaxParticipantsCount(getMaxParticipantsCount()); newLecture.setMaxParticipantsCount(getMaxParticipantsCount());
newLecture.setStartTime(getStartTime()); newLecture.setStartTime(getStartTime());
newLecture.setOpenForRoles(getOpenForRoles()); newLecture.setOpenForRoles(getOpenForRoles());
return newLecture; return newLecture;
} }
@Transient @Transient
public boolean isFull() { public boolean isFull() {
if(getMaxParticipantsCount() <= 0) { if (getMaxParticipantsCount() <= 0) {
return false; return false;
} }
return (getParticipants().size() >= getMaxParticipantsCount()); return (getParticipants().size() >= getMaxParticipantsCount());
} }
@Transient @Transient
public int getParticipantsCount() { public int getParticipantsCount() {
return getParticipants().size(); return getParticipants().size();
} }
}
}
...@@ -20,51 +20,42 @@ import org.eclipse.persistence.annotations.OptimisticLocking; ...@@ -20,51 +20,42 @@ import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType; import org.eclipse.persistence.annotations.OptimisticLockingType;
/** /**
* Group for lectures, so you can set limits how many of these the user can choose * Group for lectures, so you can set limits how many of these the user can
* choose
*/ */
@Entity @Entity
@Table(name = "lecture_groups") @Table(name = "lecture_groups")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS) @OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class LectureGroup extends GenericEntity { public class LectureGroup extends GenericEntity {
private static final long serialVersionUID = 4L;
private static final long serialVersionUID = 4L; @ManyToOne()
@JoinColumn(name = "event_id", nullable = false)
private LanEvent event;
@ManyToOne()
@JoinColumn(name = "event_id", nullable = false) @Column(name = "select_count")
private LanEvent event; private Integer selectCount;
@Column(name = "name")
@Column(name = "select_count") private String name;
private Integer selectCount;
@Lob
@Column(name = "description")
@Column(name = "name") private String description;
private String name;
@OneToMany(mappedBy = "lectureGroup", cascade = CascadeType.ALL)
private List<Lecture> lectures;
@Lob
@Column(name = "description") public LectureGroup() {
private String description; super();
}
@OneToMany(mappedBy = "lectureGroup", cascade = CascadeType.ALL) public LectureGroup(LanEvent event) {
private List<Lecture> lectures; this();
this.event = event;
}
public LectureGroup() {
super();
}
public LectureGroup(LanEvent event) {
this();
this.event = event;
}
public Integer getSelectCount() { public Integer getSelectCount() {
return selectCount; return selectCount;
...@@ -74,22 +65,18 @@ public class LectureGroup extends GenericEntity { ...@@ -74,22 +65,18 @@ public class LectureGroup extends GenericEntity {
this.selectCount = selectCount; this.selectCount = selectCount;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
public String getDescription() { public String getDescription() {
return description; return description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
...@@ -110,5 +97,4 @@ public class LectureGroup extends GenericEntity { ...@@ -110,5 +97,4 @@ public class LectureGroup extends GenericEntity {
this.lectures = lectures; this.lectures = lectures;
} }
} }
...@@ -8,17 +8,25 @@ ...@@ -8,17 +8,25 @@
<f:metadata> <f:metadata>
<f:viewParam name="userid" value="#{userView.userid}" /> <f:viewParam name="userid" value="#{userView.userid}" />
<f:event type="preRenderView" listener="#{userView.initView}" /> <f:event type="preRenderView" listener="#{userView.initView}" />
<f:event type="preRenderView" listener="#{userView.setCaptureForwardUrl('/admin/adduser/capturesuccess')}" /> <f:event type="preRenderView" listener="#{userView.setCaptureForwardUrl('/admin/adduser/update')}" />
</f:metadata> </f:metadata>
<ui:define name="topbar"> <ui:define name="topbar">
<h:link styleClass="userbackbutton" outcome="/admin/adduser/index"> <h:form>
<div>#{i18n['adduser.back']}</div> <h:commandLink styleClass="userbackbutton" action="#{userView.incomingPhotoReady}" value="Valmis">
</h:link> <div>#{i18n['adduser.back']}</div>
</h:commandLink>
</h:form>
</ui:define> </ui:define>
<ui:define name="content"> <ui:define name="content">
<div style="text-align: center;"> <div style="text-align: center;">
<h:form styleClass="captureForm"> <h:form styleClass="captureForm">
<h:panelGrid columns="2"> <h:panelGrid columns="2">
...@@ -31,28 +39,42 @@ ...@@ -31,28 +39,42 @@
</a> </a>
</h:panelGroup> </h:panelGroup>
<h:panelGroup> <h:panelGroup>
<div id="webcamcontainer"> <div id="webcamcontainer">
<p:photoCam widgetVar="pc" listener="#{userView.oncapture}" />
<p:commandButton type="button" value="Capture" onclick="PF('pc').capture()" />
<div id="count" /> <div id="count" />
<p:photoCam widgetVar="pc" listener="#{userView.oncapture}" update="@all" />
<!-- <p:commandButton type="button" value="Capture" onclick="dophoto(pc)" /> <!-- <p:commandButton type="button" value="Capture" onclick="dophoto(pc)" />
--> -->
</div> </div>
</h:panelGroup> </h:panelGroup>
</h:panelGrid> </h:panelGrid>
</h:form> </h:form>
</div> </div>
<div style=""> <div style="">
<h:link style="margin: 0 auto; font-size: 3em;" outcome="/admin/adduser/index" value="Valmis"/> <h:form id="incomingpictureform">
<h:commandLink rendered="#{!empty userView.selectedUser.currentImage}" style="margin: 0 auto; font-size: 3em;" action="#{userView.incomingPhotoReady}" value="Valmis" />
<br />
<p:fragment rendered="#{!empty userView.selectedUser.currentImage}">
<p:graphicImage value="/dydata/userimage/#{userView.selectedUser.currentImage.id}.img" alt="image" />
</p:fragment>
</h:form>
</div> </div>
<script> <script>
function dophoto(pc) { function dophoto(pc) {
docount(5,pc); docount(5, pc);
} }
function docount(count,pc) { function docount(count, pc) {
$('#count').html(count); $('#count').html(count);
$('#count').css("opacity", 1); $('#count').css("opacity", 1);
$('#count').css("font-size", "28pt"); $('#count').css("font-size", "28pt");
...@@ -63,9 +85,9 @@ ...@@ -63,9 +85,9 @@
}, 1500, function() { }, 1500, function() {
if (count > 1) if (count > 1)
docount(count - 1, pc); docount(count - 1, pc);
if (count == 1) { if (count == 1) {
pc.capture(); pc.capture();
} }
}); });
} }
......
...@@ -84,6 +84,22 @@ public class AuthView extends GenericCDIView { ...@@ -84,6 +84,22 @@ public class AuthView extends GenericCDIView {
return "/frontpage"; return "/frontpage";
} }
public void executeLogoutNoRedirect() {
HttpServletRequest req = getRequest();
if (permbean.isLoggedIn()) {
try {
req.logout();
} catch (ServletException e) {
logger.warn("Error executing logout", e);
}
}
req.getSession().invalidate();
}
public void executeLogin() { public void executeLogin() {
executeLogin(null); executeLogin(null);
......
...@@ -154,6 +154,12 @@ public class UserView extends GenericCDIView { ...@@ -154,6 +154,12 @@ public class UserView extends GenericCDIView {
} }
/** /**
* This is the user we are currently editing, if that is not found we user * This is the user we are currently editing, if that is not found we user
* current user * current user
...@@ -395,7 +401,7 @@ public class UserView extends GenericCDIView { ...@@ -395,7 +401,7 @@ public class UserView extends GenericCDIView {
public String createUserAdduserView() { public String createUserAdduserView() {
userbean.createNewUser(user, getPassword()); userbean.createNewUser(user, getPassword());
// authView.executeAdduserAutoLogin(user, getPassword()); authView.executeAdduserAutoLogin(user, getPassword());
return "/admin/adduser/update"; return "/admin/adduser/update";
} }
...@@ -404,6 +410,14 @@ public class UserView extends GenericCDIView { ...@@ -404,6 +410,14 @@ public class UserView extends GenericCDIView {
canSave = permbean.hasPermission(UserPermission.MODIFY); canSave = permbean.hasPermission(UserPermission.MODIFY);
return "/useradmin/edit"; return "/useradmin/edit";
} }
// /admin/adduser/index
public String incomingPhotoReady() {
authView.executeLogoutNoRedirect();
navihandler.forward("/admin/adduser/index?faces-redirect=true");
return "/admin/adduser/index";
}
public void setUserid(Integer userid) { public void setUserid(Integer userid) {
this.userid = userid; this.userid = userid;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!