Skip to content

Commit

Permalink
conference session and some test work
Browse files Browse the repository at this point in the history
  • Loading branch information
will1771 committed Mar 5, 2015
1 parent f03ecf7 commit bb072d2
Show file tree
Hide file tree
Showing 13 changed files with 275 additions and 44 deletions.
2 changes: 1 addition & 1 deletion DockerHostVagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", inline:
"ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill"

config.vm.network :forwarded_port, host: 8080, guest: 8080
#config.vm.network :forwarded_port, host: 8080, guest: 8080
config.vm.network :forwarded_port, host: 5432, guest: 5432
end
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
<artifactId>postgresql</artifactId>
<version>9.3-1101-jdbc41</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
55 changes: 55 additions & 0 deletions scripts/dummy_data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
INSERT INTO conf_admin.location(
name, short_desc, full_desc, parking_info, create_dttm, last_update_dttm)
VALUES ('Sample Location', 'short', 'full', 'no parking', CURRENT_DATE, CURRENT_DATE);

INSERT INTO conf_admin.conference(
name, short_desc, full_desc, start_date, end_date, location_id,
create_dttm, last_update_dttm)
select 'Sample Conference', 'short desc', 'full desc', CURRENT_DATE - 1, CURRENT_DATE, location.id,
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
from conf_admin.location where location.name = 'Sample Location';

INSERT INTO conf_admin.room(
short_desc, full_desc, conference_id)
select 'Short Description', 'Full Description', conference.id
from conf_admin.conference where conference.name = 'Sample Conference';

INSERT INTO conf_admin.presenter(
user_id, short_bio, job_title, company_affiliation_id)
VALUES (null, 'short bio', 'sample title', null);

INSERT INTO conf_admin.conference_session(
name, short_desc, full_desc, conference_id, conference_session_type_id,
room_id, start_dttm, duration, create_dttm, last_update_dttm,
conference_session_presenter_id)
SELECT 'Session name', 'short desc', 'full desc', conference.id, null,
room.id, CURRENT_DATE, 30, CURRENT_DATE, CURRENT_DATE,
null
from conf_admin.conference,conf_admin.room where conference.name = 'Sample Conference' and room.short_desc = 'Short Description';

INSERT INTO conf_admin.conference_session_presenter(
conference_session_id, presenter_id)
select conference_session.id, presenter.id
from conf_admin.presenter, conf_admin.conference_session
where presenter.job_title = 'sample title' and conference_session.name = 'Session name';



/*
select * from conf_admin.conference;
select * from conf_admin.location;
select * from conf_admin.presenter;
select * from conf_admin.room;
select * from conf_admin.conference_session;
select * from conf_admin.conference_session_presenter;
select * from conf_admin.conference;
delete from conf_admin.conference_session_presenter cascade;
delete from conf_admin.conference_session cascade;
delete from conf_admin.room cascade;
delete from conf_admin.conference cascade;
delete from conf_admin.location cascade;
delete from conf_admin.presenter cascade;
delete from conf_admin.conference cascade;
*/

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.ioextendedgr.web.builder;

import com.ioextendedgr.web.data.Conference;
import com.ioextendedgr.web.data.ConferenceSession;
import com.ioextendedgr.web.data.ConferenceSessionPresenter;
import com.ioextendedgr.web.viewDto.ConferenceSessionView;
import com.ioextendedgr.web.viewDto.ConferenceView;
import org.springframework.util.CollectionUtils;

import java.util.*;

