Search in sources :

Example 1 with RepositoryHpkrIngressJobSpecification

use of org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification in project haikudepotserver by haiku.

the class RepositoryController method importRepositorySource.

/**
 * <p>Instructs HDS to import repository data for a repository source of
 * a repository.</p>
 */
@RequestMapping(value = "{" + KEY_REPOSITORYCODE + "}/" + SEGMENT_SOURCE + "/{" + KEY_REPOSITORYSOURCECODE + "}/" + SEGMENT_IMPORT, method = RequestMethod.POST)
public ResponseEntity<String> importRepositorySource(@PathVariable(value = KEY_REPOSITORYCODE) String repositoryCode, @PathVariable(value = KEY_REPOSITORYSOURCECODE) String repositorySourceCode) {
    ObjectContext context = serverRuntime.newContext();
    Optional<Repository> repositoryOptional = Repository.tryGetByCode(context, repositoryCode);
    if (repositoryOptional.isEmpty()) {
        return new ResponseEntity<>("repository not found", HttpStatus.NOT_FOUND);
    }
    Optional<RepositorySource> repositorySourceOptional = RepositorySource.tryGetByCode(context, repositorySourceCode);
    if (repositorySourceOptional.isEmpty() || !repositoryOptional.get().equals(repositorySourceOptional.get().getRepository())) {
        return new ResponseEntity<>("repository source not found", HttpStatus.NOT_FOUND);
    }
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), repositoryOptional.get(), Permission.REPOSITORY_IMPORT)) {
        throw new AccessDeniedException("unable to import repository [" + repositoryOptional.get() + "]");
    }
    jobService.submit(new RepositoryHpkrIngressJobSpecification(repositoryCode, Collections.singleton(repositorySourceCode)), JobSnapshot.COALESCE_STATUSES_QUEUED);
    return ResponseEntity.ok("repository source import submitted");
}
Also used : Repository(org.haiku.haikudepotserver.dataobjects.Repository) ResponseEntity(org.springframework.http.ResponseEntity) AccessDeniedException(org.springframework.security.access.AccessDeniedException) RepositoryHpkrIngressJobSpecification(org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) ObjectContext(org.apache.cayenne.ObjectContext) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RepositoryHpkrIngressJobSpecification

use of org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification in project haikudepotserver by haiku.

the class RepositoryHpkrIngressJobRunner method run.

@Override
public void run(JobService jobService, RepositoryHpkrIngressJobSpecification specification) {
    Preconditions.checkNotNull(specification);
    ObjectContext mainContext = serverRuntime.newContext();
    Set<String> allowedRepositorySourceCodes = specification.getRepositorySourceCodes();
    RepositorySource.findActiveByRepository(mainContext, Repository.getByCode(mainContext, specification.getRepositoryCode())).stream().filter(rs -> null == allowedRepositorySourceCodes || allowedRepositorySourceCodes.contains(rs.getCode())).forEach(rs -> serverRuntime.performInTransaction(() -> {
        try {
            runForRepositorySource(mainContext, rs);
        } catch (Throwable e) {
            LOGGER.error("a problem has arisen processing a repository file for repository source [{}]", rs.getCode(), e);
        }
        return null;
    }));
}
Also used : PkgService(org.haiku.haikudepotserver.pkg.model.PkgService) ObjectContext(org.apache.cayenne.ObjectContext) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) DriverSettings(org.haiku.driversettings.DriverSettings) StringUtils(org.apache.commons.lang3.StringUtils) Value(org.springframework.beans.factory.annotation.Value) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Pkg(org.haiku.pkg.model.Pkg) JobService(org.haiku.haikudepotserver.job.model.JobService) PkgImportService(org.haiku.haikudepotserver.pkg.model.PkgImportService) Charsets(com.google.common.base.Charsets) Logger(org.slf4j.Logger) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) RepositoryHpkrIngressException(org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressException) AbstractJobRunner(org.haiku.haikudepotserver.job.AbstractJobRunner) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) Set(java.util.Set) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) Sets(com.google.common.collect.Sets) FileHelper(org.haiku.haikudepotserver.support.FileHelper) File(java.io.File) RepositoryHpkrIngressJobSpecification(org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification) Parameter(org.haiku.driversettings.Parameter) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Component(org.springframework.stereotype.Component) List(java.util.List) Repository(org.haiku.haikudepotserver.dataobjects.Repository) DriverSettingsException(org.haiku.driversettings.DriverSettingsException) HpkrFileExtractor(org.haiku.pkg.HpkrFileExtractor) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) BufferedReader(java.io.BufferedReader) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) PkgIterator(org.haiku.pkg.PkgIterator) InputStream(java.io.InputStream) ObjectContext(org.apache.cayenne.ObjectContext)

