From 58a5ac294f29494ec9504a4259d36b3242e2026c Mon Sep 17 00:00:00 2001 From: uPagge Date: Fri, 5 Feb 2021 16:05:35 +0300 Subject: [PATCH] pipline --- .../v.1.0.0/2021-02-05-edit-pipelines.xml | 14 ++++++++++ .../liquibase/v.1.0.0/cumulative.xml | 1 + .../context/domain/entity/Pipeline.java | 4 +++ .../convert/PipelineJsonConverter.java | 5 ++++ .../service/impl/PipelineServiceImpl.java | 22 +++++++++++++--- .../core/service/parser/PipelineParser.java | 26 ++++++++++++++----- .../bot/gitlab/sdk/domain/PipelineJson.java | 2 ++ 7 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 bot-app/src/main/resources/liquibase/v.1.0.0/2021-02-05-edit-pipelines.xml diff --git a/bot-app/src/main/resources/liquibase/v.1.0.0/2021-02-05-edit-pipelines.xml b/bot-app/src/main/resources/liquibase/v.1.0.0/2021-02-05-edit-pipelines.xml new file mode 100644 index 0000000..6fdb000 --- /dev/null +++ b/bot-app/src/main/resources/liquibase/v.1.0.0/2021-02-05-edit-pipelines.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/bot-app/src/main/resources/liquibase/v.1.0.0/cumulative.xml b/bot-app/src/main/resources/liquibase/v.1.0.0/cumulative.xml index f4fa8c2..ded14d1 100644 --- a/bot-app/src/main/resources/liquibase/v.1.0.0/cumulative.xml +++ b/bot-app/src/main/resources/liquibase/v.1.0.0/cumulative.xml @@ -5,5 +5,6 @@ + \ No newline at end of file diff --git a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Pipeline.java b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Pipeline.java index 87ff936..4988580 100644 --- a/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Pipeline.java +++ b/bot-context/src/main/java/org/sadtech/bot/gitlab/context/domain/entity/Pipeline.java @@ -54,4 +54,8 @@ public class Pipeline implements BasicEntity { @JoinColumn(name = "project_id") private Project project; + @ManyToOne + @JoinColumn(name = "person_id") + private Person person; + } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/convert/PipelineJsonConverter.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/convert/PipelineJsonConverter.java index 2de33e2..a4a6553 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/convert/PipelineJsonConverter.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/convert/PipelineJsonConverter.java @@ -1,5 +1,6 @@ package org.sadtech.bot.gitlab.core.service.convert; +import lombok.RequiredArgsConstructor; import org.sadtech.bot.gitlab.context.domain.PipelineStatus; import org.sadtech.bot.gitlab.context.domain.entity.Pipeline; import org.sadtech.bot.gitlab.sdk.domain.PipelineJson; @@ -25,8 +26,11 @@ import static org.sadtech.bot.gitlab.context.domain.PipelineStatus.WAITING_FOR_R * @author upagge 17.01.2021 */ @Component +@RequiredArgsConstructor public class PipelineJsonConverter implements Converter { + private final PersonJsonConverter convertPerson; + @Override public Pipeline convert(PipelineJson source) { final Pipeline pipeline = new Pipeline(); @@ -36,6 +40,7 @@ public class PipelineJsonConverter implements Converter pipeline.setRef(source.getRef()); pipeline.setWebUrl(source.getWebUrl()); pipeline.setStatus(convertStatus(source.getStatus())); + pipeline.setPerson(convertPerson.convert(source.getUser())); return pipeline; } diff --git a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PipelineServiceImpl.java b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PipelineServiceImpl.java index 4b2d5aa..e6d6b41 100644 --- a/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PipelineServiceImpl.java +++ b/bot-core/src/main/java/org/sadtech/bot/gitlab/core/service/impl/PipelineServiceImpl.java @@ -1,11 +1,13 @@ package org.sadtech.bot.gitlab.core.service.impl; import lombok.NonNull; +import org.sadtech.bot.gitlab.context.domain.PersonInformation; import org.sadtech.bot.gitlab.context.domain.PipelineStatus; import org.sadtech.bot.gitlab.context.domain.entity.Pipeline; import org.sadtech.bot.gitlab.context.domain.notify.pipeline.PipelineNotify; import org.sadtech.bot.gitlab.context.repository.PipelineRepository; import org.sadtech.bot.gitlab.context.service.NotifyService; +import org.sadtech.bot.gitlab.context.service.PersonService; import org.sadtech.bot.gitlab.context.service.PipelineService; import org.sadtech.haiti.context.exception.NotFoundException; import org.sadtech.haiti.context.page.Pagination; @@ -36,18 +38,28 @@ public class PipelineServiceImpl extends AbstractSimpleManagerService existsContainer = pipelineService.existsById(jsonIds); if (!existsContainer.isAllFound()) { - final List newPipelines = pipelineJsons.stream() - .filter(json -> existsContainer.getIdNoFound().contains(json.getId())) - .map(json -> conversionService.convert(json, Pipeline.class)) - .peek( - pipeline -> pipeline.setProject(project) - ).collect(Collectors.toList()); - pipelineService.createAll(newPipelines); + final Collection idsNotFound = existsContainer.getIdNoFound(); + + for (Long newId : idsNotFound) { + final Pipeline newPipeline = HttpParse.request( + MessageFormat.format(gitlabProperty.getUrlPipeline(), project.getId(), newId) + ) + .header(ACCEPT) + .header(AUTHORIZATION, BEARER + personProperty.getToken()) + .execute(PipelineJson.class) + .map(json -> { + final Pipeline pipeline = conversionService.convert(json, Pipeline.class); + pipeline.setProject(project); + return pipeline; + }) + .orElseThrow(() -> new ConvertException("Ошибка обновления Pipelines")); + pipelineService.create(newPipeline); + } + } pipelineJsons = getPipelineJsons(project.getId(), ++page); diff --git a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PipelineJson.java b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PipelineJson.java index 665ddef..933e7d7 100644 --- a/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PipelineJson.java +++ b/gitlab-sdk/src/main/java/org/sadtech/bot/gitlab/sdk/domain/PipelineJson.java @@ -33,6 +33,8 @@ public class PipelineJson { private String ref; + private PersonJson user; + @JsonProperty("web_url") private String webUrl;