use of io.irontest.models.propertyextractor.PropertyExtractionResult in project irontest by zheng-wang.
the class PropertyExtractorResource method extract.
/**
* This is a stateless operation, i.e. not persisting anything in database.
* @param propertyExtractionRequest
* @return
*/
@POST
@Path("propertyExtractors/{propertyExtractorId}/extract")
@PermitAll
public PropertyExtractionResult extract(PropertyExtractionRequest propertyExtractionRequest) throws IOException {
PropertyExtractor propertyExtractor = propertyExtractionRequest.getPropertyExtractor();
// gather referenceable string properties
long testcaseId = propertyExtractorDAO.findTestcaseIdById(propertyExtractor.getId());
List<UserDefinedProperty> testcaseUDPs = udpDAO.findByTestcaseId(testcaseId);
Map<String, String> referenceableStringProperties = IronTestUtils.udpListToMap(testcaseUDPs);
Set<String> udpNames = referenceableStringProperties.keySet();
DataTable dataTable = dataTableDAO.getTestcaseDataTable(testcaseId, true);
if (dataTable.getRows().size() > 0) {
IronTestUtils.checkDuplicatePropertyNameBetweenDataTableAndUPDs(udpNames, dataTable);
referenceableStringProperties.putAll(dataTable.getStringPropertiesInRow(0));
}
PropertyExtractorRunner propertyExtractorRunner = PropertyExtractorRunnerFactory.getInstance().create(propertyExtractor, referenceableStringProperties);
String propertyExtractionInput = propertyExtractionRequest.getInput();
PropertyExtractionResult result = new PropertyExtractionResult();
try {
result.setPropertyValue(propertyExtractorRunner.extract(propertyExtractionInput));
} catch (Exception e) {
LOGGER.error("Failed to extract property", e);
result.setError(e.getMessage());
}
return result;
}
Aggregations