use of com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject in project sechub by mercedes-benz.
the class ProjectAdministrationRestController method createProject.
/* @formatter:off */
@UseCaseAdminCreatesProject(@Step(number = 1, name = "Rest call", needsRestDoc = true, description = "Administrator creates a new project by calling rest api"))
@RequestMapping(path = AdministrationAPIConstants.API_CREATE_PROJECT, method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
@ResponseStatus(HttpStatus.CREATED)
public void createProject(@RequestBody @Valid ProjectJsonInput input) {
Set<URI> whiteListedURIs = new LinkedHashSet<>();
Optional<ProjectWhiteList> whitelistOption = input.getWhiteList();
if (whitelistOption.isPresent()) {
ProjectWhiteList whiteList = whitelistOption.get();
whiteListedURIs.addAll(whiteList.getUris());
}
ProjectMetaData metaData = new ProjectMetaData();
if (input.getMetaData().isPresent()) {
metaData = input.getMetaData().get();
}
/* @formatter:on */
creationService.createProject(input.getName(), input.getDescription(), input.getOwner(), whiteListedURIs, metaData);
}
use of com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject in project sechub by mercedes-benz.
the class ProjectCreationService method createProject.
@Validated
/* @formatter:off */
@UseCaseAdminCreatesProject(@Step(number = 2, name = "Create project", description = "The service will create the project when not already existing with such name."))
public /* @formatter:on */
void createProject(@NotNull String projectId, @NotNull String description, @NotNull String owner, @NotNull Set<URI> whitelist, @NotNull ProjectMetaData metaData) {
LOG.info("Administrator {} triggers create of project:{}, having owner:{}", userContext.getUserId(), projectId, owner);
assertion.assertIsValidProjectId(projectId);
assertion.assertIsValidUserId(owner);
assertion.assertIsValidProjectDescription(description);
/* assert found */
Optional<Project> foundProject = projectRepository.findById(projectId);
if (foundProject.isPresent()) {
throw new AlreadyExistsException("Project '" + projectId + "' already exists");
}
Optional<User> foundOwner = userRepository.findById(owner);
if (!foundOwner.isPresent()) {
throw new NotFoundException("Owner '" + owner + "' not found");
}
/* setup */
Project project = new Project();
project.id = projectId;
project.description = description;
User ownerUser = foundOwner.get();
project.owner = ownerUser;
/**
* add only accepted/valid URIs - sanitize
*/
whitelist.stream().filter(uri -> uriValidation.validate(uri).isValid()).forEach(project.getWhiteList()::add);
List<ProjectMetaDataEntity> metaDataEntities = metaData.getMetaDataMap().entrySet().stream().map(entry -> new ProjectMetaDataEntity(projectId, entry.getKey(), entry.getValue())).collect(Collectors.toList());
project.metaData.addAll(metaDataEntities);
/* store */
persistenceService.saveInOwnTransaction(project);
sendProjectCreatedEvent(projectId, whitelist);
sendRefreshUserAuth(ownerUser);
}
Aggregations