use of org.eclipse.scanning.api.scan.models.ScanMetadata in project gda-core by openGDA.
the class XanesSubmitScanSection method submitScan.
@Override
protected void submitScan() {
final IScriptService scriptService = getService(IScriptService.class);
final ScanRequest scanRequest = getScanRequest(getMappingBean());
final XanesEdgeParametersSection paramsSection = getMappingView().getSection(XanesEdgeParametersSection.class);
final XanesEdgeParameters xanesEdgeParameters = paramsSection.getScanParameters();
if (xanesEdgeParameters.isEnforcedShape()) {
final CompoundModel newModel = new CompoundModel(scanRequest.getCompoundModel());
final List<IScanPointGeneratorModel> models = newModel.getModels();
final List<IScanPointGeneratorModel> enforcedShapes = new ArrayList<>(models.size());
for (IScanPointGeneratorModel model : models) {
enforcedShapes.add(enforce(model));
}
newModel.setModels(enforcedShapes);
scanRequest.setCompoundModel(newModel);
}
xanesEdgeParameters.setVisitId(InterfaceProvider.getBatonStateProvider().getBatonHolder().getVisitID());
// Add XANES parameters as metadata to the ScanRequest, so they appear in the Nexus file
final ScanMetadata xanesMetadata = new ScanMetadata(MetadataType.ENTRY);
xanesMetadata.addField("tracking_method", xanesEdgeParameters.getTrackingMethod());
xanesMetadata.addField("visit_id", xanesEdgeParameters.getVisitId());
final LinesToTrackEntry linesToTrackEntry = xanesEdgeParameters.getLinesToTrack();
if (linesToTrackEntry == null || linesToTrackEntry.getLine() == null || linesToTrackEntry.getLine().isEmpty()) {
// The entry for a blank "lines to track" contains an unmodifiable Collection, which causes problems in
// marshalling, so make sure it is set null.
xanesEdgeParameters.setLinesToTrack(null);
xanesMetadata.addField("line", "None");
} else {
xanesMetadata.addField("line", linesToTrackEntry.getLine());
xanesMetadata.addField("file_paths", new ArrayList<String>(linesToTrackEntry.getFilePaths()));
}
final List<ScanMetadata> scanMetadata = new ArrayList<>(scanRequest.getScanMetadata());
scanMetadata.add(xanesMetadata);
scanRequest.setScanMetadata(scanMetadata);
try {
final IMarshallerService marshallerService = getService(IMarshallerService.class);
scriptService.setNamedValue(VAR_NAME_SCAN_REQUEST_JSON, marshallerService.marshal(scanRequest));
scriptService.setNamedValue(VAR_NAME_XANES_EDGE_PARAMS_JSON, marshallerService.marshal(xanesEdgeParameters));
} catch (Exception e) {
logger.error("Scan submission failed", e);
MessageDialog.openError(getShell(), "Error Submitting Scan", "The scan could not be submitted. See the error log for more details.");
return;
}
Async.execute(() -> runScript(scriptFilePath, "XANES scanning script"));
}
use of org.eclipse.scanning.api.scan.models.ScanMetadata 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.scan.models.ScanMetadata in project gda-core by openGDA.
the class ScanManagementController method setSampleMetadata.
/**
* This method clones a similar one present in {@link ScanRequestConverter#convertToScanRequest}.
* The reason is to mitigate the replacement of the {@link MetadataController} properties so that
* can be again written as {@link ScanMetadata}
*
* @param scanRequest
* @param sampleName
*/
private void setSampleMetadata(ScanRequest scanRequest, String sampleName) {
final ScanMetadata scanMetadata = new ScanMetadata(MetadataType.SAMPLE);
scanMetadata.addField(ScanRequestConverter.FIELD_NAME_SAMPLE_NAME, sampleName);
scanRequest.setScanMetadata(Arrays.asList(scanMetadata));
}
use of org.eclipse.scanning.api.scan.models.ScanMetadata 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.scan.models.ScanMetadata in project gda-core by openGDA.
the class ScanRequestConverter method setSampleMetadata.
private void setSampleMetadata(IMappingExperimentBean mappingBean, ScanRequest scanRequest) {
final ISampleMetadata sampleMetadata = mappingBean.getSampleMetadata();
String sampleName = sampleMetadata.getSampleName();
if (sampleName == null || sampleName.trim().isEmpty()) {
sampleName = "Unnamed Sample";
}
final ScanMetadata scanMetadata = new ScanMetadata(MetadataType.SAMPLE);
scanMetadata.addField(FIELD_NAME_SAMPLE_NAME, sampleName);
if (sampleMetadata instanceof SimpleSampleMetadata) {
String description = ((SimpleSampleMetadata) sampleMetadata).getDescription();
if (description == null || description.trim().isEmpty()) {
description = "No description provided.";
}
scanMetadata.addField(FIELD_NAME_SAMPLE_DESCRIPTION, description);
}
scanRequest.setScanMetadata(Arrays.asList(scanMetadata));
}
Aggregations