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;
}
......@@ -126,10 +131,10 @@ public class EntityGQLBuilder<T> {
return GraphQLUtils.GRAPHQL_DATE_TYPE;
}
return parent.typeFor(type);
}
}
@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);
}
......
/*
* 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.
*
*
* 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.
*
*/
/*
......@@ -47,7 +47,6 @@ import fi.codecrew.moya.model.LanEventProperty;
import fi.codecrew.moya.model.LanEventPropertyKey;
/**
*
* @author tuukka
*/
@Named()
......@@ -85,15 +84,15 @@ public class SessionHandler {
retStr = ret.toLanguageTag();
}
if(retStr.trim().equals(""))
if (retStr.trim().equals(""))
retStr = "fi_FI";
return retStr;
}
public String getTheme() {
if(theme == null) {
if (theme == null) {
theme = eventbean.getCurrentEvent().getTheme();
}
if (theme == null || theme.trim().isEmpty()) {
......@@ -102,16 +101,16 @@ public class SessionHandler {
}
return theme;
}
public void setTheme(String theme) {
logger.debug("Setting theme to: "+theme);
logger.debug("Setting theme to: " + theme);
}
public String getFullscreen() {
template = "fullprimelayout";
return getTemplate();
}
public String getInfoscreen() {
template = "infoview";
return template;
......@@ -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);
}
......
/*
* 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.
*
*
* 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;
......@@ -78,7 +78,7 @@ import fi.codecrew.moya.web.helper.LayoutView;
public class UserView extends GenericCDIView {
/**
*
*
*/
private static final Logger logger = LoggerFactory.getLogger(UserView.class);
private static final long serialVersionUID = 7724348195373468017L;
......@@ -90,21 +90,21 @@ public class UserView extends GenericCDIView {
public int tabIdx(String name) {
switch (name) {
case "edit":
return 0;
case "shop":
return 1;
case "accountevents":
return 2;
case "groups":
return 3;
case "picture":
return 4;
case "foodwave":
return 5;
default:
case "edit":
return 0;
case "shop":
return 1;
case "accountevents":
return 2;
case "groups":
return 3;
case "picture":
return 4;
case "foodwave":
return 5;
default:
}
return 0;
}
......@@ -174,7 +174,7 @@ public class UserView extends GenericCDIView {
/**
* This is the user that is currently logged in.
*
*
* @return
*/
@Produces
......@@ -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()});
}
......@@ -207,7 +207,7 @@ public class UserView extends GenericCDIView {
/**
* This is the user we are currently editing, if that is not found we use
* current user
*
*
* @return
*/
@Produces
......@@ -260,11 +260,11 @@ public class UserView extends GenericCDIView {
logger.info("Cropped image {}x{}", croppedImage.getLeft(), croppedImage.getTop());
logger.info("Cropped data bytesize {}, type {}", croppedImage.getBytes().length,
croppedImage.getOriginalFilename());
croppedImage.getOriginalFilename());
try {
UserImage newImage = userbean.saveCroppedImage(user.getUser().getCurrentImage(), croppedImage.getLeft(),
croppedImage.getTop(), croppedImage.getWidth(), croppedImage.getHeight());
croppedImage.getTop(), croppedImage.getWidth(), croppedImage.getHeight());
user = userbean.getEventUser(newImage.getUser(), false);
} catch (IOException e) {
......@@ -279,7 +279,7 @@ public class UserView extends GenericCDIView {
mpr = cardPrintBean.getUserCardAsPrintablePdf(getSelectedUser().getId());
ByteArrayInputStream pdfstream = new ByteArrayInputStream(mpr.getPdf());
setStreamedFile(new DefaultStreamedContent(pdfstream, "application/pdf",
"user_" + getSelectedUser().getId() + "_card.pdf"));
"user_" + getSelectedUser().getId() + "_card.pdf"));
logger.info("user_" + getSelectedUser().getId() + "_card.pdf");
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
......@@ -311,7 +311,7 @@ public class UserView extends GenericCDIView {
} else {
UserImage userimage = userbean.uploadImage(user, getImage().getContentType(), getImage().getInputstream(),
getImage().getFileName(), "");
getImage().getFileName(), "");
user = userbean.getEventUser(userimage.getUser(), false);
super.addFaceMessage("user.imageUploaded");
}
......@@ -409,7 +409,7 @@ public class UserView extends GenericCDIView {
/**
* attach barcode or rfid to card
*
*
* @return
*/
public String attachCodeToCard() {
......@@ -497,7 +497,7 @@ public class UserView extends GenericCDIView {
/**
* This is user what is currently on "user" -variable, you should almost
* newer use this. Use getCurrentUser() -instead.
*
*
* @return
*/
public EventUser getUser() {
......@@ -635,9 +635,14 @@ 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.
*
*
* @return
*/
public String getMeta() {
......@@ -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) {
return meta.toString();
}
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 "";
}
......
......@@ -1900,4 +1900,6 @@ placegroupview.count=Kpl
user.allergies=Allergiat / ruokavaliot
allergies.save=Tallenna allergiat
\ No newline at end of file
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!