Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
51 changes: 51 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.3.RELEASE")
}
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
baseName = 'writer-fic'
version = '0.1.0'
}

repositories {
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-test")
compile("org.springframework.boot:spring-boot-starter-hateoas")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.security:spring-security-test")
compile("org.springframework.security:spring-security-oauth2-client")

compile("org.apache.poi:poi:4.1.0")
compile("io.jsonwebtoken:jjwt:0.5.1")
compile("fr.opensagres.xdocreport:org.apache.poi.xwpf.converter.xhtml:1.0.4")
compile("org.apache.poi:poi-ooxml:4.1.0")
compile("es.nitaur.markdown:txtmark:0.16")
compile("org.projectlombok:lombok")
compile("mysql:mysql-connector-java")
compile("org.postgresql:postgresql")
compile("com.h2database:h2")

testCompile("junit:junit")
}
14 changes: 14 additions & 0 deletions src/main/java/fic/writer/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fic.writer;

import fic.writer.web.config.properties.AppProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

@SpringBootApplication
@EnableConfigurationProperties(AppProperties.class)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fic.writer.domain.audit;

import fic.writer.domain.entity.Profile;
import fic.writer.web.config.security.authorization.UserPrincipal;
import org.springframework.data.domain.AuditorAware;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class SpringSecurityAuditorAware implements AuditorAware<Profile> {
@Override
public Optional<Profile> getCurrentAuditor() {
Optional<Profile> user = Optional.empty();
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal();
user = Optional.ofNullable(userPrincipal.getProfileDetails().getProfile());
}
return user;
}
}
23 changes: 23 additions & 0 deletions src/main/java/fic/writer/domain/entity/Actor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fic.writer.domain.entity;

import lombok.*;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Actor {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false)
private Long id;
private String name;
private String description;
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "actors")
private Set<Book> books;
}
37 changes: 37 additions & 0 deletions src/main/java/fic/writer/domain/entity/Article.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fic.writer.domain.entity;

import lombok.*;
import org.hibernate.annotations.Formula;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EntityListeners(AuditingEntityListener.class)
public class Article {
private static final int CHARS_IN_PAGE = 1800;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
@CreatedDate
private Date created;
@LastModifiedDate
private Date lastModify;
@Column(columnDefinition = "TEXT")
private String content;
private String annotation;
@ManyToOne(fetch = FetchType.LAZY)
private Book book;
@Formula("ceil( CHAR_LENGTH(content)/" + CHARS_IN_PAGE + ")")
private long pageCount;

}
81 changes: 81 additions & 0 deletions src/main/java/fic/writer/domain/entity/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package fic.writer.domain.entity;

import fic.writer.domain.entity.enums.Size;
import fic.writer.domain.entity.enums.State;
import lombok.*;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Set;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EntityListeners(AuditingEntityListener.class)
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
@ManyToOne
@CreatedBy
@NotNull
private Profile author;

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "book_subauthors",
joinColumns = {@JoinColumn(name = "book_id")},
inverseJoinColumns = {@JoinColumn(name = "user_id")}
)
@Singular("coauthors")
private Set<Profile> coauthors;

@OneToMany(fetch = FetchType.EAGER)
@Singular("source")
private Set<Book> source;

@Column(columnDefinition = "text")
private String description;

@Enumerated
private Size size;

@Enumerated
private State state;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@Singular("articles")
private Set<Article> articles;

@Transient
private Long pageCount;

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "book_genres",
joinColumns = {@JoinColumn(name = "book_id")},
inverseJoinColumns = {@JoinColumn(name = "genre_id")}
)
private Set<Genre> genres;

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "book_actors",
joinColumns = {@JoinColumn(name = "book_id")},
inverseJoinColumns = {@JoinColumn(name = "actor_id")}
)
@Singular("actors")
private Set<Actor> actors;

@PostLoad
private void calculatePageCount() {
this.pageCount = 0L;
if (articles != null) {
pageCount = articles.stream().mapToLong(Article::getPageCount).sum();
}
}

}
23 changes: 23 additions & 0 deletions src/main/java/fic/writer/domain/entity/Genre.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fic.writer.domain.entity;

import lombok.*;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import java.util.Set;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Genre {
@Id
private Long id;
private String name;
@ManyToMany(mappedBy = "genres", fetch = FetchType.LAZY)
private Set<Book> book;
}
32 changes: 32 additions & 0 deletions src/main/java/fic/writer/domain/entity/Profile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fic.writer.domain.entity;

import lombok.*;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "profile")
public class Profile {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private String email;
private String imageUrl;
private String about;
private String information;

@ManyToMany(mappedBy = "coauthors", fetch = FetchType.LAZY)
@Singular("booksAsCoauthor")
private Set<Book> booksAsCoauthor;

@OneToMany(fetch = FetchType.LAZY)
@Singular("booksAsAuthor")
private Set<Book> booksAsAuthor;
}
5 changes: 5 additions & 0 deletions src/main/java/fic/writer/domain/entity/auth/AuthProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fic.writer.domain.entity.auth;

public enum AuthProvider {
LOCAL, GOOGLE, GITHUB
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fic.writer.domain.entity.auth;

import fic.writer.domain.entity.Profile;
import lombok.*;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class OauthProfileDetails {
@Id
@GeneratedValue
private Long id;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@NotNull
private Profile profile;
@NotNull
@Enumerated(EnumType.STRING)
private AuthProvider provider;
private String providerId;
private String password;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fic.writer.domain.entity.auth.profileInfo;

import java.util.Map;

public class GithubOAuth2ProfileInfo extends OAuth2ProfileInfo {

public GithubOAuth2ProfileInfo(Map<String, Object> attributes) {
super(attributes);
}

@Override
public String getId() {
return ((Integer) attributes.get("id")).toString();
}

@Override
public String getName() {
return (String) attributes.get("login");
}

@Override
public String getEmail() {
return (String) attributes.get("email");
}

@Override
public String getImageUrl() {
return (String) attributes.get("avatar_url");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fic.writer.domain.entity.auth.profileInfo;

import java.util.Map;

public class GoogleOAuth2ProfileInfo extends OAuth2ProfileInfo {

public GoogleOAuth2ProfileInfo(Map<String, Object> attributes) {
super(attributes);
}

@Override
public String getId() {
return (String) attributes.get("sub");
}

@Override
public String getName() {
return (String) attributes.get("name");
}

@Override
public String getEmail() {
return (String) attributes.get("email");
}

@Override
public String getImageUrl() {
return (String) attributes.get("picture");
}
}
Loading