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

AtomicEntityOperationDetails.toString() improved: removing null or empty...

AtomicEntityOperationDetails.toString() improved: removing null or empty collections entries and shows only the first 100 items of a collection
parent 6bd4425f
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.shared.dto;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
......@@ -25,6 +26,7 @@ import java.util.TreeMap;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import ch.systemsx.cisd.common.collection.CollectionUtils;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperiment;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterial;
......@@ -257,24 +259,46 @@ public class AtomicEntityOperationDetails implements Serializable
public String toString()
{
ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
sb.append("registrationIdOrNull", registrationIdOrNull);
sb.append("userIdOrNull", userIdOrNull);
sb.append("spaceRegistrations", spaceRegistrations);
sb.append("projectRegistrations", projectRegistrations);
sb.append("projectUpdates", projectUpdates);
sb.append("experimentUpdates", experimentUpdates);
sb.append("experimentRegistrations", experimentRegistrations);
sb.append("sampleUpdates", sampleUpdates);
sb.append("sampleRegistrations", sampleRegistrations);
sb.append("materialRegistrations", materialRegistrations);
sb.append("dataSetRegistrations", dataSetRegistrations);
sb.append("dataSetUpdates", dataSetUpdates);
sb.append("metaprojectRegistrations", metaprojectRegistrations);
sb.append("metaprojectUpdates", metaprojectUpdates);
sb.append("vocabularyUpdates", vocabularyUpdates);
sb.append("spaceRoleAssignments", spaceRoleAssignments);
sb.append("spaceRoleRevocations", spaceRoleRevocations);
appendTo(sb, "registrationIdOrNull", registrationIdOrNull);
appendTo(sb, "userIdOrNull", userIdOrNull);
appendTo(sb, "spaceRegistrations", spaceRegistrations);
appendTo(sb, "projectRegistrations", projectRegistrations);
appendTo(sb, "projectUpdates", projectUpdates);
appendTo(sb, "experimentUpdates", experimentUpdates);
appendTo(sb, "experimentRegistrations", experimentRegistrations);
appendTo(sb, "sampleUpdates", sampleUpdates);
appendTo(sb, "sampleRegistrations", sampleRegistrations);
appendTo(sb, "materialRegistrations", materialRegistrations);
appendTo(sb, "dataSetRegistrations", dataSetRegistrations);
appendTo(sb, "dataSetUpdates", dataSetUpdates);
appendTo(sb, "metaprojectRegistrations", metaprojectRegistrations);
appendTo(sb, "metaprojectUpdates", metaprojectUpdates);
appendTo(sb, "vocabularyUpdates", vocabularyUpdates);
appendTo(sb, "spaceRoleAssignments", spaceRoleAssignments);
appendTo(sb, "spaceRoleRevocations", spaceRoleRevocations);
return sb.toString();
}
private void appendTo(ToStringBuilder builder, String name, Object object)
{
if (object == null)
{
return;
}
if (object instanceof Map<?, ?>)
{
object = ((Map<?, ?>) object).entrySet();
}
if (object instanceof Collection<?> == false)
{
builder.append(name, object);
}
Collection<?> collection = (Collection<?>) object;
if (collection.isEmpty())
{
return;
}
builder.append(name, CollectionUtils.abbreviate(collection, 100));
}
}
......@@ -46,9 +46,12 @@ public class AtomicEntityOperationDetailsTest extends AssertJUnit
@Test
public void testToString()
{
// Given
ArrayList<NewSpace> spaceRegistrations = new ArrayList<NewSpace>();
spaceRegistrations.add(new NewSpace("SPACE1", "description", "adminUser1"));
spaceRegistrations.add(new NewSpace("SPACE2", "description", "adminUser2"));
for (int i = 0; i < 110; i++)
{
spaceRegistrations.add(new NewSpace("S" + i, "description", "adminUser" + i));
}
Map<String, List<NewMaterial>> materialRegistrations =
new HashMap<String, List<NewMaterial>>();
......@@ -111,22 +114,25 @@ public class AtomicEntityOperationDetailsTest extends AssertJUnit
dataSetRegistrations, dataSetUpdates, metaprojectRegistrations,
metaprojectUpdates, vocabularyUpdates);
// When
String detailsAsString = details.toString();
// Then
assertEquals(
"AtomicEntityOperationDetails[registrationIdOrNull=<null>"
+ ",userIdOrNull=<null>"
+ ",spaceRegistrations=[SPACE1, SPACE2]"
"AtomicEntityOperationDetails[spaceRegistrations=[S0, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, "
+ "S12, S13, S14, S15, S16, S17, S18, S19, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29, "
+ "S30, S31, S32, S33, S34, S35, S36, S37, S38, S39, S40, S41, S42, S43, S44, S45, S46, S47, "
+ "S48, S49, S50, S51, S52, S53, S54, S55, S56, S57, S58, S59, S60, S61, S62, S63, S64, S65, "
+ "S66, S67, S68, S69, S70, S71, S72, S73, S74, S75, S76, S77, S78, S79, S80, S81, S82, S83, "
+ "S84, S85, S86, S87, S88, S89, S90, S91, S92, S93, S94, S95, S96, S97, S98, S99, ... (10 left)]"
+ ",projectRegistrations=[/SPACE/P1, /SPACE/P2]"
+ ",projectUpdates=[]"
+ ",experimentUpdates=[]"
+ ",experimentRegistrations=[/SPACE/PROJECT/EXP-ID1, /SPACE/PROJECT/EXP-ID2]"
+ ",sampleUpdates=[]"
+ ",sampleRegistrations=[/SPACE/SAMPLE-ID1, /SPACE/SAMPLE-ID2]"
+ ",materialRegistrations={material-type-1=[material-one, material-two], material-type-2=[material-three]}"
+ ",materialRegistrations=[material-type-1=[material-one, material-two], material-type-2=[material-three]]"
+ ",dataSetRegistrations=[NewExternalData[code=DATA-SET-CODE,type=<null>,kind=<null>,fileFormat=<null>,properties=[]]]"
+ ",dataSetUpdates=[1]"
+ ",metaprojectRegistrations=[NewMetaproject[name=TEST-AEOD-TAG,description=short description,ownerId=test]]"
+ ",metaprojectUpdates=[]" + ",vocabularyUpdates=[]"
+ ",spaceRoleAssignments=[]" + ",spaceRoleRevocations=[]]", details.toString());
+ ",metaprojectRegistrations=[NewMetaproject[name=TEST-AEOD-TAG,description=short description,ownerId=test]]]",
detailsAsString);
}
}
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