Exemplo n.º 1
0
 @Override
 public Collection<Appointment> eval(EvalContext context) {
   if (context instanceof ReservationEvalContext) {
     Reservation reservation = ((ReservationEvalContext) context).getReservation();
     List<Appointment> asList = Arrays.asList(reservation.getAppointments());
     return asList;
   }
   return Collections.emptyList();
 }
  /**
   * Pr&uuml;fe, ob eine Ressource f&uuml;r ein bestimmten Appointment reserviert ist.
   *
   * @param alloc
   * @param when
   * @return <code>true</code>, wenn die Ressource reserviert ist. <code>false</code> sonst
   */
  private boolean isReserved(Allocatable alloc, Appointment when) {
    Reservation reservation = when.getReservation();
    Appointment[] restrictions = reservation.getRestriction(alloc);

    for (int restIt = 0, restLen = restrictions.length; restIt < restLen; restIt++) {
      if (when.equals(restrictions[restIt])) return true;
    }

    return (restrictions.length == 0);
  }
Exemplo n.º 3
0
 public void testRefresh() throws Exception {
   changeInSecondFacade("bowling");
   facade.refresh();
   Reservation resAfter = findReservation(facade, "bowling");
   Appointment appointment = resAfter.getAppointments()[0];
   Calendar cal = Calendar.getInstance(DateTools.getTimeZone());
   cal.setTime(appointment.getStart());
   assertEquals(17, cal.get(Calendar.HOUR_OF_DAY));
   assertEquals(Calendar.MONDAY, cal.get(Calendar.DAY_OF_WEEK));
   cal.setTime(appointment.getEnd());
   assertEquals(19, cal.get(Calendar.HOUR_OF_DAY));
   assertEquals(Calendar.MONDAY, cal.get(Calendar.DAY_OF_WEEK));
 }
 /**
  * F&uuml;gt einem iCal-Event den Termin-Namen aus dem &uuml;bergebenen Appointment-Objekt hinzu.
  *
  * @param appointment
  */
 private void addEventNameToEvent(Appointment appointment, PropertyList properties) {
   Reservation reservation = appointment.getReservation();
   final Locale locale = raplaLocale.getLocale();
   String eventDescription = NameFormatUtil.getExportName(appointment, locale);
   if (reservation
           .getClassification()
           .getType()
           .getAnnotation(DynamicTypeAnnotations.KEY_NAME_FORMAT_EXPORT)
       == null) {
     eventDescription += getAttendeeString(appointment);
   }
   properties.add(new Summary(eventDescription));
 }
Exemplo n.º 5
0
 @Override
 public Collection<Allocatable> eval(EvalContext context) {
   if (context instanceof AppointmentEvalContext) {
     Appointment appointment = ((AppointmentEvalContext) context).getAppointment();
     final Reservation reservation = appointment.getReservation();
     List<Allocatable> asList = Arrays.asList(reservation.getAllocatablesFor(appointment));
     return asList;
   } else if (context instanceof ReservationEvalContext) {
     Reservation reservation = ((ReservationEvalContext) context).getReservation();
     List<Allocatable> asList = Arrays.asList(reservation.getAllocatables());
     return asList;
   }
   return Collections.emptyList();
 }
Exemplo n.º 6
0
 @Override
 public void selectReservation(Reservation selectedObject, PopupContext context) {
   ApplicationEventContext editContext =
       new EditApplicationEventContext<>(Collections.singletonList(selectedObject));
   final ApplicationEvent activity =
       new ApplicationEvent(
           ReservationPresenter.EDIT_ACTIVITY_ID, selectedObject.getId(), context, editContext);
   eventBus.fireEvent(activity);
   logger.info("selection changed");
 }
