Sfoglia il codice sorgente

Merge 2b3b762e49db319fc99850eb0f79dd410ebd0c87 into f91a622cc731197181dd1b1e4b17c9bcb450ae8a

Katherine 8 anni fa
parent
commit
6c1d70140d
No account linked to committer's email
18 ha cambiato i file con 660 aggiunte e 0 eliminazioni
  1. 49
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java
  2. 71
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java
  3. 32
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java
  4. 39
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java
  5. 55
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java
  6. 37
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java
  7. 23
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dto/OptionCount.java
  8. 25
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dto/VoteResult.java
  9. 63
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/ErrorDetail.java
  10. 23
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/ValidationError.java
  11. 20
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/exception/ResourceNotFoundException.java
  12. 82
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/handler/RestExceptionHandler.java
  13. 7
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repository/OptionRepository.java
  14. 8
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repository/PollRepository.java
  15. 11
    0
      src/main/java/io/zipcoder/tc_spring_poll_application/repository/VoteRepository.java
  16. 0
    0
      src/main/resources/application.properties
  17. 113
    0
      src/main/resources/import.sql
  18. 2
    0
      src/main/resources/messages.properties

+ 49
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/ComputeResultController.java Vedi File

@@ -0,0 +1,49 @@
1
+package io.zipcoder.tc_spring_poll_application.controller;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
4
+import io.zipcoder.tc_spring_poll_application.dto.OptionCount;
5
+import io.zipcoder.tc_spring_poll_application.dto.VoteResult;
6
+import io.zipcoder.tc_spring_poll_application.repository.VoteRepository;
7
+import org.springframework.http.HttpStatus;
8
+import org.springframework.http.ResponseEntity;
9
+import org.springframework.web.bind.annotation.RequestMapping;
10
+import org.springframework.web.bind.annotation.RequestMethod;
11
+import org.springframework.web.bind.annotation.RequestParam;
12
+import org.springframework.web.bind.annotation.RestController;
13
+
14
+import javax.inject.Inject;
15
+import java.util.HashMap;
16
+import java.util.Map;
17
+
18
+@RestController
19
+public class ComputeResultController {
20
+
21
+    @Inject
22
+    private VoteRepository voteRepository;
23
+
24
+    @RequestMapping(value="/computeresult", method= RequestMethod.GET)
25
+    public ResponseEntity<?> computeResult(@RequestParam Long pollId) {
26
+        VoteResult voteResult = new VoteResult();
27
+        Iterable<Vote> allVotes = voteRepository.findByPoll(pollId);
28
+        countVotes(voteResult, allVotes);
29
+        return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
30
+    }
31
+
32
+    private void countVotes(VoteResult voteResult, Iterable<Vote> allVotes) {
33
+        int totalVotes = 0;
34
+        Map<Long, OptionCount> tempMap = new HashMap<Long, OptionCount>();
35
+        for(Vote v : allVotes) {
36
+            totalVotes ++;
37
+
38
+            OptionCount optionCount = tempMap.get(v.getOption().getId());
39
+            if(optionCount == null) {
40
+                optionCount = new OptionCount();
41
+                optionCount.setOptionId(v.getOption().getId());
42
+                tempMap.put(v.getOption().getId(), optionCount);
43
+            }
44
+            optionCount.setCount(optionCount.getCount()+1);
45
+        }
46
+        voteResult.setTotalVotes(totalVotes);
47
+        voteResult.setResults(tempMap.values());
48
+    }
49
+}

+ 71
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/PollController.java Vedi File

