Commit 9fcd6a9d by Tuomas Riihimäki

Lisätty CSV exporttiin käyttäjän paikka.

1 parent dd3cb56c
...@@ -16,12 +16,15 @@ import org.slf4j.Logger; ...@@ -16,12 +16,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.web.cdiview.GenericCDIView; import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named @Named
@ConversationScoped @ConversationScoped
public class UserCartView extends GenericCDIView { public class UserCartView extends GenericCDIView {
private static final String CSV_SEPARATOR = ";";
private static final long serialVersionUID = 5294631925744474031L; private static final long serialVersionUID = 5294631925744474031L;
private static final Charset UTF8 = Charset.forName("UTF-8"); private static final Charset UTF8 = Charset.forName("UTF-8");
...@@ -38,25 +41,34 @@ public class UserCartView extends GenericCDIView { ...@@ -38,25 +41,34 @@ public class UserCartView extends GenericCDIView {
public StreamedContent getDownloadCsv() { public StreamedContent getDownloadCsv() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("firstname").append(";"); sb.append("firstname").append(CSV_SEPARATOR);
sb.append("lastname").append(";"); sb.append("lastname").append(CSV_SEPARATOR);
sb.append("nick").append(";"); sb.append("nick").append(CSV_SEPARATOR);
sb.append("login").append(";"); sb.append("login").append(CSV_SEPARATOR);
sb.append("birthday").append(";"); sb.append("birthday").append(CSV_SEPARATOR);
sb.append("phone").append(";"); sb.append("phone").append(CSV_SEPARATOR);
sb.append("email").append(";"); sb.append("email").append(CSV_SEPARATOR);
sb.append("places").append(CSV_SEPARATOR);
sb.append("\n"); sb.append("\n");
for (EventUser uc : usercart) for (EventUser uc : usercart)
{ {
sb.append(uc.getFirstnames()).append(";"); sb.append(uc.getFirstnames()).append(CSV_SEPARATOR);
sb.append(uc.getLastname()).append(";"); sb.append(uc.getLastname()).append(CSV_SEPARATOR);
sb.append(uc.getNick()).append(";"); sb.append(uc.getNick()).append(CSV_SEPARATOR);
sb.append(uc.getLogin()).append(";"); sb.append(uc.getLogin()).append(CSV_SEPARATOR);
sb.append(uc.getBirthday() != null ? dateformat.format(uc.getBirthday()) : "").append(";"); sb.append(uc.getBirthday() != null ? dateformat.format(uc.getBirthday()) : "").append(CSV_SEPARATOR);
sb.append(uc.getPhone()).append(";"); sb.append(uc.getPhone()).append(CSV_SEPARATOR);
sb.append(uc.getEmail()).append(";"); sb.append(uc.getEmail()).append(CSV_SEPARATOR);
sb.append("\n"); for (GroupMembership gm : uc.getGroupMemberships())
{
if (gm.getPlaceReservation() != null)
{
sb.append(gm.getPlaceReservation().getName()).append(", ");
}
}
sb.append(CSV_SEPARATOR);
sb.append("\n");
} }
DefaultStreamedContent ret = new DefaultStreamedContent(new ByteArrayInputStream(sb.toString().getBytes(UTF8))); DefaultStreamedContent ret = new DefaultStreamedContent(new ByteArrayInputStream(sb.toString().getBytes(UTF8)));
ret.setContentType("text/csv"); ret.setContentType("text/csv");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!