Search in sources :

Example 1 with PropertyExtractionResult

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;
}
Also used : DataTable(io.irontest.models.DataTable) UserDefinedProperty(io.irontest.models.UserDefinedProperty) PropertyExtractor(io.irontest.models.propertyextractor.PropertyExtractor) PropertyExtractorRunner(io.irontest.core.propertyextractor.PropertyExtractorRunner) IOException(java.io.IOException) PropertyExtractionResult(io.irontest.models.propertyextractor.PropertyExtractionResult) PermitAll(javax.annotation.security.PermitAll)

Aggregations

PropertyExtractorRunner (io.irontest.core.propertyextractor.PropertyExtractorRunner)1 DataTable (io.irontest.models.DataTable)1 UserDefinedProperty (io.irontest.models.UserDefinedProperty)1 PropertyExtractionResult (io.irontest.models.propertyextractor.PropertyExtractionResult)1 PropertyExtractor (io.irontest.models.propertyextractor.PropertyExtractor)1 IOException (java.io.IOException)1 PermitAll (javax.annotation.security.PermitAll)1