@@ -0,0 +1,71 @@
1
+package io.zipcoder.tc_spring_poll_application.controller;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Poll;
4
+import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
5
+import io.zipcoder.tc_spring_poll_application.repository.PollRepository;
6
+import org.springframework.data.domain.Page;
7
+import org.springframework.data.domain.Pageable;
8
+import org.springframework.http.HttpHeaders;
9
+import org.springframework.http.HttpStatus;
10
+import org.springframework.http.ResponseEntity;
11
+import org.springframework.web.bind.annotation.*;
12
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
13
+
14
+import javax.inject.Inject;
15
+import javax.validation.Valid;
16
+import java.net.URI;
17
+
18
+@RestController
19
+public class PollController {
20
+
21
+    @Inject
22
+    private PollRepository pollRepository;
23
+
24
+    protected void verifyPoll(Long pollId) throws ResourceNotFoundException {
25
+        Poll poll = pollRepository.findOne(pollId);
26
+        if(poll == null) {
27
+            throw new ResourceNotFoundException("Poll with id " + pollId + " not found");
28
+        } }
29
+
30
+    @RequestMapping(value = "/polls", method = RequestMethod.GET)
31
+    public ResponseEntity<Page<Poll>> getAllPolls(Pageable pageable) {
32
+        Page<Poll> allPolls = pollRepository.findAll(pageable);
33
+        return new ResponseEntity<>(allPolls, HttpStatus.OK);
34
+    }
35
+
36
+    @RequestMapping(value="/polls", method= RequestMethod.POST)
37
+    public ResponseEntity<?> createPoll(@Valid @RequestBody Poll poll) {
38
+
39
+        poll = pollRepository.save(poll);
40
+
41
+        HttpHeaders responseHeaders = new HttpHeaders();
42
+        URI newPollUri = ServletUriComponentsBuilder
43
+                .fromCurrentRequest()
44
+                .path("/{id}")
45
+                .buildAndExpand(poll.getId())
46
+                .toUri();
47
+        responseHeaders.setLocation(newPollUri);
48
+        return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
49
+    }
50
+
51
+    @RequestMapping(value="/polls/{pollId}", method= RequestMethod.GET)
52
+    public ResponseEntity<?> getPoll(@PathVariable Long pollId) {
53
+        verifyPoll(pollId);
54
+        Poll p = pollRepository.findOne(pollId);
55
+        return new ResponseEntity<>(p, HttpStatus.OK);
56
+    }
57
+
58
+    @RequestMapping(value="/polls/{pollId}", method= RequestMethod.PUT)
59
+    public ResponseEntity<?> updatePoll(@RequestBody Poll poll, @PathVariable Long pollId) {
60
+        verifyPoll(pollId);
61
+        pollRepository.save(poll);
62
+        return new ResponseEntity<>(HttpStatus.OK);
63
+    }
64
+
65
+    @RequestMapping(value="/polls/{pollId}", method= RequestMethod.DELETE)
66
+    public ResponseEntity<?> deletePoll(@PathVariable Long pollId) {
67
+        verifyPoll(pollId);
68
+        pollRepository.delete(pollId);
69
+        return new ResponseEntity<>(HttpStatus.OK);
70
+    }
71
+}

+ 32
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/controller/VoteController.java Vedi File

@@ -0,0 +1,32 @@
1
+package io.zipcoder.tc_spring_poll_application.controller;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
4
+import io.zipcoder.tc_spring_poll_application.repository.VoteRepository;
5
+import org.springframework.http.HttpHeaders;
6
+import org.springframework.http.HttpStatus;
7
+import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.*;
9
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
10
+
11
+import javax.inject.Inject;
12
+
13
+@RestController
14
+public class VoteController {
15
+    @Inject
16
+    private VoteRepository voteRepository;
17
+
18
+    @RequestMapping(value="/polls/{pollId}/votes", method= RequestMethod.POST)
19
+    public ResponseEntity<?> createVote(@PathVariable Long pollId, @RequestBody Vote vote) {
20
+        vote = voteRepository.save(vote);
21
+        HttpHeaders responseHeaders = new HttpHeaders();
22
+        responseHeaders.setLocation(ServletUriComponentsBuilder.
23
+                fromCurrentRequest().path("/{id}").buildAndExpand(vote.getId()).toUri());
24
+
25
+        return new ResponseEntity<>(null, responseHeaders, HttpStatus.CREATED);
26
+    }
27
+
28
+    @RequestMapping(value="/polls/{pollId}/votes", method= RequestMethod.GET)
29
+    public Iterable<Vote> getAllVotes(@PathVariable Long pollId) {
30
+        return voteRepository.findByPoll(pollId);
31
+    }
32
+}

