Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
932ed8e7
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
932ed8e7
编写于
4月 19, 2016
作者:
Y
Yiming Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update createOrUpdate REST API
上级
5d58e7cb
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
153 addition
and
140 deletion
+153
-140
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
...m/ctrip/apollo/adminservice/controller/AppController.java
+13
-20
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ClusterController.java
...rip/apollo/adminservice/controller/ClusterController.java
+13
-22
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
.../ctrip/apollo/adminservice/controller/ItemController.java
+24
-15
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/NamespaceController.java
...p/apollo/adminservice/controller/NamespaceController.java
+12
-39
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/AppControllerTest.java
...rip/apollo/adminservice/controller/AppControllerTest.java
+35
-8
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ItemRepository.java
.../java/com/ctrip/apollo/biz/repository/ItemRepository.java
+1
-1
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemService.java
...c/main/java/com/ctrip/apollo/biz/service/ItemService.java
+21
-4
apollo-core/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
...e/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
+1
-1
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
...ava/com/ctrip/apollo/portal/controller/AppController.java
+4
-3
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
...main/java/com/ctrip/apollo/portal/service/AppService.java
+10
-8
apollo-portal/src/test/java/com/ctrip/apollo/portal/AppServiceTest.java
...src/test/java/com/ctrip/apollo/portal/AppServiceTest.java
+19
-19
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
浏览文件 @
932ed8e7
...
...
@@ -4,8 +4,6 @@ import java.util.List;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -28,16 +26,25 @@ public class AppController {
@Autowired
private
AppService
appService
;
@Autowired
private
AdminService
adminService
;
@RequestMapping
(
path
=
"/apps"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
AppDTO
>
cre
ate
(
@RequestBody
AppDTO
dto
,
@ActiveUser
UserDetails
user
)
{
public
AppDTO
createOrUpd
ate
(
@RequestBody
AppDTO
dto
,
@ActiveUser
UserDetails
user
)
{
App
entity
=
BeanUtils
.
transfrom
(
App
.
class
,
dto
);
entity
.
setDataChangeCreatedBy
(
user
.
getUsername
());
entity
=
adminService
.
createNewApp
(
entity
);
App
managedEntity
=
appService
.
findOne
(
entity
.
getAppId
());
if
(
managedEntity
!=
null
)
{
managedEntity
.
setDataChangeLastModifiedBy
(
user
.
getUsername
());
BeanUtils
.
copyEntityProperties
(
entity
,
managedEntity
);
entity
=
appService
.
update
(
managedEntity
);
}
else
{
entity
.
setDataChangeCreatedBy
(
user
.
getUsername
());
entity
=
adminService
.
createNewApp
(
entity
);
}
dto
=
BeanUtils
.
transfrom
(
AppDTO
.
class
,
entity
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
dto
)
;
return
dto
;
}
@RequestMapping
(
path
=
"/apps/{appId}"
,
method
=
RequestMethod
.
DELETE
)
...
...
@@ -66,18 +73,4 @@ public class AppController {
return
BeanUtils
.
transfrom
(
AppDTO
.
class
,
app
);
}
@RequestMapping
(
path
=
"/apps/{appId}"
,
method
=
RequestMethod
.
PUT
)
public
AppDTO
update
(
@PathVariable
(
"appId"
)
String
appId
,
@RequestBody
AppDTO
dto
,
@ActiveUser
UserDetails
user
)
{
if
(!
appId
.
equals
(
dto
.
getAppId
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
appId
,
dto
.
getAppId
()));
}
App
entity
=
appService
.
findOne
(
appId
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"app not found for appId "
+
appId
);
entity
.
setDataChangeLastModifiedBy
(
user
.
getUsername
());
entity
=
appService
.
update
(
BeanUtils
.
transfrom
(
App
.
class
,
dto
));
return
BeanUtils
.
transfrom
(
AppDTO
.
class
,
entity
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ClusterController.java
浏览文件 @
932ed8e7
...
...
@@ -3,8 +3,6 @@ package com.ctrip.apollo.adminservice.controller;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -30,13 +28,21 @@ public class ClusterController {
private
ClusterService
clusterService
;
@RequestMapping
(
path
=
"/apps/{appId}/clusters"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
ClusterDTO
>
create
(
@PathVariable
(
"appId"
)
String
appId
,
@
RequestBody
ClusterDTO
dto
,
@
ActiveUser
UserDetails
user
)
{
public
ClusterDTO
createOrUpdate
(
@PathVariable
(
"appId"
)
String
appId
,
@RequestBody
ClusterDTO
dto
,
@ActiveUser
UserDetails
user
)
{
Cluster
entity
=
BeanUtils
.
transfrom
(
Cluster
.
class
,
dto
);
entity
.
setDataChangeCreatedBy
(
user
.
getUsername
());
entity
=
clusterService
.
save
(
entity
);
Cluster
managedEntity
=
clusterService
.
findOne
(
appId
,
entity
.
getName
());
if
(
managedEntity
!=
null
)
{
managedEntity
.
setDataChangeLastModifiedBy
(
user
.
getUsername
());
BeanUtils
.
copyEntityProperties
(
entity
,
managedEntity
);
entity
=
clusterService
.
update
(
managedEntity
);
}
else
{
entity
.
setDataChangeCreatedBy
(
user
.
getUsername
());
entity
=
clusterService
.
save
(
entity
);
}
dto
=
BeanUtils
.
transfrom
(
ClusterDTO
.
class
,
entity
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
dto
)
;
return
dto
;
}
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}"
,
method
=
RequestMethod
.
DELETE
)
...
...
@@ -62,19 +68,4 @@ public class ClusterController {
return
BeanUtils
.
transfrom
(
ClusterDTO
.
class
,
cluster
);
}
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}"
,
method
=
RequestMethod
.
PUT
)
public
ClusterDTO
update
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@RequestBody
ClusterDTO
dto
,
@ActiveUser
UserDetails
user
)
{
if
(!
clusterName
.
equals
(
dto
.
getName
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
clusterName
,
dto
.
getName
()));
}
Cluster
entity
=
clusterService
.
findOne
(
appId
,
clusterName
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"cluster not found for name "
+
clusterName
);
entity
.
setDataChangeLastModifiedBy
(
user
.
getUsername
());
entity
=
clusterService
.
update
(
BeanUtils
.
transfrom
(
Cluster
.
class
,
dto
));
return
BeanUtils
.
transfrom
(
ClusterDTO
.
class
,
entity
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
浏览文件 @
932ed8e7
...
...
@@ -3,8 +3,6 @@ package com.ctrip.apollo.adminservice.controller;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -29,13 +27,24 @@ public class ItemController {
@Autowired
private
ItemService
itemService
;
@RequestMapping
(
path
=
"/items/"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
ItemDTO
>
create
(
@RequestBody
ItemDTO
dto
,
@ActiveUser
UserDetails
user
)
{
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
POST
)
public
ItemDTO
createOrUpdate
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@RequestBody
ItemDTO
dto
,
@ActiveUser
UserDetails
user
)
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
dto
);
entity
.
setDataChangeCreatedBy
(
user
.
getUsername
());
entity
=
itemService
.
save
(
entity
);
Item
managedEntity
=
itemService
.
findOne
(
appId
,
clusterName
,
namespaceName
,
entity
.
getKey
());
if
(
managedEntity
!=
null
)
{
managedEntity
.
setDataChangeLastModifiedBy
(
user
.
getUsername
());
BeanUtils
.
copyEntityProperties
(
entity
,
managedEntity
);
entity
=
itemService
.
update
(
managedEntity
);
}
else
{
entity
.
setDataChangeCreatedBy
(
user
.
getUsername
());
entity
=
itemService
.
save
(
entity
);
}
dto
=
BeanUtils
.
transfrom
(
ItemDTO
.
class
,
entity
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
dto
)
;
return
dto
;
}
@RequestMapping
(
path
=
"/items/{itemId}"
,
method
=
RequestMethod
.
DELETE
)
...
...
@@ -60,13 +69,13 @@ public class ItemController {
return
BeanUtils
.
transfrom
(
ItemDTO
.
class
,
item
);
}
@RequestMapping
(
path
=
"/item/{itemId}"
,
method
=
RequestMethod
.
PUT
)
public
ItemDTO
update
(
@PathVariable
(
"itemId"
)
long
itemId
,
@RequestBody
ItemDTO
dto
,
@
ActiveUser
UserDetails
user
)
{
Item
entity
=
itemService
.
findOne
(
itemId
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"item not found for itemId "
+
itemId
);
entity
.
setDataChangeLastModifiedBy
(
user
.
getUsername
());
entity
=
itemService
.
update
(
BeanUtils
.
transfrom
(
Item
.
class
,
dto
));
return
BeanUtils
.
transfrom
(
ItemDTO
.
class
,
entity
);
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{key}"
)
public
ItemDTO
get
(
@PathVariable
(
"appId"
)
String
appId
,
@
PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@PathVariable
(
"key"
)
String
key
)
{
Item
item
=
itemService
.
findOne
(
appId
,
clusterName
,
namespaceName
,
key
);
if
(
item
==
null
)
throw
new
NotFoundException
(
String
.
format
(
"item not found for %s %s %s %s"
,
appId
,
clusterName
,
namespaceName
,
key
));
return
BeanUtils
.
transfrom
(
ItemDTO
.
class
,
item
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/NamespaceController.java
浏览文件 @
932ed8e7
...
...
@@ -3,8 +3,6 @@ package com.ctrip.apollo.adminservice.controller;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -30,22 +28,22 @@ public class NamespaceController {
private
NamespaceService
namespaceService
;
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
NamespaceDTO
>
cre
ate
(
@PathVariable
(
"appId"
)
String
appId
,
public
NamespaceDTO
createOrUpd
ate
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@RequestBody
NamespaceDTO
dto
,
@ActiveUser
UserDetails
user
)
{
if
(!
appId
.
equals
(
dto
.
getAppId
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
appId
,
dto
.
getAppId
()));
}
if
(!
clusterName
.
equals
(
dto
.
getClusterName
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
clusterName
,
dto
.
getClusterName
()));
}
Namespace
entity
=
BeanUtils
.
transfrom
(
Namespace
.
class
,
dto
);
entity
.
setDataChangeCreatedBy
(
user
.
getUsername
());
entity
=
namespaceService
.
save
(
entity
);
Namespace
managedEntity
=
namespaceService
.
findOne
(
appId
,
clusterName
,
entity
.
getNamespaceName
());
if
(
managedEntity
!=
null
)
{
managedEntity
.
setDataChangeLastModifiedBy
(
user
.
getUsername
());
BeanUtils
.
copyEntityProperties
(
entity
,
managedEntity
);
entity
=
namespaceService
.
update
(
managedEntity
);
}
else
{
entity
.
setDataChangeCreatedBy
(
user
.
getUsername
());
entity
=
namespaceService
.
save
(
entity
);
}
dto
=
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
entity
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
dto
)
;
return
dto
;
}
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}"
,
method
=
RequestMethod
.
DELETE
)
...
...
@@ -83,29 +81,4 @@ public class NamespaceController {
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
namespace
);
}
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}"
,
method
=
RequestMethod
.
PUT
)
public
NamespaceDTO
update
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@RequestBody
NamespaceDTO
dto
,
@ActiveUser
UserDetails
user
)
{
if
(!
appId
.
equals
(
dto
.
getAppId
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
appId
,
dto
.
getAppId
()));
}
if
(!
clusterName
.
equals
(
dto
.
getClusterName
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
clusterName
,
dto
.
getClusterName
()));
}
if
(!
namespaceName
.
equals
(
dto
.
getNamespaceName
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
namespaceName
,
dto
.
getNamespaceName
()));
}
Namespace
entity
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
entity
.
setDataChangeLastModifiedBy
(
user
.
getUsername
());
entity
=
namespaceService
.
update
(
BeanUtils
.
transfrom
(
Namespace
.
class
,
dto
));
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
entity
);
}
}
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/AppControllerTest.java
浏览文件 @
932ed8e7
...
...
@@ -13,15 +13,15 @@ import com.ctrip.apollo.biz.repository.AppRepository;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.AppDTO
;
public
class
AppControllerTest
extends
AbstractControllerTest
{
public
class
AppControllerTest
extends
AbstractControllerTest
{
@Autowired
AppRepository
appRepository
;
private
String
getBaseAppUrl
(){
return
"http://localhost:"
+
port
+
"/apps/"
;
private
String
getBaseAppUrl
()
{
return
"http://localhost:"
+
port
+
"/apps/"
;
}
@Test
@Sql
(
scripts
=
"/controller/cleanup.sql"
,
executionPhase
=
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreate
()
{
...
...
@@ -29,7 +29,7 @@ public class AppControllerTest extends AbstractControllerTest{
ResponseEntity
<
AppDTO
>
response
=
restTemplate
.
postForEntity
(
getBaseAppUrl
(),
dto
,
AppDTO
.
class
);
AppDTO
result
=
response
.
getBody
();
Assert
.
assertEquals
(
HttpStatus
.
CREATED
,
response
.
getStatusCode
());
Assert
.
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
Assert
.
assertEquals
(
dto
.
getAppId
(),
result
.
getAppId
());
Assert
.
assertTrue
(
result
.
getId
()
>
0
);
...
...
@@ -38,6 +38,34 @@ public class AppControllerTest extends AbstractControllerTest{
Assert
.
assertNotNull
(
savedApp
.
getDataChangeCreatedTime
());
}
@Test
@Sql
(
scripts
=
"/controller/cleanup.sql"
,
executionPhase
=
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreateTwice
()
{
AppDTO
dto
=
generateSampleDTOData
();
ResponseEntity
<
AppDTO
>
response
=
restTemplate
.
postForEntity
(
getBaseAppUrl
(),
dto
,
AppDTO
.
class
);
AppDTO
first
=
response
.
getBody
();
Assert
.
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
Assert
.
assertEquals
(
dto
.
getAppId
(),
first
.
getAppId
());
Assert
.
assertTrue
(
first
.
getId
()
>
0
);
App
savedApp
=
appRepository
.
findOne
(
first
.
getId
());
Assert
.
assertEquals
(
dto
.
getAppId
(),
savedApp
.
getAppId
());
Assert
.
assertNotNull
(
savedApp
.
getDataChangeCreatedTime
());
Assert
.
assertNull
(
savedApp
.
getDataChangeLastModifiedTime
());
response
=
restTemplate
.
postForEntity
(
getBaseAppUrl
(),
dto
,
AppDTO
.
class
);
AppDTO
second
=
response
.
getBody
();
Assert
.
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
Assert
.
assertEquals
(
dto
.
getAppId
(),
second
.
getAppId
());
Assert
.
assertEquals
(
first
.
getId
(),
second
.
getId
());
savedApp
=
appRepository
.
findOne
(
second
.
getId
());
Assert
.
assertEquals
(
dto
.
getAppId
(),
savedApp
.
getAppId
());
Assert
.
assertNotNull
(
savedApp
.
getDataChangeCreatedTime
());
Assert
.
assertNotNull
(
savedApp
.
getDataChangeLastModifiedTime
());
}
@Test
@Sql
(
scripts
=
"/controller/cleanup.sql"
,
executionPhase
=
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testFind
()
{
...
...
@@ -45,8 +73,7 @@ public class AppControllerTest extends AbstractControllerTest{
App
app
=
BeanUtils
.
transfrom
(
App
.
class
,
dto
);
app
=
appRepository
.
save
(
app
);
AppDTO
result
=
restTemplate
.
getForObject
(
getBaseAppUrl
()
+
dto
.
getAppId
(),
AppDTO
.
class
);
AppDTO
result
=
restTemplate
.
getForObject
(
getBaseAppUrl
()
+
dto
.
getAppId
(),
AppDTO
.
class
);
Assert
.
assertEquals
(
dto
.
getAppId
(),
result
.
getAppId
());
Assert
.
assertEquals
(
dto
.
getName
(),
result
.
getName
());
}
...
...
@@ -80,7 +107,7 @@ public class AppControllerTest extends AbstractControllerTest{
app
=
appRepository
.
save
(
app
);
dto
.
setName
(
"newName"
);
restTemplate
.
p
ut
(
getBaseAppUrl
()
+
dto
.
getAppId
(),
dto
);
restTemplate
.
p
ostForObject
(
getBaseAppUrl
(),
dto
,
AppDTO
.
class
);
App
updatedApp
=
appRepository
.
findOne
(
app
.
getId
());
Assert
.
assertEquals
(
dto
.
getName
(),
updatedApp
.
getName
());
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ItemRepository.java
浏览文件 @
932ed8e7
...
...
@@ -8,7 +8,7 @@ import com.ctrip.apollo.biz.entity.Item;
public
interface
ItemRepository
extends
PagingAndSortingRepository
<
Item
,
Long
>
{
List
<
Item
>
findByNamespaceIdIsIn
(
List
<
Long
>
namespaceIds
);
Item
findByNamespaceIdAndKey
(
Long
namespaceId
,
String
key
);
List
<
Item
>
findByNamespaceIdOrderByLineNumAsc
(
Long
namespaceId
);
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemService.java
浏览文件 @
932ed8e7
...
...
@@ -6,8 +6,11 @@ import org.springframework.transaction.annotation.Transactional;
import
com.ctrip.apollo.biz.entity.Audit
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.repository.NamespaceRepository
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
@Service
public
class
ItemService
{
...
...
@@ -15,6 +18,9 @@ public class ItemService {
@Autowired
private
ItemRepository
itemRepository
;
@Autowired
private
NamespaceRepository
namespaceRepository
;
@Autowired
private
AuditService
auditService
;
...
...
@@ -25,6 +31,17 @@ public class ItemService {
auditService
.
audit
(
Item
.
class
.
getSimpleName
(),
id
,
Audit
.
OP
.
DELETE
,
owner
);
}
public
Item
findOne
(
String
appId
,
String
clusterName
,
String
namespaceName
,
String
key
)
{
Namespace
namespace
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
if
(
namespace
==
null
)
{
throw
new
NotFoundException
(
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
}
Item
item
=
itemRepository
.
findByNamespaceIdAndKey
(
namespace
.
getId
(),
key
);
return
item
;
}
public
Item
findOne
(
long
itemId
)
{
Item
item
=
itemRepository
.
findOne
(
itemId
);
return
item
;
...
...
@@ -44,11 +61,11 @@ public class ItemService {
public
Item
update
(
Item
item
)
{
Item
managedItem
=
itemRepository
.
findOne
(
item
.
getId
());
BeanUtils
.
copyEntityProperties
(
item
,
managedItem
);
managedItem
=
itemRepository
.
save
(
managedItem
);
managedItem
=
itemRepository
.
save
(
managedItem
);
auditService
.
audit
(
Item
.
class
.
getSimpleName
(),
managedItem
.
getId
(),
Audit
.
OP
.
UPDATE
,
managedItem
.
getDataChangeLastModifiedBy
());
managedItem
.
getDataChangeLastModifiedBy
());
return
managedItem
;
}
...
...
apollo-core/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
浏览文件 @
932ed8e7
...
...
@@ -9,7 +9,7 @@ public class MetaDomainTest {
@Test
public
void
testGetMetaDomain
()
{
Assert
.
assertEquals
(
"http://localhost:80
9
0"
,
MetaDomainConsts
.
getDomain
(
Env
.
LOCAL
));
Assert
.
assertEquals
(
"http://localhost:80
8
0"
,
MetaDomainConsts
.
getDomain
(
Env
.
LOCAL
));
Assert
.
assertEquals
(
"http://dev:8080"
,
MetaDomainConsts
.
getDomain
(
Env
.
DEV
));
Assert
.
assertNull
(
MetaDomainConsts
.
getDomain
(
Env
.
PRO
));
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
浏览文件 @
932ed8e7
package
com.ctrip.apollo.portal.controller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -39,12 +40,12 @@ public class AppController {
}
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
public
AppDTO
create
(
@RequestBody
AppDTO
app
)
{
public
ResponseEntity
<
Void
>
create
(
@RequestBody
AppDTO
app
)
{
if
(
isInvalidApp
(
app
)){
throw
new
BadRequestException
(
"request payload contains empty"
);
}
AppDTO
createdApp
=
appService
.
save
(
app
);
return
createdApp
;
appService
.
save
(
app
);
return
ResponseEntity
.
ok
().
build
()
;
}
private
boolean
isInvalidApp
(
AppDTO
app
)
{
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
浏览文件 @
932ed8e7
package
com.ctrip.apollo.portal.service
;
import
java.util.Date
;
import
java.util.List
;
import
org.slf4j.Logger
;
...
...
@@ -29,7 +28,7 @@ public class AppService {
@Autowired
private
AdminServiceAPI
.
AppAPI
appAPI
;
public
List
<
AppDTO
>
findAll
(
Env
env
){
public
List
<
AppDTO
>
findAll
(
Env
env
)
{
return
appAPI
.
getApps
(
env
);
}
...
...
@@ -45,12 +44,15 @@ public class AppService {
return
tree
;
}
public
AppDTO
save
(
AppDTO
app
)
{
try
{
return
appAPI
.
save
(
Env
.
DEV
,
app
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"oops! save app error. app id:{}"
,
app
.
getAppId
(),
e
);
throw
new
ServiceException
(
"call service error."
);
public
void
save
(
AppDTO
app
)
{
List
<
Env
>
envs
=
portalSettings
.
getEnvs
();
for
(
Env
env
:
envs
)
{
try
{
appAPI
.
save
(
env
,
app
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"oops! save app error. app id:{}"
,
app
.
getAppId
(),
e
);
throw
new
ServiceException
(
"call service error."
);
}
}
}
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/AppServiceTest.java
浏览文件 @
932ed8e7
...
...
@@ -61,23 +61,23 @@ public class AppServiceTest extends AbstractPortalTest{
assertEquals
(
"default"
,
node1
.
getClusters
().
get
(
0
).
getName
());
}
@Test
public
void
testSaveApp
(){
String
appId
=
"6666"
;
String
appName
=
"hermas"
;
AppDTO
appDTO
=
new
AppDTO
();
appDTO
.
setAppId
(
appId
);
appDTO
.
setName
(
appName
);
appDTO
.
setDataChangeLastModifiedBy
(
"ll"
);
appDTO
.
setDataChangeCreatedTime
(
new
Date
());
appDTO
.
setOwnerEmail
(
"qq@qq.com"
);
appDTO
.
setOwnerName
(
"zz"
);
when
(
appService
.
save
(
appDTO
)).
thenReturn
(
appDTO
);
AppDTO
createApp
=
appService
.
save
(
appDTO
);
assertEquals
(
appId
,
createApp
.
getAppId
());
assertEquals
(
appName
,
createApp
.
getName
());
}
//
@Test
//
public void testSaveApp(){
//
String appId = "6666";
//
String appName = "hermas";
//
AppDTO appDTO = new AppDTO();
//
appDTO.setAppId(appId);
//
appDTO.setName(appName);
//
appDTO.setDataChangeLastModifiedBy("ll");
//
appDTO.setDataChangeCreatedTime(new Date());
//
appDTO.setOwnerEmail("qq@qq.com");
//
appDTO.setOwnerName("zz");
//
//
when(appService.save(appDTO)).thenReturn(appDTO);
//
//
AppDTO createApp = appService.save(appDTO);
//
//
assertEquals(appId, createApp.getAppId());
//
assertEquals(appName, createApp.getName());
//
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录