use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.
the class ScanRequestConverter method mergeSampleMetadata.
private void mergeSampleMetadata(ScanRequest scanRequest, IMappingExperimentBean mappingBean) {
List<ScanMetadata> scanMetadata = scanRequest.getScanMetadata();
if (scanMetadata == null)
return;
Optional<ScanMetadata> sampleScanMetadataOpt = scanMetadata.stream().filter(metadata -> metadata.getType() == MetadataType.SAMPLE).findFirst();
if (!sampleScanMetadataOpt.isPresent())
return;
ScanMetadata sampleScanMetadata = sampleScanMetadataOpt.get();
SimpleSampleMetadata sampleMetadata = (SimpleSampleMetadata) mappingBean.getSampleMetadata();
if (sampleMetadata == null) {
sampleMetadata = new SimpleSampleMetadata();
mappingBean.setSampleMetadata(sampleMetadata);
}
sampleMetadata.setSampleName((String) sampleScanMetadata.getFieldValue(FIELD_NAME_SAMPLE_NAME));
sampleMetadata.setDescription((String) sampleScanMetadata.getFieldValue(FIELD_NAME_SAMPLE_DESCRIPTION));
}
use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.
the class SavuProcessingRequestHandlerTest method testSavuProcessingRequest.
@Test
public void testSavuProcessingRequest() throws Exception {
ProcessingRequestHandler handler = new SavuProcessingRequestHandler();
URL file1 = new URL("file:/lev1/lev2");
URL file2 = new URL("file:/lev3/lev4");
List<URL> paths = new ArrayList<>();
paths.add(file1);
paths.add(file2);
SavuProcessingRequest request = new SavuProcessingRequest.Builder().withValue(paths).build();
ScanRequest scanRequest = new ScanRequest();
scanRequest.setProcessingRequest(new ProcessingRequest());
scanRequest.getProcessingRequest().setRequest(new HashMap<>());
handler.handle(request, scanRequest);
Collection<Object> translated = scanRequest.getProcessingRequest().getRequest().get(request.getKey());
Assert.assertEquals(2, translated.size());
Assert.assertTrue(translated.contains(file1.getPath()));
Assert.assertTrue(translated.contains(file2.getPath()));
}
use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.
the class ScanRequestConverterTest method testStageNamesAreSetCorrectly.
@Test
public void testStageNamesAreSetCorrectly() throws Exception {
// Initially the scan path doesn't have the correct axis names
assertThat(scanPath.getxAxisName(), is(not(equalTo(X_AXIS_NAME))));
assertThat(scanPath.getyAxisName(), is(not(equalTo(Y_AXIS_NAME))));
// Act - they're set according to the MappingStageInfo when the mapping bean is
// converted to a scan request
ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
// Assert - the axis names are now set to the names of the stage
assertThat(scanPath.getxAxisName(), is(equalTo(X_AXIS_NAME)));
assertThat(scanPath.getyAxisName(), is(equalTo(Y_AXIS_NAME)));
scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
}
use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.
the class ScanRequestConverterTest method testSampleMetadataSet.
@Test
public void testSampleMetadataSet() throws Exception {
// Arrange
final String sampleName = "testSample";
final String sampleDescription = "This is a description of the test sample.";
mappingBean.getSampleMetadata().setSampleName(sampleName);
mappingBean.getSampleMetadata().setDescription(sampleDescription);
// Act - convert mapping bean to scan request
ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
// Assert
List<ScanMetadata> scanMetadataList = scanRequest.getScanMetadata();
assertEquals(1, scanMetadataList.size());
ScanMetadata scanMetadata = scanMetadataList.get(0);
assertEquals(MetadataType.SAMPLE, scanMetadata.getType());
assertEquals(sampleName, scanMetadata.getFieldValue("name"));
assertEquals(sampleDescription, scanMetadata.getFieldValue("description"));
// Act again - merge scan request back into new mapping bean
scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
// Assert again - check the new mapping bean is the same as the old one
SimpleSampleMetadata sampleMetadata = newMappingBean.getSampleMetadata();
assertEquals(sampleName, sampleMetadata.getSampleName());
assertEquals(sampleDescription, sampleMetadata.getDescription());
}
use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.
the class ScanRequestConverterTest method testProcessingRequestIncludedCorrectly.
@Test
public void testProcessingRequestIncludedCorrectly() throws Exception {
ConfigWrapper wrapper = new ConfigWrapper();
String appName = "test";
String pathToConfig = "/path/to/config";
wrapper.setAppName(appName);
wrapper.setPathToConfig(pathToConfig);
wrapper.setActive(true);
mappingBean.addProcessingRequest(wrapper);
// Act - convert mapping bean to scan request
final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
// Assert
ProcessingRequest processingRequest = scanRequest.getProcessingRequest();
testProcessingRequest(appName, pathToConfig, processingRequest);
// Act again - merge scan request into new mapping bean
scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
// Assert again - check the new mapping bean is the same as the old one
ProcessingRequest r = new ProcessingRequest();
r.setRequest(newMappingBean.getProcessingRequest());
testProcessingRequest(appName, pathToConfig, r);
}
Aggregations