/**
* Created by Scott Williams on 3/4/2015.
*/
public class ConferenceSessionBuilder {

public static List<ConferenceSessionView> build(Collection<ConferenceSession> datas) {
if (CollectionUtils.isEmpty(datas)) {
return new ArrayList<>();
}

List<ConferenceSessionView> views = new ArrayList<>();
for (ConferenceSession data : datas) {
views.add(build(data));
}
return views;
}


public static ConferenceSessionView build(ConferenceSession data) {
if (data == null)
return null;

ConferenceSessionView view = new ConferenceSessionView();

view.setId(data.getId());
view.setName(data.getName());
view.setConferenceId(data.getConference().getId());
view.setDurationMinutes(data.getDuration());
view.setShortDesc(data.getShortDesc());
view.setFullDesc(data.getFullDesc());
view.setCreateDttm(data.getCreateDttm());
view.setLastUpdateDttm(data.getLastUpdateDttm());
Set<Integer> cspIds = new HashSet<>();
for(ConferenceSessionPresenter csp: data.getConferenceSessionPresenters()){
cspIds.add(csp.getId());
}
view.setPresenterIds(new ArrayList<>(cspIds));
view.setRoomId(data.getRoom().getId());
view.setStartDttm(data.getStartDttm());

return view;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ConferenceView findConferenceById(@PathVariable("id") Integer id) {
}

@RequestMapping("/conference/{id}/conferenceSessions")
public Collection<ConferenceSessionView> findConferenceSessionsByConferenceId(@PathVariable("id") Long id) {
public Collection<ConferenceSessionView> findConferenceSessionsByConferenceId(@PathVariable("id") Integer id) {
return conferenceService.findConferenceSessionsByConferenceId(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
import com.ioextendedgr.web.viewDto.ConferenceSessionView;

@RestController
@RequestMapping("/api")
@RequestMapping("/api/conferenceSession")
public class ConferenceSessionController {

@Autowired
private ConferenceService conferenceService;

@RequestMapping("/conferenceSession")
@RequestMapping("")
public Collection<ConferenceSessionView> findAllConferenceSessions() {
return conferenceService.findAllConferenceSessions();
}

@RequestMapping("/conferenceSession/{id}")
public ConferenceSessionView findConferenceSessionById(@PathVariable("id") Long id) {
@RequestMapping("/{id}")
public ConferenceSessionView findConferenceSessionById(@PathVariable("id") Integer id) {
return conferenceService.findConferenceSessionById(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ioextendedgr.web.repository;

import com.ioextendedgr.web.data.ConferenceSession;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

/**
* Created by Scott Williams on 3/4/2015.
*/
public interface ConferenceSessionRepository extends JpaRepository<ConferenceSession, Integer> {

public List<ConferenceSession> findByConferenceId(Integer id);

}
15 changes: 10 additions & 5 deletions src/main/java/com/ioextendedgr/web/service/ConferenceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.Collection;

import com.ioextendedgr.web.builder.ConferenceSessionBuilder;
import com.ioextendedgr.web.repository.ConferenceSessionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -21,6 +23,9 @@ public class ConferenceService {
@Autowired
private ConferenceRepository conferenceRepository;

@Autowired
private ConferenceSessionRepository conferenceSessionRepository;

public Collection<ConferenceView> findAllConferences() {
return ConferenceViewBuilder.build(conferenceRepository.findAll());
}
Expand All @@ -38,15 +43,15 @@ public PresenterView findPresenterById(Long id) {
}

public Collection<ConferenceSessionView> findAllConferenceSessions() {
return stubFactory.findAllConferenceSessions();
return ConferenceSessionBuilder.build(conferenceSessionRepository.findAll());
}

public ConferenceSessionView findConferenceSessionById(Long id) {
return stubFactory.findConferenceSessionById(id);
public ConferenceSessionView findConferenceSessionById(Integer id) {
return ConferenceSessionBuilder.build(conferenceSessionRepository.findOne(id));
}

public Collection<ConferenceSessionView> findConferenceSessionsByConferenceId(Long id) {
return stubFactory.findConferenceSessionsByConferenceId(id);
public Collection<ConferenceSessionView> findConferenceSessionsByConferenceId(Integer id) {
return ConferenceSessionBuilder.build(conferenceSessionRepository.findByConferenceId(id));
}

}
40 changes: 20 additions & 20 deletions src/main/java/com/ioextendedgr/web/util/StubFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
@Component
public class StubFactory {

Map<Long, ConferenceView> conferenceViewsByIdMap = new HashMap<Long, ConferenceView>();
Map<Long, PresenterView> presenterViewsByIdMap = new HashMap<Long, PresenterView>();
Map<Long, ConferenceSessionView> conferenceSessionByIdMap = new HashMap<Long, ConferenceSessionView>();
Map<Integer, ConferenceView> conferenceViewsByIdMap = new HashMap<Integer, ConferenceView>();
Map<Integer, PresenterView> presenterViewsByIdMap = new HashMap<Integer, PresenterView>();
Map<Integer, ConferenceSessionView> conferenceSessionByIdMap = new HashMap<Integer, ConferenceSessionView>();

public StubFactory() {
init();
Expand Down Expand Up @@ -84,15 +84,15 @@ private void initializeConferenceSessions() {
private void initializePresenterViews() {
List<PresenterView> presenterViews = createPresenterViews();
for (PresenterView currPresenterView : presenterViews) {
presenterViewsByIdMap.put(currPresenterView.getId(), currPresenterView);
presenterViewsByIdMap.put(currPresenterView.getId().intValue(), currPresenterView);
}

}

private void initializeConferenceViews() {
List<ConferenceView> createConferenceViews = createConferenceViews();
for (ConferenceView currConferenceView : createConferenceViews) {
conferenceViewsByIdMap.put(currConferenceView.getId(), currConferenceView);
conferenceViewsByIdMap.put(currConferenceView.getId().intValue(), currConferenceView);
}
}

Expand Down Expand Up @@ -121,45 +121,45 @@ private List<PresenterView> createPresenterViews() {

private ConferenceSessionView toConferenceSessionView(int index) {
ConferenceSessionView dto = new ConferenceSessionView();
List<Long> conferenceIds = new ArrayList<Long>(conferenceViewsByIdMap.keySet());
List<Long> presenterIds = new ArrayList<Long>(presenterViewsByIdMap.keySet());

List<Integer> conferenceIds = new ArrayList<Integer>(conferenceViewsByIdMap.keySet());
List<Integer> presenterIds = new ArrayList<Integer>(presenterViewsByIdMap.keySet());

Random random = new Random();
dto.setId(Long.valueOf(50 + index));

dto.setId(50 + index);
dto.setConferenceId(conferenceIds.get(random.nextInt(conferenceIds.size())));
dto.setCreateDttm(new Date());
dto.setDurationMinutes((index % 2 == 0) ? 30 : 60);
dto.setFullDesc(format("Full description of the session talk for session: %d", dto.getId()));
dto.setLastUpdateDttm(new Date());
dto.setName(format("Name of Session for %d", dto.getId()));
List<Long> selectedPresenterIds = null;

List<Integer> selectedPresenterIds = null;
if (index % 2 == 0) {
selectedPresenterIds = toSinglePresenterIdList(random, presenterIds);
} else {
selectedPresenterIds = toMultiplePresenterIdsList(random, presenterIds);
}
dto.setPresenterIds(selectedPresenterIds);
dto.setRoomId(-1L);
dto.setRoomId(-1);
dto.setShortDesc(format("Short Description Session: %d", dto.getId()));
dto.setStartDttm(new Date());

return dto;
}

private List<Long> toMultiplePresenterIdsList(Random random, List<Long> presenterIds) {
Set<Long> presenterIdSet = new HashSet<Long>();
private List<Integer> toMultiplePresenterIdsList(Random random, List<Integer> presenterIds) {
Set<Integer> presenterIdSet = new HashSet<Integer>();
presenterIdSet.add(presenterIds.get(random.nextInt(presenterIds.size())));
presenterIdSet.add(presenterIds.get(random.nextInt(presenterIds.size())));
presenterIdSet.add(presenterIds.get(random.nextInt(presenterIds.size())));
presenterIdSet.add(presenterIds.get(random.nextInt(presenterIds.size())));
return new ArrayList<Long>(presenterIdSet);
return new ArrayList<Integer>(presenterIdSet);
}

private List<Long> toSinglePresenterIdList(Random random, List<Long> presenterIds) {
List<Long> presenterIdList = new ArrayList<Long>();
private List<Integer> toSinglePresenterIdList(Random random, List<Integer> presenterIds) {
List<Integer> presenterIdList = new ArrayList<Integer>();
presenterIdList.add(presenterIds.get(random.nextInt(presenterIds.size())));
return presenterIdList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@

public class ConferenceSessionView {

private Long id;
private Integer id;
private String name;
private String shortDesc;
private String fullDesc;
private Long conferenceId;
private List<Long> presenterIds;
private Long roomId;
private Integer conferenceId;
private List<Integer> presenterIds;
private Integer roomId;
private Date startDttm;
private Integer durationMinutes;
private Date createDttm;
private Date lastUpdateDttm;


public Long getId() {
public Integer getId() {
return id;
}
public void setId(Long id) {
public void setId(Integer id) {
this.id = id;
}
public String getName() {
Expand All @@ -42,22 +42,22 @@ public String getFullDesc() {
public void setFullDesc(String fullDesc) {
this.fullDesc = fullDesc;
}
public Long getConferenceId() {
public Integer getConferenceId() {
return conferenceId;
}
public void setConferenceId(Long conferenceId) {
public void setConferenceId(Integer conferenceId) {
this.conferenceId = conferenceId;
}
public List<Long> getPresenterIds() {
public List<Integer> getPresenterIds() {
return presenterIds;
}
public void setPresenterIds(List<Long> presenterIds) {
public void setPresenterIds(List<Integer> presenterIds) {
this.presenterIds = presenterIds;
}
public Long getRoomId() {
public Integer getRoomId() {
return roomId;
}
public void setRoomId(Long roomId) {
public void setRoomId(Integer roomId) {
this.roomId = roomId;
}
public Date getStartDttm() {
Expand Down

0 comments on commit bb072d2

Please sign in to comment.