/** @param dairy */
  private void populateBaseCollectionSessions(Dairy dairy) {
    CollectionSession cSession;

    Session session;
    Transaction transaction;

    session = getOrCreateSession();
    transaction = session.beginTransaction();

    dairy = (Dairy) session.load("Dairy", dairy.getCompanyId());

    cSession = DairyFactory.eINSTANCE.createCollectionSession();
    cSession.setCode("AM");
    cSession.setTimeOfDay(new Date(0, 0, 0, 6, 0));
    cSession.setDescription("The first collection session of the day");
    dairy.getCollectionSessions().add(cSession);

    cSession = DairyFactory.eINSTANCE.createCollectionSession();
    cSession.setCode("PM");
    cSession.setDescription("An additional collection session.");
    cSession.setTimeOfDay(new Date(0, 0, 0, 13, 0));
    dairy.getCollectionSessions().add(cSession);

    transaction.commit();
  }
 private void condenseContacts() {
   // TODO: this is really not safe.. need to lock dairy as well?
   synchronized (localDairy.getContactMethods()) {
     final List<ContactMethod> emptyMethods = new LinkedList<ContactMethod>();
     for (final ContactMethod method : localDairy.getContactMethods()) {
       if (method.getCmValue() == null || method.getCmValue().trim().length() == 0) {
         emptyMethods.add(method);
       }
     }
     localDairy.getContactMethods().removeAll(emptyMethods);
   }
 }
  /** Initialize bindings (bind to model). */
  private void initBindings() {
    // info panel
    txtID.bindToModel(localDairy, "companyId");
    txtNAME.bindToModel(localDairy, "companyName");
    txtPHONE.bindToModel(localDairy, "phoneNumber");
    txtPUBLIC_DESCRIPTION.bindToModel(localDairy, "description");
    txtPROFILE_IMAGE.bindToModel(localDairy, "profilePhoto");

    txtMANAGER_NAME.bindToModel(localDairy, "managerName");
    txtESTABLISHED_DATE.bindToModel(localDairy, "establishedDate");
    txtMEMBER_COUNT.bindToModel(this, "memberCount");
    // setMemberCount(localDairy.getMemberships().size());
    // registration panel
    txtLEGAL_NAME.bindToModel(localDairy, "legalName");
    txtREGISTRATION_NBR.bindToModel(localDairy, "registrationNumber");
    txtNSSF_NUMBER.bindToModel(localDairy, "nssfNumber");
    txtNHIF_NUMBER.bindToModel(localDairy, "nhifNumber");
    txtFEDERAL_PIN.bindToModel(localDairy, "federalPin");
    txtLIC_EFFECTIVE_DATE.bindToModel(localDairy, "licenseEffectiveDate");
    txtLIC_EXPIRATION_DATE.bindToModel(localDairy, "licenseExpirationDate");

    locationController.setInputModel(localDairy.getLocation());
    contactsGroup.bindToModel(localDairy.getContactMethods());

    //		System.err.println("ADAPTER COUNT: " + localDairy.eAdapters().size());
    //		System.err.println("ADAPTERS : " + localDairy.eAdapters());
    //		localDairy.eAdapters().add(new Adapter() {
    //			Notifier target;
    //			@Override
    //			public void notifyChanged(Notification notification) {
    //				System.err.println( ">> NOTIFICATION: " + notification);
    //			}
    //
    //			@Override
    //			public Notifier getTarget() {
    //				System.err.println( ">> getTarget: " + target);
    //				return target;
    //			}
    //
    //			@Override
    //			public void setTarget(Notifier newTarget) {
    //				System.err.println( ">> setTarget: " + newTarget);
    //				target = newTarget;
    //			}
    //
    //			@Override
    //			public boolean isAdapterForType(Object type) {
    //				System.err.println(  ">> IS_ADAPTER_FOR_CHECK: " + type);
    //				return true;
    //			}
    //
    //		});
  }
  protected Dairy createDairy(String dairyNumber, String licenseeName) {
    Session session;
    Transaction transaction;

    Dairy dairy;
    Location location;

    session = getOrCreateSession();
    transaction = session.beginTransaction();

    location = ModelFactory.eINSTANCE.createLocation();
    location.setDescriptiveLocation(null);
    location.setMapLocation(null);
    location.setPostalLocation(null);
    location.setStatutoryLocation(null);
    session.persist(location);

    dairy = DairyFactory.eINSTANCE.createDairy();
    dairy.setRegistrationNumber(dairyNumber);
    dairy.setLegalName(licenseeName);
    // dairy.setCompanyId(getDairyId());

    dairy.setDescription("<description>");
    dairy.setCompanyName("<company common name>");
    dairy.setPhoneNumber("+254 0072 0000 0000");
    dairy.setEstablishedDate(new Date(1, 1, 1975));

    dairy.setLocation(location);
    session.persist(dairy);

    transaction.commit();

    return dairy;
  }
  protected Membership createMember(String accountNo) {
    final Farmer farmer = DairyUtil.createFarmer(accountNo, "", "", "", (Farm) null);
    farmer.setNickName(accountNo);

    final Membership member = DairyUtil.createMembership(new Date(), new Date(), farmer);
    member.setMemberNumber(accountNo);
    member.setStatus(MembershipStatus.ACTIVE);

    DAIRY.getMemberships().add(member);
    repo.save(DAIRY);

    return member;
  }
 private DairyLocation getCenter(String key) {
   DairyLocation center = centers.get(key);
   if (center == null) {
     center = DairyFactory.eINSTANCE.createDairyLocation();
     center.setCode(key);
     center.setName(key);
     center.setLocation(DairyUtil.createLocation(null, null, null));
     DAIRY.getBranchLocations().add(center);
     repo.save(center);
     centers.put(key, center);
   }
   return center;
 }
  private void initSampleDairy() {
    DAIRY = DairyFactory.eINSTANCE.createDairy();
    DAIRY.setCompanyName("test");
    DAIRY.setDescription("");
    DAIRY.setRegistrationNumber("");
    DAIRY.setLocation(DairyUtil.createLocation(null, null, null));
    DAIRY.setPhoneNumber("");

    DEFAULT_DRIVER =
        DairyUtil.createEmployee(
            null, "Driver", new Date(100000), "Strom", "", "Thurmond", "", null, null);
    DAIRY.getEmployees().add(DEFAULT_DRIVER);
  }