diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/AppUserDto.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/AppUserDto.java index e7418af9..56f30e11 100644 --- a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/AppUserDto.java +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/AppUserDto.java @@ -1,8 +1,11 @@ package fr.desaintsteban.liste.envies.dto; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + /** - * Created by sfeir on 30/11/2016. + * */ +@JsonIgnoreProperties(ignoreUnknown = true) public class AppUserDto { private String email; diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/EnvieDto.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/EnvieDto.java deleted file mode 100644 index 89306635..00000000 --- a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/EnvieDto.java +++ /dev/null @@ -1,89 +0,0 @@ -package fr.desaintsteban.liste.envies.dto; - -import com.googlecode.objectify.Key; -import com.googlecode.objectify.annotation.Cache; -import com.googlecode.objectify.annotation.Entity; -import com.googlecode.objectify.annotation.Id; -import com.googlecode.objectify.annotation.Parent; -import fr.desaintsteban.liste.envies.model.AppUser; -import fr.desaintsteban.liste.envies.model.Envie; -import fr.desaintsteban.liste.envies.dto.NoteDto; -import org.codehaus.jackson.annotate.JsonIgnore; - -import java.util.List; - -/** - * 01/10/2014. - */ -public class EnvieDto { - private Long id; - - private String label; - - private String comment; - - private String price; - private String url; - private String userTake; - - private List notes; - - public EnvieDto() { - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - this.comment = comment; - } - - public String getPrice() { - return price; - } - - public void setPrice(String price) { - this.price = price; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getUserTake() { - return userTake; - } - - public void setUserTake(String userTake) { - this.userTake = userTake; - } - - public List getNotes() { - return notes; - } - - public void setNotes(List notes) { - this.notes = notes; - } -} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/EnvyDto.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/EnvyDto.java new file mode 100644 index 00000000..2d4a3722 --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/EnvyDto.java @@ -0,0 +1,110 @@ +package fr.desaintsteban.liste.envies.dto; + +import fr.desaintsteban.liste.envies.model.Link; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import java.util.List; + +/** + * 01/10/2014. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class EnvyDto { + private Long id; + + private String owner; + private Boolean suggest = false; + private String label; + + private String description; + + private String price; + private String picture; + private List urls; + private List userTake; + + private List notes; + + public EnvyDto() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public Boolean getSuggest() { + return suggest; + } + + public void setSuggest(Boolean suggest) { + this.suggest = suggest; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getPicture() { + return picture; + } + + public void setPicture(String picture) { + this.picture = picture; + } + + public List getUrls() { + return urls; + } + + public void setUrls(List urls) { + this.urls = urls; + } + + public List getUserTake() { + return userTake; + } + + public void setUserTake(List userTake) { + this.userTake = userTake; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + + public List getNotes() { + return notes; + } + + public void setNotes(List notes) { + this.notes = notes; + } +} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/ListEnviesDto.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/ListEnviesDto.java new file mode 100644 index 00000000..7a926da7 --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/ListEnviesDto.java @@ -0,0 +1,68 @@ +package fr.desaintsteban.liste.envies.dto; + +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import java.util.List; + +/** + * + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class ListEnviesDto { + private String name; + + private String title; + private String description; + private Boolean isOwner; + private List users; + + private List owners; + + public List getOwners() { + return owners; + } + + public void setOwners(List owners) { + this.owners = owners; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } + + public Boolean getOwner() { + return isOwner; + } + + public void setOwner(Boolean owner) { + isOwner = owner; + } +} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/UserShareDto.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/UserShareDto.java new file mode 100644 index 00000000..1012028a --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/dto/UserShareDto.java @@ -0,0 +1,56 @@ +package fr.desaintsteban.liste.envies.dto; + +import fr.desaintsteban.liste.envies.model.AppUser; +import fr.desaintsteban.liste.envies.model.UserShareType; + +import java.util.Map; + +/** + * + */ +public class UserShareDto { + private String email; + private String name; + private UserShareType type; + + public UserShareDto() { + } + + public UserShareDto(String email, String name, UserShareType type) { + this.email = email; + this.name = name; + this.type = type; + } + + public UserShareDto(String email, UserShareType type, Map userName) { + this.email = email; + this.type = type; + if (userName != null && userName.containsKey(email)) { + this.name = userName.get(email).getName(); + } + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public UserShareType getType() { + return type; + } + + public void setType(UserShareType type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/Envie.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/Envie.java index 5dd3bde1..aa2a3347 100644 --- a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/Envie.java +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/Envie.java @@ -5,7 +5,7 @@ import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Parent; -import fr.desaintsteban.liste.envies.dto.EnvieDto; +import fr.desaintsteban.liste.envies.dto.EnvyDto; import fr.desaintsteban.liste.envies.dto.NoteDto; import fr.desaintsteban.liste.envies.util.EncodeUtils; import org.codehaus.jackson.annotate.JsonIgnore; @@ -19,6 +19,7 @@ */ @Cache @Entity +@Deprecated public class Envie { @Parent @@ -49,38 +50,6 @@ public Envie(AppUser owner, String label) { this.notes = new ArrayList<>(); } - - public Envie(EnvieDto envie) { - setId(envie.getId()); - setLabel(envie.getLabel()); - setComment(envie.getComment()); - setPrice(envie.getPrice()); - setUrl(envie.getUrl()); - setUserTake(EncodeUtils.encode(envie.getUserTake())); - - this.notes = new ArrayList<>(); - - } - - public EnvieDto toDto() { - EnvieDto envie = new EnvieDto(); - envie.setId(getId()); - envie.setLabel(getLabel()); - envie.setComment(getComment()); - envie.setPrice(getPrice()); - envie.setUrl(getUrl()); - envie.setUserTake(EncodeUtils.decode(getUserTake())); - - if (this.notes != null && !this.notes.isEmpty()) { - List listNoteDto = new ArrayList<>(); - for (Note note : this.notes) { - listNoteDto.add(note.toDto()); - } - envie.setNotes(listNoteDto); - } - return envie; - } - public Key getOwner() { return owner; } diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/Envy.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/Envy.java new file mode 100644 index 00000000..8a8d5a2a --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/Envy.java @@ -0,0 +1,221 @@ +package fr.desaintsteban.liste.envies.model; + +import com.googlecode.objectify.Key; +import com.googlecode.objectify.annotation.*; +import fr.desaintsteban.liste.envies.dto.EnvyDto; +import fr.desaintsteban.liste.envies.dto.NoteDto; +import fr.desaintsteban.liste.envies.util.EncodeUtils; +import fr.desaintsteban.liste.envies.util.StringUtils; +import org.codehaus.jackson.annotate.JsonIgnore; + +import javax.jdo.annotations.Embedded; +import java.util.ArrayList; +import java.util.List; + +/** + * 01/10/2014. + */ +@Cache +@Entity +public class Envy { + + @Parent + @JsonIgnore + Key list; + @Id + private Long id; + + private String owner; + /** + * L'envie à été suggéré par une autre personne + */ + private Boolean suggest = false; + + private String label; + + private String description; + + private String price; + private String picture; + @Embedded + private List urls; + @Index + private List userTake; + + @Embedded + private List notes; + + + public Envy() { + this.notes = new ArrayList<>(); + } + + public Envy(ListEnvies list, String label) { + this.list = Key.create(list); + this.label = label; + this.notes = new ArrayList<>(); + } + + + public Envy(EnvyDto envie) { + setId(envie.getId()); + setOwner(envie.getOwner()); + setSuggest(envie.getSuggest()); + setLabel(envie.getLabel()); + setDescription(envie.getDescription()); + setPrice(envie.getPrice()); + setPicture(envie.getPicture()); + setUrls(envie.getUrls()); + if (envie.getUserTake() != null) { + List userTake = new ArrayList<>(); + for (String email : envie.getUserTake()) { + userTake.add(EncodeUtils.encode(email)); + } + setUserTake(userTake); + } + this.notes = new ArrayList<>(); + } + + public EnvyDto toDto() { + EnvyDto envie = new EnvyDto(); + envie.setId(getId()); + envie.setOwner(getOwner()); + envie.setSuggest(suggest); + envie.setLabel(getLabel()); + envie.setDescription(getDescription()); + envie.setPrice(getPrice()); + envie.setPicture(getPicture()); + envie.setUrls(getUrls()); + List userTake = new ArrayList<>(); + if (getUserTake() != null) { + for (String email : getUserTake()) { + userTake.add(EncodeUtils.decode(email)); + } + } + envie.setUserTake(userTake); + if (this.notes != null && !this.notes.isEmpty()) { + List listNoteDto = new ArrayList<>(); + for (Note note : this.notes) { + listNoteDto.add(note.toDto()); + } + envie.setNotes(listNoteDto); + } + return envie; + } + + public Key getList() { + return list; + } + + public void setList(Key owner) { + this.list = owner; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public Boolean getSuggest() { + return suggest; + } + + public void setSuggest(Boolean suggest) { + this.suggest = suggest; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + + public String getPicture() { + return picture; + } + + public void setPicture(String picture) { + this.picture = picture; + } + + public List getUrls() { + return urls; + } + + public void setUrls(List urls) { + this.urls = urls; + } + + public void addUrl(String url) { + if (this.urls == null) { + this.urls = new ArrayList<>(); + } + if (!StringUtils.isNullOrEmpty(url)) { + this.urls.add(new Link(url)); + } + } + + public void setUserTake(List userTake) { + this.userTake = userTake; + } + + public List getUserTake() { + return userTake; + } + + public void addUserTake(String userTake) { + if (this.userTake == null) { + this.userTake = new ArrayList<>(); + } + if (!StringUtils.isNullOrEmpty(userTake)) { + this.userTake.add(userTake); + } + } + + public void removeUserTake(String userTake) { + if (userTake != null) { + this.userTake.remove(userTake); + } + } + + public void addNote(String owner, String email, String text) { + this.notes.add(new Note(owner, email, text)); + } + + public List getNotes () { + return this.notes; + } + + public void setNotes(List notes) { + this.notes = notes; + } +} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/Link.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/Link.java new file mode 100644 index 00000000..29ba5b1e --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/Link.java @@ -0,0 +1,36 @@ +package fr.desaintsteban.liste.envies.model; + +/** + */ +public class Link { + private String url; + private String name; + + public Link() { + } + + public Link(String url) { + this.url = url; + } + + public Link(String url, String name) { + this.url = url; + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/ListEnvies.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/ListEnvies.java new file mode 100644 index 00000000..8ad86b19 --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/ListEnvies.java @@ -0,0 +1,125 @@ +package fr.desaintsteban.liste.envies.model; + +import com.googlecode.objectify.annotation.Entity; +import com.googlecode.objectify.annotation.Id; +import fr.desaintsteban.liste.envies.dto.ListEnviesDto; +import fr.desaintsteban.liste.envies.dto.UserShareDto; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * + */ +@Entity() +public class ListEnvies { + @Id private String name; + + private String title; + private String description; + private List users; + + public ListEnvies() { + } + + public ListEnvies(String name, String title, String owner, String... shared) { + this.name = name; + this.title = title; + users = new ArrayList<>(); + users.add(new UserShare(owner, UserShareType.OWNER)); + for (String shareUser : shared) { + users.add(new UserShare(shareUser, UserShareType.SHARED)); + } + } + + public ListEnvies(ListEnviesDto dto) { + setName(dto.getName()); + setTitle(dto.getTitle()); + setDescription(dto.getDescription()); + List users = new ArrayList<>(); + for (UserShareDto userShareDto : dto.getUsers()) { + users.add(new UserShare(userShareDto.getEmail(), userShareDto.getType())); + } + setUsers(users); + } + + public ListEnviesDto toDto(boolean convertUsers, String userEmail, Map userName) { + ListEnviesDto dto = new ListEnviesDto(); + dto.setName(getName()); + dto.setTitle(getTitle()); + dto.setDescription(getDescription()); + List users = getUsers(); + List usersDto = new ArrayList<>(); + List ownersDto = new ArrayList<>(); + for (UserShare user : users) { + UserShareDto userShareDto = new UserShareDto(user.getEmail(), user.getType(), userName); + if (user.getType() == UserShareType.OWNER) { + ownersDto.add(userShareDto); + } + if (convertUsers) { + usersDto.add(userShareDto); + } + } + if (convertUsers) { + dto.setUsers(usersDto); + } + dto.setOwners(ownersDto); + if (userEmail != null) { + dto.setOwner(containsOwner(userEmail)); + } + return dto; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } + + public boolean containsOwner(String email) { + if (users != null) { + for (UserShare user : users) { + if (user.getType() == UserShareType.OWNER && user.getEmail().equals(email)) + return true; + } + } + return false; + } + + public boolean containsUser(String email) { + if (users != null) { + for (UserShare user : users) { + if (user.getEmail().equals(email)) + return true; + } + } + return false; + } +} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/UserShare.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/UserShare.java new file mode 100644 index 00000000..e2d9aaa1 --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/UserShare.java @@ -0,0 +1,37 @@ +package fr.desaintsteban.liste.envies.model; + +import com.googlecode.objectify.annotation.Index; + +/** + * + */ +public class UserShare { + @Index + private String email; + + private UserShareType type; + + public UserShare() { + } + + public UserShare(String email, UserShareType type) { + this.email = email; + this.type = type; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public UserShareType getType() { + return type; + } + + public void setType(UserShareType type) { + this.type = type; + } +} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/UserShareType.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/UserShareType.java new file mode 100644 index 00000000..8197398b --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/model/UserShareType.java @@ -0,0 +1,8 @@ +package fr.desaintsteban.liste.envies.model; + +/** + * + */ +public enum UserShareType { + OWNER, SHARED +} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/rest/EnviesRestService.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/rest/EnviesRestService.java index 964982a9..44a27a4f 100644 --- a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/rest/EnviesRestService.java +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/rest/EnviesRestService.java @@ -1,19 +1,26 @@ package fr.desaintsteban.liste.envies.rest; -import fr.desaintsteban.liste.envies.dto.EnvieDto; +import fr.desaintsteban.liste.envies.dto.EnvyDto; import fr.desaintsteban.liste.envies.dto.NoteDto; import fr.desaintsteban.liste.envies.model.AppUser; -import fr.desaintsteban.liste.envies.model.Envie; +import fr.desaintsteban.liste.envies.model.Envy; import fr.desaintsteban.liste.envies.service.EnviesService; import fr.desaintsteban.liste.envies.util.ServletUtils; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; -@Path("/liste/{email}/envies") +@Path("/envies/{name}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public class EnviesRestService { @@ -21,11 +28,11 @@ public class EnviesRestService { @GET @Path("/{id}") - public EnvieDto getEnvie(@PathParam("email") String email, @PathParam("id") Long id) { + public EnvyDto getEnvie(@PathParam("name") String name, @PathParam("id") Long id) { final AppUser user = ServletUtils.getUserAuthenticated(); if(user != null){ LOGGER.info("Get " + id); - Envie envie = EnviesService.get(user, email, id); + Envy envie = EnviesService.get(user, name, id); if (envie != null) return envie.toDto(); } @@ -34,33 +41,33 @@ public EnvieDto getEnvie(@PathParam("email") String email, @PathParam("id") Long @PUT @Path("/{id}/give") - public void give(@PathParam("email") String email, @PathParam("id") Long id) { + public void give(@PathParam("name") String name, @PathParam("id") Long id) { final AppUser user = ServletUtils.getUserAuthenticated(); if (user != null){ LOGGER.info("Get " + id); - EnviesService.given(user, email, id); + EnviesService.given(user, name, id); } } @PUT @Path("/{id}/cancel") - public void cancel(@PathParam("email") String email, @PathParam("id") Long id) { + public void cancel(@PathParam("name") String name, @PathParam("id") Long id) { final AppUser user = ServletUtils.getUserAuthenticated(); if (user != null){ LOGGER.info("Get " + id); - EnviesService.cancel(user, email, id); + EnviesService.cancel(user, name, id); } } @GET - public List getEnvie(@PathParam("email") String email) { + public List getEnvie(@PathParam("name") String name) { final AppUser user = ServletUtils.getUserAuthenticated(); if(user != null){ LOGGER.info("List"); - List list = EnviesService.list(user, email); - List result = new ArrayList<>(list.size()); - for (Envie envie : list) { + List list = EnviesService.list(user, name); + List result = new ArrayList<>(list.size()); + for (Envy envie : list) { result.add(envie.toDto()); } return result; @@ -69,41 +76,41 @@ public List getEnvie(@PathParam("email") String email) { } @POST - public void addEnvie(@PathParam("email") String email, EnvieDto envie) { + public void addEnvie(@PathParam("name") String name, EnvyDto envie) { final AppUser user = ServletUtils.getUserAuthenticated(); if (user != null) { LOGGER.info("Put " + envie.getLabel()); - EnviesService.createOrUpdate(user, email, new Envie(envie)); + EnviesService.createOrUpdate(user, name, new Envy(envie)); } } @POST @Path("/{id}/addNote") - public void addNote(@PathParam("email") String email, @PathParam("id") Long envieId, NoteDto note) { + public void addNote(@PathParam("name") String name, @PathParam("id") Long envieId, NoteDto note) { final AppUser user = ServletUtils.getUserAuthenticated(); if (user != null) { LOGGER.info("add note from " + user.getName()); - EnviesService.addNote(user, envieId, email, note); + EnviesService.addNote(user, envieId, name, note); } } @POST @Path("/{id}") - public void updateEnvie(@PathParam("email") String email, EnvieDto envie) { + public void updateEnvie(@PathParam("name") String name, EnvyDto envie) { final AppUser user = ServletUtils.getUserAuthenticated(); if (user != null) { LOGGER.info("Put " + envie.getLabel()); - EnviesService.createOrUpdate(user, email, new Envie(envie)); + EnviesService.createOrUpdate(user, name, new Envy(envie)); } } @DELETE @Path("/{id}") - public void deleteEnvie(@PathParam("email") String email, @PathParam("id") Long id){ + public void deleteEnvie(@PathParam("name") String name, @PathParam("id") Long id){ final AppUser user = ServletUtils.getUserAuthenticated(); if(user != null){ LOGGER.info("Delete " + id); - EnviesService.delete(user, email, id); + EnviesService.delete(user, name, id); } } } diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/rest/ListEnviesRestService.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/rest/ListEnviesRestService.java new file mode 100644 index 00000000..c5e0136d --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/rest/ListEnviesRestService.java @@ -0,0 +1,158 @@ +package fr.desaintsteban.liste.envies.rest; + +import fr.desaintsteban.liste.envies.dto.ListEnviesDto; +import fr.desaintsteban.liste.envies.model.AppUser; +import fr.desaintsteban.liste.envies.model.ListEnvies; +import fr.desaintsteban.liste.envies.model.UserShare; +import fr.desaintsteban.liste.envies.model.UserShareType; +import fr.desaintsteban.liste.envies.service.AppUserService; +import fr.desaintsteban.liste.envies.service.ListEnviesService; +import fr.desaintsteban.liste.envies.util.ServletUtils; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.util.*; +import java.util.logging.Logger; + +@Path("/liste") +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class ListEnviesRestService { + private static final Logger LOGGER = Logger.getLogger(ListEnviesRestService.class.getName()); + + @GET + public List getListEnvies() { + final AppUser user = ServletUtils.getUserAuthenticated(); + if(user != null){ + LOGGER.info("List users"); + List list = ListEnviesService.list(user.getEmail()); + return getListEnviesDtos(user, list); + } + return null; + } + + /** + * Récuppère les listes d'un utilisateur filtré par l'utilisateur courant + * @param email + * @return + */ + @GET + @Path("/of/{email}") + public List getListEnvies(@PathParam("email") String email) { + final AppUser user = ServletUtils.getUserAuthenticated(); + if(user != null){ + LOGGER.info("List authorized liste for user: "+email); + List list = ListEnviesService.list(email); + ArrayList convertList = new ArrayList<>(); + for (ListEnvies listeEnvy : list) { + if (listeEnvy.containsOwner(email) && (listeEnvy.containsUser(user.getEmail()) || user.isAdmin())) { + convertList.add(listeEnvy.toDto(false, user.getEmail(), null)); + } + } + return convertList; + } + return null; + } + + /** + * Récuppère toutes les listes pour l'administration + * @return + */ + @GET + @Path("/all") + public List getAllList() { + final AppUser user = ServletUtils.getUserAuthenticated(); + if(user != null && user.isAdmin()){ + LOGGER.info("List all ListEnvies"); + List list = ListEnviesService.list(); + ArrayList convertList = new ArrayList<>(); + for (ListEnvies listeEnvy : list) { + convertList.add(listeEnvy.toDto(false, user.getEmail(), null)); + } + return convertList; + } + return null; + } + + @POST + @Path("/{name}") + public ListEnviesDto updateListeEnvie(@PathParam("name") String name, ListEnviesDto listEnvies) { + final AppUser user = ServletUtils.getUserAuthenticated(); + if (user != null) { + LOGGER.info("Save ListEnvies " + listEnvies.getName()); + ListEnvies orUpdate = ListEnviesService.createOrUpdate(user, new ListEnvies(listEnvies)); + return orUpdate.toDto(true, user.getEmail(), null); + } + return null; + } + + @POST + @Path("/") + public ListEnviesDto addListeEnvie(ListEnviesDto listEnvies) { + final AppUser user = ServletUtils.getUserAuthenticated(); + if (user != null) { + LOGGER.info("Save ListEnvies " + listEnvies.getName()); + ListEnvies listEnvie = ListEnviesService.createOrUpdate(user, new ListEnvies(listEnvies)); + return getListEnviesDto(user, listEnvie); + } + return null; + } + + @GET + @Path("/{name}") + public ListEnviesDto getUser(@PathParam("name") String email) { + final AppUser user = ServletUtils.getUserAuthenticated(); + if (user != null) { + LOGGER.info("Get " + email); + ListEnvies listEnvies = ListEnviesService.get(email); + return getListEnviesDto(user, listEnvies); + } + return null; + } + + @DELETE + @Path("/{name}") + public void deleteEnvie(@PathParam("name") String name){ + final AppUser user = ServletUtils.getUserAuthenticated(); + if(user != null){ + LOGGER.info("name " + name); + ListEnviesService.delete(name); + } + } + + private ListEnviesDto getListEnviesDto(AppUser user, ListEnvies listEnvie) { + Map map = null; + if (listEnvie.getUsers() != null) { + List emails = new ArrayList<>(); + for (UserShare userShare : listEnvie.getUsers()) { + emails.add(userShare.getEmail()); + } + map = AppUserService.loadAll(emails); + } + return listEnvie.toDto(true, user.getEmail(), map); + } + + private List getListEnviesDtos(AppUser user, List list) { + ArrayList convertList = new ArrayList<>(); + Set emails = new HashSet<>(); + Map map = null; + for (ListEnvies listeEnvy : list) { + for (UserShare userShare : listeEnvy.getUsers()) { + if (userShare.getType() == UserShareType.OWNER) { + emails.add(userShare.getEmail()); + } + } + } + map = AppUserService.loadAll(emails); + for (ListEnvies listeEnvy : list) { + convertList.add(listeEnvy.toDto(false, user.getEmail(), map)); + } + return convertList; + } +} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/AppUserService.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/AppUserService.java index 75ce86fe..234ae301 100644 --- a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/AppUserService.java +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/AppUserService.java @@ -9,7 +9,9 @@ import com.googlecode.objectify.cmd.Saver; import fr.desaintsteban.liste.envies.model.AppUser; +import java.util.Collection; import java.util.List; +import java.util.Map; public final class AppUserService { private AppUserService() {} @@ -47,6 +49,9 @@ public static List list() { return list; } + public static Map loadAll(Collection emails) { + return OfyService.ofy().load().type(AppUser.class).ids(emails); + } public static void delete(String email) { OfyService.ofy().delete().key(Key.create(AppUser.class, email)).now(); diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/EnviesService.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/EnviesService.java index 0da9e460..4161806f 100644 --- a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/EnviesService.java +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/EnviesService.java @@ -1,6 +1,7 @@ package fr.desaintsteban.liste.envies.service; import com.googlecode.objectify.Key; +import com.googlecode.objectify.LoadResult; import com.googlecode.objectify.Objectify; import com.googlecode.objectify.VoidWork; import com.googlecode.objectify.Work; @@ -8,138 +9,165 @@ import fr.desaintsteban.liste.envies.dto.NoteDto; import fr.desaintsteban.liste.envies.model.AppUser; import fr.desaintsteban.liste.envies.model.Envie; +import fr.desaintsteban.liste.envies.model.Envy; +import fr.desaintsteban.liste.envies.model.ListEnvies; import fr.desaintsteban.liste.envies.util.EncodeUtils; +import java.util.ArrayList; import java.util.List; public final class EnviesService { private EnviesService() {} - public static List list(AppUser user, String email) { - Key parent = Key.create(AppUser.class, email); - List list = OfyService.ofy().load().type(Envie.class).ancestor(parent).list(); - if (user.getEmail().equals(email)) { - removeUserTake(list); - } + public static List list(AppUser user, String name) { + Objectify ofy = OfyService.ofy(); + Key key = Key.create(ListEnvies.class, name); + LoadResult loadResult = ofy.load().key(key); //Chargement asynchrone + List list = ofy.load().type(Envy.class).ancestor(key).list(); + ListEnvies listEnvies = loadResult.now(); + removeUserTake(user, listEnvies, list); return list; } - public static List listAll() { - List list = OfyService.ofy().load().type(Envie.class).list(); + public static List listAll() { + List list = OfyService.ofy().load().type(Envy.class).list(); //On supprime toujours celui qui a donner le cadeaux - removeUserTake(list); + removeUserTake(null, null, list); return list; } - public static List list(AppUser user, String email, String libelle) { - Key parent = Key.create(AppUser.class, email); - List list = OfyService.ofy().load().type(Envie.class).ancestor(parent).filter("label >=", libelle).filter("label <", libelle + "\uFFFD").list(); - if (user.getEmail().equals(email)) { - removeUserTake(list); - } + public static List list(AppUser user, String name, String libelle) { + Objectify ofy = OfyService.ofy(); + Key parent = Key.create(ListEnvies.class, name); + LoadResult loadResult = ofy.load().key(parent); //Chargement asynchrone + List list = ofy.load().type(Envy.class).ancestor(parent).filter("label >=", libelle).filter("label <", libelle + "\uFFFD").list(); + ListEnvies listEnvies = loadResult.now(); + removeUserTake(user, listEnvies, list); return list; } - public static void delete(AppUser user, String email, Long itemid) { - Key parent = Key.create(AppUser.class, email); - if (user.getEmail().equals(email) || user.isAdmin()) { + public static void delete(AppUser user, String name, Long itemid) { + Objectify ofy = OfyService.ofy(); + Key parent = Key.create(ListEnvies.class, name); + ListEnvies listEnvies = ofy.load().key(parent).now(); + if (listEnvies.containsOwner(user.getEmail()) || user.isAdmin()) { OfyService.ofy().delete().key(Key.create(parent, Envie.class, itemid)).now(); } } - public static Envie get(AppUser user, String email, Long itemid) { - Key parent = Key.create(AppUser.class, email); - Envie envie = OfyService.ofy().load().key(Key.create(parent, Envie.class, itemid)).now(); - if (user.getEmail().equals(email)) { + public static Envy get(AppUser user, String name, Long itemid) { + Objectify ofy = OfyService.ofy(); + Key parent = Key.create(ListEnvies.class, name); + LoadResult loadResult = ofy.load().key(parent); //Chargement asynchrone + Envy envie = OfyService.ofy().load().key(Key.create(parent, Envy.class, itemid)).now(); + ListEnvies listEnvies = loadResult.now(); + if (listEnvies != null && listEnvies.containsOwner(user.getEmail())) { envie.setUserTake(null); envie.setNotes(null); } return envie; } - public static void given(final AppUser user, String email, final Long itemId) { - if (user.getEmail().equals(email)) { - - } - else if (!user.getEmail().equals(email)) { - final Key parent = Key.create(AppUser.class, email); + public static void given(final AppUser user, String name, final Long itemId) { + Objectify ofy = OfyService.ofy(); + final Key parent = Key.create(ListEnvies.class, name); + ListEnvies listEnvies = ofy.load().key(parent).now(); + if (!listEnvies.containsOwner(user.getEmail()) && listEnvies.containsUser(user.getEmail())) { OfyService.ofy().transact(new VoidWork() { @Override public void vrun() { Objectify ofy = OfyService.ofy(); - Envie saved = ofy.load().key(Key.create(parent, Envie.class, itemId)).now(); + Envy saved = ofy.load().key(Key.create(parent, Envy.class, itemId)).now(); Saver saver = ofy.save(); - saved.setUserTake(EncodeUtils.encode(user.getEmail())); + saved.addUserTake(EncodeUtils.encode(user.getEmail())); saver.entity(saved); } }); } } - public static void addNote(final AppUser user, final Long itemId, final String email, final NoteDto note) { - - if (user.getEmail().equals(email)) { - - } - else if (!user.getEmail().equals(email)) { - final Key parent = Key.create(AppUser.class, email); + public static void addNote(final AppUser user, final Long itemId, final String name, final NoteDto note) { + Objectify ofy = OfyService.ofy(); + final Key parent = Key.create(ListEnvies.class, name); + ListEnvies listEnvies = ofy.load().key(parent).now(); + if (listEnvies != null && !listEnvies.containsOwner(user.getEmail()) && listEnvies.containsUser(user.getEmail())) { OfyService.ofy().transact(new VoidWork() { @Override public void vrun() { - Objectify ofy = OfyService.ofy(); - Envie saved = ofy.load().key(Key.create(parent, Envie.class, itemId)).now(); - Saver saver = ofy.save(); - saved.addNote(user.getName(), user.getEmail(), note.getText()); - saver.entity(saved); + Objectify ofy = OfyService.ofy(); + Envy saved = ofy.load().key(Key.create(parent, Envy.class, itemId)).now(); + Saver saver = ofy.save(); + saved.addNote(user.getName(), user.getEmail(), note.getText()); + saver.entity(saved); } }); } } - public static void cancel(final AppUser user, String email, final Long itemId) { - if (user.getEmail().equals(email)) { - - } - else if (!user.getEmail().equals(email)) { - final Key parent = Key.create(AppUser.class, email); + public static void cancel(final AppUser user, String name, final Long itemId) { + Objectify ofy = OfyService.ofy(); + final Key parent = Key.create(ListEnvies.class, name); + ListEnvies listEnvies = ofy.load().key(parent).now(); + if (listEnvies != null && !listEnvies.containsOwner(user.getEmail()) && listEnvies.containsUser(user.getEmail())) { OfyService.ofy().transact(new VoidWork() { @Override public void vrun() { - Objectify ofy = OfyService.ofy(); - Envie saved = ofy.load().key(Key.create(parent, Envie.class, itemId)).now(); - Saver saver = ofy.save(); - saved.setUserTake(null); - saver.entity(saved); + Objectify ofy = OfyService.ofy(); + Envy saved = ofy.load().key(Key.create(parent, Envy.class, itemId)).now(); + Saver saver = ofy.save(); + saved.setUserTake(null); + saver.entity(saved); } }); } } - public static Envie createOrUpdate(final AppUser user, final String email, final Envie item) { - if (user.getEmail().equals(email)) { - final Key parent = Key.create(AppUser.class, email); - return OfyService.ofy().transact(new Work() { + public static Envy createOrUpdate(final AppUser user, final String name, final Envy item) { + Objectify ofy = OfyService.ofy(); + final Key parent = Key.create(ListEnvies.class, name); + final ListEnvies listEnvies = ofy.load().key(parent).now(); + if (listEnvies != null) { + return OfyService.ofy().transact(new Work() { @Override - public Envie run() { - Objectify ofy = OfyService.ofy(); - Saver saver = ofy.save(); - item.setOwner(parent); - if (item.getId() != null) { - Envie saved = ofy.load().key(Key.create(parent, Envie.class, item.getId())).now(); - item.setUserTake(saved.getUserTake()); - } - Key key = saver.entity(item).now(); - return item; + public Envy run() { + Objectify ofy = OfyService.ofy(); + Saver saver = ofy.save(); + item.setList(parent); + if (item.getId() != null) { + Envy saved = ofy.load().key(Key.create(parent, Envy.class, item.getId())).now(); + item.setUserTake(saved.getUserTake()); + item.setNotes(saved.getNotes()); + item.setOwner(saved.getOwner()); + } + if (item.getOwner() == null) { + item.setOwner(user.getEmail()); + } + item.setSuggest(!listEnvies.containsOwner(item.getOwner())); + Key key = saver.entity(item).now(); + return item; } }); } return null; } - private static void removeUserTake(List list) { - for (Envie envie : list) { - envie.setUserTake(null); //Si l'utilisateur courrant est le propriétaire des envies, on efface le nom de qui lui a offert un cadeau. - envie.setNotes(null); + private static void removeUserTake(AppUser user, ListEnvies listEnvies, List list) { + List toRemove = new ArrayList<>(); + for (Envy envy : list) { + if (listEnvies == null || user == null) { //Liste globale + envy.setUserTake(null); + envy.setNotes(null); + } + else { + if (listEnvies.containsOwner(user.getEmail())) { //Si l'utilisateur courant est le propriétaire des envies, on efface le nom de qui lui a offert un cadeau. + envy.setUserTake(null); + envy.setNotes(null); + if (envy.getSuggest()) { // On supprime les envies ajoutés par d'autres personnes + toRemove.add(envy); + } + } + } } + list.removeAll(toRemove); } } \ No newline at end of file diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/ListEnviesService.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/ListEnviesService.java new file mode 100644 index 00000000..ea3e537f --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/ListEnviesService.java @@ -0,0 +1,61 @@ +package fr.desaintsteban.liste.envies.service; + +import com.googlecode.objectify.Key; +import com.googlecode.objectify.Work; +import com.googlecode.objectify.cmd.Saver; +import fr.desaintsteban.liste.envies.model.AppUser; +import fr.desaintsteban.liste.envies.model.ListEnvies; +import fr.desaintsteban.liste.envies.util.StringUtils; + +import java.util.List; +import java.util.Map; + +public final class ListEnviesService { + private ListEnviesService() {} + + public static List list() { + List list = OfyService.ofy().load().type(ListEnvies.class).list(); + return list; + } + + public static List list(String email) { + List list = OfyService.ofy().load().type(ListEnvies.class).filter("users.email =", email).list(); + return list; + } + + public static Map loadAll(List names) { + return OfyService.ofy().load().type(ListEnvies.class).ids(names); + } + + public static void delete(String email) { + OfyService.ofy().delete().key(Key.create(ListEnvies.class, email)).now(); + } + + public static ListEnvies get(String email) { + return OfyService.ofy().load().key(Key.create(ListEnvies.class, email)).now(); + } + + public static ListEnvies createOrUpdate(AppUser user, final ListEnvies item) { + if (StringUtils.isNullOrEmpty(item.getTitle())) { + String title = "Liste de " + user.getName(); + item.setTitle(title); + } + if (StringUtils.isNullOrEmpty(item.getName())) { + String name = StringUtils.toValidIdName(item.getTitle()); + int i = 0; + String prefix = name; + while (OfyService.ofy().load().key(Key.create(ListEnvies.class, name)).now() != null) { + name = prefix + '-' + i; + } + item.setName(name); + } + return OfyService.ofy().transact(new Work() { + @Override + public ListEnvies run() { + final Saver saver = OfyService.ofy().save(); + saver.entities(item).now(); + return item; + } + }); + } +} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/OfyService.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/OfyService.java index aa382a9d..edf42c77 100644 --- a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/OfyService.java +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/service/OfyService.java @@ -6,11 +6,15 @@ import com.googlecode.objectify.util.Closeable; import fr.desaintsteban.liste.envies.model.AppUser; import fr.desaintsteban.liste.envies.model.Envie; +import fr.desaintsteban.liste.envies.model.Envy; +import fr.desaintsteban.liste.envies.model.ListEnvies; public final class OfyService { static { factory().register(AppUser.class); factory().register(Envie.class); + factory().register(Envy.class); + factory().register(ListEnvies.class); } private OfyService() {} diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/servlet/MigrateServlet.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/servlet/MigrateServlet.java index 5238b1e8..70a08bc9 100644 --- a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/servlet/MigrateServlet.java +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/servlet/MigrateServlet.java @@ -1,17 +1,22 @@ package fr.desaintsteban.liste.envies.servlet; +import com.googlecode.objectify.Key; import com.googlecode.objectify.Objectify; -import com.googlecode.objectify.VoidWork; +import fr.desaintsteban.liste.envies.model.AppUser; import fr.desaintsteban.liste.envies.model.Envie; -import fr.desaintsteban.liste.envies.model.Note; +import fr.desaintsteban.liste.envies.model.Envy; +import fr.desaintsteban.liste.envies.model.ListEnvies; +import fr.desaintsteban.liste.envies.model.UserShare; +import fr.desaintsteban.liste.envies.model.UserShareType; import fr.desaintsteban.liste.envies.service.OfyService; -import fr.desaintsteban.liste.envies.util.EncodeUtils; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; import java.util.List; /** @@ -20,19 +25,43 @@ public class MigrateServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("text/plain;charset=UTF-8"); + PrintWriter out = resp.getWriter(); Objectify ofy = OfyService.ofy(); - List list = ofy.load().type(Envie.class).list(); - for (Envie envie : list) { - if (envie.getUserTake() != null) { - envie.setUserTake(EncodeUtils.encode(envie.getUserTake())); - } - if (envie.getNotes() != null) { - for (Note note : envie.getNotes()) { - note.setOwner(EncodeUtils.encode(note.getOwner())); - note.setText(EncodeUtils.encode(note.getText())); + List listUser = ofy.load().type(AppUser.class).list(); + for (AppUser appUser : listUser) { + out.println("Liste de "+appUser.getName()); + ListEnvies envies = new ListEnvies(); + envies.setName("list-"+appUser.getName().toLowerCase()); + envies.setTitle("Liste de " + appUser.getName()); + List users = new ArrayList<>(); + users.add(new UserShare(appUser.getEmail(), UserShareType.OWNER)); + for (AppUser shareUser : listUser) { + if (!shareUser.getEmail().equals(appUser.getEmail())) { + users.add(new UserShare(shareUser.getEmail(), UserShareType.SHARED)); } } + envies.setUsers(users); + + Key key = ofy.save().entity(envies).now(); + + List list = ofy.load().type(Envie.class).ancestor(appUser).list(); + List listConverted = new ArrayList<>(); + for (Envie envie : list) { + Envy envy = new Envy(); + envy.setList(key); + envy.setOwner(envie.getOwner().getName()); + envy.setLabel(envie.getLabel()); + envy.setDescription(envie.getComment()); + envy.setPrice(envie.getPrice()); + envy.addUrl(envie.getUrl()); + envy.setNotes(envie.getNotes()); + envy.addUserTake(envie.getUserTake()); + listConverted.add(envy); + } + ofy.save().entities(listConverted); } - ofy.save().entities(list); + + out.println("OK"); } } diff --git a/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/util/StringUtils.java b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/util/StringUtils.java new file mode 100644 index 00000000..87e58f9d --- /dev/null +++ b/liste-envies-war/src/main/java/fr/desaintsteban/liste/envies/util/StringUtils.java @@ -0,0 +1,67 @@ +package fr.desaintsteban.liste.envies.util; + +public class StringUtils { + private StringUtils() { + } + + private static String accents = "àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ"; + private static String withoutAccent = "aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY"; + + public static String withoutAccent(String txt) { + if (txt == null) { + return ""; + } + StringBuilder sb = new StringBuilder(); + int n = txt.length(); + for (int i = 0; i < n; i++) { + char c = txt.charAt(i); + int pos = accents.indexOf(c); + if (pos > -1) { + sb.append(withoutAccent.charAt(pos)); + } else if (c == 'œ' || c == 'Œ') { + sb.append("oe"); + } else if (c == 'æ' || c == 'Æ') { + sb.append("ae"); + } else { + sb.append(c); + } + } + return sb.toString(); + } + + public static String withoutAccentToUpperCase(String txt) { + return withoutAccent(txt).toUpperCase(); + } + + public static String toValidIdName(String name) { + return withoutAccent(name).replaceAll("[^-a-zA-Z0-9/]+", "-").toLowerCase(); + } + + public static String toValidIdFromName(String name) { + return withoutAccent(name.trim()).toLowerCase().replaceAll("[^-a-z0-9/]+", "-"); + } + + public static String toSearchString(String string) { + if (isNullOrEmpty(string)) + return ""; + return withoutAccentToUpperCase(string.trim()).replaceAll("[^A-Z0-9]+", " ").trim(); + } + + public static String upperFirstLetter(String content) { + if (content.length() > 1) { + return content.substring(0, 1).toUpperCase() + content.substring(1); + } else { + return content.toUpperCase(); + } + } + + public static String n2br(String text) { + if (isNullOrEmpty(text)) + return text; + return text.replaceAll("(\r\n|\n\r|\r|\n)", "
"); + } + + public static boolean isNullOrEmpty(String text) { + return text == null || text.isEmpty(); + } +} \ No newline at end of file diff --git a/liste-envies-war/src/main/webapp/css/style.css b/liste-envies-war/src/main/webapp/css/style.css index 88c611bc..b110ac84 100644 --- a/liste-envies-war/src/main/webapp/css/style.css +++ b/liste-envies-war/src/main/webapp/css/style.css @@ -1,13 +1,26 @@ .edit-button { display: none; position: absolute; - bottom: 31px; + top: 31px; right: 24px; } .comment-textarea { } +.title .btn { + display: none; +} +.title:hover .btn { + display: inline-block !important; +} + +.title-edit { + font-size: 36px; + width: auto; + outline: none; + padding: 0; +} .list-envie .envie-item:hover .edit-button { display: block !important; @@ -130,6 +143,11 @@ color: #5f5e5e; } +.links-editor input { + width: 44%; + display: inline-block; +} + .spin { -webkit-animation: spin .4s infinite linear; diff --git a/liste-envies-war/src/main/webapp/index.html b/liste-envies-war/src/main/webapp/index.html index 826361ca..0585e901 100644 --- a/liste-envies-war/src/main/webapp/index.html +++ b/liste-envies-war/src/main/webapp/index.html @@ -47,6 +47,7 @@ {{main.user.name}}