From 13fe0afb045e769cc1f80460abea39224c6ae0a9 Mon Sep 17 00:00:00 2001 From: pkupczyk <pkupczyk> Date: Thu, 3 May 2012 08:20:09 +0000 Subject: [PATCH] SP-18 / BIS-20: Ensure a dataset is only deleted on the DSS when it was successfully deleted in the AS database - JUnit SVN: 25147 --- .../basic/dto/DeletedDataSetLocation.java | 78 +++++++++++++++++-- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DeletedDataSetLocation.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DeletedDataSetLocation.java index 991abf97c2b..aee627488fa 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DeletedDataSetLocation.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/DeletedDataSetLocation.java @@ -19,9 +19,15 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.List; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + import ch.systemsx.cisd.common.shared.basic.utils.StringUtils; /** @@ -34,7 +40,7 @@ public class DeletedDataSetLocation implements IDeletedDataSetLocation, Serializ private static final String SEPARATOR_BETWEEN_LOCATIONS = ", "; - private static final String SEPARATOR_BETWEEN_PARTS = "//"; + private static final String SEPARATOR_BETWEEN_PARTS = "/"; private String datastoreCode; @@ -42,6 +48,10 @@ public class DeletedDataSetLocation implements IDeletedDataSetLocation, Serializ private String location; + public DeletedDataSetLocation() + { + } + public String getDatastoreCode() { return datastoreCode; @@ -121,8 +131,12 @@ public class DeletedDataSetLocation implements IDeletedDataSetLocation, Serializ public static List<DeletedDataSetLocation> parse(String str) { + if (str == null) + { + return Collections.emptyList(); + } List<DeletedDataSetLocation> locationObjects = new ArrayList<DeletedDataSetLocation>(); - String[] locationStrings = str.split(SEPARATOR_BETWEEN_LOCATIONS); + String[] locationStrings = str.split(SEPARATOR_BETWEEN_LOCATIONS, -1); for (String locationString : locationStrings) { @@ -137,19 +151,30 @@ public class DeletedDataSetLocation implements IDeletedDataSetLocation, Serializ if (locationPartsIter.hasNext()) { - locationObject.setDatastoreCode(locationPartsIter.next()); + locationObject.setDatastoreCode(StringUtils.nullIfBlank(locationPartsIter + .next())); } if (locationPartsIter.hasNext()) { - locationObject.setShareId(locationPartsIter.next()); + locationObject.setShareId(StringUtils.nullIfBlank(locationPartsIter.next())); } if (locationPartsIter.hasNext()) { - locationObject.setLocation(locationPartsIter.next()); + StringBuilder location = new StringBuilder(); + while (locationPartsIter.hasNext()) + { + location.append(locationPartsIter.next()); + if (locationPartsIter.hasNext()) + { + location.append(SEPARATOR_BETWEEN_PARTS); + } + } + locationObject.setLocation(StringUtils.nullIfBlank(location.toString())); } - } else if (locationString.trim().length() > 0) + + } else { - locationObject.setLocation(locationString); + locationObject.setLocation(StringUtils.nullIfBlank(locationString)); } locationObjects.add(locationObject); @@ -158,4 +183,43 @@ public class DeletedDataSetLocation implements IDeletedDataSetLocation, Serializ return locationObjects; } + @Override + public int hashCode() + { + HashCodeBuilder builder = new HashCodeBuilder(); + builder.append(getDatastoreCode()); + builder.append(getShareId()); + builder.append(getLocation()); + return builder.toHashCode(); + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + + DeletedDataSetLocation other = (DeletedDataSetLocation) obj; + + EqualsBuilder builder = new EqualsBuilder(); + builder.append(getDatastoreCode(), other.getDatastoreCode()); + builder.append(getShareId(), other.getShareId()); + builder.append(getLocation(), other.getLocation()); + + return builder.isEquals(); + } + + @Override + public String toString() + { + ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); + builder.append("datastoreCode", getDatastoreCode()); + builder.append("shareId", getShareId()); + builder.append("location", getLocation()); + return builder.toString(); + } } -- GitLab