Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

Commit

Permalink
Add csv export with speaker email
Browse files Browse the repository at this point in the history
  • Loading branch information
alexthomazo authored and ndeloof committed Nov 8, 2017
1 parent fa4ace0 commit 60ba84c
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/io/cfp/controller/AdminSessionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@

package io.cfp.controller;

import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import com.itextpdf.text.DocumentException;
import io.cfp.domain.exception.CospeakerNotFoundException;
import io.cfp.dto.EventSched;
import io.cfp.dto.TalkAdmin;
import io.cfp.dto.TalkAdminCsv;
import io.cfp.entity.Event;
import io.cfp.entity.Role;
import io.cfp.entity.Talk;
Expand Down Expand Up @@ -178,4 +182,21 @@ public List<EventSched> exportSched(@RequestParam(required = false) Talk.State[]
}
return talkService.exportSched(states);
}

@RequestMapping(path = "/sessions/export/sessions.csv", produces = "text/csv")
@Secured(Role.ADMIN)
public void exportCsv(HttpServletResponse response, @RequestParam(name = "status", required = false) String status) throws IOException {
response.addHeader(HttpHeaders.CONTENT_TYPE, "text/csv");

CsvMapper mapper = new CsvMapper();
mapper.addMixIn(TalkAdmin.class, TalkAdminCsv.class);

CsvSchema schema = mapper.schemaFor(TalkAdmin.class).withHeader();
ObjectWriter writer = mapper.writer(schema);

List<TalkAdmin> sessions = getAllSessions(status);
for (TalkAdmin s : sessions) {
writer.writeValue(response.getOutputStream(), s);
}
}
}
21 changes: 21 additions & 0 deletions src/main/java/io/cfp/dto/TalkAdminCsv.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.cfp.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import io.cfp.dto.user.CospeakerProfil;
import io.cfp.dto.user.UserProfil;

import java.util.Set;

/**
* Allow CSV export to unwrap speaker
*/
public interface TalkAdminCsv {

@JsonUnwrapped
UserProfil getSpeaker();

@JsonIgnore
Set<CospeakerProfil> getCospeakers();

}
2 changes: 1 addition & 1 deletion src/main/java/io/cfp/dto/TalkUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public TalkUser(Talk t) {
this.references = t.getReferences();
this.difficulty = t.getDifficulty();
this.added = t.getAdded();
this.speaker = new UserProfil(t.getId(), t.getUser().getFirstname(), t.getUser().getLastname());
this.speaker = new UserProfil(t.getId(), t.getUser().getFirstname(), t.getUser().getLastname(), t.getUser().getEmail());
this.cospeakers = t.getCospeakers().stream().map( u -> new CospeakerProfil(u.getEmail()) ).collect(Collectors.toSet());
this.room = t.getRoom() != null ? t.getRoom().getId() : null;
if (t.getDate() != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/cfp/dto/user/UserProfil.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public UserProfil() {
super();
}

public UserProfil(int id, String firstname, String lastname) {
public UserProfil(int id, String firstname, String lastname, String email) {
super();
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
}

public UserProfil(User user, boolean includePrivateData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void setup() {
public void testGetScheduleList() throws Exception {

// Given
UserProfil userProfil = new UserProfil(0,"John", "Doe");
UserProfil userProfil = new UserProfil(0, "John", "Doe", "john@doe.net");
// TalkUser 1
TalkUser talkUser1 = new TalkUser();
talkUser1.setId(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void setup() throws IOException {
talkUser.setId(1);
talkUser.setName("My amazing user talk 1");

UserProfil speaker = new UserProfil(0, "john", "Doe");
UserProfil speaker = new UserProfil(0, "john", "Doe", "john@doe.net");
speaker.setEmail(JOHN_DOE_EMAIL);
talkUser.setSpeaker(speaker);

Expand Down

0 comments on commit 60ba84c

Please sign in to comment.