• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IQSS / dataverse / #24958

10 Mar 2025 05:32PM CUT coverage: 22.614%. Remained the same
#24958

Pull #11325

github

stevenwinship
extend size of deaccessionlink column
Pull Request #11325: extend size of deaccessionlink column

20033 of 88586 relevant lines covered (22.61%)

0.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/edu/harvard/iq/dataverse/api/batchjob/BatchJobResource.java
1
package edu.harvard.iq.dataverse.api.batchjob;
2

3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import edu.harvard.iq.dataverse.api.AbstractApiBean;
5
import edu.harvard.iq.dataverse.batch.entities.JobExecutionEntity;
6

7
import jakarta.batch.operations.JobOperator;
8
import jakarta.batch.runtime.BatchRuntime;
9
import jakarta.batch.runtime.JobExecution;
10
import jakarta.batch.runtime.JobInstance;
11
import jakarta.ejb.Stateless;
12
import jakarta.ws.rs.GET;
13
import jakarta.ws.rs.Path;
14
import jakarta.ws.rs.PathParam;
15
import jakarta.ws.rs.Produces;
16
import jakarta.ws.rs.core.MediaType;
17
import jakarta.ws.rs.core.Response;
18
import java.util.ArrayList;
19
import java.util.List;
20
import java.util.Set;
21

22

23
@Stateless
24
@Path("admin/batch")
25
public class BatchJobResource extends AbstractApiBean {
×
26

27
    private static String EMPTY_JSON_LIST = "[]";
×
28
    private static String EMPTY_JSON_OBJ = "{}";
×
29
    private static ObjectMapper mapper = new ObjectMapper();
×
30

31
    @GET
32
    @Path("/jobs")
33
    @Produces(MediaType.APPLICATION_JSON)
34
    public Response listBatchJobs() {
35
        try {
36
            final List<JobExecutionEntity> executionEntities = new ArrayList<>();
×
37
            final JobOperator jobOperator = BatchRuntime.getJobOperator();
×
38
            final Set<String> names = jobOperator.getJobNames();
×
39
            for (String name : names) {
×
40
                final int end = jobOperator.getJobInstanceCount(name);
×
41
                final List<JobInstance> jobInstances = jobOperator.getJobInstances(name, 0, end);
×
42
                for (JobInstance jobInstance : jobInstances) {
×
43
                    final List<JobExecution> executions = jobOperator.getJobExecutions(jobInstance);
×
44
                    for (JobExecution execution : executions) {
×
45
                        executionEntities.add(JobExecutionEntity.create(execution));
×
46
                    }
×
47
                }
×
48
            }
×
49
            return Response.ok("{ \"jobs\": \n" + mapper.writeValueAsString(executionEntities) + "\n}").build();
×
50
        } catch (Exception e) {
×
51
            return Response.ok(EMPTY_JSON_LIST).build();
×
52
        }
53
    }
54

55
    @GET
56
    @Path("/jobs/name/{jobName}")
57
    @Produces(MediaType.APPLICATION_JSON)
58
    public Response listBatchJobsByName( @PathParam("jobName") String jobName) {
59
        try {
60
            final List<JobExecutionEntity> executionEntities = new ArrayList<>();
×
61
            final JobOperator jobOperator = BatchRuntime.getJobOperator();
×
62
            final int end = jobOperator.getJobInstanceCount(jobName);
×
63
            final List<JobInstance> jobInstances = jobOperator.getJobInstances(jobName, 0, end);
×
64
            for (JobInstance jobInstance : jobInstances) {
×
65
                final List<JobExecution> executions = jobOperator.getJobExecutions(jobInstance);
×
66
                for (JobExecution execution : executions) {
×
67
                    executionEntities.add(JobExecutionEntity.create(execution));
×
68
                }
×
69
            }
×
70
            return Response.ok("{ \"jobs\": \n" + mapper.writeValueAsString(executionEntities) + "\n}").build();
×
71
        } catch (Exception e) {
×
72
            return Response.ok(EMPTY_JSON_LIST).build();
×
73
        }
74
    }
75

76

77
    @GET
78
    @Path("/jobs/{jobId}")
79
    @Produces(MediaType.APPLICATION_JSON)
80
    public Response listBatchJobById(@PathParam("jobId") String jobId) {
81
        try {
82
            JobExecution execution = BatchRuntime.getJobOperator().getJobExecution(Long.valueOf(jobId));
×
83
            return Response.ok(mapper.writeValueAsString(JobExecutionEntity.create(execution))).build();
×
84
        } catch (Exception e) {
×
85
            return Response.ok(EMPTY_JSON_OBJ).build();
×
86
        }
87
    }
88

89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc