コード例 #1
0
 public void printClassificationFilter(ClassificationFilter f) throws IOException, RaplaException {
   openTag("rapla:classificationfilter");
   att("dynamictype", f.getType().getKey());
   closeTag();
   for (Iterator<? extends ClassificationFilterRule> it = f.ruleIterator(); it.hasNext(); ) {
     ClassificationFilterRule rule = it.next();
     printClassificationFilterRule(rule);
   }
   closeElement("rapla:classificationfilter");
 }
コード例 #2
0
ファイル: ClientFacadeTest.java プロジェクト: kevnallen/rapla
 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);
 }
コード例 #3
0
ファイル: ClientFacadeTest.java プロジェクト: kevnallen/rapla
  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]);
  }