project initialized

This commit is contained in:
crusader 2019-07-03 00:33:43 +09:00
commit bd7d597eab
23 changed files with 717 additions and 0 deletions

55
.classpath Normal file
View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>rpc</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8

View File

@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false

View File

@ -0,0 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

11
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - SpringGrpcApplication",
"request": "launch",
"mainClass": "com.loafle.cms.rpc.SpringGrpcApplication",
"projectName": "rpc"
}
]
}

14
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.autoClosingBrackets": "languageDefined",
"editor.trimAutoWhitespace": true,
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"go.testFlags": ["-v"],
"go.testTimeout": "100s",
"java.configuration.updateBuildConfiguration": "automatic"
}

108
pom.xml Normal file
View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.loafle.cms</groupId>
<artifactId>rpc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cms-rpc</name>
<description>rpc of cms</description>
<url>https://codenotfound.com/grpc-java-example.html</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<grpc-spring-boot-starter.version>3.2.2</grpc-spring-boot-starter.version>
<protobuf.version>3.7.1</protobuf.version>
<grpc.version>1.21.0</grpc.version>
<gson.version>2.8.5</gson.version>
<postgresql.version>42.2.5</postgresql.version>
<protobuf-java-util.version>3.7.1</protobuf-java-util.version>
<loafle-cms-proto.version>0.0.1-SNAPSHOT</loafle-cms-proto.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.github.lognet</groupId>
<artifactId>grpc-spring-boot-starter</artifactId>
<version>${grpc-spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>com.loafle.cms</groupId>
<artifactId>proto</artifactId>
<version>${loafle-cms-proto.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>${protobuf-java-util.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,12 @@
package com.loafle.cms.rpc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringGrpcApplication {
public static void main(String[] args) {
SpringApplication.run(SpringGrpcApplication.class, args);
}
}

View File

@ -0,0 +1,23 @@
package com.loafle.cms.rpc.common.util;
import java.util.Date;
import com.google.protobuf.Timestamp;
public class Time {
static final long MILLIS_PER_SECOND = 1000;
public static Date toDate(Timestamp timestamp) {
if (null == timestamp) {
return null;
}
return new Date(timestamp.getSeconds() * MILLIS_PER_SECOND);
}
public static Timestamp toTimestamp(Date date) {
if (null == date) {
return null;
}
return Timestamp.newBuilder().setSeconds(date.getTime() / MILLIS_PER_SECOND).build();
}
}

View File

@ -0,0 +1,270 @@
package com.loafle.cms.rpc.user.model;
import com.loafle.cms.proto.user.UserOuterClass;
import com.loafle.cms.rpc.common.util.Time;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.util.Date;
import java.util.Objects;
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(generator = "user_generator")
@SequenceGenerator(name = "user_generator", sequenceName = "user_sequence", initialValue = 1000)
private Long id;
@Basic
@Column(name = "name", nullable = false, length = 255)
private String name;
@Basic
@Column(name = "username", nullable = false, length = 150)
private String username;
@Basic
@Column(name = "email", nullable = false, length = 100)
private String email;
@Basic
@Column(name = "password", nullable = false, length = 100)
private String password;
@Basic
@Column(name = "block", nullable = false, columnDefinition = "bool default false")
private Boolean block;
@Basic
@Column(name = "send_email", nullable = true, columnDefinition = "bool default false")
private Boolean sendEmail;
@Basic
@Column(name = "register_date", nullable = false)
private Date registerDate;
@Basic
@Column(name = "lastvisit_date", nullable = false)
private Date lastvisitDate;
@Basic
@Column(name = "activation", nullable = false, length = 100)
private String activation;
@Basic
@Column(name = "params", nullable = false)
private String params;
@Basic
@Column(name = "last_reset_time", nullable = false)
private Date lastResetTime;
@Basic
@Column(name = "reset_count", nullable = false)
private Long resetCount;
@Basic
@Column(name = "otp_key", nullable = false, length = 1000)
private String otpKey;
@Basic
@Column(name = "otep", nullable = false, length = 1000)
private String otep;
@Basic
@Column(name = "require_reset", nullable = true, columnDefinition = "bool default false")
private Boolean requireReset;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Boolean getBlock() {
return block;
}
public void setBlock(Boolean block) {
this.block = block;
}
public Boolean getSendEmail() {
return sendEmail;
}
public void setSendEmail(Boolean sendEmail) {
this.sendEmail = sendEmail;
}
public Date getRegisterDate() {
return registerDate;
}
public void setRegisterDate(Date registerDate) {
this.registerDate = registerDate;
}
public Date getLastvisitDate() {
return lastvisitDate;
}
public void setLastvisitDate(Date lastvisitDate) {
this.lastvisitDate = lastvisitDate;
}
public String getActivation() {
return activation;
}
public void setActivation(String activation) {
this.activation = activation;
}
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
public Date getLastResetTime() {
return lastResetTime;
}
public void setLastResetTime(Date lastResetTime) {
this.lastResetTime = lastResetTime;
}
public Long getResetCount() {
return resetCount;
}
public void setResetCount(Long resetCount) {
this.resetCount = resetCount;
}
public String getOtpKey() {
return otpKey;
}
public void setOtpKey(String otpKey) {
this.otpKey = otpKey;
}
public String getOtep() {
return otep;
}
public void setOtep(String otep) {
this.otep = otep;
}
public Boolean getRequireReset() {
return requireReset;
}
public void setRequireReset(Boolean requireReset) {
this.requireReset = requireReset;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
User user = (User) o;
return id == user.id && block == user.block && resetCount == user.resetCount && Objects.equals(name, user.name)
&& Objects.equals(username, user.username) && Objects.equals(email, user.email)
&& Objects.equals(password, user.password) && Objects.equals(sendEmail, user.sendEmail)
&& Objects.equals(registerDate, user.registerDate) && Objects.equals(lastvisitDate, user.lastvisitDate)
&& Objects.equals(activation, user.activation) && Objects.equals(params, user.params)
&& Objects.equals(lastResetTime, user.lastResetTime) && Objects.equals(otpKey, user.otpKey)
&& Objects.equals(otep, user.otep) && Objects.equals(requireReset, user.requireReset);
}
@Override
public int hashCode() {
return Objects.hash(id, name, username, email, password, block, sendEmail, registerDate, lastvisitDate, activation,
params, lastResetTime, resetCount, otpKey, otep, requireReset);
}
public UserOuterClass.User toProto() {
return UserOuterClass.User.newBuilder().setId(getId()).setName(getName()).setUsername(getUsername())
.setEmail(getEmail()).setPassword(getPassword()).setBlock(getBlock()).setSendEmail(getSendEmail())
.setRegisterDate(Time.toTimestamp(getRegisterDate())).setLastvisitDate(Time.toTimestamp(getLastvisitDate()))
.setActivation(getActivation()).setParams(getParams()).setLastResetTime(Time.toTimestamp(getLastResetTime()))
.setResetCount(getResetCount()).setOtpKey(getOtpKey()).setOtep(getOtep()).setRequireReset(getRequireReset())
.build();
}
public static User fromProto(UserOuterClass.User proto) {
if (null == proto) {
return null;
}
User model = new User();
model.setId(proto.getId());
model.setName(proto.getName());
model.setUsername(proto.getUsername());
model.setEmail(proto.getEmail());
model.setPassword(proto.getPassword());
model.setBlock(proto.getBlock());
model.setSendEmail(proto.getSendEmail());
model.setRegisterDate(Time.toDate(proto.getRegisterDate()));
model.setLastvisitDate(Time.toDate(proto.getLastvisitDate()));
model.setActivation(proto.getActivation());
model.setParams(proto.getParams());
model.setLastResetTime(Time.toDate(proto.getLastResetTime()));
model.setResetCount(proto.getResetCount());
model.setOtpKey(proto.getOtpKey());
model.setOtep(proto.getOtep());
model.setRequireReset(proto.getRequireReset());
return model;
}
}

View File

@ -0,0 +1,13 @@
package com.loafle.cms.rpc.user.repository;
import com.loafle.cms.rpc.user.model.User;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface UserRepository extends PagingAndSortingRepository<User, Long>, JpaSpecificationExecutor<User> {
User findByUsername(String username);
}

View File

@ -0,0 +1,81 @@
package com.loafle.cms.rpc.user.service;
import com.loafle.cms.proto.user.UserServiceGrpc;
import com.loafle.cms.proto.user.UserServiceOuterClass;
import com.loafle.cms.rpc.user.model.User;
import com.loafle.cms.rpc.user.repository.UserRepository;
import org.lognet.springboot.grpc.GRpcService;
import org.springframework.beans.factory.annotation.Autowired;
import io.grpc.stub.StreamObserver;
@GRpcService
public class UserService extends UserServiceGrpc.UserServiceImplBase {
@Autowired
private UserRepository userRepository;
public void createUser(UserServiceOuterClass.CreateUserRequest request,
StreamObserver<UserServiceOuterClass.CreateUserResponse> responseObserver) {
try {
User user = User.fromProto(request.getUser());
user = userRepository.save(user);
responseObserver.onNext(UserServiceOuterClass.CreateUserResponse.newBuilder().setId(user.getId()).build());
} catch (Exception e) {
responseObserver.onError(e);
} finally {
responseObserver.onCompleted();
}
}
public void readUserById(UserServiceOuterClass.ReadUserByIdRequest request,
StreamObserver<UserServiceOuterClass.ReadUserResponse> responseObserver) {
try {
User user = userRepository.findById(request.getId()).orElse(null);
responseObserver.onNext(
UserServiceOuterClass.ReadUserResponse.newBuilder().setUser(null == user ? null : user.toProto()).build());
} catch (Exception e) {
responseObserver.onError(e);
} finally {
responseObserver.onCompleted();
}
}
public void readUserByUsername(UserServiceOuterClass.ReadUserByUsernameRequest request,
StreamObserver<UserServiceOuterClass.ReadUserResponse> responseObserver) {
try {
User user = userRepository.findByUsername(request.getUsername());
responseObserver.onNext(
UserServiceOuterClass.ReadUserResponse.newBuilder().setUser(null == user ? null : user.toProto()).build());
} catch (Exception e) {
responseObserver.onError(e);
} finally {
responseObserver.onCompleted();
}
}
public void updateUser(UserServiceOuterClass.UpdateUserRequest request,
StreamObserver<UserServiceOuterClass.UpdateUserResponse> responseObserver) {
}
public void deleteUser(UserServiceOuterClass.DeleteUserRequest request,
StreamObserver<UserServiceOuterClass.DeleteUserResponse> responseObserver) {
try {
userRepository.deleteById(request.getId());
responseObserver.onNext(UserServiceOuterClass.DeleteUserResponse.newBuilder().setDeleted(0).build());
} catch (Exception e) {
responseObserver.onError(e);
} finally {
responseObserver.onCompleted();
}
}
public void readAllUsers(UserServiceOuterClass.ReadAllUsersRequest request,
StreamObserver<UserServiceOuterClass.ReadAllUsersResponse> responseObserver) {
}
}

View File

@ -0,0 +1,41 @@
# Spring Boot configuration
spring:
profiles:
active: development
# Database
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:32768/postgres
username: postgres
password: qwer5795
# JPA properties
jpa:
hibernate:
ddl-auto: create
show-sql: true
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
open-in-view: false
generate-ddl: false
properties:
hibernate:
jdbc:
time_zone: UTC
security:
user:
name: admin
password: admin
gson:
date-format: "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
# Logger configuration
logging:
pattern:
console: "%d %-5level %logger : %msg%n"
level:
org.springframework: INFO
org.hibernate: DEBUG
# Server configuration
# server:
# port: 8080
# sessionTimeout: 30

View File

@ -0,0 +1,41 @@
# Spring Boot configuration
spring:
profiles:
active: development
# Database
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:32768/postgres
username: postgres
password: qwer5795
# JPA properties
jpa:
hibernate:
ddl-auto: create
show-sql: true
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
open-in-view: false
generate-ddl: false
properties:
hibernate:
jdbc:
time_zone: UTC
security:
user:
name: admin
password: admin
gson:
date-format: "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
# Logger configuration
logging:
pattern:
console: "%d %-5level %logger : %msg%n"
level:
org.springframework: INFO
org.hibernate: DEBUG
# Server configuration
# server:
# port: 8080
# sessionTimeout: 30

View File

@ -0,0 +1,3 @@
/home/crusader/Projects/git.loafle.net/outsourcing/totopia/totopia-rpc/src/main/java/com/loafle/cms/rpc/user/repository/UserRepository.java
/home/crusader/Projects/git.loafle.net/outsourcing/totopia/totopia-rpc/src/main/java/com/loafle/cms/rpc/user/model/User.java
/home/crusader/Projects/git.loafle.net/outsourcing/totopia/totopia-rpc/src/main/java/com/loafle/cms/rpc/SpringGrpcApplication.java