Search in sources :

Example 1 with Template

use of com.epam.pipeline.entity.template.Template in project cloud-pipeline by epam.

the class GitManager method createRepository.

public String createRepository(String templateId, String pipelineName, String description) throws GitClientException {
    TemplatesScanner templatesScanner = new TemplatesScanner(templatesDirectoryPath);
    Template template = templatesScanner.listTemplates().get(templateId);
    Assert.notNull(template, "There is no such a template: " + templateId);
    return getDefaultGitlabClient().createTemplateRepository(template, pipelineName, description, preferenceManager.getPreference(SystemPreferences.GIT_REPOSITORY_INDEXING_ENABLED), preferenceManager.getPreference(SystemPreferences.GIT_REPOSITORY_HOOK_URL)).getRepoUrl();
}
Also used : Template(com.epam.pipeline.entity.template.Template)

Example 2 with Template

use of com.epam.pipeline.entity.template.Template in project cloud-pipeline by epam.

the class GitlabClient method findUser.

private Optional<GitlabUser> findUser(String userName) {
    final RestTemplate template = new RestTemplate();
    final HttpEntity headers = getAuthHeaders();
    final String searchUri = UriComponentsBuilder.fromHttpUrl(String.format(GITLAB_API_USERS, gitHost)).queryParam("search", userName).build().toUriString();
    ResponseEntity<List<GitlabUser>> response = template.exchange(searchUri, HttpMethod.GET, headers, new ParameterizedTypeReference<List<GitlabUser>>() {
    });
    return Optional.of(response).filter(r -> r.getStatusCode() == HttpStatus.OK).map(ResponseEntity::getBody).map(List::stream).flatMap(Stream::findFirst);
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) PipelineSourceItemErrorVO(com.epam.pipeline.controller.vo.PipelineSourceItemErrorVO) GitlabUser(com.epam.pipeline.entity.git.GitlabUser) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Wither(lombok.experimental.Wither) StringUtils(org.apache.commons.lang3.StringUtils) Map(java.util.Map) URI(java.net.URI) Path(java.nio.file.Path) RestTemplate(org.springframework.web.client.RestTemplate) DateFormat(java.text.DateFormat) HttpHeaders(org.springframework.http.HttpHeaders) TimeZone(java.util.TimeZone) GitCredentials(com.epam.pipeline.entity.git.GitCredentials) GitProject(com.epam.pipeline.entity.git.GitProject) GitPushCommitEntry(com.epam.pipeline.entity.git.GitPushCommitEntry) Collectors(java.util.stream.Collectors) GitlabVersion(com.epam.pipeline.entity.git.GitlabVersion) IOUtils(org.apache.commons.io.IOUtils) HttpEntity(org.springframework.http.HttpEntity) Base64(java.util.Base64) List(java.util.List) Stream(java.util.stream.Stream) GitRepositoryUrl(com.epam.pipeline.entity.git.GitRepositoryUrl) Template(com.epam.pipeline.entity.template.Template) LocalDate(java.time.LocalDate) Optional(java.util.Optional) UnsupportedEncodingException(java.io.UnsupportedEncodingException) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) GitClientException(com.epam.pipeline.exception.git.GitClientException) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) SimpleDateFormat(java.text.SimpleDateFormat) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) HashMap(java.util.HashMap) Charset(java.nio.charset.Charset) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) Logger(org.slf4j.Logger) UnexpectedResponseStatusException(com.epam.pipeline.exception.git.UnexpectedResponseStatusException) GitFile(com.epam.pipeline.entity.git.GitFile) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpMethod(org.springframework.http.HttpMethod) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) HttpStatus(org.springframework.http.HttpStatus) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) URLEncoder(java.net.URLEncoder) Paths(java.nio.file.Paths) DateTimeFormatter(java.time.format.DateTimeFormatter) ResponseEntity(org.springframework.http.ResponseEntity) GitToken(com.epam.pipeline.entity.git.GitToken) AllArgsConstructor(lombok.AllArgsConstructor) NoArgsConstructor(lombok.NoArgsConstructor) Assert(org.springframework.util.Assert) InputStream(java.io.InputStream) ResponseEntity(org.springframework.http.ResponseEntity) HttpEntity(org.springframework.http.HttpEntity) RestTemplate(org.springframework.web.client.RestTemplate) List(java.util.List) Stream(java.util.stream.Stream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 3 with Template

use of com.epam.pipeline.entity.template.Template in project cloud-pipeline by epam.

the class FolderTemplateManager method create.

@Transactional(propagation = Propagation.REQUIRED)
public Folder create(final Folder folder, final String templateName) {
    TemplatesScanner templatesScanner = new TemplatesScanner(folderTemplatesDirectoryPath);
    Template template = templatesScanner.listTemplates().get(templateName);
    Assert.notNull(template, messageHelper.getMessage(MessageConstants.ERROR_FOLDER_TEMPLATE_NOT_FOUND, templateName));
    Assert.isTrue(StringUtils.hasText(folder.getName()), messageHelper.getMessage(MessageConstants.ERROR_FOLDER_NAME_IS_EMPTY));
    FolderTemplate folderTemplate = parseTemplateJson(template.getDirPath(), folder.getName());
    Assert.isTrue(StringUtils.hasText(folderTemplate.getName()), messageHelper.getMessage(MessageConstants.ERROR_TEMPLATE_FOLDER_NAME_IS_EMPTY, templateName));
    Assert.isNull(folderDao.loadFolderByNameAndParentId(folderTemplate.getName(), folder.getParentId()), messageHelper.getMessage(MessageConstants.ERROR_FOLDER_NAME_EXISTS, folderTemplate.getName(), folder.getParentId()));
    prepareTemplate(folderTemplate, folder.getName());
    createFolderFromTemplate(folder, folderTemplate);
    return folder;
}
Also used : TemplatesScanner(com.epam.pipeline.manager.git.TemplatesScanner) FolderTemplate(com.epam.pipeline.entity.templates.FolderTemplate) Template(com.epam.pipeline.entity.template.Template) FolderTemplate(com.epam.pipeline.entity.templates.FolderTemplate) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Template

use of com.epam.pipeline.entity.template.Template in project cloud-pipeline by epam.

the class TemplateManager method getPipelineTemplates.

public Collection<Template> getPipelineTemplates() {
    TemplatesScanner templatesScanner = new TemplatesScanner(pipelineTemplatesDirectoryPath);
    Collection<Template> templates = templatesScanner.listTemplates().values();
    templates.forEach(template -> {
        if (template.getId().equals(pipelineDefaultTemplate)) {
            template.setDefaultTemplate(true);
        }
    });
    return templates;
}
Also used : TemplatesScanner(com.epam.pipeline.manager.git.TemplatesScanner) Template(com.epam.pipeline.entity.template.Template)

Aggregations

Template (com.epam.pipeline.entity.template.Template)4 TemplatesScanner (com.epam.pipeline.manager.git.TemplatesScanner)2 PipelineSourceItemErrorVO (com.epam.pipeline.controller.vo.PipelineSourceItemErrorVO)1 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)1 GitCredentials (com.epam.pipeline.entity.git.GitCredentials)1 GitFile (com.epam.pipeline.entity.git.GitFile)1 GitProject (com.epam.pipeline.entity.git.GitProject)1 GitPushCommitEntry (com.epam.pipeline.entity.git.GitPushCommitEntry)1 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)1 GitRepositoryUrl (com.epam.pipeline.entity.git.GitRepositoryUrl)1 GitTagEntry (com.epam.pipeline.entity.git.GitTagEntry)1 GitToken (com.epam.pipeline.entity.git.GitToken)1 GitlabUser (com.epam.pipeline.entity.git.GitlabUser)1 GitlabVersion (com.epam.pipeline.entity.git.GitlabVersion)1 FolderTemplate (com.epam.pipeline.entity.templates.FolderTemplate)1 GitClientException (com.epam.pipeline.exception.git.GitClientException)1 UnexpectedResponseStatusException (com.epam.pipeline.exception.git.UnexpectedResponseStatusException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1