Example 3 with RepositoryHpkrIngressJobSpecification

use of org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification in project haikudepotserver by haiku.

the class RepositoryHpkrIngressServiceIT method testImportThenCheck.

@Test
public void testImportThenCheck() throws Exception {
    File temporaryDir;
    File temporaryRepoFile = null;
    File temporaryRepoInfoFile = null;
    try {
        temporaryDir = Files.createTempDir();
        temporaryRepoFile = new File(temporaryDir, "repo");
        temporaryRepoInfoFile = new File(temporaryDir, "repo.info");
        // get the test hpkr data and copy it into a temporary file that can be used as a source
        // for a repository.
        Files.write(getResourceData("sample-repo.info"), temporaryRepoInfoFile);
        Files.write(getResourceData("sample-repo.hpkr"), temporaryRepoFile);
        // first setup a fake repository to import that points at the local test HPKR file.
        {
            ObjectContext context = serverRuntime.newContext();
            Repository repository = context.newObject(Repository.class);
            repository.setCode("test");
            repository.setName("Test Repository");
            RepositorySource repositorySource = context.newObject(RepositorySource.class);
            repositorySource.setCode("testsrc_xyz");
            repositorySource.setIdentifier("file://" + temporaryDir.getAbsolutePath());
            repository.addToManyTarget(Repository.REPOSITORY_SOURCES.getName(), repositorySource, true);
            RepositorySourceMirror repositorySourceMirror = context.newObject(RepositorySourceMirror.class);
            repositorySourceMirror.setBaseUrl("file://" + temporaryDir.getAbsolutePath());
            repositorySourceMirror.setIsPrimary(true);
            repositorySourceMirror.setCode("testsrc_xyz_mirror");
            repositorySourceMirror.setCountry(Country.getByCode(context, Country.CODE_NZ));
            repositorySource.addToManyTarget(RepositorySource.REPOSITORY_SOURCE_MIRRORS.getName(), repositorySourceMirror, true);
            context.commitChanges();
        }
        // setup another repository that is not related to the import test to check some stuff...
        {
            ObjectContext context = serverRuntime.newContext();
            Repository repository = context.newObject(Repository.class);
            repository.setCode("test2");
            repository.setName("Test 2");
            RepositorySource repositorySource = context.newObject(RepositorySource.class);
            repositorySource.setCode("testsrc2_xyz");
            // just after epoc second.
            repositorySource.setLastImportTimestamp(new java.sql.Timestamp(12345L));
            repository.addToManyTarget(Repository.REPOSITORY_SOURCES.getName(), repositorySource, true);
            RepositorySourceMirror repositorySourceMirror = context.newObject(RepositorySourceMirror.class);
            repositorySourceMirror.setBaseUrl("file://does-not-exist/path");
            repositorySourceMirror.setIsPrimary(true);
            repositorySourceMirror.setCode("testsrc2_xyz_mirror");
            repositorySourceMirror.setCountry(Country.getByCode(context, Country.CODE_NZ));
            repositorySource.addToManyTarget(RepositorySource.REPOSITORY_SOURCE_MIRRORS.getName(), repositorySourceMirror, true);
            context.commitChanges();
        }
        // add a package version from this repository that is known not to be in that example and then
        // latterly check that the package version is no longer active.
        {
            ObjectContext context = serverRuntime.newContext();
            Pkg pkg = integrationTestSupportService.createPkg(context, "taranaki");
            pkgService.ensurePkgProminence(context, pkg, Repository.tryGetByCode(context, "test").get());
            pkgService.ensurePkgProminence(context, pkg, Repository.tryGetByCode(context, "test2").get());
            // this one should get deactivated
            {
                PkgVersion pkgVersion = context.newObject(PkgVersion.class);
                pkgVersion.setPkg(pkg);
                pkgVersion.setMajor("1");
                pkgVersion.setMinor("2");
                pkgVersion.setArchitecture(Architecture.tryGetByCode(context, "x86_64").get());
                pkgVersion.setIsLatest(true);
                pkgVersion.setRepositorySource(RepositorySource.tryGetByCode(context, "testsrc_xyz").get());
            }
            // this one should remain
            {
                PkgVersion pkgVersion = context.newObject(PkgVersion.class);
                pkgVersion.setPkg(pkg);
                pkgVersion.setMajor("1");
                pkgVersion.setMinor("3");
                pkgVersion.setArchitecture(Architecture.tryGetByCode(context, "x86_64").get());
                pkgVersion.setIsLatest(true);
                pkgVersion.setRepositorySource(RepositorySource.tryGetByCode(context, "testsrc2_xyz").get());
            }
            context.commitChanges();
        }
        // add an inactive package version from this repository that is known to be in the repository.  This
        // package should be activated and re-used.
        ObjectId originalFfmpegPkgOid;
        {
            ObjectContext context = serverRuntime.newContext();
            Pkg pkg = integrationTestSupportService.createPkg(context, "ffmpeg");
            pkgService.ensurePkgProminence(context, pkg, Repository.tryGetByCode(context, "test").get());
            pkgService.ensurePkgProminence(context, pkg, Repository.tryGetByCode(context, "test2").get());
            PkgVersion pkgVersion = context.newObject(PkgVersion.class);
            pkgVersion.setPkg(pkg);
            pkgVersion.setMajor("3");
            pkgVersion.setMinor("3");
            pkgVersion.setMicro("2");
            pkgVersion.setRevision(1);
            pkgVersion.setArchitecture(Architecture.tryGetByCode(context, "x86_64").get());
            pkgVersion.setIsLatest(true);
            // to be sure!
            pkgVersion.setActive(false);
            pkgVersion.setRepositorySource(RepositorySource.tryGetByCode(context, "testsrc_xyz").get());
            PkgVersionUrl pkgVersionUrl = context.newObject(PkgVersionUrl.class);
            pkgVersionUrl.setPkgUrlType(PkgUrlType.getByCode(context, org.haiku.pkg.model.PkgUrlType.HOMEPAGE.name().toLowerCase()).get());
            pkgVersionUrl.setUrl("http://noop");
            pkgVersion.addToManyTarget(PkgVersion.PKG_VERSION_URLS.getName(), pkgVersionUrl, true);
            PkgVersionCopyright pkgVersionCopyright = context.newObject(PkgVersionCopyright.class);
            pkgVersionCopyright.setBody("Norfolk pine");
            pkgVersion.addToManyTarget(PkgVersion.PKG_VERSION_COPYRIGHTS.getName(), pkgVersionCopyright, true);
            PkgVersionLicense pkgVersionLicense = context.newObject(PkgVersionLicense.class);
            pkgVersionLicense.setBody("Punga");
            pkgVersion.addToManyTarget(PkgVersion.PKG_VERSION_LICENSES.getName(), pkgVersionLicense, true);
            context.commitChanges();
            originalFfmpegPkgOid = pkgVersion.getObjectId();
        }
        // do the import.
        String guid = jobService.submit(new RepositoryHpkrIngressJobSpecification("test"), JobSnapshot.COALESCE_STATUSES_NONE);
        // wait for it to finish.
        {
            long startMs = System.currentTimeMillis();
            while (Jobs.isQueuedOrStarted(jobService.tryGetJob(guid).get()) && (System.currentTimeMillis() - startMs) < DELAY_PROCESSSUBMITTEDTESTJOB) {
                Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
            }
            if (Jobs.isQueuedOrStarted(jobService.tryGetJob(guid).get())) {
                throw new IllegalStateException("test processing of the sample repo has taken > " + DELAY_PROCESSSUBMITTEDTESTJOB + "ms");
            }
        }
        // check that the sample url is loaded into the repository source.
        {
            ObjectContext context = serverRuntime.newContext();
            RepositorySource repositorySource = RepositorySource.tryGetByCode(context, "testsrc_xyz").get();
            Assertions.assertThat(repositorySource.getIdentifier()).isEqualTo("f0c086e5-e096-429c-b38d-57beabd764e9");
            // ^^ as defined in the repo info file.
            Assertions.assertThat(repositorySource.getArchitecture().getCode()).isEqualTo("x86_gcc2");
        // ^^ as defined in the repo info file.
        }
        // now pull out some known packages and make sure they are imported correctly.
        // TODO - this is a fairly simplistic test; do some more checks.
        {
            ObjectContext context = serverRuntime.newContext();
            verifyPackage(context, "apr");
            verifyPackage(context, "schroedinger");
            // this one is not in the import and so should be inactive afterwards.
            List<PkgVersion> pkgVersions = ObjectSelect.query(PkgVersion.class).where(PkgVersion.PKG.dot(Pkg.NAME).eq("taranaki")).select(context);
            Assertions.assertThat(pkgVersions.size()).isEqualTo(2);
            for (PkgVersion pkgVersion : pkgVersions) {
                boolean isTestRepository = pkgVersion.getRepositorySource().getRepository().getCode().equals("test");
                Assertions.assertThat(pkgVersion.getActive()).isEqualTo(!isTestRepository);
            }
            // check that the ffmpeg package was re-used and populated; as an example.
            {
                PkgVersion pkgVersion = PkgVersion.get(context, originalFfmpegPkgOid);
                Assertions.assertThat(pkgVersion.getActive()).isTrue();
                Assertions.assertThat(pkgVersion.getIsLatest()).isTrue();
                Assertions.assertThat(PkgVersion.getForPkg(context, pkgVersion.getPkg(), Repository.tryGetByCode(context, "test").get(), true).size()).isEqualTo(// include inactive
                1);
                PkgVersionLocalization localization = pkgVersion.getPkgVersionLocalization(NaturalLanguage.getByCode(context, NaturalLanguage.CODE_ENGLISH)).get();
                Assertions.assertThat(localization.getDescription().get()).startsWith("FFmpeg is a complete, cro");
                Assertions.assertThat(localization.getSummary().get()).startsWith("Audio and video rec");
                // the former rubbish copyright is removed
                List<String> copyrights = pkgVersion.getCopyrights();
                Assertions.assertThat(copyrights.size()).isEqualTo(2);
                Assertions.assertThat(ImmutableSet.copyOf(copyrights)).containsOnly("2000-2003 Fabrice Bellard", "2003-2017 the FFmpeg developers");
                // the former rubbish license is removed
                List<String> licenses = pkgVersion.getLicenses();
                Assertions.assertThat(licenses.size()).isEqualTo(2);
                Assertions.assertThat(ImmutableSet.copyOf(licenses)).containsOnly("GNU LGPL v2.1", "GNU GPL v2");
                Optional<PkgVersionUrl> pkgVersionUrlOptional = pkgVersion.getPkgVersionUrlForType(PkgUrlType.getByCode(context, org.haiku.pkg.model.PkgUrlType.HOMEPAGE.name().toLowerCase()).get());
                Assertions.assertThat(pkgVersionUrlOptional.isPresent()).isTrue();
                Assertions.assertThat(pkgVersionUrlOptional.get().getUrl()).isEqualTo("https://ffmpeg.org/");
            }
        }
    } finally {
        if (null != temporaryRepoFile) {
            if (!temporaryRepoFile.delete()) {
                LOGGER.warn("unable to delete the temporary 'repo' file");
            }
        }
        if (null != temporaryRepoInfoFile) {
            if (!temporaryRepoInfoFile.delete()) {
                LOGGER.warn("unable to delete the temporary 'repo.info' file");
            }
        }
    }
}
Also used : PkgVersionLocalization(org.haiku.haikudepotserver.dataobjects.PkgVersionLocalization) PkgVersionLicense(org.haiku.haikudepotserver.dataobjects.PkgVersionLicense) RepositoryHpkrIngressJobSpecification(org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification) ObjectId(org.apache.cayenne.ObjectId) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) Repository(org.haiku.haikudepotserver.dataobjects.Repository) RepositorySourceMirror(org.haiku.haikudepotserver.dataobjects.RepositorySourceMirror) PkgVersionUrl(org.haiku.haikudepotserver.dataobjects.PkgVersionUrl) PkgVersionCopyright(org.haiku.haikudepotserver.dataobjects.PkgVersionCopyright) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) List(java.util.List) ObjectContext(org.apache.cayenne.ObjectContext) File(java.io.File) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with RepositoryHpkrIngressJobSpecification

