Skip to content

Commit

Permalink
INSIGHT-1098: attaching corpus correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Nechaev committed May 27, 2021
1 parent 7907244 commit b35b9c5
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
*/
public class ExportCaller implements Resource {

public static final String CORPUS_PARAM = "corpus";

private final Logger log = LogManager.getLogger(ExportCaller.class);

private final InsightClient client;
Expand Down Expand Up @@ -82,7 +80,7 @@ public <T> T call(Map<String, Serializable> parameters, Serializable payload)
case BIND:
return (T) handleBind(parameters);
case ATTACH:
return (T) handleAttach(parameters, (AICorpus) payload);
return (T) handleAttach((String) parameters.get(CORPORA_ID_PARAM), (AICorpus) payload);
case DONE:
return (T) handleDone(parameters);
default:
Expand Down Expand Up @@ -134,15 +132,14 @@ private Boolean handleBind(Map<String, Serializable> parameters) {
});
}

private String handleAttach(Map<String, Serializable> parameters, AICorpus payload) throws IOException {
private String handleAttach(String corporaId, AICorpus payload) throws IOException {
String jsonString;
try (StringWriter writer = new StringWriter()) {
MAPPER.writeValue(writer, parameters.get(CORPUS_PARAM));
MAPPER.writeValue(writer, payload);
jsonString = writer.toString();
}

log.info("Creating dataset document");
String corporaId = (String) parameters.get(CORPORA_ID_PARAM);
Objects.requireNonNull(corporaId, "Attach API requires corpora ID");
JsonNode node = client.post(API.Export.ATTACH.toPath(client.getProjectId(), corporaId), jsonString, (resp) -> {
if (!resp.isSuccessful()) {
Expand Down

0 comments on commit b35b9c5

Please sign in to comment.