Search in sources :

Example 26 with Repository

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

the class PkgApiIT method testIncrementViewCounter.

@Test
public void testIncrementViewCounter() {
    integrationTestSupportService.createStandardTestData();
    IncrementViewCounterRequest request = new IncrementViewCounterRequest();
    request.major = "1";
    request.micro = "2";
    request.revision = 3;
    request.name = "pkg1";
    request.architectureCode = "x86_64";
    request.repositoryCode = "testrepo";
    // ------------------------------------
    IncrementViewCounterResult result = pkgApi.incrementViewCounter(request);
    // ------------------------------------
    Assertions.assertThat(result).isNotNull();
    {
        ObjectContext context = serverRuntime.newContext();
        Pkg pkg1 = Pkg.getByName(context, "pkg1");
        Repository repository = Repository.getByCode(context, "testrepo");
        Architecture architecture = Architecture.getByCode(context, "x86_64");
        PkgVersion pkgVersion = PkgVersion.getForPkg(context, pkg1, repository, architecture, new VersionCoordinates("1", null, "2", null, 3)).get();
        Assertions.assertThat(pkgVersion.getViewCounter()).isEqualTo(1L);
    }
}
Also used : IncrementViewCounterRequest(org.haiku.haikudepotserver.api1.model.pkg.IncrementViewCounterRequest) Repository(org.haiku.haikudepotserver.dataobjects.Repository) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) VersionCoordinates(org.haiku.haikudepotserver.support.VersionCoordinates) IncrementViewCounterResult(org.haiku.haikudepotserver.api1.model.pkg.IncrementViewCounterResult) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 27 with Repository

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

the class PkgApiIT method updatePkgVersion_deactivate.

@Test
public void updatePkgVersion_deactivate() {
    integrationTestSupportService.createStandardTestData();
    setAuthenticatedUserToRoot();
    UpdatePkgVersionRequest request = new UpdatePkgVersionRequest();
    request.pkgName = "pkg1";
    request.repositoryCode = "testrepo";
    request.architectureCode = "x86_64";
    request.major = "1";
    request.micro = "2";
    request.revision = 3;
    request.filter = Collections.singletonList(UpdatePkgVersionRequest.Filter.ACTIVE);
    request.active = false;
    // ------------------------------------
    pkgApi.updatePkgVersion(request);
    // ------------------------------------
    {
        ObjectContext context = serverRuntime.newContext();
        Pkg pkg1 = Pkg.getByName(context, "pkg1");
        Repository repository = Repository.getByCode(context, "testrepo");
        Architecture architecture = Architecture.getByCode(context, "x86_64");
        PkgVersion pkgVersion = PkgVersion.getForPkg(context, pkg1, repository, architecture, new VersionCoordinates("1", null, "2", null, 3)).get();
        Assertions.assertThat(pkgVersion.getActive()).isFalse();
    }
}
Also used : Repository(org.haiku.haikudepotserver.dataobjects.Repository) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) VersionCoordinates(org.haiku.haikudepotserver.support.VersionCoordinates) UpdatePkgVersionRequest(org.haiku.haikudepotserver.api1.model.pkg.UpdatePkgVersionRequest) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 28 with Repository

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

the class RepositoryApiIT method testUpdateRepository_password.

@Test
public void testUpdateRepository_password() {
    IntegrationTestSupportService.StandardTestData data = integrationTestSupportService.createStandardTestData();
    Assertions.assertThat(data.repository.getPasswordHash()).isNull();
    setAuthenticatedUserToRoot();
    UpdateRepositoryRequest request = new UpdateRepositoryRequest();
    request.code = "testrepo";
    request.active = false;
    request.passwordClear = "Quatsch";
    request.filter = Collections.singletonList(UpdateRepositoryRequest.Filter.PASSWORD);
    // ------------------------------------
    repositoryApi.updateRepository(request);
    // ------------------------------------
    ObjectContext context = serverRuntime.newContext();
    Repository repository = ObjectSelect.query(Repository.class).where(Repository.CODE.eq(data.repository.getCode())).selectOne(context);
    Assertions.assertThat(repository.getPasswordHash()).matches("^[A-Za-z0-9]+$");
}
Also used : UpdateRepositoryRequest(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositoryRequest) Repository(org.haiku.haikudepotserver.dataobjects.Repository) ObjectContext(org.apache.cayenne.ObjectContext) IntegrationTestSupportService(org.haiku.haikudepotserver.IntegrationTestSupportService) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 29 with Repository

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

the class UserRatingSpreadsheetJobRunner method run.