Exemplo n.º 7
0
 private int getAppointmentNumber(AppointmentBlock appointmentBlock) {
   final long blockStart = appointmentBlock.getEnd();
   final Date end = new Date(blockStart);
   final Appointment appointment = appointmentBlock.getAppointment();
   final Reservation reservation = appointment.getReservation();
   final Date start = reservation.getFirstDate();
   SortedSet<AppointmentBlock> blocks = new TreeSet<AppointmentBlock>();
   for (Appointment app : reservation.getAppointments()) {
     app.createBlocks(start, end, blocks);
   }
   final SortedSet<AppointmentBlock> headSet = blocks.headSet(appointmentBlock);
   final int size = headSet.size();
   //                final long appoimtmentStart = reservation.getFirstDate().getTime();
   //                if (appoimtmentStart ==  start)
   //                {
   //                    return 1;
   //                }
   return size + 1;
 }
  private void addDescriptionToEvent(Appointment appointment, PropertyList properties) {

    Reservation reservation = appointment.getReservation();
    String eventDescription;
    if (reservation
            .getClassification()
            .getType()
            .getAnnotation(DynamicTypeAnnotations.KEY_DESCRIPTION_FORMAT_EXPORT)
        != null) {
      eventDescription =
          reservation.format(
              raplaLocale.getLocale(),
              DynamicTypeAnnotations.KEY_DESCRIPTION_FORMAT_EXPORT,
              appointment);
    } else {
      eventDescription = null;
    }
    if (eventDescription != null) {
      properties.add(new Description(eventDescription));
    }
  }
Exemplo n.º 9
0
 private void addRestriction(Reservation reservation, Allocatable allocatable, StringBuffer buf) {
   Appointment[] appointments = reservation.getRestriction(allocatable);
   if (appointments.length == 0) return;
   buf.append("<small>");
   buf.append(" (");
   for (int i = 0; i < appointments.length; i++) {
     if (i > 0) buf.append(", ");
     encode(getAppointmentFormater().getShortSummary(appointments[i]), buf);
   }
   buf.append(")");
   buf.append("</small>");
 }
Exemplo n.º 10
0
  public String getAttendeeString(Appointment appointment) {

    String attendeeString = "";

    Reservation raplaReservation = appointment.getReservation();
    Allocatable[] raplaPersons = raplaReservation.getPersons();

    for (int i = 0; i < raplaPersons.length; i++) {
      if (!isReserved(raplaPersons[i], appointment)) continue;

      attendeeString += raplaPersons[i].getName(raplaLocale.getLocale());
      attendeeString = attendeeString.trim();

      if (i != raplaPersons.length - 1) {
        attendeeString += ", ";
      } else {
        attendeeString = " [" + attendeeString + "]";
      }
    }

    return attendeeString;
  }
Exemplo n.º 11
0
 public void testClone() throws Exception {
   ClassificationFilter filter = facade.getDynamicType("event").newClassificationFilter();
   filter.addEqualsRule("name", "power planting");
   Reservation orig =
       facade
           .getReservationsForAllocatable(null, null, null, new ClassificationFilter[] {filter})[
           0];
   Reservation clone = facade.clone(orig);
   Appointment a = clone.getAppointments()[0];
   Date newStart = new SerializableDateTimeFormat().parseDateTime("2005-10-10", "10:20:00");
   Date newEnd = new SerializableDateTimeFormat().parseDateTime("2005-10-12", null);
   a.move(newStart);
   a.getRepeating().setEnd(newEnd);
   facade.store(clone);
   Reservation[] allPowerPlantings =
       facade.getReservationsForAllocatable(null, null, null, new ClassificationFilter[] {filter});
   assertEquals(2, allPowerPlantings.length);
   Reservation[] onlyClones =
       facade.getReservationsForAllocatable(
           null, newStart, null, new ClassificationFilter[] {filter});
   assertEquals(1, onlyClones.length);
 }
Exemplo n.º 12
0
  public void testConflicts() throws Exception {
    Conflict[] conflicts = facade.getConflicts();
    Reservation[] all = facade.getReservationsForAllocatable(null, null, null, null);
    facade.removeObjects(all);
    Reservation orig = facade.newReservation();
    orig.getClassification().setValue("name", "new");
    Date start = DateTools.fillDate(new Date());
    Date end = getRaplaLocale().toDate(start, getRaplaLocale().toTime(12, 0, 0));
    orig.addAppointment(facade.newAppointment(start, end));

    orig.addAllocatable(facade.getAllocatables()[0]);

    Reservation clone = facade.clone(orig);
    facade.store(orig);
    facade.store(clone);

    Conflict[] conflictsAfter = facade.getConflicts();
    assertEquals(1, conflictsAfter.length - conflicts.length);
    HashSet<Conflict> set = new HashSet<Conflict>(Arrays.asList(conflictsAfter));

    assertTrue(set.containsAll(new HashSet<Conflict>(Arrays.asList(conflicts))));
  }