+ 39
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Option.java Vedi File

@@ -0,0 +1,39 @@
1
+package io.zipcoder.tc_spring_poll_application.domain;
2
+
3
+import javax.persistence.Column;
4
+import javax.persistence.Entity;
5
+import javax.persistence.GeneratedValue;
6
+import javax.persistence.Id;
7
+
8
+@Entity
9
+public class Option {
10
+
11
+    @Id
12
+    @GeneratedValue
13
+    @Column(name = "OPTION_ID")
14
+    private Long id;
15
+
16
+    @Column(name = "OPTION_VALUE")
17
+    private String value;
18
+
19
+    public Long getId() {
20
+        return id;
21
+    }
22
+
23
+    public void setId(Long id) {
24
+        this.id = id;
25
+    }
26
+
27
+    public String getValue() {
28
+        return value;
29
+    }
30
+
31
+    public void setValue(String value) {
32
+        this.value = value;
33
+    }
34
+
35
+    @Override
36
+    public String toString() {
37
+        return getId() + "," + getValue();
38
+    }
39
+}

+ 55
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Poll.java Vedi File

@@ -0,0 +1,55 @@
1
+package io.zipcoder.tc_spring_poll_application.domain;
2
+
3
+import org.hibernate.validator.constraints.NotEmpty;
4
+
5
+import javax.persistence.*;
6
+import javax.validation.constraints.Size;
7
+import java.util.Set;
8
+
9
+@Entity
10
+public class Poll {
11
+
12
+    @Id
13
+    @GeneratedValue
14
+    @Column(name = "POLL_ID")
15
+    private Long id;
16
+
17
+    @Column(name = "QUESTION")
18
+    @NotEmpty
19
+    private String question;
20
+
21
+    @OneToMany(cascade = CascadeType.ALL)
22
+    @JoinColumn(name = "POLL_ID")
23
+    @OrderBy
24
+    @Size(min=2, max = 6)
25
+    private Set<Option> options;
26
+
27
+    public Long getId() {
28
+        return id;
29
+    }
30
+
31
+    public void setId(Long id) {
32
+        this.id = id;
33
+    }
34
+
35
+    public String getQuestion() {
36
+        return question;
37
+    }
38
+
39
+    public void setQuestion(String question) {
40
+        this.question = question;
41
+    }
42
+
43
+    public Set<Option> getOptions() {
44
+        return options;
45
+    }
46
+
47
+    public void setOptions(Set<Option> options) {
48
+        this.options = options;
49
+    }
50
+
51
+    @Override
52
+    public String toString() {
53
+        return getId() + ", " + getQuestion() + ", " + getOptions();
54
+    }
55
+}

+ 37
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/domain/Vote.java Vedi File

@@ -0,0 +1,37 @@
1
+package io.zipcoder.tc_spring_poll_application.domain;
2
+
3
+import javax.persistence.*;
4
+
5
+@Entity
6
+public class Vote {
7
+
8
+    @Id
9
+    @GeneratedValue
10
+    @Column(name = "VOTE_ID")
11
+    private Long id;
12
+
13
+    @ManyToOne
14
+    @JoinColumn(name = "OPTION_ID")
15
+    private Option option;
16
+
17
+    public Long getId() {
18
+        return id;
19
+    }
20
+
21
+    public void setId(Long id) {
22
+        this.id = id;
23
+    }
24
+
25
+    public Option getOption() {
26
+        return option;
27
+    }
28
+
29
+    public void setOption(Option option) {
30
+        this.option = option;
31
+    }
32
+
33
+    @Override
34
+    public String toString() {
35
+        return getId() + ", " + getOption();
36
+    }
37
+}