@Override
public void run(JobService jobService, UserRatingSpreadsheetJobSpecification specification) throws IOException {
    Preconditions.checkArgument(null != jobService);
    Preconditions.checkArgument(null != specification);
    final ObjectContext context = serverRuntime.newContext();
    // this will register the outbound data against the job.
    JobDataWithByteSink jobDataWithByteSink = jobService.storeGeneratedData(specification.getGuid(), "download", MediaType.CSV_UTF_8.toString());
    try (OutputStream outputStream = jobDataWithByteSink.getByteSink().openBufferedStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);
        CSVWriter writer = new CSVWriter(outputStreamWriter, ',')) {
        Optional<Pkg> paramPkgOptional = Optional.empty();
        Optional<User> paramUserOptional = Optional.empty();
        Optional<Repository> paramRepositoryOptional = Optional.empty();
        if (!Strings.isNullOrEmpty(specification.getRepositoryCode())) {
            paramRepositoryOptional = Repository.tryGetByCode(context, specification.getRepositoryCode());
            if (!paramRepositoryOptional.isPresent()) {
                throw new IllegalStateException("unable to find the repository; " + specification.getRepositoryCode());
            }
        }
        if (!Strings.isNullOrEmpty(specification.getUserNickname())) {
            paramUserOptional = User.tryGetByNickname(context, specification.getUserNickname());
            if (!paramUserOptional.isPresent()) {
                throw new IllegalStateException("unable to find the user; " + specification.getUserNickname());
            }
        }
        if (!Strings.isNullOrEmpty(specification.getPkgName())) {
            paramPkgOptional = Pkg.tryGetByName(context, specification.getPkgName());
            if (!paramPkgOptional.isPresent()) {
                throw new IllegalStateException("unable to find the package; " + specification.getPkgName());
            }
        }
        writer.writeNext(new String[] { "pkg-name", "repository-code", "architecture-code", "version-coordinates", "user-nickname", "create-timestamp", "modify-timestamp", "rating", "stability-code", "natural-language-code", "comment", "code" });
        // stream out the packages.
        long startMs = System.currentTimeMillis();
        LOGGER.info("will user rating spreadsheet report");
        final DateTimeFormatter dateTimeFormatter = DateTimeHelper.createStandardDateTimeFormat();
        UserRatingSearchSpecification spec = new UserRatingSearchSpecification();
        spec.setPkg(paramPkgOptional.orElse(null));
        spec.setUser(paramUserOptional.orElse(null));
        spec.setRepository(paramRepositoryOptional.orElse(null));
        // TODO; provide a prefetch tree into the user, pkgversion.
        int count = userRatingService.each(context, spec, userRating -> {
            writer.writeNext(new String[] { userRating.getPkgVersion().getPkg().getName(), userRating.getPkgVersion().getRepositorySource().getRepository().getCode(), userRating.getPkgVersion().getArchitecture().getCode(), userRating.getPkgVersion().toVersionCoordinates().toString(), userRating.getUser().getNickname(), dateTimeFormatter.format(Instant.ofEpochMilli(userRating.getCreateTimestamp().getTime())), dateTimeFormatter.format(Instant.ofEpochMilli(userRating.getModifyTimestamp().getTime())), null != userRating.getRating() ? userRating.getRating().toString() : "", null != userRating.getUserRatingStability() ? userRating.getUserRatingStability().getCode() : "", userRating.getNaturalLanguage().getCode(), userRating.getComment(), userRating.getCode() });
            return true;
        });
        LOGGER.info("did produce user rating spreadsheet report for {} user ratings in {}ms", count, System.currentTimeMillis() - startMs);
    }
}
Also used : User(org.haiku.haikudepotserver.dataobjects.User) OutputStream(java.io.OutputStream) CSVWriter(com.opencsv.CSVWriter) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) JobDataWithByteSink(org.haiku.haikudepotserver.job.model.JobDataWithByteSink) Repository(org.haiku.haikudepotserver.dataobjects.Repository) UserRatingSearchSpecification(org.haiku.haikudepotserver.userrating.model.UserRatingSearchSpecification) OutputStreamWriter(java.io.OutputStreamWriter) ObjectContext(org.apache.cayenne.ObjectContext) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 30 with Repository

use of org.haiku.haikudepotserver.dataobjects.Repository 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

Repository (org.haiku.haikudepotserver.dataobjects.Repository)30 ObjectContext (org.apache.cayenne.ObjectContext)26 List (java.util.List)9 RepositorySource (org.haiku.haikudepotserver.dataobjects.RepositorySource)9 AccessDeniedException (org.springframework.security.access.AccessDeniedException)9 Optional (java.util.Optional)8 Architecture (org.haiku.haikudepotserver.dataobjects.Architecture)8 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)7 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)7 RepositoryHpkrIngressJobSpecification (org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification)7 Test (org.junit.jupiter.api.Test)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Preconditions (com.google.common.base.Preconditions)6 UpdateRepositoryRequest (org.haiku.haikudepotserver.api1.model.repository.UpdateRepositoryRequest)6 Pkg (org.haiku.haikudepotserver.dataobjects.Pkg)6 Component (org.springframework.stereotype.Component)6 ObjectId (org.apache.cayenne.ObjectId)5 StringUtils (org.apache.commons.lang3.StringUtils)5 OutputStream (java.io.OutputStream)4