Skip to content
Snippets Groups Projects
Commit ec4dc6a0 authored by felmer's avatar felmer
Browse files

LMS-2483 Following bug fixed: In case of deleted container data sets EventDAO...

LMS-2483 Following bug fixed: In case of deleted container data sets EventDAO thrown an exception because number of locations where different from number of identifiers. Also archiving tasks are modified to delete only physical data sets.

SVN: 24150
parent b7e664c4
No related branches found
No related tags found
No related merge requests found
......@@ -125,7 +125,7 @@ public class DeleteFromArchiveMaintenanceTask extends
List<DeletedDataSet> result = new ArrayList<DeletedDataSet>();
for (DeletedDataSet dataset : datasets) {
if (dataset.getIdentifier() != null
&& false == dataset.getIdentifier().equals(dataset.getLocation()))
&& false == dataset.getIdentifier().equals(dataset.getLocationOrNull()))
{
result.add(dataset);
}
......@@ -138,7 +138,10 @@ public class DeleteFromArchiveMaintenanceTask extends
ArrayList<DatasetLocation> result = new ArrayList<DatasetLocation>(datasets.size());
for (DeletedDataSet deletedDS : datasets)
{
result.add(toDataSetLocations(deletedDS));
if (deletedDS.getLocationOrNull() != null)
{
result.add(toDataSetLocations(deletedDS));
}
}
return result;
}
......@@ -147,7 +150,7 @@ public class DeleteFromArchiveMaintenanceTask extends
{
DatasetLocation dsLocation = new DatasetLocation();
dsLocation.setDatasetCode(deletedDS.getIdentifier());
dsLocation.setDataSetLocation(deletedDS.getLocation());
dsLocation.setDataSetLocation(deletedDS.getLocationOrNull());
return dsLocation;
}
}
......@@ -209,7 +209,7 @@ public class ArchivingPostRegistrationTask extends AbstractPostRegistrationTask
IArchiverPlugin archiver = ServiceProvider.getDataStoreService().getArchiverPlugin();
DatasetDescription dataSet = tryGetDatasetWithLocation(dataSetCode, openBISService);
if (archiver != null && dataSet != null)
if (archiver != null && dataSet != null && dataSet.getDataSetLocation() != null)
{
DatasetLocation dataset = new DatasetLocation();
dataset.setDatasetCode(dataSetCode);
......
......@@ -17,9 +17,10 @@
package ch.systemsx.cisd.openbis.generic.server.dataaccess.db;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.hibernate.Criteria;
......@@ -29,7 +30,6 @@ import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.jdbc.support.JdbcAccessor;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory;
import ch.systemsx.cisd.common.utilities.MethodUtils;
......@@ -53,8 +53,8 @@ public class EventDAO extends AbstractGenericEntityDAO<EventPE> implements IEven
* This logger does not output any SQL statement. If you want to do so, you had better set an
* appropriate debugging level for class {@link JdbcAccessor}. </p>
*/
private static final Logger operationLog =
LogFactory.getLogger(LogCategory.OPERATION, EventPE.class);
private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION,
EventPE.class);
public EventDAO(SessionFactory sessionFactory, DatabaseInstancePE databaseInstance)
{
......@@ -108,21 +108,11 @@ public class EventDAO extends AbstractGenericEntityDAO<EventPE> implements IEven
ArrayList<DeletedDataSet> result = new ArrayList<DeletedDataSet>();
for (EventPE event : list)
{
Map<String, String> map = createIdentifierToLocationMap(event.getDescription());
List<String> identifiers = event.getIdentifiers();
List<String> locations =
Arrays.asList(event.getDescription().split(EventPE.IDENTIFIER_SEPARATOR));
if (identifiers.size() != locations.size())
for (String dataSetCode : identifiers)
{
throw EnvironmentFailureException.fromTemplate(
"Number of deleted dataset codes %s does not match "
+ "the number of deleted data set locations %s in eventId='%s'",
identifiers.size(), locations.size(), event.getId());
}
int pos = 0;
for (pos = 0; pos < identifiers.size(); pos++)
{
String dataSetCode = identifiers.get(pos);
String dataSetLocation = locations.get(pos);
String dataSetLocation = map.get(dataSetCode);
DeletedDataSet deletedDataSet =
new DeletedDataSet(dataSetCode, dataSetLocation, event.getId());
result.add(deletedDataSet);
......@@ -130,4 +120,17 @@ public class EventDAO extends AbstractGenericEntityDAO<EventPE> implements IEven
}
return result;
}
private Map<String, String> createIdentifierToLocationMap(String locations)
{
Map<String, String> result = new HashMap<String, String>();
for (String location : locations.split(EventPE.IDENTIFIER_SEPARATOR))
{
int lastIndexOfSlash = location.lastIndexOf('/');
String identifier =
lastIndexOfSlash < 0 ? location : location.substring(lastIndexOfSlash + 1);
result.put(identifier, location);
}
return result;
}
}
......@@ -34,18 +34,19 @@ public class DeletedDataSet implements Serializable, ICodeHolder
private final long eventId;
private final String location; // the location where the data set existed before deletion
private final String locationOrNull; // the location where the data set existed before deletion
// or null if it was a container data set
public DeletedDataSet(String identifier, String location, long eventId)
public DeletedDataSet(String identifier, String locationOrNull, long eventId)
{
this.eventId = eventId;
this.identifier = identifier;
this.location = location;
this.locationOrNull = locationOrNull;
}
public String getLocation()
public String getLocationOrNull()
{
return location;
return locationOrNull;
}
public String getCode()
......
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