Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
9d19d637
Commit
9d19d637
authored
Mar 28, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor DTOConverter out of entity class
parent
8563b8b9
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
161 additions
and
85 deletions
+161
-85
ConverterUtils.java
...n/java/com/ctrip/apollo/biz/converter/ConverterUtils.java
+24
-0
DTOToEntityConverter.java
.../com/ctrip/apollo/biz/converter/DTOToEntityConverter.java
+40
-0
EntityToDTOConverter.java
.../com/ctrip/apollo/biz/converter/EntityToDTOConverter.java
+45
-0
ConfigItem.java
...src/main/java/com/ctrip/apollo/biz/entity/ConfigItem.java
+0
-17
ReleaseSnapshot.java
...ain/java/com/ctrip/apollo/biz/entity/ReleaseSnapshot.java
+2
-12
Version.java
...iz/src/main/java/com/ctrip/apollo/biz/entity/Version.java
+0
-11
ReleaseSnapShotRepository.java
...trip/apollo/biz/repository/ReleaseSnapShotRepository.java
+4
-4
AdminConfigServiceImpl.java
...ctrip/apollo/biz/service/impl/AdminConfigServiceImpl.java
+12
-7
ConfigServiceImpl.java
.../com/ctrip/apollo/biz/service/impl/ConfigServiceImpl.java
+3
-3
ConfigServiceImplTest.java
.../ctrip/apollo/biz/service/impl/ConfigServiceImplTest.java
+4
-4
pom.xml
pom.xml
+27
-27
No files found.
apollo-biz/src/main/java/com/ctrip/apollo/biz/converter/ConverterUtils.java
0 → 100644
View file @
9d19d637
package
com
.
ctrip
.
apollo
.
biz
.
converter
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.springframework.beans.BeanWrapper
;
import
org.springframework.beans.BeanWrapperImpl
;
public
class
ConverterUtils
{
static
String
[]
getNullPropertyNames
(
Object
source
)
{
final
BeanWrapper
src
=
new
BeanWrapperImpl
(
source
);
java
.
beans
.
PropertyDescriptor
[]
pds
=
src
.
getPropertyDescriptors
();
Set
<
String
>
emptyNames
=
new
HashSet
<
String
>();
for
(
java
.
beans
.
PropertyDescriptor
pd
:
pds
)
{
Object
srcValue
=
src
.
getPropertyValue
(
pd
.
getName
());
if
(
srcValue
==
null
)
emptyNames
.
add
(
pd
.
getName
());
}
String
[]
result
=
new
String
[
emptyNames
.
size
()];
return
emptyNames
.
toArray
(
result
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/converter/DTOToEntityConverter.java
0 → 100644
View file @
9d19d637
package
com
.
ctrip
.
apollo
.
biz
.
converter
;
import
org.springframework.beans.BeanUtils
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.ConfigItem
;
import
com.ctrip.apollo.biz.entity.ReleaseSnapshot
;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
public
class
DTOToEntityConverter
{
public
static
Cluster
convert
(
ClusterDTO
source
)
{
Cluster
target
=
new
Cluster
();
BeanUtils
.
copyProperties
(
source
,
target
,
ConverterUtils
.
getNullPropertyNames
(
source
));
return
target
;
}
public
static
ConfigItem
convert
(
ConfigItemDTO
source
)
{
ConfigItem
target
=
new
ConfigItem
();
BeanUtils
.
copyProperties
(
source
,
target
,
ConverterUtils
.
getNullPropertyNames
(
source
));
return
target
;
}
public
static
ReleaseSnapshot
convert
(
ReleaseSnapshotDTO
source
)
{
ReleaseSnapshot
target
=
new
ReleaseSnapshot
();
BeanUtils
.
copyProperties
(
source
,
target
,
ConverterUtils
.
getNullPropertyNames
(
source
));
return
target
;
}
public
static
Version
convert
(
VersionDTO
source
)
{
Version
target
=
new
Version
();
BeanUtils
.
copyProperties
(
source
,
target
,
ConverterUtils
.
getNullPropertyNames
(
source
));
return
target
;
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/converter/EntityToDTOConverter.java
0 → 100644
View file @
9d19d637
package
com
.
ctrip
.
apollo
.
biz
.
converter
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanWrapper
;
import
org.springframework.beans.BeanWrapperImpl
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.ConfigItem
;
import
com.ctrip.apollo.biz.entity.ReleaseSnapshot
;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
public
class
EntityToDTOConverter
{
public
static
ClusterDTO
convert
(
Cluster
source
)
{
ClusterDTO
target
=
new
ClusterDTO
();
BeanUtils
.
copyProperties
(
source
,
target
,
ConverterUtils
.
getNullPropertyNames
(
source
));
return
target
;
}
public
static
ConfigItemDTO
convert
(
ConfigItem
source
)
{
ConfigItemDTO
target
=
new
ConfigItemDTO
();
BeanUtils
.
copyProperties
(
source
,
target
,
ConverterUtils
.
getNullPropertyNames
(
source
));
return
target
;
}
public
static
ReleaseSnapshotDTO
convert
(
ReleaseSnapshot
source
)
{
ReleaseSnapshotDTO
target
=
new
ReleaseSnapshotDTO
();
BeanUtils
.
copyProperties
(
source
,
target
,
ConverterUtils
.
getNullPropertyNames
(
source
));
return
target
;
}
public
static
VersionDTO
convert
(
Version
source
)
{
VersionDTO
target
=
new
VersionDTO
();
BeanUtils
.
copyProperties
(
source
,
target
,
ConverterUtils
.
getNullPropertyNames
(
source
));
return
target
;
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/ConfigItem.java
View file @
9d19d637
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
...
...
@@ -150,19 +148,4 @@ public class ConfigItem {
this
.
dataChangeLastModifiedTime
=
dataChangeLastModifiedTime
;
}
public
ConfigItemDTO
toDTO
()
{
ConfigItemDTO
dto
=
new
ConfigItemDTO
();
dto
.
setAppId
(
appId
);
dto
.
setId
(
id
);
dto
.
setClusterId
(
clusterId
);
dto
.
setClusterName
(
clusterName
);
dto
.
setDataChangeCreatedBy
(
dataChangeCreatedBy
);
dto
.
setDataChangeLastModifiedBy
(
dataChangeLastModifiedBy
);
dto
.
setDataChangeCreatedTime
(
dataChangeCreatedTime
);
dto
.
setDataChangeLastModifiedTime
(
dataChangeLastModifiedTime
);
dto
.
setKey
(
key
);
dto
.
setValue
(
value
);
dto
.
setComment
(
comment
);
return
dto
;
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/ReleaseSnap
S
hot.java
→
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/ReleaseSnap
s
hot.java
View file @
9d19d637
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
...
...
@@ -16,7 +14,7 @@ import javax.persistence.Id;
@Entity
@Where
(
clause
=
"isDeleted = 0"
)
@SQLDelete
(
sql
=
"Update ReleaseSnapShot set isDeleted = 1 where id = ?"
)
public
class
ReleaseSnap
S
hot
{
public
class
ReleaseSnap
s
hot
{
@Id
@GeneratedValue
private
long
id
;
...
...
@@ -32,7 +30,7 @@ public class ReleaseSnapShot {
private
boolean
isDeleted
;
public
ReleaseSnap
S
hot
()
{
public
ReleaseSnap
s
hot
()
{
}
public
long
getId
()
{
...
...
@@ -75,12 +73,4 @@ public class ReleaseSnapShot {
isDeleted
=
deleted
;
}
public
ReleaseSnapshotDTO
toDTO
()
{
ReleaseSnapshotDTO
dto
=
new
ReleaseSnapshotDTO
();
dto
.
setId
(
id
);
dto
.
setClusterName
(
clusterName
);
dto
.
setConfigurations
(
configurations
);
dto
.
setReleaseId
(
releaseId
);
return
dto
;
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Version.java
View file @
9d19d637
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
...
...
@@ -84,13 +82,4 @@ public class Version {
this
.
parentVersion
=
parentVersion
;
}
public
VersionDTO
toDTO
()
{
VersionDTO
dto
=
new
VersionDTO
();
dto
.
setAppId
(
this
.
appId
);
dto
.
setId
(
this
.
id
);
dto
.
setName
(
this
.
name
);
dto
.
setParentVersion
(
this
.
parentVersion
);
dto
.
setReleaseId
(
this
.
releaseId
);
return
dto
;
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ReleaseSnapShotRepository.java
View file @
9d19d637
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
com.ctrip.apollo.biz.entity.ReleaseSnap
S
hot
;
import
com.ctrip.apollo.biz.entity.ReleaseSnap
s
hot
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
...
...
@@ -10,8 +10,8 @@ import java.util.List;
* @author Jason Song(song_s@ctrip.com)
*/
public
interface
ReleaseSnapShotRepository
extends
PagingAndSortingRepository
<
ReleaseSnap
S
hot
,
Long
>
{
ReleaseSnap
S
hot
findByReleaseIdAndClusterName
(
long
releaseId
,
String
clusterName
);
extends
PagingAndSortingRepository
<
ReleaseSnap
s
hot
,
Long
>
{
ReleaseSnap
s
hot
findByReleaseIdAndClusterName
(
long
releaseId
,
String
clusterName
);
List
<
ReleaseSnap
S
hot
>
findByReleaseId
(
long
releaseId
);
List
<
ReleaseSnap
s
hot
>
findByReleaseId
(
long
releaseId
);
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/impl/AdminConfigServiceImpl.java
View file @
9d19d637
package
com
.
ctrip
.
apollo
.
biz
.
service
.
impl
;
import
com.ctrip.apollo.biz.converter.EntityToDTOConverter
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.ConfigItem
;
import
com.ctrip.apollo.biz.entity.ReleaseSnap
S
hot
;
import
com.ctrip.apollo.biz.entity.ReleaseSnap
s
hot
;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.repository.ConfigItemRepository
;
...
...
@@ -39,15 +40,16 @@ public class AdminConfigServiceImpl implements AdminConfigService {
return
Collections
.
EMPTY_LIST
;
}
List
<
ReleaseSnap
S
hot
>
releaseSnapShots
=
releaseSnapShotRepository
.
findByReleaseId
(
releaseId
);
List
<
ReleaseSnap
s
hot
>
releaseSnapShots
=
releaseSnapShotRepository
.
findByReleaseId
(
releaseId
);
if
(
releaseSnapShots
==
null
||
releaseSnapShots
.
size
()
==
0
)
{
return
Collections
.
EMPTY_LIST
;
}
List
<
ReleaseSnapshotDTO
>
result
=
new
ArrayList
<>(
releaseSnapShots
.
size
());
for
(
ReleaseSnapShot
releaseSnapShot
:
releaseSnapShots
)
{
result
.
add
(
releaseSnapShot
.
toDTO
());
for
(
ReleaseSnapshot
releaseSnapShot
:
releaseSnapShots
)
{
ReleaseSnapshotDTO
dto
=
EntityToDTOConverter
.
convert
(
releaseSnapShot
);
result
.
add
(
dto
);
}
return
result
;
}
...
...
@@ -66,7 +68,8 @@ public class AdminConfigServiceImpl implements AdminConfigService {
List
<
VersionDTO
>
result
=
new
ArrayList
<>(
versions
.
size
());
for
(
Version
version
:
versions
)
{
result
.
add
(
version
.
toDTO
());
VersionDTO
dto
=
EntityToDTOConverter
.
convert
(
version
);
result
.
add
(
dto
);
}
return
result
;
}
...
...
@@ -80,7 +83,8 @@ public class AdminConfigServiceImpl implements AdminConfigService {
if
(
version
==
null
){
return
null
;
}
return
version
.
toDTO
();
VersionDTO
dto
=
EntityToDTOConverter
.
convert
(
version
);
return
dto
;
}
@Override
...
...
@@ -112,7 +116,8 @@ public class AdminConfigServiceImpl implements AdminConfigService {
List
<
ConfigItemDTO
>
result
=
new
ArrayList
<>(
configItems
.
size
());
for
(
ConfigItem
configItem
:
configItems
)
{
result
.
add
(
configItem
.
toDTO
());
ConfigItemDTO
dto
=
EntityToDTOConverter
.
convert
(
configItem
);
result
.
add
(
dto
);
}
return
result
;
}
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/impl/ConfigServiceImpl.java
View file @
9d19d637
...
...
@@ -2,7 +2,7 @@ package com.ctrip.apollo.biz.service.impl;
import
com.google.common.collect.Maps
;
import
com.ctrip.apollo.biz.entity.ReleaseSnap
S
hot
;
import
com.ctrip.apollo.biz.entity.ReleaseSnap
s
hot
;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository
;
import
com.ctrip.apollo.biz.repository.VersionRepository
;
...
...
@@ -49,7 +49,7 @@ public class ConfigServiceImpl implements ConfigService {
@Override
public
ApolloConfig
loadConfigByVersionAndClusterName
(
Version
version
,
String
clusterName
)
{
ReleaseSnap
S
hot
releaseSnapShot
=
ReleaseSnap
s
hot
releaseSnapShot
=
releaseSnapShotRepository
.
findByReleaseIdAndClusterName
(
version
.
getReleaseId
(),
clusterName
);
if
(
releaseSnapShot
==
null
)
{
...
...
@@ -59,7 +59,7 @@ public class ConfigServiceImpl implements ConfigService {
return
assembleConfig
(
version
,
releaseSnapShot
);
}
private
ApolloConfig
assembleConfig
(
Version
version
,
ReleaseSnap
S
hot
releaseSnapShot
)
{
private
ApolloConfig
assembleConfig
(
Version
version
,
ReleaseSnap
s
hot
releaseSnapShot
)
{
ApolloConfig
config
=
new
ApolloConfig
(
version
.
getAppId
(),
releaseSnapShot
.
getClusterName
(),
version
.
getName
(),
version
.
getReleaseId
());
...
...
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/impl/ConfigServiceImplTest.java
View file @
9d19d637
...
...
@@ -2,7 +2,7 @@ package com.ctrip.apollo.biz.service.impl;
import
com.google.common.collect.Maps
;
import
com.ctrip.apollo.biz.entity.ReleaseSnap
S
hot
;
import
com.ctrip.apollo.biz.entity.ReleaseSnap
s
hot
;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository
;
import
com.ctrip.apollo.biz.repository.VersionRepository
;
...
...
@@ -60,7 +60,7 @@ public class ConfigServiceImplTest {
String
someValidConfiguration
=
"{\"apollo.bar\": \"foo\"}"
;
Version
someVersion
=
assembleVersion
(
someAppId
,
someVersionName
,
someReleaseId
);
ReleaseSnap
S
hot
ReleaseSnap
s
hot
someReleaseSnapShot
=
assembleReleaseSnapShot
(
someReleaseId
,
someClusterName
,
someValidConfiguration
);
Map
<
String
,
Object
>
someMap
=
Maps
.
newHashMap
();
...
...
@@ -122,9 +122,9 @@ public class ConfigServiceImplTest {
return
version
;
}
private
ReleaseSnap
S
hot
assembleReleaseSnapShot
(
long
releaseId
,
String
clusterName
,
private
ReleaseSnap
s
hot
assembleReleaseSnapShot
(
long
releaseId
,
String
clusterName
,
String
configurations
)
{
ReleaseSnap
Shot
releaseSnapShot
=
new
ReleaseSnapS
hot
();
ReleaseSnap
shot
releaseSnapShot
=
new
ReleaseSnaps
hot
();
releaseSnapShot
.
setReleaseId
(
releaseId
);
releaseSnapShot
.
setClusterName
(
clusterName
);
releaseSnapShot
.
setConfigurations
(
configurations
);
...
...
pom.xml
View file @
9d19d637
...
...
@@ -40,10 +40,10 @@
<url>
https://travis-ci.org/ctripcorp/apollo
</url>
</ciManagement>
<issueManagement>
<system>
github
</system>
<url>
https://github.com/ctripcorp/apollo/issues
</url>
</issueManagement>
<issueManagement>
<system>
github
</system>
<url>
https://github.com/ctripcorp/apollo/issues
</url>
</issueManagement>
<developers>
<developer>
...
...
@@ -77,14 +77,14 @@
</roles>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<java.version>
1.8
</java.version>
<github.global.server>
github
</github.global.server>
<github.global.oauth2Token>
${env.GITHUB_OAUTH_TOKEN}
</github.global.oauth2Token>
</properties>
<modules>
<module>
apollo-buildtools
</module>
<module>
apollo-core
</module>
...
...
@@ -95,7 +95,7 @@
<module>
apollo-portal
</module>
<module>
apollo-demo
</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
...
...
@@ -154,7 +154,7 @@
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -162,7 +162,7 @@
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
...
...
@@ -218,22 +218,6 @@
</pluginManagement>
<plugins>
<plugin>
<groupId>
com.github.github
</groupId>
<artifactId>
site-maven-plugin
</artifactId>
<version>
0.12
</version>
<configuration>
<message>
Building site for ${project.version}
</message>
</configuration>
<executions>
<execution>
<goals>
<goal>
site
</goal>
</goals>
<phase>
site
</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-checkstyle-plugin
</artifactId>
</plugin>
...
...
@@ -243,7 +227,7 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>
travis
</id>
...
...
@@ -256,6 +240,22 @@
<build>
<plugins>
<plugin>
<groupId>
com.github.github
</groupId>
<artifactId>
site-maven-plugin
</artifactId>
<version>
0.12
</version>
<configuration>
<message>
Building site for ${project.version}
</message>
</configuration>
<executions>
<execution>
<goals>
<goal>
site
</goal>
</goals>
<phase>
site
</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
cobertura-maven-plugin
</artifactId>
<version>
2.7
</version>
...
...
@@ -285,7 +285,7 @@
</snapshots>
</repository>
</repositories>
<reporting>
<plugins>
<plugin>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment