Skip to content

Commit

Permalink
Bug fixes: When submitting a resolution request with an embedded mode…
Browse files Browse the repository at this point in the history
…l and an entity type, raise an error because the request is ambiguous. When submitting a resolution request with an embedded model and no entity type, process the request.
  • Loading branch information
davemoore- committed Jul 18, 2019
1 parent 3fdde88 commit b45b24a
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 188 deletions.
24 changes: 5 additions & 19 deletions src/main/java/io/zentity/resolution/input/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class Input {

private Map<String, Attribute> attributes = new TreeMap<>();
private Map<String, Set<String>> ids = new TreeMap<>();
private String entityType;
private Model model;
private Scope scope = new Scope();

Expand All @@ -34,13 +33,11 @@ public Input(String json, Model model) throws ValidationException, IOException {
this.deserialize(json);
}

public Input(JsonNode json, String entityType) throws ValidationException, IOException {
this.entityType = parseEntityType(entityType);
public Input(JsonNode json) throws ValidationException, IOException {
this.deserialize(json);
}

public Input(String json, String entityType) throws ValidationException, IOException {
this.entityType = parseEntityType(entityType);
public Input(String json) throws ValidationException, IOException {
this.deserialize(json);
}

Expand Down Expand Up @@ -215,17 +212,6 @@ public static Model parseEntityModel(JsonNode requestBody) throws IOException, V
return new Model(model.toString());
}

/**
* Parse and validate the entity type.
*
* @param entityType
*/
private String parseEntityType(String entityType) {
if (entityType == null || Patterns.EMPTY_STRING.matcher(entityType).matches())
return null;
return entityType;
}

/**
* Validate a top-level field of the input.
*
Expand Down Expand Up @@ -293,10 +279,10 @@ public void deserialize(JsonNode json) throws ValidationException, IOException {

// Parse and validate the "model" field of the request body, or the entity model stored in the index.
if (this.model == null) {
if (this.entityType == null || !json.has("model"))
if (!json.has("model"))
throw new ValidationException("You must specify either an entity type or an entity model.");
this.model = parseEntityModel(json.get("model"));
} else if (this.entityType != null) {
this.model = parseEntityModel(json);
} else if (json.has("model")) {
throw new ValidationException("You must specify either an entity type or an entity model, not both.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,14 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
// Parse and validate the job input.
Input input;
if (entityType == null || entityType.equals("")) {
input = new Input(body, entityType);
input = new Input(body);
} else {
GetResponse getResponse = ModelsAction.getEntityModel(entityType, client);
if (!getResponse.isExists())
throw new NotFoundException("Entity type '" + entityType + "' not found.");
String model = getResponse.getSourceAsString();
input = new Input(body, new Model(model));
}
if (input.model() == null)
throw new ValidationException("An entity model was not given for this request.");

// Prepare the entity resolution job.
Job job = new Job(client);
Expand Down
Loading

0 comments on commit b45b24a

Please sign in to comment.