Skip to content

Commit

Permalink
Merge pull request #70 from geneontology/user-groups
Browse files Browse the repository at this point in the history
Implemented support for 'provided-by' annotation (user groups).
  • Loading branch information
kltm committed Nov 1, 2016
2 parents d63e8e1 + 5cd7908 commit 198e2ed
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum AnnotationShorthand {
// DC recommends http://www.w3.org/TR/NOTE-datetime, one example format is YYYY-MM-DD
source(IRI.create("http://purl.org/dc/elements/1.1/source")), // arbitrary string, such as PMID:000000
contributor(IRI.create("http://purl.org/dc/elements/1.1/contributor")), // who contributed to the annotation
providedBy(IRI.create("http://purl.org/pav/providedBy")), // organization supporting the annotation
title(IRI.create("http://purl.org/dc/elements/1.1/title")), // title (of the model)
deprecated(OWLRDFVocabulary.OWL_DEPRECATED.getIRI()), // model annotation to indicate deprecated models
templatestate(IRI.create("http://geneontology.org/lego/templatestate"), "template"), // designate a model as a template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -69,25 +70,25 @@ boolean validateBeforeSave() {
@Override
@JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE)
public M3BatchResponse m3BatchGet(String intention, String packetId, String requestString, String useReasoner) {
return m3Batch(null, intention, packetId, requestString, useReasoner, false);
return m3Batch(null, Collections.emptySet(), intention, packetId, requestString, useReasoner, false);
}

@Override
@JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE)
public M3BatchResponse m3BatchGetPrivileged(String uid, String intention, String packetId, String requestString, String useReasoner) {
return m3Batch(uid, intention, packetId, requestString, useReasoner, true);
public M3BatchResponse m3BatchGetPrivileged(String uid, Set<String> providerGroups, String intention, String packetId, String requestString, String useReasoner) {
return m3Batch(uid, providerGroups, intention, packetId, requestString, useReasoner, true);
}

@Override
@JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE)
public M3BatchResponse m3BatchPost(String intention, String packetId, String requestString, String useReasoner) {
return m3Batch(null, intention, packetId, requestString, useReasoner, false);
return m3Batch(null, Collections.emptySet(), intention, packetId, requestString, useReasoner, false);
}

