Skip to content

Commit

Permalink
fixups (action status and parameters)
Browse files Browse the repository at this point in the history
  • Loading branch information
grapigeau committed Sep 10, 2024
1 parent 6833cf5 commit e97c9a6
Showing 1 changed file with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ArchiveCaseAction extends JsonParameterisedAction {
public Set<String> workflowRunIdsForOffsiteArchive;
public Set<String> workflowRunIdsForVidarrArchival;
static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
private final ObjectNode parameters;
private final ObjectNode rootParameters = MAPPER.createObjectNode();

private static final Counter NabuRequestErrors =
Counter.build(
Expand All @@ -46,36 +48,37 @@ public class ArchiveCaseAction extends JsonParameterisedAction {
public ArchiveCaseAction(Definer<NabuPlugin> owner) {
super("nabu-plugin");
this.owner = owner;
parameters = rootParameters.putObject("parameters");
}

@ActionParameter
@ActionParameter(name = "case_identifier")
public void caseId(String caseId) {
this.caseId = caseId;
}

@ActionParameter
@ActionParameter(name = "requisition_id")
public void requisitionId(long requisitionId) {
this.requisitionId = requisitionId;
}

@ActionParameter
@ActionParameter(name = "workflow_run_ids_for_offsite_archive")
public void workflowRunIdsForOffsiteArchive(Set<String> workflowRunIdsForOffsiteArchive) {
this.workflowRunIdsForOffsiteArchive = workflowRunIdsForOffsiteArchive;
}

@ActionParameter
@ActionParameter(name = "workflow_run_ids_for_vidarr_archival")
public void workflowRunIdsForVidarrArchival(Set<String> workflowRunIdsForVidarrArchival) {
this.workflowRunIdsForVidarrArchival = workflowRunIdsForVidarrArchival;
}

@ActionParameter
@ActionParameter(name = "lims_ids")
public void limsIds(Set<String> limsIds) {
this.limsIds = limsIds;
}

@Override
public ObjectNode parameters() {
return null;
return parameters;
}

private ActionState actionStatusFromArchive(NabuCaseArchiveDto caseArchive) {
Expand All @@ -85,7 +88,7 @@ private ActionState actionStatusFromArchive(NabuCaseArchiveDto caseArchive) {
&& caseArchive.getFilesLoadedIntoVidarrArchival() != null) {
return ActionState.SUCCEEDED;
} else {
return ActionState.WAITING;
return ActionState.INFLIGHT;
}
}
return ActionState.UNKNOWN;
Expand All @@ -104,6 +107,8 @@ public boolean equals(Object obj) {
return false;
} else if (!limsIds.equals(other.limsIds)) {
return false;
} else if (!parameters.equals(other.parameters)) {
return false;
}
return caseId.equals(other.caseId);
}
Expand All @@ -117,20 +122,15 @@ public void generateUUID(Consumer<byte[]> digest) {
digest.accept(new byte[] {0});
digest.accept(Utils.toBytes(requisitionId));
digest.accept(MAPPER.writeValueAsBytes(limsIds));
digest.accept(MAPPER.writeValueAsBytes(parameters));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}

@Override
public int hashCode() {
final var prime = 31;
var result = 1;
result = prime * result + (owner == null ? 0 : owner.hashCode());
result = prime * result + (caseId == null ? 0 : caseId.hashCode());
result = prime * result + (limsIds == null ? 0 : limsIds.hashCode());
result = prime * result + Long.hashCode(requisitionId);
return result;
return Objects.hash(owner, parameters, caseId, limsIds, requisitionId);
}

private String createRequestBody() {
Expand Down Expand Up @@ -203,10 +203,13 @@ public ActionState perform(
final var results = response.body().get().collect(Collectors.toList());
return actionStatusFromArchive(results.get(0));
} else {
return ActionState.FAILED;
return ActionState.UNKNOWN;
}
} catch (final Exception e) {
e.printStackTrace();
final Map<String, String> labels = new TreeMap<>();
labels.put("url", baseUrl);
owner.log(
"Error performing case archiving action: " + e.getMessage(), LogLevel.ERROR, labels);
this.errors = Collections.singletonList(e.getMessage());
NabuRequestErrors.labels(baseUrl).inc();
return ActionState.FAILED;
Expand All @@ -230,18 +233,22 @@ private void showHTTPError(HttpResponse<?> response, String url)
labels.put("url", url);
owner.log("HTTP error: " + response.statusCode(), LogLevel.ERROR, labels);
errors.add("HTTP error: " + response.statusCode());
NabuRequestErrors.labels(url).inc();
this.errors = errors;
}

@Override
public ObjectNode toJson(ObjectMapper mapper) {
final var node = mapper.createObjectNode();
node.put("type", "nabu-archive");
node.put("caseId", caseId);
node.put("requisitionId", requisitionId);
limsIds.forEach(node.putArray("limsIds")::add);
workflowRunIdsForOffsiteArchive.forEach(node.putArray("workflowRunIdsForOffsiteArchive")::add);
workflowRunIdsForVidarrArchival.forEach(node.putArray("workflowRunIdsForVidarrArchival")::add);
node.put("case_id", caseId);
node.put("requisition_id", requisitionId);
node.set("parameters", parameters);
limsIds.forEach(node.putArray("lims_ids")::add);
workflowRunIdsForOffsiteArchive.forEach(
node.putArray("workflow_run_ids_for_offsite_archive")::add);
workflowRunIdsForVidarrArchival.forEach(
node.putArray("workflow_run_ids_for_vidarr_archival")::add);
return node;
}
}

0 comments on commit e97c9a6

Please sign in to comment.