Commit f22c63df by Tuomas Riihimäki

WIP: Users eventproperties

1 parent 67b43f5f
package fi.codecrew.moya.beans;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.EventUserproperty;
import fi.codecrew.moya.model.UsersEventUserproperty;
import javax.ejb.Local;
import java.util.List;
@Local
public interface UserPropertyBeanLocal {
List<EventUserproperty> getPropertiesForUser(EventUser user);
List<UsersEventUserproperty> getUserPropertiesForUser(EventUser user);
}
...@@ -586,8 +586,19 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -586,8 +586,19 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE users ALTER confirm_time TYPE TIMESTAMPTZ", "ALTER TABLE users ALTER confirm_time TYPE TIMESTAMPTZ",
"ALTER TABLE users ALTER created TYPE TIMESTAMPTZ" "ALTER TABLE users ALTER created TYPE TIMESTAMPTZ"
}); });
dbUpdates.add(new String[]{
"CREATE TABLE event_userproperties (id SERIAL NOT NULL, description jsonb not null, meta json, name jsonb not null, TYPE TEXT NOT NULL, event_id INTEGER NOT NULL, for_role_id INTEGER, PRIMARY KEY (id))",
"CREATE TABLE users_event_userproperties (id SERIAL NOT NULL, datavalue BYTEA, decimalvalue DECIMAL(38,10), integervalue BIGINT, meta json, textvalue TEXT, property_id INTEGER NOT NULL, user_id INTEGER NOT NULL, PRIMARY KEY (id))",
"ALTER TABLE event_userproperties ADD CONSTRAINT FK_event_userproperties_for_role_id FOREIGN KEY (for_role_id) REFERENCES roles (id)",
"ALTER TABLE event_userproperties ADD CONSTRAINT FK_event_userproperties_event_id FOREIGN KEY (event_id) REFERENCES events (id)",
"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)"
});
} }
public BootstrapBean() { public BootstrapBean() {
} }
......
/*
* 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.beans;
import fi.codecrew.moya.facade.EventUserpropertyFacade;
import fi.codecrew.moya.facade.UserEventUserpropertyFacade;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.EventUserproperty;
import fi.codecrew.moya.model.UsersEventUserproperty;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import java.util.List;
@Stateless
@LocalBean
public class UserPropertyBean implements UserPropertyBeanLocal {
@EJB
private EventUserpropertyFacade eventPropertyFacade;
@EJB
private UserEventUserpropertyFacade userPropertyFacade;
@EJB
private PermissionBean permbean;
public UserPropertyBean() {
}
@Override
public List<EventUserproperty> getPropertiesForUser(EventUser user){
return eventPropertyFacade.findForUser(user);
}
@Override
public List<UsersEventUserproperty> getUserPropertiesForUser(EventUser user){
return userPropertyFacade.findForUser(user);
}
}
/*
* 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.beans.UserBean;
import fi.codecrew.moya.model.*;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Root;
import java.util.List;
@Stateless
@LocalBean
public class EventUserpropertyFacade extends IntegerPkGenericFacade<EventUserproperty> {
public EventUserpropertyFacade() {
super(EventUserproperty.class);
}
@EJB
private UserBean userbean;
public List<EventUserproperty> findForUser(EventUser user) {
CriteriaBuilder cq = getEm().getCriteriaBuilder();
CriteriaQuery<EventUserproperty> cb = cq.createQuery(EventUserproperty.class);
Root<EventUserproperty> root = cb.from(EventUserproperty.class);
Path<Role> rolePath = root.get(EventUserproperty_.forRole);
cb.where(
cq.equal(root.get(EventUserproperty_.event), user.getEvent()),
cq.or(cq.isNull(rolePath), rolePath.in(userbean.localFindUsersRoles(user)))
);
return getEm().createQuery(cb).getResultList();
}
}
/*
* 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.Path;
import javax.persistence.criteria.Root;
import java.util.List;
@Stateless
@LocalBean
public class UserEventUserpropertyFacade extends IntegerPkGenericFacade<UsersEventUserproperty> {
public UserEventUserpropertyFacade() {
super(UsersEventUserproperty.class);
}
public List<UsersEventUserproperty> findForUser(EventUser user) {
CriteriaBuilder cq = getEm().getCriteriaBuilder();
CriteriaQuery<UsersEventUserproperty> cb = cq.createQuery(UsersEventUserproperty.class);
Root<UsersEventUserproperty> root = cb.from(UsersEventUserproperty.class);
cb.where(
cq.equal(root.get(UsersEventUserproperty_.user), user)
);
return getEm().createQuery(cb).getResultList();
}
}
/*
* 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.model;
import javax.persistence.*;
@Entity
@Table(name = "event_userproperties")
public class EventUserproperty extends GenericEntity {
public enum PropertyType {
STRING, INTEGER, DECIMAL, IMAGE, BLOB
}
@ManyToOne(optional = false)
@JoinColumn(nullable = false, updatable = false, name = "event_id", referencedColumnName = "id")
private LanEvent event;
@Convert(converter = LanguageAwareStringConverter.class )
@Column(nullable = false, columnDefinition = "jsonb not null", name="name")
private LanguageAwareString name;
@Convert(converter = LanguageAwareStringConverter.class )
@Column(nullable = false, columnDefinition = "jsonb not null", name="description")
private LanguageAwareString description;
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private PropertyType type = PropertyType.STRING;
@ManyToOne
@JoinColumn(nullable = true, name = "for_role_id", referencedColumnName = "id")
private Role forRole;
public LanEvent getEvent() {
return event;
}
public void setEvent(LanEvent event) {
this.event = event;
}
public PropertyType getType() {
return type;
}
public void setType(PropertyType type) {
this.type = type;
}
public LanguageAwareString getName() {
return name;
}
public void setName(LanguageAwareString name) {
this.name = name;
}
public LanguageAwareString getDescription() {
return description;
}
public void setDescription(LanguageAwareString description) {
this.description = description;
}
public Role getForRole() {
return forRole;
}
public void setForRole(Role forRole) {
this.forRole = forRole;
}
}
/*
* 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.model;
import javax.persistence.*;
import java.math.BigDecimal;
import java.math.BigInteger;
@Entity
@Table(name = "users_event_userproperties")
public class UsersEventUserproperty extends GenericEntity {
@ManyToOne(optional = false)
@JoinColumn(name = "property_id", updatable = false, nullable = false)
private EventUserproperty property;
@ManyToOne(optional = false)
@JoinColumn(name = "user_id", updatable = false, nullable = false)
private EventUser user;
@Lob
@Column(name = "textvalue")
private String textvalue = "";
@Column(name = "integervalue")
private BigInteger integerValue;
@Column(name = "decimalvalue", scale = 38, precision = 10)
private BigDecimal decimalValue;
@Lob
@Column(name = "datavalue")
private byte[] dataValue;
public UsersEventUserproperty() {
super();
}
public UsersEventUserproperty(EventUserproperty prop, EventUser eventuser) {
super();
this.property = prop;
this.user = eventuser;
}
public EventUserproperty getProperty() {
return property;
}
public void setProperty(EventUserproperty property) {
this.property = property;
}
public EventUser getUser() {
return user;
}
public void setUser(EventUser user) {
this.user = user;
}
public String getTextvalue() {
return textvalue;
}
public void setTextvalue(String textvalue) {
this.textvalue = textvalue;
}
public BigInteger getIntegerValue() {
return integerValue;
}
public void setIntegerValue(BigInteger integerValue) {
this.integerValue = integerValue;
}
public BigDecimal getDecimalValue() {
return decimalValue;
}
public void setDecimalValue(BigDecimal decimalValue) {
this.decimalValue = decimalValue;
}
public byte[] getDataValue() {
return dataValue;
}
public void setDataValue(byte[] dataValue) {
this.dataValue = dataValue;
}
}
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
</composite:interface> </composite:interface>
<composite:implementation> <composite:implementation>
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
<p:panelGrid columns="2" columnClasses="topalign,topalign,topalign" styleClass="noBorders user_profile_page"> <p:panelGrid columns="2" columnClasses="topalign,topalign,topalign" styleClass="noBorders user_profile_page">
<h:form id="userform" enctype="multipart/form-data"> <h:form id="userform" enctype="multipart/form-data">
...@@ -166,6 +165,31 @@ ...@@ -166,6 +165,31 @@
</p:panelGrid> </p:panelGrid>
<p:fieldset toggleable="true" collapsed="true" legend="#{i18n['user.eventproperties']}">
<h:form id="eventpropertyview">
<p:growl id="msgs" showDetail="true"/>
<p:dataTable id="userpropertytable" value="#{userEventPropertyView.properties}" var="property" editable="true">
<p:ajax event="rowEdit" listener="#{userEventPropertyView.onRowEdit}" update="@form:msgs"/>
<p:ajax event="rowEditCancel" listener="#{userEventPropertyView.onRowCancel}" update="@form:msgs"/>
<p:column><h:outputText value="#{property.property.name.getValue(sessionStore.language)}" title="#{property.property.description.getValue(sessionStore.language)}"/></p:column>
<p:column>
<!--p:ajax event="save" listener="#{userEventPropertyView.saveProperty}" update="userpropertytable">
<f:setPropertyActionListener value="#{property}" target="#{userEventPropertyView.selectedProperty}"/>
</p:ajax-->
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{property.textvalue}"/></f:facet>
<f:facet name="input"><p:inputText value="#{property.textvalue}" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor/>
</p:column>
</p:dataTable>
</h:form>
</p:fieldset>
<p:fieldset toggleable="true" collapsed="true" legend="#{i18n['user.allergies']}"> <p:fieldset toggleable="true" collapsed="true" legend="#{i18n['user.allergies']}">
<h:form id="userAllergies"> <h:form id="userAllergies">
<p:dataTable value="#{userAllergyView.allergies}" var="allergy"> <p:dataTable value="#{userAllergyView.allergies}" var="allergy">
...@@ -178,18 +202,18 @@ ...@@ -178,18 +202,18 @@
</h:form> </h:form>
</p:fieldset> </p:fieldset>
<h:form id="userSelectableRoles"> <h:form id="userSelectableRoles">
<p:fieldset legend="#{i18n['user.userSelectableRoles']}" rendered="#{userView.showUserSelectableRoles and cc.attrs.showRoles}"> <p:fieldset legend="#{i18n['user.userSelectableRoles']}" rendered="#{userView.showUserSelectableRoles and cc.attrs.showRoles}">
<p:panelGrid columns="2" styleClass="noBorders"> <p:panelGrid columns="2" styleClass="noBorders">
<p:selectManyCheckbox converter="#{roleConverter}" layout="pageDirection" value="#{userView.userSelectableRoles}"> <p:selectManyCheckbox converter="#{roleConverter}" layout="pageDirection" value="#{userView.userSelectableRoles}">
<f:selectItems value="#{roleDataView.userSelectableRoles}" var="roleitem" itemLabel="#{roleitem.name}" itemValue="#{roleitem}" /> <f:selectItems value="#{roleDataView.userSelectableRoles}" var="roleitem" itemLabel="#{roleitem.name}" itemValue="#{roleitem}"/>
</p:selectManyCheckbox> </p:selectManyCheckbox>
</p:panelGrid> </p:panelGrid>
<p:commandButton update="userSelectableRoles" actionListener="#{userView.saveUserSelectableRoles}" value="#{i18n['user.saveUserSelectableRoles']}" /> <p:commandButton update="userSelectableRoles" actionListener="#{userView.saveUserSelectableRoles}" value="#{i18n['user.saveUserSelectableRoles']}"/>
<br /><h:outputText rendered="#{userView.saveSuccess}" styleClass="success" value="#{i18n['user.saveSuccessfull']}" /> <br/>
</p:fieldset> <h:outputText rendered="#{userView.saveSuccess}" styleClass="success" value="#{i18n['user.saveSuccessfull']}"/>
</h:form> </p:fieldset>
</h:form>
</composite:implementation> </composite:implementation>
......
/*
* 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.web.cdiview.user;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.beans.UserPropertyBeanLocal;
import fi.codecrew.moya.model.*;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import org.primefaces.event.RowEditEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;
import java.util.stream.Collectors;
@Named()
@ConversationScoped
public class UserEventPropertyView extends GenericCDIView {
private static final Logger logger = LoggerFactory.getLogger(UserEventPropertyView.class);
@Inject
private UserView userview;
@EJB
private UserBeanLocal userbean;
@EJB
private UserPropertyBeanLocal propBean;
private List<UsersEventUserproperty> properties;
private UsersEventUserproperty selectedProperty;
public void saveProperty(){
logger.warn("Selected property {}, value: {}",selectedProperty, selectedProperty != null ? selectedProperty.getTextvalue():"NULL");
}
public List<UsersEventUserproperty> getProperties() {
if (properties == null) {
EventUser selectedUser = userview.getSelectedUser();
List<UsersEventUserproperty> userprops = propBean.getUserPropertiesForUser(userview.getSelectedUser());
properties = propBean.getPropertiesForUser(userview.getSelectedUser())
.stream()
.map(prop -> userprops.stream()
.filter(usrProp -> usrProp.getProperty().equals(prop))
.findFirst()
.orElse(new UsersEventUserproperty(prop, selectedUser)))
.collect(Collectors.toList());
}
logger.warn("UserEventProperties: ", properties);
return properties;
}
public void onRowEdit(RowEditEvent event) {
logger.warn("onRowEdit, {} {}", event, event.getObject());
FacesMessage msg = new FacesMessage("Car Edited");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowCancel(RowEditEvent event) {
logger.warn("Cancel Event {}, {}", event, event.getObject());
FacesMessage msg = new FacesMessage("Edit Cancelled");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!