+ 23
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dto/OptionCount.java Vedi File

@@ -0,0 +1,23 @@
1
+package io.zipcoder.tc_spring_poll_application.dto;
2
+
3
+public class OptionCount {
4
+
5
+    private Long optionId;
6
+    private int count;
7
+
8
+    public Long getOptionId() {
9
+        return optionId;
10
+    }
11
+
12
+    public void setOptionId(Long optionId) {
13
+        this.optionId = optionId;
14
+    }
15
+
16
+    public int getCount() {
17
+        return count;
18
+    }
19
+
20
+    public void setCount(int count) {
21
+        this.count = count;
22
+    }
23
+}

+ 25
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dto/VoteResult.java Vedi File

@@ -0,0 +1,25 @@
1
+package io.zipcoder.tc_spring_poll_application.dto;
2
+
3
+import java.util.Collection;
4
+
5
+public class VoteResult {
6
+
7
+    private int totalVotes;
8
+    private Collection<OptionCount> results;
9
+
10
+    public int getTotalVotes() {
11
+        return totalVotes;
12
+    }
13
+
14
+    public void setTotalVotes(int totalVotes) {
15
+        this.totalVotes = totalVotes;
16
+    }
17
+
18
+    public Collection<OptionCount> getResults() {
19
+        return results;
20
+    }
21
+
22
+    public void setResults(Collection<OptionCount> results) {
23
+        this.results = results;
24
+    }
25
+}

+ 63
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/ErrorDetail.java Vedi File

@@ -0,0 +1,63 @@
1
+package io.zipcoder.tc_spring_poll_application.dto.error;
2
+
3
+import java.util.HashMap;
4
+import java.util.List;
5
+import java.util.Map;
6
+
7
+public class ErrorDetail {
8
+
9
+    private String title;
10
+    private int status;
11
+    private String detail;
12
+    private long timeStamp;
13
+    private String developerMessage;
14
+    private Map<String, List<ValidationError>> errors = new HashMap<String, List<ValidationError>>();
15
+
16
+    public Map<String, List<ValidationError>> getErrors() {
17
+        return errors;
18
+    }
19
+
20
+    public void setErrors(Map<String, List<ValidationError>> errors) {
21
+        this.errors = errors;
22
+    }
23
+
24
+    public String getTitle() {
25
+        return title;
26
+    }
27
+
28
+    public void setTitle(String title) {
29
+        this.title = title;
30
+    }
31
+
32
+    public int getStatus() {
33
+        return status;
34
+    }
35
+
36
+    public void setStatus(int status) {
37
+        this.status = status;
38
+    }
39
+
40
+    public String getDetail() {
41
+        return detail;
42
+    }
43
+
44
+    public void setDetail(String detail) {
45
+        this.detail = detail;
46
+    }
47
+
48
+    public long getTimeStamp() {
49
+        return timeStamp;
50
+    }
51
+
52
+    public void setTimeStamp(long timeStamp) {
53
+        this.timeStamp = timeStamp;
54
+    }
55
+
56
+    public String getDeveloperMessage() {
57
+        return developerMessage;
58
+    }
59
+
60
+    public void setDeveloperMessage(String developerMessage) {
61
+        this.developerMessage = developerMessage;
62
+    }
63
+}

+ 23
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/dto/error/ValidationError.java Vedi File

@@ -0,0 +1,23 @@
1
+package io.zipcoder.tc_spring_poll_application.dto.error;
2
+
3
+public class ValidationError {
4
+
5
+    private String code;
6
+    private String message;
7
+
8
+    public String getCode() {
9
+        return code;
10
+    }
11
+
12
+    public void setCode(String code) {
13
+        this.code = code;
14
+    }
15
+
16
+    public String getMessage() {
17
+        return message;
18
+    }
19
+
20
+    public void setMessage(String message) {
21
+        this.message = message;
22
+    }
23
+}

