private static Either<String, RegistrationsUpdate> registrationsUpdate(JsonNode jsonNode) {
    Either<String, BillingCompany> billingCompany =
        ArgoUtils.stringValue(jsonNode, "billingCompany").right().map(BillingCompany::new);
    Either<String, Badge> badge = ArgoUtils.stringValue(jsonNode, "badge").right().map(Badge::new);
    Either<String, String> dietaryRequirements =
        ArgoUtils.stringValue(jsonNode, "dietaryRequirements");
    Either<String, Option<String>> bundle =
        ArgoUtils.stringValue(jsonNode, "bundle")
            .right()
            .map(Option::fromNull)
            .right()
            .map(r -> r.filter(Strings.isNotNullOrEmpty));

    return bundle
        .right()
        .apply(
            dietaryRequirements
                .right()
                .apply(
                    badge
                        .right()
                        .apply(
                            billingCompany
                                .right()
                                .apply(Either.right(Function.curry(RegistrationsUpdate::new))))));
  }
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Response invoices(@Context HttpServletRequest request) throws SQLException, IOException {
    authService.guardAuthenticatedUser(request);

    try (Connection c = dataSource.getConnection()) {
      List<UUID> ids = registrationsSqlMapper.all(c).map(x -> x.fst());
      List<RegistrationsSqlMapper.Registration> all = Option.somes(ids.traverseIO(ioify(c)).run());
      JsonRootNode overview =
          object(
              field(
                  "received",
                  array(
                      all.filter(x -> x.tuple.state == RegistrationState.RECEIVED)
                          .map(RegistrationsRestService::json))),
              field(
                  "invoicing",
                  array(
                      all.filter(x -> x.tuple.state == RegistrationState.INVOICING)
                          .map(RegistrationsRestService::json))),
              field(
                  "paid",
                  array(
                      all.filter(x -> x.tuple.state == RegistrationState.PAID)
                          .map(RegistrationsRestService::json))));
      return Response.ok(ArgoUtils.format(overview)).build();
    }
  }
 private static List<UUID> registrationListRequest(String body) throws InvalidSyntaxException {
   return ArgoUtils.parse(body)
       .getArrayNode("registrations")
       .stream()
       .map(RegistrationsRestService::uuid)
       .collect(Collectors.toList());
 }
  @POST
  @Path("/{registrationId}")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response postUpdate(
      @Context HttpServletRequest request, @PathParam("registrationId") UUID id, String body)
      throws Exception {
    authService.guardAuthenticatedUser(request);
    Either<String, RegistrationsUpdate> map =
        ArgoUtils.parseEither(body)
            .right()
            .map(x -> x.getNode("tuple"))
            .right()
            .bind(RegistrationsRestService::registrationsUpdate);

    if (map.isLeft()) return Response.serverError().build();
    RegistrationsUpdate ru = map.right().value();

    try (Connection c = dataSource.getConnection()) {
      c.setAutoCommit(false);
      if (!registrationsSqlMapper.one(c, id).isSome())
        return Response.status(Status.NOT_FOUND).build();
      registrationsSqlMapper.update(
          c, id, ru.billingCompany, ru.badge, ru.dietaryRequirements, ru.bundle);
      c.commit();
    }
    return Response.ok().build();
  }
 private static JsonRootNode json(RegistrationsSqlMapper.Registration r) {
   return object(
       field("id", string(r.id.toString())),
       field("tuple", json(r.tuple)),
       field("printedNametag", booleanNode(r.printedNametag.isSome())),
       field(
           "tickets",
           r.tickets
               .toList()
               .map(ToJson::json)
               .toJavaList()
               .stream()
               .collect(ArgoUtils.toArray())));
 }
  //	curl -u admin:password -X POST 'http://localhost:9080/gui/registrations/auto-mark-as-paid'
  @POST
  @Path("/auto-mark-as-paid")
  public Response postAutoMarkAsPaid(@Context HttpServletRequest httpRequest) {
    authService.guardAuthenticatedUser(httpRequest);

    int i = 0;
    try {
      i = sub();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return Response.ok(
            ArgoUtils.format(
                Result.success(String.format("%s registreringar markerade som betalda.", i))))
        .build();
  }
  @POST
  @Path("/mark-as-complete")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response postMarkAsComplete(@Context HttpServletRequest httpRequest, String body)
      throws Exception {
    authService.guardAuthenticatedUser(httpRequest);

    int i = 0;
    for (UUID uuid : registrationListRequest(body)) {
      markAsCompleteService.markAsComplete(uuid);
      i++;
    }

    return Response.ok(
            ArgoUtils.format(Result.success(String.format("Flyttade %s registreringar.", i))))
        .build();
  }
  @POST
  @Path("/send-invoices")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response postSendInvoices(@Context HttpServletRequest request, String body)
      throws Exception {
    authService.guardAuthenticatedUser(request);

    int invoicesSent = 0;
    for (UUID uuid : registrationListRequest(body)) {
      sendInvoiceService.sendInvoice(uuid);
      invoicesSent++;
    }

    return Response.ok(
            ArgoUtils.format(Result.success(String.format("Skickade %s fakturor.", invoicesSent))))
        .build();
  }
  @POST
  @Path("/dismiss-registrations")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response postDismissRegistrations(@Context HttpServletRequest httpRequest, String body)
      throws Exception {
    authService.guardAuthenticatedUser(httpRequest);

    int invoicesDismissed = 0;
    for (UUID uuid : registrationListRequest(body)) {
      dismissRegistrationService.dismissRegistration(uuid);
      invoicesDismissed++;
    }

    return Response.ok(
            ArgoUtils.format(
                Result.success(String.format("Avfärdade %s registreringar.", invoicesDismissed))))
        .build();
  }
  @POST
  @Path("/mark-as-printed")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response markAsPrinted(@Context HttpServletRequest request, String body) throws Exception {
    authService.guardAuthenticatedUser(request);

    int i = 0;
    for (UUID uuid : registrationListRequest(body)) {
      try (Connection c = dataSource.getConnection()) {
        registrationsSqlMapper.replacePrintedNametag(c, uuid, Option.some(new PrintedNametag()));
      }
      i++;
    }

    return Response.ok(
            ArgoUtils.format(
                Result.success(String.format("Markerade %s namnbrickor som utskrivna.", i))))
        .build();
  }