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
72276dca
Commit
72276dca
authored
12 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
CL-155: add a method to create groups with the REST API
parent
26ae51e4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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/LearningGroupWebService.java
+43
-0
43 additions, 0 deletions
.../java/org/olat/restapi/group/LearningGroupWebService.java
src/test/java/org/olat/restapi/GroupMgmtTest.java
+27
-0
27 additions, 0 deletions
src/test/java/org/olat/restapi/GroupMgmtTest.java
with
70 additions
and
0 deletions
src/main/java/org/olat/restapi/group/LearningGroupWebService.java
+
43
−
0
View file @
72276dca
...
@@ -179,6 +179,49 @@ public class LearningGroupWebService {
...
@@ -179,6 +179,49 @@ public class LearningGroupWebService {
return
response
.
build
();
return
response
.
build
();
}
}
/**
* Create a group.
* @response.representation.qname {http://www.example.com}groupVO
* @response.representation.mediaType application/xml, application/json
* @response.representation.doc A business group in the OLAT system
* @response.representation.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVO}
* @response.representation.200.qname {http://www.example.com}groupVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The saved business group
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The business group cannot be found
* @param groupKey The key of the group
* @param group The group
* @param request The HTTP request
* @return
*/
@PUT
@Consumes
({
MediaType
.
APPLICATION_XML
,
MediaType
.
APPLICATION_JSON
})
@Produces
({
MediaType
.
APPLICATION_XML
,
MediaType
.
APPLICATION_JSON
})
public
Response
createGroup
(
final
GroupVO
group
,
@Context
HttpServletRequest
request
)
{
Identity
identity
=
RestSecurityHelper
.
getIdentity
(
request
);
if
(
identity
==
null
||
!
isGroupManager
(
request
))
{
return
Response
.
serverError
().
status
(
Status
.
UNAUTHORIZED
).
build
();
}
final
BusinessGroupService
bgs
=
CoreSpringFactory
.
getImpl
(
BusinessGroupService
.
class
);
if
(
group
.
getKey
()
!=
null
&&
group
.
getKey
().
longValue
()
>
0
)
{
return
postGroup
(
group
.
getKey
(),
group
,
request
);
}
if
(!
StringHelper
.
containsNonWhitespace
(
group
.
getName
()))
{
return
Response
.
serverError
().
status
(
Status
.
NOT_ACCEPTABLE
).
build
();
}
Integer
minPart
=
normalize
(
group
.
getMinParticipants
());
Integer
maxPart
=
normalize
(
group
.
getMaxParticipants
());
BusinessGroup
newBG
=
bgs
.
createBusinessGroup
(
identity
,
group
.
getName
(),
group
.
getDescription
(),
minPart
,
maxPart
,
false
,
false
,
null
);
GroupVO
savedVO
=
ObjectFactory
.
get
(
newBG
);
return
Response
.
ok
(
savedVO
).
build
();
}
/**
/**
* Updates a group.
* Updates a group.
* @response.representation.qname {http://www.example.com}groupVO
* @response.representation.qname {http://www.example.com}groupVO
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/olat/restapi/GroupMgmtTest.java
+
27
−
0
View file @
72276dca
...
@@ -415,6 +415,33 @@ public class GroupMgmtTest extends OlatJerseyTestCase {
...
@@ -415,6 +415,33 @@ public class GroupMgmtTest extends OlatJerseyTestCase {
assertEquals
(
bg
.
getDescription
(),
"rest-g1 description"
);
assertEquals
(
bg
.
getDescription
(),
"rest-g1 description"
);
}
}
@Test
public
void
testCreateCourseGroup
()
throws
IOException
,
URISyntaxException
{
assertTrue
(
conn
.
login
(
"administrator"
,
"openolat"
));
GroupVO
vo
=
new
GroupVO
();
vo
.
setName
(
"rest-g5-new"
);
vo
.
setDescription
(
"rest-g5 description"
);
vo
.
setType
(
"BuddyGroup"
);
URI
request
=
UriBuilder
.
fromUri
(
getContextURI
()).
path
(
"groups"
).
build
();
HttpPut
method
=
conn
.
createPut
(
request
,
MediaType
.
APPLICATION_JSON
,
true
);
conn
.
addJsonEntity
(
method
,
vo
);
HttpResponse
response
=
conn
.
execute
(
method
);
assertTrue
(
response
.
getStatusLine
().
getStatusCode
()
==
200
||
response
.
getStatusLine
().
getStatusCode
()
==
201
);
GroupVO
newGroupVo
=
conn
.
parse
(
response
,
GroupVO
.
class
);
assertNotNull
(
newGroupVo
);
BusinessGroup
bg
=
businessGroupService
.
loadBusinessGroup
(
newGroupVo
.
getKey
());
assertNotNull
(
bg
);
assertEquals
(
bg
.
getKey
(),
newGroupVo
.
getKey
());
assertEquals
(
bg
.
getName
(),
"rest-g5-new"
);
assertEquals
(
bg
.
getDescription
(),
"rest-g5 description"
);
}
@Test
@Test
public
void
testDeleteCourseGroup
()
throws
IOException
,
URISyntaxException
{
public
void
testDeleteCourseGroup
()
throws
IOException
,
URISyntaxException
{
assertTrue
(
conn
.
login
(
"administrator"
,
"openolat"
));
assertTrue
(
conn
.
login
(
"administrator"
,
"openolat"
));
...
...
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