Commit bf475dd2 by Tuomas Riihimäki

Deploy-commit

1 parent 8930f7aa
Showing with 1711 additions and 401 deletions
......@@ -37,4 +37,14 @@ public interface ApiApplicationBeanLocal {
ApiApplication findApplication(String appKey);
String findUsernameForApikey(String appkey, String userkey, String domain);
ApiApplication createApiApplication(ApiApplication apiApp);
ApiApplication findApplication(Integer id);
ApiApplication saveApiApplication(ApiApplication apiApp);
List<ApiApplicationInstance> findInstances(ApiApplication apiApp);
ApiApplicationInstance saveApiInstance(ApiApplicationInstance selectedInstance);
}
......@@ -24,6 +24,7 @@ import javax.resource.spi.IllegalStateException;
import fi.codecrew.moya.enums.apps.IAppPermission;
import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.User;
@Local
......@@ -61,6 +62,7 @@ public interface PermissionBeanLocal {
String getPrincipalName();
// boolean hasPermission(String perm);
}
......@@ -147,6 +147,8 @@ public interface UserBeanLocal {
boolean isUserInRole(EventUser user, Integer roleId);
boolean isUserInRole(EventUser user, Role role);
EventUser getOtherEventsEventuser(User user, LanEvent event);
/**
......@@ -219,4 +221,5 @@ public interface UserBeanLocal {
List<EventUser> findAllEventusers(User user);
Map<Role,List<String>> findUsersRolesWithReason(EventUser user);
}
......@@ -22,10 +22,7 @@ import java.util.List;
import javax.ejb.Local;
import fi.codecrew.moya.model.Compo;
import fi.codecrew.moya.model.CompoEntry;
import fi.codecrew.moya.model.CompoEntryFile;
import fi.codecrew.moya.model.Vote;
import fi.codecrew.moya.model.*;
@Local
public interface VotingBeanLocal {
......@@ -59,4 +56,9 @@ public interface VotingBeanLocal {
public List<CompoEntry> getEntriesForCurrentUser();
Compo saveFiletype(CompoFileType filetype);
Compo deleteFiletype(CompoFileType ft);
CompoEntryFileType findEntryFileType(Integer entryId, Integer typeId);
}
......@@ -24,10 +24,8 @@ import java.util.List;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import javax.ejb.*;
import javax.security.jacc.EJBMethodPermission;
import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.facade.ApiApplicationFacade;
......@@ -47,7 +45,7 @@ import org.slf4j.LoggerFactory;
*/
@Singleton
@LocalBean
@DeclareRoles(SpecialPermission.S_SUPERADMIN)
@DeclareRoles({SpecialPermission.S_SUPERADMIN, SpecialPermission.S_USER})
public class ApiApplicationBean implements ApiApplicationBeanLocal {
@EJB
......@@ -71,6 +69,7 @@ public class ApiApplicationBean implements ApiApplicationBeanLocal {
UserBean userBean;
private static final Logger logger = LoggerFactory.getLogger(ApiApplicationBean.class);
/**
* Default constructor.
*/
......@@ -142,6 +141,69 @@ public class ApiApplicationBean implements ApiApplicationBeanLocal {
@Override
@RolesAllowed(SpecialPermission.S_USER)
public ApiApplication createApiApplication(ApiApplication apiApp) {
if (apiApp.getDeveloper() == null) {
apiApp.setDeveloper(permissionBean.getCurrentUser().getUser());
}
if (apiApp.getApplicationKey() == null || apiApp.getApplicationKey().isEmpty()) {
apiApp.setApplicationKey(PasswordFunctions.generateRandomString(20, PasswordFunctions.ALL_CHARS));
}
if (apiApp.getApplicationKey().length() < 8) {
throw new EJBException("Application key musst be at least 8 characters long");
}
if (!permissionBean.hasPermission(SpecialPermission.SUPERADMIN) && !permissionBean.isCurrentUser(apiApp.getDeveloper())) {
throw new EJBAccessException("Trying to create application for different user");
}
apiApp.setCreated(new Date());
applicationFacade.create(apiApp);
return apiApp;
}
@Override
@RolesAllowed(SpecialPermission.S_USER)
public ApiApplication findApplication(Integer id) {
ApiApplication ret = applicationFacade.find(id);
if (!permissionBean.isCurrentUser(ret.getDeveloper()) && !permissionBean.hasPermission(SpecialPermission.SUPERADMIN)) {
throw new EJBAccessException("Trying to return apiapp for wrong user");
}
return ret;
}
@Override
@RolesAllowed(SpecialPermission.S_USER)
public ApiApplication saveApiApplication(ApiApplication apiApp) {
if (!permissionBean.isCurrentUser(apiApp.getDeveloper()) && permissionBean.hasPermission(SpecialPermission.SUPERADMIN)) {
throw new EJBAccessException("Trying to save apiapp for another user");
}
return applicationFacade.merge(apiApp);
}
@Override
@RolesAllowed(SpecialPermission.S_USER)
public List<ApiApplicationInstance> findInstances(ApiApplication apiApp) {
return instanceFacade.findForUser(permissionBean.getCurrentUser(), apiApp);
}
@Override
@RolesAllowed(SpecialPermission.S_USER)
public ApiApplicationInstance saveApiInstance(ApiApplicationInstance instance) {
if (instance.getEventuser() == null) {
instance.setEventuser(permissionBean.getCurrentUser());
}
if (!permissionBean.isCurrentUser(instance.getEventuser()) && !permissionBean.hasPermission(SpecialPermission.SUPERADMIN)) {
throw new EJBAccessException("Trying to create apiInstance to foreign user");
}
if (instance.getId() == null) {
instanceFacade.create(instance);
return instance;
}
return instanceFacade.merge(instance);
}
@Override
@RolesAllowed(SpecialPermission.S_USER)
public List<ApiApplication> findMyApplications() {
EventUser curruser = permissionBean.getCurrentUser();
return applicationFacade.findForUser(curruser);
......@@ -153,4 +215,5 @@ public class ApiApplicationBean implements ApiApplicationBeanLocal {
return applicationFacade.findAll();
}
}
......@@ -595,7 +595,37 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE users_event_userproperties ADD CONSTRAINT FK_users_event_userproperties_property_id FOREIGN KEY (property_id) REFERENCES event_userproperties (id)",
"ALTER TABLE users_event_userproperties ADD CONSTRAINT FK_users_event_userproperties_user_id FOREIGN KEY (user_id) REFERENCES event_users (id)"
});
dbUpdates.add(new String[]{
"ALTER TABLE compo_entry_files ADD COLUMN type_id INTEGER",
"CREATE TABLE compo_file_types (id SERIAL NOT NULL, description TEXT, filetype TEXT, meta jsonb, name TEXT, required BOOLEAN, SORT INTEGER NOT NULL, compo_id INTEGER NOT NULL, PRIMARY KEY (id))",
"ALTER TABLE compo_entry_files ADD CONSTRAINT FK_compo_entry_files_type_id FOREIGN KEY (type_id) REFERENCES compo_file_types (id)",
"ALTER TABLE compo_file_types ADD CONSTRAINT FK_compo_file_types_compo_id FOREIGN KEY (compo_id) REFERENCES compos (id)"
});
dbUpdates.add(new String[]{
"ALTER TABLE compo_entry_files RENAME TO old_compo_entry_file",
"CREATE TABLE compo_entry_files (id SERIAL NOT NULL, description TEXT, file_name TEXT, filepath TEXT NOT NULL, hash TEXT, meta jsonb, mime_type TEXT, uploaded TIMESTAMPTZ NOT NULL, entryfiletype_id INTEGER NOT NULL, PRIMARY KEY (id))",
"CREATE TABLE compo_entry_file_types (id SERIAL NOT NULL, meta jsonb, updated TIMESTAMPTZ NOT NULL, current_file_id INTEGER, entry_id INTEGER NOT NULL, type_id INTEGER NOT NULL, PRIMARY KEY (id))",
"ALTER TABLE compo_entry_file_types ADD CONSTRAINT UNQ_compo_entry_file_types_0 UNIQUE (entry_id, type_id)",
"ALTER TABLE compo_entry_file_types ADD CONSTRAINT FK_compo_entry_file_types_type_id FOREIGN KEY (type_id) REFERENCES compo_file_types (id)",
"ALTER TABLE compo_entry_file_types ADD CONSTRAINT FK_compo_entry_file_types_current_file_id FOREIGN KEY (current_file_id) REFERENCES compo_entry_files (id)",
"ALTER TABLE compo_entry_file_types ADD CONSTRAINT FK_compo_entry_file_types_entry_id FOREIGN KEY (entry_id) REFERENCES compo_entries (id)",
"ALTER TABLE compo_entry_files ADD CONSTRAINT FK_compo_entry_files_entryfiletype_id FOREIGN KEY (entryfiletype_id) REFERENCES compo_entry_file_types (id)",
});
dbUpdates.add(new String[]{
"CREATE TABLE compo_voting_schemes (id SERIAL NOT NULL, allow_recusal BOOLEAN NOT NULL, max_value DECIMAL(24,8), meta jsonb, min_value DECIMAL(24,8), name TEXT NOT NULL, type TEXT NOT NULL, value_increment DECIMAL(24,8), event_id INTEGER NOT NULL, PRIMARY KEY (id))",
"CREATE TABLE compo_voting_roles (id SERIAL NOT NULL, meta jsonb, multiplier DECIMAL(24,8) NOT NULL, override_max DECIMAL(24,8), override_min DECIMAL(24,8), override_others BOOLEAN NOT NULL, PRIORITY INTEGER NOT NULL, role_id INTEGER NOT NULL, scheme_id INTEGER NOT NULL, PRIMARY KEY (id))",
"ALTER TABLE COMPOS ADD COLUMN entrysubmit_role_id INTEGER, ADD COLUMN voting_scheme_id INTEGER",
"ALTER TABLE compo_voting_schemes ADD CONSTRAINT FK_compo_voting_schemes_event_id FOREIGN KEY (event_id) REFERENCES events (id)",
"ALTER TABLE compos ADD CONSTRAINT FK_compos_voting_scheme_id FOREIGN KEY (voting_scheme_id) REFERENCES compo_voting_schemes (id)",
"ALTER TABLE compo_voting_roles ADD CONSTRAINT UNQ_compo_voting_roles_0 UNIQUE (scheme_id, role_id)",
"ALTER TABLE compo_voting_roles ADD CONSTRAINT FK_compo_voting_roles_scheme_id FOREIGN KEY (scheme_id) REFERENCES compo_voting_schemes (id)",
"ALTER TABLE compo_voting_roles ADD CONSTRAINT FK_compo_voting_roles_role_id FOREIGN KEY (role_id) REFERENCES roles (id)",
});
}
......
......@@ -28,6 +28,7 @@ import javax.resource.spi.IllegalStateException;
import fi.codecrew.moya.enums.apps.*;
import fi.codecrew.moya.facade.EventFacade;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.utilities.UserLoginUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -127,6 +128,8 @@ public class PermissionBean implements PermissionBeanLocal {
@EJB
private EventBean eventbean;
@EJB
private UserBean userbean;
@Override
......
......@@ -998,6 +998,12 @@ public class UserBean implements UserBeanLocal {
}
@Override
public boolean isUserInRole(EventUser user, Role role) {
return role != null && isUserInRole(user, role.getId());
}
@Override
public User getUser(Integer id) {
User ret = userFacade.find(id);
......
......@@ -20,6 +20,7 @@ package fi.codecrew.moya.beans;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.annotation.security.DeclareRoles;
......@@ -28,19 +29,13 @@ import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.facade.*;
import fi.codecrew.moya.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.enums.apps.CompoPermission;
import fi.codecrew.moya.facade.CompoEntryFacade;
import fi.codecrew.moya.facade.CompoEntryFileFacade;
import fi.codecrew.moya.facade.CompoFacade;
import fi.codecrew.moya.facade.VoteFacade;
import fi.codecrew.moya.model.Compo;
import fi.codecrew.moya.model.CompoEntry;
import fi.codecrew.moya.model.CompoEntryFile;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Vote;
/**
* Session Bean implementation class VotingBean
......@@ -49,7 +44,9 @@ import fi.codecrew.moya.model.Vote;
@LocalBean
@DeclareRoles({
CompoPermission.S_SUBMIT_ENTRY,
CompoPermission.S_MANAGE })
CompoPermission.S_MANAGE,
SpecialPermission.S_USER
})
public class VotingBean implements VotingBeanLocal {
@EJB
......@@ -64,7 +61,13 @@ public class VotingBean implements VotingBeanLocal {
private EventBean eventBean;
@EJB
private PermissionBeanLocal permissionBean;
@EJB
private CompoFileTypeFacade filetypeFacade;
private static final Logger logger = LoggerFactory.getLogger(VotingBean.class);
@EJB
private CompoEntryFileTypeFacade entryFiletypeFacade;
@EJB
private CompoFileTypeFacade compoFileTypeFadade;
/**
* Default constructor.
......@@ -84,7 +87,8 @@ public class VotingBean implements VotingBeanLocal {
}
public void addEntry(CompoEntry compoEntry, CompoEntryFile compoEntryFile) {
compoEntry.setCreated(Calendar.getInstance());
/*compoEntry.setCreated(Calendar.getInstance());
compoEntry.setCreator(permissionBean.getCurrentUser());
Compo c = compoFacade.merge(compoEntry.getCompo());
......@@ -93,6 +97,7 @@ public class VotingBean implements VotingBeanLocal {
compoFacade.flush();
compoEntryFile.setEntriesId(compoEntry);
// compoEntry.getFiles().add(compoEntryFile);
*/
}
public Compo getCompoById(Integer compoId) {
......@@ -104,22 +109,20 @@ public class VotingBean implements VotingBeanLocal {
}
@Override
@RolesAllowed({ CompoPermission.S_SUBMIT_ENTRY,
@RolesAllowed({CompoPermission.S_SUBMIT_ENTRY,
CompoPermission.S_MANAGE,
})
public Compo addEntry(CompoEntry entry) {
Compo co = compoFacade.reload(entry.getCompo());
entry.setCreator(permissionBean.getCurrentUser());
if (entry.getTitle() == null)
{
if (entry.getTitle() == null) {
entry.setTitle("");
}
if (co.getCompoEntries() == null) {
co.setCompoEntries(new ArrayList<CompoEntry>());
}
if (!co.getCompoEntries().contains(entry))
{
if (!co.getCompoEntries().contains(entry)) {
co.getCompoEntries().add(entry);
}
return co;
......@@ -135,7 +138,8 @@ public class VotingBean implements VotingBeanLocal {
@Override
public List<CompoEntryFile> getEntryFiles(CompoEntry entry) {
return compoEntryFileFacade.findFor(entry);
//return compoEntryFileFacade.findFor(entry);
return null;
}
@Override
......@@ -170,10 +174,8 @@ public class VotingBean implements VotingBeanLocal {
entry = compoEntryFacade.find(entry.getId());
EventUser user = permissionBean.getCurrentUser();
Vote voteEntity = voteFacade.find(entry, user);
if (vote != null)
{
if (voteEntity == null)
{
if (vote != null) {
if (voteEntity == null) {
voteEntity = new Vote();
if (user.getVotes() == null) {
user.setVotes(new ArrayList<Vote>());
......@@ -204,13 +206,59 @@ public class VotingBean implements VotingBeanLocal {
}
@Override
@RolesAllowed(SpecialPermission.S_USER)
public void create(CompoEntryFile cef) {
compoEntryFileFacade.create(cef);
CompoEntryFileType ft = entryFiletypeFacade.reload(cef.getFiletype());
ft.setUpdated(new Date());
ft.setCurrentFile(cef);
ft.getEntryFiles().add(cef);
}
@Override
@RolesAllowed(SpecialPermission.S_USER)
public List<CompoEntry> getEntriesForCurrentUser() {
EventUser user = permissionBean.getCurrentUser();
return compoEntryFacade.findUsersEntries(user);
}
@Override
@RolesAllowed(CompoPermission.S_MANAGE)
public Compo saveFiletype(CompoFileType filetype) {
if (filetype.getId() != null) {
return filetypeFacade.merge(filetype).getCompo();
}
Compo compo = compoFacade.reload(filetype.getCompo());
filetype.setCompo(compo);
compo.getFiletypes().add(filetype);
filetypeFacade.create(filetype);
return compo;
}
@Override
@RolesAllowed(CompoPermission.S_MANAGE)
public Compo deleteFiletype(CompoFileType ft) {
ft = filetypeFacade.reload(ft);
Compo compo = ft.getCompo();
compo.getFiletypes().remove(ft);
filetypeFacade.remove(ft);
return compo;
}
@Override
public CompoEntryFileType findEntryFileType(Integer entryId, Integer typeId) {
CompoEntryFileType ret = entryFiletypeFacade.findForEntryAndType(entryId, typeId);
if (ret == null) {
ret = new CompoEntryFileType();
ret.setEntry(compoEntryFacade.find(entryId));
ret.setType(compoFileTypeFadade.find(typeId));
ret.setUpdated(new Date());
ret.getEntry().getFiletypes().add(ret);
entryFiletypeFacade.create(ret);
}
return ret;
}
}
......@@ -48,7 +48,10 @@ public class BasicAuthPBean extends ApiAuth implements AuthenticationFormat {
AuthenticationResult ret = null;
//String username = UserLoginUtils.getUsernameFromJaasString(jaasUsername);
if (password.startsWith(HEADER_PREFIX)) {
if (!password.startsWith(HEADER_PREFIX)) {
return null;
}
ret = new AuthenticationResult();
ret.setUsertype(UserType.REST.name());
......@@ -58,11 +61,11 @@ public class BasicAuthPBean extends ApiAuth implements AuthenticationFormat {
String[] pwdsplit = password.split(" ");
if (pwdsplit.length != 2) {
logger.warn("Rest auth with Basic failed because pwdsplit != 2: user '{}''", username );
logger.warn("Rest auth with Basic failed because pwdsplit != 2: user '{}''", username);
return null;
}
// There is a possibility that user has a password that starts with "Basic ". To combat this,
// we chech that the authdata is really a base64 string. If not, we continue trying with other methods
// we check that the authdata is really a base64 string. If not, we continue trying with other methods
String authStr = null;
try {
authStr = new String(Base64.getDecoder().decode(pwdsplit[1]), UTF8);
......@@ -88,7 +91,7 @@ public class BasicAuthPBean extends ApiAuth implements AuthenticationFormat {
ret = null;
logger.warn("Invalid base64 string on Rest Basic auth: " + password, e);
}
}
return ret;
}
......
......@@ -61,7 +61,7 @@ public class ApiApplicationFacade extends IntegerPkGenericFacade<ApiApplication>
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<ApiApplication> q = cb.createQuery(ApiApplication.class);
Root<ApiApplication> root = q.from(ApiApplication.class);
q.where(cb.equal(root.get(ApiApplication_.developer), curruser));
q.where(cb.equal(root.get(ApiApplication_.developer), curruser.getUser()));
return getEm().createQuery(q).getResultList();
......
......@@ -26,6 +26,8 @@ import javax.persistence.criteria.Root;
import fi.codecrew.moya.model.*;
import java.util.List;
@Stateless
@LocalBean
public class ApiApplicationInstanceFacade extends IntegerPkGenericFacade<ApiApplicationInstance> {
......@@ -57,4 +59,16 @@ public class ApiApplicationInstanceFacade extends IntegerPkGenericFacade<ApiAppl
return super.getSingleNullableResult(getEm().createQuery(q));
}
public List<ApiApplicationInstance> findForUser(EventUser currentUser, ApiApplication apiApp) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<ApiApplicationInstance> q = cb.createQuery(ApiApplicationInstance.class);
Root<ApiApplicationInstance> root = q.from(ApiApplicationInstance.class);
q.where(
cb.equal(root.get(ApiApplicationInstance_.application), apiApp),
cb.equal(root.get(ApiApplicationInstance_.eventuser), currentUser)
);
return getEm().createQuery(q).getResultList();
}
}
......@@ -38,7 +38,7 @@ public class CompoEntryFileFacade extends IntegerPkGenericFacade<CompoEntryFile>
super(CompoEntryFile.class);
}
/*
public List<CompoEntryFile> findFor(CompoEntry entry) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<CompoEntryFile> cq = cb.createQuery(CompoEntryFile.class);
......@@ -47,5 +47,6 @@ public class CompoEntryFileFacade extends IntegerPkGenericFacade<CompoEntryFile>
cq.where(cb.equal(root.get(CompoEntryFile_.entry), entry));
return getEm().createQuery(cq).getResultList();
}
*/
}
package fi.codecrew.moya.facade;
import fi.codecrew.moya.model.*;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
@Stateless
@LocalBean
public class CompoEntryFileTypeFacade extends IntegerPkGenericFacade<CompoEntryFileType> {
public CompoEntryFileTypeFacade() {
super(CompoEntryFileType.class);
}
public CompoEntryFileType findForEntryAndType(Integer entryId, Integer typeId) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<CompoEntryFileType> cq = cb.createQuery(CompoEntryFileType.class);
Root<CompoEntryFileType> root = cq.from(CompoEntryFileType.class);
cq.where(
cb.equal(root.get(CompoEntryFileType_.entry).get(CompoEntry_.id), entryId),
cb.equal(root.get(CompoEntryFileType_.type).get(CompoFileType_.id), typeId)
);
return getSingleNullableResult(getEm().createQuery(cq));
}
}
......@@ -32,6 +32,7 @@ import javax.persistence.criteria.Root;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.Compo;
import fi.codecrew.moya.model.Compo_;
import fi.codecrew.moya.model.LanEvent;
@Stateless
@LocalBean
......@@ -58,4 +59,13 @@ public class CompoFacade extends IntegerPkGenericFacade<Compo> {
List<Compo> ret = getEm().createQuery(cq).getResultList();
return ret;
}
@Override
public Compo find(Integer id) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Compo> cq = cb.createQuery(Compo.class);
Root<Compo> root = cq.from(Compo.class);
cq.where(cb.equal(root.get(Compo_.id), id), cb.equal(root.get(Compo_.event), eventbean.getCurrentEvent()));
return super.getSingleNullableResult(getEm().createQuery(cq));
}
}
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.facade;
import fi.codecrew.moya.model.*;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
@Stateless
@LocalBean
public class CompoFileTypeFacade extends IntegerPkGenericFacade<CompoFileType> {
public CompoFileTypeFacade() {
super(CompoFileType.class);
}
}
......@@ -142,12 +142,12 @@ public class ApiApplication extends GenericEntity {
this.readerType = readerType;
}
public List<ApiApplicationInstance> getInstances() {
return instances;
private List<ApiApplicationInstance> getInstances() {
throw new RuntimeException("DO NOT USE. Only for metamodel generation");
}
public void setInstances(List<ApiApplicationInstance> instances) {
this.instances = instances;
throw new RuntimeException("DO NOT USE. Only for metamodel generation");
}
}
......@@ -109,14 +109,6 @@ public class Compo extends GenericEntity {
@Column(name = "hidden", nullable = false)
private boolean hidden = false;
public boolean isHidden() {
return hidden;
}
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
/**
* Entries submitted to participate this compo.
*/
......@@ -124,6 +116,19 @@ public class Compo extends GenericEntity {
@OrderBy("sort")
private List<CompoEntry> compoEntries;
@OneToMany(mappedBy = "compo")
@OrderBy("sort")
private List<CompoFileType> filetypes;
@ManyToOne()
@JoinColumn(name = "entrysubmit_role_id",referencedColumnName = "id")
private Role entrysubmitRole;
@ManyToOne()
@JoinColumn(name = "voting_scheme_id", referencedColumnName = "id")
private CompoVotingScheme votingScheme;
public Compo(String compoName, boolean holdVoting) {
this();
......@@ -131,14 +136,20 @@ public class Compo extends GenericEntity {
this.holdVoting = holdVoting;
}
public boolean isSubmit()
{
public boolean isHidden() {
return hidden;
}
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
public boolean isSubmit() {
Date now = new Date();
return now.after(getSubmitStart()) && now.before(getSubmitEnd());
}
public boolean isVote()
{
public boolean isVote() {
Date now = new Date();
return !getHoldVoting() &&
now.after(getVoteStart()) &&
......@@ -229,8 +240,7 @@ public class Compo extends GenericEntity {
}
/**
* @param maxParticipantCount
* the maxParticipantCount to set
* @param maxParticipantCount the maxParticipantCount to set
*/
public void setMaxParticipantCount(int maxParticipantCount) {
this.maxParticipantCount = maxParticipantCount;
......@@ -252,4 +262,31 @@ public class Compo extends GenericEntity {
this.endTime = endTime;
}
public boolean isHoldVoting() {
return holdVoting;
}
public List<CompoFileType> getFiletypes() {
return filetypes;
}
public void setFiletypes(List<CompoFileType> filetypes) {
this.filetypes = filetypes;
}
public Role getEntrysubmitRole() {
return entrysubmitRole;
}
public void setEntrysubmitRole(Role entrysubmitRole) {
this.entrysubmitRole = entrysubmitRole;
}
public CompoVotingScheme getVotingScheme() {
return votingScheme;
}
public void setVotingScheme(CompoVotingScheme votingScheme) {
this.votingScheme = votingScheme;
}
}
......@@ -23,6 +23,7 @@
package fi.codecrew.moya.model;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
......@@ -74,9 +75,8 @@ public class CompoEntry extends GenericEntity {
@Column(name = "final_position")
private Integer finalPosition;
@JoinColumn(name = "current_file_id", referencedColumnName = CompoEntryFile.ID_COLUMN)
@OneToOne
private CompoEntryFile currentFile;
@OneToMany(mappedBy = "entry")
private List<CompoEntryFileType> filetypes = new ArrayList<>();
@OneToMany(mappedBy = "compoEntry")
private List<Vote> votes;
......@@ -93,8 +93,7 @@ public class CompoEntry extends GenericEntity {
@ManyToOne
private EventUser creator;
public Integer getVotetotal()
{
public Integer getVotetotal() {
int votetotal = 0;
for (Vote v : getVotes()) {
votetotal += v.getScore();
......@@ -195,4 +194,11 @@ public class CompoEntry extends GenericEntity {
this.author = author;
}
public List<CompoEntryFileType> getFiletypes() {
return filetypes;
}
public void setFiletypes(List<CompoEntryFileType> filetypes) {
this.filetypes = filetypes;
}
}
......@@ -26,6 +26,7 @@ package fi.codecrew.moya.model;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
......@@ -49,6 +50,9 @@ import org.slf4j.LoggerFactory;
@Table(name = "compo_entry_files")
public class CompoEntryFile extends GenericEntity {
private static final long serialVersionUID = 1L;
private static final Logger logger = LoggerFactory.getLogger(CompoEntryFile.class);
@Column(name = "mime_type")
private String mimeType;
......@@ -62,28 +66,21 @@ public class CompoEntryFile extends GenericEntity {
@Column(name = "hash", updatable = false)
private String hash;
@Lob
@Column(name = "file_data", updatable = false)
@Basic(fetch = FetchType.LAZY)
private byte[] fileData;
@Column(name="filepath", updatable = false, nullable = false)
private String filepath;
@Column(name = "uploaded", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Calendar uploaded = Calendar.getInstance();
private Date uploaded = new Date();
@ManyToOne(optional=false)
@JoinColumn(name="entryfiletype_id", referencedColumnName = "id", nullable = false, updatable = false)
private CompoEntryFileType filetype;
@JoinColumn(name = "entry_id", referencedColumnName = "id", nullable = false, updatable = false)
@ManyToOne(optional = false)
private CompoEntry entry;
private static final Logger logger = LoggerFactory.getLogger(CompoEntryFile.class);
public CompoEntryFile() {
super();
}
public CompoEntryFile(CompoEntry entry) {
this.entry = entry;
}
public String getMimeType() {
return mimeType;
}
......@@ -116,42 +113,28 @@ public class CompoEntryFile extends GenericEntity {
this.hash = hash;
}
public byte[] getFileData() {
return fileData;
}
public void setFileData(byte[] fileData) {
this.fileData = fileData;
this.hash = getShaChecksum(fileData);
}
public Calendar getUploaded() {
public Date getUploaded() {
return uploaded;
}
public void setUploaded(Calendar uploaded) {
public void setUploaded(Date uploaded) {
this.uploaded = uploaded;
}
public CompoEntry getEntriesId() {
return entry;
}
public void setEntriesId(CompoEntry entriesId) {
this.entry = entriesId;
public CompoEntryFileType getFiletype() {
return filetype;
}
public static String getShaChecksum(byte[] data)
{
String ret = "ERROR CALCULATING CHECKSUM!";
try {
MessageDigest algo = MessageDigest.getInstance("SHA");
algo.update(data);
ret = new String(Hex.encodeHex(algo.digest())).toLowerCase();
} catch (NoSuchAlgorithmException e) {
logger.warn("Error calculating checksum", e);
public void setFiletype(CompoEntryFileType filetype) {
this.filetype = filetype;
}
return ret;
public String getFilepath() {
return filepath;
}
public void setFilepath(String filepath) {
this.filepath = filepath;
}
}
package fi.codecrew.moya.model;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
import static fi.codecrew.moya.model.CompoEntryFileType.ENTRY_ID_COLUMN;
import static fi.codecrew.moya.model.CompoEntryFileType.TYPE_ID_COLUMN;
@Entity
@Table(name = "compo_entry_file_types", uniqueConstraints = @UniqueConstraint(columnNames = {ENTRY_ID_COLUMN, TYPE_ID_COLUMN}))
public class CompoEntryFileType extends GenericEntity {
public static final String ENTRY_ID_COLUMN = "entry_id";
public static final String TYPE_ID_COLUMN = "type_id";
@ManyToOne(optional = false)
@JoinColumn(name = ENTRY_ID_COLUMN, nullable = false, updatable = false)
private CompoEntry entry;
@ManyToOne(optional = false)
@JoinColumn(name = TYPE_ID_COLUMN, nullable = false, updatable = false)
private CompoFileType type;
@ManyToOne(optional = false)
@JoinColumn(name = "current_file_id")
private CompoEntryFile currentFile;
@OneToMany(mappedBy = "filetype")
// This is here only for metamodel generation.
private List<CompoEntryFile> entryFiles;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="updated", nullable = false)
private Date updated = new Date();
public CompoEntry getEntry() {
return entry;
}
public void setEntry(CompoEntry entry) {
this.entry = entry;
}
public CompoFileType getType() {
return type;
}
public void setType(CompoFileType type) {
this.type = type;
}
public CompoEntryFile getCurrentFile() {
return currentFile;
}
public void setCurrentFile(CompoEntryFile currentFile) {
this.currentFile = currentFile;
}
public Date getUpdated() {
return updated;
}
public void setUpdated(Date updated) {
this.updated = updated;
}
public List<CompoEntryFile> getEntryFiles() {
return entryFiles;
}
public void setEntryFiles(List<CompoEntryFile> entryFiles) {
this.entryFiles = entryFiles;
}
}
package fi.codecrew.moya.model;
import javax.persistence.*;
import java.util.List;
@Table(name = "compo_file_types")
@Entity
public class CompoFileType extends GenericEntity {
public enum FileType {
DATA, THUMBNAIL, MUSIC_PREVIEW
}
@ManyToOne(optional = false)
@JoinColumn(name = "compo_id", nullable = false, updatable = false)
private Compo compo;
/*
@OneToMany(mappedBy = "filetype")
// Only here for metamodel.. Do not create getter and setter!
private List<CompoEntryFile> entryfiles;
*/
@Lob
@Column(name = "name")
private String name;
@Lob
@Column(name = "description")
private String description;
@Column(nullable = false)
private int sort = 100;
@Column(name = "required")
private boolean required = false;
@Enumerated(EnumType.STRING)
@Column(name = "filetype")
private FileType filetype = FileType.DATA;
public Compo getCompo() {
return compo;
}
public void setCompo(Compo compo) {
this.compo = compo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isRequired() {
return required;
}
public void setRequired(boolean required) {
this.required = required;
}
public int getSort() {
return sort;
}
public void setSort(int sort) {
this.sort = sort;
}
public FileType getFiletype() {
return filetype;
}
public void setFiletype(FileType filetype) {
this.filetype = filetype;
}
}
package fi.codecrew.moya.model;
import javax.persistence.*;
import java.math.BigDecimal;
import static fi.codecrew.moya.model.CompoVotingRole.SCHEME_ID_COLUMN;
import static fi.codecrew.moya.model.CompoVotingRole.ROLE_ID_COLUMN;
@Table(name = "compo_voting_roles", uniqueConstraints = @UniqueConstraint(columnNames = {SCHEME_ID_COLUMN, ROLE_ID_COLUMN}))
@Entity
public class CompoVotingRole extends GenericEntity {
static final String SCHEME_ID_COLUMN = "scheme_id";
static final String ROLE_ID_COLUMN = "role_id";
@ManyToOne()
@JoinColumn(nullable = false, updatable = false, name = SCHEME_ID_COLUMN)
private CompoVotingScheme scheme;
@Column(nullable = false)
private int priority = 100;
@ManyToOne
@JoinColumn(nullable = false, updatable = false, name = ROLE_ID_COLUMN)
private Role role;
@Column(nullable = false, precision = 24, scale = 8, name = "multiplier")
private BigDecimal multiplier = BigDecimal.ONE;
@Column(name = "override_min", scale = 24, precision = 8)
private BigDecimal overrideMin;
@Column(name = "override_max", scale = 24, precision = 8)
private BigDecimal overrideMax;
@Column(nullable = false, name = "override_others")
private boolean overrideOthers = false;
public CompoVotingScheme getScheme() {
return scheme;
}
public void setScheme(CompoVotingScheme scheme) {
this.scheme = scheme;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
public BigDecimal getMultiplier() {
return multiplier;
}
public void setMultiplier(BigDecimal multiplier) {
this.multiplier = multiplier;
}
public BigDecimal getOverrideMin() {
return overrideMin;
}
public void setOverrideMin(BigDecimal overrideMin) {
this.overrideMin = overrideMin;
}
public BigDecimal getOverrideMax() {
return overrideMax;
}
public void setOverrideMax(BigDecimal overrideMax) {
this.overrideMax = overrideMax;
}
public boolean isOverrideOthers() {
return overrideOthers;
}
public void setOverrideOthers(boolean overrideOthers) {
this.overrideOthers = overrideOthers;
}
}
package fi.codecrew.moya.model;
import javax.persistence.*;
import java.math.BigDecimal;
import java.util.List;
@Table(name = "compo_voting_schemes")
@Entity
public class CompoVotingScheme extends GenericEntity {
public enum SchemeType {
INT_TO_ALL_ENTRIES,
SORT_BEST_N,
}
@ManyToOne(optional = false)
@JoinColumn(nullable = false, updatable = false, name = "event_id")
private LanEvent event;
@Enumerated(EnumType.STRING)
@Column(nullable = false, name = "type")
private SchemeType type = SchemeType.INT_TO_ALL_ENTRIES;
@Column(nullable = false, name = "name")
private String name;
@OneToMany(mappedBy = "scheme")
@OrderBy("priority")
private List<CompoVotingRole> votingRoles;
@Column(name = "min_value", scale = 24, precision = 8)
private BigDecimal minValue = BigDecimal.ONE;
@Column(name = "max_value", scale = 24, precision = 8)
private BigDecimal maxValue = BigDecimal.TEN;
@Column(name = "value_increment", scale = 24, precision = 8)
private BigDecimal valueIncrement = BigDecimal.ONE;
@Column(name = "allow_recusal", nullable = false)
private boolean allowRecusal = false;
public LanEvent getEvent() {
return event;
}
public void setEvent(LanEvent event) {
this.event = event;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<CompoVotingRole> getVotingRoles() {
return votingRoles;
}
public void setVotingRoles(List<CompoVotingRole> votingRoles) {
this.votingRoles = votingRoles;
}
public BigDecimal getMinValue() {
return minValue;
}
public void setMinValue(BigDecimal minValue) {
this.minValue = minValue;
}
public BigDecimal getMaxValue() {
return maxValue;
}
public void setMaxValue(BigDecimal maxValue) {
this.maxValue = maxValue;
}
public BigDecimal getValueIncrement() {
return valueIncrement;
}
public void setValueIncrement(BigDecimal valueIncrement) {
this.valueIncrement = valueIncrement;
}
public boolean isAllowRecusal() {
return allowRecusal;
}
public void setAllowRecusal(boolean allowRecusal) {
this.allowRecusal = allowRecusal;
}
public SchemeType getType() {
return type;
}
public void setType(SchemeType type) {
this.type = type;
}
}
......@@ -39,10 +39,10 @@ public class GenericEntity extends EntityEquals implements ModelInterface, Entit
private static final long serialVersionUID = -9041737052951021560L;
@Id
@Column(name = ID_COLUMN, nullable = false, updatable = false)
@Column(name = ID_COLUMN, nullable = false, updatable = false, columnDefinition = "SERIAL NOT NULL")
private Integer id;
@Column(name = "meta", columnDefinition = "json")
@Column(name = "meta", columnDefinition = "jsonb")
private JsonObject meta;
@Override
......
......@@ -14,7 +14,9 @@
<property name="eclipselink.target-server" value="Glassfish" />
<property name="eclipselink.session.customizer"
value="fi.codecrew.moya.database.eclipselink.MoyaSessionCustomizer" />
<property name="eclipselink.ddl-generation" value="none"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<!--property name="eclipselink.ddl-generation" value="create-tables"/-->
<property name="eclipselink.ddl-generation.output-mode" value="sql-script"/>
</properties>
......
......@@ -15,6 +15,7 @@ public enum SystemProperty {
MOYA_IRC_SERVER,
MOYA_IRC_CHANNEL("#moya-debug"),
MOYA_IRC_SERVERPASS(),
MOYA_COMPOFILE_DIR("/tmp/moya"),
;
......
......@@ -12,7 +12,7 @@
<f:metadata>
<f:event type="preRenderView"
listener="#{applicationApiView.initApplicationListView}" />
listener="#{applicationApiView.initSuperApplicationListView}" />
</f:metadata>
<ui:define name="content">
<button></button>
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:viewParam name="id" value="#{apiAppEditView.id}"/>
<f:event type="preRenderView"
listener="#{apiAppEditView.initEdit}"/>
</f:metadata>
<ui:define name="content">
<h1>#{i18n['apiapp.edit.applist']}</h1>
<h:form id="appedit">
<p:panelGrid columns="3">
<h:outputText for="appkey" value="#{i18n['apiapp.appkey']}"/>
<p:inplace>
<f:facet name="output">
******** (Click to view and edit)
</f:facet>
<f:facet name="input">
<p:inputText size="30" id="appkey" redisplay="true" value="#{apiAppEditView.apiApp.applicationKey}"/>
</f:facet>
</p:inplace>
<h:message for="appkey"/>
<h:outputText for="appname" value="#{i18n['apiapp.name']}"/>
<p:inputText size="30" id="appname" value="#{apiAppEditView.apiApp.name}"/>
<h:message for="appname"/>
<h:outputText for="appdesc" value="#{i18n['apiapp.description']}"/>
<p:inputText size="30" id="appdesc" value="#{apiAppEditView.apiApp.description}"/>
<h:message for="appdesc"/>
</p:panelGrid>
<p:commandButton ajax="false" action="#{apiAppEditView.save}" value="#{i18n['apiapp.save']}"/>
</h:form>
<h2><h:outputText value="#{i18n['apiInstance.my.header']}"/></h2>
<p:commandButton value="#{i18n['apiInstance.create']}" action="#{apiAppEditView.initCreateInstance}" type="button" onclick="PF('createInstanceDlg').show();"/>
<p:dialog header="Create api instance" widgetVar="createInstanceDlg" closable="true" dynamic="true">
<h:form>
<p:panelGrid columns="3">
<h:outputText for="appinstevent" value="#{i18n['apiapp.event']}"/>
<h:outputText size="30" id="appinstevent" value="#{apiAppEditView.selectedInstance.eventuser.event.name}"/>
<h:message for="appinstevent"/>
<h:outputText for="appinstuser" value="#{i18n['apiapp.event']}"/>
<h:outputText size="30" id="appinstuser" value="(#{apiAppEditView.selectedInstance.eventuser.user.id}) #{apiAppEditView.selectedInstance.eventuser.user.wholeName}"/>
<h:message for="appinstuser"/>
<h:outputText for="appinstcreated" value="#{i18n['apiapp.created']}"/>
<h:outputText size="30" id="appinstcreated" value="#{apiAppEditView.selectedInstance.created}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}"/>
</h:outputText>
<h:message for="appinstcreated"/>
<h:outputText for="appinstenabled" value="#{i18n['apiapp.enabled']}"/>
<p:selectBooleanCheckbox id="appinstenabled" value="#{apiAppEditView.selectedInstance.enabled}"/>
<h:message for="appinstenabled"/>
<h:outputText for="appinstname" value="#{i18n['apiapp.name']}"/>
<p:inputText size="30" id="appinstname" value="#{apiAppEditView.selectedInstance.name}"/>
<h:message for="appinstname"/>
<h:outputText for="appinstnotes" value="#{i18n['apiapp.notes']}"/>
<p:inputText size="30" id="appinstnotes" value="#{apiAppEditView.selectedInstance.notes}"/>
<h:message for="appinstnotes"/>
<h:outputText for="appinstkey" value="#{i18n['apiapp.secretKey']}"/>
<p:inputText size="40" id="appinstkey" value="#{apiAppEditView.selectedInstance.secretKey}"/>
<h:message for="appinstkey"/>
</p:panelGrid>
<p:commandButton value="#{i18n['apiapp.save']}" action="#{apiAppEditView.saveInstance}"/>
</h:form>
</p:dialog>
<p:dataTable value="#{apiAppEditView.apiInstances}" var="instance">
<p:column width="80" headerText="#{i18n['apiInstance.enabled']}"> <h:outputText value="#{instance.enabled}"/> </p:column>
<p:column headerText="#{i18n['apiInstance.created']}"> <h:outputText value="#{instance.created}"/> </p:column>
<p:column headerText="#{i18n['apiIntance.name']}"> <h:outputText value="#{instance.name}"/> </p:column>
<p:column headerText="#{i18n['apiInstance.userWholename']}"> <h:outputText value="#{instance.eventuser.wholeName}"/> </p:column>
<p:column headerText="#{i18n['apiInstance.event']}"><h:outputText value="#{instance.eventuser.event.name}"/></p:column>
<p:column><p:commandButton value="#{i18n['apiInstance.edit']}" action="#{apiAppEditView.selectInstance}" oncomplete="PF('createInstanceDlg').show();"/></p:column>
</p:dataTable>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -12,14 +12,16 @@
<f:metadata>
<f:event type="preRenderView"
listener="#{applicationApiView.initApplicationListView}" />
listener="#{applicationApiView.initApplicationListView}"/>
</f:metadata>
<ui:define name="content">
<button></button>
<div style="display:none;" id="createApp">
</div>
<h:form>
<h:panelGrid columns="2">
<p:outputLabel for="newappName" value="#{i18n['apiapp.name']}" />
<p:inputText id="newappName" value="#{applicationApiView.newApplication.name}" required="true"/>
</h:panelGrid>
<p:commandButton ajax="false" action="#{applicationApiView.createApp()}" value="#{i18n['apiapp.create']}"/>
</h:form>
<h1>#{i18n['apiapp.edit.applist']}</h1>
......@@ -28,19 +30,19 @@
<p:dataTable value="#{applicationApiView.applist}" var="app">
<p:column headerText="#{i18n['apiapp.name']}">
<h:outputText value="#{app.name}" />
<h:link outcome="/api/edit?id=#{app.id}"><h:outputText value="#{app.name}"/></h:link>
</p:column>
<p:column headerText="#{i18n['apiapp.description']">
<h:outputText value="#{app.description}" />
<p:column headerText="#{i18n['apiapp.description']}">
<h:outputText value="#{app.description}"/>
</p:column>
<p:column>
<p:column headerText="#{i18n['apiapp.created']}">
<h:outputText value="#{app.created}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}"
timeZone="#{sessionHandler.timezone}" />
timeZone="#{sessionHandler.timezone}"/>
</h:outputText>
</p:column>
<p:column headerText="#{i18n['apiapp.enabled']}">
<h:outputText value="#{app.enabled}" />
<h:outputText value="#{app.enabled}"/>
</p:column>
</p:dataTable>
......
......@@ -14,51 +14,59 @@
<h:form>
<h:panelGrid columns="3">
<h:outputLabel value="#{i18n['voting.create.name']}:" for="name" />
<h:inputText value="#{compoMgmtView.compo.name}" id="name" />
<h:message for="name" />
<p:outputLabel value="#{i18n['voting.create.name']}:" for="name" />
<p:inputText value="#{compoMgmtView.compo.name}" id="name" />
<p:message for="name" />
<h:outputLabel value="#{i18n['voting.create.description']}:" for="desc" />
<h:inputText value="#{compoMgmtView.compo.description}" id="desc" />
<h:message for="desc" />
<p:outputLabel value="#{i18n['voting.create.description']}:" for="desc" />
<p:inputText value="#{compoMgmtView.compo.description}" id="desc" />
<p:message for="desc" />
<h:outputLabel value="#{i18n['voting.create.maxParticipants']}:" for="maxPar" />
<h:inputText value="#{compoMgmtView.compo.maxParticipantCount}" id="maxPar" />
<h:message for="maxPar" />
<p:outputLabel for="entrysubmitrole" value="#{i18n['voting.create.entrysubmitrole']}:" />
<p:selectOneMenu id="entrysubmitrole" value="#{compoMgmtView.compo.entrysubmitRole}" converter="#{roleConverter}">
<f:selectItem itemLabel="----" />
<f:selectItems value="#{roleDataView.roleList}" var="r" itemLabel="#{r.name}" />
</p:selectOneMenu>
<p:message for="entrysubmitrole" />
<h:outputLabel value="#{i18n['voting.create.holdVoting']}:" for="holdVoting" />
<h:selectBooleanCheckbox value="#{compoMgmtView.compo.holdVoting}" id="holdVoting" />
<h:message for="holdVoting" />
<h:outputLabel value="#{i18n['voting.create.hidden']}:" for="hidden" />
<h:selectBooleanCheckbox value="#{compoMgmtView.compo.hidden}" id="hidden" />
<h:message for="hidden" />
<p:outputLabel value="#{i18n['voting.create.maxParticipants']}:" for="maxPar" />
<p:inputText value="#{compoMgmtView.compo.maxParticipantCount}" id="maxPar" />
<p:message for="maxPar" />
<h:outputLabel value="#{i18n['voting.create.compoStart']}:" for="cStart" />
<p:outputLabel value="#{i18n['voting.create.holdVoting']}:" for="holdVoting" />
<p:selectBooleanCheckbox value="#{compoMgmtView.compo.holdVoting}" id="holdVoting" />
<p:message for="holdVoting" />
<p:outputLabel value="#{i18n['voting.create.hidden']}:" for="hidden" />
<p:selectBooleanCheckbox value="#{compoMgmtView.compo.hidden}" id="hidden" />
<p:message for="hidden" />
<p:outputLabel value="#{i18n['voting.create.compoStart']}:" for="cStart" />
<p:calendar validator="#{votingDateValidator.saveCStart}" value="#{compoMgmtView.compo.startTime}" pattern="dd/MM/yyyy HH:mm" id="cStart" />
<h:message for="cStart" />
<p:message for="cStart" />
<h:outputLabel value="#{i18n['voting.create.compoEnd']}:" for="cEnd" />
<p:outputLabel value="#{i18n['voting.create.compoEnd']}:" for="cEnd" />
<p:calendar validator="#{votingDateValidator.validateCompo}" value="#{compoMgmtView.compo.endTime}" pattern="dd/MM/yyyy HH:mm" id="cEnd" />
<h:message for="cEnd" />
<p:message for="cEnd" />
<h:outputLabel value="#{i18n['voting.create.voteStart']}:" for="vStart" />
<p:outputLabel value="#{i18n['voting.create.voteStart']}:" for="vStart" />
<p:calendar validator="#{votingDateValidator.saveVStart}" value="#{compoMgmtView.compo.voteStart}" pattern="dd/MM/yyyy HH:mm" id="vStart" />
<h:message for="vStart" />
<p:message for="vStart" />
<h:outputLabel value="#{i18n['voting.create.voteEnd']}:" for="vEnd" />
<p:outputLabel value="#{i18n['voting.create.voteEnd']}:" for="vEnd" />
<p:calendar validator="#{votingDateValidator.validateVote}" value="#{compoMgmtView.compo.voteEnd}" pattern="dd/MM/yyyy HH:mm" id="vEnd" />
<h:message for="vEnd" />
<p:message for="vEnd" />
<h:outputLabel value="#{i18n['voting.create.submitStart']}:" for="sStart" />
<p:outputLabel value="#{i18n['voting.create.submitStart']}:" for="sStart" />
<p:calendar validator="#{votingDateValidator.saveSStart}" value="#{compoMgmtView.compo.submitStart}" pattern="dd/MM/yyyy HH:mm" id="sStart" />
<h:message for="sStart" />
<p:message for="sStart" />
<h:outputLabel value="#{i18n['voting.create.submitEnd']}:" for="sEnd" />
<p:outputLabel value="#{i18n['voting.create.submitEnd']}:" for="sEnd" />
<p:calendar validator="#{votingDateValidator.validateSubmit}" value="#{compoMgmtView.compo.submitEnd}" pattern="dd/MM/yyyy HH:mm" id="sEnd" />
<h:message for="sEnd" />
<p:message for="sEnd" />
<h:commandButton action="#{cc.attrs.commitAction}" id="commitbutton" value="#{cc.attrs.commitValue}" />
<p:commandButton ajax="false" action="#{cc.attrs.commitAction}" id="commitbutton" value="#{cc.attrs.commitValue}" />
</h:panelGrid>
</h:form>
......
......@@ -36,8 +36,9 @@
</div>
<p:commandButton ajax="false" action="#{userView.saveRoles}" value="#{i18n['user.saveRoles']}"/>
</h:form>
<ui:fragment rendered="#{roleView.canReadRoles}">
<div style="margin-left: 4em;">
<h2>All users roles</h2>
<h2><h:outputText value="#{i18n['user.allroles']}"/></h2>
<p:dataTable style="max-width: 600px;" var="r" value="#{userView.allUsersRoles}">
<p:column style="width: 30%;"><f:facet name="header"><h:outputText value="#{i18n['role.name']}"/></f:facet><h:outputText value="#{r.key.name}"/></p:column>
<p:column>
......@@ -50,6 +51,7 @@
</p:column>
</p:dataTable>
</div>
</ui:fragment>
</div>
</ui:define>
</ui:composition>
......
......@@ -7,7 +7,7 @@
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{compoView.initAdminListView()}" />
<f:event type="preRenderView" listener="#{compoView.initAdminListView()}"/>
</f:metadata>
<ui:define name="content">
<h:form id="admincompolist" styleClass="moya_datatable2">
......@@ -17,7 +17,7 @@
<p:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{compoView.compos}" var="compo">
<p:column headerText="#{i18n['voting.allcompos.name']}">
<h:outputText value="#{compo.name}" />
<h:outputText value="#{compo.compo.name}"/>
</p:column>
<!-- <h:column rendered="#{compoView.curEntries}"> -->
......@@ -30,41 +30,40 @@
<!-- <f:facet name="header"> -->
<!-- <h:outputText value="#{i18n['voting.allcompos.maxParts']}" /> -->
<!-- </f:facet> -->
<!-- <h:outputText value="#{compo.maxParticipantCount}" /> -->
<!-- <h:outputText value="#{compo.compo.maxParticipantCount}" /> -->
<!-- </h:column> -->
<p:column headerText="#{i18n['voting.allcompos.startTime']}">
<h:outputText value="#{compo.startTime.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
<h:outputText value="#{compo.compo.startTime.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}"/>
</h:outputText>
</p:column>
<p:column headerText="#{i18n['voting.allcompos.voteEnd']}">
<h:outputText value="#{compo.voteEnd.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
<h:outputText value="#{compo.compo.voteEnd.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}"/>
</h:outputText>
</p:column>
<p:column headerText="#{i18n['voting.allcompos.submitEnd']}">
<h:outputText value="#{compo.submitEnd.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
<h:outputText value="#{compo.compo.submitEnd.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}"/>
</h:outputText>
</p:column>
<p:column headerText="#{i18n['voting.allcompos.holdVoting']}">
<h:outputText value="#{compo.holdVoting}" />
<h:outputText value="#{compo.compo.holdVoting}"/>
</p:column>
<p:column headerText="#{i18n['voting.allcompos.hidden']}">
<h:outputText value="#{compo.hidden}" />
<h:outputText value="#{compo.compo.hidden}"/>
</p:column>
<p:column>
<h:commandButton rendered="#{compo.vote or compoView.manage}" action="#{compoView.startVote()}" value="#{i18n['voting.compo.vote']}" />
</p:column>
<p:column>
<h:commandButton rendered="#{compo.submit or compoView.manage}" action="#{compoView.submitEntry()}" value="#{i18n['voting.compo.submit']}" />
<p:commandButton ajax="false" action="#{compoView.startVote()}" value="#{i18n['voting.compo.vote']}"/><br/>
<p:link rendered="#{compo.canSubmit}" outcome="/voting/submitEntry" value="#{i18n['voting.compo.submit']}">
<f:param name="compoId" value="#{compo.compo.id}"/>
</p:link>
</p:column>
<p:column rendered="#{compoView.manage}">
<h:link outcome="details" value="#{i18n['compo.edit']}">
<f:param name="compoId" value="#{compo.id}" />
<f:param name="compoId" value="#{compo.compo.id}"/>
</h:link>
</p:column>
</p:dataTable>
......
......@@ -10,70 +10,69 @@
<f:event type="preRenderView" listener="#{compoView.initListView()}" />
</f:metadata>
<ui:define name="content">
<h:outputStylesheet library="style" name="insomnia2/css/actionlog.css" />
<h1>#{i18n['voting.allcompos.header']}</h1>
<p>#{i18n['voting.allcompos.description']}</p>
<h1>#{i18n['voting.allcompos.header']}</h1>
<h:form id="compolist" styleClass="moya_datatable2">
<h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{compoView.compos}" var="compo">
<h:column>
<p:dataTable styleClass="bordertable" tableStyle="width: auto;" rowClasses="roweven,rowodd" id="compolisttable" value="#{compoView.compos}" var="compo">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['voting.allcompos.name']}" />
</f:facet>
<h:outputText value="#{compo.name}" />
</h:column>
<h:outputText value="#{compo.compo.name}" />
</p:column>
<!-- <h:column rendered="#{compoView.curEntries}"> -->
<!-- <p:column rendered="#{compoView.curEntries}"> -->
<!-- <f:facet name="header"> -->
<!-- <h:outputText value="#{i18n['voting.allcompos.curEntries']}" /> -->
<!-- </f:facet> -->
<!-- <h:outputText value="#{compoEntries.size()}" /> -->
<!-- </h:column> -->
<!-- <h:column rendered="#{compoView.maxParts}"> -->
<!-- </p:column> -->
<!-- <p:column rendered="#{compoView.maxParts}"> -->
<!-- <f:facet name="header"> -->
<!-- <h:outputText value="#{i18n['voting.allcompos.maxParts']}" /> -->
<!-- </f:facet> -->
<!-- <h:outputText value="#{compo.maxParticipantCount}" /> -->
<!-- </h:column> -->
<h:column>
<!-- </p:column> -->
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['voting.allcompos.startTime']}" />
</f:facet>
<h:outputText value="#{compo.startTime.time}">
<h:outputText value="#{compo.compo.startTime.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</h:column>
</p:column>
<h:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['voting.allcompos.voteEnd']}" />
</f:facet>
<h:outputText value="#{compo.voteEnd.time}">
<h:outputText value="#{compo.compo.voteEnd.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</h:column>
</p:column>
<h:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['voting.allcompos.submitEnd']}" />
</f:facet>
<h:outputText value="#{compo.submitEnd.time}">
<h:outputText value="#{compo.compo.submitEnd.time}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText>
</h:column>
<h:column>
<h:commandButton rendered="#{compo.vote or compoView.manage}" action="#{compoView.startVote()}" value="#{i18n['voting.compo.vote']}" />
</h:column>
<h:column>
<h:commandButton rendered="#{compo.submit or compoView.manage}" action="#{compoView.submitEntry()}" value="#{i18n['voting.compo.submit']}" />
</p:column>
<p:column>
<p:commandButton rendered="#{compo.canVote}" action="#{compoView.startVote()}" value="#{i18n['voting.compo.vote']}" />
<p:link rendered="#{compo.canSubmit}" outcome="/voting/submitEntry" value="#{i18n['voting.compo.submit']}" >
<f:param name="compoId" value="#{compo.compo.id}" />
</p:link>
</h:column>
<h:column rendered="#{compoView.manage}">
</p:column>
<p:column rendered="#{compoView.manage}">
<h:link outcome="details" value="#{i18n['compo.edit']}">
<f:param name="compoId" value="#{compo.id}" />
<f:param name="compoId" value="#{compo.compo.id}" />
</h:link>
</h:column>
</h:dataTable>
</p:column>
</p:dataTable>
</h:form>
......
......@@ -7,56 +7,88 @@
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:viewParam name="compoId" value="#{compoMgmtView.compoId}" />
<f:viewParam name="compoId" value="#{compoMgmtView.compoId}"/>
<!-- <f:viewParam name="compoId" value="#{compoMgmtView.compoId2}" /> -->
<f:event type="preRenderView" listener="#{compoMgmtView.initView}" />
<f:event type="preRenderView" listener="#{compoMgmtView.initView}"/>
</f:metadata>
<ui:define name="content">
<!-- <h:outputStylesheet library="style" name="insomnia2/css/actionlog.css" /> -->
<h1>Compo: #{compoMgmtView.compo.name}</h1>
<p>Infoa compon entryistä</p>
<compo:editCompo commitAction="#{compoMgmtView.saveCompo}" commitValue="#{i18n['voting.create.saveCompo']}" />
<compo:editCompo commitAction="#{compoMgmtView.saveCompo}" commitValue="#{i18n['voting.create.saveCompo']}"/>
<h2>Compo filetypes</h2>
<h:form id="filetypeEditform">
<p:panelGrid columns="2">
<p:outputLabel for="filetypeid" rendered="#{not empty compoMgmtView.filetype.id}" value="#{i18n['compo.filetype.id']}"/>
<h:outputText id="filetypeid" rendered="#{not empty compoMgmtView.filetype.id}" value="#{compoMgmtView.filetype.id}"/>
<p:outputLabel for="filetypename" value="#{i18n['compo.filetype.name']}"/>
<p:inputText id="filetypename" value="#{compoMgmtView.filetype.name}"/>
<p:outputLabel for="filetypesort" value="#{i18n['compo.filetype.sort']}"/>
<p:inputText id="filetypesort" value="#{compoMgmtView.filetype.sort}"/>
<p:outputLabel for="filetypetype" value="#{i18n['compo.filetype.filetype']}"/>
<p:selectOneMenu id="filetypetype" value="#{compoMgmtView.filetype.filetype}">
<f:selectItems value="#{compoMgmtView.filetypeTypes}" val="t"/>
</p:selectOneMenu>
</p:panelGrid>
<p:commandButton update="filetypelist,filetypeEditform" action="#{compoMgmtView.saveFiletype}" value="#{i18n['save']}"/>
</h:form>
<br/>
<p:dataTable id="filetypelist" value="#{compoMgmtView.compo.filetypes}" var="ft">
<p:column> <h:outputText value="#{ft.name}"/> </p:column>
<p:column> <h:outputText value="#{ft.filetype}"/> </p:column>
<p:column>
<p:commandButton value="Edit" update="filetypeEditform" action="#{compoMgmtView.editFiletype(ft.id)}" />
&nbsp;<p:commandButton value="Delete" update="filetypelist" action="#{compoMgmtView.deleteFiletype(ft.id)}" />
</p:column>
</p:dataTable>
<h2>#{i18n['compoMgmtView.compo.entries']}</h2>
<h:form>
<p:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{compoMgmtView.entries}" var="entry">
<p:column headerText="Title">
<h:outputText value="#{entry.title}" />
<h:outputText value="#{entry.title}"/>
</p:column>
<p:column headerText="Author">
<h:outputText value="#{entry.author}" />
<h:outputText value="#{entry.author}"/>
</p:column>
<p:column headerText="Notes">
<h:outputText value="#{entry.notes}" />
<h:outputText value="#{entry.notes}"/>
</p:column>
<p:column headerText="Screenmessage">
<h:outputText value="#{entry.screenMessage}" />
<h:outputText value="#{entry.screenMessage}"/>
</p:column>
<p:column headerText="creator">
<h:link outcome="/useradmin/edit" value="#{entry.creator.user.nick}">
<f:param name="userid" value="#{entry.creator.user.id}" />
<f:param name="userid" value="#{entry.creator.user.id}"/>
</h:link>
</p:column>
<p:column headerText="Sort">
<h:inputText value="#{entry.sort}" size="4" />
<h:inputText value="#{entry.sort}" size="4"/>
</p:column>
<p:column headerText="Vote total">
<h:outputText value="#{entry.votetotal}" />
<h:outputText value="#{entry.votetotal}"/>
</p:column>
<p:column headerText="Vote count">
<h:outputText value="#{entry.votes.size()}" />
<h:outputText value="#{entry.votes.size()}"/>
</p:column>
<p:column>
<h:link outcome="/voting/submitEntry" value="#{i18n['entry.edit']}">
<f:param name="entryId" value="#{entry.id}" />
<f:param name="entryId" value="#{entry.id}"/>
</h:link>
</p:column>
</p:dataTable>
<h:commandButton action="#{compoMgmtView.saveSort}" value="#{i18n['compo.savesort']}" />
<p:commandButton ajax="false" action="#{compoMgmtView.saveSort}" value="#{i18n['compo.savesort']}"/>
</h:form>
......
......@@ -14,39 +14,27 @@
<h:form id="myEntries" styleClass="moya_datatable2">
<h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{voteListView.entries}" var="entry">
<h:column>
<f:facet name="header">
<h:outputText value="Title" />
</f:facet>
<p:dataTable tableStyle="width: auto;" styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{voteListView.entries}" var="entry">
<p:column headerText="Title">
<h:outputText value="#{entry.title}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Author" />
</f:facet>
</p:column>
<p:column headerText="Author">
<h:outputText value="#{entry.author}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Notes" />
</f:facet>
</p:column>
<p:column headerText="Notes">
<h:outputText value="#{entry.notes}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Screen message" />
</f:facet>
</p:column>
<p:column headerText="Screen message">
<h:outputText value="#{entry.screenMessage}" />
</h:column>
</p:column>
<h:column>
<p:column>
<h:link outcome="/voting/submitEntry" value="#{i18n['entry.edit']}">
<f:param name="entryId" value="#{entry.id}" />
</h:link>
</h:column>
</p:column>
</h:dataTable>
</p:dataTable>
</h:form>
......
......@@ -7,75 +7,128 @@
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:viewParam name="compoId" value="#{compoView.compoId}" />
<f:viewParam name="entryId" value="#{compoView.entryId}" />
<f:event type="preRenderView" listener="#{compoView.initEntryView}" />
<f:viewParam name="compoId" value="#{entryEditView.compoId}"/>
<f:viewParam name="entryId" value="#{entryEditView.entryId}"/>
<f:event type="preRenderView" listener="#{entryEditView.initEntryView}"/>
</f:metadata>
<ui:define name="content">
<!-- <h:outputStylesheet library="style" name="insomnia2/css/actionlog.css" /> -->
<h1>#{i18n['voting.compoentryadd.title']}</h1>
<p>
#{i18n['voting.compoentryadd.description']}
<h:outputText value="#{compoView.compo.name}" />
<h:outputText value="#{entryEditView.compo.name}"/>
</p>
<p>
<h:outputText value="#{compoView.compo.description}" />
<h:outputText value="#{entryEditView.compo.description}"/>
</p>
<h:form>
<h:outputText value="#{entryEditView.entry.id}"/>
<h:panelGrid columns="3">
<h:outputLabel value="Title" for="name" />
<h:inputText value="#{compoView.entry.title}" id="name" />
<h:message for="name" />
<h:outputLabel value="Title" for="name"/>
<p:inputText value="#{entryEditView.entry.title}" id="name"/>
<h:message for="name"/>
<h:outputLabel value="Author" for="author" />
<h:inputText value="#{compoView.entry.author}" id="author" />
<h:message for="author" />
<h:outputLabel value="Author" for="author"/>
<p:inputText value="#{entryEditView.entry.author}" id="author"/>
<h:message for="author"/>
<h:outputLabel value="#{i18n['voting.compoentryadd.notes']}" for="notes" />
<h:inputTextarea value="#{compoView.entry.notes}" id="notes" />
<h:message for="notes" />
<h:outputLabel value="#{i18n['voting.compoentryadd.notes']}" for="notes"/>
<p:inputTextarea value="#{entryEditView.entry.notes}" id="notes"/>
<h:message for="notes"/>
<h:outputLabel value="#{i18n['voting.compoentryadd.screenmessage']}" for="screenmessage" />
<h:inputTextarea value="#{compoView.entry.screenMessage}" id="screenmessage" />
<h:message for="screenmessage" />
<h:commandButton rendered="#{empty compoView.entry.id}" action="#{compoView.createEntry()}" value="#{i18n['voting.compoentryadd.button']}" />
<h:commandButton rendered="#{!empty compoView.entry.id}" action="#{compoView.saveEntry()}" value="#{i18n['voting.compoentrysave.button']}" />
<h:outputLabel value="#{i18n['voting.compoentryadd.screenmessage']}" for="screenmessage"/>
<p:inputTextarea value="#{entryEditView.entry.screenMessage}" id="screenmessage"/>
<h:message for="screenmessage"/>
</h:panelGrid>
<p:commandButton ajax="false" rendered="#{empty entryEditView.entry.id}" action="#{entryEditView.createEntry()}" value="#{i18n['voting.compoentryadd.button']}"/>
<p:commandButton ajax="false" rendered="#{not empty entryEditView.entry.id}" action="#{entryEditView.saveEntry()}" value="#{i18n['voting.compoentrysave.button']}"/>
</h:form>
<ui:fragment rendered="#{!empty entryEditView.entry.id}">
<h2>
<h:outputText value="#{i18n['compofile.download.header']}"/>
</h2>
<p:dataTable style="width: auto;" value="#{entryEditView.entryFiletypes}" var="ft">
<p:column headerText="">
<h:outputText value="#{ft.filetype.name}"/>
</p:column>
<p:column headerText="Current file">
<p:commandButton rendered="#{not empty ft.entryfiletype.currentFile}" update=":fileInfoForm:fileInfoDialog" oncomplete="PF('fileInfoDialog').show()" icon="ui-icon-search"
title="View files">
<f:setPropertyActionListener value="#{ft.entryfiletype}" target="#{entryEditView.selectedFiletype}"/>
</p:commandButton>
</p:column>
<p:column>
<form id="filesubmit-#{ft.filetype.id}" action="#{request.contextPath}/EntryFile" method="post" enctype="multipart/form-data">
<div>
<input type="file" name="file"/>
<input type="hidden" name="entryId" value="#{entryEditView.entry.id}"/>
<input type="hidden" name="typeId" value="#{ft.filetype.id}"/>
<button type="submit">Submit</button>
</div>
</form>
</p:column>
</p:dataTable>
<h:commandButton rendered="#{empty compoView.entry.id}" action="#{compoView.createEntry()}" value="Ilmoittaudu kilpailuun" />
<h:form id="fileInfoForm">
<p:dialog id="fileInfoDialog" widgetVar="fileInfoDialog" modal="true" appendTo="@(body)">
<p:dataTable tableStyle="width: auto;" value="#{entryEditView.selectedFiletype.entryFiles}" var="file">
<p:column headerText="CurrentFile">
<h:outputText value="X" rendered="#{entryEditView.selectedFiletype.currentFile==file}"/>
</p:column>
<p:column headerText="#{i18n['compofile.fileName']}">
<a href="#{request.contextPath}/EntryFile/#{file.id}">
<h:outputText value="#{file.fileName}"/>
</a>
</p:column>
<p:column headerText="#{i18n['compofile.uploadTime']}">
<h:outputText value="#{file.uploaded}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}"/>
</h:outputText>
</p:column>
<p:column headerText="#{i18n['compofile.shaChecksum']}">
<h:outputText value="#{file.hash}"/>
</p:column>
</p:dataTable>
</p:dialog>
</h:form>
<!--
<ui:fragment rendered="#{!empty compoView.entry.id}">
<h:form enctype="multipart/form-data">
<p:fileUpload value="#{compoView.uploadedFile}" id="uploadedfile" mode="simple" />
<h:commandButton action="#{compoView.submitEntryfile}" value="#{i18n['compofile.upload']}" />
<p:fileUpload value="#{compoView.uploadedFile}" id="uploadedfile" mode="simple"/>
<p:commandButton ajax="false" action="#{compoView.submitEntryfile}" value="#{i18n['compofile.upload']}"/>
</h:form>
<br/>
<h:form rendered="#{!empty compoFileDownloadView.files}">
<h2>
<h:outputText value="#{i18n['compofile.download.header']}" />
</h2>
<p:dataTable value="#{compoView.compo.filetypes}" var="type">
<p:column> <h:outputText value="#{type.name}"/> </p:column>
<p:column> <h:outputText value="#{type.filetype}"/> </p:column>
</p:dataTable>
<p:dataTable value="#{compoFileDownloadView.files}" var="fi">
<p:column headerText="#{i18n['compofile.fileName']}">
<h:outputText value="#{fi.fileName}" />
<h:outputText value="#{fi.fileName}"/>
</p:column>
<p:column headerText="#{i18n['compofile.uploadTime']}">
<h:outputText value="#{fi.uploaded.time}">
<f:convertDateTime pattern="#{sessionHandler.shortDatetimeFormat}" />
</h:outputText>
<h:outputText value="#{fi.uploaded.time}"> <f:convertDateTime pattern="#{sessionHandler.shortDatetimeFormat}"/> </h:outputText>
</p:column>
<p:column headerText="#{i18n['compofile.shaChecksum']}">
<h:outputText value="#{fi.hash}" />
<h:outputText value="#{fi.hash}"/>
</p:column>
<p:column>
<p:commandButton ajax="false" value="#{i18n['compofile.download']}" actionListener="#{compoFileDownloadView.selectDownloadedFile}">
<p:fileDownload value="#{compoFileDownloadView.dlfile}" />
<p:fileDownload value="#{compoFileDownloadView.dlfile}"/>
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
-->
</ui:fragment>
</ui:define>
......
......@@ -68,7 +68,7 @@ public class MoyaGraphQLServlet extends HttpServlet {
private VotingBeanLocal votebean;
@EJB
private UserPropertyBeanLocal eventUserPropertyBean;
private static final Comparator<? super GenericEntity> ENTITY_ID_SORTER = (Comparator<GenericEntity>) (o1, o2) -> o1.getId().compareTo(o2.getId().compareTo());
private static final Comparator<? super GenericEntity> ENTITY_ID_SORTER = (Comparator<GenericEntity>) (o1, o2) -> o1.getId().compareTo(o2.getId());
@Override
public void init(ServletConfig config) throws ServletException {
......@@ -284,8 +284,8 @@ public class MoyaGraphQLServlet extends HttpServlet {
b.addField(EventUser_.event).type(builder.typeFor(SIMPLE_EVENT_TYPE_NAME));
b.addField(EventUser_.eventuserCreated);
b.addField(EventUser_.id);
b.addListField(Role.class).dataFetcher(environment -> {userbean.findUsersRoles(environment.getSource()));
b.addListField(UsersEventUserproperty.class).dataFetcher(environment -> eventUserPropertyBean.getUserPropertiesForUser(environment.getSource()).stream().sorted(ENTITY_ID_SORTER).collect(toList());
b.addListField(Role.class).dataFetcher(environment -> userbean.findUsersRoles(environment.getSource()));
b.addListField(UsersEventUserproperty.class).dataFetcher(environment -> eventUserPropertyBean.getUserPropertiesForUser(environment.getSource()).stream().sorted(ENTITY_ID_SORTER).collect(toList()));
b.addField(EventUser_.currentPlaces);
}
......@@ -499,7 +499,6 @@ public class MoyaGraphQLServlet extends HttpServlet {
b.addField(CompoEntry_.screenMessage);
b.addField(CompoEntry_.sort);
b.addField(CompoEntry_.compo);
b.addField(CompoEntry_.currentFile);
b.addField(CompoEntry_.meta);
}
......@@ -513,8 +512,6 @@ public class MoyaGraphQLServlet extends HttpServlet {
b.addField(CompoEntryFile_.fileName);
b.addField(CompoEntryFile_.description);
b.addField(CompoEntryFile_.uploaded);
b.addField(CompoEntryFile_.fileData);
b.addField(CompoEntryFile_.entry);
b.addField(CompoEntryFile_.hash).description("SHA1 hash of the file data");
b.addField(CompoEntryFile_.meta);
......@@ -549,11 +546,11 @@ public class MoyaGraphQLServlet extends HttpServlet {
b.addField(LanEvent_.meta);
b.addListField(EventMap.class).dataFetcher(environment -> placebean.getMaps().stream().sorted(ENTITY_ID_SORTER).collect(toList());
b.addListField(Role.class).dataFetcher(environment -> rolebean.listRoles().stream().sorted(ENTITY_ID_SORTER).collect(toList());
b.addListField(EventMap.class).dataFetcher(environment -> placebean.getMaps().stream().sorted(ENTITY_ID_SORTER).collect(toList()));
b.addListField(Role.class).dataFetcher(environment -> rolebean.listRoles().stream().sorted(ENTITY_ID_SORTER).collect(toList()));
b.addListField(Product.class).dataFetcher(environment -> productbean.findProductsForEvent().stream().sorted(ENTITY_ID_SORTER).collect(toList());
b.addListField(Compo.class).dataFetcher(environment -> votebean.getCompoList(true).stream().sorted(ENTITY_ID_SORTER).collect(toList());
b.addListField(Product.class).dataFetcher(environment -> productbean.findProductsForEvent().stream().sorted(ENTITY_ID_SORTER).collect(toList()));
b.addListField(Compo.class).dataFetcher(environment -> votebean.getCompoList(true).stream().sorted(ENTITY_ID_SORTER).collect(toList()));
b.addField(LanEvent_.id);
}
......
......@@ -33,7 +33,7 @@ import fi.codecrew.moya.model.CardTemplate;
/**
* Servlet implementation class UploadServlet
*/
@WebServlet("/CardTemplate")
@WebServlet(value="/CardTemplate")
public class CardTemplateServlet extends GenericImageServlet {
/**
......
package fi.codecrew.moya.servlet;
import fi.codecrew.moya.beans.VotingBeanLocal;
import fi.codecrew.moya.model.*;
import fi.codecrew.moya.utilities.SystemProperty;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@WebServlet(value = "/EntryFile/*")
public class CompoEntryFileServlet extends HttpServlet {
private static final Logger logger = LoggerFactory.getLogger(CompoEntryFileServlet.class);
/**
* @see HttpServlet#HttpServlet()
*/
public CompoEntryFileServlet() {
super();
logger.warn("Initializing StreamingUploadServlet");
}
@EJB
private VotingBeanLocal votebean;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
int fileId = Integer.parseUnsignedInt(req.getPathInfo().substring(1));
CompoEntryFile entry = votebean.findEntryFile(fileId);
if (entry == null) {
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
resp.getWriter().write("Entity not found");
return;
}
File file = new File(new File(SystemProperty.MOYA_COMPOFILE_DIR.getValueOrDefault()), entry.getFilepath());
resp.setContentType(entry.getMimeType());
resp.setHeader("Content-Disposition", "filename=\"" + entry.getFileName() + "\"");
resp.setContentLength((int) file.length());
FileInputStream inStream = new FileInputStream(file);
ServletOutputStream oStream = resp.getOutputStream();
final byte[] buff = new byte[8192];
while (true) {
int len = inStream.read(buff);
if (len < 1) {
break;
}
oStream.write(buff, 0, len);
}
oStream.close();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
File dir = new File(SystemProperty.MOYA_COMPOFILE_DIR.getValueOrDefault());
if (!dir.isDirectory()) {
dir.mkdirs();
}
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
if (!isMultipart) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Expected multipart upload");
return;
}
ServletFileUpload upload = new ServletFileUpload();
try {
FileItemIterator iter = upload.getItemIterator(req);
final byte[] buff = new byte[8192];
File tmpFile = File.createTempFile("moya-file", "tmp", dir);
CompoEntryFile entryfile = new CompoEntryFile();
Integer entryId = 0;
Integer typeId = 0;
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();
if (item.isFormField()) {
final String data = Streams.asString(stream);
logger.warn("Streaming upload form field " + name + " with value " + data + " detected.");
switch (name) {
case "entryId": {
entryId = Integer.parseInt(data);
break;
}
case "typeId": {
typeId = Integer.parseInt(data);
break;
}
}
} else {
logger.warn("File field " + name + " with file name " + item.getName() + " detected." + item.getContentType());
MessageDigest algo = MessageDigest.getInstance("SHA");
FileOutputStream ostream = new FileOutputStream(tmpFile);
while (true) {
int len = stream.read(buff);
if (len < 1) {
break;
}
ostream.write(buff, 0, len);
algo.update(buff, 0, len);
}
String shasum = new String(Hex.encodeHex(algo.digest())).toLowerCase();
logger.warn("File shasum " + shasum);
ostream.close();
entryfile.setFileName(item.getName());
entryfile.setMimeType(item.getContentType());
entryfile.setHash(shasum);
}
stream.close();
}
CompoEntryFileType ft = votebean.findEntryFileType(entryId, typeId);
String ftPath = mkEntryFiletypePath(ft);
File filetypepath = new File(dir, ftPath);
if (!filetypepath.isDirectory()) {
filetypepath.mkdirs();
}
String filePath = ftPath + mkPath(entryfile.getUploaded().getTime() + "_" + entryfile.getFileName()) + ".dat";
logger.warn("Target file: {}, ftpath {}", filePath, ftPath);
entryfile.setFilepath(filePath);
if (!tmpFile.renameTo(new File(dir, filePath))) {
throw new RuntimeException("Error moving file to " + filePath);
}
entryfile.setFiletype(ft);
votebean.create(entryfile);
resp.setStatus(HttpServletResponse.SC_SEE_OTHER);
resp.setHeader("Location", "/MoyaWeb/voting/submitEntry.jsf?entryId=" + entryId);
} catch (FileUploadException e) {
logger.warn("Error uploading streaming file", e);
} catch (NoSuchAlgorithmException e) {
logger.warn("Error calculating checksum", e);
}
}
String asString(InputStream stream) throws IOException {
final byte[] buff = new byte[100];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (true) {
int len = stream.read(buff);
if (len < 1) {
break;
}
baos.write(buff, 0, len);
}
return baos.toString();
}
public static void main(String[] asd) {
logger.warn("asda {}", mkPath("Foo", "[]{}äöherp", "1239KKKKK"));
}
public static String mkPath(Object... paths) {
StringBuilder ret = new StringBuilder();
for (Object p : paths) {
ret.append("/");
ret.append(p.toString().toLowerCase().replaceAll("[^a-z0-9]", "_"));
}
return ret.toString().replaceAll("_+", "_");
}
public static String mkEntryFiletypePath(CompoEntryFileType type) {
final CompoEntry entry = type.getEntry();
;
final Compo compo = entry.getCompo();
final LanEvent event = compo.getEvent();
return mkPath(
event.getId() + "_ " + event.getName(),
compo.getId() + "_" + compo.getName(),
entry.getId() + "_" + entry.getTitle(),
type.getId() + "_" + type.getType().getName()
);
}
}
......@@ -83,7 +83,6 @@ public class UploadServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// boolean isMultipart = ServletFileUpload.isMultipartContent(request);
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
CharSequence retmsg = "Tiedosto tallennettu onnistuneesti.";
......@@ -106,6 +105,9 @@ public class UploadServlet extends HttpServlet {
destId = null;
}
}
ServletFileUpload upload = new ServletFileUpload(factory);
for (Object ti : upload.parseRequest(request)) {
if (ti instanceof FileItem) {
......
package fi.codecrew.moya.web.api;
import fi.codecrew.moya.beans.ApiApplicationBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.model.ApiApplication;
import fi.codecrew.moya.model.ApiApplicationInstance;
import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Named;
import java.util.List;
@Named
@ConversationScoped
public class ApiAppEditView extends GenericCDIView {
private static final long serialVersionUID = -5137452386861332063L;
@EJB
private ApiApplicationBeanLocal apibean;
@EJB
private PermissionBeanLocal permbean;
private ApiApplication apiApp;
private Integer id;
private ApiApplicationInstance selectedInstance;
private ListDataModel<ApiApplicationInstance> apiInstances;
public void initEdit() {
if (super.requirePermissions(permbean.isLoggedIn()) && apiApp == null) {
super.beginConversation();
apiApp = apibean.findApplication(id);
apiInstances = new ListDataModel<>(apibean.findInstances(apiApp));
}
}
public void initCreateInstance() {
selectedInstance = apibean.createApplicationInstance(apiApp);
}
public void selectInstance(){
selectedInstance = apiInstances.getRowData();
}
public void saveInstance() {
apibean.saveApiInstance(selectedInstance);
}
public String save() {
apiApp = apibean.saveApiApplication(apiApp);
return null;
}
public ApiApplication getApiApp() {
return apiApp;
}
public void setApiApp(ApiApplication apiApp) {
this.apiApp = apiApp;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public ApiApplicationInstance getSelectedInstance() {
return selectedInstance;
}
public void setSelectedInstance(ApiApplicationInstance selectedInstance) {
this.selectedInstance = selectedInstance;
}
public ListDataModel<ApiApplicationInstance> getApiInstances() {
return apiInstances;
}
public void setApiInstances(ListDataModel<ApiApplicationInstance> apiInstances) {
this.apiInstances = apiInstances;
}
}
......@@ -39,15 +39,22 @@ public class ApplicationApiView extends GenericCDIView {
private static final Logger logger = LoggerFactory.getLogger(ApplicationApiView.class);
public void initApplicationListView() {
if (super.requirePermissions(permbean.isLoggedIn()) && applist == null) {
EventUser curruser = permbean.getCurrentUser();
if (permbean.hasPermission(SpecialPermission.SUPERADMIN)) {
applist = apibean.findAllApplications();
} else {
applist = apibean.findMyApplications();
}
}
public void initSuperApplicationListView() {
if (super.requirePermissions(permbean.hasPermission(SpecialPermission.SUPERADMIN)) && applist == null) {
applist = apibean.findAllApplications();
}
}
public String createApp() {
apibean.createApiApplication(newApplication);
return "/api/edit?faces-redirect=true&id=" + newApplication.getId();
}
public List<ApiApplication> getApplist() {
......
......@@ -55,7 +55,7 @@ public class CompoFileDownloadView extends GenericCDIView {
{
if (files == null)
{
files = new ListDataModel<CompoEntryFile>(votebean.getEntryFiles(entry));
//files = new ListDataModel<CompoEntryFile>(votebean.getEntryFiles(entry));
}
return files;
}
......@@ -64,19 +64,17 @@ public class CompoFileDownloadView extends GenericCDIView {
return file;
}
public void selectDownloadedFile()
{
file = files.getRowData();
dlfile = new DefaultStreamedContent(new ByteArrayInputStream(file.getFileData()), file.getMimeType(), file.getFileName());
}
public void setFile(CompoEntryFile file) {
this.file = file;
if (file != null)
{
/*
dlfile = new DefaultStreamedContent(new ByteArrayInputStream(file.getFileData()), file.getMimeType(), file.getFileName());
logger.info("Uploading file {}, length {}", file.getFileName(), file.getFileData().length);
*/
}
}
......
......@@ -18,13 +18,16 @@
*/
package fi.codecrew.moya.web.cdiview.voting;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Named;
import fi.codecrew.moya.model.CompoFileType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -53,6 +56,8 @@ public class CompoMgmtView extends GenericCDIView {
private ListDataModel<CompoEntry> entries;
private CompoFileType filetype = new CompoFileType();
@SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(CompoMgmtView.class);
......@@ -60,10 +65,8 @@ public class CompoMgmtView extends GenericCDIView {
return compoId;
}
public void initCreate()
{
if (super.requirePermissions(fi.codecrew.moya.enums.apps.CompoPermission.MANAGE) && compo == null)
{
public void initCreate() {
if (super.requirePermissions(fi.codecrew.moya.enums.apps.CompoPermission.MANAGE) && compo == null) {
compo = new Compo();
Date now = new Date();
compo.setStartTime(now);
......@@ -82,16 +85,13 @@ public class CompoMgmtView extends GenericCDIView {
return "details";
}
public String saveCompo()
{
public String saveCompo() {
compo = votingBean.saveCompo(compo);
return null;
}
public String saveSort()
{
for (CompoEntry e : entries)
{
public String saveSort() {
for (CompoEntry e : entries) {
setCompo(votingBean.saveSort(e).getCompo());
}
entries = new ListDataModel<CompoEntry>(getCompo().getCompoEntries());
......@@ -108,8 +108,7 @@ public class CompoMgmtView extends GenericCDIView {
}
public void initView() {
if (super.requirePermissions(CompoPermission.MANAGE) && entries == null)
{
if (super.requirePermissions(CompoPermission.MANAGE) && entries == null) {
setCompo(votingBean.getCompoById(compoId));
entries = new ListDataModel<CompoEntry>(getCompo().getCompoEntries());
super.beginConversation();
......@@ -132,4 +131,40 @@ public class CompoMgmtView extends GenericCDIView {
this.compo = compo;
}
public CompoFileType getFiletype() {
return filetype;
}
public void setFiletype(CompoFileType filetype) {
this.filetype = filetype;
}
public List<CompoFileType.FileType> getFiletypeTypes() {
return Arrays.asList(CompoFileType.FileType.values());
}
public void saveFiletype() {
filetype.setCompo(compo);
compo = votingBean.saveFiletype(filetype);
filetype = new CompoFileType();
}
public void editFiletype(Integer id) {
for (CompoFileType ft : compo.getFiletypes()) {
if (ft.getId().equals(id)) {
this.filetype = ft;
return;
}
}
}
public void deleteFiletype(Integer id) {
for (CompoFileType ft : compo.getFiletypes()) {
if (ft.getId().equals(id)) {
compo = votingBean.deleteFiletype(ft);
return;
}
}
}
}
package fi.codecrew.moya.web.cdiview.voting;
import fi.codecrew.moya.model.CompoEntryFileType;
import fi.codecrew.moya.model.CompoFileType;
public class CompoTypeWrapper {
private final CompoFileType filetype;
private CompoEntryFileType entryfiletype;
public CompoTypeWrapper(CompoFileType ft) {
this.filetype = ft;
}
public void setEntryType(CompoEntryFileType eft) {
this.entryfiletype = eft;
}
public CompoFileType getFiletype() {
return filetype;
}
public CompoEntryFileType getEntryfiletype() {
return entryfiletype;
}
}
......@@ -19,6 +19,11 @@
package fi.codecrew.moya.web.cdiview.voting;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
......@@ -26,6 +31,9 @@ import javax.enterprise.inject.Produces;
import javax.faces.model.ListDataModel;
import javax.inject.Named;
import fi.codecrew.moya.beans.RoleBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.model.*;
import fi.codecrew.moya.web.helpers.FileUploadUtils;
import org.primefaces.event.RateEvent;
import org.primefaces.model.UploadedFile;
......@@ -35,9 +43,6 @@ import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.VotingBeanLocal;
import fi.codecrew.moya.enums.apps.CompoPermission;
import fi.codecrew.moya.model.Compo;
import fi.codecrew.moya.model.CompoEntry;
import fi.codecrew.moya.model.CompoEntryFile;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
......@@ -50,11 +55,14 @@ public class CompoView extends GenericCDIView {
private VotingBeanLocal votbean;
@EJB
private PermissionBeanLocal permbean;
@EJB
private UserBeanLocal userbean;
private boolean manage;
private ListDataModel<Compo> compolist;
private ListDataModel<CompoWrapper> compolist;
@Produces
private CompoEntry entry;
......@@ -70,57 +78,26 @@ public class CompoView extends GenericCDIView {
private ListDataModel<EntryWrapper> voteEntries;
public ListDataModel<Compo> getCompos() {
public ListDataModel<CompoWrapper> getCompos() {
return compolist;
}
public void initEntryView()
{
if (super.requirePermissions(CompoPermission.SUBMIT_ENTRY) && entry == null)
{
if (entryId == null)
{
entry = new CompoEntry();
if (compo == null && compoId != null) {
compo = votbean.getCompoById(compoId);
entry.setCompo(compo);
}
super.beginConversation();
} else {
entry = votbean.findEntry(entryId);
if (entry == null ||
!super.requirePermissions(
super.hasPermission(CompoPermission.MANAGE) ||
permbean.isCurrentUser(entry.getCreator()))) {
entry = null;
compo = null;
} else {
compo = entry.getCompo();
super.beginConversation();
}
}
}
logger.info("Initializing entry view {} {}", entry, compo);
}
public String startVote()
{
compo = compolist.getRowData();
public String startVote() {
compo = compolist.getRowData().getCompo();
setVoteEntries(EntryWrapper.init(compo.getCompoEntries(), votbean, false));
logger.info("Initializing voting with entries {}, {}", compo.getCompoEntries().size(), voteEntries.getRowCount());
super.beginConversation();
return "/voting/vote";
}
public void handleVoteRate(RateEvent rateEvent)
{
public void handleVoteRate(RateEvent rateEvent) {
EntryWrapper row = voteEntries.getRowData();
Integer vote = (Integer) rateEvent.getRating() - 3;
if (vote < -2 || vote > 2)
{
if (vote < -2 || vote > 2) {
vote = 0;
}
votbean.saveVote(row.getEntry(), vote);
......@@ -128,76 +105,22 @@ public class CompoView extends GenericCDIView {
}
public String saveVotes() {
for (EntryWrapper vw : voteEntries)
{
for (EntryWrapper vw : voteEntries) {
votbean.saveVote(vw.getEntry(), vw.getVote());
}
super.addFaceMessage("compo.votesSaved");
return null;
}
public String submitEntry()
{
setCompo(compolist.getRowData());
setEntry(new CompoEntry());
getEntry().setCompo(getCompo());
return "/voting/submitEntry";
}
public String createEntry()
{
compo = votbean.addEntry(getEntry());
return null;
}
public String saveEntry()
{
setEntry(votbean.saveEntry(getEntry()));
return null;
}
public String submitEntryfile()
{
UploadedFile file = getUploadedFile();
if (file == null)
{
super.addFaceMessage("compo.fileuploadFailed");
return null;
}
byte[] contents = FileUploadUtils.getFileContents(file);
if (contents == null || contents.length == 0) {
super.addFaceMessage("compo.fileuploadFailed");
return null;
}
CompoEntryFile cef = new CompoEntryFile(getEntry());
cef.setFileData(contents);
logger.info("Got file name {} length {}", getUploadedFile().getFileName(), cef.getFileData().length);
cef.setFileName(getUploadedFile().getFileName());
cef.setMimeType(getUploadedFile().getContentType());
// getEntry().setCurrentFile(cef);
votbean.create(cef);
return null;
}
public void initAdminListView() {
if (requirePermissions(CompoPermission.MANAGE) && compolist == null) {
compolist = new ListDataModel<Compo>(votbean.getCompoList(true));
compolist = new ListDataModel<>(votbean.getCompoList(true).stream().map(c -> new CompoWrapper(c)).collect(Collectors.toList()));
setManage(hasPermission(CompoPermission.MANAGE));
logger.info("Permission to view full compo listing.");
super.beginConversation();
}
else {
} else {
logger.info("Not enough rights to view full compo listing.");
}
......@@ -206,12 +129,11 @@ public class CompoView extends GenericCDIView {
public void initListView() {
if (requirePermissions(CompoPermission.VIEW_COMPOS) && compolist == null) {
compolist = new ListDataModel<Compo>(votbean.getCompoList(false));
compolist = new ListDataModel<>(votbean.getCompoList(false).stream().map(c -> new CompoWrapper(c)).collect(Collectors.toList()));
setManage(hasPermission(CompoPermission.MANAGE));
logger.info("Permission to view full compo listing.");
super.beginConversation();
}
else {
} else {
logger.info("Not enough rights to view full compo listing.");
}
......@@ -274,4 +196,25 @@ public class CompoView extends GenericCDIView {
this.compoId = compoId;
}
public class CompoWrapper {
private final Compo compo;
public CompoWrapper(Compo c) {
this.compo = c;
}
public Compo getCompo() {
return compo;
}
public boolean isCanVote() {
return compo.isVote();
}
public boolean isCanSubmit() {
return compo.isSubmit() && (compo.getEntrysubmitRole() == null || userbean.isUserInRole(permbean.getCurrentUser(), compo.getEntrysubmitRole()));
}
}
}
package fi.codecrew.moya.web.cdiview.voting;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.beans.VotingBeanLocal;
import fi.codecrew.moya.enums.apps.CompoPermission;
import fi.codecrew.moya.model.*;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@Named
@ConversationScoped
public class EntryEditView extends GenericCDIView {
private static final Logger logger = LoggerFactory.getLogger(EntryEditView.class);
@EJB
private VotingBeanLocal votbean;
@EJB
private UserBeanLocal userbean;
private Integer compoId;
private Integer entryId;
private Compo compo;
private CompoEntry entry;
private CompoEntryFileType selectedFiletype;
public String createEntry() {
compo = votbean.addEntry(entry);
return null;
}
public String saveEntry() {
entry = votbean.saveEntry(entry);
return null;
}
public void initEntryView() {
if (!super.requirePermissions(CompoPermission.SUBMIT_ENTRY) || entry != null) {
return;
}
if (entryId == null) {
if (compo == null && compoId != null) {
compo = votbean.getCompoById(compoId);
}
if (compo == null) {
throw new RuntimeException("Compo not found.");
}
if (compo.getEntrysubmitRole() != null && !userbean.isUserInRole(permbean.getCurrentUser(), compo.getEntrysubmitRole())) {
super.addFaceMessage("You do not have correct permissions to submit an entry to this compo.");
navihandler.forward("/permissionDenied");
return;
}
entry = new CompoEntry();
entry.setCompo(compo);
} else {
entry = votbean.findEntry(entryId);
compo = entry.getCompo();
if (entry == null || !super.requirePermissions(super.hasPermission(CompoPermission.MANAGE) || permbean.isCurrentUser(entry.getCreator()))) {
entry = null;
compo = null;
return;
}
}
super.beginConversation();
logger.info("Initializing entry view {} {}", entry, compo);
}
public List<CompoTypeWrapper> getEntryFiletypes() {
HashMap<CompoFileType, CompoTypeWrapper> ret = new HashMap<>();
for (CompoFileType ft : entry.getCompo().getFiletypes()) {
ret.put(ft, new CompoTypeWrapper(ft));
}
for (CompoEntryFileType eft : entry.getFiletypes()) {
ret.get(eft.getType()).setEntryType(eft);
}
// (x < y) ? -1 : ((x == y) ? 0 : 1);
ArrayList<CompoTypeWrapper> retList = new ArrayList<>(ret.values());
retList.sort(Comparator.comparingInt(o -> o.getFiletype().getSort()));
return retList;
}
public Integer getCompoId() {
return compoId;
}
public void setCompoId(Integer compoId) {
this.compoId = compoId;
}
public Integer getEntryId() {
return entryId;
}
public void setEntryId(Integer entryId) {
this.entryId = entryId;
}
public Compo getCompo() {
return compo;
}
public void setCompo(Compo compo) {
this.compo = compo;
}
public CompoEntry getEntry() {
return entry;
}
public void setEntry(CompoEntry entry) {
this.entry = entry;
}
public CompoEntryFileType getSelectedFiletype() {
return selectedFiletype;
}
public void setSelectedFiletype(CompoEntryFileType selectedFiletype) {
this.selectedFiletype = selectedFiletype;
}
}
......@@ -126,8 +126,8 @@ public class VotingCompoAddEntryView extends GenericCDIView {
compoEntry.setNotes(notes);
compoEntry.setScreenMessage(screenMessage);
compoEntry.setCompo(votingBean.getCompoById(compoId));
CompoEntryFile cef = new CompoEntryFile(compoEntry);
cef.setFileData(contents);
CompoEntryFile cef = new CompoEntryFile();
//cef.setFileData(contents);
cef.setFileName(uploadedFile.getFileName());
votingBean.addEntry(compoEntry, cef);
return null;
......
......@@ -1604,7 +1604,7 @@ voting.allcompos.holdVoting = Hold voting
voting.allcompos.maxParts = Max participants
voting.allcompos.name = Name
voting.allcompos.startTime = Start time
voting.allcompos.submitEnd = End submitting
voting.allcompos.submitEnd =
voting.allcompos.submitEntry = Submit entry
voting.allcompos.submitStart = Start submitting
voting.allcompos.voteEnd = End voting
......@@ -1687,3 +1687,7 @@ role.source.ACCOUNTEVENT =
role.source.PLACE_PRODUCT =
role.source.EVENT_DEFAULT =
user.allroles =
voting.create.entrysubmitrole =
compo.filetype.name =
compo.filetype.sort =
compo.filetype.filetype =
\ No newline at end of file
......@@ -4,6 +4,7 @@
acc_line.eventuser = Customer
acc_line.nick = Nick
acc_line.place = Place
acc_line.product = Product
acc_line.quantity = Quantity
acc_line.time = Transaction Date
......@@ -1842,7 +1843,7 @@ voting.allcompos.holdVoting = Hold voti
voting.allcompos.maxParts = Max participants
voting.allcompos.name = Name
voting.allcompos.startTime = Start time
voting.allcompos.submitEnd = End submitting
voting.allcompos.submitEnd = Compo submit deadline
voting.allcompos.submitEntry = Submit entry
voting.allcompos.submitStart = Start submitting
voting.allcompos.voteEnd = End voting
......@@ -1924,3 +1925,7 @@ role.source.ACCOUNTEVENT = Accountev
role.source.PLACE_PRODUCT = Product via place
role.source.EVENT_DEFAULT = Event default role
user.allroles = All users roles
voting.create.entrysubmitrole = Role needed to submit entries
compo.filetype.name = Filetype name
compo.filetype.sort = Sort number
compo.filetype.filetype = Type
\ No newline at end of file
......@@ -1833,7 +1833,7 @@ voting.allcompos.holdVoting = Hold voti
voting.allcompos.maxParts = Max osallistujam\u00E4\u00E4r\u00E4
voting.allcompos.name = Nimi
voting.allcompos.startTime = Aloitusaika
voting.allcompos.submitEnd = Lis\u00E4ys kiinni
voting.allcompos.submitEnd = Ilmoittautumisen m\u00E4\u00E4r\u00E4aika
voting.allcompos.submitEntry = L\u00E4het\u00E4 entry
voting.allcompos.submitStart = Lis\u00E4ys auki
voting.allcompos.voteEnd = \u00C4\u00E4nestys kiinni
......@@ -1915,4 +1915,8 @@ role.source.PLACE = Paikka
role.source.ACCOUNTEVENT = Tilitapahtuma (Ostettu tuote)
role.source.PLACE_PRODUCT = Tuote paikan kautta
role.source.EVENT_DEFAULT = Tapahtuman oletusrooli
user.allroles = Kaikki k\u00E4yttäj\u00E4n roolit
\ No newline at end of file
user.allroles = Kaikki k\u00E4ytt\u00E4j\u00E4n roolit
voting.create.entrysubmitrole = Teosten lhettmiseen tarvittava rooli
compo.filetype.name = Tiedostotyypin nimi
compo.filetype.sort = Jrjestysnumero
compo.filetype.filetype = Tyyppi
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!