Skip to content
Snippets Groups Projects
Commit 951dd304 authored by jakubs's avatar jakubs
Browse files

LMS-2843: add deletion of contained datasets when trash is disabled

SVN: 24770
parent b4dedff3
No related branches found
No related tags found
No related merge requests found
......@@ -223,8 +223,19 @@ public abstract class AbstractServer<T> extends AbstractServiceWithLogger<T> imp
List<String> dataSetCodes, String reason, boolean force)
{
// TODO 2011-06-21, Piotr Buczek: loading less for deletion would probably be faster
// first load by codes to get the ids
dataSetTable.loadByDataSetCodes(dataSetCodes, false, false);
// get recursively all datasets that are contained and contained
List<TechId> ids =
daoFactory.getDataDAO().listContainedDataSetsRecursively(
TechId.createList(dataSetTable.getDataSets()));
dataSetTable.loadByIds(ids);
List<DataPE> dataSets = dataSetTable.getDataSets();
Map<DataSetTypePE, List<DataPE>> groupedDataSets =
new LinkedHashMap<DataSetTypePE, List<DataPE>>();
for (DataPE dataSet : dataSets)
......
......@@ -119,16 +119,7 @@ public class TrashBO extends AbstractBusinessObject implements ITrashBO
{
assert deletion != null;
LinkedHashSet<TechId> allIds = new LinkedHashSet<TechId>();
// cascade deletion of contained datasets
List<TechId> containedDataSetIds = dataSetIds;
while (allIds.addAll(containedDataSetIds))
{
containedDataSetIds = getDataDAO().listContainedDataSets(containedDataSetIds);
}
List<TechId> allIdsAsList = new ArrayList<TechId>(allIds);
List<TechId> allIdsAsList = getDataDAO().listContainedDataSetsRecursively(dataSetIds);
checkForNonDeletableDataSets(allIdsAsList);
TrashBatchOperation batchOperation =
......
......@@ -143,6 +143,12 @@ public interface IDataDAO extends IGenericDAO<DataPE>
/** Returns ids of contained data sets for a given collection of containers. */
public List<TechId> listContainedDataSets(final Collection<TechId> containerIds);
/**
* Returs ids of contained data sets, and of datasets contained in those datasets etc. Also
* includes the input ids.
*/
public List<TechId> listContainedDataSetsRecursively(final Collection<TechId> containersIds);
/**
* Delete data sets with given ids by specified registrator with specified reason.
*/
......
......@@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
......@@ -1117,4 +1119,22 @@ final class DataDAO extends AbstractGenericEntityWithPropertiesDAO<DataPE> imple
return transformNumbers2TechIdList(totalResults);
}
public List<TechId> listContainedDataSetsRecursively(Collection<TechId> containersIds)
{
LinkedHashSet<TechId> allIds = new LinkedHashSet<TechId>();
// cascade deletion of contained datasets
List<TechId> containedDataSetIds = new LinkedList<TechId>();
containedDataSetIds.addAll(containersIds);
while (allIds.addAll(containedDataSetIds))
{
containedDataSetIds = listContainedDataSets(containedDataSetIds);
}
return new ArrayList<TechId>(allIds);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment