Skip to content

Commit

Permalink
Merge pull request #25 from aosn/develop
Browse files Browse the repository at this point in the history
Ready for v0.4 release
  • Loading branch information
mikan authored May 26, 2017
2 parents 9921264 + efa508d commit 5a3261b
Show file tree
Hide file tree
Showing 36 changed files with 501 additions and 429 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ out/
classes/
src/main/resources/application-cloud.yml
src/main/resources/application-production.yml
deploy-*.sh

### STS ###
.classpath
Expand All @@ -23,4 +24,4 @@ build/
nbbuild/
dist/
nbdist/
.nb-gradle/
.nb-gradle/
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
buildscript {
ext {
vaadinVersion = '7.7.6'
vaadinSpringBootVersion = '1.1.1'
checkerFrameworkVersion = '2.1.5'
vaadinVersion = '8.0.5'
vaadinSpringBootVersion = '2.0.0'
springFoxVersion = '2.6.1'
checkerFrameworkVersion = '2.1.9'
}
}

plugins {
id 'com.gradle.build-scan' version '1.5'
id 'org.springframework.boot' version '1.4.4.RELEASE'
id 'org.springframework.boot' version '1.5.2.RELEASE'
id 'war'
}

Expand All @@ -31,6 +31,8 @@ dependencies {
compile("com.vaadin:vaadin-spring-boot-starter:${vaadinSpringBootVersion}")
compile("com.vaadin:vaadin-themes:${vaadinVersion}")
compile('org.vaadin.spring.addons:vaadin-spring-addon-i18n:0.0.7.RELEASE')
compile("com.vaadin:vaadin-compatibility-server:${vaadinVersion}")
runtime("com.vaadin:vaadin-compatibility-client-compiled:${vaadinVersion}")
// Utilities
compile('org.projectlombok:lombok')
compile("org.checkerframework:checker-qual:${checkerFrameworkVersion}")
Expand All @@ -57,7 +59,7 @@ dependencyManagement {

war {
baseName = 'mosaic'
version = '0.3'
version = '0.4'
archiveName = baseName + "." + extension
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/aosn/mosaic/MosaicApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@SpringBootApplication
public class MosaicApplication {

public static final long MOSAIC_SERIAL_VERSION_UID = 3L;
public static final String MOSAIC_VERSION = "0.3";
public static final long MOSAIC_SERIAL_VERSION_UID = 4L;
public static final String MOSAIC_VERSION = "0.4";
public static final String DEFAULT_TITLE = "Mosaic";

public static void main(String[] args) {
Expand Down
47 changes: 42 additions & 5 deletions src/main/java/io/github/aosn/mosaic/domain/model/poll/Poll.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.LongAdder;
Expand Down Expand Up @@ -47,6 +45,7 @@ public class Poll implements Serializable {

@Column(nullable = false)
@Getter
@Setter
private String subject;

@JoinColumn(nullable = false)
Expand All @@ -68,11 +67,11 @@ public class Poll implements Serializable {
@Column
@Temporal(TemporalType.DATE)
@Getter
@Setter
private Date end;

@Column(nullable = false)
@Getter
@Setter
private Integer doubles;

@JoinColumn
Expand Down Expand Up @@ -110,6 +109,24 @@ public class Poll implements Serializable {
@Nullable
private Group group;

/**
* Construct new poll.
*
* @param owner owner user
* @return poll
* @since 0.4
*/
public static Poll create(User owner, LocalDate now) {
Poll poll = new Poll();
poll.owner = owner;
poll.state = Poll.PollState.OPEN;
poll.begin = java.sql.Date.valueOf(now);
poll.setEnd(now.plusDays(1));
poll.doubles = 2;
poll.votes = Collections.emptyList();
return poll;
}

public Book judgeWinner() {
Map<Book, Integer> votesMap = new HashMap<>();
AtomicInteger max = new AtomicInteger(0);
Expand Down Expand Up @@ -165,6 +182,26 @@ public PopularityRate calcPopularityRate(Book book) {
return new PopularityRate(book.getVotes(), getVoters().size());
}

/**
* Get end as {@link LocalDate}.
*
* @return end
* @since 0.4
*/
public LocalDate getEndAsLocalDate() {
return new java.sql.Date(end.getTime()).toLocalDate();
}

/**
* Set end by {@link LocalDate}.
*
* @param end end
* @since 0.4
*/
public void setEnd(LocalDate end) {
this.end = java.sql.Date.valueOf(end);
}

public enum PollState {
@SuppressWarnings("unused")PRE_OPEN, // currently unused yet
OPEN,
Expand Down
78 changes: 76 additions & 2 deletions src/main/java/io/github/aosn/mosaic/domain/model/stock/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import javax.persistence.*;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -83,14 +84,12 @@ public class Stock implements ReleasedBook {
@Temporal(TemporalType.DATE)
@Nullable
@Getter
@Setter
private Date obtainDate;

@Column
@Temporal(TemporalType.DATE)
@Nullable
@Getter
@Setter
private Date completedDate;

@Column
Expand Down Expand Up @@ -153,6 +152,35 @@ public class Stock implements ReleasedBook {
@Setter
private Date updatedTime;

/**
* Construct stock with {@link ReleasedBook}.
*
* @param owner owner user
* @param book released book
* @return stock
* @since 0.4
*/
public static Stock create(User owner, ReleasedBook book) {
Date now = new Date();
Stock stock = new Stock();
stock.user = owner;
stock.isbn = book.getIsbn();
stock.title = book.getTitle();
stock.subtitle = book.getSubtitle();
stock.publishedDate = book.getPublishedDate();
stock.thumbnailUrl = book.getThumbnailUrl();
stock.pageCount = book.getPageCount();
stock.visibility = Visibility.PUBLIC;
stock.progress = 0;
stock.obtainType = ObtainType.BUY;
stock.mediaType = book.isEBook() ? MediaType.OTHER : MediaType.PAPER;
stock.shortText = "";
stock.longText = "";
stock.createdTime = now;
stock.updatedTime = now;
return stock;
}

/**
* Checks value for acceptable published date.
*
Expand Down Expand Up @@ -202,6 +230,12 @@ public Progress getProgress() {
}
}

public void setProgress(Progress progress) {
if (getProgress() != progress) {
this.progress = progress.actualValue;
}
}

public void setProgressPercentage(int percentage) {
if (percentage < 0 || percentage > 100) {
throw new IllegalArgumentException("percentage accepts 0~100");
Expand All @@ -213,6 +247,46 @@ public int getProgressPercentage() {
return progress;
}

/**
* Get obtain date as {@link LocalDate}.
*
* @return obtain date
* @since 0.4
*/
public LocalDate getObtainDateAsLocalDate() {
return obtainDate == null ? null : new java.sql.Date(obtainDate.getTime()).toLocalDate();
}

/**
* Set obtain date by {@link LocalDate} object.
*
* @param localDate obtain date
* @since 0.4
*/
public void setObtainDate(LocalDate localDate) {
obtainDate = localDate == null ? null : java.sql.Date.valueOf(localDate);
}

/**
* Get completed date as {@link LocalDate}.
*
* @return completed date
* @since 0.4
*/
public LocalDate getCompletedDateAsLocalDate() {
return completedDate == null ? null : new java.sql.Date(completedDate.getTime()).toLocalDate();
}

/**
* Set completed date by {@link LocalDate} object.
*
* @param localDate completed date
* @since 0.4
*/
public void setCompletedDate(LocalDate localDate) {
completedDate = localDate == null ? null : java.sql.Date.valueOf(localDate);
}

public void setPublishedDate(String date) {
if (!isValidPublishedDate(date)) {
throw new IllegalArgumentException("Invalid date: " + date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import javax.annotation.PostConstruct;
import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -73,7 +74,7 @@ private void init() {
.findFirst().orElseThrow(IllegalStateException::new);
if (!group.equals(defaultGroup)) {
// update record
log.info("Updating default group:\nfrom\t" + defaultGroup + "\nto\t" + group);
log.info("Updating default group:\ncreate\t" + defaultGroup + "\nto\t" + group);
defaultGroup.replace(group);
groupRepository.saveAndFlush(defaultGroup);
}
Expand Down Expand Up @@ -150,7 +151,7 @@ public void create(Poll poll) {
public void close(Poll poll) {
log.info("BEGIN close: " + poll);
poll.setState(Poll.PollState.CLOSED);
poll.setEnd(new Date());
poll.setEnd(LocalDate.now());
poll.setWinBook(poll.judgeWinner());
pollRepository.saveAndFlush(poll);
log.info("END close: " + poll);
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/io/github/aosn/mosaic/ui/ErrorUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
*/
package io.github.aosn.mosaic.ui;

import com.vaadin.annotations.StyleSheet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.annotations.Viewport;
import com.vaadin.annotations.*;
import com.vaadin.navigator.Navigator;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinService;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.spring.navigator.SpringViewProvider;
import com.vaadin.ui.UI;
import com.vaadin.ui.themes.ValoTheme;
import io.github.aosn.mosaic.MosaicApplication;
import io.github.aosn.mosaic.config.SecurityConfig;
import io.github.aosn.mosaic.ui.i18n.I18nSystemMessageProvider;
Expand All @@ -27,10 +25,11 @@
* @since 0.1
*/
@SpringUI(path = ErrorUI.PATH)
@Theme("valo")
@Theme(ValoTheme.THEME_NAME)
@Title(MosaicApplication.DEFAULT_TITLE)
@StyleSheet(value = "vaadin:/" + SecurityConfig.CSS_PATH)
@Viewport("user-scalable=no,initial-scale=1.0")
@Viewport("user-scalable=no,width=500")
@Widgetset("com.vaadin.v7.Vaadin7WidgetSet")
public class ErrorUI extends UI {

public static final String PATH = "/error";
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/io/github/aosn/mosaic/ui/MainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
*/
package io.github.aosn.mosaic.ui;

import com.vaadin.annotations.StyleSheet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.annotations.Viewport;
import com.vaadin.annotations.*;
import com.vaadin.navigator.Navigator;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinService;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.spring.navigator.SpringViewProvider;
import com.vaadin.ui.UI;
import com.vaadin.ui.themes.ValoTheme;
import io.github.aosn.mosaic.MosaicApplication;
import io.github.aosn.mosaic.config.SecurityConfig;
import io.github.aosn.mosaic.ui.i18n.I18nSystemMessageProvider;
Expand All @@ -27,10 +25,11 @@
* @since 0.1
*/
@SpringUI(path = MainUI.PATH)
@Theme("valo")
@Theme(ValoTheme.THEME_NAME)
@Title(MosaicApplication.DEFAULT_TITLE)
@StyleSheet(value = "vaadin:/" + SecurityConfig.CSS_PATH)
@Viewport("user-scalable=no,initial-scale=1.0")
@Viewport("user-scalable=no,width=500")
@Widgetset("com.vaadin.v7.Vaadin7WidgetSet")
public class MainUI extends UI {

public static final String PATH = "/";
Expand Down
Loading

0 comments on commit 5a3261b

Please sign in to comment.