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
450548f0
Commit
450548f0
authored
Aug 11, 2016
by
Jason Song
Committed by
GitHub
Aug 11, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #375 from lepdou/open
open api item 用key当主键
parents
03609414
e45c7bc3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
32 deletions
+27
-32
OpenItemDTO.java
...a/com/ctrip/framework/apollo/openapi/dto/OpenItemDTO.java
+0
-10
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/dto/OpenItemDTO.java
View file @
450548f0
...
...
@@ -4,22 +4,12 @@ import com.ctrip.framework.apollo.common.dto.BaseDTO;
public
class
OpenItemDTO
extends
BaseDTO
{
private
long
id
;
private
String
key
;
private
String
value
;
private
String
comment
;
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
public
String
getKey
()
{
return
key
;
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ItemController.java
View file @
450548f0
...
...
@@ -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
),
"path中的key和payload中的key不一致"
);
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
toDeleteItem
=
itemService
.
loadItem
(
Env
.
valueOf
(
env
),
appId
,
clusterName
,
namespaceName
,
key
);
if
(
toDeleteItem
==
null
){
throw
new
BadRequestException
(
"item不存在"
);
}
itemService
.
deleteItem
(
Env
.
fromString
(
env
),
itemId
,
operator
);
itemService
.
deleteItem
(
Env
.
fromString
(
env
),
toDeleteItem
.
getId
(),
operator
);
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
View file @
450548f0
...
...
@@ -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 @
450548f0
...
...
@@ -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