Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add videos field to speaker #118

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions migrate-add-videos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE USER ADD COLUMN VIDEOS VARCHAR(255);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, sometimes URLs are huge and with the comma separated approach 255 might not b enough in some cases

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made it VARCHAR(1024)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@I-Mircheva why do we need this SQL ? The schema should be updated automatically anyway.

12 changes: 9 additions & 3 deletions src/main/java/site/controller/AbstractCfpController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -15,17 +14,21 @@
import site.facade.MailService;
import site.facade.ThumbnailService;
import site.facade.UserService;
import site.facade.VideoSanitizerService;
import site.model.Branch;
import site.model.SessionLevel;
import site.model.SessionType;
import site.model.Speaker;
import site.model.Submission;
import site.model.SessionType;

/**
* @author Ivan St. Ivanov
*/
public class AbstractCfpController {


@Autowired
gochev marked this conversation as resolved.
Show resolved Hide resolved
private VideoSanitizerService videoSanitizerService;

@Autowired
@Qualifier(UserService.NAME)
protected UserService userFacade;
Expand Down Expand Up @@ -75,6 +78,9 @@ private Speaker handleSubmittedSpeaker(Speaker speaker, MultipartFile image) {
fixTwitterHandle(speaker);
speaker.setBranch(Globals.CURRENT_BRANCH);
formatPicture(speaker, image);
if(speaker.getVideos() != null) {
gochev marked this conversation as resolved.
Show resolved Hide resolved
speaker.setVideos(videoSanitizerService.formatString(speaker.getVideos()));
}
return speaker;
}
}
Expand Down
37 changes: 33 additions & 4 deletions src/main/java/site/facade/AdminService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package site.facade;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -9,17 +11,40 @@
import org.springframework.stereotype.Service;

import site.config.Globals;
import site.model.*;
import site.repository.*;

import java.util.List;
import site.model.Article;
import site.model.Branch;
import site.model.Partner;
import site.model.Registrant;
import site.model.Session;
import site.model.Speaker;
import site.model.Sponsor;
import site.model.Submission;
import site.model.SubmissionStatus;
import site.model.Tag;
import site.model.User;
import site.model.VenueHall;
import site.model.Visitor;
import site.repository.ArticleRepository;
import site.repository.PartnerRepository;
import site.repository.RegistrantRepository;
import site.repository.SessionRepository;
import site.repository.SpeakerRepository;
import site.repository.SponsorRepository;
import site.repository.SubmissionRepository;
import site.repository.TagRepository;
import site.repository.UserRepository;
import site.repository.VenueHallRepository;
import site.repository.VisitorRepository;

