Skip to content
Snippets Groups Projects
Commit 6f8ff1a8 authored by anttil's avatar anttil
Browse files

SSDM-4959: Fix a problem with fetch options

SVN: 38240
parent 2f19ba18
No related branches found
No related tags found
No related merge requests found
......@@ -71,25 +71,28 @@ public class LinkedDataTranslator extends AbstractCachingTranslator<Long, Linked
result.setContentCopies(copyList);
String externalCode = "";
ExternalDms externalDms = null;
for (ContentCopy copy : copyList)
if (fetchOptions.hasExternalDms())
{
ExternalDmsAddressType type = copy.getExternalDms().getAddressType();
if (type.equals(ExternalDmsAddressType.OPENBIS) || type.equals(ExternalDmsAddressType.URL))
ExternalDms externalDms = null;
for (ContentCopy copy : copyList)
{
ExternalDmsAddressType type = copy.getExternalDms().getAddressType();
if (type.equals(ExternalDmsAddressType.OPENBIS) || type.equals(ExternalDmsAddressType.URL))
{
externalCode = copy.getExternalCode();
externalDms = copy.getExternalDms();
break;
}
}
if (externalDms != null)
{
externalCode = copy.getExternalCode();
externalDms = copy.getExternalDms();
break;
result.setExternalDms(externalDms);
result.getFetchOptions().withExternalDmsUsing(fetchOptions.withExternalDms());
}
}
result.setExternalCode(externalCode);
if (fetchOptions.hasExternalDms() || externalDms != null)
{
result.setExternalDms(externalDms);
result.getFetchOptions().withExternalDmsUsing(fetchOptions.withExternalDms());
}
}
}
package ch.ethz.sis.openbis.systemtest.asapi.v3;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import org.testng.annotations.Test;
......@@ -90,9 +92,76 @@ public class SearchLinkDataSetTest extends AbstractLinkDataSetTest
assertThat(result.getObjects().get(0).getCode(), is("20120628092259000-41"));
}
private SearchResult<DataSet> searchWith(DataSetSearchCriteria criteria)
@Test
void testFetchOptionsWithLinkedData()
{
DataSetSearchCriteria dc = new DataSetSearchCriteria();
dc.withLinkedData().withCopy().withPath().thatContains("to");
DataSetFetchOptions fetchOptions = new DataSetFetchOptions();
fetchOptions.withLinkedData();
SearchResult<DataSet> result = searchWith(dc, fetchOptions);
assertThat(result.getTotalCount(), is(1));
DataSet dataSet = result.getObjects().get(0);
assertThat(dataSet.getCode(), is("20120628092259000-41"));
assertThat(dataSet.getLinkedData().getContentCopies().get(0).getExternalDms(), is(nullValue()));
assertThat(dataSet.getLinkedData().getExternalDms(), is(nullValue()));
}
@Test
void testFetchOptionsWithExternalDms()
{
DataSetSearchCriteria dc = new DataSetSearchCriteria();
dc.withLinkedData().withCopy().withPath().thatContains("to");
DataSetFetchOptions fetchOptions = new DataSetFetchOptions();
fetchOptions.withLinkedData().withExternalDms();
SearchResult<DataSet> result = searchWith(dc, fetchOptions);
assertThat(result.getTotalCount(), is(1));
DataSet dataSet = result.getObjects().get(0);
assertThat(result.getObjects().get(0).getCode(), is("20120628092259000-41"));
assertThat(dataSet.getLinkedData().getContentCopies().get(0).getExternalDms(), is(not(nullValue())));
// should be null with this dataset, as it is on file system (this is a legacy method)
assertThat(dataSet.getLinkedData().getExternalDms(), is(nullValue()));
}
@Test(enabled = false)
void searchAllLinkDataSetsThatHaveAtLeastOneCopy()
{
DataSetSearchCriteria dc = new DataSetSearchCriteria();
dc.withLinkedData().withCopy();
SearchResult<DataSet> result = searchWith(dc);
assertThat(result.getTotalCount(), is(3));
}
@Test(enabled = false)
void searchAllLinkDataSets()
{
DataSetSearchCriteria dc = new DataSetSearchCriteria();
dc.withLinkedData();
SearchResult<DataSet> result = searchWith(dc);
assertThat(result.getTotalCount(), is(3));
}
private SearchResult<DataSet> searchWith(DataSetSearchCriteria criteria)
{
return searchWith(criteria, new DataSetFetchOptions());
}
private SearchResult<DataSet> searchWith(DataSetSearchCriteria criteria, DataSetFetchOptions fetchOptions)
{
return v3api.searchDataSets(session, criteria, fetchOptions);
}
}
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