Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
OLAT CI-CD Testing Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lars Oliver Dam
OLAT CI-CD Testing Project
Commits
a69bf4c9
Commit
a69bf4c9
authored
11 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OO-623,OPENOLAT-80: enhance the REST API with users/{identityKey}/groups/owner and participant
parent
3a5ac929
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/olat/restapi/group/MyGroupWebService.java
+57
-1
57 additions, 1 deletion
src/main/java/org/olat/restapi/group/MyGroupWebService.java
src/test/java/org/olat/restapi/UserMgmtTest.java
+42
-0
42 additions, 0 deletions
src/test/java/org/olat/restapi/UserMgmtTest.java
with
99 additions
and
1 deletion
src/main/java/org/olat/restapi/group/MyGroupWebService.java
+
57
−
1
View file @
a69bf4c9
...
...
@@ -84,9 +84,63 @@ public class MyGroupWebService {
@QueryParam
(
"externalId"
)
String
externalId
,
@QueryParam
(
"managed"
)
Boolean
managed
,
@Context
HttpServletRequest
httpRequest
,
@Context
Request
request
)
{
return
getGroupList
(
start
,
limit
,
externalId
,
managed
,
true
,
true
,
httpRequest
,
request
);
}
/**
* Return all groups of a user where the user is coach/owner.
* @response.representation.200.qname {http://www.example.com}groupVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The groups of the user
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVOes}
* @response.representation.404.doc The identity not found
* @param start The first result
* @param limit The maximum results
* @param externalId Search with an external ID
* @param managed (true / false) Search only managed / not managed groups
* @param httpRequest The HTTP request
* @param request The REST request
* @return The list of groups
*/
@GET
@Path
(
"owner"
)
@Produces
({
MediaType
.
APPLICATION_XML
,
MediaType
.
APPLICATION_JSON
})
public
Response
getOwnedGroupList
(
@QueryParam
(
"start"
)
@DefaultValue
(
"0"
)
Integer
start
,
@QueryParam
(
"limit"
)
@DefaultValue
(
"25"
)
Integer
limit
,
@QueryParam
(
"externalId"
)
String
externalId
,
@QueryParam
(
"managed"
)
Boolean
managed
,
@Context
HttpServletRequest
httpRequest
,
@Context
Request
request
)
{
return
getGroupList
(
start
,
limit
,
externalId
,
managed
,
true
,
false
,
httpRequest
,
request
);
}
/**
* Return all groups of a user where the user is participant.
* @response.representation.200.qname {http://www.example.com}groupVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The groups of the user
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVOes}
* @response.representation.404.doc The identity not found
* @param start The first result
* @param limit The maximum results
* @param externalId Search with an external ID
* @param managed (true / false) Search only managed / not managed groups
* @param httpRequest The HTTP request
* @param request The REST request
* @return The list of groups
*/
@GET
@Path
(
"participant"
)
@Produces
({
MediaType
.
APPLICATION_XML
,
MediaType
.
APPLICATION_JSON
})
public
Response
getParticipatingGroupList
(
@QueryParam
(
"start"
)
@DefaultValue
(
"0"
)
Integer
start
,
@QueryParam
(
"limit"
)
@DefaultValue
(
"25"
)
Integer
limit
,
@QueryParam
(
"externalId"
)
String
externalId
,
@QueryParam
(
"managed"
)
Boolean
managed
,
@Context
HttpServletRequest
httpRequest
,
@Context
Request
request
)
{
return
getGroupList
(
start
,
limit
,
externalId
,
managed
,
false
,
true
,
httpRequest
,
request
);
}
private
Response
getGroupList
(
Integer
start
,
Integer
limit
,
String
externalId
,
Boolean
managed
,
boolean
owner
,
boolean
participant
,
HttpServletRequest
httpRequest
,
Request
request
)
{
BusinessGroupService
bgs
=
CoreSpringFactory
.
getImpl
(
BusinessGroupService
.
class
);
SearchBusinessGroupParams
params
=
new
SearchBusinessGroupParams
(
retrievedUser
,
true
,
true
);
SearchBusinessGroupParams
params
=
new
SearchBusinessGroupParams
(
retrievedUser
,
owner
,
participant
);
if
(
StringHelper
.
containsNonWhitespace
(
externalId
))
{
params
.
setExternalId
(
externalId
);
}
...
...
@@ -116,8 +170,10 @@ public class MyGroupWebService {
}
return
Response
.
ok
(
groupVOs
).
build
();
}
}
/**
* Return all groups with information of a user. Paging is mandatory!
* @response.representation.200.qname {http://www.example.com}groupInfoVO
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/olat/restapi/UserMgmtTest.java
+
42
−
0
View file @
a69bf4c9
...
...
@@ -996,6 +996,48 @@ public class UserMgmtTest extends OlatJerseyTestCase {
conn
.
shutdown
();
}
@Test
public
void
testUserGroup_owner
()
throws
IOException
,
URISyntaxException
{
RestConnection
conn
=
new
RestConnection
();
assertTrue
(
conn
.
login
(
"administrator"
,
"openolat"
));
//retrieve all groups
URI
uri
=
UriBuilder
.
fromUri
(
getContextURI
()).
path
(
"users"
).
path
(
id1
.
getKey
().
toString
())
.
path
(
"groups"
).
path
(
"owner"
).
queryParam
(
"start"
,
0
).
queryParam
(
"limit"
,
1
).
build
();
HttpGet
method
=
conn
.
createGet
(
uri
,
MediaType
.
APPLICATION_JSON
+
";pagingspec=1.0"
,
true
);
HttpResponse
response
=
conn
.
execute
(
method
);
assertEquals
(
200
,
response
.
getStatusLine
().
getStatusCode
());
GroupVOes
groups
=
conn
.
parse
(
response
,
GroupVOes
.
class
);
assertNotNull
(
groups
);
assertNotNull
(
groups
.
getGroups
());
assertEquals
(
1
,
groups
.
getGroups
().
length
);
assertEquals
(
1
,
groups
.
getTotalCount
());
//g1
conn
.
shutdown
();
}
@Test
public
void
testUserGroup_participant
()
throws
IOException
,
URISyntaxException
{
RestConnection
conn
=
new
RestConnection
();
assertTrue
(
conn
.
login
(
"administrator"
,
"openolat"
));
//retrieve all groups
URI
uri
=
UriBuilder
.
fromUri
(
getContextURI
()).
path
(
"users"
).
path
(
id1
.
getKey
().
toString
())
.
path
(
"groups"
).
path
(
"participant"
).
queryParam
(
"start"
,
0
).
queryParam
(
"limit"
,
1
).
build
();
HttpGet
method
=
conn
.
createGet
(
uri
,
MediaType
.
APPLICATION_JSON
+
";pagingspec=1.0"
,
true
);
HttpResponse
response
=
conn
.
execute
(
method
);
assertEquals
(
200
,
response
.
getStatusLine
().
getStatusCode
());
GroupVOes
groups
=
conn
.
parse
(
response
,
GroupVOes
.
class
);
assertNotNull
(
groups
);
assertNotNull
(
groups
.
getGroups
());
assertEquals
(
1
,
groups
.
getGroups
().
length
);
assertEquals
(
2
,
groups
.
getTotalCount
());
//g2 and g3
conn
.
shutdown
();
}
@Test
public
void
testUserGroupInfosWithPaging
()
throws
IOException
,
URISyntaxException
{
RestConnection
conn
=
new
RestConnection
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment