Skip to content
Permalink
Browse files

Bug fixes: When submitting a resolution request with an embedded mode…

…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 b45b24a463836f88213984cc1538e29a1e2e1cbc
@@ -20,7 +20,6 @@

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

@@ -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);
}

@@ -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.
*
@@ -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.");
}

@@ -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);

0 comments on commit b45b24a

Please sign in to comment.
You can’t perform that action at this time.