pipline
This commit is contained in:
parent
6946a63da4
commit
58a5ac294f
@ -0,0 +1,14 @@
|
||||
<databaseChangeLog
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
|
||||
<changeSet id="2021-02-05-edit-pipelines" author="uPagge">
|
||||
<addColumn tableName="pipeline">
|
||||
<column name="person_id" type="int">
|
||||
<constraints foreignKeyName="pipeline_person_id" references="person(id)"/>
|
||||
</column>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
@ -5,5 +5,6 @@
|
||||
|
||||
<include file="liquibase/v.1.0.0/2021-01-14-create-tables.xml"/>
|
||||
<include file="liquibase/v.1.0.0/2020-01-16-app-setting.xml"/>
|
||||
<include file="liquibase/v.1.0.0/2021-02-05-edit-pipelines.xml"/>
|
||||
|
||||
</databaseChangeLog>
|
@ -54,4 +54,8 @@ public class Pipeline implements BasicEntity<Long> {
|
||||
@JoinColumn(name = "project_id")
|
||||
private Project project;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "person_id")
|
||||
private Person person;
|
||||
|
||||
}
|
||||
|
@ -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<PipelineJson, Pipeline> {
|
||||
|
||||
private final PersonJsonConverter convertPerson;
|
||||
|
||||
@Override
|
||||
public Pipeline convert(PipelineJson source) {
|
||||
final Pipeline pipeline = new Pipeline();
|
||||
@ -36,6 +40,7 @@ public class PipelineJsonConverter implements Converter<PipelineJson, Pipeline>
|
||||
pipeline.setRef(source.getRef());
|
||||
pipeline.setWebUrl(source.getWebUrl());
|
||||
pipeline.setStatus(convertStatus(source.getStatus()));
|
||||
pipeline.setPerson(convertPerson.convert(source.getUser()));
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
|
@ -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<Pipeline,
|
||||
|
||||
private final NotifyService notifyService;
|
||||
private final PipelineRepository repository;
|
||||
private final PersonService personService;
|
||||
|
||||
public PipelineServiceImpl(NotifyService notifyService, PipelineRepository repository) {
|
||||
private final PersonInformation personInformation;
|
||||
|
||||
public PipelineServiceImpl(NotifyService notifyService, PipelineRepository repository, PersonService personService, PersonInformation personInformation) {
|
||||
super(repository);
|
||||
this.notifyService = notifyService;
|
||||
this.repository = repository;
|
||||
this.personService = personService;
|
||||
this.personInformation = personInformation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pipeline create(@NonNull Pipeline pipeline) {
|
||||
personService.create(pipeline.getPerson());
|
||||
final Pipeline newPipeline = repository.save(pipeline);
|
||||
|
||||
if (notificationStatus.contains(pipeline.getStatus())) {
|
||||
if (
|
||||
notificationStatus.contains(pipeline.getStatus())
|
||||
&& pipeline.getPerson() != null
|
||||
&& personInformation.getId().equals(pipeline.getPerson().getId())
|
||||
) {
|
||||
notifyService.send(
|
||||
PipelineNotify.builder()
|
||||
.newStatus(pipeline.getStatus().name())
|
||||
@ -70,7 +82,11 @@ public class PipelineServiceImpl extends AbstractSimpleManagerService<Pipeline,
|
||||
if (!oldPipeline.getUpdated().equals(pipeline.getUpdated())) {
|
||||
pipeline.setProject(oldPipeline.getProject());
|
||||
|
||||
if (notificationStatus.contains(pipeline.getStatus())) {
|
||||
if (
|
||||
notificationStatus.contains(pipeline.getStatus())
|
||||
&& pipeline.getPerson() != null
|
||||
&& personInformation.getId().equals(pipeline.getPerson().getId())
|
||||
) {
|
||||
notifyService.send(
|
||||
PipelineNotify.builder()
|
||||
.pipelineId(pipeline.getId())
|
||||
|
@ -18,6 +18,7 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@ -82,14 +83,25 @@ public class PipelineParser {
|
||||
final ExistsContainer<Pipeline, Long> existsContainer = pipelineService.existsById(jsonIds);
|
||||
|
||||
if (!existsContainer.isAllFound()) {
|
||||
final List<Pipeline> 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<Long> 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);
|
||||
|
@ -33,6 +33,8 @@ public class PipelineJson {
|
||||
|
||||
private String ref;
|
||||
|
||||
private PersonJson user;
|
||||
|
||||
@JsonProperty("web_url")
|
||||
private String webUrl;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user