Commit ce205efe by Tuukka Kivilahti

Merge branch 'user-preferences' into 'master'

Add allergies to user preferences

See merge request !405
2 parents 14334dff 5f895d68
Showing with 720 additions and 51 deletions
package fi.codecrew.moya.beans;
import fi.codecrew.moya.model.Allergy;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.UsersAllergy;
import javax.ejb.Local;
import java.util.ArrayList;
import java.util.List;
@Local
public interface AllergyBeanLocal {
List<Allergy> getAllergies();
List<UsersAllergy> getUserAllergies(EventUser currentUser);
List<UsersAllergy> saveAllergies(ArrayList<UsersAllergy> allergylist);
}
package fi.codecrew.moya.beans;
import fi.codecrew.moya.facade.AllergyFacade;
import fi.codecrew.moya.facade.UsersAllergyFacade;
import fi.codecrew.moya.model.Allergy;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.UsersAllergy;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import java.util.ArrayList;
import java.util.List;
@Stateless
@LocalBean
public class AllergyBean implements AllergyBeanLocal {
@EJB
private AllergyFacade allergyFacade;
@EJB
private UsersAllergyFacade userAllergyFacade;
@Override
public List<Allergy> getAllergies() {
return allergyFacade.findAll();
}
@Override
public List<UsersAllergy> getUserAllergies(EventUser user) {
return userAllergyFacade.findForUser(user);
}
@Override
public List<UsersAllergy> saveAllergies(ArrayList<UsersAllergy> allergylist) {
ArrayList<UsersAllergy> ret = new ArrayList<>();
for (UsersAllergy a : allergylist) {
if (a.getId() == null) {
userAllergyFacade.create(a);
ret.add(a);
} else {
ret.add(userAllergyFacade.merge(a));
}
}
return ret;
}
}
......@@ -436,16 +436,19 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE product_dependencies ADD CONSTRAINT FK_product_dependencies_dependant_id FOREIGN KEY (dependant_id) REFERENCES products (id)",
"ALTER TABLE product_dependencies ADD CONSTRAINT FK_product_dependencies_supporter_id FOREIGN KEY (supporter_id) REFERENCES products (id)",
});
dbUpdates.add(new String[]{
"ALTER TABLE account_events DROP COLUMN delivered_count;"
});
dbUpdates.add(new String[] {
"ALTER TABLE users ADD COLUMN locale TEXT DEFAULT NULL;"
});
dbUpdates.add(new String[]{
"CREATE TABLE user_allergies (id SERIAL NOT NULL, created TIMESTAMPTZ, meta json, notes TEXT, selected BOOLEAN NOT NULL, severity TEXT, allergy_id serial, user_id serial, PRIMARY KEY (id))",
"CREATE TABLE allergies (id SERIAL NOT NULL, allergy_type TEXT NOT NULL, description jsonb, meta json, name jsonb, PRIMARY KEY (id))",
"ALTER TABLE user_allergies ADD CONSTRAINT FK_user_allergies_user_id FOREIGN KEY (user_id) REFERENCES users (id)",
"ALTER TABLE user_allergies ADD CONSTRAINT FK_user_allergies_allergy_id FOREIGN KEY (allergy_id) REFERENCES allergies (id)"
});
}
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.facade;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.*;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Root;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Stateless
@LocalBean
public class AllergyFacade extends IntegerPkGenericFacade<Allergy> {
public AllergyFacade() {
super(Allergy.class);
}
public List<Allergy> findAll() {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Allergy> cq = cb.createQuery(Allergy.class);
Root<Allergy> root = cq.from(Allergy.class);
cq.orderBy(cb.desc(root.get(Allergy_.id)));
TypedQuery<Allergy> q = getEm().createQuery(cq);
return q.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.Allergy;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.UsersAllergy;
import fi.codecrew.moya.model.UsersAllergy_;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.util.List;
@Stateless
@LocalBean
public class UsersAllergyFacade extends IntegerPkGenericFacade<UsersAllergy> {
public UsersAllergyFacade() {
super(UsersAllergy.class);
}
public List<UsersAllergy> findForUser(EventUser user) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<UsersAllergy> cq = cb.createQuery(UsersAllergy.class);
Root<UsersAllergy> root = cq.from(UsersAllergy.class);
cq.where(cb.equal(root.get(UsersAllergy_.user), user.getUser()));
return getEm().createQuery(cq).getResultList();
}
}
package fi.codecrew.moya.model;
import javax.persistence.*;
@Table(name="allergies")
@Entity
public class Allergy extends GenericEntity {
public enum AllergyType {
FOOD, ANIMAL, DIET
}
@Column(nullable = false, name="allergy_type")
@Enumerated(EnumType.STRING)
private AllergyType allergyType;
@Convert(converter = LanguageAwareStringConverter.class )
@Column(nullable = false, columnDefinition = "jsonb", name="name")
private LanguageAwareString name = new LanguageAwareString();
@Convert(converter = LanguageAwareStringConverter.class )
@Column(nullable = false, columnDefinition = "jsonb", name="description")
private LanguageAwareString description = new LanguageAwareString() ;
public AllergyType getAllergyType() {
return allergyType;
}
public void setAllergyType(AllergyType allergyType) {
this.allergyType = allergyType;
}
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;
}
}
package fi.codecrew.moya.model;
public enum AllergySeverity {
PREFERENCE, MILD, NORMAL, SEVERE, DEADLY
}
......@@ -21,6 +21,7 @@ package fi.codecrew.moya.model;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.json.JsonValue;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
......@@ -66,10 +67,28 @@ public class GenericEntity extends EntityEquals implements ModelInterface, Entit
@Transient
public String getMetaStringValue(String key) {
try {
return getMeta().getString(key);
JsonObject m = getMeta();
if(m != null && m.containsKey(key)) {
return getMeta().getString(key);
}
} catch (NullPointerException e) {
// this is normal if key is not found etc.
return "";
}
return "";
}
@Transient
public void deleteMetaKey(String key){
final JsonObject m = getMeta();
if(m != null){
JsonObjectBuilder metaBuilder = Json.createObjectBuilder();
getMeta()
.entrySet()
.stream()
.filter(e->!e.getKey().equals(key))
.forEach(e -> metaBuilder.add(e.getKey(), e.getValue()));
setMeta(metaBuilder.build());
}
}
......@@ -79,15 +98,10 @@ public class GenericEntity extends EntityEquals implements ModelInterface, Entit
JsonObjectBuilder metaBuilder = Json.createObjectBuilder();
if (getMeta() != null) {
for (String valKey : getMeta().keySet()) {
if (!valKey.equals(key)) {
metaBuilder.add(valKey, getMeta().get(valKey));
}
}
getMeta().entrySet().forEach(e -> metaBuilder.add(e.getKey(), e.getValue()));
}
metaBuilder.add(key, value);
setMeta(metaBuilder.build());
}
......
package fi.codecrew.moya.model;
import java.util.HashMap;
import java.util.Map;
public class LanguageAwareString {
private String defaultLanguage;
private Map<String, String> values = new HashMap<>();
public String getValue(String language) {
if (values.isEmpty()) {
return null;
}
String ret = values.get(language);
// Fallback to default Language
if (ret == null) {
ret = values.get(defaultLanguage);
// If everything else fails, get a random entry from the map.
if (ret == null) {
ret = values.get(0);
}
}
return ret;
}
public String getDefaultLanguage() {
return defaultLanguage;
}
public void setDefaultLanguage(String defaultLanguage) {
this.defaultLanguage = defaultLanguage;
}
public Map<String, String> getValues() {
return values;
}
public void getValues(Map<String, String> values) {
this.values = values;
}
}
package fi.codecrew.moya.model;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.postgresql.util.PGobject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.io.IOException;
import java.sql.SQLException;
@Converter(autoApply = false)
public class LanguageAwareStringConverter implements AttributeConverter<LanguageAwareString, PGobject> {
private static final Logger logger = LoggerFactory.getLogger(LanguageAwareStringConverter.class);
private static final ObjectMapper mapper = new ObjectMapper();
private void test() {
LanguageAwareString foo = new LanguageAwareString();
foo.setDefaultLanguage("FI");
foo.getValues().put("FI", "Suomeksi");
foo.getValues().put("EN", "Eng");
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writerFor(LanguageAwareString.class);
try {
logger.warn("Got json", writer.writeValueAsString(foo));
} catch (JsonProcessingException e) {
logger.warn("Error in jsontest", e);
}
}
@Override
public PGobject convertToDatabaseColumn(LanguageAwareString attribute) {
test();
if (attribute == null) {
return null;
}
PGobject pgObject = null;
try {
pgObject = new PGobject();
pgObject.setType("jsonb");
ObjectWriter writer = mapper.writerFor(LanguageAwareString.class);
pgObject.setValue(writer.writeValueAsString(attribute));
} catch (SQLException | JsonProcessingException e) {
logger.warn("Error converting LanguageAwareString to PGObject", e);
throw new RuntimeException(e);
}
return pgObject;
}
@Override
public LanguageAwareString convertToEntityAttribute(PGobject dbData) {
test();
if (dbData == null || dbData.getValue() == null || dbData.getValue().toLowerCase().equals("null")) {
return null;
}
if (!dbData.getType().equals("jsonb") && !dbData.getType().equals("json")) {
throw new RuntimeException("Invalid type for LanguageAwareString from database. Expected json, got " + dbData.getType());
}
LanguageAwareString ret = null;
ObjectReader reader = mapper.readerFor(LanguageAwareString.class);
try {
ret = reader.readValue(dbData.getValue());
} catch (IOException e) {
logger.warn("Error converting PGobject to LanguageAwareString ", e);
throw new RuntimeException(e);
}
return ret;
}
}
......@@ -58,6 +58,7 @@ public class User extends GenericEntity implements IUser {
public static final String ANONYMOUS_LOGINNAME = "anonymous";
private static final long serialVersionUID = -1632200627103418206L;
private static final String SHIRT_SIZE_METAKEY = "shirtSize";
@Column(name = "created", nullable = false, updatable = false)
@Temporal(TemporalType.TIMESTAMP)
......@@ -433,12 +434,16 @@ public class User extends GenericEntity implements IUser {
@Transient
public String getShirtSize() {
return getMetaStringValue("shirtSize");
return getMetaStringValue(SHIRT_SIZE_METAKEY);
}
@Transient
public void setShirtSize(String size) {
setMetaStringValue("shirtSize", size);
if(size == null || size.isEmpty()){
deleteMetaKey(SHIRT_SIZE_METAKEY);
}else {
setMetaStringValue(SHIRT_SIZE_METAKEY, size);
}
}
public String getLocale() {
......
package fi.codecrew.moya.model;
import javax.persistence.*;
import java.util.Date;
@Table(name="user_allergies")
@Entity
public class UsersAllergy extends GenericEntity {
@Column(nullable=false, name = "selected")
private boolean selected = false;
@Enumerated(EnumType.STRING)
@Column(name="severity")
private AllergySeverity severity = AllergySeverity.NORMAL;
@ManyToOne
@JoinColumn(name="user_id", updatable = false, referencedColumnName = "id", nullable = false)
private User user;
@ManyToOne
@JoinColumn(name="allergy_id", updatable = false, referencedColumnName = "id", nullable = false)
private Allergy allergy;
@Column(name="created")
@Temporal(TemporalType.TIMESTAMP)
private Date created;
@Lob
@Column(name="notes")
private String notes;
public UsersAllergy() {
super();
}
public UsersAllergy(Allergy allergy, User user) {
this();
this.allergy = allergy;
this.user = user;
}
public AllergySeverity getSeverity() {
return severity;
}
public void setSeverity(AllergySeverity severity) {
this.severity = severity;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Allergy getAllergy() {
return allergy;
}
public void setAllergy(Allergy allergy) {
this.allergy = allergy;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}
......@@ -42,7 +42,7 @@ public class JsonAttributeConverter implements AttributeConverter<JsonObject, PG
//log.info("Converting JsonObject to PGobject. Original JsonObject: {}", jsonObject);
PGobject pgObject = new PGobject();
pgObject.setType("json");
pgObject.setType("jsonb");
try {
if (jsonObject != null) {
pgObject.setValue(jsonObject.toString());
......@@ -69,7 +69,7 @@ public class JsonAttributeConverter implements AttributeConverter<JsonObject, PG
}
// Correct type of object?
if (pgObject.getType().equals("json") == false) {
if (!pgObject.getType().equals("jsonb") && !pgObject.getType().equals("json")) {
log.error("Expected to be converting JSON column, but got PGobject whose type is not json but {}", pgObject.getType());
throw new RuntimeException("Expected JSON object from database");
}
......
......@@ -10,6 +10,8 @@
<composite:attribute name="commitaction" required="true" method-signature="java.lang.String action()" />
<composite:attribute name="camAlwaysOn" required="false" default="false" />
<composite:attribute name="showRoles" required="false" default="false" />
<composite:attribute name="commitvalue" required="false" default="Save" />
</composite:interface>
<composite:implementation>
......@@ -130,19 +132,24 @@
<p:outputLabel value="#{i18n['user.shirtSize']}" for="shirtSize" rendered="#{userView.shirtEnabled}" />
<p:selectOneMenu style="width: 200px;" disabled="#{!cc.attrs.creating and !userView.canSave}" id="shirtSize" value="#{userView.selectedUser.user.shirtSize}" rendered="#{userView.shirtEnabled}">
<f:selectItem itemLabel="#{i18n['user.shirt.select']}" itemValue="" />
<f:selectItem itemLabel="#{i18n['user.shirt.S']}" itemValue="S" />
<f:selectItem itemLabel="#{i18n['user.shirt.S']}" itemValue="S" />
<f:selectItem itemLabel="#{i18n['user.shirt.M']}" itemValue="M" />
<f:selectItem itemLabel="#{i18n['user.shirt.L']}" itemValue="L" />
<f:selectItem itemLabel="#{i18n['user.shirt.XL']}" itemValue="XL" />
<f:selectItem itemLabel="#{i18n['user.shirt.XXL']}" itemValue="XXL" />
<f:selectItem itemLabel="#{i18n['user.shirt.XXXL']}" itemValue="XXXL" />
<f:selectItem itemLabel="#{i18n['user.shirt.3XL']}" itemValue="3XL" />
<f:selectItem itemLabel="#{i18n['user.shirt.4XL']}" itemValue="4XL" />
<f:selectItem itemLabel="#{i18n['user.shirt.5XL']}" itemValue="5XL" />
<f:selectItem itemLabel="#{i18n['user.shirt.LadyXS']}" itemValue="Lady-XS" />
<f:selectItem itemLabel="#{i18n['user.shirt.LadyS']}" itemValue="Lady-S" />
<f:selectItem itemLabel="#{i18n['user.shirt.LadyM']}" itemValue="Lady-M" />
<f:selectItem itemLabel="#{i18n['user.shirt.LadyL']}" itemValue="Lady-L" />
<f:selectItem itemLabel="#{i18n['user.shirt.LadyXL']}" itemValue="Lady-XL" />
<f:selectItem itemLabel="#{i18n['user.shirt.LadyXXL']}" itemValue="Lady-XXL" />
<f:selectItem itemLabel="#{i18n['user.shirt.Lady3XL']}" itemValue="Lady-3XL" />
<f:selectItem itemLabel="#{i18n['user.shirt.Lady4XL']}" itemValue="Lady-4XL" />
<f:selectItem itemLabel="#{i18n['user.shirt.Lady5XL']}" itemValue="Lady-5XL" />
</p:selectOneMenu>
<p:message for="shirtSize" rendered="#{userView.shirtEnabled}" />
......@@ -150,27 +157,27 @@
<p:commandButton rendered="#{cc.attrs.creating or userView.canSave}" id="commitbtn" action="#{cc.attrs.commitaction}" ajax="false" value="#{cc.attrs.commitvalue}" onerror="location.reload(true);" />
</p:fieldset>
</h:form>
<ui:fragment rendered="#{not empty userView.meta}">
<h:outputScript target="head" library="script" name="jsonview.js" />
<h:outputScript target="head">
window.onload = function() {
jsonView('#usermetaview');
}
</h:outputScript>
<h:form id="usermetaform" enctype="multipart/form-data">
<p:fieldset legend="#{i18n['user.meta.box.title']}">
<p:panelGrid columns="1" cellpadding="1">
<div id="usermetaview">#{userView.meta}</div>
</p:panelGrid>
</p:fieldset>
</h:form>
</ui:fragment>
</p:panelGrid>
<p:fieldset legend="#{i18n['user.meta.box.title']}" toggleable="true" collapsed="true" rendered="#{not empty userView.meta}">
<div id="usermetaview"><pre><h:outputText value="#{userView.prettyMeta}" /></pre></div>
</p:fieldset>
</p:panelGrid>
<p:fieldset toggleable="true" collapsed="true" legend="#{i18n['user.allergies']}">
<h:form id="userAllergies">
<p:dataTable value="#{userAllergyView.allergies}" var="allergy">
<p:column width="30"><p:selectBooleanCheckbox value="#{allergy.usersAllergy.selected}" /></p:column>
<p:column><h:outputText value="#{allergy.allergy.name.getValue(sessionStore.language)}"/></p:column>
</p:dataTable><br />
<p:inputTextarea value="#{userAllergyView.freetext}" cols="40" rows="5"/>
<br/>
<p:commandButton ajax="false" update="userAllergies" action="#{userAllergyView.saveAllergies}" value="#{i18n['allergies.save']}" />
</h:form>
</p:fieldset>
<h:form id="userSelectableRoles">
<p:fieldset legend="#{i18n['user.userSelectableRoles']}" rendered="#{userView.showUserSelectableRoles and cc.attrs.showRoles}">
<p:panelGrid columns="2" styleClass="noBorders">
......
......@@ -45,6 +45,10 @@ public class SessionStore implements Serializable {
private static final Logger logger = LoggerFactory.getLogger(SessionStore.class);
public String getLanguage() {
return getLocale().getLanguage();
}
public Locale getLocale() {
Locale ret = locale;
if (ret == null || ret.toString().equals(""))
......
/*
* 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.*;
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.Inject;
import javax.inject.Named;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Named()
@ConversationScoped
public class UserAllergyView extends GenericCDIView {
private static final String ALLERGIES_METAKEY = "allergies";
/**
*
*/
private static final Logger logger = LoggerFactory.getLogger(UserAllergyView.class);
private static final long serialVersionUID = 7724348195373468017L;
@Inject
private UserView userview;
@EJB
private UserBeanLocal userbean;
@EJB
private AllergyBeanLocal allergyBean;
private List<UserAllergyWrapper> allergies;
private String freetext;
public List<UserAllergyWrapper> getAllergies() {
final EventUser user = userview.getSelectedUser();
if (allergies == null) {
initAllergies(allergyBean.getUserAllergies(user));
}
return allergies;
}
private void initAllergies(List<UsersAllergy> userAllergies) {
EventUser user = userview.getSelectedUser();
Map<Allergy, UsersAllergy> uag = new HashMap<>();
for (UsersAllergy a : userAllergies) {
uag.put(a.getAllergy(), a);
}
allergies = new ArrayList<>();
for (Allergy a : allergyBean.getAllergies()) {
UsersAllergy currentAllergy = uag.get(a);
if (currentAllergy == null) {
currentAllergy = new UsersAllergy(a, user.getUser());
}
allergies.add(new UserAllergyWrapper(a, currentAllergy));
}
}
public String getFreetext() {
if (freetext == null) {
freetext = userview.getSelectedUser().getUser().getMetaStringValue(ALLERGIES_METAKEY);
if (freetext == null) {
freetext = "";
}
}
return freetext;
}
public void setAllergies(List<UserAllergyWrapper> allergies) {
this.allergies = allergies;
}
public void setFreetext(String freetext) {
this.freetext = freetext;
}
public void saveAllergies() {
if(freetext != null && !freetext.isEmpty()) {
EventUser usr = userview.getSelectedUser();
usr.getUser().setMetaStringValue(ALLERGIES_METAKEY, freetext);
userview.saveUser();
}
ArrayList<UsersAllergy> allergylist = new ArrayList<>();
for (UserAllergyWrapper aw : getAllergies()) {
allergylist.add(aw.getUsersAllergy());
}
List<UsersAllergy> userAllergies = allergyBean.saveAllergies(allergylist);
initAllergies(userAllergies);
}
public static class UserAllergyWrapper {
private final UsersAllergy usersAllergy;
private Allergy allergy;
public UserAllergyWrapper(Allergy allergy, UsersAllergy usersAllergy) {
this.allergy = allergy;
this.usersAllergy = usersAllergy;
}
public UsersAllergy getUsersAllergy() {
return usersAllergy;
}
public Allergy getAllergy() {
return allergy;
}
public void setAllergy(Allergy allergy) {
this.allergy = allergy;
}
}
}
......@@ -20,7 +20,10 @@ package fi.codecrew.moya.web.cdiview.user;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.enterprise.context.Conversation;
......@@ -31,7 +34,11 @@ import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.inject.Inject;
import javax.inject.Named;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonWriter;
import javax.json.JsonWriterFactory;
import javax.json.stream.JsonGenerator;
import org.primefaces.event.CaptureEvent;
import org.primefaces.event.FileUploadEvent;
......@@ -649,6 +656,24 @@ public class UserView extends GenericCDIView {
return "";
}
public String getPrettyMeta(){
JsonObject meta = getSelectedUser().getUser().getMeta();
if(meta == null){
return "";
}
StringWriter stringWriter = new StringWriter();
Map<String, Boolean> config = new HashMap<String, Boolean>();
config.put(JsonGenerator.PRETTY_PRINTING, true);
JsonWriterFactory writerFactory = Json.createWriterFactory(config);
JsonWriter jsonWriter = writerFactory.createWriter(stringWriter);
jsonWriter.write(meta);
jsonWriter.close();
return stringWriter.toString();
}
public String getEmailCheck() {
return emailCheck;
}
......
......@@ -1442,18 +1442,26 @@ user.sendPicture = Send image
user.sex.FEMALE = Female
user.sex.MALE = Male
user.sex.UNDEFINED = Prefer not to say
user.shirt.L = Unisex L
user.shirt.LadyXS = Ladyfit XS
user.shirt.LadyS = Ladyfit S
user.shirt.LadyL = Ladyfit L
user.shirt.LadyM = Ladyfit M
user.shirt.LadyS = Ladyfit S
user.shirt.LadyXL = Ladyfit XL
user.shirt.LadyXS = Ladyfit XS
user.shirt.LadyXXL = Ladyfit XXL
user.shirt.M = Unisex M
user.shirt.Lady3XL = Ladyfit 3XL
user.shirt.Lady4XL = Ladyfit 4XL
user.shirt.Lady5XL = Ladyfit 5XL
user.shirt.S = Unisex S
user.shirt.M = Unisex M
user.shirt.L = Unisex L
user.shirt.XL = Unisex XL
user.shirt.XXL = Unisex XXL
user.shirt.XXXL = Unisex XXXL
user.shirt.3XL = Unisex 3XL
user.shirt.4XL = Unisex 4XL
user.shirt.5XL = Unisex 5XL
user.shirt.select = Valitse yksi
user.shirtSize = Paidan koko
user.shop = Buy
......@@ -1621,3 +1629,7 @@ 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
......@@ -1719,18 +1719,26 @@ user.sex = Sex
user.sex.FEMALE = Female
user.sex.MALE = Male
user.sex.UNDEFINED = Prefer not to say
user.shirt.L = Unisex L
user.shirt.LadyXS = Ladyfit XS
user.shirt.LadyS = Ladyfit S
user.shirt.LadyL = Ladyfit L
user.shirt.LadyM = Ladyfit M
user.shirt.LadyS = Ladyfit S
user.shirt.LadyXL = Ladyfit XL
user.shirt.LadyXS = Ladyfit XS
user.shirt.LadyXXL = Ladyfit XXL
user.shirt.M = Unisex M
user.shirt.Lady3XL = Ladyfit 3XL
user.shirt.Lady4XL = Ladyfit 4XL
user.shirt.Lady5XL = Ladyfit 5XL
user.shirt.S = Unisex S
user.shirt.M = Unisex M
user.shirt.L = Unisex L
user.shirt.XL = Unisex XL
user.shirt.XXL = Unisex XXL
user.shirt.XXXL = Unisex XXXL
user.shirt.3XL = Unisex 3XL
user.shirt.4XL = Unisex 4XL
user.shirt.5XL = Unisex 5XL
user.shirt.select = Select one
user.shirtSize = Shirt size
user.shop = Buy
......@@ -1902,3 +1910,6 @@ 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
......@@ -1706,18 +1706,26 @@ user.sex = Sukupuoli
user.sex.FEMALE = Nainen
user.sex.MALE = Mies
user.sex.UNDEFINED = En halua kertoa
user.shirt.L = Unisex L
user.shirt.LadyXS = Ladyfit XS
user.shirt.LadyS = Ladyfit S
user.shirt.LadyL = Ladyfit L
user.shirt.LadyM = Ladyfit M
user.shirt.LadyS = Ladyfit S
user.shirt.LadyXL = Ladyfit XL
user.shirt.LadyXS = Ladyfit XS
user.shirt.LadyXXL = Ladyfit XXL
user.shirt.M = Unisex M
user.shirt.Lady3XL = Ladyfit 3XL
user.shirt.Lady4XL = Ladyfit 4XL
user.shirt.Lady5XL = Ladyfit 5XL
user.shirt.S = Unisex S
user.shirt.M = Unisex M
user.shirt.L = Unisex L
user.shirt.XL = Unisex XL
user.shirt.XXL = Unisex XXL
user.shirt.XXXL = Unisex XXXL
user.shirt.3XL = Unisex 3XL
user.shirt.4XL = Unisex 4XL
user.shirt.5XL = Unisex 5XL
user.shirt.select = Valitse n\u00E4ist\u00E4
user.shirtSize = Paidan koko
user.shop = Osta
......@@ -1889,3 +1897,7 @@ incomingflow.deliverableProducts=Toimitettavat tuotteet
placegroupview.accountEventDescription=Kuvaus
incomingflow.ungivenProducts=K\u00E4ytt\u00E4j\u00E4ll\u00E4 on toimittamattomia tuotteita
placegroupview.count=Kpl
user.allergies=Allergiat / ruokavaliot
allergies.save=Tallenna allergiat
\ 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!