+ 20
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/exception/ResourceNotFoundException.java Vedi File

@@ -0,0 +1,20 @@
1
+package io.zipcoder.tc_spring_poll_application.exception;
2
+
3
+import org.springframework.http.HttpStatus;
4
+import org.springframework.web.bind.annotation.ResponseStatus;
5
+
6
+@ResponseStatus(HttpStatus.NOT_FOUND)
7
+public class ResourceNotFoundException extends RuntimeException {
8
+
9
+    private static final long serialVersionUID = 1L;
10
+
11
+    public ResourceNotFoundException() {}
12
+
13
+    public ResourceNotFoundException(String message) {
14
+        super(message);
15
+    }
16
+
17
+    public ResourceNotFoundException(String message, Throwable cause) {
18
+        super(message, cause);
19
+    }
20
+}

+ 82
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/handler/RestExceptionHandler.java Vedi File

@@ -0,0 +1,82 @@
1
+package io.zipcoder.tc_spring_poll_application.handler;
2
+
3
+import io.zipcoder.tc_spring_poll_application.dto.error.ErrorDetail;
4
+import io.zipcoder.tc_spring_poll_application.dto.error.ValidationError;
5
+import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
6
+import org.springframework.context.MessageSource;
7
+import org.springframework.http.HttpHeaders;
8
+import org.springframework.http.HttpStatus;
9
+import org.springframework.http.ResponseEntity;
10
+import org.springframework.http.converter.HttpMessageNotReadableException;
11
+import org.springframework.validation.FieldError;
12
+import org.springframework.web.bind.MethodArgumentNotValidException;
13
+import org.springframework.web.bind.annotation.ControllerAdvice;
14
+import org.springframework.web.bind.annotation.ExceptionHandler;
15
+import org.springframework.web.context.request.WebRequest;
16
+import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
17
+
18
+import javax.inject.Inject;
19
+import javax.servlet.http.HttpServletRequest;
20
+import java.util.ArrayList;
21
+import java.util.Date;
22
+import java.util.List;
23
+
24
+@ControllerAdvice
25
+public class RestExceptionHandler extends ResponseEntityExceptionHandler {
26
+
27
+    @Inject
28
+    private MessageSource messageSource;
29
+
30
+    @ExceptionHandler(ResourceNotFoundException.class)
31
+    public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundException rnfe, HttpServletRequest request) {
32
+
33
+        ErrorDetail errorDetail = new ErrorDetail();
34
+        errorDetail.setTimeStamp(new Date().getTime());
35
+        errorDetail.setStatus(HttpStatus.NOT_FOUND.value());
36
+        errorDetail.setTitle("Resource Not Found");
37
+        errorDetail.setDetail(rnfe.getMessage());
38
+        errorDetail.setDeveloperMessage(rnfe.getClass().getName());
39
+
40
+        return new ResponseEntity<>(errorDetail, null, HttpStatus.NOT_FOUND);
41
+    }
42
+
43
+    @Override
44
+    protected ResponseEntity<Object> handleHttpMessageNotReadable(
45
+            HttpMessageNotReadableException ex, HttpHeaders headers,
46
+            HttpStatus status, WebRequest request) {
47
+        ErrorDetail errorDetail = new ErrorDetail();
48
+        errorDetail.setTimeStamp(new Date().getTime());
49
+        errorDetail.setStatus(status.value());
50
+        errorDetail.setTitle("Message Not Readable");
51
+        errorDetail.setDetail(ex.getMessage());
52
+        errorDetail.setDeveloperMessage(ex.getClass().getName());
53
+        return handleExceptionInternal(ex, errorDetail, headers, status, request);
54
+    }
55
+
56
+    @Override
57
+    public ResponseEntity<Object> handleMethodArgumentNotValid(
58
+            MethodArgumentNotValidException manve, HttpHeaders headers,
59
+            HttpStatus status, WebRequest request) {
60
+        ErrorDetail errorDetail = new ErrorDetail();
61
+        errorDetail.setTimeStamp(new Date().getTime());
62
+        errorDetail.setStatus(HttpStatus.BAD_REQUEST.value());
63
+        errorDetail.setTitle("Validation Failed");
64
+        errorDetail.setDetail("Input validation failed");
65
+        errorDetail.setDeveloperMessage(manve.getClass().getName());
66
+
67
+        List<FieldError> fieldErrors =  manve.getBindingResult().getFieldErrors();
68
+        for(FieldError fe : fieldErrors) {
69
+            List<ValidationError> validationErrorList = errorDetail.getErrors().get(fe.getField());
70
+            if(validationErrorList == null) {
71
+                validationErrorList = new ArrayList<ValidationError>();
72
+                errorDetail.getErrors().put(fe.getField(),
73
+                        validationErrorList);
74
+            }
75
+            ValidationError validationError = new ValidationError();
76
+            validationError.setCode(fe.getCode());
77
+            validationError.setMessage(messageSource.getMessage(fe, null));
78
+            validationErrorList.add(validationError);
79
+        }
80
+        return handleExceptionInternal(manve, errorDetail, headers, status, request);
81
+    }
82
+}

