use of org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceRequest 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();
}
use of org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceRequest in project haikudepotserver by haiku.
the class RepositoryApiIT method testCreateRepositorySource.
@Test
public void testCreateRepositorySource() {
integrationTestSupportService.createStandardTestData();
setAuthenticatedUserToRoot();
CreateRepositorySourceRequest request = new CreateRepositorySourceRequest();
request.code = "testreposrcxx_xyz";
request.repositoryCode = "testrepo";
// ------------------------------------
repositoryApi.createRepositorySource(request);
// ------------------------------------
{
ObjectContext context = serverRuntime.newContext();
Optional<RepositorySource> repositorySourceOptional = RepositorySource.tryGetByCode(context, "testreposrcxx_xyz");
Assertions.assertThat(repositorySourceOptional.get().getActive()).isTrue();
Assertions.assertThat(repositorySourceOptional.get().getIdentifier()).isNull();
Assertions.assertThat(repositorySourceOptional.get().getRepository().getCode()).isEqualTo("testrepo");
Assertions.assertThat(repositorySourceOptional.get().getCode()).isEqualTo("testreposrcxx_xyz");
}
}
Aggregations