Exemplo n.º 1
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);
  }
Exemplo n.º 2
0
 public List getLinkedCollections(VDC vdc, boolean getHiddenCollections) {
   // getHiddenCollections is no longer used
   return vdc.getLinkedCollections();
 }