Commit 2b19d7ba by Tuomas Riihimäki

User preference fixes

1 parent db4acc8b
......@@ -13,4 +13,7 @@ public interface UserPropertyBeanLocal {
List<EventUserproperty> getPropertiesForUser(EventUser user);
List<UsersEventUserproperty> getUserPropertiesForUser(EventUser user);
UsersEventUserproperty saveUserproperty(UsersEventUserproperty object);
}
......@@ -29,12 +29,7 @@ import java.math.BigDecimal;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.PermitAll;
......@@ -233,7 +228,9 @@ public class UserBean implements UserBeanLocal {
throw new EJBAccessException("Not enough rights to find roles");
}
return new ArrayList<Role>(localFindUsersRoles(u));
ArrayList<Role> ret = new ArrayList<>(localFindUsersRoles(u));
ret.sort((o1, o2) -> o1.getId().compareTo(o2.getId()));
return ret;
}
......
......@@ -45,14 +45,29 @@ public class UserPropertyBean implements UserPropertyBeanLocal {
}
@Override
public List<EventUserproperty> getPropertiesForUser(EventUser user){
public List<EventUserproperty> getPropertiesForUser(EventUser user) {
return eventPropertyFacade.findForUser(user);
}
@Override
public List<UsersEventUserproperty> getUserPropertiesForUser(EventUser user){
public List<UsersEventUserproperty> getUserPropertiesForUser(EventUser user) {
return userPropertyFacade.findForUser(user);
}
@Override
public UsersEventUserproperty saveUserproperty(UsersEventUserproperty prop) {
if (prop == null) {
return null;
}
if (prop.getId() == null) {
userPropertyFacade.create(prop);
} else {
prop = userPropertyFacade.merge(prop);
}
return prop;
}
}
......@@ -199,7 +199,7 @@ public class EventUserFacade extends IntegerPkGenericFacade<EventUser> {
listQ.setFirstResult(query.getPage() * query.getPagesize());
listQ.setMaxResults(query.getPagesize());
}
return new SearchResult<EventUser>(listQ.getResultList(), countQ.getSingleResult());
return new SearchResult<>(listQ.getResultList(), countQ.getSingleResult());
}
......
......@@ -28,7 +28,9 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Root;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@Stateless
@LocalBean
......@@ -45,11 +47,14 @@ public class EventUserpropertyFacade extends IntegerPkGenericFacade<EventUserpro
CriteriaBuilder cq = getEm().getCriteriaBuilder();
CriteriaQuery<EventUserproperty> cb = cq.createQuery(EventUserproperty.class);
Root<EventUserproperty> root = cb.from(EventUserproperty.class);
Set<Role> roles = userbean.localFindUsersRoles(user);
if(roles == null || roles.isEmpty()){
return Collections.emptyList();
}
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)))
cq.or(cq.isNull(rolePath), rolePath.in(roles))
);
return getEm().createQuery(cb).getResultList();
......
......@@ -157,18 +157,16 @@
</p:fieldset>
</h:form>
<p:fieldset legend="#{i18n['user.meta.box.title']}" toggleable="true" collapsed="true" rendered="#{not empty userView.meta}">
<p:fieldset legend="#{i18n['user.meta.box.title']}" toggleable="true" collapsed="true" rendered="#{userView.metaAvailable}">
<div id="usermetaview"><pre><h:outputText value="#{userView.prettyMeta}" /></pre></div>
</p:fieldset>
</p:panelGrid>
<p:fieldset toggleable="true" collapsed="true" legend="#{i18n['user.eventproperties']}">
<p:fieldset toggleable="true" collapsed="true" legend="#{i18n['user.eventproperties']}" rendered="${!empty userEventPropertyView.properties}" style="max-width: 800px;">
<h:form id="eventpropertyview">
<p:growl id="msgs" showDetail="true"/>
<p:dataTable id="userpropertytable" value="#{userEventPropertyView.properties}" var="property" editable="true">
<p:dataTable id="userpropertytable" widgetVar="userpropertytable" value="#{userEventPropertyView.properties}" var="property" editable="true" rowIndexVar="rowIndex">
<p:ajax event="rowEdit" listener="#{userEventPropertyView.onRowEdit}" update="@form:msgs"/>
<p:ajax event="rowEditCancel" listener="#{userEventPropertyView.onRowCancel}" update="@form:msgs"/>
......@@ -180,11 +178,14 @@
</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>
<f:facet name="input"><p:inputText onkeydown="PF('userpropertytable').onKeyDown(event)"
onkeyup="PF('userpropertytable').onKeyUp(event, #{rowIndex})"
value="#{property.textvalue}"
style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor/>
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
......@@ -216,6 +217,40 @@
</h:form>
<script type="text/javascript">
$(function() {
$.extend(PF("userpropertytable"), {
onKeyDown : function(e) {
var key = e.which,
keyCode = $.ui.keyCode;
if((key === keyCode.ENTER||key === keyCode.NUMPAD_ENTER)) {
e.preventDefault();
}
},
onKeyUp : function(e, rowIndex) {
var key = e.which,
keyCode = $.ui.keyCode;
if((key === keyCode.ENTER||key === keyCode.NUMPAD_ENTER)) {
this.tbody
.find('.ui-row-editor .ui-icon-check')
.eq(rowIndex)
.click();
}
if (key === keyCode.ESCAPE) {
this.tbody
.find('.ui-row-editor .ui-icon-close')
.eq(rowIndex)
.click();
}
}
});
});
</script>
</composite:implementation>
</html>
......@@ -180,7 +180,7 @@ public class HostnameFilter implements Filter {
if (httpRequest.getUserPrincipal() == null) {
// Check if we are can login in with rest alternative methods ( appkey, basic auth, etc.. )
if (RestApplicationEntrypoint.REST_PATH.equals(httpRequest.getServletPath())
|| "/dydata".equals(httpRequest.getServletPath())) {
|| "/dydata".equals(httpRequest.getServletPath()) || "/graphql".equals(httpRequest.getServletPath())) {
authtype = AuthType.REST;
......
......@@ -10,16 +10,13 @@ import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.*;
import static graphql.Scalars.*;
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
import static graphql.schema.GraphQLObjectType.newObject;
public class EntityGQLBuilder<T> {
public class EntityGQLBuilder<T> implements GQLEntityContainer {
private final GraphQLObjectType.Builder builder;
......@@ -35,6 +32,12 @@ public class EntityGQLBuilder<T> {
}
public GraphQLFieldDefinition.Builder addField(GraphQLOutputType type) {
return addField()
.type(type)
.name(type.getName().toLowerCase());
}
public GraphQLFieldDefinition.Builder addField() {
if (builtObject != null) {
throw new AlreadyBuiltException("This method can not be called after 'build()'-function has been called");
......@@ -79,9 +82,11 @@ public class EntityGQLBuilder<T> {
}
private GraphQLOutputType typeForClass(Class<?> type) {
if (Map.Entry.class.isAssignableFrom(type)) {
return parent.getMapEntryType();
}
if (Boolean.class.isAssignableFrom(type) || boolean.class.isAssignableFrom(type)) {
return GraphQLBoolean;
}
......@@ -129,7 +134,7 @@ public class EntityGQLBuilder<T> {
}
@Override
public GraphQLObjectType build() {
if (builtObject == null) {
fields.forEach(f -> builder.field(f));
......@@ -148,7 +153,9 @@ public class EntityGQLBuilder<T> {
return this;
}
public GraphQLType getRef() {
public GraphQLTypeReference getRef() {
return parent.typeFor(typeName);
}
}
package fi.codecrew.moya.graphql;
import graphql.schema.GraphQLObjectType;
public interface GQLEntityContainer {
GraphQLObjectType build();
}
......@@ -7,10 +7,13 @@ import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.stream.Collectors;
import static graphql.Scalars.GraphQLString;
import static graphql.schema.GraphQLEnumType.newEnum;
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
import static graphql.schema.GraphQLObjectType.newObject;
public class GraphQLBuilder {
private final Map<String, EntityGQLBuilder<?>> entities = new HashMap<>();
private final Map<String, GQLEntityContainer> entities = new HashMap<>();
private final Map<String, GraphQLEnumType> enums = new HashMap<>();
private final Set<String> uncheckedTypes = new HashSet<>();
private static final Logger logger = LoggerFactory.getLogger(GraphQLBuilder.class);
......@@ -25,6 +28,24 @@ public class GraphQLBuilder {
return ret;
}
public GraphQLList getMapEntryType() {
if (!entities.containsKey("MapEntry")) {
entities.put("MapEntry", new GQLEntityContainer() {
@Override
public GraphQLObjectType build() {
return type.build();
}
final GraphQLObjectType.Builder type = newObject()
.name("MapEntry")
.field(newFieldDefinition().name("key").type(GraphQLString))
.field(newFieldDefinition().name("value").type(GraphQLString));
}
);
}
return GraphQLList.list(typeFor("MapEntry"));
}
public Set<GraphQLType> getTypes() {
Set<GraphQLType> ret = new HashSet<>(enums.values());
List<GraphQLObjectType> retEnt = entities.values().stream().map(v -> v.build()).collect(Collectors.toList());
......@@ -38,7 +59,7 @@ public class GraphQLBuilder {
public GraphQLTypeReference typeFor(String typeName) {
logger.warn("Adding typeFor: {}", typeName);
if (!entities.containsKey(typeName) && !enums.containsKey(typeName)) {
logger.warn("Adding unknown type: this might be an error!"+ typeName, new RuntimeException().fillInStackTrace());
logger.warn("Adding unknown type: this might be an error!" + typeName, new RuntimeException().fillInStackTrace());
uncheckedTypes.add(typeName);
}
......
......@@ -47,7 +47,6 @@ import fi.codecrew.moya.model.LanEventProperty;
import fi.codecrew.moya.model.LanEventPropertyKey;
/**
*
* @author tuukka
*/
@Named()
......@@ -85,7 +84,7 @@ public class SessionHandler {
retStr = ret.toLanguageTag();
}
if(retStr.trim().equals(""))
if (retStr.trim().equals(""))
retStr = "fi_FI";
return retStr;
......@@ -93,7 +92,7 @@ public class SessionHandler {
public String getTheme() {
if(theme == null) {
if (theme == null) {
theme = eventbean.getCurrentEvent().getTheme();
}
if (theme == null || theme.trim().isEmpty()) {
......@@ -104,7 +103,7 @@ public class SessionHandler {
}
public void setTheme(String theme) {
logger.debug("Setting theme to: "+theme);
logger.debug("Setting theme to: " + theme);
}
public String getFullscreen() {
......@@ -122,12 +121,11 @@ public class SessionHandler {
return template;
}
public String getTemplateName()
{
public String getTemplateName() {
if (template == null) {
template = eventbean.getPropertyString(LanEventPropertyKey.EVENT_LAYOUT);
}
if(template != null){
if (template != null) {
template = template.trim().toLowerCase();
}
......@@ -137,8 +135,7 @@ public class SessionHandler {
return template;
}
public String getTemplatePath()
{
public String getTemplatePath() {
return "/resources/templates/" + getTemplateName();
......@@ -150,8 +147,7 @@ public class SessionHandler {
private EnumMap<LanEventPropertyKey, Boolean> boolPropertyCache = new EnumMap<>(LanEventPropertyKey.class);
public boolean isEventBoolProperty(String property)
{
public boolean isEventBoolProperty(String property) {
LanEventPropertyKey prop = LanEventPropertyKey.valueOf(property);
if (!prop.isBoolean()) {
throw new RuntimeException("Trying to fetch boolean value for non-boolean property!");
......@@ -206,18 +202,15 @@ public class SessionHandler {
// return permbean.hasPermission(perm);
// }
public String getDateFormat()
{
public String getDateFormat() {
return "dd.MM.yyyy";
}
public String getDatetimeFormat()
{
public String getDatetimeFormat() {
return "dd.MM.yyyy HH:mm";
}
public String getShortDatetimeFormat()
{
public String getShortDatetimeFormat() {
return "dd.MM HH:MM:ss";
}
......@@ -247,7 +240,8 @@ public class SessionHandler {
}
public String flushCache() {
return eventbean.flushCache();
eventbean.flushCache();
return "";
}
......@@ -257,13 +251,10 @@ public class SessionHandler {
private String preurlString;
public String getRequestPreUrl()
{
if (preurlString == null)
{
public String getRequestPreUrl() {
if (preurlString == null) {
Object ext = FacesContext.getCurrentInstance().getExternalContext().getRequest();
if (ext instanceof HttpServletRequest)
{
if (ext instanceof HttpServletRequest) {
StringBuffer url = ((HttpServletRequest) ext).getRequestURL();
preurlString = url.substring(0, url.indexOf("/", 8));
......
......@@ -98,7 +98,7 @@ public class UserAllergyView extends GenericCDIView {
this.freetext = freetext;
}
public void saveAllergies() {
if(freetext != null && !freetext.isEmpty()) {
if(freetext != null) {
EventUser usr = userview.getSelectedUser();
usr.getUser().setMetaStringValue(ALLERGIES_METAKEY, freetext);
userview.saveUser();
......
......@@ -52,12 +52,13 @@ public class UserEventPropertyView extends GenericCDIView {
private List<UsersEventUserproperty> properties;
private UsersEventUserproperty selectedProperty;
public void saveProperty(){
logger.warn("Selected property {}, value: {}",selectedProperty, selectedProperty != null ? selectedProperty.getTextvalue():"NULL");
public void saveProperty() {
logger.warn("Selected property {}, value: {}", selectedProperty, selectedProperty != null ? selectedProperty.getTextvalue() : "NULL");
}
public List<UsersEventUserproperty> getProperties() {
if (properties == null) {
super.beginConversation();
EventUser selectedUser = userview.getSelectedUser();
List<UsersEventUserproperty> userprops = propBean.getUserPropertiesForUser(userview.getSelectedUser());
......@@ -75,13 +76,18 @@ public class UserEventPropertyView extends GenericCDIView {
}
public void onRowEdit(RowEditEvent event) {
logger.warn("onRowEdit, {} {}", event, event.getObject());
FacesMessage msg = new FacesMessage("Car Edited");
final UsersEventUserproperty oldObj = (UsersEventUserproperty) event.getObject();
int objPoint = properties.indexOf(oldObj);
UsersEventUserproperty newObj = propBean.saveUserproperty(oldObj);
properties.set(objPoint, newObj);
FacesMessage msg = new FacesMessage("Property saved");
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);
}
......
......@@ -189,7 +189,7 @@ public class UserView extends GenericCDIView {
FacesContext.getCurrentInstance().addMessage(null, msg);
UploadedFile f = event.getFile();
if (f != null)
logger.info("Received file {}, {}, {}", new Object[] { f.getContentType(), f.getFileName(), f.getSize() });
logger.info("Received file {}, {}, {}", new Object[]{f.getContentType(), f.getFileName(), f.getSize()});
}
......@@ -635,6 +635,11 @@ public class UserView extends GenericCDIView {
return shirtEnabled;
}
public boolean isMetaAvailable(){
JsonObject meta = getSelectedUser().getUser().getMeta();
return meta != null && !meta.isEmpty();
}
/**
* Get metadata from the User (not EventUser). The data is shown in ui.
*
......@@ -646,19 +651,17 @@ public class UserView extends GenericCDIView {
User user = eventUser.getUser();
if (user != null) {
JsonObject meta = user.getMeta();
if (meta != null) {
if (meta.keySet().size() > 0) {
if (meta != null && !meta.isEmpty()) {
return meta.toString();
}
}
}
}
return "";
}
public String getPrettyMeta(){
public String getPrettyMeta() {
JsonObject meta = getSelectedUser().getUser().getMeta();
if(meta == null){
if (meta == null) {
return "";
}
......
......@@ -597,7 +597,7 @@ incomingflow.giveplace = Mark given
incomingflow.groupmemberships = Computer places and tickets
incomingflow.invalidbarcode.message = Nothing found with the barcode, you can now add it to the user
incomingflow.invalidbarcode.title = Invalid code
incomingflow.markEverythingGiven=Give all ungiven tickets
incomingflow.markEverythingGiven =Give all ungiven tickets
incomingflow.multisearch = Multisearch
incomingflow.placesummary = Place summary
incomingflow.printedCard = Card
......@@ -608,6 +608,7 @@ incomingflow.usereditor = User
incomingflow.usereditor.info = User
incomingflow.usereditor.picture = New picture
index.title = Frontpage
infoview.back = Back
infoview.computerplace = Computer places
infoview.multisearch = User search
......@@ -1873,43 +1874,45 @@ voting.create.voteEnd = Voting close
voting.create.voteStart = Voting start
yes = Yes
page.product.shopClosed.header=Shop is closed!
page.product.shopClosed.notOpenYet=Shop is not opened. Try again later.
page.product.shopClosed.alreadyClosed=Shop is closed, welcome back in next event!
queuemgmt.inDatabase=Value in database
queuemgmt.biggestFirst=Biggest group first
queuemgmt.biggestIsFirst=Bigger group automaticly rises up in queue.
reservequeue.reservingTimeIsUpAlert=Timeslot for your place reservation has timeouted. Pleace go back to queue to continue.
mapView.reserveTimeLeft=Time to reserve places
queuemgmt.queueEnabled=Queue is ENABLED
queuemgmt.queueDisabled=Queue is DISABLED (enable from Edit event -page)
product.dependency.add=Add product dependency
product.dependency.create=Create
product.dependency.supporter=Depended product
product.dependency.type=Dependency type
product.dependency.priority=Priority
product.dependency.delete=Delete
product.dependency.multiplier=Multiplier
product.dependency.MAX_SUPPORTED_COUNT=Only up to same number of products can be bought
placemove.alreadyTaken=Moving the places was cancelled because place {0} was already taken.
placegroupview.moveUsersPlaces=Move users places
submenu.neomap.moveplaces=Change places
mapEdit.removeSelectedPlaces=Delete places
page.product.shopClosed.header =Shop is closed!
page.product.shopClosed.notOpenYet =Shop is not opened. Try again later.
page.product.shopClosed.alreadyClosed =Shop is closed, welcome back in next event!
queuemgmt.inDatabase =Value in database
queuemgmt.biggestFirst =Biggest group first
queuemgmt.biggestIsFirst =Bigger group automaticly rises up in queue.
reservequeue.reservingTimeIsUpAlert =Timeslot for your place reservation has timeouted. Pleace go back to queue to continue.
mapView.reserveTimeLeft =Time to reserve places
queuemgmt.queueEnabled =Queue is ENABLED
queuemgmt.queueDisabled =Queue is DISABLED (enable from Edit event -page)
product.dependency.add =Add product dependency
product.dependency.create =Create
product.dependency.supporter =Depended product
product.dependency.type =Dependency type
product.dependency.priority =Priority
product.dependency.delete =Delete
product.dependency.multiplier =Multiplier
product.dependency.MAX_SUPPORTED_COUNT =Only up to same number of products can be bought
placemove.alreadyTaken =Moving the places was cancelled because place {0} was already taken.
placegroupview.moveUsersPlaces =Move users places
submenu.neomap.moveplaces =Change places
mapEdit.removeSelectedPlaces =Delete places
bortalApplication.map.MOVE_PLACES = Selfservice place moving
bill.list.header = Orders
placemove.noMovablePlaces = No movable places
deliver=Deliver
placegroupview.noProductsToDeliver=No deliverable products
placegroupview.productName=Product name
incomingflow.giveAccountEvent=Mark given
incomingflow.ungiveAccountEvent=Mark not given
incomingflow.deliverableProducts=Products to deliver
placegroupview.accountEventDescription=Description
incomingflow.ungivenProducts=User has ungiven deliverable products
placegroupview.count=Count
user.allergies=Allergies / diets
allergies.save=Save allergies
\ No newline at end of file
deliver =Deliver
placegroupview.noProductsToDeliver =No deliverable products
placegroupview.productName =Product name
incomingflow.giveAccountEvent =Mark given
incomingflow.ungiveAccountEvent =Mark not given
incomingflow.deliverableProducts =Products to deliver
placegroupview.accountEventDescription =Description
incomingflow.ungivenProducts =User has ungiven deliverable products
placegroupview.count =Count
user.allergies =Allergies / diets
allergies.save =Save allergies
user.eventproperties = Event specific properties
submenu.permissionDenied = Access denied
\ No newline at end of file
......@@ -1901,3 +1901,5 @@ placegroupview.count=Kpl
user.allergies=Allergiat / ruokavaliot
allergies.save=Tallenna allergiat
user.eventproperties = Tapahtumakohtaiset tiedot
submenu.permissionDenied = Pääsy kielletty
\ 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!