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());
}
Aggregations