Skip to content
Snippets Groups Projects
Commit aedd412f authored by buczekp's avatar buczekp
Browse files

[LMS-1264] loading permlinks of dependent samples for entity tracking

SVN: 13522
parent 8717828c
No related branches found
No related tags found
No related merge requests found
...@@ -145,6 +145,8 @@ final class SampleListingWorker ...@@ -145,6 +145,8 @@ final class SampleListingWorker
private boolean singleSampleTypeMode; private boolean singleSampleTypeMode;
private boolean enrichDependentSamples;
private int maxSampleParentResolutionDepth; private int maxSampleParentResolutionDepth;
private int maxSampleContainerResolutionDepth; private int maxSampleContainerResolutionDepth;
...@@ -185,6 +187,7 @@ final class SampleListingWorker ...@@ -185,6 +187,7 @@ final class SampleListingWorker
this.databaseInstance = databaseInstance; this.databaseInstance = databaseInstance;
this.query = query; this.query = query;
this.samplePropertiesEnricherOrNull = samplePropertiesEnricherOrNull; this.samplePropertiesEnricherOrNull = samplePropertiesEnricherOrNull;
this.enrichDependentSamples = criteria.isEnrichDependentSamplesWithProperties();
this.referencedEntityDAO = referencedEntityDAO; this.referencedEntityDAO = referencedEntityDAO;
} }
...@@ -216,8 +219,7 @@ final class SampleListingWorker ...@@ -216,8 +219,7 @@ final class SampleListingWorker
watch.reset(); watch.reset();
watch.start(); watch.start();
} }
if (enrichDependentSamples == false)
if (criteria.isEnrichDependentSamplesWithProperties() == false)
{ {
// only 'primary' samples were retrieved up to this point // only 'primary' samples were retrieved up to this point
enrichRetrievedSamplesWithProperties(watch); enrichRetrievedSamplesWithProperties(watch);
...@@ -225,7 +227,7 @@ final class SampleListingWorker ...@@ -225,7 +227,7 @@ final class SampleListingWorker
retrieveDependentSamplesRecursively(); retrieveDependentSamplesRecursively();
resolveParents(); resolveParents();
resolveContainers(); resolveContainers();
if (criteria.isEnrichDependentSamplesWithProperties()) if (enrichDependentSamples)
{ {
// dependent samples will also be enriched // dependent samples will also be enriched
enrichRetrievedSamplesWithProperties(watch); enrichRetrievedSamplesWithProperties(watch);
...@@ -240,12 +242,6 @@ final class SampleListingWorker ...@@ -240,12 +242,6 @@ final class SampleListingWorker
private void enrichRetrievedSamplesWithProperties(StopWatch watch) private void enrichRetrievedSamplesWithProperties(StopWatch watch)
{ {
// Initialize property collections of all samples retrieved up to this point
// (without this enricher will not work properly).
for (Sample sample : sampleMap.values())
{
sample.setProperties(new ArrayList<IEntityProperty>());
}
if (samplePropertiesEnricherOrNull != null) if (samplePropertiesEnricherOrNull != null)
{ {
samplePropertiesEnricherOrNull.enrich(sampleMap.keySet(), samplePropertiesEnricherOrNull.enrich(sampleMap.keySet(),
...@@ -411,9 +407,6 @@ final class SampleListingWorker ...@@ -411,9 +407,6 @@ final class SampleListingWorker
{ {
return null; return null;
} }
// uncomment if we want all dependent samples to be loaded
// maxSampleContainerResolutionDepth = Integer.MAX_VALUE;
// maxSampleParentResolutionDepth = Integer.MAX_VALUE;
Long sampleTypeId = Long sampleTypeId =
referencedEntityDAO.getSampleTypeIdForSampleTypeCode(criteria.getSampleTypeCode()); referencedEntityDAO.getSampleTypeIdForSampleTypeCode(criteria.getSampleTypeCode());
return query.getNewSamplesForSampleType(sampleTypeId, criteria.getLastSeenSampleId()); return query.getNewSamplesForSampleType(sampleTypeId, criteria.getLastSeenSampleId());
...@@ -423,16 +416,16 @@ final class SampleListingWorker ...@@ -423,16 +416,16 @@ final class SampleListingWorker
{ {
assert sampleList != null; assert sampleList != null;
retrieveBasicSamples(sampleIteratorOrNull, baseIndexURL, sampleList); retrieveBasicSamples(sampleIteratorOrNull, sampleList);
} }
private void retrieveDependentBasicSamples(final Iterable<SampleRecord> sampleIteratorOrNull) private void retrieveDependentBasicSamples(final Iterable<SampleRecord> sampleIteratorOrNull)
{ {
retrieveBasicSamples(sampleIteratorOrNull, null, null); retrieveBasicSamples(sampleIteratorOrNull, null);
} }
private void retrieveBasicSamples(final Iterable<SampleRecord> sampleIteratorOrNull, private void retrieveBasicSamples(final Iterable<SampleRecord> sampleIteratorOrNull,
final String baseIndexURLOrNull, final List<Sample> sampleListOrNull) final List<Sample> sampleListOrNull)
{ {
if (sampleIteratorOrNull == null) if (sampleIteratorOrNull == null)
{ {
...@@ -441,7 +434,7 @@ final class SampleListingWorker ...@@ -441,7 +434,7 @@ final class SampleListingWorker
final boolean primarySample = (sampleListOrNull != null); final boolean primarySample = (sampleListOrNull != null);
for (SampleRecord row : sampleIteratorOrNull) for (SampleRecord row : sampleIteratorOrNull)
{ {
final Sample sampleOrNull = tryCreateSample(row, baseIndexURLOrNull, primarySample); final Sample sampleOrNull = tryCreateSample(row, primarySample);
if (sampleOrNull != null) // null == different db instance if (sampleOrNull != null) // null == different db instance
{ {
sampleMap.put(sampleOrNull.getId(), sampleOrNull); sampleMap.put(sampleOrNull.getId(), sampleOrNull);
...@@ -453,8 +446,7 @@ final class SampleListingWorker ...@@ -453,8 +446,7 @@ final class SampleListingWorker
} }
} }
private Sample tryCreateSample(SampleRecord row, final String baseIndexURLOrNull, private Sample tryCreateSample(SampleRecord row, final boolean primarySample)
final boolean primarySample)
{ {
final Sample sample = new Sample(); final Sample sample = new Sample();
sample.setId(row.id); sample.setId(row.id);
...@@ -485,11 +477,14 @@ final class SampleListingWorker ...@@ -485,11 +477,14 @@ final class SampleListingWorker
} }
} }
// set properties needed for primary samples // set properties needed for primary samples
if (primarySample) // (dependent samples too if they need to be enriched e.g. for entity tracking)
if (primarySample || enrichDependentSamples)
{ {
// initializing property collection - without this enricher will not work properly
sample.setProperties(new ArrayList<IEntityProperty>());
sample.setPermId(StringEscapeUtils.escapeHtml(row.perm_id)); sample.setPermId(StringEscapeUtils.escapeHtml(row.perm_id));
sample.setPermlink(PermlinkUtilities.createPermlinkURL(baseIndexURLOrNull, sample.setPermlink(PermlinkUtilities.createPermlinkURL(baseIndexURL, EntityKind.SAMPLE,
EntityKind.SAMPLE, row.perm_id)); row.perm_id));
sample.setRegistrationDate(row.registration_timestamp); sample.setRegistrationDate(row.registration_timestamp);
if (row.inva_id != null) if (row.inva_id != null)
{ {
......
...@@ -176,6 +176,7 @@ public class OpenbisClientTest ...@@ -176,6 +176,7 @@ public class OpenbisClientTest
builder.append(" code", sample.getCode()); builder.append(" code", sample.getCode());
builder.append(" identifier", sample.getIdentifier()); builder.append(" identifier", sample.getIdentifier());
builder.append(" type", sample.getSampleType()); builder.append(" type", sample.getSampleType());
builder.append(" permlink", sample.getPermlink());
builder.append(" properties", toString(sample.getProperties())); builder.append(" properties", toString(sample.getProperties()));
sb.append(builder.toString()); sb.append(builder.toString());
final String newIndent = indent + INDENT; final String newIndent = indent + INDENT;
...@@ -200,6 +201,7 @@ public class OpenbisClientTest ...@@ -200,6 +201,7 @@ public class OpenbisClientTest
builder.append("id", dataSet.getId()); builder.append("id", dataSet.getId());
builder.append(" code", dataSet.getCode()); builder.append(" code", dataSet.getCode());
builder.append(" type", dataSet.getDataSetType()); builder.append(" type", dataSet.getDataSetType());
builder.append(" permlink", dataSet.getPermlink());
builder.append(" properties", toString(dataSet.getProperties())); builder.append(" properties", toString(dataSet.getProperties()));
sb.append(builder.toString()); sb.append(builder.toString());
if (dataSet.getSample() != null) if (dataSet.getSample() != null)
......
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