@Override
@JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE)
public M3BatchResponse m3BatchPostPrivileged(String uid, String intention, String packetId, String requestString, String useReasoner) {
return m3Batch(uid, intention, packetId, requestString, useReasoner, true);
public M3BatchResponse m3BatchPostPrivileged(String uid, Set<String> providerGroups, String intention, String packetId, String requestString, String useReasoner) {
return m3Batch(uid, providerGroups, intention, packetId, requestString, useReasoner, true);
}

private static String checkPacketId(String packetId) {
Expand All @@ -98,13 +99,13 @@ private static String checkPacketId(String packetId) {
}

@Override
public M3BatchResponse m3Batch(String uid, String intention, String packetId, M3Request[] requests, boolean useReasoner, boolean isPrivileged) {
M3BatchResponse response = new M3BatchResponse(uid, intention, checkPacketId(packetId));
public M3BatchResponse m3Batch(String uid, Set<String> providerGroups, String intention, String packetId, M3Request[] requests, boolean useReasoner, boolean isPrivileged) {
M3BatchResponse response = new M3BatchResponse(uid, providerGroups, intention, checkPacketId(packetId));
if (requests == null) {
return error(response, "The batch contains no requests: null value for request array", null);
}
try {
return m3Batch(response, requests, uid, useReasoner, isPrivileged);
return m3Batch(response, requests, uid, providerGroups, useReasoner, isPrivileged);
} catch (InsufficientPermissionsException e) {
return error(response, e.getMessage(), null);
} catch (Exception e) {
Expand All @@ -115,20 +116,20 @@ public M3BatchResponse m3Batch(String uid, String intention, String packetId, M3
}
}

private M3BatchResponse m3Batch(String uid, String intention, String packetId, String requestString, String useReasonerString, boolean isPrivileged) {
private M3BatchResponse m3Batch(String uid, Set<String> providerGroups, String intention, String packetId, String requestString, String useReasonerString, boolean isPrivileged) {
boolean useReasoner = false;
if (inferenceProviderCreator != null) {
useReasonerString = StringUtils.trimToNull(useReasonerString);
useReasoner = "true".equalsIgnoreCase(useReasonerString);
}
M3BatchResponse response = new M3BatchResponse(uid, intention, checkPacketId(packetId));
M3BatchResponse response = new M3BatchResponse(uid, providerGroups, intention, checkPacketId(packetId));
requestString = StringUtils.trimToNull(requestString);
if (requestString == null) {
return error(response, "The batch contains no requests: null value for request", null);
}
try {
M3Request[] requests = MolecularModelJsonRenderer.parseFromJson(requestString, requestType);
return m3Batch(response, requests, uid, useReasoner, isPrivileged);
return m3Batch(response, requests, uid, providerGroups, useReasoner, isPrivileged);
} catch (Exception e) {
return error(response, "Could not successfully handle batch request.", e);
} catch (Throwable t) {
Expand All @@ -137,7 +138,7 @@ private M3BatchResponse m3Batch(String uid, String intention, String packetId, S
}
}

private M3BatchResponse m3Batch(M3BatchResponse response, M3Request[] requests, String userId, boolean useReasoner, boolean isPrivileged) throws InsufficientPermissionsException, Exception {
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);

Expand All @@ -152,21 +153,21 @@ private M3BatchResponse m3Batch(M3BatchResponse response, M3Request[] requests,

// individual
if (Entity.individual == entity) {
String error = handleRequestForIndividual(request, operation, userId, token, values);
String error = handleRequestForIndividual(request, operation, userId, providerGroups, token, values);
if (error != null) {
return error(response, error, null);
}
}
// edge
else if (Entity.edge == entity) {
String error = handleRequestForEdge(request, operation, userId, token, values);
String error = handleRequestForEdge(request, operation, userId, providerGroups, token, values);
if (error != null) {
return error(response, error, null);
}
}
//model
else if (Entity.model == entity) {
String error = handleRequestForModel(request, response, operation, userId, token, values);
String error = handleRequestForModel(request, response, operation, userId, providerGroups, token, values);
if (error != null) {
return error(response, error, null);
}
Expand All @@ -178,7 +179,7 @@ else if (Entity.meta == entity) {
// 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);
getMeta(response, userId, providerGroups);
} else if (Operation.exportAll == operation) {
exportAllModels();
response.message = "Dumped all models to folder";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ public JsonOrJsonpSeedHandler(UndoAwareMolecularModelManager m3, String defaultM
@JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE)
public SeedResponse fromProcessPost(String intention, String packetId, String requestString) {
// only privileged calls are allowed
SeedResponse response = new SeedResponse(null, intention, packetId);
SeedResponse response = new SeedResponse(null, Collections.emptySet(), intention, packetId);
return error(response, "Insufficient permissions for seed operation.", null);
}

@Override
@JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE)
public SeedResponse fromProcessPostPrivileged(String uid, String intention, String packetId, String requestString) {
return fromProcess(uid, intention, checkPacketId(packetId), requestString);
public SeedResponse fromProcessPostPrivileged(String uid, Set<String> providerGroups, String intention, String packetId, String requestString) {
return fromProcess(uid, providerGroups, intention, checkPacketId(packetId), requestString);
}

@Override
@JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE)
public SeedResponse fromProcessGet(String intention, String packetId, String requestString) {
// only privileged calls are allowed
SeedResponse response = new SeedResponse(null, intention, packetId);
SeedResponse response = new SeedResponse(null, Collections.emptySet(), intention, packetId);
return error(response, "Insufficient permissions for seed operation.", null);
}

@Override
@JSONP(callback = JSONP_DEFAULT_CALLBACK, queryParam = JSONP_DEFAULT_OVERWRITE)
public SeedResponse fromProcessGetPrivileged(String uid, String intention, String packetId, String requestString) {
return fromProcess(uid, intention, checkPacketId(packetId), requestString);
public SeedResponse fromProcessGetPrivileged(String uid, Set<String> providerGroups, String intention, String packetId, String requestString) {
return fromProcess(uid, providerGroups, intention, checkPacketId(packetId), requestString);
}

private static String checkPacketId(String packetId) {
Expand All @@ -93,8 +93,8 @@ private static String checkPacketId(String packetId) {
return packetId;
}

private SeedResponse fromProcess(String uid, String intention, String packetId, String requestString) {
SeedResponse response = new SeedResponse(uid, intention, packetId);
private SeedResponse fromProcess(String uid, Set<String> providerGroups, String intention, String packetId, String requestString) {
SeedResponse response = new SeedResponse(uid, providerGroups, intention, packetId);
ModelContainer model = null;
try {
requestString = StringUtils.trimToNull(requestString);
Expand All @@ -106,8 +106,8 @@ private SeedResponse fromProcess(String uid, String intention, String packetId,
}
uid = normalizeUserId(uid);
UndoMetadata token = new UndoMetadata(uid);
model = createModel(uid, token, VariableResolver.EMPTY, null);
return seedFromProcess(uid, request[0].arguments, model, response, token);
model = createModel(uid, providerGroups, token, VariableResolver.EMPTY, null);
return seedFromProcess(uid, providerGroups, request[0].arguments, model, response, token);
} catch (Exception e) {
deleteModel(model);
return error(response, "Could not successfully handle batch request.", e);
Expand All @@ -118,7 +118,7 @@ private SeedResponse fromProcess(String uid, String intention, String packetId,
}
}

private SeedResponse seedFromProcess(String uid, SeedRequestArgument request, ModelContainer model, SeedResponse response, UndoMetadata token) throws Exception {
private SeedResponse seedFromProcess(String uid, Set<String> providerGroups, SeedRequestArgument request, ModelContainer model, SeedResponse response, UndoMetadata token) throws Exception {
// check required fields
requireNotNull(request.process, "A process id is required for seeding");
requireNotNull(request.taxon, "A taxon id is required for seeding");
Expand Down Expand Up @@ -151,7 +151,7 @@ protected void logRequest(URI uri) {

};
Set<OWLAnnotation> defaultAnnotations = new HashSet<OWLAnnotation>();
addGeneratedAnnotations(uid, defaultAnnotations, model.getOWLDataFactory());
addGeneratedAnnotations(uid, providerGroups, defaultAnnotations, model.getOWLDataFactory());
addDateAnnotation(defaultAnnotations, model.getOWLDataFactory());
ModelSeeding<UndoMetadata> seeder = new ModelSeeding<UndoMetadata>(reasoner, provider, defaultAnnotations, curieHandler, ecoMapper);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
Expand Down Expand Up @@ -144,8 +145,8 @@ public static class MetaResponse {
* @param intention
* @param packetId
*/
public M3BatchResponse(String uid, String intention, String packetId) {
super(uid, intention, packetId);
public M3BatchResponse(String uid, Set<String> providerGroups, String intention, String packetId) {
super(uid, providerGroups, intention, packetId);
}

}
Expand All @@ -162,7 +163,7 @@ public M3BatchResponse(String uid, String intention, String packetId) {
* @param isPrivileged true, if the access is privileged
* @return response object, never null
*/
public M3BatchResponse m3Batch(String uid, String intention, String packetId, M3Request[] requests, boolean useReasoner, boolean isPrivileged);
public M3BatchResponse m3Batch(String uid, Set<String> providerGroups, String intention, String packetId, M3Request[] requests, boolean useReasoner, boolean isPrivileged);

/**
* Jersey REST method for POST with three form parameters.
Expand All @@ -186,6 +187,7 @@ public M3BatchResponse m3BatchPost(
* Jersey REST method for POST with three form parameters with privileged rights.
*
* @param uid user id, JSONP relevant
* @param providerGroups user groups, JSONP relevant
* @param intention JSONP relevant
* @param packetId
* @param requests JSON string of the batch request
Expand All @@ -197,6 +199,7 @@ public M3BatchResponse m3BatchPost(
@Consumes("application/x-www-form-urlencoded")
public M3BatchResponse m3BatchPostPrivileged(
@FormParam("uid") String uid,
@FormParam("provided-by") Set<String> providerGroups,
@FormParam("intention") String intention,
@FormParam("packet-id") String packetId,
@FormParam("requests") String requests,
Expand All @@ -223,6 +226,7 @@ public M3BatchResponse m3BatchGet(
* Jersey REST method for GET with three query parameters with privileged rights.
*
* @param uid user id, JSONP relevant
* @param providerGroups user groups, JSONP relevant
* @param intention JSONP relevant
* @param packetId
* @param requests JSON string of the batch request
Expand All @@ -233,6 +237,7 @@ public M3BatchResponse m3BatchGet(
@GET
public M3BatchResponse m3BatchGetPrivileged(
@QueryParam("uid") String uid,
@QueryParam("provided-by") Set<String> providerGroups,
@QueryParam("intention") String intention,
@QueryParam("packet-id") String packetId,
@QueryParam("requests") String requests,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.geneontology.minerva.server.handler;

import java.util.Set;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
Expand Down Expand Up @@ -53,8 +55,8 @@ public static class SeedResponseData {
* @param intention
* @param packetId
*/
public SeedResponse(String uid, String intention, String packetId) {
super(uid, intention, packetId);
public SeedResponse(String uid, Set<String> providerGroups, String intention, String packetId) {
super(uid, providerGroups, intention, packetId);
}
}

Expand All @@ -78,6 +80,7 @@ public SeedResponse fromProcessPost(
* Jersey REST method for POST with three form parameters with privileged rights.
*
* @param uid user id, JSONP relevant
* @param providerGroups user groups, JSONP relevant
* @param intention JSONP relevant
* @param packetId
* @param requestString seed request
Expand All @@ -88,6 +91,7 @@ public SeedResponse fromProcessPost(
@Consumes("application/x-www-form-urlencoded")
public SeedResponse fromProcessPostPrivileged(
@FormParam("uid") String uid,
@FormParam("provided-by") Set<String> providerGroups,
@FormParam("intention") String intention,
@FormParam("packet-id") String packetId,
@FormParam("requests") String requestString);
Expand All @@ -112,6 +116,7 @@ public SeedResponse fromProcessGet(
* Jersey REST method for GET with three query parameters with privileged rights.
*
* @param uid user id, JSONP relevant
* @param providerGroups user groups, JSONP relevant
* @param intention JSONP relevant
* @param packetId
* @param requestString seed request
Expand All @@ -121,6 +126,7 @@ public SeedResponse fromProcessGet(
@GET
public SeedResponse fromProcessGetPrivileged(
@QueryParam("uid") String uid,
@QueryParam("provided-by") Set<String> providerGroups,
@QueryParam("intention") String intention,
@QueryParam("packet-id") String packetId,
@QueryParam("requests") String requestString);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package org.geneontology.minerva.server.handler;

import java.util.Collections;
import java.util.Set;

import com.google.gson.annotations.SerializedName;

public abstract class MinervaResponse<DATA> {

@SerializedName("packet-id")
final String packetId; // generated or pass-through
final String uid; // pass-through
@SerializedName("provided-by")
final Set<String> providerGroups; // pass-through

@SerializedName("is-reasoned")
boolean isReasoned = false;
Expand Down Expand Up @@ -49,8 +54,13 @@ public abstract class MinervaResponse<DATA> {
* @param intention
* @param packetId
*/
public MinervaResponse(String uid, String intention, String packetId) {
public MinervaResponse(String uid, Set<String> providerGroups, String intention, String packetId) {
this.uid = uid;
if (providerGroups != null) {
this.providerGroups = providerGroups;
} else {
this.providerGroups = Collections.emptySet();
}
this.intention = intention;
this.packetId = packetId;
}
Expand Down
Loading

0 comments on commit 198e2ed

Please sign in to comment.