Search in sources :

Example 41 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class PipelineRunMapperOld method getRequestForRun.

private Optional<DocWriteRequest> getRequestForRun(final String indexName, final PipelineEvent event, final Map<String, PipelineUser> users) {
    try {
        PipelineRunWithLog run = cloudPipelineAPIClient.loadPipelineRunWithLogs(event.getObjectId());
        PipelineUser pipelineUser = users.get(run.getPipelineRun().getOwner());
        run.setRunOwner(pipelineUser);
        return Optional.of(new IndexRequest(indexName, INDEX_TYPE, String.valueOf(run.getPipelineRun().getId())).source(pipelineRunToDocument(run)));
    } catch (PipelineResponseException e) {
        log.error(e.getMessage(), e);
        if (isRunMissingError(event, e)) {
            return Optional.of(createDeleteRequest(event, indexName));
        }
        return Optional.empty();
    }
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) PipelineResponseException(com.epam.pipeline.exception.PipelineResponseException) PipelineRunWithLog(com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 42 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class ObjectCreationUtils method buildPipelineUser.

public static PipelineUser buildPipelineUser(final String name, final String prettyName, final List<String> groups) {
    PipelineUser user = new PipelineUser();
    user.setId(1L);
    user.setUserName(name);
    user.setGroups(groups);
    if (StringUtils.isNotBlank(prettyName)) {
        user.setAttributes(Collections.singletonMap(PRETTY_NAME_ATTRIBUTE, prettyName));
    }
    return user;
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser)

Example 43 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class SMTPNotificationManagerTest method testEmailSendingWithParams.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testEmailSendingWithParams() {
    PipelineUser user = new PipelineUser();
    user.setUserName(USER_NAME);
    user.setAdmin(true);
    user.setAttributes(Collections.singletonMap(EMAIL_KEY, EMAIL));
    userRepository.save(user);
    NotificationMessage message = new NotificationMessage();
    NotificationTemplate template = new NotificationTemplate();
    template.setSubject(MESSAGE_SUBJECT);
    template.setBody(MESSAGE_BODY_WITH_PARAM);
    message.setTemplate(template);
    message.setTemplateParameters(Collections.singletonMap("name", USER_NAME));
    message.setToUserId(user.getId());
    message.setCopyUserIds(Collections.singletonList(user.getId()));
    smtpNotificationManager.notifySubscribers(message);
    MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
    assertTrue(receivedMessages.length == 2);
    String filledMessage = PARSED_MESSAGE_BODY_WITH_PARAM.replace("$templateParameters.get(\"name\")", USER_NAME);
    assertTrue(GreenMailUtil.getBody(receivedMessages[0]).contains(filledMessage));
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) MimeMessage(javax.mail.internet.MimeMessage) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest) AbstractSpringTest(com.epam.pipeline.notifier.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class UserRepositoryTest method loadUserTest.

@Test
public void loadUserTest() {
    PipelineUser user = new PipelineUser();
    user.setUserName(USER_NAME);
    user.setAdmin(true);
    userRepository.save(user);
    List<PipelineUser> users = userRepository.findByIdIn(Collections.singletonList(user.getId()));
    Assert.assertTrue(users.size() == 1);
    Assert.assertEquals(USER_NAME, users.get(0).getUserName());
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.notifier.AbstractSpringTest)

Aggregations

PipelineUser (com.epam.pipeline.entity.user.PipelineUser)44 Transactional (org.springframework.transaction.annotation.Transactional)23 Test (org.junit.Test)19 NotificationMessage (com.epam.pipeline.entity.notification.NotificationMessage)13 NotificationTemplate (com.epam.pipeline.entity.notification.NotificationTemplate)13 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)12 ArrayList (java.util.ArrayList)8 DefaultRoles (com.epam.pipeline.entity.user.DefaultRoles)7 Collections (java.util.Collections)7 List (java.util.List)7 Map (java.util.Map)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 Role (com.epam.pipeline.entity.user.Role)6 AbstractSpringTest (com.epam.pipeline.notifier.AbstractSpringTest)6 Arrays (java.util.Arrays)6 S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)5 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)5 Collection (java.util.Collection)5 CollectionUtils (org.apache.commons.collections4.CollectionUtils)5 DataStorageDao (com.epam.pipeline.dao.datastorage.DataStorageDao)4