Example #1
0
  @Override
  protected void handleNotificationEvent(Notification notification) {
    super.handleNotificationEvent(notification);
    if ((notification.getEventType() == Notification.SET)
        && (notification.getNotifier() instanceof org.ow2.aspirerfid.ide.bpwme.impl.EBProcImpl)) {

      EBProcImpl epi = (EBProcImpl) notification.getNotifier();
      EAttributeImpl ei = (EAttributeImpl) notification.getFeature();
      MainControl mc = MainControl.getMainControl();

      org.ow2.aspirerfid.commons.apdl.model.EBProc ebproc =
          (org.ow2.aspirerfid.commons.apdl.model.EBProc) mc.getMapObject(epi.hashCode());

      EPCISMasterDataDocumentType doc = MasterDataUtil.getEPCISMasterDataDocument(ebproc);
      VocabularyElementType vocabularyElement = MasterDataUtil.getEBProcVocabularyElement(doc);

      if (ei.getName().equals("id")) {
        ebproc.setId(notification.getNewStringValue());
        MasterDataUtil.setVocabularyElementID(vocabularyElement, notification.getNewStringValue());
      } else if (ei.getName().equals("name")) {
        ebproc.setName(notification.getNewStringValue());
        MasterDataUtil.setVocabularyElementAttribute(
            vocabularyElement,
            "urn:epcglobal:epcis:mda:event_name",
            notification.getNewStringValue());
      } else if (ei.getName().equals("description")) {
        ebproc.setDescription(notification.getNewStringValue());
      } else {
        return;
      }

      mc.saveObject();
    }
  }
 protected void updateSimpleRefID(Notification notification) {
   for (StructValue structValue : getStructValue()) {
     for (SimpleRef ref : structValue.getSimpleRef()) {
       if (ref.getRefID() != null) {
         if (ref.getRefID().equals(notification.getOldStringValue())) {
           ref.setRefID(notification.getNewStringValue());
           break;
         }
       } else if (ref.getRefID() == null && notification.getOldStringValue() == null) {
         ref.setRefID(notification.getNewStringValue());
         break;
       }
     }
   }
 }
  public void testNotificationChain() throws Exception {
    msg("Opening session");
    final CDOSession session = openSession();

    // ************************************************************* //

    msg("Creating category1");
    final Category category1A = getModel1Factory().createCategory();
    category1A.setName("category1");

    msg("Creating company");
    final Company companyA = getModel1Factory().createCompany();

    msg("Adding categories");
    companyA.getCategories().add(category1A);

    msg("Opening transaction");
    final CDOTransaction transaction = session.openTransaction();

    transaction.options().addChangeSubscriptionPolicy(CDOAdapterPolicy.ALL);

    msg("Creating resource");
    final CDOResource resourceA = transaction.createResource(getResourcePath("/test1"));

    msg("Adding company");
    resourceA.getContents().add(companyA);

    msg("Committing");
    transaction.commit();

    final TestAdapter adapter = new TestAdapter();

    companyA.eAdapters().add(adapter);

    // ************************************************************* //

    msg("Opening view");
    final CDOSession session2 = openSession();
    final CDOTransaction transaction2 = session2.openTransaction();

    final Company company1B =
        (Company)
            CDOUtil.getEObject(
                transaction2.getObject(CDOUtil.getCDOObject(companyA).cdoID(), true));

    msg("Changing name");
    company1B.setName("TEST1");
    company1B.setCity("CITY1");

    final Category category2B = getModel1Factory().createCategory();
    company1B.getCategories().add(category2B);

    assertEquals(0, adapter.getNotifications().length);

    msg("Committing");
    transaction2.commit();

    msg("Checking after commit");
    new PollingTimeOuter() {
      @Override
      protected boolean successful() {
        return adapter.getNotifications().length == 3;
      }
    }.assertNoTimeOut();

    int count = 0;
    for (Notification notification : adapter.getNotifications()) {
      CDODeltaNotification cdoNotification = (CDODeltaNotification) notification;
      if (adapter.getNotifications().length - 1 == count) {
        assertEquals(false, cdoNotification.hasNext());
      } else {
        assertEquals(true, cdoNotification.hasNext());
      }

      if (notification.getFeature() == getModel1Package().getCategory_Name()) {
        assertEquals(Notification.SET, notification.getEventType());
        assertEquals("TEST1", notification.getNewStringValue());
      } else if (notification.getFeature() == getModel1Package().getAddress_City()) {
        assertEquals(Notification.SET, notification.getEventType());
        assertEquals("CITY1", notification.getNewStringValue());
      } else if (notification.getFeature() == getModel1Package().getCompany_Categories()) {
        assertEquals(Notification.ADD, notification.getEventType());
        assertEquals(1, notification.getPosition());
        assertEquals(
            transaction.getObject(CDOUtil.getCDOObject(category2B).cdoID(), true),
            notification.getNewValue());
      } else {
        assertEquals(false, false);
      }

      count++;
    }
  }