Пример #1
1
 public VDC find(Object pk) {
   VDC vdc = (VDC) em.find(VDC.class, pk);
   VDCCollection rootCollection = vdc.getRootCollection();
   rootCollection.getId();
   Collection<VDCCollection> subcollections = rootCollection.getSubCollections();
   traverseCollections(subcollections);
   return vdc;
 }
Пример #2
0
  private void traverseCollections(Collection<VDCCollection> collections) {
    for (Iterator it = collections.iterator(); it.hasNext(); ) {
      VDCCollection elem = (VDCCollection) it.next();
      elem.getId();

      Collection<VDCCollection> subcollections = elem.getSubCollections();
      if (subcollections.size() > 0) {
        traverseCollections(subcollections);
      }
    }
  }
Пример #3
0
  public void delete(Long vdcId) {
    VDC vdc = em.find(VDC.class, vdcId);
    em.refresh(vdc);
    List studyIds = new ArrayList();

    // Get the studyIds separately, to avoid a ConcurrentAccess Exception
    // (This is necessary because the studies are deleted in Native SQL)
    for (Iterator it = vdc.getOwnedStudies().iterator(); it.hasNext(); ) {
      Study elem = (Study) it.next();
      studyIds.add(elem.getId());
    }

    if (!studyIds.isEmpty()) {
      studyService.deleteStudyList(studyIds);
    }

    vdc.getOwnedStudies().clear();

    vdc.setRootCollection(null);

    for (Iterator it = vdc.getOwnedCollections().iterator(); it.hasNext(); ) {
      VDCCollection elem = (VDCCollection) it.next();
      elem.setParentCollection(null);
      elem.setOwner(null);
      // Remove this Collection from all linked VDCs
      for (Iterator itc = elem.getLinkedVDCs().iterator(); itc.hasNext(); ) {
        VDC linkedVDC = (VDC) itc.next();
        linkedVDC.getLinkedCollections().remove(elem);
      }
    }

    for (Iterator it = vdc.getLinkedCollections().iterator(); it.hasNext(); ) {
      VDCCollection elem = (VDCCollection) it.next();
      VDCCollection coll = em.find(VDCCollection.class, elem.getId());
      coll.getLinkedVDCs().remove(vdc);
    }

    for (Iterator it = vdc.getVdcGroups().iterator(); it.hasNext(); ) {
      VDCGroup vdcGroup = (VDCGroup) it.next();
      vdcGroup.getVdcs().remove(vdc);
    }

    for (Iterator it = vdc.getVdcRoles().iterator(); it.hasNext(); ) {
      VDCRole vdcRole = (VDCRole) it.next();
      VDCUser vdcUser = vdcRole.getVdcUser();
      vdcUser.getVdcRoles().remove(vdcRole);
    }

    if (vdc.isHarvestingDv()) {
      harvesterService.removeHarvestTimer(vdc.getHarvestingDataverse());
    }

    // If the vdc Default Template is in the list of dataverse templates
    // (not the Network Default Template), then remove the reference before deleting the dataverse.
    // If not removed, you will get a foreign key violation when the persistence logic deletes
    // the collection of templates.
    if (vdc.getTemplates().contains(vdc.getDefaultTemplate())) {
      vdc.setDefaultTemplate(null);
    }
    em.remove(vdc);
  }