use of org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceResult in project haikudepotserver by haiku.
the class RepositoryApiImpl method createRepositorySource.
@Override
public CreateRepositorySourceResult createRepositorySource(CreateRepositorySourceRequest request) {
Preconditions.checkArgument(null != request, "the request must be supplied");
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.code), "the code for the new repository source must be supplied");
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.repositoryCode), "the repository for the new repository source must be identified");
final ObjectContext context = serverRuntime.newContext();
Repository repository = getRepositoryOrThrow(context, request.repositoryCode);
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), repository, Permission.REPOSITORY_EDIT)) {
throw new AccessDeniedException("unable to edit the repository [" + repository + "]");
}
Optional<RepositorySource> existingRepositorySourceOptional = RepositorySource.tryGetByCode(context, request.code);
if (existingRepositorySourceOptional.isPresent()) {
throw new ValidationException(new ValidationFailure(RepositorySource.CODE.getName(), "unique"));
}
RepositorySource repositorySource = context.newObject(RepositorySource.class);
repositorySource.setRepository(repository);
repositorySource.setCode(request.code);
repository.setModifyTimestamp();
context.commitChanges();
LOGGER.info("did create a new repository source '{}' on the repository '{}'", repositorySource, repository);
return new CreateRepositorySourceResult();
}
Aggregations