Search in sources :

Example 1 with ProjectMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage in project sechub by mercedes-benz.

the class ProjectChangeAccessLevelService method sendProjectAccessLevelChangedEvent.

@IsSendingAsyncMessage(MessageID.PROJECT_ACCESS_LEVEL_CHANGED)
private void sendProjectAccessLevelChangedEvent(Project project, ProjectAccessLevel formerAccessLevel) {
    DomainMessage request = new DomainMessage(MessageID.PROJECT_ACCESS_LEVEL_CHANGED);
    ProjectMessage projectData = new ProjectMessage();
    projectData.setProjectId(project.id);
    projectData.setFormerAccessLevel(formerAccessLevel);
    projectData.setNewAccessLevel(project.getAccessLevel());
    request.set(MessageDataKeys.PROJECT_ACCESS_LEVEL_CHANGE_DATA, projectData);
    eventBus.sendAsynchron(request);
}
Also used : ProjectMessage(com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) IsSendingAsyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingAsyncMessage)

Example 2 with ProjectMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage in project sechub by mercedes-benz.

the class ProjectChangeOwnerService method sendOwnerChangedForProjectEvent.

@IsSendingAsyncMessage(MessageID.PROJECT_OWNER_CHANGED)
private void sendOwnerChangedForProjectEvent(Project project, User previousOwner, User newOwner) {
    DomainMessage request = new DomainMessage(MessageID.PROJECT_OWNER_CHANGED);
    ProjectMessage projectData = new ProjectMessage();
    projectData.setProjectId(project.id);
    projectData.setPreviousProjectOwnerEmailAddress(previousOwner.getEmailAdress());
    projectData.setProjectOwnerEmailAddress(newOwner.getEmailAdress());
    project.users.forEach(user -> {
        projectData.addUserEmailAddress(user.getEmailAdress());
    });
    request.set(MessageDataKeys.PROJECT_OWNER_CHANGE_DATA, projectData);
    eventBus.sendAsynchron(request);
}
Also used : ProjectMessage(com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) IsSendingAsyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingAsyncMessage)

Example 3 with ProjectMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage in project sechub by mercedes-benz.

the class ProjectDeleteService method deleteProject.

@UseCaseAdminDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7 }, description = "The service will delete the project with dependencies and triggers asynchronous events"))
public void deleteProject(String projectId) {
    auditLogService.log("triggers delete of project {}", logSanitizer.sanitize(projectId, 30));
    assertion.assertIsValidProjectId(projectId);
    Project project = projectRepository.findOrFailProject(projectId);
    /* create message containing data before project is deleted */
    ProjectMessage message = new ProjectMessage();
    message.setProjectId(project.getId());
    message.setProjectActionTriggeredBy(userContext.getUserId());
    User owner = project.getOwner();
    if (owner == null) {
        LOG.warn("No owner found for project {} while deleting", project.getId());
    } else {
        message.setProjectOwnerEmailAddress(owner.getEmailAdress());
        // handle ORM mapping. Avoid cache conflicts
        owner.getOwnedProjects().remove(project);
    }
    for (User user : project.getUsers()) {
        message.addUserEmailAddress(user.getEmailAdress());
        // handle ORM mapping. Avoid cache conflicts
        user.getProjects().remove(project);
    }
    transactionService.deleteWithAssociationsInOwnTransaction(projectId);
    informProjectDeleted(message);
    if (owner != null) {
        sendRefreshUserAuth(owner);
    }
}
Also used : UseCaseAdminDeleteProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminDeleteProject) ProjectMessage(com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage) User(com.mercedesbenz.sechub.domain.administration.user.User) UseCaseAdminDeleteProject(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminDeleteProject)

Example 4 with ProjectMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage in project sechub by mercedes-benz.

the class ProjectChangeAccessLevelServiceTest method a_change_from_full_access_to_read_only_does_trigger_one_async_event_containing_old_and_new_access_level.

@Test
void a_change_from_full_access_to_read_only_does_trigger_one_async_event_containing_old_and_new_access_level() {
    /* prepare */
    Project project = new Project();
    when(repository.findOrFailProject(PROJECT1_ID)).thenReturn(project);
    /* execute */
    serviceToTest.changeProjectAccessLevel(PROJECT1_ID, ProjectAccessLevel.READ_ONLY);
    /* test */
    ArgumentCaptor<DomainMessage> eventCaptor = ArgumentCaptor.forClass(DomainMessage.class);
    verify(eventBus).sendAsynchron(eventCaptor.capture());
    DomainMessage sentEvent = eventCaptor.getValue();
    assertEquals(MessageID.PROJECT_ACCESS_LEVEL_CHANGED, sentEvent.getMessageId());
    ProjectMessage eventProjectMessage = sentEvent.get(MessageDataKeys.PROJECT_ACCESS_LEVEL_CHANGE_DATA);
    assertNotNull(eventProjectMessage);
    assertEquals(ProjectAccessLevel.FULL, eventProjectMessage.getFormerAccessLevel());
    assertEquals(ProjectAccessLevel.READ_ONLY, eventProjectMessage.getNewAccessLevel());
}
Also used : ProjectMessage(com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.jupiter.api.Test)

Example 5 with ProjectMessage

use of com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage in project sechub by mercedes-benz.

the class ProjectUpdateWhitelistService method sendProjectCreatedEvent.

@IsSendingAsyncMessage(MessageID.PROJECT_WHITELIST_UPDATED)
private void sendProjectCreatedEvent(String projectId, Set<URI> whitelist) {
    DomainMessage request = new DomainMessage(MessageID.PROJECT_WHITELIST_UPDATED);
    ProjectMessage message = new ProjectMessage();
    message.setProjectId(projectId);
    message.setWhitelist(whitelist);
    request.set(MessageDataKeys.PROJECT_WHITELIST_UPDATE_DATA, message);
    eventBus.sendAsynchron(request);
}
Also used : ProjectMessage(com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) IsSendingAsyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingAsyncMessage)

Aggregations

ProjectMessage (com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage)25 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)10 Test (org.junit.Test)9 IsReceivingAsyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsReceivingAsyncMessage)6 Test (org.junit.jupiter.api.Test)5 IsSendingAsyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingAsyncMessage)4 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)4 ProjectAccessLevel (com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel)3 UseCaseAdministratorChangesProjectAccessLevel (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel)2 LinkedHashSet (java.util.LinkedHashSet)2 User (com.mercedesbenz.sechub.domain.administration.user.User)1 UseCaseAdminDeleteProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminDeleteProject)1