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
a91fce64
Commit
a91fce64
authored
Aug 11, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
open api item 用key当主键
parent
03609414
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
22 deletions
+27
-22
ItemController.java
...ramework/apollo/openapi/v1/controller/ItemController.java
+22
-18
AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+3
-2
ItemService.java
...om/ctrip/framework/apollo/portal/service/ItemService.java
+2
-2
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java
View file @
a91fce64
...
...
@@ -35,8 +35,7 @@ public class ItemController {
@PreAuthorize
(
value
=
"@consumerPermissionValidator.hasModifyNamespacePermission(#request, #appId, #namespaceName)"
)
@RequestMapping
(
value
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
POST
)
public
OpenItemDTO
createItem
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
OpenItemDTO
item
,
HttpServletRequest
request
)
{
RequestPrecondition
.
checkArguments
(
...
...
@@ -60,48 +59,53 @@ public class ItemController {
}
@PreAuthorize
(
value
=
"@consumerPermissionValidator.hasModifyNamespacePermission(#request, #appId, #namespaceName)"
)
@RequestMapping
(
value
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{
itemId
}"
,
method
=
RequestMethod
.
PUT
)
@RequestMapping
(
value
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{
key:.+
}"
,
method
=
RequestMethod
.
PUT
)
public
void
updateItem
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@PathVariable
long
itemId
,
@RequestBody
OpenItemDTO
item
,
HttpServletRequest
request
)
{
@PathVariable
String
key
,
@RequestBody
OpenItemDTO
item
,
HttpServletRequest
request
)
{
RequestPrecondition
.
checkArguments
(
item
!=
null
,
"item payload can not be empty"
);
RequestPrecondition
.
checkArguments
(
item
!=
null
&&
item
.
getId
()
>
0
&&
itemId
==
item
.
getId
(),
"item data error"
);
RequestPrecondition
.
checkArguments
(
!
StringUtils
.
isContainEmpty
(
item
.
getKey
(),
item
.
getValue
(),
item
.
getDataChangeLastModifiedBy
()),
!
StringUtils
.
isContainEmpty
(
item
.
getKey
(),
item
.
getValue
(),
item
.
getDataChangeLastModifiedBy
()),
"key,value,dataChangeLastModifiedBy 字段不能为空"
);
RequestPrecondition
.
checkArguments
(
item
.
getKey
().
equals
(
key
),
"item payload can not be empty"
);
if
(
userService
.
findByUserId
(
item
.
getDataChangeLastModifiedBy
())
==
null
)
{
throw
new
BadRequestException
(
"用户不存在
.
"
);
throw
new
BadRequestException
(
"用户不存在"
);
}
ItemDTO
toUpdateItem
=
itemService
.
loadItem
(
Env
.
fromString
(
env
),
itemId
);
ItemDTO
toUpdateItem
=
itemService
.
loadItem
(
Env
.
fromString
(
env
),
appId
,
clusterName
,
namespaceName
,
item
.
getKey
()
);
if
(
toUpdateItem
==
null
)
{
throw
new
BadRequestException
(
"item
not exist
"
);
throw
new
BadRequestException
(
"item
不存在
"
);
}
//protect. only value,comment,lastModifiedBy can be modified
toUpdateItem
.
setComment
(
item
.
getComment
());
toUpdateItem
.
setValue
(
item
.
getValue
());
toUpdateItem
.
setDataChangeLastModifiedBy
(
item
.
getDataChangeLastModifiedBy
());
itemService
.
updateItem
(
appId
,
Env
.
fromString
(
env
),
clusterName
,
namespaceName
,
toUpdateItem
);
itemService
.
updateItem
(
appId
,
Env
.
fromString
(
env
),
clusterName
,
namespaceName
,
toUpdateItem
);
}
@PreAuthorize
(
value
=
"@consumerPermissionValidator.hasModifyNamespacePermission(#request, #appId, #namespaceName)"
)
@RequestMapping
(
value
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{
itemId
}"
,
method
=
RequestMethod
.
DELETE
)
@RequestMapping
(
value
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{
key:.+
}"
,
method
=
RequestMethod
.
DELETE
)
public
void
deleteItem
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@PathVariable
long
itemId
,
@RequestParam
String
operator
,
@PathVariable
String
key
,
@RequestParam
String
operator
,
HttpServletRequest
request
)
{
if
(
userService
.
findByUserId
(
operator
)
==
null
)
{
throw
new
BadRequestException
(
"用户不存在."
);
throw
new
BadRequestException
(
"用户不存在"
);
}
ItemDTO
toDeletedItem
=
itemService
.
loadItem
(
Env
.
valueOf
(
env
),
appId
,
clusterName
,
namespaceName
,
key
);
if
(
toDeletedItem
==
null
){
throw
new
BadRequestException
(
"item不存在"
);
}
itemService
.
deleteItem
(
Env
.
fromString
(
env
),
itemId
,
operator
);
itemService
.
deleteItem
(
Env
.
fromString
(
env
),
toDeletedItem
.
getId
(),
operator
);
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
View file @
a91fce64
...
...
@@ -90,8 +90,9 @@ public class AdminServiceAPI {
return
Arrays
.
asList
(
itemDTOs
);
}
public
ItemDTO
loadItem
(
Env
env
,
long
itemId
)
{
return
restTemplate
.
get
(
env
,
"/items/{itemId}"
,
ItemDTO
.
class
,
itemId
);
public
ItemDTO
loadItem
(
Env
env
,
String
appId
,
String
clusterName
,
String
namespaceName
,
String
key
)
{
return
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{key}"
,
ItemDTO
.
class
,
appId
,
clusterName
,
namespaceName
,
key
);
}
public
void
updateItemsByChangeSet
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java
View file @
a91fce64
...
...
@@ -114,8 +114,8 @@ public class ItemService {
return
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
);
}
public
ItemDTO
loadItem
(
Env
env
,
long
itemId
)
{
return
itemAPI
.
loadItem
(
env
,
itemId
);
public
ItemDTO
loadItem
(
Env
env
,
String
appId
,
String
clusterName
,
String
namespaceName
,
String
key
)
{
return
itemAPI
.
loadItem
(
env
,
appId
,
clusterName
,
namespaceName
,
key
);
}
public
void
syncItems
(
List
<
NamespaceIdentifier
>
comparedNamespaces
,
List
<
ItemDTO
>
sourceItems
)
{
...
...
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