+ 7
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repository/OptionRepository.java Vedi File

@@ -0,0 +1,7 @@
1
+package io.zipcoder.tc_spring_poll_application.repository;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Option;
4
+import org.springframework.data.repository.CrudRepository;
5
+
6
+public interface OptionRepository extends CrudRepository<Option, Long> {
7
+}

+ 8
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repository/PollRepository.java Vedi File

@@ -0,0 +1,8 @@
1
+package io.zipcoder.tc_spring_poll_application.repository;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Poll;
4
+import org.springframework.data.repository.PagingAndSortingRepository;
5
+
6
+public interface PollRepository extends PagingAndSortingRepository<Poll, Long> {
7
+
8
+}

+ 11
- 0
src/main/java/io/zipcoder/tc_spring_poll_application/repository/VoteRepository.java Vedi File

@@ -0,0 +1,11 @@
1
+package io.zipcoder.tc_spring_poll_application.repository;
2
+
3
+import io.zipcoder.tc_spring_poll_application.domain.Vote;
4
+import org.springframework.data.jpa.repository.Query;
5
+import org.springframework.data.repository.CrudRepository;
6
+
7
+public interface VoteRepository extends CrudRepository<Vote, Long> {
8
+
9
+    @Query(value="select v.* from Option o, Vote v where o.POLL_ID = ?1 and v.OPTION_ID = o.OPTION_ID", nativeQuery = true)
10
+            public Iterable<Vote> findByPoll(Long pollId);
11
+}

+ 0
- 0
src/main/resources/application.properties Vedi File


+ 113
- 0
src/main/resources/import.sql Vedi File

