Search in sources :

Example 1 with NotAcceptableException

use of com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException in project sechub by mercedes-benz.

the class SchedulerUploadService method assertJobFoundAndStillInitializing.

private void assertJobFoundAndStillInitializing(String projectId, UUID jobUUID) {
    ScheduleSecHubJob secHubJob = assertService.assertJob(projectId, jobUUID);
    ExecutionState state = secHubJob.getExecutionState();
    if (!ExecutionState.INITIALIZING.equals(state)) {
        // upload only possible when in initializing state
        throw new NotAcceptableException("Not in correct state");
    }
}
Also used : NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)

Example 2 with NotAcceptableException

use of com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException in project sechub by mercedes-benz.

the class UserRepositoryImpl method deleteUserWithAssociations.

@Override
public void deleteUserWithAssociations(String userId) {
    int count = countAmountOfOwnedProjects(userId);
    if (count > 0) {
        throw new NotAcceptableException("User " + userId + " is " + count + " times still owner of a project! Move ownership before delete!");
    }
    Query deleteProjectToUser = em.createNativeQuery(QUERY_DELETE_PROJECT_TO_USER);
    deleteProjectToUser.setParameter(1, userId);
    deleteProjectToUser.executeUpdate();
    Query deleteUser = em.createNativeQuery(QUERY_DELETE_USER);
    deleteUser.setParameter(1, userId);
    deleteUser.executeUpdate();
}
Also used : Query(javax.persistence.Query) NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException)

Example 3 with NotAcceptableException

use of com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException in project sechub by mercedes-benz.

the class UserDeleteService method deleteUser.

/* @formatter:off */
@Validated
@UseCaseAdminDeletesUser(@Step(number = 2, name = "Service deletes user.", next = { 3, 4 }, description = "The service will delete the user with dependencies and triggers asynchronous events"))
/* @formatter:on */
@Transactional
public void deleteUser(String userId) {
    auditLogService.log("Triggers delete of user {}", logSanitizer.sanitize(userId, 30));
    assertion.assertIsValidUserId(userId);
    if (userId.contentEquals(userContext.getUserId())) {
        throw new NotAcceptableException("You are not allowed to delete yourself!");
    }
    User user = userRepository.findOrFailUser(userId);
    /* create message containing data before user is deleted */
    UserMessage message = new UserMessage();
    message.setUserId(user.getName());
    message.setEmailAdress(user.getEmailAdress());
    userRepository.deleteUserWithAssociations(user.getName());
    informUserDeleted(message);
}
Also used : UseCaseAdminDeletesUser(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser) NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException) UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) Validated(org.springframework.validation.annotation.Validated) UseCaseAdminDeletesUser(com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with NotAcceptableException

use of com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException in project sechub by mercedes-benz.

the class SchedulerSourcecodeUploadService method assertJobFoundAndStillInitializing.

private void assertJobFoundAndStillInitializing(String projectId, UUID jobUUID) {
    ScheduleSecHubJob secHubJob = assertService.assertJob(projectId, jobUUID);
    ExecutionState state = secHubJob.getExecutionState();
    if (!ExecutionState.INITIALIZING.equals(state)) {
        // upload only possible when in initializing state
        throw new NotAcceptableException("Not in correct state");
    }
}
Also used : NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)

Example 5 with NotAcceptableException

use of com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException in project sechub by mercedes-benz.

the class SchedulerApproveJobService method approveJob.

@UseCaseUserApprovesJob(@Step(number = 2, name = "Try to find job annd update execution state", description = "When job is found and user has access job will be marked as ready for execution"))
public void approveJob(String projectId, UUID jobUUID) {
    assertion.assertIsValidProjectId(projectId);
    assertion.assertIsValidJobUUID(jobUUID);
    assertService.assertUserHasAccessToProject(projectId);
    assertService.assertProjectAllowsWriteAccess(projectId);
    ScheduleSecHubJob secHubJob = assertService.assertJob(projectId, jobUUID);
    ExecutionState state = secHubJob.getExecutionState();
    if (!ExecutionState.INITIALIZING.equals(state)) {
        throw new NotAcceptableException("Not in correct state");
    }
    secHubJob.setExecutionState(ExecutionState.READY_TO_START);
    jobRepository.save(secHubJob);
    LOG.info("job {} now approved", jobUUID);
}
Also used : NotAcceptableException(com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UseCaseUserApprovesJob(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserApprovesJob)

Aggregations

NotAcceptableException (com.mercedesbenz.sechub.sharedkernel.error.NotAcceptableException)7 ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)3 UserMessage (com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Validated (org.springframework.validation.annotation.Validated)2 ScanType (com.mercedesbenz.sechub.commons.model.ScanType)1 SecHubCodeCallStack (com.mercedesbenz.sechub.commons.model.SecHubCodeCallStack)1 UseCaseAdminDeletesUser (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminDeletesUser)1 UseCaseAdminUpdatesUserEmailAddress (com.mercedesbenz.sechub.sharedkernel.usecases.admin.user.UseCaseAdminUpdatesUserEmailAddress)1 UseCaseUserApprovesJob (com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserApprovesJob)1 Query (javax.persistence.Query)1