Markup() { nameLowercased = Ascii.toLowerCase(name()); }
static String toJsonString(String summary, String detail, Markup markup, Revision nextRevision) { try { final StringWriter stringWriter = new StringWriter(); final JsonGenerator jsonGenerator = Jackson.createPrettyGenerator(stringWriter); jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(FIELD_NAME_SUMMARY, summary); jsonGenerator.writeStringField(FIELD_NAME_DETAIL, detail); jsonGenerator.writeStringField(FIELD_NAME_MARKUP, markup.nameLowercased()); jsonGenerator.writeStringField(FIELD_NAME_REVISION, nextRevision.text()); jsonGenerator.writeEndObject(); jsonGenerator.close(); return stringWriter.toString(); } catch (IOException e) { throw new StorageException("failed to generate a JSON string", e); } }
@Override public CommitMessageDto deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { final JsonNode jsonNode = p.readValueAsTree(); final JsonNode summary = jsonNode.get("summary"); if (summary == null || summary.textValue() == null) { ctxt.reportInputMismatch(CommitMessageDto.class, "commit message should have a summary."); // should never reach here throw new Error(); } final String detail = jsonNode.get("detail") == null ? "" : jsonNode.get("detail").textValue(); final JsonNode markupNode = jsonNode.get("markup"); final Markup markup = Markup.parse(markupNode == null ? "unknown" : markupNode.textValue()); return new CommitMessageDto(summary.textValue(), detail, markup); } }
@Override protected com.linecorp.centraldogma.common.Commit doBackward(Commit commit) { final Markup markup = Markup.valueOf(commit.getDetail().getMarkup().name()); return new com.linecorp.centraldogma.common.Commit( RevisionConverter.TO_MODEL.convert(commit.getRevision()), AuthorConverter.TO_MODEL.convert(commit.getAuthor()), Instant.parse(commit.getTimestamp()).toEpochMilli(), commit.getSummary(), commit.getDetail().getContent(), markup); } }
@Override protected com.linecorp.centraldogma.common.Commit doBackward(Commit commit) { final Markup markup = Markup.valueOf(commit.getDetail().getMarkup().name()); return new com.linecorp.centraldogma.common.Commit( RevisionConverter.TO_MODEL.convert(commit.getRevision()), AuthorConverter.TO_MODEL.convert(commit.getAuthor()), Instant.parse(commit.getTimestamp()).toEpochMilli(), commit.getSummary(), commit.getDetail().getContent(), markup); } }
/** * POST|PUT /projects/{projectName}/repositories/{repoName}/files/revisions/{revision} * Adds a new file or edits the existing file. */ @Post @Put @Path("/projects/{projectName}/repositories/{repoName}/files/revisions/{revision}") @RequiresWritePermission public CompletionStage<Object> addOrEditFile(@Param("projectName") String projectName, @Param("repoName") String repoName, @Param("revision") String revision, AggregatedHttpMessage message, ServiceRequestContext ctx) { final Entry<CommitMessageDto, Change<?>> p = commitMessageAndChange(message); final CommitMessageDto commitMessage = p.getKey(); final Change<?> change = p.getValue(); return push(projectName, repoName, new Revision(revision), AuthUtil.currentAuthor(ctx), commitMessage.getSummary(), commitMessage.getDetail().getContent(), Markup.valueOf(commitMessage.getDetail().getMarkup()), change) // This is so weird but there is no way to find a converter for 'null' with the current // Armeria's converter implementation. We will figure out a better way to improve it. .thenApply(unused -> VOID); }
Markup() { nameLowercased = Ascii.toLowerCase(name()); }
@Override public CommitMessageDto deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { final JsonNode jsonNode = p.readValueAsTree(); final JsonNode summary = jsonNode.get("summary"); if (summary == null || summary.textValue() == null) { ctxt.reportInputMismatch(CommitMessageDto.class, "commit message should have a summary."); // should never reach here throw new Error(); } final String detail = jsonNode.get("detail") == null ? "" : jsonNode.get("detail").textValue(); final JsonNode markupNode = jsonNode.get("markup"); final Markup markup = Markup.parse(markupNode == null ? "unknown" : markupNode.textValue()); return new CommitMessageDto(summary.textValue(), detail, markup); } }
static String toJsonString(String summary, String detail, Markup markup, Revision nextRevision) { try { final StringWriter stringWriter = new StringWriter(); final JsonGenerator jsonGenerator = Jackson.createPrettyGenerator(stringWriter); jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(FIELD_NAME_SUMMARY, summary); jsonGenerator.writeStringField(FIELD_NAME_DETAIL, detail); jsonGenerator.writeStringField(FIELD_NAME_MARKUP, markup.nameLowercased()); jsonGenerator.writeStringField(FIELD_NAME_REVISION, nextRevision.text()); jsonGenerator.writeEndObject(); jsonGenerator.close(); return stringWriter.toString(); } catch (IOException e) { throw new StorageException("failed to generate a JSON string", e); } }
/** * POST|PUT /projects/{projectName}/repositories/{repoName}/files/revisions/{revision} * Adds a new file or edits the existing file. */ @Post @Put @Path("/projects/{projectName}/repositories/{repoName}/files/revisions/{revision}") @Decorator(HasWritePermission.class) public CompletionStage<Object> addOrEditFile(@Param("projectName") String projectName, @Param("repoName") String repoName, @Param("revision") String revision, AggregatedHttpMessage message, ServiceRequestContext ctx) { final Entry<CommitMessageDto, Change<?>> p = commitMessageAndChange(message); final CommitMessageDto commitMessage = p.getKey(); final Change<?> change = p.getValue(); return push(projectName, repoName, new Revision(revision), AuthenticationUtil.currentAuthor(ctx), commitMessage.getSummary(), commitMessage.getDetail().getContent(), Markup.valueOf(commitMessage.getDetail().getMarkup()), change) // This is so weird but there is no way to find a converter for 'null' with the current // Armeria's converter implementation. We will figure out a better way to improve it. .thenApply(unused -> VOID); }
Markup() { nameLowercased = Ascii.toLowerCase(name()); }
@Override public CommitMessageDto deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { final JsonNode jsonNode = p.readValueAsTree(); final JsonNode summary = jsonNode.get("summary"); if (summary == null || summary.textValue() == null) { ctxt.reportInputMismatch(CommitMessageDto.class, "commit message should have a summary."); // should never reach here throw new Error(); } final String detail = jsonNode.get("detail") == null ? "" : jsonNode.get("detail").textValue(); final JsonNode markupNode = jsonNode.get("markup"); final Markup markup = Markup.parse(markupNode == null ? "unknown" : markupNode.textValue()); return new CommitMessageDto(summary.textValue(), detail, markup); } }
static String toJsonString(String summary, String detail, Markup markup, Revision nextRevision) { try { final StringWriter stringWriter = new StringWriter(); final JsonGenerator jsonGenerator = Jackson.createPrettyGenerator(stringWriter); jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(FIELD_NAME_SUMMARY, summary); jsonGenerator.writeStringField(FIELD_NAME_DETAIL, detail); jsonGenerator.writeStringField(FIELD_NAME_MARKUP, markup.nameLowercased()); jsonGenerator.writeStringField(FIELD_NAME_REVISION, nextRevision.text()); jsonGenerator.writeEndObject(); jsonGenerator.close(); return stringWriter.toString(); } catch (IOException e) { throw new StorageException("failed to generate a JSON string", e); } }
/** * POST|PUT /projects/{projectName}/repositories/{repoName}/files/revisions/{revision} * Adds a new file or edits the existing file. */ @Post @Put @Path("/projects/{projectName}/repositories/{repoName}/files/revisions/{revision}") @RequiresWritePermission public CompletionStage<Object> addOrEditFile(@Param("projectName") String projectName, @Param("repoName") String repoName, @Param("revision") String revision, AggregatedHttpMessage message, ServiceRequestContext ctx) { final Entry<CommitMessageDto, Change<?>> p = commitMessageAndChange(message); final CommitMessageDto commitMessage = p.getKey(); final Change<?> change = p.getValue(); return push(projectName, repoName, new Revision(revision), AuthUtil.currentAuthor(ctx), commitMessage.getSummary(), commitMessage.getDetail().getContent(), Markup.valueOf(commitMessage.getDetail().getMarkup()), change) // This is so weird but there is no way to find a converter for 'null' with the current // Armeria's converter implementation. We will figure out a better way to improve it. .thenApply(unused -> VOID); }
static CommentDto convert(String content, Markup markup) { final CommentDto dto = new CommentDto(); dto.setContent(content); dto.setMarkup(markup.name()); return dto; }
/** * POST /projects/{projectName}/repositories/{repoName}/delete/revisions/{revision}{path} * Deletes a file. */ @Post("regex:/projects/(?<projectName>[^/]+)/repositories/(?<repoName>[^/]+)" + "/delete/revisions/(?<revision>[^/]+)(?<path>/.*$)") @RequiresWritePermission public HttpResponse deleteFile(@Param("projectName") String projectName, @Param("repoName") String repoName, @Param("revision") String revision, @Param("path") String path, AggregatedHttpMessage message, ServiceRequestContext ctx) { final CommitMessageDto commitMessage; try { final JsonNode node = Jackson.readTree(message.content().toStringUtf8()); commitMessage = Jackson.convertValue(node.get("commitMessage"), CommitMessageDto.class); } catch (IOException e) { throw new IllegalArgumentException("invalid data to be parsed", e); } final CompletableFuture<?> future = push(projectName, repoName, new Revision(revision), AuthUtil.currentAuthor(ctx), commitMessage.getSummary(), commitMessage.getDetail().getContent(), Markup.valueOf(commitMessage.getDetail().getMarkup()), Change.ofRemoval(path)); return HttpResponse.from(future.thenApply(unused -> HttpResponse.of(HttpStatus.OK))); }
static CommentDto convert(String content, Markup markup) { final CommentDto dto = new CommentDto(); dto.setContent(content); dto.setMarkup(markup.name()); return dto; }
/** * POST /projects/{projectName}/repositories/{repoName}/delete/revisions/{revision}{path} * Deletes a file. */ @Post("regex:/projects/(?<projectName>[^/]+)/repositories/(?<repoName>[^/]+)" + "/delete/revisions/(?<revision>[^/]+)(?<path>/.*$)") @RequiresWritePermission public HttpResponse deleteFile(@Param("projectName") String projectName, @Param("repoName") String repoName, @Param("revision") String revision, @Param("path") String path, AggregatedHttpMessage message, ServiceRequestContext ctx) { final CommitMessageDto commitMessage; try { final JsonNode node = Jackson.readTree(message.content().toStringUtf8()); commitMessage = Jackson.convertValue(node.get("commitMessage"), CommitMessageDto.class); } catch (IOException e) { throw new IllegalArgumentException("invalid data to be parsed", e); } final CompletableFuture<?> future = push(projectName, repoName, new Revision(revision), AuthUtil.currentAuthor(ctx), commitMessage.getSummary(), commitMessage.getDetail().getContent(), Markup.valueOf(commitMessage.getDetail().getMarkup()), Change.ofRemoval(path)); return HttpResponse.from(future.thenApply(unused -> HttpResponse.of(HttpStatus.OK))); }
static CommentDto convert(String content, Markup markup) { final CommentDto dto = new CommentDto(); dto.setContent(content); dto.setMarkup(markup.name()); return dto; }
/** * POST /projects/{projectName}/repositories/{repoName}/delete/revisions/{revision}{path} * Deletes a file. */ @Post("regex:/projects/(?<projectName>[^/]+)/repositories/(?<repoName>[^/]+)" + "/delete/revisions/(?<revision>[^/]+)(?<path>/.*$)") @Decorator(HasWritePermission.class) public HttpResponse deleteFile(@Param("projectName") String projectName, @Param("repoName") String repoName, @Param("revision") String revision, @Param("path") String path, AggregatedHttpMessage message, ServiceRequestContext ctx) { final CommitMessageDto commitMessage; try { final JsonNode node = Jackson.readTree(message.content().toStringUtf8()); commitMessage = Jackson.convertValue(node.get("commitMessage"), CommitMessageDto.class); } catch (IOException e) { throw new IllegalArgumentException("invalid data to be parsed", e); } final CompletableFuture<?> future = push(projectName, repoName, new Revision(revision), AuthenticationUtil.currentAuthor(ctx), commitMessage.getSummary(), commitMessage.getDetail().getContent(), Markup.valueOf(commitMessage.getDetail().getMarkup()), Change.ofRemoval(path)); return HttpResponse.from(future.thenApply(unused -> HttpResponse.of(HttpStatus.OK))); }