Exemplo n.º 13
0
  public List<Row> getAttributes(
      Reservation reservation,
      LinkController controller,
      User user,
      boolean excludeAdditionalInfos) {
    ArrayList<Row> att = new ArrayList<Row>();
    att.addAll(getClassificationAttributes(reservation, excludeAdditionalInfos, controller));
    User owner = reservation.getOwner();
    final Locale locale = getLocale();
    if (owner != null) {
      final String ownerName = owner.getName(locale);
      String ownerText = encode(ownerName);
      if (controller != null) ownerText = controller.createLink(owner, ownerName);
      att.add(new Row(getString("reservation.owner"), ownerText));
    }
    User lastChangeBy = reservation.getLastChangedBy();
    if (lastChangeBy != null && (owner == null || !lastChangeBy.equals(owner))) {
      final String lastChangedName = lastChangeBy.getName(locale);
      String lastChangeByText = encode(lastChangedName);
      if (controller != null)
        lastChangeByText = controller.createLink(lastChangeBy, lastChangedName);
      att.add(new Row(getString("last_changed_by"), lastChangeByText));
    }

    Allocatable[] resources = reservation.getResources();
    String resourceList = allocatableList(reservation, resources, user, controller);
    if (resourceList.length() > 0) {
      att.add(new Row(getString("resources"), resourceList));
    }
    Allocatable[] persons = reservation.getPersons();
    String personList = allocatableList(reservation, persons, user, controller);
    if (personList.length() > 0) {
      att.add(new Row(getString("persons"), personList));
    }
    return att;
  }
Exemplo n.º 14
0
  // Make some Changes to the Reservation in another client
  private void changeInSecondFacade(String name) throws Exception {
    ClientFacade facade2 = raplaContainer.lookup(ClientFacade.class, "local-facade2");
    facade2.login("homer", "duffs".toCharArray());
    UserModule userMod2 = facade2;
    QueryModule queryMod2 = facade2;
    ModificationModule modificationMod2 = facade2;
    boolean bLogin = userMod2.login("homer", "duffs".toCharArray());
    assertTrue(bLogin);
    Reservation reservation = findReservation(queryMod2, name);
    Reservation mutableReseravation = modificationMod2.edit(reservation);
    Appointment appointment = mutableReseravation.getAppointments()[0];

    RaplaLocale loc = getRaplaLocale();
    Calendar cal = loc.createCalendar();
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    Date startTime = loc.toTime(17, 0, 0);
    Date startTime1 = loc.toDate(cal.getTime(), startTime);
    Date endTime = loc.toTime(19, 0, 0);
    Date endTime1 = loc.toDate(cal.getTime(), endTime);
    appointment.move(startTime1, endTime1);

    modificationMod2.store(mutableReseravation);
    // userMod2.logout();
  }
Exemplo n.º 15
0
 void insertAllAppointments(Reservation reservation, StringBuffer buf) {
   buf.append("<table cellpadding=\"2\">");
   buf.append("<tr>\n");
   buf.append("<td colspan=\"2\" class=\"label\">");
   String appointmentLabel = getString("appointments");
   encode(appointmentLabel, buf);
   buf.append(":");
   buf.append("</td>\n");
   buf.append("</tr>\n");
   Appointment[] appointments = reservation.getAppointments();
   for (int i = 0; i < appointments.length; i++) {
     buf.append("<tr>\n");
     buf.append("<td valign=\"top\">\n");
     if (appointments[i].getRepeating() != null) {
       buf.append("<img width=\"16\" height=\"16\" src=\"org/rapla/gui/images/repeating.png\">");
     } else {
       buf.append("<img width=\"16\" height=\"16\" src=\"org/rapla/gui/images/single.png\">");
     }
     buf.append("</td>\n");
     buf.append("<td>\n");
     String appointmentSummary = getAppointmentFormater().getSummary(appointments[i]);
     encode(appointmentSummary, buf);
     Repeating repeating = appointments[i].getRepeating();
     if (repeating != null) {
       buf.append("<br>");
       buf.append("<small>");
       List<Period> periods = getPeriodModel().getPeriodsFor(appointments[i].getStart());
       String repeatingSummary = getAppointmentFormater().getSummary(repeating, periods);
       encode(repeatingSummary, buf);
       if (repeating.hasExceptions()) {
         buf.append("<br>");
         buf.append(getAppointmentFormater().getExceptionSummary(repeating));
       }
       buf.append("</small>");
     }
     buf.append("</td>\n");
     buf.append("<td></td>");
     buf.append("</tr>\n");
   }
   buf.append("</table>\n");
 }
