@Transactional(
      value = "jamiTransactionManager",
      readOnly = true,
      propagation = Propagation.REQUIRED)
  public IntactSource reloadFullyInitialisedSource(IntactSource cv) {
    if (cv == null) {
      return null;
    }
    IntactSource reloaded = null;
    if (areSourceCollectionsLazy(cv)
        && cv.getAc() != null
        && !getIntactDao().getEntityManager().contains(cv)) {
      reloaded = loadSourceByAc(cv.getAc());
    }

    // we need first to merge with reloaded complex
    if (reloaded != null) {
      // detach reloaded now so not changes will be committed
      getIntactDao().getEntityManager().detach(reloaded);
      InstitutionCloner cloner = new InstitutionCloner();
      cloner.copyInitialisedProperties(cv, reloaded);
      cv = reloaded;
    }

    // initialise xrefs because are first tab visible
    initialiseXrefs(cv.getDbXrefs());
    // initialise annotations because needs caution
    initialiseAnnotations(cv.getDbAnnotations());
    // initialise aliases
    initialiseAliases(cv.getSynonyms());

    return cv;
  }
 @Transactional(
     value = "jamiTransactionManager",
     readOnly = true,
     propagation = Propagation.REQUIRED)
 public int countAliases(IntactSource cv) {
   return getIntactDao().getSourceDao().countSynonymsForSource(cv.getAc());
 }
  @Transactional(
      value = "jamiTransactionManager",
      readOnly = true,
      propagation = Propagation.REQUIRED)
  public Collection<Annotation> initialiseSourceAnnotations(IntactSource releasable) {
    // reload complex without flushing changes
    IntactSource reloaded = releasable;
    // merge current user because detached
    if (releasable.getAc() != null && !getIntactDao().getEntityManager().contains(releasable)) {
      reloaded = getIntactDao().getEntityManager().find(IntactSource.class, releasable.getAc());
      if (reloaded == null) {
        reloaded = releasable;
      }
    }

    initialiseAnnotations(reloaded.getAnnotations());
    return reloaded.getAnnotations();
  }
  @Transactional(
      value = "jamiTransactionManager",
      readOnly = true,
      propagation = Propagation.REQUIRED)
  public IntactSource loadSourceByAc(String ac) {
    IntactSource cv = getIntactDao().getEntityManager().find(IntactSource.class, ac);

    if (cv != null) {
      // initialise xrefs because are first tab visible
      initialiseXrefs(cv.getDbXrefs());
      // initialise annotations because needs caution, url, etc
      initialiseAnnotations(cv.getDbAnnotations());
      // initialise aliases
      initialiseAliases(cv.getSynonyms());
    }

    return cv;
  }
  @Transactional(
      value = "jamiTransactionManager",
      propagation = Propagation.REQUIRED,
      readOnly = true)
  public void loadInstitutions() {
    if (log.isDebugEnabled()) log.debug("Loading Institutions");

    synchronized (this) {
      this.institutionSelectItems = null;
      List<IntactSource> allInstitutions =
          getIntactDao().getSourceDao().getAllSorted(0, Integer.MAX_VALUE, "shortName", true);

      institutionSelectItems = new ArrayList<SelectItem>(allInstitutions.size());

      for (IntactSource institution : allInstitutions) {
        institutionSelectItems.add(
            new SelectItem(institution, institution.getShortName(), institution.getFullName()));
      }

      isInitialised = true;
    }
  }
 private boolean areSourceCollectionsLazy(IntactSource cv) {
   return !cv.areAnnotationsInitialized()
       || !cv.areXrefsInitialized()
       || !cv.areSynonymsInitialized();
 }