Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Riina Antikainen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 4d3aef6b
authored
Oct 31, 2010
by
Juho Juopperi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
poll stuff
1 parent
bd7bc9b5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
5 deletions
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/beans/PollBean.java
code/LanBortalDatabase/src/fi/insomnia/bortal/model/Poll.java
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/beans/PollBean.java
View file @
4d3aef6
package
fi
.
insomnia
.
bortal
.
beans
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.List
;
import
javax.ejb.EJB
;
import
javax.ejb.Stateless
;
import
fi.insomnia.bortal.facade.PollAnswerFacade
;
import
fi.insomnia.bortal.facade.PollFacade
;
import
fi.insomnia.bortal.model.Poll
;
import
fi.insomnia.bortal.model.PollAnswer
;
import
fi.insomnia.bortal.model.PollQuestion
;
/**
* Session Bean implementation class PollBean
*/
@Stateless
public
class
PollBean
implements
PollBeanLocal
{
@EJB
private
PollFacade
pollFacade
;
@EJB
private
PollAnswerFacade
pollAnswerFacade
;
@EJB
private
EventBean
eventBean
;
@EJB
private
UserBean
userBean
;
/**
* Default constructor.
*/
...
...
@@ -22,14 +41,48 @@ public class PollBean implements PollBeanLocal {
@Override
public
List
<
Poll
>
findPolls
()
{
// TODO Auto-generated method stub
return
null
;
List
<
Poll
>
list
=
new
ArrayList
<
Poll
>();
userBean
.
fatalNotLoggedIn
();
for
(
Poll
p
:
pollFacade
.
findAll
(
eventBean
.
getCurrentEvent
()))
if
(
pollIsUsable
(
p
))
list
.
add
(
p
);
return
list
;
}
private
boolean
pollIsUsable
(
Poll
poll
)
{
Calendar
now
=
Calendar
.
getInstance
();
// Already valid
if
(
poll
.
getBegin
().
before
(
now
))
return
false
;
// Still valid
if
(
poll
.
getEnd
().
after
(
now
))
return
false
;
// At least one question that is on a page
for
(
PollQuestion
q
:
poll
.
getQuestions
())
{
if
(
q
.
getPage
()
>
0
)
return
true
;
}
// No usable questions
return
false
;
}
@Override
public
boolean
createAnswers
(
List
<
PollAnswer
>
answers
)
{
// TODO Auto-generated method stub
return
false
;
userBean
.
fatalNotLoggedIn
();
for
(
PollAnswer
answer
:
answers
)
{
answer
.
setUser
(
userBean
.
getCurrentUser
());
if
(
answer
.
getId
().
getId
()
!=
null
)
pollAnswerFacade
.
create
(
answer
);
}
return
false
;
}
}
code/LanBortalDatabase/src/fi/insomnia/bortal/model/Poll.java
View file @
4d3aef6
...
...
@@ -7,6 +7,7 @@ import java.util.Calendar;
import
java.util.List
;
import
javax.persistence.Entity
;
import
javax.persistence.FetchType
;
import
javax.persistence.Lob
;
import
javax.persistence.OneToMany
;
import
javax.persistence.Table
;
...
...
@@ -33,7 +34,7 @@ public class Poll extends GenericEventChild implements Serializable {
@Lob
private
String
description
;
@OneToMany
(
mappedBy
=
"poll"
)
@OneToMany
(
mappedBy
=
"poll"
,
fetch
=
FetchType
.
EAGER
)
private
List
<
PollQuestion
>
questions
;
public
Poll
()
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment