Search in sources :

Example 1 with RepositorySourceExtraIdentifier

use of org.haiku.haikudepotserver.dataobjects.RepositorySourceExtraIdentifier in project haikudepotserver by haiku.

the class RepositoryApiImpl method updateRepositorySource.

@Override
public UpdateRepositorySourceResult updateRepositorySource(UpdateRepositorySourceRequest request) {
    Preconditions.checkArgument(null != request);
    Preconditions.checkArgument(StringUtils.isNotBlank(request.code), "a code is required to identify the repository source to update");
    Preconditions.checkArgument(null != request.filter, "filters must be provided to specify what aspects of the repository source should be updated");
    final ObjectContext context = serverRuntime.newContext();
    RepositorySource repositorySource = getRepositorySourceOrThrow(context, request.code);
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), repositorySource.getRepository(), Permission.REPOSITORY_EDIT)) {
        throw new AccessDeniedException("cannot edit the repository [" + repositorySource.getRepository() + "]");
    }
    for (UpdateRepositorySourceRequest.Filter filter : request.filter) {
        switch(filter) {
            case ACTIVE:
                if (null == request.active) {
                    throw new IllegalArgumentException("the active field must be provided if the request requires it to be updated");
                }
                repositorySource.setActive(request.active);
                LOGGER.info("did set the repository source {} active to {}", repositorySource, request.active);
                break;
            case FORCED_INTERNAL_BASE_URL:
                repositorySource.setForcedInternalBaseUrl(StringUtils.trimToNull(request.forcedInternalBaseUrl));
                LOGGER.info("did set the repository source forced internal base url");
                break;
            case EXTRA_IDENTIFIERS:
                {
                    Set<String> existing = Set.copyOf(repositorySource.getExtraIdentifiers());
                    Set<String> desired = Set.copyOf(CollectionUtils.emptyIfNull(request.extraIdentifiers));
                    SetUtils.difference(existing, desired).stream().map(repositorySource::tryGetRepositorySourceExtraIdentifierForIdentifier).map(Optional::orElseThrow).forEach(rsei -> {
                        repositorySource.removeFromRepositorySourceExtraIdentifiers(rsei);
                        context.deleteObject(rsei);
                    });
                    SetUtils.difference(desired, existing).forEach(i -> {
                        RepositorySourceExtraIdentifier rsei = context.newObject(RepositorySourceExtraIdentifier.class);
                        rsei.setRepositorySource(repositorySource);
                        rsei.setIdentifier(i);
                        repositorySource.addToRepositorySourceExtraIdentifiers(rsei);
                    });
                    break;
                }
            default:
                throw new IllegalStateException("unhandled filter; " + filter.name());
        }
    }
    if (context.hasChanges()) {
        repositorySource.getRepository().setModifyTimestamp();
        context.commitChanges();
    } else {
        LOGGER.info("update repository source {} with no changes made", repositorySource);
    }
    return new UpdateRepositorySourceResult();
}
Also used : GetRepositorySourceMirrorResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceMirrorResult) CreateRepositoryResult(org.haiku.haikudepotserver.api1.model.repository.CreateRepositoryResult) CreateRepositorySourceRequest(org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceRequest) RemoveRepositorySourceMirrorResult(org.haiku.haikudepotserver.api1.model.repository.RemoveRepositorySourceMirrorResult) LoggerFactory(org.slf4j.LoggerFactory) RepositorySourceExtraIdentifier(org.haiku.haikudepotserver.dataobjects.RepositorySourceExtraIdentifier) StringUtils(org.apache.commons.lang3.StringUtils) RepositoryService(org.haiku.haikudepotserver.repository.model.RepositoryService) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) UpdateRepositorySourceMirrorResult(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositorySourceMirrorResult) org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror(org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror) PkgSearchSpecification(org.haiku.haikudepotserver.pkg.model.PkgSearchSpecification) SingleCollector(org.haiku.haikudepotserver.support.SingleCollector) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) RepositorySourceMirror(org.haiku.haikudepotserver.dataobjects.RepositorySourceMirror) Set(java.util.Set) SearchRepositoriesResult(org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesResult) UUID(java.util.UUID) GetRepositoriesResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositoriesResult) UpdateRepositorySourceResult(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositorySourceResult) Collectors(java.util.stream.Collectors) GetRepositorySourceMirrorRequest(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceMirrorRequest) List(java.util.List) GetRepositoryRequest(org.haiku.haikudepotserver.api1.model.repository.GetRepositoryRequest) UpdateRepositoryRequest(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositoryRequest) Repository(org.haiku.haikudepotserver.dataobjects.Repository) Optional(java.util.Optional) Country(org.haiku.haikudepotserver.dataobjects.Country) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) UpdateRepositoryResult(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositoryResult) TriggerImportRepositoryRequest(org.haiku.haikudepotserver.api1.model.repository.TriggerImportRepositoryRequest) ObjectContext(org.apache.cayenne.ObjectContext) Permission(org.haiku.haikudepotserver.security.model.Permission) ValidationException(org.haiku.haikudepotserver.api1.support.ValidationException) JobSnapshot(org.haiku.haikudepotserver.job.model.JobSnapshot) TriggerImportRepositoryResult(org.haiku.haikudepotserver.api1.model.repository.TriggerImportRepositoryResult) BooleanUtils(org.apache.commons.lang3.BooleanUtils) GetRepositorySourceResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceResult) PersistentObject(org.apache.cayenne.PersistentObject) CreateRepositorySourceResult(org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceResult) CollectionUtils(org.apache.commons.collections4.CollectionUtils) RemoveRepositorySourceMirrorRequest(org.haiku.haikudepotserver.api1.model.repository.RemoveRepositorySourceMirrorRequest) GetRepositoriesRequest(org.haiku.haikudepotserver.api1.model.repository.GetRepositoriesRequest) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) SetUtils(org.apache.commons.collections4.SetUtils) SearchRepositoriesRequest(org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesRequest) JobService(org.haiku.haikudepotserver.job.model.JobService) GetRepositoryResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositoryResult) Logger(org.slf4j.Logger) UpdateRepositorySourceRequest(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositorySourceRequest) AutoJsonRpcServiceImpl(com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) AccessDeniedException(org.springframework.security.access.AccessDeniedException) PermissionEvaluator(org.springframework.security.access.PermissionEvaluator) CreateRepositorySourceMirrorRequest(org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceMirrorRequest) RepositoryHpkrIngressJobSpecification(org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification) CreateRepositorySourceMirrorResult(org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceMirrorResult) Component(org.springframework.stereotype.Component) CreateRepositoryRequest(org.haiku.haikudepotserver.api1.model.repository.CreateRepositoryRequest) ObjectId(org.apache.cayenne.ObjectId) UpdateRepositorySourceMirrorRequest(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositorySourceMirrorRequest) Preconditions(com.google.common.base.Preconditions) RepositorySearchSpecification(org.haiku.haikudepotserver.repository.model.RepositorySearchSpecification) ValidationFailure(org.haiku.haikudepotserver.api1.support.ValidationFailure) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) Collections(java.util.Collections) GetRepositorySourceRequest(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceRequest) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Set(java.util.Set) HashSet(java.util.HashSet) Optional(java.util.Optional) UpdateRepositorySourceResult(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositorySourceResult) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) RepositorySourceExtraIdentifier(org.haiku.haikudepotserver.dataobjects.RepositorySourceExtraIdentifier) ObjectContext(org.apache.cayenne.ObjectContext) UpdateRepositorySourceRequest(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositorySourceRequest)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 AutoJsonRpcServiceImpl (com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 ObjectContext (org.apache.cayenne.ObjectContext)1 ObjectId (org.apache.cayenne.ObjectId)1 PersistentObject (org.apache.cayenne.PersistentObject)1 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1 SetUtils (org.apache.commons.collections4.SetUtils)1 BooleanUtils (org.apache.commons.lang3.BooleanUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 CreateRepositoryRequest (org.haiku.haikudepotserver.api1.model.repository.CreateRepositoryRequest)1 CreateRepositoryResult (org.haiku.haikudepotserver.api1.model.repository.CreateRepositoryResult)1