use of org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification in project haikudepotserver by haiku.

the class RepositoryApiImpl method triggerImportRepository.

// note; no integration test for this one.
@Override
public TriggerImportRepositoryResult triggerImportRepository(TriggerImportRepositoryRequest triggerImportRepositoryRequest) {
    Preconditions.checkNotNull(triggerImportRepositoryRequest);
    Preconditions.checkState(!Strings.isNullOrEmpty(triggerImportRepositoryRequest.repositoryCode));
    Preconditions.checkArgument(null == triggerImportRepositoryRequest.repositorySourceCodes || !triggerImportRepositoryRequest.repositorySourceCodes.isEmpty(), "bad repository sources");
    final ObjectContext context = serverRuntime.newContext();
    Optional<Repository> repositoryOptional = Repository.tryGetByCode(context, triggerImportRepositoryRequest.repositoryCode);
    if (repositoryOptional.isEmpty()) {
        throw new ObjectNotFoundException(Repository.class.getSimpleName(), triggerImportRepositoryRequest.repositoryCode);
    }
    Repository repository = repositoryOptional.get();
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), repository, Permission.REPOSITORY_IMPORT)) {
        throw new AccessDeniedException("attempt to trigger repository import for [" + repository + "]");
    }
    Set<RepositorySource> repositorySources = null;
    if (null != triggerImportRepositoryRequest.repositorySourceCodes) {
        repositorySources = new HashSet<>();
        for (String repositorySourceCode : triggerImportRepositoryRequest.repositorySourceCodes) {
            repositorySources.add(repository.getRepositorySources().stream().filter(rs -> rs.getCode().equals(repositorySourceCode)).collect(SingleCollector.optional()).orElseThrow(() -> new ObjectNotFoundException(RepositorySource.class.getSimpleName(), repositorySourceCode)));
        }
    }
    jobService.submit(new RepositoryHpkrIngressJobSpecification(repository.getCode(), null == repositorySources ? null : repositorySources.stream().map(RepositorySource::getCode).collect(Collectors.toSet())), JobSnapshot.COALESCE_STATUSES_QUEUED);
    return new TriggerImportRepositoryResult();
}
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) Repository(org.haiku.haikudepotserver.dataobjects.Repository) AccessDeniedException(org.springframework.security.access.AccessDeniedException) RepositoryHpkrIngressJobSpecification(org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) ObjectContext(org.apache.cayenne.ObjectContext) TriggerImportRepositoryResult(org.haiku.haikudepotserver.api1.model.repository.TriggerImportRepositoryResult)

