Skip to content
Snippets Groups Projects
Commit ec882dad authored by tpylak's avatar tpylak
Browse files

LMS-1988 write DataSetInformation.toString() to allow to override it in subclusses

SVN: 19927
parent b074e6cf
No related branches found
No related tags found
No related merge requests found
......@@ -20,11 +20,8 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.log4j.Logger;
......@@ -242,30 +239,7 @@ public class DataSetStorageAlgorithm<T extends DataSetInformation>
public String getSuccessRegistrationMessage()
{
final StringBuilder buffer = new StringBuilder();
String userID = dataSetInformation.getUploadingUserIdOrNull();
String userEMail = dataSetInformation.tryGetUploadingUserEmail();
if (userID != null || userEMail != null)
{
appendNameAndObject(buffer, "User", userID == null ? userEMail : userID);
}
appendNameAndObject(buffer, "Data Set Code", dataSetInformation.getDataSetCode());
appendNameAndObject(buffer, "Data Set Type", dataSetType.getCode());
appendNameAndObject(buffer, "Experiment Identifier",
dataSetInformation.getExperimentIdentifier());
appendNameAndObject(buffer, "Sample Identifier", dataSetInformation.getSampleIdentifier());
appendNameAndObject(buffer, "Producer Code", dataSetInformation.getProducerCode());
appendNameAndObject(buffer, "Production Date",
formatDate(dataSetInformation.getProductionDate()));
final List<String> parentDataSetCodes = dataSetInformation.getParentDataSetCodes();
if (parentDataSetCodes.isEmpty() == false)
{
appendNameAndObject(buffer, "Parent Data Sets",
StringUtils.join(parentDataSetCodes, ' '));
}
appendNameAndObject(buffer, "Is complete", dataSetInformation.getIsCompleteFlag());
buffer.setLength(buffer.length() - 1);
return buffer.toString();
return dataSetInformation.toString();
}
public String getFailureRegistrationMessage()
......@@ -273,20 +247,6 @@ public class DataSetStorageAlgorithm<T extends DataSetInformation>
return "Error when trying to register data set '" + incomingDataSetFile.getName() + "'.";
}
private String formatDate(Date productionDate)
{
return productionDate == null ? "" : Constants.DATE_FORMAT.get().format(productionDate);
}
private final void appendNameAndObject(final StringBuilder buffer, final String name,
final Object object)
{
if (object != null)
{
buffer.append(name).append("::").append(object).append(";");
}
}
protected DataSetType getDataSetType()
{
return dataSetType;
......
......@@ -20,10 +20,10 @@ import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.StringUtils;
import ch.systemsx.cisd.common.Constants;
import ch.systemsx.cisd.common.types.BooleanOrUnknown;
import ch.systemsx.cisd.common.utilities.ModifiedShortPrefixToStringStyle;
import ch.systemsx.cisd.openbis.generic.shared.IServer;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment;
......@@ -344,7 +344,41 @@ public class DataSetInformation implements Serializable
@Override
public String toString()
{
return ToStringBuilder.reflectionToString(this,
ModifiedShortPrefixToStringStyle.MODIFIED_SHORT_PREFIX_STYLE);
final StringBuilder buffer = new StringBuilder();
String userID = getUploadingUserIdOrNull();
String userEMail = tryGetUploadingUserEmail();
if (userID != null || userEMail != null)
{
appendNameAndObject(buffer, "User", userID == null ? userEMail : userID);
}
appendNameAndObject(buffer, "Data Set Code", getDataSetCode());
appendNameAndObject(buffer, "Data Set Type", getDataSetType().getCode());
appendNameAndObject(buffer, "Experiment Identifier", getExperimentIdentifier());
appendNameAndObject(buffer, "Sample Identifier", getSampleIdentifier());
appendNameAndObject(buffer, "Producer Code", getProducerCode());
appendNameAndObject(buffer, "Production Date", formatDate(getProductionDate()));
final List<String> parentDataSetCodes = getParentDataSetCodes();
if (parentDataSetCodes.isEmpty() == false)
{
appendNameAndObject(buffer, "Parent Data Sets",
StringUtils.join(parentDataSetCodes, ' '));
}
appendNameAndObject(buffer, "Is complete", getIsCompleteFlag());
buffer.setLength(buffer.length() - 1);
return buffer.toString();
}
private static String formatDate(Date productionDate)
{
return productionDate == null ? "" : Constants.DATE_FORMAT.get().format(productionDate);
}
protected static final void appendNameAndObject(final StringBuilder buffer, final String name,
final Object object)
{
if (object != null)
{
buffer.append(name).append("::").append(object).append(";");
}
}
}
\ No newline at end of file
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