Search in sources :

Example 1 with ExternalUploadResult

use of com.bakdata.conquery.apiv1.query.ExternalUploadResult in project conquery by bakdata.

the class QueryProcessor method uploadEntities.

/**
 * Try to resolve the external upload, if successful, create query for the subject and return id and statistics for that.
 */
public ExternalUploadResult uploadEntities(Subject subject, Dataset dataset, ExternalUpload upload) {
    final CQExternal.ResolveStatistic statistic = CQExternal.resolveEntities(upload.getValues(), upload.getFormat(), datasetRegistry.get(dataset.getId()).getStorage().getIdMapping(), config.getFrontend().getQueryUpload(), config.getLocale().getDateReader());
    // Resolving nothing is a problem thus we fail.
    if (statistic.getResolved().isEmpty()) {
        throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(new ExternalUploadResult(null, 0, statistic.getUnresolvedId(), statistic.getUnreadableDate())).build());
    }
    final ConceptQuery query = new ConceptQuery(new CQExternal(upload.getFormat(), upload.getValues()));
    // We only create the Query, really no need to execute it as it's only useful for composition.
    final ManagedQuery execution = ((ManagedQuery) datasetRegistry.get(dataset.getId()).getExecutionManager().createExecution(datasetRegistry, query, subject.getUser(), dataset));
    execution.setLastResultCount((long) statistic.getResolved().size());
    if (upload.getLabel() != null) {
        execution.setLabel(upload.getLabel());
    }
    execution.initExecutable(datasetRegistry, config);
    return new ExternalUploadResult(execution.getId(), statistic.getResolved().size(), statistic.getUnresolvedId(), statistic.getUnreadableDate());
}
Also used : ExternalUploadResult(com.bakdata.conquery.apiv1.query.ExternalUploadResult) BadRequestException(javax.ws.rs.BadRequestException) CQExternal(com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery)

Aggregations

ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)1 ExternalUploadResult (com.bakdata.conquery.apiv1.query.ExternalUploadResult)1 CQExternal (com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal)1 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)1 BadRequestException (javax.ws.rs.BadRequestException)1