Example 5 with RepositoryHpkrIngressJobSpecification

use of org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification in project haikudepotserver by haiku.

the class RepositoryController method importRepository.

/**
 * <p>Instructs HDS to start importing data for all repository sources of
 * the nominated repository</p>
 */
@RequestMapping(value = "{" + KEY_REPOSITORYCODE + "}/" + SEGMENT_IMPORT, method = RequestMethod.POST)
public ResponseEntity<String> importRepository(@PathVariable(value = KEY_REPOSITORYCODE) String repositoryCode) {
    ObjectContext context = serverRuntime.newContext();
    Optional<Repository> repositoryOptional = Repository.tryGetByCode(context, repositoryCode);
    if (repositoryOptional.isEmpty()) {
        return new ResponseEntity<>("repository not found", HttpStatus.NOT_FOUND);
    }
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), repositoryOptional.get(), Permission.REPOSITORY_IMPORT)) {
        throw new AccessDeniedException("unable to import repository [" + repositoryOptional.get() + "]");
    }
    jobService.submit(new RepositoryHpkrIngressJobSpecification(repositoryCode), JobSnapshot.COALESCE_STATUSES_QUEUED);
    return ResponseEntity.ok("repository import submitted");
}
Also used : Repository(org.haiku.haikudepotserver.dataobjects.Repository) ResponseEntity(org.springframework.http.ResponseEntity) AccessDeniedException(org.springframework.security.access.AccessDeniedException) RepositoryHpkrIngressJobSpecification(org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification) ObjectContext(org.apache.cayenne.ObjectContext) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)5 Repository (org.haiku.haikudepotserver.dataobjects.Repository)5 RepositoryHpkrIngressJobSpecification (org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification)5 RepositorySource (org.haiku.haikudepotserver.dataobjects.RepositorySource)4 List (java.util.List)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)3 Preconditions (com.google.common.base.Preconditions)2 File (java.io.File)2 Optional (java.util.Optional)2 Set (java.util.Set)2 ObjectId (org.apache.cayenne.ObjectId)2 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)2 StringUtils (org.apache.commons.lang3.StringUtils)2 RepositorySourceMirror (org.haiku.haikudepotserver.dataobjects.RepositorySourceMirror)2 Charsets (com.google.common.base.Charsets)1 Strings (com.google.common.base.Strings)1 Sets (com.google.common.collect.Sets)1 AutoJsonRpcServiceImpl (com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1