Exemplo n.º 16
0
 public ReservationEvalContext(
     Locale locale, int callStackDepth, String annotationName, Reservation reservation) {
   super(locale, callStackDepth, annotationName, reservation.getClassification());
   this.reservation = reservation;
 }
Exemplo n.º 17
0
  public void testExampleEdit() throws Exception {

    String allocatableId;
    String eventId;
    {
      Allocatable nonPersistantAllocatable = getFacade().newResource();
      nonPersistantAllocatable.getClassification().setValue("name", "Bla");

      Reservation nonPeristantEvent = getFacade().newReservation();
      nonPeristantEvent.getClassification().setValue("name", "dummy-event");
      assertEquals("event", nonPeristantEvent.getClassification().getType().getKey());
      nonPeristantEvent.addAllocatable(nonPersistantAllocatable);
      nonPeristantEvent.addAppointment(getFacade().newAppointment(new Date(), new Date()));
      getFacade().storeObjects(new Entity[] {nonPersistantAllocatable, nonPeristantEvent});
      allocatableId = nonPersistantAllocatable.getId();
      eventId = nonPeristantEvent.getId();
    }
    Allocatable allocatable =
        facade.edit(facade.getOperator().resolve(allocatableId, Allocatable.class));

    // Store the allocatable it a second time to test if it is still modifiable after storing
    allocatable.getClassification().setValue("name", "Blubs");
    getFacade().store(allocatable);

    // query the allocatable from the store
    ClassificationFilter filter = getFacade().getDynamicType("room").newClassificationFilter();
    filter.addEqualsRule("name", "Blubs");
    Allocatable persistantAllocatable =
        getFacade().getAllocatables(new ClassificationFilter[] {filter})[0];

    // query the event from the store
    ClassificationFilter eventFilter =
        getFacade().getDynamicType("event").newClassificationFilter();
    eventFilter.addEqualsRule("name", "dummy-event");
    Reservation persistantEvent =
        getFacade()
            .getReservationsForAllocatable(
                null, null, null, new ClassificationFilter[] {eventFilter})[0];
    // Another way to get the persistant event would have been
    // Reservation persistantEvent = getFacade().getPersistant( nonPeristantEvent );

    // test if the ids of editable Versions are equal to the persistant ones
    assertEquals(persistantAllocatable, allocatable);
    Reservation event = facade.getOperator().resolve(eventId, Reservation.class);
    assertEquals(persistantEvent, event);
    assertEquals(persistantEvent.getAllocatables()[0], event.getAllocatables()[0]);

    //        // Check if the modifiable/original versions are different to the persistant versions
    //        assertTrue( persistantAllocatable !=  allocatable );
    //        assertTrue( persistantEvent !=  event );
    //        assertTrue( persistantEvent.getAllocatables()[0] != event.getAllocatables()[0]);

    // Test the read only constraints
    try {
      persistantAllocatable.getClassification().setValue("name", "asdflkj");
      fail("ReadOnlyException should have been thrown");
    } catch (ReadOnlyException ex) {
    }

    try {
      persistantEvent.getClassification().setValue("name", "dummy-event");
      fail("ReadOnlyException should have been thrown");
    } catch (ReadOnlyException ex) {
    }

    try {
      persistantEvent.removeAllocatable(allocatable);
      fail("ReadOnlyException should have been thrown");
    } catch (ReadOnlyException ex) {
    }

    // now we get a second edit copy of the event
    Reservation nonPersistantEventVersion2 = getFacade().edit(persistantEvent);
    assertTrue(nonPersistantEventVersion2 != event);

    // Both allocatables are persitant, so they have the same reference
    assertTrue(
        persistantEvent.getAllocatables()[0] == nonPersistantEventVersion2.getAllocatables()[0]);
  }