@Service(AdminService.NAME)
@Transactional
public class AdminService {

public static final String NAME = "adminFacade";

@Autowired
private VideoSanitizerService videoSanitizerService;

@Autowired
@Qualifier(ArticleRepository.NAME)
private ArticleRepository articleRepository;
Expand Down Expand Up @@ -141,6 +166,10 @@ public void deleteSpeaker(Long id){
}

public Speaker saveSpeaker(Speaker speaker){
if(speaker.getVideos() != null)
speaker.setVideos(videoSanitizerService.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing { }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed formatting and {}

formatString(speaker.getVideos()));

return speakerRepository.save(speaker);
}

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/site/facade/CSVService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CSVService {
private static final Logger logger = LogManager.getLogger(CSVService.class);
public static final String NAME = "csvFacade";
final String[] submissionHeader = new String[] { "Title", "Abstract", "Session level", "Session type", "Speaker Name", "Speaker Bio",
"Co-Speaker Name", "Co-Speaker Bio" };
"Co-Speaker Name", "Co-Speaker Bio" , "Speaker Videos", "Co-Speaker Videos"};

public File exportSubmissions(List<Submission> submissions) throws IOException{
File submissionsCSVFile = File.createTempFile("submissions.", ".csv");
Expand All @@ -34,7 +34,7 @@ public File exportSubmissions(List<Submission> submissions) throws IOException{
}

private void writeSubmissions(List<Submission> submissions, ICsvMapWriter mapWriter) throws IOException{
CellProcessor[] processors = new CellProcessor[] {null, null, null, null, null, null, null, null};
CellProcessor[] processors = new CellProcessor[] {null, null, null, null, null, null, null, null, null, null};
Map<String, Object> submissionRow;
mapWriter.writeHeader(submissionHeader);

Expand All @@ -50,6 +50,11 @@ private void writeSubmissions(List<Submission> submissions, ICsvMapWriter mapWri
submissionRow.put(submissionHeader[6], submission.getCoSpeaker().getFirstName());
submissionRow.put(submissionHeader[7], submission.getCoSpeaker().getBio());
}
submissionRow.put(submissionHeader[8] , submission.getSpeaker().getVideos());
if(submission.getCoSpeaker() != null) {
submissionRow.put(submissionHeader[9] , submission.getCoSpeaker().getVideos());
}

mapWriter.write(submissionRow, submissionHeader, processors);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/site/facade/VideoSanitizerService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package site.facade;

import org.springframework.stereotype.Service;

@Service
public class VideoSanitizerService {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like Util method for me. Also it doesn't work with a Video actually, it is more like working with a String name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: Not a service anymore, but a class StringSanitizer


public String formatString(String video) {
return video.replaceAll("(\t|\n|,| |;)+", " ");
}
}
29 changes: 25 additions & 4 deletions src/main/java/site/model/Speaker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package site.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -13,31 +16,31 @@

import site.config.Globals;

import java.util.HashSet;
import java.util.Set;

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Speaker extends User {

/**
*
*/

private static final long serialVersionUID = 1L;

@Column(length = 1024)
private String bio;

private String headline;

private String twitter;
private String twitter;
gochev marked this conversation as resolved.
Show resolved Hide resolved

private Boolean featured = false;

private Boolean accepted = false;

@Lob
private byte[] picture;

private String videos;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why did you prefer to have them as comma separated values, instead of a List coming from a 1 to many relation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • We choose a String field as the forms when working with speaker would become too complicated
  • The admin panel for add/edit a speaker would be inconvenient

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@I-Mircheva can you make videos to be "videoLink" and to be just one URL mapped with

@column(length = 500)
private String videoLink;

for example so we dont need a migrate sql.


@OneToMany(mappedBy = "speaker", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, targetEntity = Submission.class)
private Set<Submission> submissions = new HashSet<>();
Expand All @@ -57,6 +60,17 @@ public Speaker(String firstName, String lastName, String email, String headline,
this.featured = featured;
this.accepted = accepted;
}

public Speaker(String firstName, String lastName, String email, String headline, String twitter, boolean featured, boolean accepted, String videos) {
setFirstName(firstName);
setLastName(lastName);
setEmail(email);
this.headline = headline;
this.twitter = twitter;
this.featured = featured;
this.accepted = accepted;
setVideos(videos);
}

public byte[] getPicture() {
return picture;
Expand All @@ -81,6 +95,13 @@ public String getBio() {
public void setBio(String bio) {
this.bio = bio;
}

public String getVideos() {
return videos;
}
public void setVideos(String videos) {
this.videos = videos;
}

public String getTwitter() {
return twitter;
Expand Down
8 changes: 8 additions & 0 deletions src/main/webapp/WEB-INF/tags/user/speaker.tag
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
<form:textarea path="${role}.bio" style="width:80%" rows="5" />
</dd>
</dl>
<dl>
<dt>
<label for="${role}.videos">Video</label>
</dt>
<dd>
<form:textarea path="${role}.videos" style="width:80%" rows="3" />
</dd>
</dl>
<dl>
<dt>
<label for="${role}Image">Image</label>
Expand Down
8 changes: 8 additions & 0 deletions src/main/webapp/admin/speaker/edit.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@
<input name="file" type="file" />
</dd>
</dl>
<dl>
<dt>
<label for="videos">Videos</label>
</dt>
<dd>
<form:input path="videos" />
</dd>
</dl>
<sec:csrfInput />
<form:hidden path="id" />
<form:hidden path="createdDate" />
Expand Down
2 changes: 2 additions & 0 deletions src/main/webapp/admin/speaker/view.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<td><i>Accepted?</i></td>
<td><i>Branch?</i></td>
<td><i>Picture</i></td>
<td><i>Video</i></td>
<td><i>Operations</i></td>
</tr>
<c:forEach var="speaker" items="${speakers.content}">
Expand All @@ -42,6 +43,7 @@
<td>${speaker.accepted}</td>
<td>${speaker.branch}</td>
<td><img src="/image/speaker/${speaker.id}" style="max-width: 280px"/></td>
<td>${speaker.videos}</td>
<td>
<span style="float:left;"><a href="/admin/speaker/edit/${speaker.id}">Edit</a></span> &nbsp;
<span style="float:right;"><a href="/admin/speaker/remove/${speaker.id}"> Remove </a></span>
Expand Down
4 changes: 4 additions & 0 deletions src/main/webapp/admin/submission/view.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
<td><i>Level</i></td>
<td><i>Type</i></td>
<td><i>Speaker</i></td>
<td><i>Speaker video</i></td>
<td><i>Co-Speaker</i></td>
<td><i>Co-Speaker video</i></td>
<td><i>Branch</i></td>
<td><i>Status</i></td>
<td><i>Operations</i></td>
Expand All @@ -45,7 +47,9 @@
<td>${submission.level}</td>
<td>${submission.type != null ? submission.type.toString() : "Conference session"}</td>
<td>${submission.speaker.firstName} ${submission.speaker.lastName}</td>
<td>${submission.speaker.videos}</td>
<td>${submission.coSpeaker.firstName} ${submission.coSpeaker.lastName}</td>
<td>${submission.coSpeaker.videos}</td>
<td>${submission.branch}</td>
<td>${submission.status}</td>
<td>
Expand Down
20 changes: 15 additions & 5 deletions src/main/webapp/speaker.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<a href="/speakers">Back</a><br/><br/>
<!-- Start Single Post Area -->
<div class="blog-post gallery-post">
<div class="blog-post gallery-post" style="margin-bottom: 10em;">
<div class="col-md-3 col-sm-6 col-xs-12 animated">
<div class="team-member modern">
<!-- Memebr Photo, Name & Position -->
Expand All @@ -64,10 +64,20 @@
</div>
</div>
</div>

<p>
<c:out value="${speaker.bio}"/>
</p>
<div>
<p>
<c:out value="${speaker.bio}"/>
</p>
</div>
</div>
<div>
<c:forEach items="${speaker.videos.split(' ')}" var="video">
<div style= "width: 50%; height:50%; margin-left: 30%; margin-top: 2%">
<iframe align = "centered"src="${video}"
frameborder="1" allow="autoplay; encrypted-media" allowfullscreen>
</iframe>
</div>
</c:forEach>
</div>
<!-- End Single Post Area -->
<!-- currently not needed!!
Expand Down
Loading