diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ResearchGroupDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ResearchGroupDao.java index 006976de..4be3abe6 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ResearchGroupDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ResearchGroupDao.java @@ -57,4 +57,6 @@ public interface ResearchGroupDao extends GenericDao { public int getCountForList(); List getGroupsForList(int start, int limit); + + ResearchGroup getResearchGroupById(int id); } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleCommentDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleCommentDao.java index 2812eb86..61d658c0 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleCommentDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleCommentDao.java @@ -44,7 +44,7 @@ public SimpleArticleCommentDao() { public List getCommentsForArticle(int articleId) { String query = "select distinct c from ArticleComment c left join fetch c.children join fetch c.person " + "where " + - "c.article.id = :id " + + "c.article.id = :id and c.parent is null " + "order by c.time desc"; return getSessionFactory().getCurrentSession().createQuery(query).setParameter("id", articleId).list(); } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleDao.java index 05a58629..d409f5d8 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleArticleDao.java @@ -27,14 +27,11 @@ package cz.zcu.kiv.eegdatabase.data.dao; +import java.util.Collections; +import java.util.List; + import cz.zcu.kiv.eegdatabase.data.pojo.Article; import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import org.hibernate.Hibernate; -import org.springframework.transaction.annotation.Transactional; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; /** * @author Jiri Vlasimsky @@ -54,23 +51,21 @@ public List
getAllArticles() { @Override public List
getArticlesForUser(Person person) { String query; - List articles = null; + List articles = Collections.EMPTY_LIST; if (person.getAuthority().equals("ROLE_ADMIN")) { // We can simply load the newest articles - query = "from Article a left join fetch a.researchGroup r " + - "order by a.time desc"; - articles = getHibernateTemplate().find(query); + query = "select DISTINCT a from Article a left join fetch a.articleComments order by a.time desc"; + articles = getSession().createQuery(query).list(); } else { // We need to load only articles which can be viewed by the logged user. // That is, we need to load only public articles or articles from the groups the logged user is member of. - query = "from Article a left join fetch a.researchGroup r " + - "where " + + query = "select DISTINCT a from Article a left join fetch a.articleComments where " + "a.researchGroup.researchGroupId is null or " + "a.researchGroup.researchGroupId in " + "(select rm.id.researchGroupId from ResearchGroupMembership rm where rm.id.personId = :personId) " + "order by a.time desc"; - articles = getHibernateTemplate().findByNamedParam(query, "personId", person.getPersonId()); + articles = getSession().createQuery(query).setParameter("personId", person.getPersonId()).list(); } return articles; @@ -78,27 +73,40 @@ public List
getArticlesForUser(Person person) { @Override public List
getArticlesForUser(Person person, int limit) { - getHibernateTemplate().setMaxResults(limit); - List
articles = getArticlesForUser(person); - getHibernateTemplate().setMaxResults(0); + String query; + List articles = Collections.EMPTY_LIST; + + if (person.getAuthority().equals("ROLE_ADMIN")) { + // We can simply load the newest articles + query = "select DISTINCT a from Article a left join fetch a.articleComments order by a.time desc"; + articles = getSession().createQuery(query).setMaxResults(limit).list(); + } else { + // We need to load only articles which can be viewed by the logged user. + // That is, we need to load only public articles or articles from the groups the logged user is member of. + query = "select DISTINCT a from Article a left join fetch a.articleComments where " + + "a.researchGroup.researchGroupId is null or " + + "a.researchGroup.researchGroupId in " + + "(select rm.id.researchGroupId from ResearchGroupMembership rm where rm.id.personId = :personId) " + + "order by a.time desc"; + articles = getSession().createQuery(query).setParameter("personId", person.getPersonId()).setMaxResults(limit).list(); + } + return articles; } @Override public List
getArticlesForList(Person person, int min, int count) { String query; - List articles = null; + List articles = Collections.EMPTY_LIST; if (person.getAuthority().equals("ROLE_ADMIN")) { // We can simply load the newest articles - query = "from Article a left join fetch a.researchGroup r join fetch a.person p " + - "order by a.time desc"; + query = "from Article a order by a.time desc"; articles = getSession().createQuery(query).setFirstResult(min).setMaxResults(count).list(); } else { // We need to load only articles which can be viewed by the logged user. // That is, we need to load only public articles or articles from the groups the logged user is member of. - query = "from Article a left join fetch a.researchGroup r join fetch a.person p " + - "where " + + query = "from Article a where " + "a.researchGroup.researchGroupId is null or " + "a.researchGroup.researchGroupId in " + "(select rm.id.researchGroupId from ResearchGroupMembership rm where rm.id.personId = :personId) " + @@ -114,7 +122,7 @@ public int getArticleCountForPerson(Person person) { if (person.getAuthority().equals("ROLE_ADMIN")) { return ((Long) getSession().createQuery("select count(*) from Article").uniqueResult()).intValue(); } - String query = "select count(*) from Article a left join a.person p where " + + String query = "select count(*) from Article a where " + "a.researchGroup.researchGroupId is null or " + "a.researchGroup.researchGroupId in " + "(select rm.id.researchGroupId from ResearchGroupMembership rm where rm.id.personId = :personId)"; @@ -133,14 +141,12 @@ public int getArticleCountForPerson(Person person) { public Article getArticleDetail(int id, Person loggedPerson) { if (loggedPerson.getAuthority().equals("ROLE_ADMIN")) { - String query = "from Article a join fetch a.person left join fetch a.researchGroup " + - "where " + - "a.articleId = :id"; + String query = "from Article a left join fetch a.subscribers left join fetch a.articleComments " + + "where a.articleId = :id"; return (Article) getSession().createQuery(query).setParameter("id", id).uniqueResult(); } else { - String query = "from Article a join fetch a.person left join fetch a.researchGroup " + - "where " + - "a.articleId = :id and (" + + String query = "from Article a left join fetch a.subscribers left join fetch a.articleComments "+ + "where a.articleId = :id and (" + "a.researchGroup.researchGroupId is null or " + "a.researchGroup.researchGroupId in " + "(select rm.id.researchGroupId from ResearchGroupMembership rm where rm.id.personId = :personId))"; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleHistoryDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleHistoryDao.java index a070e49e..106f79c2 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleHistoryDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleHistoryDao.java @@ -78,11 +78,22 @@ public List getHistory(ChoiceHistory historyType, boolean isGroupAdmin, * @return string left join for hql query */ private String getLeftJoin(boolean isGroupAdmin, int groupId) { + + String joinedTables = " left join fetch h.scenario left join fetch h.person as person left join fetch h.dataFile"; + if (isGroupAdmin && groupId > 0) { - return " left join h.person.researchGroupMemberships m"; + return joinedTables + " left join person.researchGroupMemberships m"; } - return ""; + return joinedTables; + } + + private String getLeftJoinForTopDownload(boolean isGroupAdmin, int groupId){ + if (isGroupAdmin && groupId > 0) { + return " join h.person as person join person.researchGroupMemberships m"; + } + return ""; } + /** * Returns group condition for hql query * @param isGroupAdmin - determined role GROUP_ADMIN @@ -107,7 +118,7 @@ public long getCountOfFilesHistory(ChoiceHistory historyType, boolean isGroupAdm List dCount = null; String leftJoin = ""; String groupCondition = ""; - leftJoin = getLeftJoin(isGroupAdmin, groupId); + leftJoin = getLeftJoinForTopDownload(isGroupAdmin, groupId); whereCondition = getWhereCondition(historyType); groupCondition = getGroupCondition(isGroupAdmin, groupId); @@ -174,15 +185,15 @@ private String getWhereCondition(ChoiceHistory historyType) { String whereCondition = ""; switch (historyType) { case DAILY: - whereCondition = " where h.dateOfDownload > trunc(sysdate)"; + whereCondition = " where h.dateOfDownload >= date_trunc('day', current_date)"; break; case WEEKLY: - whereCondition = " where h.dateOfDownload >= trunc(sysdate, 'iw')"; + whereCondition = " where h.dateOfDownload >= date_trunc('week', current_date)"; break; case MONTHLY: - whereCondition = " where h.dateOfDownload > trunc(sysdate,'mm')"; + whereCondition = " where h.dateOfDownload >= date_trunc('month', current_date)"; break; default: @@ -207,7 +218,7 @@ public List getTopDownloadHistory(ChoiceHistory historyType, List topHistory = null; String leftJoin = ""; String groupCondition = ""; - leftJoin = getLeftJoin(isGroupAdmin, groupId); + leftJoin = getLeftJoinForTopDownload(isGroupAdmin, groupId); groupCondition = getGroupCondition(isGroupAdmin, groupId); String selectAndCreateObject = "select distinct new cz.zcu.kiv.eegdatabase.logic.controller.history.DownloadStatistic"; session = getHibernateTemplate().getSessionFactory().getCurrentSession(); diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleResearchGroupDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleResearchGroupDao.java index 43d7969f..3a999b37 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleResearchGroupDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleResearchGroupDao.java @@ -170,4 +170,10 @@ public List getGroupsForList(int start, int limit) { public List getAllRecordsFull() { return super.getAllRecordsFull(); } + + @Override + public ResearchGroup getResearchGroupById(int id) { + String query = "from ResearchGroup g left join fetch g.articlesSubscribers where g.researchGroupId = :id"; + return (ResearchGroup) getSessionFactory().getCurrentSession().createQuery(query).setParameter("id", id).uniqueResult(); + } } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Article.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Article.java index d0979195..cabb48bd 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Article.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Article.java @@ -27,19 +27,33 @@ */ package cz.zcu.kiv.eegdatabase.data.pojo; +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.Lob; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.OrderBy; +import javax.persistence.Table; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.Type; + import cz.zcu.kiv.eegdatabase.data.annotation.Indexed; import cz.zcu.kiv.eegdatabase.data.annotation.SolrField; import cz.zcu.kiv.eegdatabase.data.annotation.SolrId; import cz.zcu.kiv.eegdatabase.logic.indexing.IndexField; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.Type; - -import javax.persistence.*; -import java.io.Serializable; -import java.sql.Timestamp; -import java.util.HashSet; -import java.util.Set; /** * Article generated by hbm2java @@ -92,7 +106,7 @@ public void setArticleId(int articleId) { this.articleId = articleId; } - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "PERSON_ID", nullable = false) public Person getPerson() { return this.person; @@ -102,7 +116,7 @@ public void setPerson(Person person) { this.person = person; } - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "RESEARCH_GROUP_ID") public ResearchGroup getResearchGroup() { return this.researchGroup; @@ -141,7 +155,8 @@ public void setTitle(String title) { this.title = title; } - @OneToMany(fetch = FetchType.EAGER, mappedBy = "article") + @OneToMany(fetch = FetchType.LAZY, mappedBy = "article") + @OrderBy("time ASC") public Set getArticleComments() { return this.articleComments; } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ArticleComment.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ArticleComment.java index aef2bf9e..d2317522 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ArticleComment.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ArticleComment.java @@ -130,7 +130,8 @@ public void setParent(ArticleComment parent) { this.parent = parent; } - @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent") + @OneToMany(fetch = FetchType.EAGER, mappedBy = "parent") + @OrderBy("time ASC") public Set getChildren() { return this.children; } @@ -148,7 +149,7 @@ public void setTime(Timestamp time) { this.time = time; } - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "PERSON_ID", nullable = false) public Person getPerson() { return this.person; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Person.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Person.java index ae332766..88b66d88 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Person.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/Person.java @@ -22,7 +22,25 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.data.pojo; -// Generated 2.12.2013 0:56:28 by Hibernate Tools 3.4.0.CR1 +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Transient; + +import org.hibernate.annotations.GenericGenerator; import cz.zcu.kiv.eegdatabase.wui.ui.experiments.converters.IAutoCompletable; import cz.zcu.kiv.formgen.annotation.FormId; @@ -30,14 +48,7 @@ import cz.zcu.kiv.formgen.annotation.FormItemRestriction; import cz.zcu.kiv.formgen.annotation.PreviewLevel; -import org.hibernate.annotations.GenericGenerator; - -import javax.persistence.*; - -import java.io.Serializable; -import java.sql.Timestamp; -import java.util.HashSet; -import java.util.Set; +// Generated 2.12.2013 0:56:28 by Hibernate Tools 3.4.0.CR1 /** * Person generated by hbm2java @@ -72,6 +83,7 @@ public class Person implements Serializable, Comparable, IAutoCompletabl private String authority; private Timestamp registrationDate; private boolean confirmed; + private boolean lock = false; private String authenticationHash; private ResearchGroup defaultGroup; private EducationLevel educationLevel; @@ -446,10 +458,19 @@ public void setPersonalLicenses(Set personalLicenses) { this.personalLicenses = personalLicenses; } - @Transient + @Column(name="LOCK" ,nullable=false, columnDefinition = "BOOLEAN DEFAULT FALSE") + public boolean isLock() { + return lock; + } + + public void setLock(boolean lock) { + this.lock = lock; + } + + @Transient public String getFullName() { - if (getGivenname() == null && getSurname() == null && getEmail() == null) { + if (getGivenname() == null && getSurname() == null) { return null; } @@ -476,4 +497,25 @@ public String getAutoCompleteData() { fullName += (getUsername() != null) ? " " + getUsername() : ""; return fullName; } + + @Override + public boolean equals(Object obj) { + + if (obj == null) { + return false; + } + + if(!obj.getClass().equals(this.getClass())) { + return false; + } + + Person other = (Person) obj; + + return getPersonId() == other.getPersonId(); + } + + @Override + public int hashCode() { + return getPersonId(); + } } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroup.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroup.java index 864e9763..1ea81268 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroup.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroup.java @@ -61,6 +61,8 @@ public class ResearchGroup implements java.io.Serializable { private String description; @FormItem private boolean paidAccount; + private boolean lock = true; + private Set researchGroupMemberships = new HashSet( 0); private Set keywords = new HashSet(0); @@ -493,4 +495,13 @@ public Set getArtifacts() { public void setArtifacts(Set artifacts) { this.artifacts = artifacts; } + + @Column(name="LOCK" ,nullable=false, columnDefinition = "BOOLEAN DEFAULT FALSE") + public boolean isLock() { + return lock; + } + + public void setLock(boolean lock) { + this.lock = lock; + } } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroupMembership.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroupMembership.java index 1d4ae39d..cdced4ac 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroupMembership.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/pojo/ResearchGroupMembership.java @@ -69,7 +69,7 @@ public void setId(ResearchGroupMembershipId id) { this.id = id; } - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "RESEARCH_GROUP_ID", nullable = false, insertable = false, updatable = false) public ResearchGroup getResearchGroup() { return this.researchGroup; @@ -79,7 +79,7 @@ public void setResearchGroup(ResearchGroup researchGroup) { this.researchGroup = researchGroup; } - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "PERSON_ID", nullable = false, insertable = false, updatable = false) public Person getPerson() { return this.person; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/service/MailService.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/service/MailService.java index a6d0d896..3acb0024 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/service/MailService.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/service/MailService.java @@ -22,10 +22,16 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.data.service; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; import java.util.Locale; + +import javax.servlet.http.HttpServletRequest; + import org.springframework.mail.MailException; +import cz.zcu.kiv.eegdatabase.data.pojo.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; + /** * Created by IntelliJ IDEA. * User: Jiri Novotny @@ -113,4 +119,7 @@ boolean sendRequestForJoiningGroupMail(String toEmail, int requestId, String use String researchGroupTitle, Locale locale) throws MailException; boolean sendForgottenPasswordMail(String email, String plainPassword); + + void sendNotification(String email, Article article, Locale locale); + void sendNotification(String email, ArticleComment comment, Locale locale); } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/service/SpringJavaMailService.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/service/SpringJavaMailService.java index 1008b049..a90f95cc 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/service/SpringJavaMailService.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/service/SpringJavaMailService.java @@ -22,11 +22,11 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.data.service; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; -import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; -import cz.zcu.kiv.eegdatabase.wui.ui.groups.role.GroupRoleAcceptPage; -import cz.zcu.kiv.eegdatabase.wui.ui.security.ConfirmPage; +import java.util.Locale; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -39,9 +39,15 @@ import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; -import java.util.Locale; +import cz.zcu.kiv.eegdatabase.data.pojo.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; +import cz.zcu.kiv.eegdatabase.wui.ui.groups.role.GroupRoleAcceptPage; +import cz.zcu.kiv.eegdatabase.wui.ui.security.ConfirmPage; + + /** * Created by IntelliJ IDEA. User: Jiri Novotny Date: 11.3.12 Time: 23:57 @@ -153,6 +159,101 @@ public boolean sendForgottenPasswordMail(String email, String plainPassword) { public boolean sendEmail(String to, String subject, String emailBody) throws MailException { return sendEmail(mailMessage.getFrom(), to, subject, emailBody); } + + @Override + public void sendNotification(String email, Article article, Locale locale) { + + try { + String articleURL = "http://" + domain + "/articles/detail.html?articleId=" + article.getArticleId(); + // System.out.println(articleURL); + String subject = messageSource.getMessage("articles.group.email.subscribtion.subject", new String[] { article.getTitle(), article.getPerson().getUsername() }, + locale); + // System.out.println(subject); + String emailBody = ""; + + emailBody += "

" + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part1", + new String[] { article.getTitle() }, + locale) + ""; + emailBody += " (" + articleURL + ")


"; + emailBody += "

" + article.getTitle() + "

" + article.getText() + "


"; + emailBody += "

" + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part2", null, locale) + "

"; + emailBody += ""; + + // System.out.println(emailBody); + log.debug("email body: " + emailBody); + + log.debug("Composing e-mail message"); + MimeMessage mimeMessage = mailSender.createMimeMessage(); + + MimeMessageHelper message = new MimeMessageHelper(mimeMessage); + message.setFrom(mailMessage.getFrom()); + + // message.setContent("text/html"); + message.setTo(email); + // helper.setFrom(messageSource.getMessage("registration.email.from", null, RequestContextUtils.getLocale(request))); + message.setSubject(subject); + message.setText(emailBody, true); + + log.debug("Sending e-mail" + message); + log.debug("mailSender" + mailSender); + mailSender.send(mimeMessage); + log.debug("E-mail was sent"); + + } catch (MailException e) { + log.error("E-mail for subscribers was NOT sent"); + log.error(e.getMessage(), e); + } catch (MessagingException e) { + log.error("E-mail for subscribers was NOT sent"); + log.error(e.getMessage(), e); + } + } + + @Override + public void sendNotification(String email, ArticleComment comment, Locale locale) throws MailException { + + try { + String articleURL = "http://" + domain + "/articles/detail.html?articleId=" + comment.getArticle().getArticleId(); + //System.out.println(articleURL); + String subject = messageSource.getMessage("articles.group.email.subscribtion.subject", new String[]{comment.getArticle().getTitle(), comment.getPerson().getUsername()}, locale); + //System.out.println(subject); + String emailBody = ""; + + emailBody += "

" + messageSource.getMessage("articles.group.email.subscribtion.body.text.part1", + new String[]{comment.getArticle().getTitle()}, + locale) + ""; + emailBody += " (" + articleURL + ")


"; + emailBody += "

Text:

" + comment.getText() + "


"; + emailBody += "

" + messageSource.getMessage("articles.group.email.subscribtion.body.text.part2", null, locale) + "

"; + emailBody += ""; + + //System.out.println(emailBody); + log.debug("email body: " + emailBody); + + + log.debug("Composing e-mail message"); + MimeMessage mimeMessage = mailSender.createMimeMessage(); + + MimeMessageHelper message = new MimeMessageHelper(mimeMessage); + message.setFrom(mailMessage.getFrom()); + + // message.setContent("text/html"); + message.setTo(email); + //helper.setFrom(messageSource.getMessage("registration.email.from", null, RequestContextUtils.getLocale(request))); + message.setSubject(subject); + message.setText(emailBody, true); + + log.debug("Sending e-mail" + message); + log.debug("mailSender" + mailSender); + mailSender.send(mimeMessage); + log.debug("E-mail was sent"); + } catch (MailException e) { + log.error("E-mail for subscribers was NOT sent"); + log.error(e.getMessage(), e); + } catch (MessagingException e) { + log.error("E-mail for subscribers was NOT sent"); + log.error(e.getMessage(), e); + } + } private boolean sendEmail(String from, String to, String subject, String emailBody) throws MailException {// make // public diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/DownloadStatistic.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/DownloadStatistic.java index 6ed494e5..b7974218 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/DownloadStatistic.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/DownloadStatistic.java @@ -32,7 +32,7 @@ * * @author pbruha */ -public class DownloadStatistic implements Comparable { +public class DownloadStatistic implements Comparable, java.io.Serializable { private int scenarioId; private int experimentId; private String fileName; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/social/LinkedInManager.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/social/LinkedInManager.java index db8c8642..a04a2b0f 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/social/LinkedInManager.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/social/LinkedInManager.java @@ -67,6 +67,10 @@ public class LinkedInManager { private Log log = LogFactory.getLog(getClass()); + public LinkedInManager() { + // default contructor for spring IoC + } + public LinkedInManager(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret, int groupId) { this.consumerKey = consumerKey; this.consumerSercet = consumerSecret; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/indexing/IndexingServiceImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/indexing/IndexingServiceImpl.java index 3d73afa2..06e4ff2d 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/indexing/IndexingServiceImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/logic/indexing/IndexingServiceImpl.java @@ -24,6 +24,7 @@ import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; import cz.zcu.kiv.eegdatabase.logic.controller.social.LinkedInManager; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.solr.client.solrj.SolrServerException; @@ -35,6 +36,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.social.linkedin.api.Post; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; @@ -82,7 +84,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws * @throws SolrServerException */ @Async - @Transactional + @Transactional(propagation=Propagation.MANDATORY) public void indexDatabase() throws IllegalAccessException, SolrServerException, IOException, NoSuchMethodException, InstantiationException { // get required dao beans @@ -104,7 +106,7 @@ public void indexDatabase() throws IllegalAccessException, SolrServerException, * @throws IOException */ @Async - @Transactional + @Transactional(propagation=Propagation.MANDATORY) public void indexLinkedIn() throws IllegalAccessException, SolrServerException, IOException { int startIndex = 0; @@ -160,6 +162,7 @@ public void indexLinkedIn(List posts) throws IllegalAccessException, SolrS * @throws ClassNotFoundException */ @Scheduled(cron = "${solr.indexingPeriod}") + @Transactional(propagation=Propagation.REQUIRED) public void indexAll() { log.info("Starting indexing data"); try { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/EEGDataBaseApplication.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/EEGDataBaseApplication.java index bdc94ed1..b5f6d35a 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/EEGDataBaseApplication.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/EEGDataBaseApplication.java @@ -22,7 +22,6 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.wui.app; - import org.apache.wicket.ConverterLocator; import org.apache.wicket.IConverterLocator; import org.apache.wicket.Page; @@ -70,8 +69,14 @@ import cz.zcu.kiv.eegdatabase.wui.core.scenarios.ScenariosFacade; import cz.zcu.kiv.eegdatabase.wui.ui.account.AccountOverViewPage; import cz.zcu.kiv.eegdatabase.wui.ui.account.SocialNetworksPage; -import cz.zcu.kiv.eegdatabase.wui.ui.administration.ChangeUserRolePage; +import cz.zcu.kiv.eegdatabase.wui.ui.administration.AdminManagePersonPage; +import cz.zcu.kiv.eegdatabase.wui.ui.administration.AdminManageUserRolePage; +import cz.zcu.kiv.eegdatabase.wui.ui.administration.ManageResearchGroupPage; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ArticleCommentFormPage; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ArticleFormPage; import cz.zcu.kiv.eegdatabase.wui.ui.articles.ArticlesPage; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ArticlesSettingsPage; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ViewArticlePage; import cz.zcu.kiv.eegdatabase.wui.ui.data.DataFileDetailPage; import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ExperimentFormPage; import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ExperimentsDetailPage; @@ -128,11 +133,10 @@ import cz.zcu.kiv.eegdatabase.wui.ui.welcome.WelcomePage; /** - * Main class for wicket core. Initialization of wicket core, mounter pages on specific url, - * prepare project settings: security policy, redirect policy. + * Main class for wicket core. Initialization of wicket core, mounter pages on specific url, prepare project settings: security policy, redirect policy. * * @author Jakub Rinkes - * + * */ public class EEGDataBaseApplication extends AuthenticatedWebApplication implements ApplicationContextAware { @@ -161,9 +165,8 @@ public class EEGDataBaseApplication extends AuthenticatedWebApplication implemen private WeatherFacade weatherFacade; @Autowired private StimulusFacade stimulusFacade; - - private boolean development = true; + private boolean development = true; public java.lang.Class getHomePage() { @@ -234,10 +237,16 @@ private void mountPages() { mountPage("account-overview", AccountOverViewPage.class); // mountPage("account-change-pass", ChangePasswordPage.class); mountPage("account-social", SocialNetworksPage.class); - - mountPage("administration-change-user-role", ChangeUserRolePage.class); - mountPage("articles-page", ArticlesPage.class); + mountPage("administration-manage-user-role", AdminManageUserRolePage.class); + mountPage("administration-manage-user", AdminManagePersonPage.class); + mountPage("administration-manage-group", ManageResearchGroupPage.class); + + mountPage("articles-list", ArticlesPage.class); + mountPage("articles-form", ArticleFormPage.class); + mountPage("articles-view", ViewArticlePage.class); + mountPage("articles-comment-add", ArticleCommentFormPage.class); + mountPage("articles-settings", ArticlesSettingsPage.class); mountPage("experiments-list", ListExperimentsPage.class); mountPage("experiments-detail", ExperimentsDetailPage.class); @@ -282,22 +291,21 @@ private void mountPages() { mountPage("search-page", SearchPage.class); mountPage("add-experiment-wizard-page", ExperimentFormPage.class); - mountPage("manage-packages", ManageExperimentPackagesPage.class); - mountPage("license-request", LicenseRequestPage.class); - mountPage("granted-licenses", GrantedLicensesPage.class); - mountPage("manage-license-requests", ManageLicenseRequestsPage.class); - mountPage("revoked-licenses", RevokedRequestPage.class); + mountPage("manage-packages", ManageExperimentPackagesPage.class); + mountPage("license-request", LicenseRequestPage.class); + mountPage("granted-licenses", GrantedLicensesPage.class); + mountPage("manage-license-requests", ManageLicenseRequestsPage.class); + mountPage("revoked-licenses", RevokedRequestPage.class); - - mountPage("elastic", Elastic.class); + mountPage("elastic", Elastic.class); } @Override protected IConverterLocator newConverterLocator() { ConverterLocator locator = (ConverterLocator) super.newConverterLocator(); - + // here should be added custom convertor for converting types. - + locator.set(Disease.class, new DiseaseConverter(diseaseFacade)); locator.set(Person.class, new PersonConverter(personFacade)); locator.set(Pharmaceutical.class, new PharmaceuticalConverter(pharmaceuticalFacade)); @@ -331,7 +339,7 @@ protected Class getWebSessionClass() protected Class getSignInPageClass() { return HomePage.class; } - + public void setDevelopment(boolean development) { this.development = development; } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/menu/EEGDatabaseMainMenu.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/menu/EEGDatabaseMainMenu.java index cd4c5404..af496538 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/menu/EEGDatabaseMainMenu.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/menu/EEGDatabaseMainMenu.java @@ -23,7 +23,7 @@ package cz.zcu.kiv.eegdatabase.wui.app.menu; import cz.zcu.kiv.eegdatabase.wui.components.menu.MenuDefinition; -import cz.zcu.kiv.eegdatabase.wui.ui.administration.ChangeUserRolePage; +import cz.zcu.kiv.eegdatabase.wui.ui.administration.AdminManageUserRolePage; import cz.zcu.kiv.eegdatabase.wui.ui.articles.ArticlesPage; import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ListExperimentsByPackagePage; import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ListExperimentsPage; @@ -52,7 +52,7 @@ public enum EEGDatabaseMainMenu implements MenuDefinition { PeoplePage(ListPersonPage.class, "menuItem.people"), ListsPage(ListListsPage.class, "menuItem.lists"), HistoryPage(HistoryPage.class, "menuItem.history"), - Administration(ChangeUserRolePage.class, "menuItem.administration"), + Administration(AdminManageUserRolePage.class, "menuItem.administration"), Main(new EEGDatabaseMainMenu[] { HomePage, ArticlesPage, SearchPage, ExperimentsPage, ScenariosPage, GroupsPage, PeoplePage, ListsPage, HistoryPage, Administration }, ""), diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/session/EEGDataBaseSession.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/session/EEGDataBaseSession.java index 832ac47f..e38b313b 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/session/EEGDataBaseSession.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/app/session/EEGDataBaseSession.java @@ -41,6 +41,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.Person; import cz.zcu.kiv.eegdatabase.logic.eshop.ShoppingCart; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; import cz.zcu.kiv.eegdatabase.wui.core.person.PersonFacade; /** @@ -110,6 +111,15 @@ public boolean authenticate(String username, String password) { error((String.format("User '%s' failed to login. Reason: %s", username, e.getMessage()))); authenticated = false; } + + if (getLoggedUser() != null && getLoggedUser().isLock()) { + this.setLoggedUser(null); + SecurityContextHolder.clearContext(); + this.shoppingCart = null; + error(ResourceUtils.getString("text.user.lock.login", username)); + return false; + } + return authenticated; } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/form/PersonForm.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/form/PersonForm.java new file mode 100644 index 00000000..dfad0862 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/form/PersonForm.java @@ -0,0 +1,293 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * PersonForm.java, 2013/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.components.form; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox; +import org.apache.wicket.markup.html.form.CheckBox; +import org.apache.wicket.markup.html.form.ChoiceRenderer; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.EmailTextField; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.FormComponentLabel; +import org.apache.wicket.markup.html.form.PasswordTextField; +import org.apache.wicket.markup.html.form.RadioChoice; +import org.apache.wicket.markup.html.form.TextArea; +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.markup.html.panel.FeedbackPanel; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.util.convert.IConverter; +import org.apache.wicket.util.lang.Classes; +import org.apache.wicket.validation.validator.PatternValidator; +import org.apache.wicket.validation.validator.StringValidator; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +import cz.zcu.kiv.eegdatabase.data.pojo.EducationLevel; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.logic.Util; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.form.input.DateTimeFieldPicker; +import cz.zcu.kiv.eegdatabase.wui.components.table.TimestampConverter; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.components.utils.StringUtils; +import cz.zcu.kiv.eegdatabase.wui.core.Gender; +import cz.zcu.kiv.eegdatabase.wui.core.Laterality; +import cz.zcu.kiv.eegdatabase.wui.core.UserRole; +import cz.zcu.kiv.eegdatabase.wui.core.educationlevel.EducationLevelFacade; +import cz.zcu.kiv.eegdatabase.wui.core.person.PersonFacade; + +public class PersonForm extends Form { + + private static final long serialVersionUID = 1L; + + public PersonForm(String id, IModel model, final EducationLevelFacade educationFacade, final PersonFacade personFacade, final FeedbackPanel feedback) { + super(id, new CompoundPropertyModel(model)); + + final boolean isUserAdmin = EEGDataBaseSession.get().hasRole(UserRole.ROLE_ADMIN.name()); + + TextField name = new TextField("givenname"); + name.setLabel(ResourceUtils.getModel("label.name")); + name.setRequired(true); + name.add(new PatternValidator(StringUtils.REGEX_ONLY_LETTERS)); + FormComponentLabel nameLabel = new FormComponentLabel("nameLb", name); + add(name, nameLabel); + + TextField surname = new TextField("surname"); + surname.setLabel(ResourceUtils.getModel("label.surname")); + surname.setRequired(true); + surname.add(new PatternValidator(StringUtils.REGEX_ONLY_LETTERS)); + FormComponentLabel surnameLabel = new FormComponentLabel("surnameLb", surname); + add(surname, surnameLabel); + + DateTimeFieldPicker date = new DateTimeFieldPicker("dateOfBirth") { + + private static final long serialVersionUID = 1L; + + @Override + public IConverter getConverter(Class type) { + return (IConverter) new TimestampConverter(); + } + }; + + date.setLabel(ResourceUtils.getModel("label.dateOfBirth")); + date.setRequired(true); + FormComponentLabel dateLabel = new FormComponentLabel("dateLb", date); + add(date, dateLabel); + + EmailTextField email = new EmailTextField("username"); + email.setLabel(ResourceUtils.getModel("label.email")); + email.setRequired(true); + FormComponentLabel emailLabel = new FormComponentLabel("emailLb", email); + add(email, emailLabel); + + // only for admins + + final PasswordTextField password = new PasswordTextField("password", new Model("")); + password.setLabel(ResourceUtils.getModel("general.password")); + password.add(StringValidator.minimumLength(6)); + password.setRequired(false); + password.setVisibilityAllowed(isUserAdmin); + password.setVisible(false); + add(password); + + final PasswordTextField passwordVerify = new PasswordTextField("passwordVerify", new Model("")); + passwordVerify.setLabel(ResourceUtils.getModel("general.password.verify")); + passwordVerify.add(StringValidator.minimumLength(6)); + passwordVerify.setRequired(false); + passwordVerify.setVisibilityAllowed(isUserAdmin); + passwordVerify.setVisible(false); + add(passwordVerify); + + final AjaxCheckBox changePasswordBox = new AjaxCheckBox("changePassword", new Model(Boolean.FALSE)) { + + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate(AjaxRequestTarget target) { + + Boolean visible = getModelObject(); + password.setVisible(visible); + password.setRequired(visible); + passwordVerify.setVisible(visible); + passwordVerify.setRequired(visible); + + target.add(PersonForm.this); + } + }; + changePasswordBox.setVisibilityAllowed(isUserAdmin); + add(changePasswordBox); + // end only for admins + + TextField phoneNumber = new TextField("phoneNumber"); + phoneNumber.setLabel(ResourceUtils.getModel("label.phoneNumber")); + FormComponentLabel phoneNumberLabel = new FormComponentLabel("phoneNumberLb", phoneNumber); + add(phoneNumber, phoneNumberLabel); + + RadioChoice gender = new RadioChoice("gender", Gender.getShortcutList(), new ChoiceRenderer() { + + private static final long serialVersionUID = 1L; + + @Override + public Object getDisplayValue(Character object) { + Gender enumValue = Gender.getGenderByShortcut(object); + return getString(Classes.simpleName(enumValue.getDeclaringClass()) + '.' + enumValue.name()); + } + + }); + gender.setSuffix("\n"); + gender.setRequired(true); + gender.setLabel(ResourceUtils.getModel("label.gender")); + FormComponentLabel genderLabel = new FormComponentLabel("genderLb", gender); + add(gender, genderLabel); + + TextArea note = new TextArea("note"); + note.setLabel(ResourceUtils.getModel("label.note")); + note.add(StringValidator.maximumLength(255)); + FormComponentLabel noteLabel = new FormComponentLabel("noteLb", note); + add(note, noteLabel); + + DropDownChoice laterality = new DropDownChoice("laterality", Laterality.getShortcutList(), + new ChoiceRenderer() { + + private static final long serialVersionUID = 1L; + + @Override + public Object getDisplayValue(Character object) { + Laterality enumValue = Laterality.getLateralityByShortcut(object); + return getString(Classes.simpleName(enumValue.getDeclaringClass()) + '.' + enumValue.name()); + } + + }); + + laterality.setLabel(ResourceUtils.getModel("label.laterality")); + FormComponentLabel lateralityLabel = new FormComponentLabel("lateralityLb", laterality); + add(laterality, lateralityLabel); + + DropDownChoice educationLevel = new DropDownChoice("educationLevel", educationFacade.getAllRecords(), + new ChoiceRenderer("title", "educationLevelId") { + + private static final long serialVersionUID = 1L; + + @Override + public Object getDisplayValue(EducationLevel object) { + return object.getEducationLevelId() + " " + super.getDisplayValue(object); + } + + }); + + educationLevel.setLabel(ResourceUtils.getModel("label.educationLevel")); + FormComponentLabel educationLevelLabel = new FormComponentLabel("educationLevelLb", educationLevel); + add(educationLevel, educationLevelLabel); + + CheckBox lockCheckBox = new CheckBox("lock"); + add(lockCheckBox); + + AjaxButton submit = new AjaxButton("submit", ResourceUtils.getModel("button.save"), this) { + + private static final long serialVersionUID = 1L; + + @Override + protected void onError(AjaxRequestTarget target, Form form) { + target.add(feedback); + } + + @Override + protected void onSubmit(AjaxRequestTarget target, Form form) { + + Person user = PersonForm.this.getModelObject(); + user.setEmail(user.getUsername().toLowerCase()); + boolean isEdit = user.getPersonId() > 0; + + String planPassword = password.getModelObject(); + String plainPasswordVerify = passwordVerify.getModelObject(); + Boolean isPasswordChanged = changePasswordBox.getModelObject(); + + if (validation(user, personFacade, isEdit, isUserAdmin, isPasswordChanged, planPassword, plainPasswordVerify)) { + if (isEdit) { + + if (isPasswordChanged) + user.setPassword(encodePassword(planPassword)); + + personFacade.update(user); + } else { + user.setAuthority(Util.ROLE_READER); + personFacade.create(user); + } + setResponsePage(getPage().getClass()); + } + + target.add(feedback); + } + }; + add(submit); + } + + private boolean validation(Person user, PersonFacade facade, boolean editation, boolean isUserAdmin, boolean isPasswordChanged, String password, String passwordVerify) { + + boolean validate = true; + + // if its editation we can't check if email exist + if (!editation && facade.usernameExists(user.getEmail())) { + error(ResourceUtils.getString("inUse.email")); + validate = false; + } + + if (user.getDateOfBirth().getTime() >= System.currentTimeMillis()) { + error(ResourceUtils.getString("invalid.dateOfBirth")); + validate = false; + } + + if (user.getPhoneNumber() != null && !user.getPhoneNumber().isEmpty()) { + try { + if (user.getPhoneNumber().charAt(0) == '+') { + Long.parseLong(user.getPhoneNumber().substring(1)); + } else { + Long.parseLong(user.getPhoneNumber()); + } + + } catch (NumberFormatException ex) { + error(ResourceUtils.getString("invalid.phoneNumber")); + validate = false; + } + + } + + if (isUserAdmin && isPasswordChanged && password != null && passwordVerify != null + && password.isEmpty() && passwordVerify.isEmpty() + && password.equals(passwordVerify)) { + error(ResourceUtils.getString("invalid.passwordMatch")); + validate = false; + } + + return validate; + } + + private String encodePassword(String plaintextPassword) { + + return new BCryptPasswordEncoder().encode(plaintextPassword); + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/form/input/AjaxConfirmLink.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/form/input/AjaxConfirmLink.java new file mode 100644 index 00000000..f2b75402 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/form/input/AjaxConfirmLink.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * AjaxConfirmLink.java, 2014/03/07 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.components.form.input; + +import org.apache.wicket.ajax.attributes.AjaxCallListener; +import org.apache.wicket.ajax.attributes.AjaxRequestAttributes; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.model.IModel; + +public abstract class AjaxConfirmLink extends AjaxLink { + + private static final long serialVersionUID = 1839713633026370773L; + private String confirmMessage; + + public AjaxConfirmLink(String id, String confirmMessage) { + super(id); + this.confirmMessage = confirmMessage; + } + + public AjaxConfirmLink(String id, IModel model, String confirmMessage) { + super(id, model); + this.confirmMessage = confirmMessage; + } + + @Override + protected void updateAjaxAttributes(AjaxRequestAttributes attributes) + { + super.updateAjaxAttributes(attributes); + + AjaxCallListener ajaxCallListener = new AjaxCallListener(); + ajaxCallListener.onPrecondition("return confirm('" + confirmMessage + "');"); + attributes.getAjaxCallListeners().add(ajaxCallListener); + } +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/ChartUtils.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/ChartUtils.java new file mode 100644 index 00000000..2f21b764 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/ChartUtils.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ChartUtils.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.components.utils; + +import java.awt.image.BufferedImage; +import java.util.List; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PiePlot3D; +import org.jfree.data.general.DefaultPieDataset; +import org.jfree.util.Rotation; + +import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; +import cz.zcu.kiv.eegdatabase.logic.controller.history.DownloadStatistic; + +public class ChartUtils { + + public static BufferedImage gererateChartForTopDownloadHistory(ChoiceHistory choiceHistory, boolean generateEmptyGraph, + List topDownloadedFilesList, long countOfFilesHistory) { + + long countFile = 0; + + DefaultPieDataset dataset = new DefaultPieDataset(); + if (!generateEmptyGraph && topDownloadedFilesList != null) { + for (int i = 0; i < topDownloadedFilesList.size(); i++) { + dataset.setValue(topDownloadedFilesList.get(i).getFileName(), new Long(topDownloadedFilesList.get(i).getCount())); + countFile = countFile + topDownloadedFilesList.get(i).getCount(); + } + + if (countOfFilesHistory > countFile) { + dataset.setValue("Other", countOfFilesHistory - countFile); + } + } + + String chartTitle = ResourceUtils.getString("title.dailyStatistic"); + if (choiceHistory == ChoiceHistory.WEEKLY) { + chartTitle = ResourceUtils.getString("title.weeklyStatistic"); + + } else if (choiceHistory == ChoiceHistory.MONTHLY) { + chartTitle = ResourceUtils.getString("title.monthlyStatistic"); + } + + JFreeChart chart = ChartFactory.createPieChart3D(chartTitle, // chart + // title + dataset, // data + true, // include legend + true, false); + + PiePlot3D plot = (PiePlot3D) chart.getPlot(); + plot.setStartAngle(290); + plot.setDirection(Rotation.CLOCKWISE); + plot.setForegroundAlpha(0.5f); + plot.setNoDataMessage(ResourceUtils.getString("label.noDataMessage")); + + return chart.createBufferedImage(600, 400); + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/PageParametersUtils.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/PageParametersUtils.java index 4330b626..7d76f891 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/PageParametersUtils.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/PageParametersUtils.java @@ -38,6 +38,8 @@ public class PageParametersUtils { public static final String GROUP_PARAM = "GROUP"; public static final String METHOD_NAME = "METHOD_NAME"; public static final String DATA = "DATA"; + public static final String ARTICLE = "ARTICLE"; + public static final String COMMENT = "COMMENT"; /** * Created page parameters with parameter key and object @@ -74,7 +76,7 @@ public static PageParameters addParameters(PageParameters parameters, parameters.add(key, object); return parameters; } - + /** * Get url for page and parameter from wicket. Wicket will generate absolute url for this page. * diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/ResourceUtils.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/ResourceUtils.java index 47648bab..9f9aeaf2 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/ResourceUtils.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/ResourceUtils.java @@ -84,6 +84,32 @@ public static IModel getModel(String propertyExpression, IModel model return new StringResourceModel(propertyExpression, model, new Object[] {}); } + /** + * Get string with string from properties where his key is propertyExpression + * and params contains data for formatted string. + * + * @param propertyExpression + * @param params + * @return + */ + public static String getString(String propertyExpression, Object... params) { + + return new StringResourceModel(propertyExpression, null, params).getString(); + } + + /** + * Get IModel with string from properties where his key is propertyExpression + * and params contains data for formatted string. + * + * @param propertyExpression + * @param params + * @return + */ + public static IModel getModel(String propertyExpression, Object... params) { + + return new StringResourceModel(propertyExpression, null, params); + } + /** * Get image from directory images. Not tested. * diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/StringUtils.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/StringUtils.java index de4a5768..106645df 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/StringUtils.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/components/utils/StringUtils.java @@ -31,7 +31,7 @@ public class StringUtils { public static String REGEX_ONLY_LETTERS = "[a-zA-Z][a-zA-Z\\s]*"; - public static String DATE_TIME_FORMAT_PATTER = "dd.MM.yyyy, HH:mm"; + public static String DATE_TIME_FORMAT_PATTER = "dd.MM.yyyy, HH:mm:ss"; public static String DATE_FORMAT_PATTER = "dd.MM.yyyy"; public static String DATE_TIME_FORMAT_PATTER_ONLY_YEAR = "yyyy"; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/article/ArticleServiceImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/article/ArticleServiceImpl.java index 9557cf0d..3b7cc67f 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/article/ArticleServiceImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/article/ArticleServiceImpl.java @@ -22,24 +22,33 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.wui.core.article; -import cz.zcu.kiv.eegdatabase.data.dao.ArticleCommentDao; -import cz.zcu.kiv.eegdatabase.data.dao.ArticleDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Article; -import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.TreeSet; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Required; import org.springframework.transaction.annotation.Transactional; -import java.util.List; +import cz.zcu.kiv.eegdatabase.data.dao.ArticleCommentDao; +import cz.zcu.kiv.eegdatabase.data.dao.ArticleDao; +import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; +import cz.zcu.kiv.eegdatabase.data.pojo.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.data.service.MailService; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; public class ArticleServiceImpl implements ArticleService { - + protected Log log = LogFactory.getLog(getClass()); - ArticleDao dao; - ArticleCommentDao commentDao; + private ArticleDao dao; + private ArticleCommentDao commentDao; + private MailService mailService; + private ResearchGroupDao groupDao; @Required public void setDao(ArticleDao dao) { @@ -51,10 +60,32 @@ public void setCommentDao(ArticleCommentDao commentDao) { this.commentDao = commentDao; } + @Required + public void setMailService(MailService mailService) { + this.mailService = mailService; + } + + @Required + public void setGroupDao(ResearchGroupDao groupDao) { + this.groupDao = groupDao; + } + @Override @Transactional - public Integer create(Article newInstance) { - return dao.create(newInstance); + public Integer create(Article article) { + + Integer id = dao.create(article); + + if (article.getResearchGroup() != null) { + ResearchGroup group = groupDao.read(article.getResearchGroup().getResearchGroupId()); + for (Person subscriber : group.getArticlesSubscribers()) { + if (!subscriber.equals(article.getPerson())) { + mailService.sendNotification(subscriber.getEmail(), article, EEGDataBaseSession.get().getLocale()); + } + } + } + + return id; } @Override @@ -78,7 +109,15 @@ public void update(Article transientObject) { @Override @Transactional public void delete(Article persistentObject) { + dao.delete(persistentObject); + + List comments = commentDao.getCommentsForArticle(persistentObject.getArticleId()); + + for (ArticleComment comment : comments) { + commentDao.delete(comment); + } + } @Override @@ -137,13 +176,30 @@ public int getArticleCountForPerson(Person person) { @Override @Transactional(readOnly = true) public Article getArticleDetail(int id, Person loggedPerson) { - return dao.getArticleDetail(id, loggedPerson); + + Article detail = dao.getArticleDetail(id, loggedPerson); + List comments = commentDao.getCommentsForArticle(detail.getArticleId()); + + detail.setArticleComments(new LinkedHashSet(comments)); + + return detail; } @Override @Transactional - public Integer create(ArticleComment newInstance) { - return commentDao.create(newInstance); + public Integer create(ArticleComment comment) { + + Integer id = commentDao.create(comment); + // logged user is that person who own this comment. + Person loggedUser = comment.getPerson(); + + Article article = dao.read(comment.getArticle().getArticleId()); + for (Person subscriber : article.getSubscribers()) { + if (!loggedUser.equals(subscriber)) { + mailService.sendNotification(subscriber.getEmail(), comment, EEGDataBaseSession.get().getLocale()); + } + } + return id; } @Override diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsFacade.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsFacade.java new file mode 100644 index 00000000..df58b026 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsFacade.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * KeywordsFacade.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.core.common; + +import cz.zcu.kiv.eegdatabase.data.pojo.Keywords; +import cz.zcu.kiv.eegdatabase.wui.core.GenericFacade; + +public interface KeywordsFacade extends GenericFacade { + + String getKeywords(int groupId); + + int getID(int groupId); +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsFacadeImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsFacadeImpl.java new file mode 100644 index 00000000..0e63f776 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsFacadeImpl.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * KeywordsFacadeImpl.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.core.common; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Required; + +import cz.zcu.kiv.eegdatabase.data.pojo.Keywords; + +public class KeywordsFacadeImpl implements KeywordsFacade { + + private KeywordsService service; + + @Required + public void setService(KeywordsService service) { + this.service = service; + } + + @Override + public Integer create(Keywords newInstance) { + return service.create(newInstance); + } + + @Override + public Keywords read(Integer id) { + return service.read(id); + } + + @Override + public List readByParameter(String parameterName, Object parameterValue) { + return service.readByParameter(parameterName, parameterValue); + } + + @Override + public void update(Keywords transientObject) { + service.update(transientObject); + } + + @Override + public void delete(Keywords persistentObject) { + service.delete(persistentObject); + } + + @Override + public List getAllRecords() { + return service.getAllRecords(); + } + + @Override + public List getRecordsAtSides(int first, int max) { + return service.getRecordsAtSides(first, max); + } + + @Override + public int getCountRecords() { + return service.getCountRecords(); + } + + @Override + public List getUnique(Keywords example) { + return service.getUnique(example); + } + + @Override + public String getKeywords(int groupId) { + return service.getKeywords(groupId); + } + + @Override + public int getID(int groupId) { + return service.getID(groupId); + } +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsService.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsService.java new file mode 100644 index 00000000..563cd6bb --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsService.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * KeywordsService.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.core.common; + +import cz.zcu.kiv.eegdatabase.data.pojo.Keywords; +import cz.zcu.kiv.eegdatabase.wui.core.GenericService; + +public interface KeywordsService extends GenericService { + + String getKeywords(int groupId); + + int getID(int groupId); +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsServiceImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsServiceImpl.java new file mode 100644 index 00000000..9188ade8 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/common/KeywordsServiceImpl.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * KeywordsServiceImpl.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.core.common; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Required; +import org.springframework.transaction.annotation.Transactional; + +import cz.zcu.kiv.eegdatabase.data.dao.SimpleKeywordsDao; +import cz.zcu.kiv.eegdatabase.data.pojo.Keywords; + +public class KeywordsServiceImpl implements KeywordsService { + + private SimpleKeywordsDao dao; + + @Required + public void setDao(SimpleKeywordsDao dao) { + this.dao = dao; + } + + @Override + @Transactional + public Integer create(Keywords newInstance) { + return dao.create(newInstance); + } + + @Override + @Transactional(readOnly = true) + public Keywords read(Integer id) { + return dao.read(id); + } + + @Override + @Transactional(readOnly = true) + public List readByParameter(String parameterName, Object parameterValue) { + return dao.readByParameter(parameterName, parameterValue); + } + + @Override + @Transactional + public void update(Keywords transientObject) { + dao.update(transientObject); + } + + @Override + @Transactional + public void delete(Keywords persistentObject) { + dao.delete(persistentObject); + } + + @Override + @Transactional(readOnly = true) + public List getAllRecords() { + return dao.getAllRecords(); + } + + @Override + @Transactional(readOnly = true) + public List getRecordsAtSides(int first, int max) { + return dao.getRecordsAtSides(first, max); + } + + @Override + @Transactional(readOnly = true) + public int getCountRecords() { + return dao.getCountRecords(); + } + + @Override + @Transactional(readOnly = true) + public List getUnique(Keywords example) { + return dao.findByExample(example); + } + + @Override + @Transactional(readOnly = true) + public String getKeywords(int groupId) { + return dao.getKeywords(groupId); + } + + @Override + @Transactional(readOnly = true) + public int getID(int groupId) { + return dao.getID(groupId); + } +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/group/ResearchGroupServiceImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/group/ResearchGroupServiceImpl.java index 1a17cabd..8e6c0fb1 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/group/ResearchGroupServiceImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/group/ResearchGroupServiceImpl.java @@ -260,7 +260,7 @@ public void update(ResearchGroup group) { @Override @Transactional(readOnly = true) public ResearchGroup getResearchGroupById(int id) { - return researchGroupDAO.read(id); + return researchGroupDAO.getResearchGroupById(id); } @Override diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.html index 14abb2bb..61c827a5 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.html +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/account/AccountOverViewPage.html @@ -54,7 +54,7 @@

- +
diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManagePersonPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManagePersonPage.html new file mode 100644 index 00000000..ffcab589 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManagePersonPage.html @@ -0,0 +1,123 @@ + + + + + +
+ +
+ +

+ +

+ +
+ +
+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+ +
+ +
+ +
+ + + +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManagePersonPage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManagePersonPage.java new file mode 100644 index 00000000..44466abc --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManagePersonPage.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * AdminManagePersonPage.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.administration; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; +import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AbstractAutoCompleteTextRenderer; +import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings; +import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.model.Model; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.util.string.Strings; + +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.form.PersonForm; +import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu; +import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.educationlevel.EducationLevelFacade; +import cz.zcu.kiv.eegdatabase.wui.core.person.PersonFacade; + +@AuthorizeInstantiation("ROLE_ADMIN") +public class AdminManagePersonPage extends MenuPage { + + private static final long serialVersionUID = -353795863744483030L; + + @SpringBean + private PersonFacade personFacade; + + @SpringBean + private EducationLevelFacade educationFacade; + + public AdminManagePersonPage() { + + setPageTitle(ResourceUtils.getModel("menuItem.managePerson")); + add(new ButtonPageMenu("leftMenu", AdministrationPageLeftMenu.values())); + + Model person = new Model(); + PersonForm personForm = new PersonForm("form", person, educationFacade, personFacade, getFeedback()); + personForm.setOutputMarkupPlaceholderTag(true); + personForm.setVisible(false); + addPersonField(personForm); + add(personForm); + } + + private void addPersonField(final PersonForm form) { + + // added autocomplete textfield for subject + AutoCompleteSettings settings = prepareAutoCompleteSettings(); + + AbstractAutoCompleteTextRenderer renderer = new AbstractAutoCompleteTextRenderer() { + + private static final long serialVersionUID = 1L; + + @Override + protected String getTextValue(Person object) { + return object.getAutoCompleteData(); + } + }; + + final AutoCompleteTextField personField = new AutoCompleteTextField("personField", new Model(), + Person.class, renderer, settings) { + + private static final long serialVersionUID = 1L; + + @Override + protected Iterator getChoices(String input) { + List choices; + List allChoices = personFacade.getAllRecords(); + + if (Strings.isEmpty(input)) { + choices = allChoices; + } else { + + choices = new ArrayList(10); + for (Person t : allChoices) { + if ((t.getAutoCompleteData() != null) && + t.getAutoCompleteData().toLowerCase().contains(input.toLowerCase()) + || t.getAutoCompleteData().toLowerCase().startsWith(input.toLowerCase())) { + choices.add(t); + } + } + } + Collections.sort(choices); + return choices.iterator(); + } + }; + + personField.setLabel(ResourceUtils.getModel("label.subjectPerson")); + personField.add(new AjaxFormComponentUpdatingBehavior("onChange") { + + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate(AjaxRequestTarget target) { + + Person person = personField.getModelObject(); + if (person.getPersonId() != 0) { + form.setModelObject(person); + form.setVisible(true); + } + + target.add(getFeedback(), form); + } + }); + Form selectForm = new Form("selectForm"); + add(selectForm.add(personField)); + } + + private AutoCompleteSettings prepareAutoCompleteSettings() { + + AutoCompleteSettings settings = new AutoCompleteSettings(); + settings.setShowListOnEmptyInput(true); + settings.setShowCompleteListOnFocusGain(true); + settings.setUseHideShowCoveredIEFix(false); + settings.setMaxHeightInPx(200); + settings.setAdjustInputWidth(false); + return settings; + } +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManageUserRolePage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManageUserRolePage.html new file mode 100644 index 00000000..a0609de5 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManageUserRolePage.html @@ -0,0 +1,82 @@ + + + + + +
+ +
+ +

+ +

+ +
+
+ +
+ +
+ +
+ + +
+ +

+ +

+ + +
+ +
+
+ + + + + + + + + + + + + + + + +
+
+
+
+
+
+ + diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManageUserRolePage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManageUserRolePage.java new file mode 100644 index 00000000..b531fae3 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdminManageUserRolePage.java @@ -0,0 +1,251 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * AdminManageUserRolePage.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.administration; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; +import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AbstractAutoCompleteTextRenderer; +import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteSettings; +import org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.EnumChoiceRenderer; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.PropertyListView; +import org.apache.wicket.markup.html.panel.FeedbackPanel; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.util.string.Strings; + +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroupMembership; +import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu; +import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.GroupRole; +import cz.zcu.kiv.eegdatabase.wui.core.UserRole; +import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; +import cz.zcu.kiv.eegdatabase.wui.core.person.PersonFacade; + +/** + * Page for change user role. + * + * @author Jakub Rinkes + * + */ +@AuthorizeInstantiation("ROLE_ADMIN") +public class AdminManageUserRolePage extends MenuPage { + + private static final long serialVersionUID = -1047855945455763134L; + + @SpringBean + PersonFacade personFacade; + + @SpringBean + ResearchGroupFacade groupFacade; + + public AdminManageUserRolePage() { + + setPageTitle(ResourceUtils.getModel("pageTitle.changeUserRole")); + + add(new ButtonPageMenu("leftMenu", AdministrationPageLeftMenu.values())); + + add(new ChangeUserRoleForm("form", new Model(), personFacade, getFeedback())); + } + + // inner for used for change user role + private class ChangeUserRoleForm extends Form { + + private static final long serialVersionUID = 1L; + + public ChangeUserRoleForm(String id, IModel model, final PersonFacade facade, final FeedbackPanel feedback) { + super(id, new CompoundPropertyModel(model)); + + final DropDownChoice roles = new DropDownChoice("authority", new Model(), Arrays.asList(UserRole.values()), + new EnumChoiceRenderer()); + roles.setLabel(ResourceUtils.getModel("label.userRole")); + roles.setOutputMarkupId(true); + roles.add(new AjaxFormComponentUpdatingBehavior("onChange") { + + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate(AjaxRequestTarget target) { + + UserRole role = roles.getModelObject(); + Person person = ChangeUserRoleForm.this.getModelObject(); + if (person != null && role != null) { + person.setAuthority(role.name()); + personFacade.update(person); + + String localizedValue = ResourceUtils.getString(roles.getModelObject().getClass().getSimpleName() + "." + roles.getModelObject()); + info(ResourceUtils.getString("text.administration.role.user.changed", ChangeUserRoleForm.this.getModelObject().getUsername(), localizedValue)); + target.add(feedback); + } + } + }); + + final PropertyListView groupRoles = new PropertyListView("groupRoles", Collections.EMPTY_LIST) { + + private static final long serialVersionUID = 1L; + + @Override + protected void populateItem(ListItem item) { + item.add(new Label("authority")); + item.add(new Label("person.username")); + item.add(new Label("researchGroup.title")); + + final ResearchGroupMembership membership = item.getModelObject(); + final DropDownChoice groupRoles = new DropDownChoice("groupRoles", + new Model(GroupRole.valueOf(membership.getAuthority())), + Arrays.asList(GroupRole.values()), + new EnumChoiceRenderer()); + + groupRoles.add(new AjaxFormComponentUpdatingBehavior("onChange") { + + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate(AjaxRequestTarget target) { + + GroupRole groupRole = groupRoles.getModelObject(); + membership.setAuthority(groupRole.name()); + groupFacade.updateMemberhip(membership); + + String localizedValue = ResourceUtils.getString(groupRole.getClass().getSimpleName() + "." + groupRole); + info(ResourceUtils.getString("text.administration.role.group.changed", membership.getPerson().getUsername(), + membership.getResearchGroup().getTitle(), localizedValue)); + target.add(feedback); + } + + }); + + item.add(groupRoles); + + } + + @Override + public boolean isVisible() { + return getModelObject() != null && getModelObject().size() != 0; + } + + }; + + WebMarkupContainer noGroups = new WebMarkupContainer("noGroups") { + + private static final long serialVersionUID = 1L; + + @Override + public boolean isVisible() { + return !groupRoles.isVisible(); + } + }; + + // added autocomplete textfield for subject + AutoCompleteSettings settings = prepareAutoCompleteSettings(); + + AbstractAutoCompleteTextRenderer renderer = new AbstractAutoCompleteTextRenderer() { + + private static final long serialVersionUID = 1L; + + @Override + protected String getTextValue(Person object) { + return object.getAutoCompleteData(); + } + }; + + final AutoCompleteTextField personField = new AutoCompleteTextField("personField", new Model(), + Person.class, renderer, settings) { + + private static final long serialVersionUID = 1L; + + @Override + protected Iterator getChoices(String input) { + List choices; + List allChoices = personFacade.getAllRecords(); + + if (Strings.isEmpty(input)) { + choices = allChoices; + } else { + + choices = new ArrayList(10); + for (Person t : allChoices) { + if ((t.getAutoCompleteData() != null) && + t.getAutoCompleteData().toLowerCase().contains(input.toLowerCase()) + || t.getAutoCompleteData().toLowerCase().startsWith(input.toLowerCase())) { + choices.add(t); + } + } + } + Collections.sort(choices); + return choices.iterator(); + } + }; + + personField.setLabel(ResourceUtils.getModel("label.subjectPerson")); + personField.add(new AjaxFormComponentUpdatingBehavior("onChange") { + + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate(AjaxRequestTarget target) { + + Person person = personField.getModelObject(); + if (person != null && person.getPersonId() != 0) { + ChangeUserRoleForm.this.setModelObject(person); + groupRoles.setModelObject(groupFacade.readMemberhipByParameter("person.id", person.getPersonId())); + roles.setModelObject(UserRole.valueOf(person.getAuthority())); + } + + target.add(getFeedback(), ChangeUserRoleForm.this); + } + }); + + add(roles, noGroups, groupRoles, personField); + } + + } + + private AutoCompleteSettings prepareAutoCompleteSettings() { + + AutoCompleteSettings settings = new AutoCompleteSettings(); + settings.setShowListOnEmptyInput(true); + settings.setShowCompleteListOnFocusGain(true); + settings.setUseHideShowCoveredIEFix(false); + settings.setMaxHeightInPx(200); + settings.setAdjustInputWidth(false); + return settings; + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdministrationPageLeftMenu.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdministrationPageLeftMenu.java index 8e05331f..8367faa2 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdministrationPageLeftMenu.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/AdministrationPageLeftMenu.java @@ -34,7 +34,8 @@ */ public enum AdministrationPageLeftMenu implements IButtonPageMenu { - CHANGE_USER_ROLE_PAGE(ChangeUserRolePage.class, "menuItem.changeUserRole", null), + CHANGE_USER_ROLE_PAGE(AdminManageUserRolePage.class, "menuItem.manageRoles", null), + MANAGE_PERSON(AdminManagePersonPage.class, "menuItem.managePerson", null), MANAGE_RESEARCH_GROUP_PAGE(ManageResearchGroupPage.class, "menuItem.manageResearchGroup", null) ; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/ManageResearchGroupPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/ManageResearchGroupPage.html index fc8ee291..99b13ede 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/ManageResearchGroupPage.html +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/ManageResearchGroupPage.html @@ -18,25 +18,27 @@ *********************************************************************************************************************** - ManageResearchGroupPage.html, 2013/10/02 00:01 Jakub Rinkes + ManageResearchGroupPage.html, 2014/05/13 00:01 Jakub Rinkes --> - + - -
+ +
-
+
-

- -

+

+ +

-
-
-
- +
+ + +
+
+
+
+
diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/ManageResearchGroupPage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/ManageResearchGroupPage.java index 7d7d2fa7..5653f177 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/ManageResearchGroupPage.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/ManageResearchGroupPage.java @@ -18,10 +18,17 @@ * * *********************************************************************************************************************** * - * ManageResearchGroupPage.java, 2013/10/02 00:01 Jakub Rinkes + * ManageResearchGroupPage.java, 2014/05/13 00:01 Jakub Rinkes ******************************************************************************/ package cz.zcu.kiv.eegdatabase.wui.ui.administration; +import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.util.ListModel; +import org.apache.wicket.spring.injection.annot.SpringBean; + import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu; import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; @@ -29,12 +36,6 @@ import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; import cz.zcu.kiv.eegdatabase.wui.ui.administration.components.ResearchGroupManagementForm; import cz.zcu.kiv.eegdatabase.wui.ui.lists.components.ResearchGroupSelectForm; -import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; -import org.apache.wicket.markup.html.WebMarkupContainer; -import org.apache.wicket.model.IModel; -import org.apache.wicket.model.Model; -import org.apache.wicket.model.util.ListModel; -import org.apache.wicket.spring.injection.annot.SpringBean; /** * Page for research group management, payments etc. @@ -43,7 +44,10 @@ */ @AuthorizeInstantiation("ROLE_ADMIN") public class ManageResearchGroupPage extends MenuPage { - @SpringBean + + private static final long serialVersionUID = -6454786667956638151L; + + @SpringBean private ResearchGroupFacade researchGroupFacade; private ListModel groupChoices; @@ -70,7 +74,7 @@ private void addComponents() { this.add(new ButtonPageMenu("leftMenu", AdministrationPageLeftMenu.values())); - managementComp = new ResearchGroupManagementForm("groupForm", selectedGroup) { + managementComp = new ResearchGroupManagementForm("groupForm", selectedGroup, getFeedback()) { @Override protected void onConfigure() { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/components/ResearchGroupManagementForm.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/components/ResearchGroupManagementForm.html index dd358737..ceae8663 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/components/ResearchGroupManagementForm.html +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/components/ResearchGroupManagementForm.html @@ -20,20 +20,44 @@ ResearchGroupManagementForm.html, 2013/10/02 00:01 Jakub Rinkes --> - -
-
+ + + + + +
+
+ + +
+
+
+ +
+ + +

+
-
-
+
+ + +

+
-
- - -
-
- -
+
+ + +
+
+
+ +
+ +
+
+ +
+ + diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/components/ResearchGroupManagementForm.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/components/ResearchGroupManagementForm.java index db543088..9b28196d 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/components/ResearchGroupManagementForm.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/administration/components/ResearchGroupManagementForm.java @@ -22,22 +22,26 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.wui.ui.administration.components; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; -import cz.zcu.kiv.eegdatabase.wui.components.utils.WicketUtils; -import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.form.AjaxButton; -import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.CheckBox; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.FormComponent; +import org.apache.wicket.markup.html.form.TextArea; +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.PropertyModel; import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.validation.validator.StringValidator; + +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.components.utils.WicketUtils; +import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; /** * Panel for research group management - payment settings, @@ -47,20 +51,24 @@ */ public class ResearchGroupManagementForm extends Panel { - @SpringBean + private static final long serialVersionUID = -1188319159199447785L; + + @SpringBean private ResearchGroupFacade researchGroupFacade; private IModel groupModel; private Form form; + private FeedbackPanel feedback; /** * * @param id component id * @param groupModel model with the group to display settings for */ - public ResearchGroupManagementForm(String id, IModel groupModel) { + public ResearchGroupManagementForm(String id, IModel groupModel, final FeedbackPanel feedback) { super(id); this.groupModel = groupModel; + this.feedback = feedback; this.form = new Form("form"); this.form.setOutputMarkupId(true); @@ -79,6 +87,22 @@ private void addContent(WebMarkupContainer f) { cmp.setLabel(ResourceUtils.getModel("label.paidAccount")); f.add(cmp); + + final TextField title = new TextField("title", new PropertyModel(this.groupModel, "title")); + title.setRequired(true); + title.setLabel(ResourceUtils.getModel("label.researchGroupTitle")); + title.add(StringValidator.maximumLength(100)); + + final TextArea description = new TextArea("description", new PropertyModel(this.groupModel, "description")); + description.setRequired(true); + description.setLabel(ResourceUtils.getModel("label.researchGroupDescription")); + description.add(StringValidator.maximumLength(250)); + + CheckBox lockCheckBox = new CheckBox("lock", new PropertyModel(this.groupModel, "lock")); + lockCheckBox.setLabel(ResourceUtils.getModel("label.lock")); + f.add(lockCheckBox); + + f.add(title, description); this.addControls(f); } @@ -90,11 +114,15 @@ private void addContent(WebMarkupContainer f) { private void addControls(WebMarkupContainer f) { Button button = new AjaxButton("submitButton", ResourceUtils.getModel("button.save")) { - @Override + private static final long serialVersionUID = 1L; + + @Override protected void onSubmit(AjaxRequestTarget target, Form form) { super.onSubmit(target, form); researchGroupFacade.update(groupModel.getObject()); - target.add(form); + + info(ResourceUtils.getString("text.administration.group.changed", groupModel.getObject().getTitle())); + target.add(form, feedback); } }; @@ -103,7 +131,9 @@ protected void onSubmit(AjaxRequestTarget target, Form form) { button = new AjaxButton("cancelButton", ResourceUtils.getModel("button.cancel")) { - @Override + private static final long serialVersionUID = 1L; + + @Override protected void onSubmit(AjaxRequestTarget target, Form form) { super.onSubmit(target, form); form.clearInput(); diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleCommentFormPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleCommentFormPage.html new file mode 100644 index 00000000..2f741dc1 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleCommentFormPage.html @@ -0,0 +1,39 @@ + + + + + +
+ +
+
+

+ +

+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleCommentFormPage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleCommentFormPage.java new file mode 100644 index 00000000..8c1b3a41 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleCommentFormPage.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ArticleCommentFormPage.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.articles; + +import org.apache.wicket.RestartResponseAtInterceptPageException; +import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; +import org.apache.wicket.model.Model; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.util.string.StringValue; + +import cz.zcu.kiv.eegdatabase.data.pojo.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu; +import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; +import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.UserRole; +import cz.zcu.kiv.eegdatabase.wui.core.article.ArticleFacade; +import cz.zcu.kiv.eegdatabase.wui.core.security.SecurityFacade; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.components.ArticleCommentFormPanel; + +@AuthorizeInstantiation(value = { "ROLE_READER", "ROLE_USER", "ROLE_EXPERIMENTER", "ROLE_ADMIN" }) +public class ArticleCommentFormPage extends MenuPage { + + private static final long serialVersionUID = -6483764280064711699L; + + @SpringBean + private ArticleFacade facade; + + @SpringBean + private SecurityFacade securityFacade; + + public ArticleCommentFormPage(PageParameters parameters) { + + + setPageTitle(ResourceUtils.getModel("label.addComment")); + add(new ButtonPageMenu("leftMenu", ArticlesPageLeftMenu.values())); + + StringValue articleParam = parameters.get(PageParametersUtils.ARTICLE); + StringValue commentParam = parameters.get(PageParametersUtils.COMMENT); + + if (articleParam.isNull() || articleParam.isEmpty() || commentParam.isEmpty() || commentParam.isNull()) { + throw new RestartResponseAtInterceptPageException(ArticlesPage.class); + } + + int articleId = articleParam.toInt(); + int commentId = commentParam.toInt(); + + Article article = facade.read(articleId); + + boolean isPublicArticle = article.getResearchGroup() == null; + testUserCanAddArticleComment(isPublicArticle); + + ArticleComment parentComment = facade.readComment(commentId); + Person person = EEGDataBaseSession.get().getLoggedUser(); + + ArticleComment newComment = new ArticleComment(); + newComment.setArticle(article); + newComment.setPerson(person); + newComment.setParent(parentComment); + + add(new ArticleCommentFormPanel("addCommentFormPanel", new Model(newComment), getFeedback())); + + } + + private void testUserCanAddArticleComment(boolean isPublicArticle) { + + boolean isUserAdmin = EEGDataBaseSession.get().hasRole(UserRole.ROLE_ADMIN.name()); + boolean userCanAddArticle = securityFacade.userIsGroupAdmin() || securityFacade.userIsExperimenter() || isPublicArticle || isUserAdmin; + if (!userCanAddArticle) { + throw new RestartResponseAtInterceptPageException(ArticlesPage.class); + } + } +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleFormPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleFormPage.html new file mode 100644 index 00000000..d58be083 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleFormPage.html @@ -0,0 +1,68 @@ + + + + + + +
+ +
+ +

+ +
+ +
+ + +
+ +
+ + +
+ +

+ +

+ +
+ +
+ +
+ + +
+ +
+ +
+ +
+ +
+
+ + diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleFormPage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleFormPage.java new file mode 100644 index 00000000..8175101b --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticleFormPage.java @@ -0,0 +1,210 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ArticleFormPage.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.articles; + +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.List; + +import org.apache.wicket.RestartResponseAtInterceptPageException; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.CheckBox; +import org.apache.wicket.markup.html.form.ChoiceRenderer; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.TextArea; +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.markup.html.panel.FeedbackPanel; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.util.string.StringValue; +import org.apache.wicket.validation.validator.StringValidator; + +import cz.zcu.kiv.eegdatabase.data.pojo.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.controller.social.LinkedInManager; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu; +import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; +import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.UserRole; +import cz.zcu.kiv.eegdatabase.wui.core.article.ArticleFacade; +import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; +import cz.zcu.kiv.eegdatabase.wui.core.security.SecurityFacade; + +@AuthorizeInstantiation(value = { "ROLE_READER", "ROLE_USER", "ROLE_EXPERIMENTER", "ROLE_ADMIN" }) +public class ArticleFormPage extends MenuPage { + + private static final long serialVersionUID = 8092717501137834521L; + + @SpringBean + private ArticleFacade articleFacade; + + @SpringBean + private SecurityFacade securityFacade; + + @SpringBean + private ResearchGroupFacade groupFacade; + + @SpringBean + private LinkedInManager linkedInManager; + + public ArticleFormPage() { + + testUserCanAddArticle(); + + setPageTitle(ResourceUtils.getModel("pageTitle.addArticle")); + add(new Label("title", ResourceUtils.getModel("pageTitle.addArticle"))); + + setupComponents(new Model
(new Article())); + } + + public ArticleFormPage(PageParameters parameters) { + + testUserCanAddArticle(); + + setPageTitle(ResourceUtils.getModel("pageTitle.editArticle")); + add(new Label("title", ResourceUtils.getModel("pageTitle.editArticle"))); + + StringValue param = parameters.get(DEFAULT_PARAM_ID); + if (param.isNull() || param.isEmpty()) { + throw new RestartResponseAtInterceptPageException(ArticlesPage.class); + } + + int articleId = param.toInt(); + Article article = articleFacade.getArticleDetail(articleId, EEGDataBaseSession.get().getLoggedUser()); + setupComponents(new Model
(article)); + } + + private void setupComponents(IModel
model) { + + add(new ButtonPageMenu("leftMenu", ArticlesPageLeftMenu.values())); + + add(new ArticleForm("form", model, getFeedback())); + } + + private void testUserCanAddArticle() { + boolean userAdmin = EEGDataBaseSession.get().hasRole(UserRole.ROLE_ADMIN.name()); + boolean userCanAddArticle = securityFacade.userIsGroupAdmin() || securityFacade.userIsExperimenter() || userAdmin; + if (!userCanAddArticle) { + throw new RestartResponseAtInterceptPageException(ArticlesPage.class); + } + } + + private class ArticleForm extends Form
{ + + private static final long serialVersionUID = 1L; + + public ArticleForm(String id, IModel
model, final FeedbackPanel feedback) { + super(id, new CompoundPropertyModel
(model)); + setOutputMarkupId(true); + final Person loggedUser = EEGDataBaseSession.get().getLoggedUser(); + + boolean userAdmin = EEGDataBaseSession.get().hasRole(UserRole.ROLE_ADMIN.name()); + + List groups = groupFacade.getResearchGroupsWhereAbleToWriteInto(loggedUser); + if (userAdmin) { + ResearchGroup defaultGroup = new ResearchGroup(); + defaultGroup.setResearchGroupId(0); + defaultGroup.setTitle(ResourceUtils.getString("select.option.article.public")); + groups.add(0, defaultGroup); + } + + ChoiceRenderer groupRenderer = new ChoiceRenderer("title", "researchGroupId"); + DropDownChoice groupChoice = new DropDownChoice("researchGroup", groups, groupRenderer); + groupChoice.setRequired(true); + groupChoice.setLabel(ResourceUtils.getModel("label.researchGroup")); + groupChoice.setEnabled(model.getObject().getArticleId() == 0); + add(groupChoice); + + if (userAdmin) { + groupChoice.setModelObject(groups.get(0)); + } + + TextField titleField = new TextField("title"); + titleField.setRequired(true); + titleField.add(StringValidator.maximumLength(150)); + titleField.setLabel(ResourceUtils.getModel("label.title")); + add(titleField); + + TextArea textArea = new TextArea("text"); + textArea.setRequired(true); + textArea.setLabel(ResourceUtils.getModel("label.text")); + textArea.setEscapeModelStrings(true); + add(textArea); + + final CheckBox linkedIn = new CheckBox("linkedin", new Model(Boolean.FALSE)); + add(linkedIn); + + AjaxButton submit = new AjaxButton("submit", ResourceUtils.getModel("button.save")) { + + private static final long serialVersionUID = 1L; + + @Override + protected void onError(AjaxRequestTarget target, Form form) { + target.add(feedback); + } + + @Override + protected void onSubmit(AjaxRequestTarget target, Form form) { + + Article article = ArticleForm.this.getModelObject(); + + // if research group is default, save article without group. + if (article.getResearchGroup().getResearchGroupId() == 0) { + article.setResearchGroup(null); + } + + if (article.getArticleId() > 0) { + // edit article + articleFacade.update(article); + setResponsePage(ViewArticlePage.class, PageParametersUtils.getDefaultPageParameters(article.getArticleId())); + } else { + // add new article + article.setPerson(loggedUser); + article.setTime(new Timestamp(Calendar.getInstance().getTime().getTime())); + Integer articleId = articleFacade.create(article); + setResponsePage(ViewArticlePage.class, PageParametersUtils.getDefaultPageParameters(articleId)); + } + + Boolean publishOnLinkedIn = linkedIn.getModelObject(); + if (publishOnLinkedIn) { + linkedInManager.publish(article.getTitle(), article.getText()); + } + } + }; + + add(submit); + + } + + } +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPage.html index 0207d122..0fd0f5f2 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPage.html +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPage.html @@ -21,12 +21,50 @@ ArticlesPage.html, 2013/10/02 00:01 Jakub Rinkes --> - + - + +
-
+
+ +

+ +
+ + + + +
+ +
+
+

+ LinkedIn article + +

+
+
+ + + | + + +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPage.java index 5ed1df81..60a4d9fd 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPage.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPage.java @@ -22,22 +22,140 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.wui.ui.articles; -import org.apache.wicket.RestartResponseAtInterceptPageException; +import java.util.List; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox; +import org.apache.wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator; import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.PageableListView; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.springframework.social.linkedin.api.Group; +import cz.zcu.kiv.eegdatabase.data.pojo.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.logic.controller.social.LinkedInManager; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu; import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; -import cz.zcu.kiv.eegdatabase.wui.components.page.UnderConstructPage; import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.article.ArticleFacade; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.components.ArticleListItemPanel; @AuthorizeInstantiation(value = { "ROLE_READER", "ROLE_USER", "ROLE_EXPERIMENTER", "ROLE_ADMIN" }) public class ArticlesPage extends MenuPage { + private static final int ARTICLES_PER_PAGE = 10; + + @SpringBean + private ArticleFacade articleFacade; + + @SpringBean + private LinkedInManager linkedInManager; + private static final long serialVersionUID = -1967810037377960414L; public ArticlesPage() { - + setPageTitle(ResourceUtils.getModel("title.page.articles")); - - throw new RestartResponseAtInterceptPageException(UnderConstructPage.class); + add(new ButtonPageMenu("leftMenu", ArticlesPageLeftMenu.values())); + + // title component + final Label pageTitle = new Label("title", ResourceUtils.getModel("pageTitle.allArticles")); + pageTitle.setOutputMarkupId(true); + add(pageTitle); + + // internal articles container + final WebMarkupContainer internalContainer = new WebMarkupContainer("internalContainer"); + internalContainer.setOutputMarkupPlaceholderTag(true); + add(internalContainer); + + // linkedin articles container + final WebMarkupContainer linkedInContainer = new WebMarkupContainer("linkedInContainer"); + linkedInContainer.setOutputMarkupPlaceholderTag(true); + add(linkedInContainer); + + // show configuration form + Form form = new Form("form"); + form.setOutputMarkupId(true); + add(form); + final Model internalModel = new Model(Boolean.TRUE); + final Model linkedInModel = new Model(Boolean.TRUE); + form.add(new AjaxCheckBox("showInternal", internalModel) { + + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate(AjaxRequestTarget target) { + updatePageTitleAndView(pageTitle, internalContainer, linkedInContainer, + internalModel, linkedInModel, target); + } + + }); + form.add(new AjaxCheckBox("showLinkedIn", linkedInModel) { + + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate(AjaxRequestTarget target) { + updatePageTitleAndView(pageTitle, internalContainer, linkedInContainer, + internalModel, linkedInModel, target); + } + }); + + // linkedin articles components + Group groupDetails = linkedInManager.getGroupDetails(); + linkedInContainer.add(new Label("groupDetails.name", new PropertyModel(groupDetails, "name"))); + linkedInContainer.add(new Label("groupDetails.description", new PropertyModel(groupDetails, "description"))); + + // internal articles components + Person loggedPerson = EEGDataBaseSession.get().getLoggedUser(); + List
list = articleFacade.getArticlesForUser(loggedPerson); + // list of internal articles with page control + PageableListView
articlesListView = new PageableListView
("articles", list, ARTICLES_PER_PAGE) { + + private static final long serialVersionUID = 1L; + + @Override + protected void populateItem(ListItem
item) { + item.add(new ArticleListItemPanel("item", item.getModel())); + } + }; + internalContainer.add(new AjaxPagingNavigator("topPaginator", articlesListView)); + internalContainer.add(new AjaxPagingNavigator("bottomPaginator", articlesListView)); + internalContainer.add(articlesListView); + + } + + private void updatePageTitleAndView(final Label pageTitle, final WebMarkupContainer internalContainer, final WebMarkupContainer linkedInContainer, final Model internalModel, + final Model linkedInModel, AjaxRequestTarget target) { + + // get show configuration from form + Boolean showInternalArticles = internalModel.getObject(); + Boolean showLinkedInArticles = linkedInModel.getObject(); + + // update visibility with data from form + internalContainer.setVisible(showInternalArticles); + linkedInContainer.setVisible(showLinkedInArticles); + + // change date for updated visibility configuration + if (showLinkedInArticles && showInternalArticles) { + pageTitle.setDefaultModelObject(ResourceUtils.getString("pageTitle.allArticles")); + } else if (!showLinkedInArticles && !showInternalArticles) { + pageTitle.setDefaultModelObject(ResourceUtils.getString("pageTitle.noArticles")); + } else if (showLinkedInArticles) { + pageTitle.setDefaultModelObject(ResourceUtils.getString("pageTitle.linkedInArticles")); + } else { + pageTitle.setDefaultModelObject(ResourceUtils.getString("pageTitle.internalArticles")); + } + + // ajax refresh + target.add(pageTitle, internalContainer, linkedInContainer); } } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPageLeftMenu.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPageLeftMenu.java new file mode 100644 index 00000000..de0aac10 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesPageLeftMenu.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ArticlesPageLeftMenu.java, 2014/03/07 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.articles; + +import org.apache.wicket.request.mapper.parameter.PageParameters; + +import cz.zcu.kiv.eegdatabase.wui.components.menu.button.IButtonPageMenu; +import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; + +public enum ArticlesPageLeftMenu implements IButtonPageMenu { + + ALL_ARTICLES(ArticlesPage.class, "menuItem.articles.allArticles", null), + ADD_ARTICLE(ArticleFormPage.class, "menuItem.articles.addArticle", null), + ARTICLES_SETTINGS(ArticlesSettingsPage.class, "menuItem.articles.settings", null), + + ; + + private Class pageClass; + private String pageTitleKey; + private PageParameters parameters; + + private ArticlesPageLeftMenu(Class pageClass, String pageTitleKey, PageParameters parameters) { + this.pageClass = pageClass; + this.pageTitleKey = pageTitleKey; + this.parameters = parameters; + } + + @Override + public Class getPageClass() { + return pageClass; + } + + @Override + public String getPageTitleKey() { + return pageTitleKey; + } + + @Override + public PageParameters getPageParameters() { + return parameters; + } +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesSettingsPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesSettingsPage.html new file mode 100644 index 00000000..bb3a57ea --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesSettingsPage.html @@ -0,0 +1,69 @@ + + + + + +
+ +
+ +

+ +

+

+ +

+
+
+ +
+ +

+ +
+
+
+

+ +

+ + + + + + + + + + + + + +
+
+
+ + \ No newline at end of file diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesSettingsPage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesSettingsPage.java new file mode 100644 index 00000000..719c7b9e --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ArticlesSettingsPage.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ArticlesSettingsPage.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.articles; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.TextArea; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.PropertyListView; +import org.apache.wicket.model.Model; +import org.apache.wicket.spring.injection.annot.SpringBean; + +import cz.zcu.kiv.eegdatabase.data.pojo.Keywords; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu; +import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.common.KeywordsFacade; +import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; +import cz.zcu.kiv.eegdatabase.wui.core.security.SecurityFacade; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.components.SubscribeGroupLink; + +@AuthorizeInstantiation(value = { "ROLE_READER", "ROLE_USER", "ROLE_EXPERIMENTER", "ROLE_ADMIN" }) +public class ArticlesSettingsPage extends MenuPage { + + private static final long serialVersionUID = 7335700157186853057L; + + @SpringBean + private ResearchGroupFacade groupFacade; + + @SpringBean + private KeywordsFacade keywordsFacade; + + @SpringBean + private SecurityFacade securityFacade; + + public ArticlesSettingsPage() { + + add(new ButtonPageMenu("leftMenu", ArticlesPageLeftMenu.values())); + setPageTitle(ResourceUtils.getModel("heading.ArticlesSettings")); + + setupComponents(); + + } + + private void setupComponents() { + + final Person loggedUser = EEGDataBaseSession.get().getLoggedUser(); + List groupList = groupFacade.getResearchGroupsWhereMember(loggedUser); + + List list = new ArrayList(); + for (ResearchGroup item : groupList) { + // gets keywords from DB + String keyword = keywordsFacade.getKeywords(item.getResearchGroupId()); + list.add(keyword); + } + + String keywords = list.size() > 0 ? list.get(0) : ""; + + Form form = new Form("filterForm"); + final TextArea textarea = new TextArea("keywords", new Model(keywords)); + add(textarea); + + AjaxButton filter = new AjaxButton("filter", ResourceUtils.getModel("button.changeFilter"), form) { + + private static final long serialVersionUID = 1L; + + @Override + protected void onSubmit(AjaxRequestTarget target, Form form) { + String keywords = textarea.getModelObject(); + setKeywordsFilter(loggedUser, keywords); + setResponsePage(ArticlesSettingsPage.class); + } + + }; + + PropertyListView groups = new PropertyListView("groups", groupList) { + + private static final long serialVersionUID = 1L; + + @Override + protected void populateItem(ListItem item) { + item.add(new Label("title")); + item.add(new SubscribeGroupLink("subscribe", item.getModel(), groupFacade)); + } + }; + + form.add(textarea, filter); + add(form, groups); + } + + private void setKeywordsFilter(final Person loggedUser, String keywords) { + Keywords keywordsRecord; + ResearchGroup researchGroup; + int keywordID; + List groups = groupFacade.getResearchGroupsWhereMember(loggedUser); + + for (ResearchGroup item : groups) { + keywordID = keywordsFacade.getID(item.getResearchGroupId()); + // research group id not exist in Keywords + if (keywordID == -1) { + keywordsRecord = new Keywords(); + researchGroup = new ResearchGroup(); + researchGroup.setResearchGroupId(item.getResearchGroupId()); + keywordsRecord.setKeywordsText(keywords); + keywordsRecord.setResearchGroup(researchGroup); + keywordsFacade.create(keywordsRecord); + // research group already exist in keywords + } else { + researchGroup = new ResearchGroup(); + researchGroup.setResearchGroupId(item.getResearchGroupId()); + keywordsRecord = keywordsFacade.read(keywordsFacade.getID(item.getResearchGroupId())); + keywordsRecord.setKeywordsText(keywords); + keywordsRecord.setResearchGroup(researchGroup); + keywordsFacade.update(keywordsRecord); + } + } + } +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ViewArticlePage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ViewArticlePage.html new file mode 100644 index 00000000..6e57b443 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ViewArticlePage.html @@ -0,0 +1,62 @@ + + + + + +
+ +
+
+

+ +
+ + | + | + + + + | + | + + | + +
+
+ +

+
+ +

+
    +
  • +
    +
  • +
+
+ +
+
+ + \ No newline at end of file diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ViewArticlePage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ViewArticlePage.java new file mode 100644 index 00000000..f4a5e197 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/ViewArticlePage.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ViewArticlePage.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.articles; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.wicket.RestartResponseAtInterceptPageException; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.basic.MultiLineLabel; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.PropertyListView; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.util.string.StringValue; + +import cz.zcu.kiv.eegdatabase.data.pojo.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.form.input.AjaxConfirmLink; +import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu; +import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; +import cz.zcu.kiv.eegdatabase.wui.components.table.TimestampLabel; +import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.components.utils.StringUtils; +import cz.zcu.kiv.eegdatabase.wui.core.UserRole; +import cz.zcu.kiv.eegdatabase.wui.core.article.ArticleFacade; +import cz.zcu.kiv.eegdatabase.wui.core.security.SecurityFacade; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.components.ArticleCommentFormPanel; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.components.ArticleCommentPanel; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.components.SubscribeLink; + +@AuthorizeInstantiation(value = { "ROLE_READER", "ROLE_USER", "ROLE_EXPERIMENTER", "ROLE_ADMIN" }) +public class ViewArticlePage extends MenuPage { + + private static final long serialVersionUID = -4755705839078394200L; + + @SpringBean + private ArticleFacade articleFacade; + + @SpringBean + private SecurityFacade securityFacade; + + public ViewArticlePage(PageParameters parameters) { + + StringValue param = parameters.get(DEFAULT_PARAM_ID); + if (param.isNull() || param.isEmpty()) { + throw new RestartResponseAtInterceptPageException(ArticlesPage.class); + } + int articleId = param.toInt(); + + setupComponents(articleId); + } + + private void setupComponents(int articleId) { + + add(new ButtonPageMenu("leftMenu", ArticlesPageLeftMenu.values())); + PageParameters pageParameters = PageParametersUtils.getDefaultPageParameters(articleId); + + final Article article = articleFacade.getArticleDetail(articleId, EEGDataBaseSession.get().getLoggedUser()); + CompoundPropertyModel
model = new CompoundPropertyModel
(article); + setDefaultModel(model); + + Label pageTitle = new Label("title"); + add(pageTitle); + + ResearchGroup group = article.getResearchGroup(); + add(new Label("group", group == null ? ResourceUtils.getString("label.publicArticle") : group.getTitle())); + add(new TimestampLabel("time", article.getTime(), StringUtils.DATE_FORMAT_PATTER)); + add(new Label("person.givenname").setRenderBodyOnly(true)); + add(new Label("person.surname").setRenderBodyOnly(true)); + + BookmarkablePageLink editLink = new BookmarkablePageLink("editLink", ArticleFormPage.class, pageParameters); + AjaxConfirmLink deleteLink = new AjaxConfirmLink("deleteLink", ResourceUtils.getString("text.delete.article")) { + + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) { + // delete article + articleFacade.delete(article); + setResponsePage(ArticlesPage.class); + } + }; + Person loggedUser = EEGDataBaseSession.get().getLoggedUser(); + boolean showControlLinks = EEGDataBaseSession.get().hasRole(UserRole.ROLE_ADMIN.name()) || + loggedUser.getPersonId() == article.getPerson().getPersonId(); + + editLink.setVisibilityAllowed(showControlLinks); + deleteLink.setVisibilityAllowed(showControlLinks); + add(editLink, deleteLink); + + add(new SubscribeLink("subscribe", model, articleFacade)); + + add(new MultiLineLabel("text")); + + ArticleComment comment = new ArticleComment(loggedUser); + comment.setArticle(article); + ArticleCommentFormPanel articleCommentFormPanel = new ArticleCommentFormPanel("commentFormPanel", new Model(comment), getFeedback()); + boolean canUserAddComment = securityFacade.userIsGroupAdmin() || securityFacade.userIsExperimenter(); + articleCommentFormPanel.setVisibilityAllowed(canUserAddComment); + add(articleCommentFormPanel); + + List commentList = new ArrayList(model.getObject().getArticleComments()); + PropertyListView comments = new PropertyListView("articleComments", commentList) { + + private static final long serialVersionUID = 1L; + + @Override + protected void populateItem(ListItem item) { + item.add(new ArticleCommentPanel("commentPanel", item.getModel())); + } + }; + comments.setRenderBodyOnly(true); + + add(comments); + + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentFormPanel.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentFormPanel.html new file mode 100644 index 00000000..899970b9 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentFormPanel.html @@ -0,0 +1,39 @@ + + + + + +
+

+
+ +
+ +
+ +
+
+
+ + \ No newline at end of file diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentFormPanel.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentFormPanel.java new file mode 100644 index 00000000..a520143e --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentFormPanel.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ArticleCommentFormPanel.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.articles.components; + +import java.sql.Timestamp; +import java.util.Date; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.TextArea; +import org.apache.wicket.markup.html.panel.FeedbackPanel; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.spring.injection.annot.SpringBean; + +import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; +import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.article.ArticleFacade; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ViewArticlePage; + +public class ArticleCommentFormPanel extends Panel { + + private static final long serialVersionUID = 1L; + + @SpringBean + ArticleFacade facade; + + public ArticleCommentFormPanel(String id, IModel model, final FeedbackPanel feedback) { + super(id, model); + + add(new CommentForm("form", model, feedback)); + setRenderBodyOnly(true); + } + + private class CommentForm extends Form { + + private static final long serialVersionUID = 1L; + + public CommentForm(String id, final IModel model, final FeedbackPanel feedback) { + super(id, new CompoundPropertyModel(model)); + + TextArea text = new TextArea("text"); + text.setEscapeModelStrings(true); + text.setRequired(true); + text.setLabel(ResourceUtils.getModel("label.text")); + add(text); + + AjaxButton submit = new AjaxButton("submit", ResourceUtils.getModel("button.save"), this) { + + private static final long serialVersionUID = 1L; + + @Override + protected void onError(AjaxRequestTarget target, Form form) { + target.add(feedback); + } + + @Override + protected void onSubmit(AjaxRequestTarget target, Form form) { + + ArticleComment articleComment = CommentForm.this.getModelObject(); + articleComment.setTime(new Timestamp(new Date().getTime())); + + if (articleComment.getCommentId() == 0) { + facade.create(articleComment); + } else { + facade.updateComment(articleComment); + } + + setResponsePage(ViewArticlePage.class, PageParametersUtils.getDefaultPageParameters(model.getObject().getArticle().getArticleId())); + + } + + }; + + add(submit); + + } + + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentPanel.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentPanel.html new file mode 100644 index 00000000..d898a48f --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentPanel.html @@ -0,0 +1,49 @@ + + + + + +
    +
  • + + | + + + + + + + + +
    + + +
    +
    +
    +
  • +
+
+ + \ No newline at end of file diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentPanel.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentPanel.java new file mode 100644 index 00000000..557ddbb9 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleCommentPanel.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ArticleCommentPanel.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.articles.components; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.basic.MultiLineLabel; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; +import org.apache.wicket.markup.html.list.ListItem; +import org.apache.wicket.markup.html.list.PropertyListView; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.request.mapper.parameter.PageParameters; + +import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; +import cz.zcu.kiv.eegdatabase.wui.components.table.TimestampLabel; +import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; +import cz.zcu.kiv.eegdatabase.wui.components.utils.StringUtils; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ArticleCommentFormPage; + +public class ArticleCommentPanel extends Panel { + + private static final long serialVersionUID = -6031347593914148212L; + + public ArticleCommentPanel(String id, IModel model) { + super(id, new CompoundPropertyModel(model)); + + setRenderBodyOnly(true); + add(new TimestampLabel("time", model.getObject().getTime(), StringUtils.DATE_TIME_FORMAT_PATTER)); + add(new Label("person.givenname").setRenderBodyOnly(true)); + add(new Label("person.surname").setRenderBodyOnly(true)); + + add(new MultiLineLabel("text")); + List commentList = new ArrayList(model.getObject().getChildren()); + PropertyListView comments = new PropertyListView("children", commentList) { + + private static final long serialVersionUID = 1L; + + @Override + protected void populateItem(ListItem item) { + item.add(new ArticleCommentPanel("comments", item.getModel())); + } + }; + comments.setRenderBodyOnly(true); + + PageParameters parameters = PageParametersUtils.getPageParameters(PageParametersUtils.ARTICLE, model.getObject().getArticle().getArticleId()); + parameters = PageParametersUtils.addParameters(parameters, PageParametersUtils.COMMENT, model.getObject().getCommentId()); + + BookmarkablePageLink addCommentLink = new BookmarkablePageLink("addCommentLink", ArticleCommentFormPage.class, parameters); + + add(comments, addCommentLink); + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleListItemPanel.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleListItemPanel.html new file mode 100644 index 00000000..2c4d044b --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleListItemPanel.html @@ -0,0 +1,53 @@ + + + + + +
+
+

+ + +

+
+ + +
+ +
+ + +
+
+ + \ No newline at end of file diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleListItemPanel.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleListItemPanel.java new file mode 100644 index 00000000..ea671293 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/ArticleListItemPanel.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ArticleListItemPanel.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.articles.components; + +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.link.BookmarkablePageLink; +import org.apache.wicket.markup.html.panel.Panel; +import org.apache.wicket.model.CompoundPropertyModel; +import org.apache.wicket.model.IModel; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.apache.wicket.spring.injection.annot.SpringBean; + +import cz.zcu.kiv.eegdatabase.data.pojo.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.form.input.AjaxConfirmLink; +import cz.zcu.kiv.eegdatabase.wui.components.table.TimestampLabel; +import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.components.utils.StringUtils; +import cz.zcu.kiv.eegdatabase.wui.core.UserRole; +import cz.zcu.kiv.eegdatabase.wui.core.article.ArticleFacade; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ArticleFormPage; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ArticlesPage; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ViewArticlePage; + +public class ArticleListItemPanel extends Panel { + + private static final long serialVersionUID = 1L; + + @SpringBean + private ArticleFacade facade; + + public ArticleListItemPanel(String id, final IModel
model) { + super(id, new CompoundPropertyModel
(model)); + + PageParameters pageParameters = PageParametersUtils.getDefaultPageParameters(model.getObject().getArticleId()); + BookmarkablePageLink viewLink = new BookmarkablePageLink("viewLink", ViewArticlePage.class, pageParameters); + viewLink.add(new Label("title")); + add(viewLink); + + String text = model.getObject().getText(); + add(new Label("text", text.length() > 500 ? text.substring(0, 500) : text)); + + BookmarkablePageLink readMoreLink = new BookmarkablePageLink("readMoreLink", ViewArticlePage.class, PageParametersUtils.getDefaultPageParameters(model.getObject() + .getArticleId())); + readMoreLink.setVisibilityAllowed(text.length() > 500); + add(readMoreLink); + + add(new TimestampLabel("time", model.getObject().getTime(), StringUtils.DATE_FORMAT_PATTER)); + + ResearchGroup group = model.getObject().getResearchGroup(); + add(new Label("groupLabel", ResourceUtils.getString("researchGroup")).setVisibilityAllowed(group != null)); + add(new Label("group", group == null ? ResourceUtils.getString("label.publicArticle") : group.getTitle())); + add(new Label("person.givenname")); + add(new Label("person.surname")); + add(new Label("articleComments.size", model.getObject().getArticleComments().size())); + + // edit / delete links + BookmarkablePageLink editLink = new BookmarkablePageLink("editLink", ArticleFormPage.class, pageParameters); + AjaxConfirmLink deleteLink = new AjaxConfirmLink("deleteLink", ResourceUtils.getString("text.delete.article")) { + + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) { + // delete article + facade.delete(model.getObject()); + setResponsePage(ArticlesPage.class); + } + }; + boolean showControlLinks = EEGDataBaseSession.get().hasRole(UserRole.ROLE_ADMIN.name()) || + EEGDataBaseSession.get().getLoggedUser().getPersonId() == model.getObject().getPerson().getPersonId(); + + editLink.setVisibilityAllowed(showControlLinks); + deleteLink.setVisibilityAllowed(showControlLinks); + add(editLink, deleteLink); + + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/SubscribeGroupLink.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/SubscribeGroupLink.java new file mode 100644 index 00000000..970757f9 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/SubscribeGroupLink.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * SubscribeGroupLink.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.articles.components; + +import java.util.HashSet; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; + +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; + +public class SubscribeGroupLink extends AjaxLink { + + private static final long serialVersionUID = 1L; + + protected Log log = LogFactory.getLog(getClass()); + + private ResearchGroupFacade facade; + private boolean subscribe; + private IModel subscribeLabel; + private IModel unsubscribeLabel; + private Label label; + + public SubscribeGroupLink(String id, IModel model, ResearchGroupFacade facade) { + super(id, new Model(facade.getResearchGroupById(model.getObject().getResearchGroupId()))); + setOutputMarkupId(true); + + this.facade = facade; + this.subscribeLabel = ResourceUtils.getModel("label.subscribe"); + this.unsubscribeLabel = ResourceUtils.getModel("label.unsubscribe"); + + ResearchGroup group = getModelObject(); + group.setArticlesSubscribers(new HashSet(group.getArticlesSubscribers())); + Person person = EEGDataBaseSession.get().getLoggedUser(); + + subscribe = group.getArticlesSubscribers().contains(person); + + label = new Label("label", !subscribe ? subscribeLabel : unsubscribeLabel); + label.setRenderBodyOnly(true); + + add(label.setOutputMarkupId(true)); + + } + + @Override + public void onClick(AjaxRequestTarget target) { + + Person person = EEGDataBaseSession.get().getLoggedUser(); + ResearchGroup group = getModelObject(); + + if (subscribe) { + group.getArticlesSubscribers().remove(person); + } else { + group.getArticlesSubscribers().add(person); + } + subscribe = !subscribe; + label.setDefaultModel(!subscribe ? subscribeLabel : unsubscribeLabel); + + facade.update(group); + + target.add(this); + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/SubscribeLink.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/SubscribeLink.java new file mode 100644 index 00000000..b84a3705 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/articles/components/SubscribeLink.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * SubscribeLink.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.articles.components; + +import java.util.HashSet; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.model.IModel; + +import cz.zcu.kiv.eegdatabase.data.pojo.Article; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.article.ArticleFacade; + +public class SubscribeLink extends AjaxLink
{ + + private static final long serialVersionUID = 1L; + + protected Log log = LogFactory.getLog(getClass()); + + private ArticleFacade articleFacade; + private boolean subscribe; + private IModel subscribeLabel; + private IModel unsubscribeLabel; + private Label label; + + public SubscribeLink(String id, IModel
model, ArticleFacade facade) { + super(id, model); + setOutputMarkupId(true); + + this.articleFacade = facade; + this.subscribeLabel = ResourceUtils.getModel("label.subscribe"); + this.unsubscribeLabel = ResourceUtils.getModel("label.unsubscribe"); + + Article article = getModelObject(); + article.setSubscribers(new HashSet(article.getSubscribers())); + Person person = EEGDataBaseSession.get().getLoggedUser(); + + subscribe = article.getSubscribers().contains(person); + + label = new Label("label", !subscribe ? subscribeLabel : unsubscribeLabel); + label.setRenderBodyOnly(true); + + add(label.setOutputMarkupId(true)); + + } + + @Override + public void onClick(AjaxRequestTarget target) { + + Person person = EEGDataBaseSession.get().getLoggedUser(); + Article article = articleFacade.getArticleDetail(getModelObject().getArticleId(), EEGDataBaseSession.get().getLoggedUser()); + + if (subscribe) { + article.getSubscribers().remove(person); + } else { + article.getSubscribers().add(person); + } + subscribe = !subscribe; + label.setDefaultModel(!subscribe ? subscribeLabel : unsubscribeLabel); + + articleFacade.update(article); + + target.add(this); + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/ExperimentFormPage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/ExperimentFormPage.java index 91285cfe..23e54873 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/ExperimentFormPage.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/ExperimentFormPage.java @@ -48,6 +48,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; import cz.zcu.kiv.eegdatabase.wui.app.EEGDataBaseApplication; import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; import cz.zcu.kiv.eegdatabase.wui.components.form.AjaxWizardButtonBar; @@ -113,7 +114,14 @@ private void setupComponents(final Model model) { public void onFinish() { Experiment experiment = model.getObject(); - + + ResearchGroup group = experiment.getResearchGroup(); + if (group != null && group.isLock()) { + this.error(ResourceUtils.getString("text.group.lock.experiment.create", group.getTitle())); + setResponsePage(getPage()); + return; + } + Set files = new HashSet(); try { List fileUploadList = fileModel.getObject(); diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/forms/wizard/AddExperimentScenarioForm.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/forms/wizard/AddExperimentScenarioForm.java index ca5ef8f8..9ea11435 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/forms/wizard/AddExperimentScenarioForm.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/experiments/forms/wizard/AddExperimentScenarioForm.java @@ -232,6 +232,7 @@ private void addResearchGroup() { // added dropdown choice for research group ChoiceRenderer renderer = new ChoiceRenderer("title", "researchGroupId"); List choices = researchGroupFacade.getResearchGroupsWhereAbleToWriteInto(EEGDataBaseSession.get().getLoggedUser()); + researchGroupChoice = new DropDownChoice("researchGroup", new PropertyModel(model.getObject(), "researchGroup"), choices, renderer); researchGroupChoice.setRequired(true); @@ -243,6 +244,11 @@ private void addResearchGroup() { @Override protected void onUpdate(AjaxRequestTarget target) { + + ResearchGroup group = researchGroupChoice.getModelObject(); + if (group != null && group.isLock()) { + researchGroupChoice.error(ResourceUtils.getString("text.group.lock.experiment.create", group.getTitle())); + } target.add(AddExperimentScenarioForm.this); } }); diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryAllTimeRangeRecordsDataProvider.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryAllTimeRangeRecordsDataProvider.java new file mode 100644 index 00000000..4925ad1e --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryAllTimeRangeRecordsDataProvider.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * HistoryAllTimeRangeRecordsDataProvider.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.history; + +import java.io.Serializable; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; + +import cz.zcu.kiv.eegdatabase.data.pojo.History; +import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; +import cz.zcu.kiv.eegdatabase.wui.core.history.HistoryFacade; + +// TODO change extended paretn class - use generic provider from master +public class HistoryAllTimeRangeRecordsDataProvider extends SortableDataProvider { + + private static final long serialVersionUID = -4981823056148067437L; + + private HistoryFacade facade; + + private List list; + + private int size; + + public HistoryAllTimeRangeRecordsDataProvider(HistoryFacade facade) { + this.facade = facade; + } + + public void setData(ChoiceHistory history, boolean isGroupAdmin, int groupId) { + + list = facade.getHistory(history, isGroupAdmin, groupId); + size = list.size(); + } + + public int getCountOfHistory() { + return size; + } + + @Override + public Iterator iterator(long first, long count) { + if (getSort() != null) + Collections.sort(list, new HistoryLastDownloadedDataProviderComparator()); + + if (size() < first + count) + return list.subList((int) first, (int) (first + size() - first)).iterator(); + + return list.subList((int) first, (int) (first + count)).iterator(); + } + + @Override + public long size() { + return size; + } + + @Override + public IModel model(History object) { + return new Model(object); + } + + private class HistoryLastDownloadedDataProviderComparator implements Comparator, Serializable { + + private static final long serialVersionUID = 1L; + + @SuppressWarnings("unchecked") + public int compare(final History h1, final History h2) { + PropertyModel model1 = new PropertyModel(h1, getSort().getProperty()); + PropertyModel model2 = new PropertyModel(h2, getSort().getProperty()); + + int result = 0; + + if (model1.getObject() == null) + result = -1; + else if (model2.getObject() == null) + result = 1; + else if (model1.getObject() != null && model2.getObject() != null) + result = model1.getObject().compareTo(model2.getObject()); + + if (!getSort().isAscending()) { + result = -result; + } + + return result; + } + + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryLastDownloadedDataProvider.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryLastDownloadedDataProvider.java new file mode 100644 index 00000000..806fabf6 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryLastDownloadedDataProvider.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * HistoryLastDownloadedDataProvider.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.history; + +import java.io.Serializable; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; + +import cz.zcu.kiv.eegdatabase.data.pojo.History; +import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; +import cz.zcu.kiv.eegdatabase.wui.core.history.HistoryFacade; + +//TODO change extended paretn class - use generic provider from master +public class HistoryLastDownloadedDataProvider extends SortableDataProvider { + + private static final long serialVersionUID = -4981823056148067437L; + + private HistoryFacade facade; + + private List list; + + private int size; + + public HistoryLastDownloadedDataProvider(HistoryFacade facade) { + this.facade = facade; + } + + public void setData(ChoiceHistory history, boolean isGroupAdmin, int groupId) { + + list = facade.getLastDownloadHistory(history, isGroupAdmin, groupId); + size = list.size(); + } + + @Override + public Iterator iterator(long first, long count) { + + if (getSort() != null) + Collections.sort(list, new HistoryLastDownloadedDataProviderComparator()); + + if (size() < first + count) + return list.subList((int) first, (int) (first + size() - first)).iterator(); + + return list.subList((int) first, (int) (first + count)).iterator(); + } + + @Override + public long size() { + return size; + } + + @Override + public IModel model(History object) { + return new Model(object); + } + + private class HistoryLastDownloadedDataProviderComparator implements Comparator, Serializable { + + private static final long serialVersionUID = 1L; + + @SuppressWarnings("unchecked") + public int compare(final History h1, final History h2) { + PropertyModel model1 = new PropertyModel(h1, getSort().getProperty()); + PropertyModel model2 = new PropertyModel(h2, getSort().getProperty()); + + int result = 0; + + if (model1.getObject() == null) + result = -1; + else if (model2.getObject() == null) + result = 1; + else if (model1.getObject() != null && model2.getObject() != null) + result = model1.getObject().compareTo(model2.getObject()); + + if (!getSort().isAscending()) { + result = -result; + } + + return result; + } + + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryLeftPageMenu.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryLeftPageMenu.java new file mode 100644 index 00000000..23444bac --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryLeftPageMenu.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * ListsLeftPageMenu.java, 2013/10/02 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.history; + +import org.apache.wicket.request.mapper.parameter.PageParameters; + +import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; +import cz.zcu.kiv.eegdatabase.wui.components.menu.button.IButtonPageMenu; +import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; +import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; + +/** + * Enumeration of left menu page for lists section. + * + * @author Jakub Rinkes + * + */ +public enum HistoryLeftPageMenu implements IButtonPageMenu { + + DAILY_HISTORY(HistoryPage.class, "menuItem.history.dailyHistory", PageParametersUtils.getDefaultPageParameters(ChoiceHistory.DAILY)), + WEEKLY_HISTORY(HistoryPage.class, "menuItem.history.weeklyHistory", PageParametersUtils.getDefaultPageParameters(ChoiceHistory.WEEKLY)), + MONTHLY_HISTORY(HistoryPage.class, "menuItem.history.monthlyHistory", PageParametersUtils.getDefaultPageParameters(ChoiceHistory.MONTHLY)), + ; + + private Class pageClass; + private String pageTitleKey; + private PageParameters parameters; + + private HistoryLeftPageMenu(Class pageClass, String pageTitleKey, PageParameters parameters) { + this.pageClass = pageClass; + this.pageTitleKey = pageTitleKey; + this.parameters = parameters; + } + + @Override + public Class getPageClass() { + return pageClass; + } + + @Override + public String getPageTitleKey() { + return pageTitleKey; + } + + @Override + public PageParameters getPageParameters() { + return parameters; + } +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryPage.html index 1924fb92..12d1fcb5 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryPage.html +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryPage.html @@ -22,11 +22,43 @@ --> + xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" + xml:lang="en" lang="en"> - + +
-
+
+ +
+

+ +
+ + +
+ +

+ +

+ +

+ +

+
+ + + +

+
+ +

+
+ +
+ +
+
diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryPage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryPage.java index 9970a93c..d603b45e 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryPage.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryPage.java @@ -22,22 +22,307 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.wui.ui.history; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; + import org.apache.wicket.RestartResponseAtInterceptPageException; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; +import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; +import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder; +import org.apache.wicket.extensions.markup.html.repeater.data.table.DefaultDataTable; +import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.markup.html.WebMarkupContainer; +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.ChoiceRenderer; +import org.apache.wicket.markup.html.form.DropDownChoice; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.image.NonCachingImage; +import org.apache.wicket.markup.html.image.resource.BufferedDynamicImageResource; +import org.apache.wicket.markup.repeater.Item; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.request.mapper.parameter.PageParameters; +import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.util.string.StringValue; +import cz.zcu.kiv.eegdatabase.data.pojo.History; +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; +import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; +import cz.zcu.kiv.eegdatabase.logic.controller.history.DownloadStatistic; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu; +import cz.zcu.kiv.eegdatabase.wui.components.page.BasePage; import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; -import cz.zcu.kiv.eegdatabase.wui.components.page.UnderConstructPage; +import cz.zcu.kiv.eegdatabase.wui.components.table.StyleClassPropertyColumn; +import cz.zcu.kiv.eegdatabase.wui.components.table.ViewLinkPanel; +import cz.zcu.kiv.eegdatabase.wui.components.utils.ChartUtils; import cz.zcu.kiv.eegdatabase.wui.components.utils.ResourceUtils; +import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; +import cz.zcu.kiv.eegdatabase.wui.core.history.HistoryFacade; +import cz.zcu.kiv.eegdatabase.wui.core.security.SecurityFacade; +import cz.zcu.kiv.eegdatabase.wui.ui.home.HomePage; +import cz.zcu.kiv.eegdatabase.wui.ui.people.PersonDetailPage; @AuthorizeInstantiation(value = { "ROLE_READER", "ROLE_USER", "ROLE_EXPERIMENTER", "ROLE_ADMIN" }) public class HistoryPage extends MenuPage { private static final long serialVersionUID = -1967810037377960414L; + private static final int ITEMS_PER_PAGE = 20; + + @SpringBean + private ResearchGroupFacade researchGroupFacade; + + @SpringBean + private HistoryFacade historyFacade; + + @SpringBean + private SecurityFacade securityFacade; + + private boolean isGroupAdmin; + private int groupId = -1; + private ChoiceHistory choice; + private NonCachingImage chartImage = null; + public HistoryPage() { - + addComponents(ChoiceHistory.DAILY); + } + + public HistoryPage(PageParameters parameters) { + + StringValue value = parseParameters(parameters); + + ChoiceHistory choice = ChoiceHistory.DAILY; + + try { + choice = ChoiceHistory.valueOf(ChoiceHistory.class, value.toString()); + } catch (IllegalArgumentException e) { + throw new RestartResponseAtInterceptPageException(HistoryPage.class); + } + + addComponents(choice); + } + + public void addComponents(final ChoiceHistory choice) { + + this.choice = choice; + + isGroupAdmin = securityFacade.userIsGroupAdmin(); + Person loggedUser = EEGDataBaseSession.get().getLoggedUser(); + ResearchGroup defaultGroup = loggedUser.getDefaultGroup(); + groupId = defaultGroup == null ? 0 : loggedUser.getDefaultGroup().getResearchGroupId(); + + final boolean admin = securityFacade.isAdmin(); + if (!admin && !isGroupAdmin) { + throw new RestartResponseAtInterceptPageException(HomePage.class); + } + + if (admin) { + groupId = 0; + isGroupAdmin = false; + } + setPageTitle(ResourceUtils.getModel("title.page.history")); + add(new ButtonPageMenu("leftMenu", HistoryLeftPageMenu.values())); + + final WebMarkupContainer container = new WebMarkupContainer("container"); + container.setOutputMarkupId(true); + + final HistoryTopDownloadsDataProvider topDownloadsDataProvider = new HistoryTopDownloadsDataProvider(historyFacade); + topDownloadsDataProvider.setData(choice, isGroupAdmin, groupId); + topDownloadsDataProvider.setSort("count", SortOrder.DESCENDING); + + final HistoryLastDownloadedDataProvider lastDownloadedDataProvider = new HistoryLastDownloadedDataProvider(historyFacade); + lastDownloadedDataProvider.setData(choice, isGroupAdmin, groupId); + lastDownloadedDataProvider.setSort("dateOfDownload", SortOrder.DESCENDING); + + final HistoryAllTimeRangeRecordsDataProvider allTimeRangeDataProvider = new HistoryAllTimeRangeRecordsDataProvider(historyFacade); + allTimeRangeDataProvider.setData(choice, isGroupAdmin, groupId); + allTimeRangeDataProvider.setSort("dateOfDownload", SortOrder.DESCENDING); + + if (choice == ChoiceHistory.DAILY) { + container.add(new Label("title", ResourceUtils.getModel("pageTitle.dailyDownloadHistory"))); + container.add(new Label("timePeriodStatistic", ResourceUtils.getModel("title.dailyStatistic"))); + container.add(new Label("allTimePeriodRecords", ResourceUtils.getModel("title.allDailyRecords"))); + + } else if (choice == ChoiceHistory.WEEKLY) { + container.add(new Label("title", ResourceUtils.getModel("pageTitle.weeklyDownloadHistory"))); + container.add(new Label("timePeriodStatistic", ResourceUtils.getModel("title.weeklyStatistic"))); + container.add(new Label("allTimePeriodRecords", ResourceUtils.getModel("title.allWeeklyRecords"))); + + } else if (choice == ChoiceHistory.MONTHLY) { + container.add(new Label("title", ResourceUtils.getModel("pageTitle.monthlyDownloadHistory"))); + container.add(new Label("timePeriodStatistic", ResourceUtils.getModel("title.monthlyStatistic"))); + container.add(new Label("allTimePeriodRecords", ResourceUtils.getModel("title.allMonthlyRecords"))); + + } else { + throw new RestartResponseAtInterceptPageException(HistoryPage.class); + } + + container.add(new Label("downloadFiles", ResourceUtils.getModel("text.downloadFiles")).setRenderBodyOnly(true)); + + final Model countModel = new Model("" + allTimeRangeDataProvider.getCountOfHistory()); + container.add(new Label("count", countModel).setRenderBodyOnly(true)); + + container.add(new Label("topDownloads", ResourceUtils.getModel("title.topDownloads"))); + + DefaultDataTable topDownloadedFilelist = new DefaultDataTable("topDownloadedFilelist", + createListColumnsTopDownloads(), topDownloadsDataProvider, ITEMS_PER_PAGE); + container.add(topDownloadedFilelist); + + getChartImage(); + container.add(chartImage); + + container.add(new Label("lastDownloaded", ResourceUtils.getModel("title.lastDownloaded"))); + + DefaultDataTable lastDownloadedFilesHistoryList = new DefaultDataTable("lastDownloadedFilesHistoryList", + createListColumnsLastDownloaded(), lastDownloadedDataProvider, ITEMS_PER_PAGE); + container.add(lastDownloadedFilesHistoryList); + + DefaultDataTable historyList = new DefaultDataTable("historyList", createListColumnsAllTimeRangeRecords(), allTimeRangeDataProvider, + ITEMS_PER_PAGE); + container.add(historyList); + + Form groupForm = new Form("form"); + ChoiceRenderer renderer = new ChoiceRenderer("title", "researchGroupId"); + List choices = researchGroupFacade.getResearchGroupsWhereUserIsGroupAdmin(loggedUser); + final DropDownChoice researchGroupChoice = new DropDownChoice("researchGroup", new Model(), choices, renderer); + + if(defaultGroup != null) + researchGroupChoice.setModelObject(defaultGroup); + + if (admin) { + ResearchGroup showAll = new ResearchGroup(); + showAll.setResearchGroupId(0); + showAll.setTitle(ResourceUtils.getString("select.option.allGroups")); + choices.add(0, showAll); + researchGroupChoice.setModelObject(showAll); + } + + researchGroupChoice.setRequired(true); + researchGroupChoice.setLabel(ResourceUtils.getModel("label.group")); + researchGroupChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") { + + private static final long serialVersionUID = 1L; + + @Override + protected void onUpdate(AjaxRequestTarget target) { + isGroupAdmin = securityFacade.userIsGroupAdmin(); + ResearchGroup group = researchGroupChoice.getModelObject(); + groupId = group == null ? -1 : group.getResearchGroupId(); + + if (groupId == 0 && admin) { + isGroupAdmin = false; + } + + topDownloadsDataProvider.setData(choice, isGroupAdmin, groupId); + lastDownloadedDataProvider.setData(choice, isGroupAdmin, groupId); + allTimeRangeDataProvider.setData(choice, isGroupAdmin, groupId); + + countModel.setObject("" + allTimeRangeDataProvider.getCountOfHistory()); + + getChartImage(); + + target.add(container); + } + }); + + groupForm.add(researchGroupChoice); + container.add(groupForm); + + add(container); + + } + + private void getChartImage() { + + List topDownloadedFilesList = historyFacade.getTopDownloadHistory(choice, isGroupAdmin, groupId); + long countOfFilesHistory = historyFacade.getCountOfFilesHistory(choice, isGroupAdmin, groupId); + + BufferedImage chart = ChartUtils.gererateChartForTopDownloadHistory(choice, groupId == -1 ? true : false, topDownloadedFilesList, countOfFilesHistory); + + BufferedDynamicImageResource res = new BufferedDynamicImageResource(); + res.setImage(chart); + + if (chartImage == null) + chartImage = new NonCachingImage("chart", res); + else + chartImage.setImageResource(res); + + chartImage.setOutputMarkupId(true); + } + + private List> createListColumnsTopDownloads() { + + List> columns = new ArrayList>(); + + columns.add(new StyleClassPropertyColumn(ResourceUtils.getModel("dataTable.heading.fileName"), "fileName", "fileName", "width100")); + + columns.add(new StyleClassPropertyColumn(ResourceUtils.getModel("dataTable.heading.count"), "count", "count", "width100")); + + return columns; + } + + private List> createListColumnsLastDownloaded() { + + List> columns = new ArrayList>(); + + columns.add(new StyleClassPropertyColumn(ResourceUtils.getModel("dataTable.heading.date"), "dateOfDownload", "dateOfDownload", "width100")); + + columns.add(new StyleClassPropertyColumn(ResourceUtils.getModel("dataTable.heading.fileName"), "dataFile.filename", "dataFile.filename", "width100")); + + columns.add(new StyleClassPropertyColumn(ResourceUtils.getModel("dataTable.heading.detailOfUser"), null, null, "width50") { + + private static final long serialVersionUID = 1L; + + @Override + public void populateItem(Item> item, String componentId, IModel rowModel) { + item.add(new ViewLinkPanel(componentId, PersonDetailPage.class, "person.personId", rowModel, ResourceUtils.getModel("link.detail"))); + } + }); + + return columns; + } + + private List> createListColumnsAllTimeRangeRecords() { - throw new RestartResponseAtInterceptPageException(UnderConstructPage.class); + List> columns = new ArrayList>(); + + columns.add(new StyleClassPropertyColumn(ResourceUtils.getModel("dataTable.heading.date"), "dateOfDownload", "dateOfDownload", "width100")); + + columns.add(new PropertyColumn(ResourceUtils.getModel("dataTable.heading.id"), "historyId", "historyId")); + + columns.add(new StyleClassPropertyColumn(ResourceUtils.getModel("dataTable.heading.fileName"), "dataFile.filename", "dataFile.filename", "width100")); + + columns.add(new StyleClassPropertyColumn(ResourceUtils.getModel("dataTable.heading.scenarioTitle"), "scenario.title", "scenario.title", "width100")); + + columns.add(new StyleClassPropertyColumn(ResourceUtils.getModel("dataTable.heading.user"), "person.fullName", "person.fullName", "width100")); + + columns.add(new StyleClassPropertyColumn(ResourceUtils.getModel("dataTable.heading.detailOfUser"), null, null, "width50") { + + private static final long serialVersionUID = 1L; + + @Override + public void populateItem(Item> item, String componentId, IModel rowModel) { + item.add(new ViewLinkPanel(componentId, PersonDetailPage.class, "person.personId", rowModel, ResourceUtils.getModel("link.detail"))); + } + }); + + return columns; } + + private StringValue parseParameters(PageParameters parameters) { + + StringValue value = parameters.get(BasePage.DEFAULT_PARAM_ID); + if (value.isNull() || value.isEmpty()) + throw new RestartResponseAtInterceptPageException(HistoryPage.class); + + return value; + } + } diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryTopDownloadsDataProvider.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryTopDownloadsDataProvider.java new file mode 100644 index 00000000..3936d549 --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/history/HistoryTopDownloadsDataProvider.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * This file is part of the EEG-database project + * + * ========================================== + * + * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) + * + * *********************************************************************************************************************** + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * *********************************************************************************************************************** + * + * HistoryTopDownloadsDataProvider.java, 2014/05/13 00:01 Jakub Rinkes + ******************************************************************************/ +package cz.zcu.kiv.eegdatabase.wui.ui.history; + +import java.io.Serializable; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider; +import org.apache.wicket.model.IModel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; + +import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; +import cz.zcu.kiv.eegdatabase.logic.controller.history.DownloadStatistic; +import cz.zcu.kiv.eegdatabase.wui.core.history.HistoryFacade; + +//TODO change extended paretn class - use generic provider from master +public class HistoryTopDownloadsDataProvider extends SortableDataProvider { + + private static final long serialVersionUID = -378398640716460880L; + + private HistoryFacade facade; + + private List list; + + private int size; + + public HistoryTopDownloadsDataProvider(HistoryFacade facade) { + this.facade = facade; + } + + public void setData(ChoiceHistory history, boolean isGroupAdmin, int groupId) { + + list = facade.getTopDownloadHistory(history, isGroupAdmin, groupId); + size = list.size(); + } + + @Override + public Iterator iterator(long first, long count) { + + if (getSort() != null) + Collections.sort(list, new HistoryTopDownloadsDataProviderComparator()); + + if (size() < first + count) + return list.subList((int) first, (int) (first + size() - first)).iterator(); + + return list.subList((int) first, (int) (first + count)).iterator(); + } + + @Override + public long size() { + return size; + } + + @Override + public IModel model(DownloadStatistic object) { + return new Model(object); + } + + private class HistoryTopDownloadsDataProviderComparator implements Comparator, Serializable { + + private static final long serialVersionUID = 1L; + + @SuppressWarnings("unchecked") + public int compare(final DownloadStatistic s1, final DownloadStatistic s2) { + PropertyModel model1 = new PropertyModel(s1, getSort().getProperty()); + PropertyModel model2 = new PropertyModel(s2, getSort().getProperty()); + + int result = 0; + + if (model1.getObject() == null) + result = -1; + else if (model2.getObject() == null) + result = 1; + else if (model1.getObject() != null && model2.getObject() != null) + result = model1.getObject().compareTo(model2.getObject()); + + if (!getSort().isAscending()) { + result = -result; + } + + return result; + } + + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/home/HomePage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/home/HomePage.html index 05df270e..e9473d88 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/home/HomePage.html +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/home/HomePage.html @@ -63,15 +63,15 @@

    -
  • Downloading
  • -
  • Add group
  • -
  • Account management
  • -
  • Wizard - add experiment
@@ -129,11 +129,11 @@

Login

Partners

    -
  • Registered with NIF
  • -
  • INCF National node of Czech Republic
  • diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ListScenariosPage.html b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ListScenariosPage.html index fd1d60a9..dafa5b9a 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ListScenariosPage.html +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ListScenariosPage.html @@ -28,9 +28,7 @@
    -

    - -

    +

    diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ListScenariosPage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ListScenariosPage.java index 156003f3..1c4a8033 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ListScenariosPage.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ListScenariosPage.java @@ -25,14 +25,19 @@ import java.util.ArrayList; import java.util.List; +import org.apache.wicket.RestartResponseAtInterceptPageException; import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation; import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator; import org.apache.wicket.extensions.markup.html.repeater.data.table.DefaultDataTable; import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; +import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider; import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; +import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.repeater.Item; import org.apache.wicket.model.IModel; +import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.spring.injection.annot.SpringBean; +import org.apache.wicket.util.string.StringValue; import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; import cz.zcu.kiv.eegdatabase.wui.components.menu.button.ButtonPageMenu; @@ -55,6 +60,7 @@ public class ListScenariosPage extends MenuPage { private static final long serialVersionUID = -1967810037377960414L; private static final int ITEMS_PER_PAGE = 20; + public static final String MY_SCENARIOS_PARAM = "MY_SCENARIOS"; @SpringBean ScenariosFacade scenariosFacade; @@ -62,15 +68,29 @@ public class ListScenariosPage extends MenuPage { public ListScenariosPage() { setPageTitle(ResourceUtils.getModel("pageTitle.listOfScenarios")); - setupComponents(); + add(new Label("title", ResourceUtils.getModel("pageTitle.listOfScenarios"))); + setupComponents(new ListScenariosDataProvider(scenariosFacade)); + } + + public ListScenariosPage(PageParameters parameters) + { + StringValue paramValue = parameters.get(MY_SCENARIOS_PARAM); + if(paramValue.isNull() || paramValue.isEmpty()) + { + throw new RestartResponseAtInterceptPageException(ListScenariosPage.class); + } else { + setPageTitle(ResourceUtils.getModel("menuItem.myScenarios")); + add(new Label("title", ResourceUtils.getModel("menuItem.myScenarios"))); + setupComponents(new MyScenarioDataProvider(scenariosFacade)); + } } - private void setupComponents() { + private void setupComponents(ISortableDataProvider provider) { add(new ButtonPageMenu("leftMenu", ScenariosPageLeftMenu.values())); DefaultDataTable list = new DefaultDataTable("list", createListColumns(), - new ListScenariosDataProvider(scenariosFacade), ITEMS_PER_PAGE); + provider, ITEMS_PER_PAGE); add(list); diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/MyScenarioDataProvider.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/MyScenarioDataProvider.java new file mode 100644 index 00000000..546de90b --- /dev/null +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/MyScenarioDataProvider.java @@ -0,0 +1,35 @@ +package cz.zcu.kiv.eegdatabase.wui.ui.scenarios; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder; + +import cz.zcu.kiv.eegdatabase.data.pojo.Person; +import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; +import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; +import cz.zcu.kiv.eegdatabase.wui.components.repeater.BasicDataProvider; +import cz.zcu.kiv.eegdatabase.wui.core.scenarios.ScenariosFacade; + +public class MyScenarioDataProvider extends BasicDataProvider { + + private static final long serialVersionUID = 3555979400074686801L; + + protected Log log = LogFactory.getLog(getClass()); + + ScenariosFacade facade; + + + public MyScenarioDataProvider(ScenariosFacade facade) { + super("scenarioId", SortOrder.ASCENDING); + + List list; + + Person loggedUser = EEGDataBaseSession.get().getLoggedUser(); + list = facade.getScenariosWhereOwner(loggedUser); + + super.listModel.setObject(list); + } + +} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ScenariosPageLeftMenu.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ScenariosPageLeftMenu.java index 90494d26..1e52dc2f 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ScenariosPageLeftMenu.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/scenarios/ScenariosPageLeftMenu.java @@ -27,6 +27,7 @@ import cz.zcu.kiv.eegdatabase.wui.components.menu.button.IButtonPageMenu; import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; import cz.zcu.kiv.eegdatabase.wui.components.page.UnderConstructPage; +import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; import cz.zcu.kiv.eegdatabase.wui.ui.scenarios.form.ScenarioFormPage; import cz.zcu.kiv.eegdatabase.wui.ui.scenarios.form.ScenarioSchemaFormPage; @@ -39,7 +40,12 @@ public enum ScenariosPageLeftMenu implements IButtonPageMenu { LIST_OF_SCENARIOS(ListScenariosPage.class, "menuItem.listOfScenarios", null), - MY_SCENARIOS(UnderConstructPage.class, "menuItem.myScenarios", null), + + MY_SCENARIOS(ListScenariosPage.class, "menuItem.myScenarios", + PageParametersUtils.getPageParameters( + ListScenariosPage.MY_SCENARIOS_PARAM, + ListScenariosPage.MY_SCENARIOS_PARAM)), + SEARCH_SCENARIOS(UnderConstructPage.class, "menuItem.searchScenario", null), ADD_SCENARIOS(ScenarioFormPage.class, "menuItem.addScenario", null), ADD_SCENARIOS_SCHEMA(ScenarioSchemaFormPage.class, "menuItem.addScenarioSchema", null), ; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/welcome/WelcomePage.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/welcome/WelcomePage.java index 7aaed0a7..b9f32739 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/welcome/WelcomePage.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/ui/welcome/WelcomePage.java @@ -42,7 +42,6 @@ import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; import cz.zcu.kiv.eegdatabase.wui.app.session.EEGDataBaseSession; import cz.zcu.kiv.eegdatabase.wui.components.page.MenuPage; -import cz.zcu.kiv.eegdatabase.wui.components.page.UnderConstructPage; import cz.zcu.kiv.eegdatabase.wui.components.table.TimestampLabel; import cz.zcu.kiv.eegdatabase.wui.components.table.ViewLinkPanel; import cz.zcu.kiv.eegdatabase.wui.components.utils.PageParametersUtils; @@ -52,6 +51,8 @@ import cz.zcu.kiv.eegdatabase.wui.core.experiments.ExperimentsFacade; import cz.zcu.kiv.eegdatabase.wui.core.group.ResearchGroupFacade; import cz.zcu.kiv.eegdatabase.wui.core.scenarios.ScenariosFacade; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ArticlesPage; +import cz.zcu.kiv.eegdatabase.wui.ui.articles.ViewArticlePage; import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ExperimentsDetailPage; import cz.zcu.kiv.eegdatabase.wui.ui.experiments.ListExperimentsPage; import cz.zcu.kiv.eegdatabase.wui.ui.groups.ListResearchGroupsPage; @@ -114,7 +115,7 @@ public WelcomePage() { else add(new Fragment("myGroups", "emptyFrag", this)); - add(new BookmarkablePageLink("articlesList", UnderConstructPage.class)); + add(new BookmarkablePageLink("articlesList", ArticlesPage.class)); add(new BookmarkablePageLink("experimentList", ListExperimentsPage.class, PageParametersUtils.getDefaultPageParameters(ListExperimentsPage.PARAM_OWNER))); add(new BookmarkablePageLink("meAsSubjectList", ListExperimentsPage.class, PageParametersUtils.getDefaultPageParameters(ListExperimentsPage.PARAM_SUBJECT))); add(new BookmarkablePageLink("scenariosList", ListScenariosPage.class)); @@ -137,7 +138,7 @@ protected void populateItem(ListItem
    item) { item.add(new TimestampLabel("time", item.getModelObject().getTime(), StringUtils.DATE_TIME_FORMAT_PATTER)); item.add(new Label("groupTitle", item.getModelObject().getResearchGroup() != null ? item.getModelObject().getResearchGroup().getTitle() : "Public Article")); item.add(new Label("comments", item.getModelObject().getArticleComments().size() + "")); - item.add(new ViewLinkPanel("articleTitle", UnderConstructPage.class, "articleId", item.getModel(), "title")); + item.add(new ViewLinkPanel("articleTitle", ViewArticlePage.class, "articleId", item.getModel(), "title")); } }; diff --git a/src/main/resources/cz/zcu/kiv/eegdatabase/wui/app/EEGDataBaseApplication.properties b/src/main/resources/cz/zcu/kiv/eegdatabase/wui/app/EEGDataBaseApplication.properties index 393da433..28187c1a 100644 --- a/src/main/resources/cz/zcu/kiv/eegdatabase/wui/app/EEGDataBaseApplication.properties +++ b/src/main/resources/cz/zcu/kiv/eegdatabase/wui/app/EEGDataBaseApplication.properties @@ -256,7 +256,8 @@ button.submitDisable= Submitting, please wait... button.visualization=Visualization currency.euro=\u20ac dataTable.heading.articleTitle=Article title -dataTable.heading.buy= +dataTable.heading.articleText=Article text +dataTable.heading.buy=Buy dataTable.heading.count=Count dataTable.heading.date=Date dataTable.heading.remove=Remove @@ -276,6 +277,7 @@ dataTable.heading.fileName=File name dataTable.heading.gender=Gender dataTable.heading.groupName=Group name dataTable.heading.groupTitle=Group title +dataTable.heading.groupDescription=Group description dataTable.heading.hardwareDescription=Description dataTable.heading.hardwareId=ID dataTable.heading.hardwareTitle=Title @@ -471,6 +473,7 @@ label.measuration=Experiment label.measurationId=Experiment ID label.minutes=minutes label.name=Name +label.noDataMessage=No data to display label.notAvailable=Not Available label.note=Note label.parameterDataType=Parameter data type @@ -563,6 +566,7 @@ label.experimentPackage.name=Package Name label.price.currency=EUR label.licensePolicy=Licensing Policy label.paidAccount=Premium Group +label.lock=Locked link.matchingPursuit=Matching Pursuit link.discreteWavelet=Discrete Wavelet Transformation link.continuousWavelet=Continuous Wavelet Transformation @@ -652,6 +656,8 @@ menuItem.searchPeople=Search people menuItem.searchScenario=Search scenario menuItem.writeRequests=Write requests menuItem.manageResearchGroup=Manage Research Groups +menuItem.managePerson=Manage Person +menuItem.manageRoles=Manage user roles option.And=AND option.None=NONE option.Or=OR @@ -850,6 +856,11 @@ text.youNeedExperimenterRole=You need experimenter role in a group to add data. text.youNeedToBeOwnerOrCoexperimenterToEditExperiment=You need to be owner or co-experimenter to edit experiment. text.license.add.public=Do you wish to add the package to public domain? text.license.remove.public=Do you wish to remove the package from public domain? +text.administration.role.user.changed=User role for user {0} changed to {1}. +text.administration.role.group.changed=Group role for user {0} in research group {1} changed to {2}. +text.administration.group.changed=Research group {0} was changed. +text.user.lock.login=User account {0} is locked. Contact administrator for unlocking. +text.group.lock.experiment.create=Research group {0} can't create or edit experiment. Research group is locked. title.accessInfo=Accessible only to group administrator and administrator. title.accessIsDenied="Access is denied" title.allDailyRecords=All daily records @@ -921,6 +932,7 @@ link.backToListOfItems=Back to list of items readMore=Read more researchGroup=Research group author=Author +text.delete.article=Are you sure you want to delete this article? #Search Page text.search.noResults=No results found. diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml index 005f4ed0..f0fa70c7 100644 --- a/src/main/resources/log4j.xml +++ b/src/main/resources/log4j.xml @@ -47,9 +47,26 @@ - + + + + + + + + + + + + + + + + + + @@ -85,6 +102,14 @@ + + + + + + + + @@ -94,5 +119,7 @@ + + diff --git a/src/main/webapp/WEB-INF/applicationContext.xml b/src/main/webapp/WEB-INF/applicationContext.xml index 18d9b9a7..2bd82670 100644 --- a/src/main/webapp/WEB-INF/applicationContext.xml +++ b/src/main/webapp/WEB-INF/applicationContext.xml @@ -153,7 +153,11 @@ - + + + + + diff --git a/src/main/webapp/WEB-INF/project.properties b/src/main/webapp/WEB-INF/project.properties index 79bae773..db9fd936 100644 --- a/src/main/webapp/WEB-INF/project.properties +++ b/src/main/webapp/WEB-INF/project.properties @@ -31,7 +31,7 @@ jdbc.password=eeg hibernate.show_sql=true # create/validate/create-drop/update -hibernate.hbm2ddl.auto=validate +hibernate.hbm2ddl.auto=update hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider hibernate.connection.pool_size=10 diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 74744870..491920a9 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -160,22 +160,4 @@ CXFServlet /webservice/* - - - SOAP CXF SSL - /webservice/* - - - CONFIDENTIAL - - - - - Spring REST SSL - /rest/* - - - CONFIDENTIAL - - diff --git a/src/main/webapp/files/style.css b/src/main/webapp/files/style.css index f310d182..78b174e0 100644 --- a/src/main/webapp/files/style.css +++ b/src/main/webapp/files/style.css @@ -187,16 +187,20 @@ while still visible in code, so it can be accessible without styles **/ padding: 5px; text-align: center; } -.paginator a { +.paginator > a, +.paginator > span { background: #666; color: #fff; text-decoration: none; } + +.paginator > span, .paginator .disabled { background: #ddd; color: #999; } -.paginator a, +.paginator > a, +.paginator > span, .paginator .disabled { font-size: 1.3em; padding: 3px 10px;