Ejemplo n.º 1
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");
 }
Ejemplo n.º 2
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]);
  }