Skip to content
Snippets Groups Projects
Commit 5d2d06eb authored by srosse's avatar srosse
Browse files

CL-328: REST API to manage vitero rooms of courses

parent b8a64c22
No related branches found
No related tags found
No related merge requests found
Showing
with 1001 additions and 131 deletions
......@@ -44,6 +44,7 @@ public enum ErrorCode {
moduleCollision(502, "error.moduleCollision"),
bookingInPast(505, "error.bookingInPast"),
bookingDoesntExist(506, "error.bookingDoesntExist"),
noRoomsAvailable(508, "error.noRoomsAvailable"),
bookingDoesntExistPrime(509, "error.bookingDoesntExist"),
licenseExpired(703, "error.licenseExpired");
......
......@@ -37,6 +37,8 @@ public class ViteroBooking {
private int bookingId;
private int groupId;
private String groupName;
private String eventName;
private String externalId;
private Date start;
private int startBuffer;
private Date end;
......@@ -94,6 +96,22 @@ public class ViteroBooking {
this.groupName = groupName;
}
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public String getExternalId() {
return externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
public int getRoomSize() {
return roomSize;
}
......
......@@ -38,6 +38,7 @@ public class ViteroGroupRoles {
private final List<String> emailsOfParticipants = new ArrayList<String>();
private final Map<String, GroupRole> emailsToRole = new HashMap<String,GroupRole>();
private final Map<String, Integer> emailsToVmsUserId = new HashMap<String,Integer>();
public List<String> getEmailsOfParticipants() {
return emailsOfParticipants;
......@@ -47,6 +48,10 @@ public class ViteroGroupRoles {
return emailsToRole;
}
public Map<String, Integer> getEmailsToVmsUserId() {
return emailsToVmsUserId;
}
public int size() {
return emailsOfParticipants.size();
}
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.vitero.restapi;
import java.util.Date;
/**
*
* Initial date: 15.07.2015<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class Examples {
public static final ViteroBookingVO SAMPLE_ViteroBookingVO = new ViteroBookingVO();
public static final ViteroGroupMemberVO SAMPLE_ViteroGroupMemberVO = new ViteroGroupMemberVO();
static {
SAMPLE_ViteroBookingVO.setAutoSignIn(true);
SAMPLE_ViteroBookingVO.setBookingId(23);
SAMPLE_ViteroBookingVO.setEnd(new Date());
SAMPLE_ViteroBookingVO.setEndBuffer(15);
SAMPLE_ViteroBookingVO.setEventName("New event");
SAMPLE_ViteroBookingVO.setExternalId("AC-234");
SAMPLE_ViteroBookingVO.setGroupId(24);
SAMPLE_ViteroBookingVO.setGroupName("NEW-EVENT_OLAT_938745983");
SAMPLE_ViteroBookingVO.setRoomSize(22);
SAMPLE_ViteroBookingVO.setStart(new Date());
SAMPLE_ViteroBookingVO.setStartBuffer(15);
SAMPLE_ViteroBookingVO.setTimeZoneId("");
SAMPLE_ViteroGroupMemberVO.setGroupRole("participant");
SAMPLE_ViteroGroupMemberVO.setIdentityKey(23497l);
}
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.vitero.restapi;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.olat.modules.vitero.model.ViteroBooking;
/**
*
* Initial date: 06.07.2015<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "viteroBookingVO")
public class ViteroBookingVO {
private int bookingId = -1;
private int groupId;
private String groupName;
private String eventName;
private String externalId;
private Date start;
private int startBuffer;
private Date end;
private int endBuffer;
private int roomSize;
private boolean autoSignIn;
private String timeZoneId;
public ViteroBookingVO() {
//
}
public ViteroBookingVO(ViteroBooking booking) {
bookingId = booking.getBookingId();
groupId = booking.getGroupId();
groupName = booking.getGroupName();
eventName = booking.getEventName();
externalId = booking.getExternalId();
start = booking.getStart();
startBuffer = booking.getStartBuffer();
end = booking.getEnd();
endBuffer = booking.getEndBuffer();
roomSize = booking.getRoomSize();
autoSignIn = booking.isAutoSignIn();
timeZoneId = booking.getTimeZoneId();
}
public int getBookingId() {
return bookingId;
}
public void setBookingId(int bookingId) {
this.bookingId = bookingId;
}
public int getGroupId() {
return groupId;
}
public void setGroupId(int groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getEventName() {
return eventName;
}
public void setEventName(String eventName) {
this.eventName = eventName;
}
public String getExternalId() {
return externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
public Date getStart() {
return start;
}
public void setStart(Date start) {
this.start = start;
}
public int getStartBuffer() {
return startBuffer;
}
public void setStartBuffer(int startBuffer) {
this.startBuffer = startBuffer;
}
public Date getEnd() {
return end;
}
public void setEnd(Date end) {
this.end = end;
}
public int getEndBuffer() {
return endBuffer;
}
public void setEndBuffer(int endBuffer) {
this.endBuffer = endBuffer;
}
public int getRoomSize() {
return roomSize;
}
public void setRoomSize(int roomSize) {
this.roomSize = roomSize;
}
public boolean isAutoSignIn() {
return autoSignIn;
}
public void setAutoSignIn(boolean autoSignIn) {
this.autoSignIn = autoSignIn;
}
public String getTimeZoneId() {
return timeZoneId;
}
public void setTimeZoneId(String timeZoneId) {
this.timeZoneId = timeZoneId;
}
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.vitero.restapi;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
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;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.olat.basesecurity.BaseSecurity;
import org.olat.basesecurity.SearchIdentityParams;
import org.olat.core.CoreSpringFactory;
import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable;
import org.olat.core.id.UserConstants;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.Util;
import org.olat.modules.vitero.ViteroModule;
import org.olat.modules.vitero.manager.ViteroManager;
import org.olat.modules.vitero.manager.VmsNotAvailableException;
import org.olat.modules.vitero.model.GroupRole;
import org.olat.modules.vitero.model.ViteroBooking;
import org.olat.modules.vitero.model.ViteroGroupRoles;
import org.olat.modules.vitero.model.ViteroStatus;
import org.olat.modules.vitero.ui.ViteroBookingsController;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* Initial date: 14.07.2015<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class ViteroBookingWebService {
private static final OLog log = Tracing.createLoggerFor(ViteroBookingWebService.class);
private final String subIdentifier;
private final OLATResourceable ores;
@Autowired
private ViteroModule viteroModule;
@Autowired
private ViteroManager viteroManager;
@Autowired
private BaseSecurity securityManager;
public ViteroBookingWebService(OLATResourceable ores, String subIdentifier) {
this.ores = ores;
this.subIdentifier = subIdentifier;
}
/**
* returns the list of booking of the resource.
*
* @response.representation.200.qname {http://www.example.com}viteroBookingVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc This is the list of all bookings of a resource
* @response.representation.200.example {@link org.olat.modules.vitero.restapi.Examples#SAMPLE_ViteroBookingVO}
* @return The list of vitero booking
*/
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getRooms() {
ViteroManager viteroManager = CoreSpringFactory.getImpl(ViteroManager.class);
try {
List<ViteroBooking> bookings = viteroManager.getBookings(null, ores, subIdentifier);
ViteroBookingVO[] bookingVos = new ViteroBookingVO[bookings.size()];
int count = 0;
for(ViteroBooking booking:bookings) {
bookingVos[count++] = new ViteroBookingVO(booking);
}
return Response.ok(bookingVos).build();
} catch (VmsNotAvailableException e) {
log.error("", e);
return handleNotAvailableException();
}
}
/**
* Return the created or updated booking
*
* @response.representation.200.qname {http://www.example.com}viteroBookingVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The created booking
* @response.representation.200.example {@link org.olat.modules.vitero.restapi.Examples#SAMPLE_ViteroBookingVO}
* @return The list of vitero booking
*/
@PUT
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response createRoom(ViteroBookingVO booking) {
return saveRoom(booking);
}
/**
* Return the created or updated booking
*
* @response.representation.200.qname {http://www.example.com}viteroBookingVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The created booking
* @response.representation.200.example {@link org.olat.modules.vitero.restapi.Examples#SAMPLE_ViteroBookingVO}
* @return The list of vitero booking
*/
@POST
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response updateRoom(ViteroBookingVO booking) {
return saveRoom(booking);
}
private Response saveRoom(ViteroBookingVO booking) {
try {
ViteroBooking vBooking = new ViteroBooking();
vBooking.setBookingId(booking.getBookingId());
vBooking.setExternalId(booking.getExternalId());
vBooking.setGroupId(booking.getGroupId());
vBooking.setGroupName(booking.getGroupName());
vBooking.setEventName(booking.getEventName());
vBooking.setStart(booking.getStart());
vBooking.setStartBuffer(booking.getStartBuffer());
vBooking.setEnd(booking.getEnd());
vBooking.setEndBuffer(booking.getEndBuffer());
vBooking.setRoomSize(booking.getRoomSize());
vBooking.setAutoSignIn(booking.isAutoSignIn());
vBooking.setTimeZoneId(viteroModule.getTimeZoneId());
ViteroStatus status;
if(booking.getBookingId() > 0) {
status = viteroManager.updateVmsBooking(null, ores, subIdentifier, vBooking);
} else {
status = viteroManager.createBooking(null, ores, subIdentifier, vBooking);
}
Response response;
if(status.isOk()) {
response = Response.ok(new ViteroBookingVO(vBooking)).build();
} else {
response = handleViteroError(status);
}
return response;
} catch (VmsNotAvailableException e) {
log.error("", e);
return handleNotAvailableException();
}
}
/**
* Delete the booking
*
* @response.representation.200.doc The booking is deleted
* @return Nothing
*/
@DELETE
@Path("{bookingId}")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response deleteRoom(@PathParam("bookingId") int bookingId) {
try {
ViteroBooking vBooking = viteroManager.getBookingById(null, ores, subIdentifier, bookingId);
if(vBooking == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if(viteroManager.deleteBooking(vBooking)) {
return Response.ok().build();
} else {
return Response.serverError().status(500).build();
}
} catch (VmsNotAvailableException e) {
log.error("", e);
return handleNotAvailableException();
}
}
/**
* Returns the list of members of the booking.
*
* @response.representation.200.qname {http://www.example.com}viteroGroupMemberVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc This is the list of all bookings of a resource
* @response.representation.200.example {@link org.olat.modules.vitero.restapi.Examples#SAMPLE_ViteroGroupMemberVO}
* @param bookingId The id of the booking
* @return The list of members in the specified booking
*/
@GET
@Path("{bookingId}/members")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response getMembers(@PathParam("bookingId") int bookingId) {
try {
ViteroBooking booking = viteroManager.getBookingById(null, ores, subIdentifier, bookingId);
if(booking == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ViteroGroupRoles roles = viteroManager.getGroupRoles(booking.getGroupId());
if(roles == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
List<String> currentEmails = new ArrayList<>(roles.getEmailsOfParticipants());
List<ViteroGroupMemberVO> memberList = new ArrayList<>(currentEmails.size());
for(String email:currentEmails) {
SearchIdentityParams params = new SearchIdentityParams();
params.setUserProperties(Collections.singletonMap(UserConstants.EMAIL, email));
List<Identity> identities = securityManager.getIdentitiesByPowerSearch(params, 0, 1);
for(Identity identity:identities) {
GroupRole role = roles.getEmailsToRole().get(email);
memberList.add(new ViteroGroupMemberVO(identity.getKey(), role.name()));
}
}
ViteroGroupMemberVO[] members = memberList.toArray(new ViteroGroupMemberVO[memberList.size()]);
return Response.ok(members).build();
} catch (VmsNotAvailableException e) {
log.error("", e);
return handleNotAvailableException();
}
}
/**
* Update the list of members of the booking, it add and mutates the
* members and delete the missing members.
*
* @response.representation.200.qname {http://www.example.com}viteroGroupMemberVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc This is the list of all bookings of a resource
* @response.representation.200.example {@link org.olat.modules.vitero.restapi.Examples#SAMPLE_ViteroGroupMemberVO}
* @param bookingId The id of the booking
* @param members The array of members
* @return Nothing
*/
@POST
@Path("{bookingId}/members")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response addMembers(@PathParam("bookingId") int bookingId, ViteroGroupMemberVO[] members) {
try {
ViteroBooking booking = viteroManager.getBookingById(null, ores, subIdentifier, bookingId);
if(booking == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ViteroGroupRoles roles = viteroManager.getGroupRoles(booking.getGroupId());
if(roles == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
List<ViteroErrorVO> errors = new ArrayList<>();
List<String> currentEmails = new ArrayList<>(roles.getEmailsOfParticipants());
for(ViteroGroupMemberVO member:members) {
GroupRole role = GroupRole.valueOf(member.getGroupRole());
Identity identity = securityManager.loadIdentityByKey(member.getIdentityKey());
String currentEmail = identity.getUser().getProperty(UserConstants.EMAIL, null);
GroupRole currentRole = roles.getEmailsToRole().get(currentEmail);
if(currentRole == null) {
ViteroStatus status = viteroManager.addToRoom(booking, identity, role);
if(!status.isOk()) {
errors.add(viteroErrorVO(status));
}
} else if(!currentRole.equals(role)) {
Integer vmsUserId = roles.getEmailsToVmsUserId().get(currentEmail);
ViteroStatus status = viteroManager.changeGroupRole(booking.getGroupId(), vmsUserId.intValue(), role.getVmsValue());
if(!status.isOk()) {
errors.add(viteroErrorVO(status));
}
}
currentEmails.remove(currentEmail);
}
for(String email:currentEmails) {
SearchIdentityParams params = new SearchIdentityParams();
params.setUserProperties(Collections.singletonMap(UserConstants.EMAIL, email));
List<Identity> identities = securityManager.getIdentitiesByPowerSearch(params, 0, 1);
for(Identity identity:identities) {
ViteroStatus status = viteroManager.removeFromRoom(booking, identity);
if(!status.isOk()) {
errors.add(viteroErrorVO(status));
}
}
}
return Response.ok().build();
} catch (VmsNotAvailableException e) {
log.error("", e);
return handleNotAvailableException();
}
}
private Response handleViteroError(ViteroStatus status) {
return Response.serverError().entity(viteroErrorVO(status)).status(500).build();
}
private ViteroErrorVO viteroErrorVO(ViteroStatus status) {
String msg = "";
if(status.getError() != null) {
msg = Util.createPackageTranslator(ViteroBookingsController.class, Locale.ENGLISH)
.translate(status.getError().i18nKey());
}
return new ViteroErrorVO(status, msg);
}
private Response handleNotAvailableException() {
return Response.serverError().status(Status.SERVICE_UNAVAILABLE).build();
}
}
\ No newline at end of file
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.vitero.restapi;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.olat.modules.vitero.model.ViteroStatus;
/**
*
* Initial date: 15.07.2015<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "viteroErrorVO")
public class ViteroErrorVO {
private int errorCode;
private String errorName;
private String errorMessage;
public ViteroErrorVO() {
//
}
public ViteroErrorVO(ViteroStatus status, String errorMessage) {
this.errorMessage = errorMessage;
if(status != null && status.getError() != null) {
errorCode = status.getError().code();
errorName = status.getError().name();
}
}
public int getErrorCode() {
return errorCode;
}
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}
public String getErrorName() {
return errorName;
}
public void setErrorName(String errorName) {
this.errorName = errorName;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.vitero.restapi;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* Initial date: 13.07.2015<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "viteroGroupMemberVO")
public class ViteroGroupMemberVO {
private Long identityKey;
private String groupRole;
public ViteroGroupMemberVO() {
//
}
public ViteroGroupMemberVO(Long identityKey, String groupRole) {
this.identityKey = identityKey;
this.groupRole = groupRole;
}
public Long getIdentityKey() {
return identityKey;
}
public void setIdentityKey(Long identityKey) {
this.identityKey = identityKey;
}
public String getGroupRole() {
return groupRole;
}
public void setGroupRole(String groupRole) {
this.groupRole = groupRole;
}
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.vitero.restapi;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.olat.core.CoreSpringFactory;
import org.olat.core.id.OLATResourceable;
import org.olat.core.util.resource.OresHelper;
/**
*
* Initial date: 06.07.2015<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
@Path("vitero")
public class ViteroWebService {
@Path("{resourceName}/{resourceId}/{subIdentifier}")
public ViteroBookingWebService getBookingWebService(@PathParam("resourceName") String resourceName,
@PathParam("resourceId") Long resourceId, @PathParam("subIdentifier") String subIdentifier) {
OLATResourceable ores = OresHelper.createOLATResourceableInstance(resourceName, resourceId);
ViteroBookingWebService service = new ViteroBookingWebService(ores, subIdentifier);
CoreSpringFactory.autowireObject(service);
return service;
}
}
......@@ -44,6 +44,7 @@ import org.olat.core.id.UserConstants;
import org.olat.modules.vitero.manager.ViteroManager;
import org.olat.modules.vitero.manager.VmsNotAvailableException;
import org.olat.modules.vitero.model.ViteroBooking;
import org.olat.modules.vitero.model.ViteroStatus;
import org.olat.modules.vitero.model.ViteroUser;
import org.olat.user.UserManager;
import org.olat.user.propertyhandlers.UserPropertyHandler;
......@@ -143,7 +144,8 @@ public class ViteroAdminBookingMembersController extends BasicController {
private void signOut(List<ViteroUser> members) {
try {
for(ViteroUser member:members) {
if(viteroManager.removeFromRoom(booking, member.getUserId())) {
ViteroStatus status = viteroManager.removeFromRoom(booking, member.getUserId());
if(status.isOk()) {
showInfo("signout.ok");
} else {
showInfo("signout.nok");
......
......@@ -35,6 +35,7 @@ import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.helpers.Settings;
import org.olat.core.id.OLATResourceable;
import org.olat.core.util.StringHelper;
import org.olat.group.BusinessGroup;
......@@ -92,12 +93,16 @@ public class ViteroBookingEditController extends FormBasicController {
showError(VmsNotAvailableException.I18N_KEY);
sizes = Collections.emptyList();
}
roomSizes = new String[sizes.size()];
int i=0;
for(Integer size:sizes) {
roomSizes[i++] = size.toString();
if(Settings.isDebuging() && sizes.isEmpty()) {
roomSizes = new String[]{ "22" };
} else {
roomSizes = new String[sizes.size()];
int i=0;
for(Integer size:sizes) {
roomSizes[i++] = size.toString();
}
}
autoSignInValues = new String[]{ translate("enabled") };
initForm(ureq);
......@@ -105,7 +110,6 @@ public class ViteroBookingEditController extends FormBasicController {
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("booking.admin.title");
boolean editable = booking.getBookingId() <= 0;
if(editable) {
setFormWarning("new.booking.warning");
......@@ -116,6 +120,10 @@ public class ViteroBookingEditController extends FormBasicController {
groupName.setMandatory(true);
groupName.setEnabled(editable);
if(StringHelper.containsNonWhitespace(booking.getExternalId())) {
uifactory.addStaticTextElement("external.id", booking.getExternalId(), formLayout);
}
//begin
beginChooser = uifactory.addDateChooser("booking.begin", null, formLayout);
beginChooser.setDisplaySize(21);
......
......@@ -43,6 +43,7 @@ import org.olat.modules.vitero.manager.ViteroManager;
import org.olat.modules.vitero.manager.VmsNotAvailableException;
import org.olat.modules.vitero.model.StartBookingComparator;
import org.olat.modules.vitero.model.ViteroBooking;
import org.olat.modules.vitero.model.ViteroStatus;
/**
*
......@@ -167,8 +168,8 @@ public class ViteroBookingsController extends BasicController {
protected void signInVitero(UserRequest ureq, ViteroBooking booking) {
try {
boolean ok = viteroManager.addToRoom(booking, ureq.getIdentity(), null);
if(ok) {
ViteroStatus status = viteroManager.addToRoom(booking, ureq.getIdentity(), null);
if(status.isOk()) {
showInfo("signin.ok");
} else {
showError("signin.nok");
......@@ -181,8 +182,8 @@ public class ViteroBookingsController extends BasicController {
protected void signOutVitero(UserRequest ureq, ViteroBooking booking) {
try {
boolean ok = viteroManager.removeFromRoom(booking, ureq.getIdentity());
if(ok) {
ViteroStatus status = viteroManager.removeFromRoom(booking, ureq.getIdentity());
if(status.isOk()) {
showInfo("signout.ok");
} else {
showError("signout.nok");
......
......@@ -266,13 +266,14 @@ public class ViteroBookingsEditController extends FormBasicController {
}
protected void usersBooking(UserRequest ureq, ViteroBooking viteroBooking) {
removeAsListenerAndDispose(cmc);
removeAsListenerAndDispose(usersController);
usersController = new ViteroUserToGroupController(ureq, getWindowControl(), group, ores, viteroBooking);
listenTo(usersController);
removeAsListenerAndDispose(cmc);
cmc = new CloseableModalController(getWindowControl(), translate("close"), usersController.getInitialComponent(), true, translate("users"));
String title = translate("users.title");
cmc = new CloseableModalController(getWindowControl(), translate("close"), usersController.getInitialComponent(), true, title);
listenTo(cmc);
cmc.activate();
}
......
......@@ -73,6 +73,9 @@ public class ViteroRoomsOverviewController extends BasicController {
tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("booking.roomSize", ViteroBookingDataModel.Column.roomSize.ordinal(), null, ureq.getLocale()));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
Date begin = cal.getTime();
cal.add(Calendar.DATE, 2);
Date end = cal.getTime();
......@@ -93,9 +96,4 @@ public class ViteroRoomsOverviewController extends BasicController {
protected void event(UserRequest ureq, Component source, Event event) {
//
}
}
}
\ No newline at end of file
......@@ -57,6 +57,7 @@ import org.olat.modules.vitero.manager.VmsNotAvailableException;
import org.olat.modules.vitero.model.GroupRole;
import org.olat.modules.vitero.model.ViteroBooking;
import org.olat.modules.vitero.model.ViteroGroupRoles;
import org.olat.modules.vitero.model.ViteroStatus;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryManager;
import org.olat.repository.RepositoryService;
......@@ -206,7 +207,8 @@ public class ViteroUserToGroupController extends BasicController {
for(Identity identity:identities) {
boolean upgrade = members.getCoaches().contains(identity) || members.getOwners().contains(identity);
GroupRole role = upgrade ? GroupRole.teamleader : null;
if(viteroManager.addToRoom(booking, identity, role)) {
ViteroStatus status = viteroManager.addToRoom(booking, identity, role);
if(status.isOk()) {
showInfo("signin.ok");
} else {
showInfo("signin.nok");
......@@ -223,7 +225,8 @@ public class ViteroUserToGroupController extends BasicController {
private void signOut(List<Identity> identities) {
try {
for(Identity identity:identities) {
if(viteroManager.removeFromRoom(booking, identity)) {
ViteroStatus status = viteroManager.removeFromRoom(booking, identity);
if(status.isOk()) {
showInfo("signout.ok");
} else {
showInfo("signout.nok");
......@@ -282,7 +285,7 @@ public class ViteroUserToGroupController extends BasicController {
//add all self signed participants
if(booking.isAutoSignIn()) {
List<String> emailsOfParticipants = groupRoles.getEmailsOfParticipants();
List<String> emailsOfParticipants = new ArrayList<>(groupRoles.getEmailsOfParticipants());
//remove owners, coaches and already participating users
for(Identity owner:owners) {
emailsOfParticipants.remove(owner.getUser().getProperty(UserConstants.EMAIL, null));
......
......@@ -8,7 +8,7 @@
<th>$r.translate("group.name")</th>
<th>$r.translate("booking.begin")</th>
<th>$r.translate("booking.end")</th>
<th colspan="3"></th>
<th colspan="4"></th>
</tr>
</thead>
<tbody>
......
<div>
<iframe class=popup_iframe src="$groupUrl"></iframe>
<iframe class=vitero_iframe src="$groupUrl"></iframe>
</div>
\ No newline at end of file
<fieldset>
<legend>$r.translate("users.title")</legend>
<p>$r.translate("users.intro")</p>
$r.translate('available.places', $freePlaces)<br/>
$r.render("userTable")
</fieldset>
\ No newline at end of file
<div class="o_info">$r.translate("users.intro")<br/>$r.translate('available.places', $freePlaces)</div>
$r.render("userTable")
\ No newline at end of file
......@@ -5,6 +5,7 @@ vitero.intro=Verf\u00FCgen Sie \u00FCber einen vitero Server der Firma vitero Gm
vitero.module.enabled=Modul "vitero"
vitero.account=Konfiguration
enabled=eingeschaltet
external.id=Extern ID
signin=Eintragen
signin.ok=Die Teilnahme f\u00FCr diesen Termin wurde erfolgreich eingetragen
signin.nok=Die Teilnahme f\u00FCr diesen Termin konnte nicht eingetragen werden. Pr\u00FCfen Sie ob f\u00FCr diesen Termin noch freie Pl\u00E4tze vorhanden sind.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment