diff --git a/src/main/java/com/frentix/olat/course/nodes/ViteroCourseNode.java b/src/main/java/com/frentix/olat/course/nodes/ViteroCourseNode.java index 655cb79235abb2be9c36b7ecd0789b10a4158fcc..dbf0e33bbba107e43ceff4a0c5ca090c14737a9e 100644 --- a/src/main/java/com/frentix/olat/course/nodes/ViteroCourseNode.java +++ b/src/main/java/com/frentix/olat/course/nodes/ViteroCourseNode.java @@ -49,6 +49,7 @@ import org.olat.repository.RepositoryEntry; import org.olat.repository.RepositoryManager; import com.frentix.olat.course.nodes.vitero.ViteroEditController; +import com.frentix.olat.course.nodes.vitero.ViteroPeekViewController; import com.frentix.olat.course.nodes.vitero.ViteroRunController; import com.frentix.olat.vitero.manager.ViteroManager; @@ -125,9 +126,8 @@ public class ViteroCourseNode extends AbstractAccessableCourseNode { } @Override - public Controller createPeekViewRunController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, - NodeEvaluation ne) { - return null; + public Controller createPeekViewRunController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv, NodeEvaluation ne) { + return new ViteroPeekViewController(ureq, wControl, userCourseEnv); } @Override diff --git a/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroCourseNodeConfiguration.java b/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroCourseNodeConfiguration.java index 198bb64cbba0ca57a2ae4095e2c2602ba4a82e35..f20ef412f9a009df9340f709d01eeaa89714209b 100644 --- a/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroCourseNodeConfiguration.java +++ b/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroCourseNodeConfiguration.java @@ -20,10 +20,8 @@ */ package com.frentix.olat.course.nodes.vitero; -import java.util.List; import java.util.Locale; -import org.olat.core.extensions.ExtensionResource; import org.olat.core.gui.translator.Translator; import org.olat.core.util.Util; import org.olat.course.nodes.AbstractCourseNodeConfiguration; @@ -70,24 +68,7 @@ public class ViteroCourseNodeConfiguration extends AbstractCourseNodeConfigurati return super.isEnabled(); } - public ExtensionResource getExtensionCSS() { - return null; - } - - public List getExtensionResources() { - return null; - } - public String getName() { return getAlias(); } - - public void setup() { - // no special setup necessary - } - - public void tearDown() { - // no special tear down necessary - } - } \ No newline at end of file diff --git a/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroEditController.java b/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroEditController.java index 3873f8459ba56b74df641ed0dece907db5ba3287..3221fb9ff034f2b0b03e43e0541d6b15f7a39502 100644 --- a/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroEditController.java +++ b/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroEditController.java @@ -74,7 +74,6 @@ public class ViteroEditController extends ActivateableTabbableDefaultController super(ureq, wControl); this.courseNode = courseNode; - editVc = this.createVelocityContainer("edit"); Condition accessCondition = courseNode.getPreConditionAccess(); accessibilityCondContr = new ConditionEditController(ureq, wControl, course.getCourseEnvironment().getCourseGroupManager(), @@ -85,7 +84,9 @@ public class ViteroEditController extends ActivateableTabbableDefaultController OLATResourceable ores = OresHelper.createOLATResourceableInstance(course.getResourceableTypeName(), course.getResourceableId()); editForm = new ViteroBookingsEditController(ureq, wControl, null, ores); listenTo(editForm); - editVc.put("editForm", editForm.getInitialComponent()); + + editVc = createVelocityContainer("edit"); + editVc.put("editRooms", editForm.getInitialComponent()); } @Override diff --git a/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroPeekViewController.java b/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroPeekViewController.java new file mode 100644 index 0000000000000000000000000000000000000000..445f605b17a0ae3700f0344c96b43923e9c87d76 --- /dev/null +++ b/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroPeekViewController.java @@ -0,0 +1,110 @@ +/** + * OLAT - Online Learning and Training<br> + * http://www.olat.org + * <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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <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> + * Copyright (c) frentix GmbH<br> + * http://www.frentix.com<br> + * <p> + */ +package com.frentix.olat.course.nodes.vitero; + +import java.util.Collections; +import java.util.List; + +import org.olat.core.CoreSpringFactory; +import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.Component; +import org.olat.core.gui.components.table.DefaultColumnDescriptor; +import org.olat.core.gui.components.table.TableController; +import org.olat.core.gui.components.table.TableGuiConfiguration; +import org.olat.core.gui.control.Event; +import org.olat.core.gui.control.WindowControl; +import org.olat.core.gui.control.controller.BasicController; +import org.olat.core.id.OLATResourceable; +import org.olat.core.util.resource.OresHelper; +import org.olat.course.CourseModule; +import org.olat.course.run.userview.UserCourseEnvironment; + +import com.frentix.olat.vitero.manager.ViteroManager; +import com.frentix.olat.vitero.model.StartBookingComparator; +import com.frentix.olat.vitero.model.ViteroBooking; +import com.frentix.olat.vitero.ui.FilterBookings; +import com.frentix.olat.vitero.ui.ViteroBookingDataModel; + +/** + * + * Description:<br> + * + * <P> + * Initial Date: 11 oct. 2011 <br> + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class ViteroPeekViewController extends BasicController { + + private TableController tableController; + + private final ViteroManager viteroManager; + private final OLATResourceable ores; + + public ViteroPeekViewController(UserRequest ureq, WindowControl wControl, UserCourseEnvironment userCourseEnv) { + super(ureq, wControl); + + viteroManager = (ViteroManager)CoreSpringFactory.getBean("viteroManager"); + ores = OresHelper.createOLATResourceableInstance(CourseModule.class, + userCourseEnv.getCourseEnvironment().getCourseResourceableId()); + + init(ureq); + + + putInitialPanel(tableController.getInitialComponent()); + } + + @Override + protected void doDispose() { + // + } + + @Override + protected void event(UserRequest ureq, Component source, Event event) { + // + } + + private void init(UserRequest ureq) { + List<ViteroBooking> bookings = viteroManager.getBookings(null, ores); + List<ViteroBooking> myBookings = viteroManager.getBookingInFutures(getIdentity()); + FilterBookings.filterMyFutureBookings(bookings, myBookings); + Collections.sort(bookings, new StartBookingComparator()); + + TableGuiConfiguration tableConfig = new TableGuiConfiguration(); + tableConfig.setTableEmptyMessage(translate("vc.table.empty")); + tableConfig.setDisplayTableHeader(false); + tableConfig.setCustomCssClass("b_portlet_table"); + tableConfig.setDisplayRowCount(false); + tableConfig.setPageingEnabled(false); + tableConfig.setDownloadOffered(false); + tableConfig.setSortingEnabled(false); + + removeAsListenerAndDispose(tableController); + tableController = new TableController(tableConfig, ureq, getWindowControl(), getTranslator()); + listenTo(tableController); + + // dummy header key, won't be used since setDisplayTableHeader is set to + // false + tableController.addColumnDescriptor(new DefaultColumnDescriptor("vc.table.begin", ViteroBookingDataModel.Column.begin.ordinal(), null, ureq.getLocale())); + tableController.addColumnDescriptor(new DefaultColumnDescriptor("vc.table.end", ViteroBookingDataModel.Column.end.ordinal(), null, ureq.getLocale())); + tableController.setTableDataModel(new ViteroBookingDataModel(bookings)); + } +} diff --git a/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroRunController.java b/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroRunController.java index 026862b9801639a058f61dcb03cf20d0abd4ca48..209dc18bc34aaf00b50f4014c98d7059c1a8dfb8 100644 --- a/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroRunController.java +++ b/src/main/java/com/frentix/olat/course/nodes/vitero/ViteroRunController.java @@ -34,31 +34,30 @@ import com.frentix.olat.vitero.ui.ViteroBookingsController; * Description:<br> * * <P> - * Initial Date: 6 oct. 2011 <br> - * + * Initial Date: 6 oct. 2011 <br> + * * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com */ public class ViteroRunController extends BasicController { private final ViteroBookingsController bookingsController; + public ViteroRunController(UserRequest ureq, WindowControl wControl, OLATResourceable ores) { + super(ureq, wControl); + + bookingsController = new ViteroBookingsController(ureq, wControl, null, ores); + listenTo(bookingsController); - public ViteroRunController(UserRequest ureq, WindowControl wControl, OLATResourceable ores) { - super(ureq, wControl); - - bookingsController = new ViteroBookingsController(ureq, wControl, null, ores); - listenTo(bookingsController); - - putInitialPanel(bookingsController.getInitialComponent()); - } + putInitialPanel(bookingsController.getInitialComponent()); + } - @Override - protected void event(UserRequest ureq, Component source, Event event) { - //nothing to do - } + @Override + protected void event(UserRequest ureq, Component source, Event event) { + // nothing to do + } - @Override - protected void doDispose() { - //nothing to do - } + @Override + protected void doDispose() { + // nothing to do + } } \ No newline at end of file diff --git a/src/main/java/com/frentix/olat/course/nodes/vitero/_content/edit.html b/src/main/java/com/frentix/olat/course/nodes/vitero/_content/edit.html index 29ec5aa26f2133b240cc7a91955302dd27eb2a82..b6db8fce606d9dc183fced1f8352ab0f805ff802 100644 --- a/src/main/java/com/frentix/olat/course/nodes/vitero/_content/edit.html +++ b/src/main/java/com/frentix/olat/course/nodes/vitero/_content/edit.html @@ -1 +1,2 @@ -$r.render('editForm') + +$r.render('editRooms') diff --git a/src/main/java/com/frentix/olat/course/nodes/vitero/_content/run.html b/src/main/java/com/frentix/olat/course/nodes/vitero/_content/run.html new file mode 100644 index 0000000000000000000000000000000000000000..445a34418c4b3ab38a9f51a89cb10b49f23ae2a5 --- /dev/null +++ b/src/main/java/com/frentix/olat/course/nodes/vitero/_content/run.html @@ -0,0 +1 @@ +Hello world (by Vitero) \ No newline at end of file diff --git a/src/main/java/com/frentix/olat/vitero/manager/ViteroManager.java b/src/main/java/com/frentix/olat/vitero/manager/ViteroManager.java index 46cd3ef9cdaddc31b96cc02210262348ce5877cf..046084549f227c3c2257bc2e75575a0bb726ed50 100644 --- a/src/main/java/com/frentix/olat/vitero/manager/ViteroManager.java +++ b/src/main/java/com/frentix/olat/vitero/manager/ViteroManager.java @@ -21,6 +21,7 @@ package com.frentix.olat.vitero.manager; import java.io.File; +import java.io.StringWriter; import java.math.BigInteger; import java.rmi.RemoteException; import java.text.ParseException; @@ -28,7 +29,9 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; +import java.util.Iterator; import java.util.List; +import java.util.TimeZone; import java.util.UUID; import javax.activation.DataHandler; @@ -70,6 +73,7 @@ import com.frentix.olat.vitero.manager.stubs.UserServiceStub.Userid; import com.frentix.olat.vitero.model.ViteroBooking; import com.ibm.icu.util.Calendar; import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.xml.CompactWriter; /** * @@ -151,6 +155,23 @@ public class ViteroManager extends BasicManager { } } + public boolean canGoBooking(ViteroBooking booking) { + Date now = new Date(); + + Calendar cal = Calendar.getInstance(); + cal.setTime(booking.getStart()); + cal.add(Calendar.MINUTE, -booking.getStartBuffer()); + Date start = cal.getTime(); + cal.setTime(booking.getEnd()); + cal.add(Calendar.MINUTE, booking.getEndBuffer()); + Date end = cal.getTime(); + + if(start.before(now) && end.after(now)) { + return true; + } + return false; + } + public List<ViteroBooking> getBookingInFutures(Identity identity) { int userId = getVmsUserId(identity); Booking[] bookings = getBookingInFutureByCustomerId(userId); @@ -186,7 +207,10 @@ public class ViteroManager extends BasicManager { } public String serializeViteroBooking(ViteroBooking booking) { - return xStream.toXML(booking); + StringWriter writer = new StringWriter(); + xStream.marshal(booking, new CompactWriter(writer)); + writer.flush(); + return writer.toString(); } public ViteroBooking deserializeViteroBooking(String booking) { @@ -258,7 +282,7 @@ public class ViteroManager extends BasicManager { protected int createVmsUser(Identity identity) { try { - UserServiceStub userWs = this.getUserWebService(); + UserServiceStub userWs = getUserWebService(); UserServiceStub.CreateUserRequest createRequest = new UserServiceStub.CreateUserRequest(); UserServiceStub.Newusertype user = new UserServiceStub.Newusertype(); @@ -313,6 +337,9 @@ public class ViteroManager extends BasicManager { user.setCompany(""); user.setTimezone(""); */ + TimeZone.getDefault().getID(); + + user.setTechnicalnote("Generated by OpenOLAT"); createRequest.setUser(user); @@ -435,9 +462,88 @@ public class ViteroManager extends BasicManager { } } - public boolean updateBooking(BusinessGroup group, OLATResourceable ores, ViteroBooking vBooking) { - //TODO - return false; + public boolean addToRoom(ViteroBooking booking, Identity identity) { + try { + int userId = getVmsUserId(identity); + if(userId < 0) { + return false; + } + + GroupServiceStub groupWs = getGroupWebService(); + GroupServiceStub.AddUserToGroupRequest addRequest = new GroupServiceStub.AddUserToGroupRequest(); + GroupServiceStub.Groupiduserid groupuserId = new GroupServiceStub.Groupiduserid(); + groupuserId.setGroupid(booking.getGroupId()); + groupuserId.setUserid(userId); + + addRequest.setAddUserToGroupRequest(groupuserId); + groupWs.addUserToGroup(addRequest); + return true; + } catch(AxisFault f) { + String msg = f.getFaultDetailElement().toString(); + if(msg.contains("<errorCode>53</errorCode>")) { + logError("The user doesn Ìt exist!", f); + } else if(msg.contains("<errorCode>103</errorCode>")) { + logError("The user is not attached to the customer (to which this group belongs)", f); + } else if(msg.contains("<errorCode>151</errorCode>")) { + logError("The group doesn Ìt exist", f); + } else if(msg.contains("<errorCode>303</errorCode>")) { + logError("An id <= 0", f); + } else { + logError(msg, f); + } + return false; + } catch (RemoteException e) { + logError("Cannot add an user to a group", e); + return false; + } + } + + public boolean removeFromRoom(ViteroBooking booking, Identity identity) { + try { + int userId = getVmsUserId(identity); + if(userId < 0) { + return true;//nothing to remove + } + + GroupServiceStub groupWs = getGroupWebService(); + GroupServiceStub.RemoveUserFromGroupRequest removeRequest = new GroupServiceStub.RemoveUserFromGroupRequest(); + GroupServiceStub.Groupiduserid groupuserId = new GroupServiceStub.Groupiduserid(); + groupuserId.setGroupid(booking.getGroupId()); + groupuserId.setUserid(userId); + removeRequest.setRemoveUserFromGroupRequest(groupuserId); + groupWs.removeUserFromGroup(removeRequest); + return true; + } catch(AxisFault f) { + String msg = f.getFaultDetailElement().toString(); + if(msg.contains("<errorCode>53</errorCode>")) { + logError("The user doesn Ìt exist!", f); + } else if(msg.contains("<errorCode>151</errorCode>")) { + logError("The group doesn Ìt exist", f); + } else if(msg.contains("<errorCode>303</errorCode>")) { + logError("An id <= 0", f); + } else { + logError(msg, f); + } + return false; + } catch (RemoteException e) { + logError("Cannot add an user to a group", e); + return false; + } + } + + public ViteroBooking updateBooking(BusinessGroup group, OLATResourceable ores, ViteroBooking vBooking) { + Bookingtype bookingType = getBookingById(vBooking.getBookingId()); + if(bookingType == null) { + logInfo("Booking doesn't exist: " + vBooking.getBookingId()); + return null; + } + + Booking booking = bookingType.getBooking(); + //set the vms values + update(vBooking, booking); + //update the property + updateProperty(group, ores, vBooking); + return vBooking; } public boolean createBooking(BusinessGroup group, OLATResourceable ores, ViteroBooking vBooking) { @@ -482,8 +588,11 @@ public class ViteroManager extends BasicManager { newBooking.setPcstateokrequired(false); newBooking.setRepetitionpattern("once"); newBooking.setRepetitionenddate(""); - newBooking.setTimezone("Africa/Ceuta"); + */ + //newBooking.setTimezone("Africa/Ceuta"); + newBooking.setTimezone("Africa/Ceuta"); + createRequest.setBooking(newBooking); BookingServiceStub.CreateBookingResponse response = bookingWs.createBooking(createRequest); @@ -509,6 +618,8 @@ public class ViteroManager extends BasicManager { logError("Booking collision!", f); } else if(msg.contains("<errorCode>703</errorCode>")) { logError("License/customer expired!", f); + } else if(msg.contains("<errorCode>304</errorCode>")) { + logError("Invalid time zone!", f); } else { logError(msg, f); } @@ -581,16 +692,34 @@ public class ViteroManager extends BasicManager { propertyManager.deleteProperties(null, null, null, VMS_CATEGORY, bookingId); } + public String getTimeZoneId() { + return "Africa/Ceuta"; + } + protected Booking[] getBookingInFutureByCustomerId(int userId) { try { BookingServiceStub bookingWs = getBookingWebService(); BookingServiceStub.GetBookingListByUserInFutureRequest request = new BookingServiceStub.GetBookingListByUserInFutureRequest(); request.setUserid(userId); + request.setTimezone(getTimeZoneId()); BookingServiceStub.GetBookingListByUserInFutureResponse response = bookingWs.getBookingListByUserInFuture(request); Bookinglist bookingList = response.getGetBookingListByUserInFutureResponse(); return bookingList.getBooking(); + } catch(AxisFault f) { + String msg = f.getFaultDetailElement().toString(); + if(msg.contains("<errorCode>304</errorCode>")) { + logError("Invalid time zone!", f); + } else if(msg.contains("<errorCode>53</errorCode>")) { + logError("The user does not exist!", f); + } else if(msg.contains("<errorCode>303</errorCode>")) { + logError("ids <= 0!", f); + } else { + logError(msg, f); + } + logError(msg, f); + return null; } catch (RemoteException e) { logError("", e); return null; @@ -611,6 +740,10 @@ public class ViteroManager extends BasicManager { protected ViteroBooking convert(Booking booking) { ViteroBooking vb = new ViteroBooking(); + return update(vb, booking); + } + + protected ViteroBooking update(ViteroBooking vb, Booking booking) { vb.setBookingId(booking.getBookingid()); vb.setGroupId(booking.getGroupid()); vb.setRoomSize(booking.getRoomsize()); @@ -621,22 +754,39 @@ public class ViteroManager extends BasicManager { return vb; } - protected Property getProperty(final BusinessGroup group, final OLATResourceable courseResource) { - return propertyManager.findProperty(null, group, courseResource, VMS_CATEGORY, null); + protected Property getProperty(final BusinessGroup group, final OLATResourceable courseResource, final ViteroBooking booking) { + String propertyName = Integer.toString(booking.getBookingId()); + return propertyManager.findProperty(null, group, courseResource, VMS_CATEGORY, propertyName); } - protected Property getOrCreateProperty(final BusinessGroup group, final OLATResourceable courseResource, ViteroBooking booking) { - Property property = getProperty(group, courseResource); + protected Property getOrCreateProperty(final BusinessGroup group, final OLATResourceable courseResource, final ViteroBooking booking) { + Property property = getProperty(group, courseResource, booking); if(property == null) { - String serialized = serializeViteroBooking(booking); - String bookingId = Integer.toString(booking.getBookingId()); - Long groupId = new Long(booking.getGroupId()); - property = propertyManager.createPropertyInstance(null, group, courseResource, VMS_CATEGORY, bookingId, null, groupId, null, serialized); + property = createProperty(group, courseResource, booking); propertyManager.saveProperty(property); } return property; } - + + protected Property updateProperty(final BusinessGroup group, final OLATResourceable courseResource, ViteroBooking booking) { + Property property = getProperty(group, courseResource, booking); + if(property == null) { + property = createProperty(group, courseResource, booking); + propertyManager.saveProperty(property); + } else { + String serialized = serializeViteroBooking(booking); + property.setTextValue(serialized); + propertyManager.updateProperty(property); + } + return property; + } + + protected Property createProperty(final BusinessGroup group, final OLATResourceable courseResource, ViteroBooking booking) { + String serialized = serializeViteroBooking(booking); + String bookingId = Integer.toString(booking.getBookingId()); + Long groupId = new Long(booking.getGroupId()); + return propertyManager.createPropertyInstance(null, group, courseResource, VMS_CATEGORY, bookingId, null, groupId, null, serialized); + } protected Bookingtype getBookingById(int id) { if(id < 0) return null; diff --git a/src/main/java/com/frentix/olat/vitero/model/StartBookingComparator.java b/src/main/java/com/frentix/olat/vitero/model/StartBookingComparator.java new file mode 100644 index 0000000000000000000000000000000000000000..6e20b7bbd51154528fc8d0da3846b3c2fcfa9e3f --- /dev/null +++ b/src/main/java/com/frentix/olat/vitero/model/StartBookingComparator.java @@ -0,0 +1,47 @@ +/** + * OLAT - Online Learning and Training<br> + * http://www.olat.org + * <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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <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> + * Copyright (c) frentix GmbH<br> + * http://www.frentix.com<br> + * <p> + */ +package com.frentix.olat.vitero.model; + +import java.util.Comparator; +import java.util.Date; + + +/** + * + * Description:<br> + * + * <P> + * Initial Date: 11 oct. 2011 <br> + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class StartBookingComparator implements Comparator<ViteroBooking> { + + @Override + public int compare(ViteroBooking b1, ViteroBooking b2) { + Date d1 = b1.getStart(); + Date d2 = b2.getStart(); + + if(d1 == null) return -1; + if(d2 == null) return 1; + return d1.compareTo(d2); + } +} diff --git a/src/main/java/com/frentix/olat/vitero/model/ViteroBooking.java b/src/main/java/com/frentix/olat/vitero/model/ViteroBooking.java index 9b5f14e3066ad073f83b6015233bbbeed0447872..a56f8404eb0533137dad23d1b7eb666225b8e84b 100644 --- a/src/main/java/com/frentix/olat/vitero/model/ViteroBooking.java +++ b/src/main/java/com/frentix/olat/vitero/model/ViteroBooking.java @@ -40,6 +40,8 @@ public class ViteroBooking { private Date end; private int endBuffer; private int roomSize; + private boolean autoSignIn; + private String timeZoneId; public ViteroBooking() { // nothing to do @@ -68,8 +70,6 @@ public class ViteroBooking { public void setRoomSize(int roomSize) { this.roomSize = roomSize; } - - public int getStartBuffer() { return startBuffer; @@ -87,8 +87,6 @@ public class ViteroBooking { this.start = start; } - - public int getEndBuffer() { return endBuffer; } @@ -104,4 +102,20 @@ public class ViteroBooking { public void setEnd(Date end) { this.end = end; } + + public String getTimeZoneId() { + return timeZoneId; + } + + public void setTimeZoneId(String timeZoneId) { + this.timeZoneId = timeZoneId; + } + + public boolean isAutoSignIn() { + return autoSignIn; + } + + public void setAutoSignIn(boolean autoSignIn) { + this.autoSignIn = autoSignIn; + } } \ No newline at end of file diff --git a/src/main/java/com/frentix/olat/vitero/ui/FilterBookings.java b/src/main/java/com/frentix/olat/vitero/ui/FilterBookings.java new file mode 100644 index 0000000000000000000000000000000000000000..c00bddd5d1a4199d58ea9e493fdd53404635944d --- /dev/null +++ b/src/main/java/com/frentix/olat/vitero/ui/FilterBookings.java @@ -0,0 +1,42 @@ +package com.frentix.olat.vitero.ui; + +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import com.frentix.olat.vitero.model.ViteroBooking; + +/** + * + * Description:<br> + * + * <P> + * Initial Date: 11 oct. 2011 <br> + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class FilterBookings { + + public static void filterMyFutureBookings(final List<ViteroBooking> bookings, final List<ViteroBooking> signedInBookings) { + //only the bookings in the future + Date now = new Date(); + for(Iterator<ViteroBooking> it=bookings.iterator(); it.hasNext(); ) { + ViteroBooking booking = it.next(); + Date end = booking.getEnd(); + if(end.before(now)) { + it.remove(); + } else if(!booking.isAutoSignIn()) { + boolean in = false; + for(ViteroBooking signedInBooking:signedInBookings) { + if(signedInBooking.getBookingId() == booking.getBookingId()) { + in = true;//already in + } + } + if(!in) { + it.remove(); + } + } + } + } + +} diff --git a/src/main/java/com/frentix/olat/vitero/ui/SignColumnDescriptor.java b/src/main/java/com/frentix/olat/vitero/ui/SignColumnDescriptor.java new file mode 100644 index 0000000000000000000000000000000000000000..3210e1291a9446c486a511c81eb54bb430061898 --- /dev/null +++ b/src/main/java/com/frentix/olat/vitero/ui/SignColumnDescriptor.java @@ -0,0 +1,73 @@ +/** + * OLAT - Online Learning and Training<br> + * http://www.olat.org + * <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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <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> + * Copyright (c) frentix GmbH<br> + * http://www.frentix.com<br> + * <p> + */ +package com.frentix.olat.vitero.ui; + +import java.util.Locale; + +import org.olat.core.gui.components.table.DefaultColumnDescriptor; +import org.olat.core.gui.render.Renderer; +import org.olat.core.gui.render.StringOutput; +import org.olat.core.gui.translator.Translator; + +/** + * + * Description:<br> + * + * <P> + * Initial Date: 11 oct. 2011 <br> + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class SignColumnDescriptor extends DefaultColumnDescriptor { + + private final Translator translator; + + public SignColumnDescriptor(final String headerKey, final int dataColumn, final Locale locale, final Translator translator) { + super(headerKey, dataColumn, null, locale); + this.translator = translator; + } + + @Override + public String getAction(int row) { + Object state = getTable().getTableDataModel().getValueAt(row, getDataColumn()); + if(state instanceof ViteroBookingDataModel.Sign) { + ViteroBookingDataModel.Sign sign = (ViteroBookingDataModel.Sign)state; + switch(sign) { + case signin: return sign.name(); + case signout: return sign.name(); + default: return null; + } + } + return null; + } + + @Override + public void renderValue(StringOutput sb, int row, Renderer renderer) { + Object state = getTable().getTableDataModel().getValueAt(row, getDataColumn()); + if(state instanceof ViteroBookingDataModel.Sign) { + ViteroBookingDataModel.Sign sign = (ViteroBookingDataModel.Sign)state; + switch(sign) { + case signin: sb.append(translator.translate("signin")); break; + case signout: sb.append(translator.translate("signout")); break; + } + } + } +} diff --git a/src/main/java/com/frentix/olat/vitero/ui/StartColumnDescriptor.java b/src/main/java/com/frentix/olat/vitero/ui/StartColumnDescriptor.java new file mode 100644 index 0000000000000000000000000000000000000000..d95bdf6b332cde709534e12335249731ff4d5050 --- /dev/null +++ b/src/main/java/com/frentix/olat/vitero/ui/StartColumnDescriptor.java @@ -0,0 +1,76 @@ +/** + * OLAT - Online Learning and Training<br> + * http://www.olat.org + * <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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <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> + * Copyright (c) frentix GmbH<br> + * http://www.frentix.com<br> + * <p> + */ +package com.frentix.olat.vitero.ui; + +import java.util.Locale; + +import org.olat.core.gui.components.table.DefaultColumnDescriptor; +import org.olat.core.gui.render.Renderer; +import org.olat.core.gui.render.StringOutput; +import org.olat.core.gui.translator.Translator; + +import com.frentix.olat.vitero.manager.ViteroManager; +import com.frentix.olat.vitero.model.ViteroBooking; + +/** + * + * Description:<br> + * + * <P> + * Initial Date: 11 oct. 2011 <br> + * + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + */ +public class StartColumnDescriptor extends DefaultColumnDescriptor { + + private final ViteroManager viteroManager; + + private final Translator translator; + + public StartColumnDescriptor(final String headerKey, String action, final Locale locale, ViteroManager viteroManager, Translator translator) { + super(headerKey, 1, action, locale); + this.viteroManager = viteroManager; + this.translator = translator; + } + + @Override + public String getAction(int row) { + ViteroBooking booking = (ViteroBooking)getTable().getTableDataModel().getObject(row); + if(viteroManager.canGoBooking(booking)) { + Object state = getTable().getTableDataModel().getValueAt(row, ViteroBookingDataModel.Column.sign.ordinal()); + if(ViteroBookingDataModel.Sign.signout.equals(state)) { + return super.getAction(row); + } + } + return null; + } + + @Override + public void renderValue(StringOutput sb, int row, Renderer renderer) { + ViteroBooking booking = (ViteroBooking)getTable().getTableDataModel().getObject(row); + if(viteroManager.canGoBooking(booking)) { + Object state = getTable().getTableDataModel().getValueAt(row, ViteroBookingDataModel.Column.sign.ordinal()); + if(ViteroBookingDataModel.Sign.signout.equals(state)) { + sb.append(translator.translate(getHeaderKey())); + } + } + } +} diff --git a/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingDataModel.java b/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingDataModel.java index ea9b973c81c1e0533d727c6ca43a4ab22bccf9c9..9df1debae936e1e44d252bac49c299482c5161b5 100644 --- a/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingDataModel.java +++ b/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingDataModel.java @@ -38,6 +38,8 @@ import com.frentix.olat.vitero.model.ViteroBooking; public class ViteroBookingDataModel implements TableDataModel { private List<ViteroBooking> bookings; + private List<ViteroBooking> signedInBookings; + public ViteroBookingDataModel() { // @@ -46,6 +48,11 @@ public class ViteroBookingDataModel implements TableDataModel { public ViteroBookingDataModel(List<ViteroBooking> bookings) { this.bookings = bookings; } + + public ViteroBookingDataModel(List<ViteroBooking> bookings, List<ViteroBooking> signedInBookings) { + this.bookings = bookings; + this.signedInBookings = signedInBookings; + } @Override public int getColumnCount() { @@ -68,6 +75,20 @@ public class ViteroBookingDataModel implements TableDataModel { switch(Column.values()[col]) { case begin: return booking.getStart(); case end: return booking.getEnd(); + case sign: { + boolean auto = booking.isAutoSignIn(); + if(auto) { + if(signedInBookings != null) { + for(ViteroBooking signedInBooking: signedInBookings) { + if(booking.getBookingId() == signedInBooking.getBookingId()) { + return Sign.signout; + } + } + } + return Sign.signin; + } + return Sign.no; + } default: return ""; } } @@ -81,10 +102,17 @@ public class ViteroBookingDataModel implements TableDataModel { public Object createCopyWithEmptyList() { return new ViteroBookingDataModel(); } + + public enum Sign { + signin, + signout, + no, + } public enum Column { begin, end, open, + sign, } } \ No newline at end of file diff --git a/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingEditController.java b/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingEditController.java index 7b0ace00fccba6d24445d27b7748ea54a9a2d7c3..9b409e6c1d29484eef634cbff7583c6cd98070bc 100644 --- a/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingEditController.java +++ b/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingEditController.java @@ -27,6 +27,7 @@ import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.form.flexible.FormItemContainer; import org.olat.core.gui.components.form.flexible.elements.DateChooser; +import org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement; import org.olat.core.gui.components.form.flexible.elements.SingleSelection; import org.olat.core.gui.components.form.flexible.impl.FormBasicController; import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer; @@ -56,9 +57,13 @@ public class ViteroBookingEditController extends FormBasicController { private SingleSelection endBufferEl; private SingleSelection roomSizeEl; + private MultipleSelectionElement autoSignIn; + private static final String[] bufferKeys = new String[]{"0", "15", "30", "45", "60"}; private static final String[] bufferValues = bufferKeys; private final String[] roomSizes; + private static final String[] autoSignInKeys = new String[]{"on"}; + private final String[] autoSignInValues; private final BusinessGroup group; private final OLATResourceable ores; @@ -81,37 +86,51 @@ public class ViteroBookingEditController extends FormBasicController { roomSizes[i++] = size.toString(); } + autoSignInValues = new String[]{ translate("enabled") }; + initForm(ureq); } @Override protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { + boolean editable = booking.getBookingId() <= 0; + //begin beginChooser = uifactory.addDateChooser("vc.table.begin", "", formLayout); beginChooser.setDisplaySize(21); beginChooser.setDateChooserTimeEnabled(true); beginChooser.setMandatory(true); beginChooser.setDate(booking.getStart()); + beginChooser.setEnabled(editable); //end endChooser = uifactory.addDateChooser("vc.table.end", "", formLayout); endChooser.setDisplaySize(21); endChooser.setDateChooserTimeEnabled(true); endChooser.setMandatory(true); endChooser.setDate(booking.getEnd()); + endChooser.setEnabled(editable); //buffer start beginBufferEl = uifactory.addDropdownSingleselect("vc.table.beginBuffer", formLayout, bufferKeys, bufferValues, null); beginBufferEl.select(Integer.toString(booking.getStartBuffer()), true); + beginBufferEl.setEnabled(editable); //buffer end endBufferEl = uifactory.addDropdownSingleselect("vc.table.endBuffer", formLayout, bufferKeys, bufferValues, null); endBufferEl.select(Integer.toString(booking.getEndBuffer()), true); + endBufferEl.setEnabled(editable); //room size roomSizeEl = uifactory.addDropdownSingleselect("vc.table.roomSize", formLayout, roomSizes, roomSizes, null); if(booking.getRoomSize() > 0) { roomSizeEl.select(Integer.toString(booking.getRoomSize()), true); } + roomSizeEl.setEnabled(editable); + + autoSignIn = uifactory.addCheckboxesHorizontal("vc.autoSignIn", formLayout, autoSignInKeys, autoSignInValues, null); + if(booking.isAutoSignIn()) { + autoSignIn.select(autoSignInKeys[0], true); + } FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator()); formLayout.add(buttonCont); @@ -133,9 +152,33 @@ public class ViteroBookingEditController extends FormBasicController { boolean allOk = true; Date begin = beginChooser.getDate(); - + beginChooser.clearError(); + if(begin == null) { + beginChooser.setErrorKey("form.legende.mandatory", null); + allOk = false; + } else if(new Date().after(begin)) { + beginChooser.setErrorKey("vc.check.bookingInPast", null); + allOk = false; + } + Date end = endChooser.getDate(); + endChooser.clearError(); + if(end == null) { + endChooser.setErrorKey("form.legende.mandatory", null); + allOk = false; + } else if(new Date().after(begin)) { + beginChooser.setErrorKey("vc.check.bookingInPast", null); + allOk = false; + } else if(end.before(begin)) { + beginChooser.setErrorKey("vc.check.bookingInPast", null); + allOk = false; + } + roomSizeEl.clearError(); + if(!roomSizeEl.isOneSelected()) { + roomSizeEl.setErrorKey("form.legende.mandatory", null); + allOk = false; + } return allOk && super.validateFormLogic(ureq); } @@ -166,17 +209,26 @@ public class ViteroBookingEditController extends FormBasicController { } booking.setRoomSize(roomSize); + boolean auto = autoSignIn.isMultiselect() && autoSignIn.isSelected(0); + booking.setAutoSignIn(auto); + if(booking.getBookingId() >= 0) { - viteroManager.updateBooking(group, ores, booking); + ViteroBooking updatedBooking = viteroManager.updateBooking(group, ores, booking); + if(updatedBooking != null) { + showInfo("vc.check.ok"); + fireEvent(ureq, Event.DONE_EVENT); + } else { + showError("vc.check.nok"); + } } else { if(viteroManager.createBooking(group, ores, booking)) { showInfo("vc.check.ok"); + fireEvent(ureq, Event.DONE_EVENT); } else { showError("vc.check.nok"); } } - fireEvent(ureq, Event.DONE_EVENT); } @Override diff --git a/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingsController.java b/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingsController.java index 5493d532fc501c79c72ac40a84cef4ddee3c5682..3fb488ac83b99aea8c7457d05dc842d528b0495b 100644 --- a/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingsController.java +++ b/src/main/java/com/frentix/olat/vitero/ui/ViteroBookingsController.java @@ -26,7 +26,6 @@ import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.table.DefaultColumnDescriptor; -import org.olat.core.gui.components.table.StaticColumnDescriptor; import org.olat.core.gui.components.table.TableController; import org.olat.core.gui.components.table.TableDataModel; import org.olat.core.gui.components.table.TableEvent; @@ -41,8 +40,11 @@ import org.olat.core.id.OLATResourceable; import org.olat.group.BusinessGroup; import com.frentix.olat.vitero.manager.ViteroManager; +import com.frentix.olat.vitero.model.StartBookingComparator; import com.frentix.olat.vitero.model.ViteroBooking; +import edu.emory.mathcs.backport.java.util.Collections; + /** * * Description:<br> @@ -56,17 +58,19 @@ public class ViteroBookingsController extends BasicController { private final VelocityContainer runVC; private final TableController tableCtr; + + private final BusinessGroup group; + private final OLATResourceable ores; private final ViteroManager viteroManager; public ViteroBookingsController(UserRequest ureq, WindowControl wControl, BusinessGroup group, OLATResourceable ores) { super(ureq, wControl); + this.ores = ores; + this.group = group; viteroManager = (ViteroManager) CoreSpringFactory.getBean("viteroManager"); - List<ViteroBooking> bookings = viteroManager.getBookings(group, ores); - TableDataModel tableData = new ViteroBookingDataModel(bookings); - TableGuiConfiguration tableConfig = new TableGuiConfiguration(); tableConfig.setTableEmptyMessage(translate("vc.table.empty")); tableConfig.setColumnMovingOffered(true); @@ -75,11 +79,14 @@ public class ViteroBookingsController extends BasicController { tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("vc.table.begin", ViteroBookingDataModel.Column.begin.ordinal(), null, ureq.getLocale())); tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("vc.table.end", ViteroBookingDataModel.Column.end.ordinal(), null, ureq.getLocale())); - StaticColumnDescriptor startRoom = new StaticColumnDescriptor("start", "start", translate("start")); + StartColumnDescriptor startRoom = new StartColumnDescriptor("start", "start", ureq.getLocale(), viteroManager, getTranslator()); startRoom.setIsPopUpWindowAction(true, ""); tableCtr.addColumnDescriptor(startRoom); + + tableCtr.addColumnDescriptor(new SignColumnDescriptor("signin", ViteroBookingDataModel.Column.sign.ordinal(), ureq.getLocale(), getTranslator())); - tableCtr.setTableDataModel(tableData); + loadModel(); + tableCtr.setSortColumn(1, true);// timeframe listenTo(tableCtr); @@ -108,12 +115,45 @@ public class ViteroBookingsController extends BasicController { ViteroBooking booking = (ViteroBooking)tableCtr.getTableDataModel().getObject(row); if("start".equals(e.getActionId())) { openVitero(ureq, booking); + } else if("signin".equals(e.getActionId())) { + signInVitero(ureq, booking); + } else if("signout".equals(e.getActionId())) { + signOutVitero(ureq, booking); } } } super.event(ureq, source, event); } + protected void loadModel() { + List<ViteroBooking> bookings = viteroManager.getBookings(group, ores); + List<ViteroBooking> myBookings = viteroManager.getBookingInFutures(getIdentity()); + FilterBookings.filterMyFutureBookings(bookings, myBookings); + Collections.sort(bookings, new StartBookingComparator()); + TableDataModel tableData = new ViteroBookingDataModel(bookings, myBookings); + tableCtr.setTableDataModel(tableData); + } + + protected void signInVitero(UserRequest ureq, ViteroBooking booking) { + boolean ok = viteroManager.addToRoom(booking, ureq.getIdentity()); + if(ok) { + showInfo("signin.ok"); + } else { + showError("signin.nok"); + } + loadModel(); + } + + protected void signOutVitero(UserRequest ureq, ViteroBooking booking) { + boolean ok = viteroManager.removeFromRoom(booking, ureq.getIdentity()); + if(ok) { + showInfo("signout.ok"); + } else { + showError("signout.nok"); + } + loadModel(); + } + protected void openVitero(UserRequest ureq, ViteroBooking booking) { String url = viteroManager.getURLToBooking(ureq.getIdentity(), booking); RedirectMediaResource redirect = new RedirectMediaResource(url); diff --git a/src/main/java/com/frentix/olat/vitero/ui/_i18n/LocalStrings_de.properties b/src/main/java/com/frentix/olat/vitero/ui/_i18n/LocalStrings_de.properties index 2a6d5d862e71f3e6c4a1912c5c2bace375855cae..01ad1acb0983bc3415fdd419977f105d2b091fda 100644 --- a/src/main/java/com/frentix/olat/vitero/ui/_i18n/LocalStrings_de.properties +++ b/src/main/java/com/frentix/olat/vitero/ui/_i18n/LocalStrings_de.properties @@ -5,7 +5,12 @@ vitero.intro=Hiermit kann die gesamte Vitero-Funktionalit vitero.module.enabled=Vitero einschalten vitero.account=Konto enabled=Ein - +signin=Sign in +signin.ok=Sign in ok +signin.nok=Sign in not ok +signout=Sign out +signout.ok=Sign out ok +signout.nok=Sign out not ok vc.booking.title=Termin f\u00fcr Meeting vc.booking.new=Neu Booking @@ -22,7 +27,9 @@ vc.check.ok=OK vc.check.nok=Nicht OK! vc.check.url.invalid=URL ist nicht gültig vc.check.customer.invalid=Benutzer ID ist nicht gültig - +vc.check.bookingInPast=Booking in the past +vc.check.bookingDatesInverted=End is before begin +vc.autoSignIn=Auto sign-in vc.table.begin=Start vc.table.beginBuffer=Start buffer vc.table.end=Ende