Skip to content

Commit

Permalink
Merge branch 'feature/changePresenter' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasrob committed May 16, 2015
2 parents def68be + 41f17dd commit d65b521
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 262 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Expand Up @@ -69,6 +69,10 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
</dependencies>
<properties>
<start-class>com.ioextendedgr.web.Application</start-class>
Expand Down
55 changes: 45 additions & 10 deletions src/main/java/com/ioextendedgr/web/builder/PresenterBuilder.java
Expand Up @@ -4,33 +4,68 @@
import java.util.Collection;
import java.util.List;

import com.ioextendedgr.web.data.Company;
import org.apache.commons.collections.CollectionUtils;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.ioextendedgr.web.data.Presenter;
import com.ioextendedgr.web.viewDto.CompanyView;
import com.ioextendedgr.web.data.User;
import com.ioextendedgr.web.viewDto.PresenterView;

public class PresenterBuilder {

public static Collection<PresenterView> build(Collection<Presenter> dtos) {
public static Collection<PresenterView> build(Collection<Presenter> dtos,
Collection<User> userDtos) {
List<PresenterView> presenters = new ArrayList<PresenterView>();

for (Presenter currPresenter : dtos) {
presenters.add(build(currPresenter));
User user = findUserById(currPresenter.getId(), userDtos);
presenters.add(build(currPresenter, user));
}

return presenters;
}
public static PresenterView build(Presenter dto) {

public static PresenterView build(Presenter dto, User userDto) {
PresenterView presenter = new PresenterView();

presenter.setCompanyView(CompanyBuilder.build(dto.getCompany()));
presenter.setId(dto.getId());
presenter.setJobTitle(dto.getJobTitle());
presenter.setShortBio(dto.getShortBio());
presenter.setUserId(dto.getUserId());


if (userDto != null) {
presenter.setFirstName(userDto.getFirstName());
presenter.setLastName(userDto.getLastName());
presenter.setEmail(userDto.getEmailAddress());
}

return presenter;
}

private static User findUserById(final Integer id,
Collection<User> userDatas) {

if (id == null) {
return null;
}

Collection<User> items = Collections2.filter(userDatas,
new Predicate<User>() {

@Override
public boolean apply(User input) {
return id.equals(input.getId());
}
});

if (CollectionUtils.isEmpty(items)) {
return null;
}

return items.iterator().next();

}

}
16 changes: 0 additions & 16 deletions src/main/java/com/ioextendedgr/web/data/ConferenceSession.java
Expand Up @@ -173,22 +173,6 @@ public void setConferenceSessionPresenters(
this.conferenceSessionPresenters = conferenceSessionPresenters;
}

public ConferenceSessionPresenter addConferenceSessionPresenter(
ConferenceSessionPresenter conferenceSessionPresenter) {
getConferenceSessionPresenters().add(conferenceSessionPresenter);
conferenceSessionPresenter.setConferenceSession(this);

return conferenceSessionPresenter;
}

public ConferenceSessionPresenter removeConferenceSessionPresenter(
ConferenceSessionPresenter conferenceSessionPresenter) {
getConferenceSessionPresenters().remove(conferenceSessionPresenter);
conferenceSessionPresenter.setConferenceSession(null);

return conferenceSessionPresenter;
}

public List<ConferenceSessionRegistration> getConferenceSessionRegistrations() {
return this.conferenceSessionRegistrations;
}
Expand Down
@@ -1,15 +1,13 @@
package com.ioextendedgr.web.data;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
Expand All @@ -25,10 +23,6 @@ public class ConferenceSessionPresenter implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

// bi-directional many-to-one association to ConferenceSession
@OneToMany(mappedBy = "conferenceSessionPresenter")
private List<ConferenceSession> conferenceSessions;

// bi-directional many-to-one association to ConferenceSession
@ManyToOne
@JoinColumn(name = "conference_session_id")
Expand All @@ -49,14 +43,6 @@ public void setId(Integer id) {
this.id = id;
}

public List<ConferenceSession> getConferenceSessions() {
return this.conferenceSessions;
}

public void setConferenceSessions(List<ConferenceSession> conferenceSessions) {
this.conferenceSessions = conferenceSessions;
}

public ConferenceSession getConferenceSession() {
return this.conferenceSession;
}
Expand Down
@@ -0,0 +1,9 @@
package com.ioextendedgr.web.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.ioextendedgr.web.data.User;

public interface UserRepository extends JpaRepository<User, Integer> {

}

0 comments on commit d65b521

Please sign in to comment.