use of org.geneontology.minerva.server.handler.M3BatchHandler.M3BatchResponse.ResponseData in project minerva by geneontology.
the class JsonOrJsonpBatchHandler method m3Batch.
private M3BatchResponse m3Batch(M3BatchResponse response, M3Request[] requests, String userId, Set<String> providerGroups, boolean useReasoner, boolean isPrivileged) throws InsufficientPermissionsException, Exception {
userId = normalizeUserId(userId);
UndoMetadata token = new UndoMetadata(userId);
final BatchHandlerValues values = new BatchHandlerValues();
for (M3Request request : requests) {
requireNotNull(request, "request");
requireNotNull(request.entity, "entity");
requireNotNull(request.operation, "operation");
final Entity entity = request.entity;
final Operation operation = request.operation;
checkPermissions(entity, operation, isPrivileged);
// individual
if (Entity.individual == entity) {
String error = handleRequestForIndividual(request, operation, userId, providerGroups, token, values);
if (error != null) {
return error(response, error, null);
}
} else // edge
if (Entity.edge == entity) {
String error = handleRequestForEdge(request, operation, userId, providerGroups, token, values);
if (error != null) {
return error(response, error, null);
}
} else // model
if (Entity.model == entity) {
String error = handleRequestForModel(request, response, operation, userId, providerGroups, token, values);
if (error != null) {
return error(response, error, null);
}
} else // meta (e.g. relations, model ids, evidence)
if (Entity.meta == entity) {
if (Operation.get == operation) {
if (values.nonMeta) {
// can only be used with other "meta" operations in batch mode, otherwise it would lead to conflicts in the returned signal
return error(response, "Get meta entity can only be combined with other meta operations.", null);
}
getMeta(response, userId, providerGroups);
} else if (Operation.exportAll == operation) {
exportAllModels();
response.messageType = "success";
response.signal = "meta";
response.message = "Dumped all models to folder";
return response;
} else if (Operation.sparql == operation) {
handleSPARQLRequest(request, response);
} else {
return error(response, "Unknown operation: " + operation, null);
}
} else {
return error(response, "Unknown entity: " + entity, null);
}
}
if (M3BatchResponse.SIGNAL_META.equals(response.signal)) {
return response;
}
if (values.model == null) {
return error(response, "Empty batch calls are not supported, at least one request is required.", null);
}
// update reasoner
// report state
InferenceProvider inferenceProvider = null;
boolean isConsistent = true;
boolean isConformant = true;
if (inferenceProviderCreator != null && useReasoner) {
inferenceProvider = inferenceProviderCreator.create(values.model);
isConsistent = inferenceProvider.isConsistent();
response.setReasoned(true);
// to ensure that all individuals are in the response
values.renderBulk = true;
org.geneontology.minerva.validation.ValidationResultSet validations = inferenceProvider.getValidation_results();
isConformant = validations.allConformant();
}
// create response.data
response.data = new ResponseData();
// final MolecularModelJsonRenderer renderer = createModelRenderer(values.model, externalLookupService, inferenceProvider, curieHandler);
// working towards zero use of external look up service.. which is both slow and confusing.
final MolecularModelJsonRenderer renderer = createModelRenderer(values.model, m3.getGolego_repo(), inferenceProvider, curieHandler);
if (values.renderBulk) {
// render complete model
JsonModel jsonModel = renderer.renderModel();
initResponseData(jsonModel, response.data);
response.signal = M3BatchResponse.SIGNAL_REBUILD;
} else {
response.signal = M3BatchResponse.SIGNAL_MERGE;
// render individuals
if (values.relevantIndividuals.isEmpty() == false) {
Pair<JsonOwlIndividual[], JsonOwlFact[]> pair = renderer.renderIndividuals(values.relevantIndividuals);
response.data.individuals = pair.getLeft();
response.data.facts = pair.getRight();
}
// add model annotations
response.data.annotations = MolecularModelJsonRenderer.renderModelAnnotations(values.model.getAboxOntology(), curieHandler);
response.data.modelId = curieHandler.getCuri(values.model.getModelId());
}
// add other infos to data
if (!isConsistent) {
response.data.inconsistentFlag = Boolean.TRUE;
}
if (!isConformant) {
response.data.validation_results = inferenceProvider.getValidation_results();
}
response.data.diffResult = values.diffResult;
response.data.modifiedFlag = Boolean.valueOf(values.model.isModified());
// These are required for an "okay" response.
response.messageType = M3BatchResponse.MESSAGE_TYPE_SUCCESS;
if (response.message == null) {
response.message = "success";
}
return response;
}
use of org.geneontology.minerva.server.handler.M3BatchHandler.M3BatchResponse.ResponseData in project minerva by geneontology.
the class OperationsImpl method initMetaResponse.
private void initMetaResponse(M3BatchResponse response) {
if (response.data == null) {
response.data = new ResponseData();
response.messageType = M3BatchResponse.MESSAGE_TYPE_SUCCESS;
response.message = "success: 0";
response.signal = M3BatchResponse.SIGNAL_META;
}
}
Aggregations