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
368a8e0e
Commit
368a8e0e
authored
12 years ago
by
srosse
Browse files
Options
Downloads
Patches
Plain Diff
OMA-78: add method to delete calendar events
parent
0f3418ce
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/commons/calendar/restapi/CalendarWebService.java
+38
-0
38 additions, 0 deletions
...org/olat/commons/calendar/restapi/CalendarWebService.java
src/test/java/org/olat/restapi/CalendarTest.java
+29
-0
29 additions, 0 deletions
src/test/java/org/olat/restapi/CalendarTest.java
with
67 additions
and
0 deletions
src/main/java/org/olat/commons/calendar/restapi/CalendarWebService.java
+
38
−
0
View file @
368a8e0e
...
...
@@ -29,6 +29,7 @@ import java.util.UUID;
import
javax.servlet.http.HttpServletRequest
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.DELETE
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.PUT
;
...
...
@@ -137,6 +138,43 @@ public class CalendarWebService {
return
Response
.
ok
(
voes
).
build
();
}
@DELETE
@Path
(
"{calendarId}/events/{eventId}"
)
@Produces
({
MediaType
.
APPLICATION_XML
,
MediaType
.
APPLICATION_JSON
})
@Consumes
({
MediaType
.
APPLICATION_FORM_URLENCODED
,
MediaType
.
APPLICATION_XML
,
MediaType
.
APPLICATION_JSON
})
public
Response
deleteEventByCalendar
(
@PathParam
(
"calendarId"
)
String
calendarId
,
@PathParam
(
"eventId"
)
String
eventId
,
@PathParam
(
"identityKey"
)
Long
identityKey
,
@Context
HttpServletRequest
httpRequest
)
{
UserRequest
ureq
=
getUserRequest
(
httpRequest
);
if
(!
ureq
.
getUserSession
().
isAuthenticated
())
{
return
Response
.
serverError
().
status
(
Status
.
UNAUTHORIZED
).
build
();
}
else
if
(
ureq
.
getIdentity
()
==
null
||
!
ureq
.
getIdentity
().
getKey
().
equals
(
identityKey
))
{
return
Response
.
serverError
().
status
(
Status
.
UNAUTHORIZED
).
build
();
}
KalendarRenderWrapper
calendar
=
getCalendar
(
ureq
,
calendarId
);
if
(
calendar
==
null
)
{
return
Response
.
serverError
().
status
(
Status
.
NOT_FOUND
).
build
();
}
else
if
(!
hasWriteAccess
(
calendar
))
{
return
Response
.
serverError
().
status
(
Status
.
UNAUTHORIZED
).
build
();
}
CalendarManager
calendarManager
=
CalendarManagerFactory
.
getInstance
().
getCalendarManager
();
if
(
eventId
==
null
)
{
return
Response
.
ok
().
status
(
Status
.
NOT_FOUND
).
build
();
}
else
{
KalendarEvent
kalEvent
=
calendar
.
getKalendar
().
getEvent
(
eventId
);
if
(
kalEvent
==
null
)
{
return
Response
.
ok
().
status
(
Status
.
NOT_FOUND
).
build
();
}
else
{
calendarManager
.
removeEventFrom
(
calendar
.
getKalendar
(),
kalEvent
);
}
}
return
Response
.
ok
().
build
();
}
@PUT
@Path
(
"{calendarId}/events"
)
@Produces
({
MediaType
.
APPLICATION_XML
,
MediaType
.
APPLICATION_JSON
})
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/olat/restapi/CalendarTest.java
+
29
−
0
View file @
368a8e0e
...
...
@@ -37,6 +37,7 @@ import javax.ws.rs.core.MediaType;
import
javax.ws.rs.core.UriBuilder
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.methods.HttpDelete
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.methods.HttpPut
;
...
...
@@ -395,6 +396,34 @@ public class CalendarTest extends OlatJerseyTestCase {
conn
.
shutdown
();
}
@Test
public
void
testDeletePersonalCalendarEvents
()
throws
IOException
,
URISyntaxException
{
RestConnection
conn
=
new
RestConnection
();
assertTrue
(
conn
.
login
(
id2
.
getName
(),
"A6B7C8"
));
//check if the event is saved
CalendarManager
calendarManager
=
CalendarManagerFactory
.
getInstance
().
getCalendarManager
();
KalendarRenderWrapper
calendarWrapper
=
calendarManager
.
getPersonalCalendar
(
id2
);
KalendarEvent
kalEvent
=
new
KalendarEvent
(
UUID
.
randomUUID
().
toString
(),
"Rendez-vous"
,
new
Date
(),
new
Date
());
calendarManager
.
addEventTo
(
calendarWrapper
.
getKalendar
(),
kalEvent
);
URI
eventUri
=
UriBuilder
.
fromUri
(
getContextURI
()).
path
(
"users"
).
path
(
id2
.
getKey
().
toString
())
.
path
(
"calendars"
).
path
(
"user_"
+
calendarWrapper
.
getKalendar
().
getCalendarID
())
.
path
(
"events"
).
path
(
kalEvent
.
getID
()).
build
();
HttpDelete
delEventMethod
=
conn
.
createDelete
(
eventUri
,
MediaType
.
APPLICATION_JSON
,
true
);
HttpResponse
delEventResponse
=
conn
.
execute
(
delEventMethod
);
assertEquals
(
200
,
delEventResponse
.
getStatusLine
().
getStatusCode
());
EntityUtils
.
consume
(
delEventResponse
.
getEntity
());
conn
.
shutdown
();
//check if the event is saved
Collection
<
KalendarEvent
>
savedEvents
=
calendarWrapper
.
getKalendar
().
getEvents
();
for
(
KalendarEvent
savedEvent:
savedEvents
)
{
Assert
.
assertFalse
(
savedEvent
.
getID
().
equals
(
kalEvent
.
getID
()));
}
}
protected
CalendarVO
getCourseCalendar
(
List
<
CalendarVO
>
vos
)
{
for
(
CalendarVO
vo:
vos
)
{
if
(
vo
.
getId
().
startsWith
(
"course"
))
{
...
...
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