class SchedulerUploadService {

	@UseCaseUserUploadsSourceCode(@Step(number = 2, name = "Try to find project annd upload sourcecode as zipfile", description = "When project is found and user has access and job is initializing the sourcecode file will be uploaded"))
	public void uploadSourceCode(String projectId, UUID jobUUID, MultipartFile file, String checkSum) {
		assertion.isValidProjectId(projectId);
		assertion.isValidJobUUID(jobUUID);
		notNull(file, "file may not be null!");

		String traceLogID = logSanitizer.sanitize(UUIDTraceLogID.traceLogID(jobUUID),-1);

		auditLogService.log("Wants to upload source code to project {}, {}", logSanitizer.sanitize(projectId, 30) ,traceLogID);

		assertService.assertUserHasAccessToProject(projectId);

		assertJobFoundAndStillInitializing(projectId, jobUUID);

		JobStorage jobStorage = storageService.getJobStorage(projectId, jobUUID);
		Path tmpFile = null;
		try {
			/* prepare a tmp file for validation */
			try {
				tmpFile = Files.createTempFile("sechub_schedule_upload_tmp", null);
				file.transferTo(tmpFile);
			} catch (IOException e) {
				LOG.error("Was not able to create temp file of zipped sources!", e);
				throw new SecHubRuntimeException("Was not able to create temp file");
			}
			/* validate */
			assertValidZipFile(tmpFile);
			assertCheckSumCorrect(checkSum, tmpFile);

			/* now store */
			try {
				jobStorage.store(SOURCECODE_ZIP, file.getInputStream());
			} catch (IOException e) {
				LOG.error("Was not able to store zipped sources! {}", traceLogID, e);
				throw new SecHubRuntimeException("Was not able to upload sources");
			}
			LOG.info("uploaded sourcecode for {}", traceLogID);
		} finally {
			if (tmpFile != null && Files.exists(tmpFile)) {
				try {
					Files.delete(tmpFile);
				} catch (IOException e) {
					LOG.error("Was not able delete former temp file for zipped sources! {}",traceLogID, e);
				}
			}
		}

	}

}