Search in sources :

Example 1 with SearchJobsResult

use of org.haiku.haikudepotserver.api1.model.job.SearchJobsResult in project haikudepotserver by haiku.

the class JobApiIT method testSearchJobs_startedOnly.

@Test
public void testSearchJobs_startedOnly() {
    setAuthenticatedUserToRoot();
    SearchJobsRequest request = new SearchJobsRequest();
    request.statuses = EnumSet.of(JobStatus.STARTED);
    // ------------------------------------
    SearchJobsResult result = jobApi.searchJobs(request);
    // ------------------------------------
    Assertions.assertThat(result.items.size()).isEqualTo(1);
    SearchJobsResult.Job job = result.items.get(0);
    Assertions.assertThat(job.guid).isEqualTo("started");
    Assertions.assertThat(job.queuedTimestamp.longValue()).isEqualTo(TestJobServiceImpl.DT_1976_FEB.toEpochMilli());
    Assertions.assertThat(job.startTimestamp.longValue()).isEqualTo(TestJobServiceImpl.DT_1976_MAR.toEpochMilli());
    Assertions.assertThat(job.finishTimestamp).isNull();
    Assertions.assertThat(job.ownerUserNickname).isNull();
    Assertions.assertThat(job.jobStatus).isEqualTo(JobStatus.STARTED);
}
Also used : SearchJobsRequest(org.haiku.haikudepotserver.api1.model.job.SearchJobsRequest) SearchJobsResult(org.haiku.haikudepotserver.api1.model.job.SearchJobsResult) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with SearchJobsResult

use of org.haiku.haikudepotserver.api1.model.job.SearchJobsResult in project haikudepotserver by haiku.

the class JobApiIT method testSearchJobs_userOnly.

@Test
public void testSearchJobs_userOnly() {
    {
        ObjectContext context = serverRuntime.newContext();
        // language is english
        User user = integrationTestSupportService.createBasicUser(context, "testuser", "yUe4o2Nwe009");
        integrationTestSupportService.agreeToUserUsageConditions(context, user);
        setAuthenticatedUser("testuser");
    }
    SearchJobsRequest request = new SearchJobsRequest();
    request.ownerUserNickname = "testuser";
    // ------------------------------------
    SearchJobsResult result = jobApi.searchJobs(request);
    // ------------------------------------
    Assertions.assertThat(result.items.size()).isEqualTo(1);
    SearchJobsResult.Job job = result.items.get(0);
    Assertions.assertThat(job.guid).isEqualTo("finished");
    Assertions.assertThat(job.queuedTimestamp.longValue()).isEqualTo(TestJobServiceImpl.DT_1976_APR.toEpochMilli());
    Assertions.assertThat(job.startTimestamp.longValue()).isEqualTo(TestJobServiceImpl.DT_1976_JUN.toEpochMilli());
    Assertions.assertThat(job.finishTimestamp.longValue()).isEqualTo(TestJobServiceImpl.DT_1976_JUL.toEpochMilli());
    Assertions.assertThat(job.ownerUserNickname).isEqualTo("testuser");
    Assertions.assertThat(job.jobStatus).isEqualTo(JobStatus.FINISHED);
}
Also used : User(org.haiku.haikudepotserver.dataobjects.User) SearchJobsRequest(org.haiku.haikudepotserver.api1.model.job.SearchJobsRequest) SearchJobsResult(org.haiku.haikudepotserver.api1.model.job.SearchJobsResult) ObjectContext(org.apache.cayenne.ObjectContext) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with SearchJobsResult

use of org.haiku.haikudepotserver.api1.model.job.SearchJobsResult in project haikudepotserver by haiku.

the class JobApiIT method testSearchJobs_all.

/**
 * <p>This test will find some data because it is sourced from {@link TestJobServiceImpl}.</p>
 */
@Test
public void testSearchJobs_all() {
    setAuthenticatedUserToRoot();
    // ------------------------------------
    SearchJobsResult result = jobApi.searchJobs(new SearchJobsRequest());
    // ------------------------------------
    Assertions.assertThat(result.items.size()).isEqualTo(3);
}
Also used : SearchJobsRequest(org.haiku.haikudepotserver.api1.model.job.SearchJobsRequest) SearchJobsResult(org.haiku.haikudepotserver.api1.model.job.SearchJobsResult) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with SearchJobsResult

use of org.haiku.haikudepotserver.api1.model.job.SearchJobsResult in project haikudepotserver by haiku.

the class JobApiImpl method searchJobs.

@Override
public SearchJobsResult searchJobs(SearchJobsRequest request) {
    Preconditions.checkArgument(null != request);
    final SearchJobsResult result = new SearchJobsResult();
    final ObjectContext context = serverRuntime.newContext();
    User ownerUser = null;
    if (Strings.isNullOrEmpty(request.ownerUserNickname)) {
        if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.JOBS_VIEW)) {
            throw new AccessDeniedException("attempt to access jobs view");
        }
    } else {
        ownerUser = User.tryGetByNickname(context, request.ownerUserNickname).orElseThrow(() -> new ObjectNotFoundException(User.class.getSimpleName(), request.ownerUserNickname));
        if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), ownerUser, Permission.USER_VIEWJOBS)) {
            throw new AccessDeniedException("attempt to access jobs view for [" + ownerUser + "]");
        }
    }
    if (null != request.statuses && request.statuses.isEmpty()) {
        result.items = Collections.emptyList();
        result.total = 0L;
    } else {
        Set<JobSnapshot.Status> statuses = null;
        if (null != request.statuses) {
            statuses = request.statuses.stream().map(s -> JobSnapshot.Status.valueOf(s.name())).collect(Collectors.toSet());
        }
        result.total = (long) jobService.totalJobs(ownerUser, statuses);
        result.items = jobService.findJobs(ownerUser, statuses, null == request.offset ? 0 : request.offset, null == request.limit ? Integer.MAX_VALUE : request.limit).stream().map(js -> {
            SearchJobsResult.Job resultJob = new SearchJobsResult.Job();
            resultJob.guid = js.getGuid();
            resultJob.jobStatus = JobStatus.valueOf(js.getStatus().name());
            resultJob.jobTypeCode = js.getJobTypeCode();
            resultJob.ownerUserNickname = js.getOwnerUserNickname();
            resultJob.startTimestamp = null == js.getStartTimestamp() ? null : js.getStartTimestamp().getTime();
            resultJob.finishTimestamp = null == js.getFinishTimestamp() ? null : js.getFinishTimestamp().getTime();
            resultJob.queuedTimestamp = null == js.getQueuedTimestamp() ? null : js.getQueuedTimestamp().getTime();
            resultJob.failTimestamp = null == js.getFailTimestamp() ? null : js.getFailTimestamp().getTime();
            resultJob.cancelTimestamp = null == js.getCancelTimestamp() ? null : js.getCancelTimestamp().getTime();
            resultJob.progressPercent = js.getProgressPercent();
            return resultJob;
        }).collect(Collectors.toList());
        LOGGER.info("search for jobs found {} results", result.items.size());
    }
    return result;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) User(org.haiku.haikudepotserver.dataobjects.User) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) ObjectContext(org.apache.cayenne.ObjectContext)

Aggregations

AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)3 SearchJobsRequest (org.haiku.haikudepotserver.api1.model.job.SearchJobsRequest)3 SearchJobsResult (org.haiku.haikudepotserver.api1.model.job.SearchJobsResult)3 Test (org.junit.jupiter.api.Test)3 ObjectContext (org.apache.cayenne.ObjectContext)2 User (org.haiku.haikudepotserver.dataobjects.User)2 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1