@@ -0,0 +1,113 @@
1
+insert into poll (poll_id, question) values (1, 'Are you a morning, afternoon or evening person?');
2
+insert into option (option_id, option_value, poll_id) values (1, 'Morning', 1);
3
+insert into option (option_id, option_value, poll_id) values (2, 'Afternoon', 1);
4
+insert into option (option_id, option_value, poll_id) values (3, 'Evening', 1);
5
+insert into option (option_id, option_value, poll_id) values (4, 'Not an any time person!', 1);
6
+
7
+insert into poll (poll_id, question) values (2, 'How many countries have you travelled to?');
8
+insert into option (option_id, option_value, poll_id) values (5, 'Zero', 2);
9
+insert into option (option_id, option_value, poll_id) values (6, 'One', 2);
10
+insert into option (option_id, option_value, poll_id) values (7, 'Two', 2);
11
+insert into option (option_id, option_value, poll_id) values (8, 'Three or more', 2);
12
+
13
+insert into poll (poll_id, question) values (3, 'What is your favorite color?');
14
+insert into option (option_id, option_value, poll_id) values (9, 'Red', 3);
15
+insert into option (option_id, option_value, poll_id) values (10, 'Blue', 3);
16
+insert into option (option_id, option_value, poll_id) values (11, 'Green', 3);
17
+insert into option (option_id, option_value, poll_id) values (12, 'Black', 3);
18
+
19
+insert into poll (poll_id, question) values (4, 'What is your favorite season?');
20
+insert into option (option_id, option_value, poll_id) values (13, 'Spring', 4);
21
+insert into option (option_id, option_value, poll_id) values (14, 'Summer', 4);
22
+insert into option (option_id, option_value, poll_id) values (15, 'Fall', 4);
23
+insert into option (option_id, option_value, poll_id) values (16, 'Winter', 4);
24
+
25
+insert into poll (poll_id, question) values (5, 'How do you rate overall satisfaction with Zip Code Wilmington?');
26
+insert into option (option_id, option_value, poll_id) values (17, 'Very Satisfied', 5);
27
+insert into option (option_id, option_value, poll_id) values (18, 'Somewhat Satisfied', 5);
28
+insert into option (option_id, option_value, poll_id) values (19, 'Neutral', 5);
29
+insert into option (option_id, option_value, poll_id) values (20, 'Somewhat Dissatisfied', 5);
30
+insert into option (option_id, option_value, poll_id) values (21, 'Dissatisfied', 5);
31
+
32
+insert into poll (poll_id, question) values (6, 'Smooth or crunchy peanut butter?');
33
+insert into option (option_id, option_value, poll_id) values (22, 'Smooth', 6);
34
+insert into option (option_id, option_value, poll_id) values (23, 'Crunchy', 6);
35
+
36
+insert into poll (poll_id, question) values (7, 'Who will win 2020 elections in the United States?');
37
+insert into option (option_id, option_value, poll_id) values (24, 'Democrat', 7);
38
+insert into option (option_id, option_value, poll_id) values (25, 'Republican', 7);
39
+
40
+insert into poll (poll_id, question) values (8, 'Star Wars or Star Trek?');
41
+insert into option (option_id, option_value, poll_id) values (26, 'Star Wars', 8);
42
+insert into option (option_id, option_value, poll_id) values (27, 'Star Trek', 8);
43
+insert into option (option_id, option_value, poll_id) values (28, 'Neither', 8);
44
+
45
+insert into poll (poll_id, question) values (9, 'Favorite operating system?');
46
+insert into option (option_id, option_value, poll_id) values (29, 'Windows', 9);
47
+insert into option (option_id, option_value, poll_id) values (30, 'Mac', 9);
48
+insert into option (option_id, option_value, poll_id) values (31, 'Ubuntu', 9);
49
+
50
+insert into poll (poll_id, question) values (10, 'Favorite eye color?');
51
+insert into option (option_id, option_value, poll_id) values (32, 'Blue', 10);
52
+insert into option (option_id, option_value, poll_id) values (33, 'Green', 10);
53
+insert into option (option_id, option_value, poll_id) values (34, 'Brown', 10);
54
+insert into option (option_id, option_value, poll_id) values (35, 'Hazel', 10);
55
+
56
+insert into poll (poll_id, question) values (11, 'Which number has the most votes?');
57
+insert into option (option_id, option_value, poll_id) values (36, '1', 11);
58
+insert into option (option_id, option_value, poll_id) values (37, '2', 11);
59
+insert into option (option_id, option_value, poll_id) values (38, '3', 11);
60
+insert into option (option_id, option_value, poll_id) values (39, '4', 11);
61
+
62
+insert into poll (poll_id, question) values (12, 'What is your greatest desire?');
63
+insert into option (option_id, option_value, poll_id) values (40, 'Beauty', 12);
64
+insert into option (option_id, option_value, poll_id) values (41, 'Money', 12);
65
+insert into option (option_id, option_value, poll_id) values (42, 'Love', 12);
66
+insert into option (option_id, option_value, poll_id) values (43, 'Pokemon', 12);
67
+
68
+insert into poll (poll_id, question) values (13, 'What is the biggest State in the US?');
69
+insert into option (option_id, option_value, poll_id) values (44, 'Texas', 13);
70
+insert into option (option_id, option_value, poll_id) values (45, 'California', 13);
71
+insert into option (option_id, option_value, poll_id) values (46, 'Florida', 13);
72
+insert into option (option_id, option_value, poll_id) values (47, 'Alaska', 13);
73
+
74
+insert into poll (poll_id, question) values (14, 'How many hours of sleep do you average per night');
75
+insert into option (option_id, option_value, poll_id) values (48, '< 5.5', 14);
76
+insert into option (option_id, option_value, poll_id) values (49, '5.5-7.5', 14);
77
+insert into option (option_id, option_value, poll_id) values (50, '> 7.5', 14);
78
+
79
+insert into poll (poll_id, question) values (15, 'How many keys are on a standard piano?');
80
+insert into option (option_id, option_value, poll_id) values (51, '66', 15);
81
+insert into option (option_id, option_value, poll_id) values (52, '44', 15);
82
+insert into option (option_id, option_value, poll_id) values (53, '88', 15);
83
+insert into option (option_id, option_value, poll_id) values (54, '122', 15);
84
+
85
+insert into poll (poll_id, question) values (16, 'Which country gave America the Statue of Liberty?');
86
+insert into option (option_id, option_value, poll_id) values (55, 'Canada', 16);
87
+insert into option (option_id, option_value, poll_id) values (56, 'France', 16);
88
+insert into option (option_id, option_value, poll_id) values (57, 'Germany', 16);
89
+insert into option (option_id, option_value, poll_id) values (58, 'England', 16);
90
+
91
+insert into poll (poll_id, question) values (17, 'Best Christmas Gift?');
92
+insert into option (option_id, option_value, poll_id) values (59, 'Smartphone', 17);
93
+insert into option (option_id, option_value, poll_id) values (60, 'Car', 17);
94
+insert into option (option_id, option_value, poll_id) values (61, 'House', 17);
95
+insert into option (option_id, option_value, poll_id) values (62, 'World Trip', 17);
96
+
97
+insert into poll (poll_id, question) values (18, 'How many kids do you want?');
98
+insert into option (option_id, option_value, poll_id) values (63, 'Zero', 18);
99
+insert into option (option_id, option_value, poll_id) values (64, 'One', 18);
100
+insert into option (option_id, option_value, poll_id) values (65, 'Two', 18);
101
+insert into option (option_id, option_value, poll_id) values (66, 'Three+', 18);
102
+
103
+insert into poll (poll_id, question) values (19, 'Pick an animal');
104
+insert into option (option_id, option_value, poll_id) values (67, 'Panther', 19);
105
+insert into option (option_id, option_value, poll_id) values (68, 'Tiger', 19);
106
+insert into option (option_id, option_value, poll_id) values (69, 'Python', 19);
107
+insert into option (option_id, option_value, poll_id) values (70, 'Alpaca', 19);
108
+
109
+insert into poll (poll_id, question) values (20, 'How many rings are on the Olympic flag?');
110
+insert into option (option_id, option_value, poll_id) values (71, '6', 20);
111
+insert into option (option_id, option_value, poll_id) values (72, '8', 20);
112
+insert into option (option_id, option_value, poll_id) values (73, '5', 20);
113
+insert into option (option_id, option_value, poll_id) values (74, '4', 20);

+ 2
- 0
src/main/resources/messages.properties Vedi File

@@ -0,0 +1,2 @@
1
+NotEmpty.poll.question=Question is a required field
2
+Size.poll.options=Options must be greater than {2} and less than {1}