Skip to content

Commit

Permalink
prepare coc-war project
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Chan committed May 11, 2018
1 parent 0c0e628 commit 5b6135c
Show file tree
Hide file tree
Showing 37 changed files with 540 additions and 147 deletions.
1 change: 1 addition & 0 deletions coc-clan-war/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# coc-war
4 changes: 4 additions & 0 deletions coc-clan-war/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:8-jre-alpine
COPY coc-war*.jar app.jar
EXPOSE 18900
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
158 changes: 158 additions & 0 deletions coc-clan-war/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?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>

<artifactId>coc-clan-war</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
<groupId>me.shufork.jaracks</groupId>
<artifactId>sc-coc</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>


<dependencies>
<dependency>
<groupId>me.shufork.jaracks</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.shufork.jaracks</groupId>
<artifactId>coc-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
26 changes: 26 additions & 0 deletions coc-clan-war/src/main/java/me/shufork/biz/CocWarApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.shufork.biz;

import me.shufork.common.mq.sink.WarLogLoadedSink;
import me.shufork.common.mq.sink.WarLogRejectedSink;
import me.shufork.common.mq.source.ClanFoundSource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@SpringBootApplication(scanBasePackages = {"me.shufork.biz", "me.shufork.common"})
@EnableDiscoveryClient
@EnableBinding({
ClanFoundSource.class,
WarLogLoadedSink.class,
WarLogRejectedSink.class})
@EnableJpaRepositories(basePackages = "me.shufork.biz.repository")
@EnableSwagger2
public class CocWarApplication {
public static void main(String[] args) {
SpringApplication.run(CocWarApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.shufork.biz.config;

import org.springframework.context.annotation.Configuration;

@Configuration
public class CustomBeanConfiguration {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package me.shufork.biz.config;

import me.shufork.biz.converter.WarLogEntryClanVoConverter;
import me.shufork.biz.converter.WarLogEntryVoConverter;
import me.shufork.biz.domain.CocWarLog;
import me.shufork.biz.domain.CocWarTeam;
import me.shufork.biz.vo.WarLogEntryClanVo;
import me.shufork.biz.vo.WarLogEntryVo;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ModelMapperConfiguration {
@Bean
public ModelMapper modelMapper() {
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);

// note ignore version,createdTime,modifiedTime for domain object

modelMapper.createTypeMap(WarLogEntryClanVo.class,CocWarTeam.class)
.setConverter(new WarLogEntryClanVoConverter.ToCocWarTeam());

modelMapper.createTypeMap(CocWarTeam.class,WarLogEntryClanVo.class)
.setConverter(new WarLogEntryClanVoConverter.FromCocWarTeam());

modelMapper.createTypeMap(CocWarLog.class,WarLogEntryVo.class)
.setConverter(new WarLogEntryVoConverter.FromCocWarLog());

return modelMapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.extern.slf4j.Slf4j;
import me.shufork.biz.mq.publisher.ClanFoundPublisher;
import me.shufork.biz.service.ClanService;
import me.shufork.biz.service.WarLogService;
import me.shufork.common.dto.supercell.coc.ClanBasicInfoDto;
import me.shufork.common.dto.supercell.coc.WarLogEntryDto;
Expand All @@ -21,8 +20,6 @@
@Slf4j
public class WarLogListLoadedConsumer implements MessageConsumer<WarLogListPayload> {

@Autowired
private ClanService clanService;
@Autowired
private WarLogService warLogService;
@Autowired
Expand All @@ -40,7 +37,6 @@ public void handleMessage(WarLogListPayload message) {
.collect(Collectors.toList());
//List<PlayerBasicInfoDto> players;
clanFoundPublisher.publishClanFound(clans);
clanService.insertOrUpdate(clans);
warLogService.updateWarLog(warLogList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package me.shufork.biz.utils;

import me.shufork.biz.domain.CocWarTeam;
import me.shufork.biz.vo.WarLogEntryClanVo;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public final class EntityKeyUtils {

private static final String KEY_JOIN_CHAR = "-";

private EntityKeyUtils(){}

private static String makeKey(List<String> strings){
return strings.stream()
.map(o-> StringUtils.trimToNull(o.toLowerCase()))
.filter(o-> !StringUtils.isBlank(o))
.collect(Collectors.joining(KEY_JOIN_CHAR));
}

public static String keyOfWarLog(String clanTag,String endTime){
if(StringUtils.isBlank(clanTag) || StringUtils.isBlank(endTime)){
throw new IllegalStateException("Can not make key");
}
return makeKey(Arrays.asList(
clanTag,
endTime
)
);
}

public static String keyOf(WarLogEntryClanVo val){
if(StringUtils.isBlank(val.getTag()) || val.getWarTime() == null ){
throw new IllegalStateException("Can not make key");
}
return makeKey(Arrays.asList(
val.getTag(),
Long.toString(val.getWarTime().getTime())
)
);
}

public static String keyOf(CocWarTeam val){

if(StringUtils.isBlank(val.getClan()) || val.getWarTime() == null ){
throw new IllegalStateException("Can not make key");
}
return makeKey(Arrays.asList(
val.getClan(),
Long.toString(val.getWarTime().getTime())
)
);
}

}
Loading

0 comments on commit 5b6135c

Please sign in to comment.