Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

DSpace / DSpace / 7170

21 Oct 2019 - 14:31 coverage increased (+1.1%) to 36.543%
7170

Pull #2529

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Evaluated feedback on scripts and processes endpoints and model classes. Added javadoc, fixed tests and made improvements to various parts of the Scripts and processes feature
Pull Request #2529: Scripts and processes endpoint

439 of 666 new or added lines in 29 files covered. (65.92%)

888 existing lines in 25 files now uncovered.

28781 of 78760 relevant lines covered (36.54%)

0.37 hits per line

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

87.04
/dspace-api/src/main/java/org/dspace/scripts/ProcessServiceImpl.java
1
/**
2
 * The contents of this file are subject to the license and copyright
3
 * detailed in the LICENSE and NOTICE files at the root of the source
4
 * tree and available online at
5
 *
6
 * http://www.dspace.org/license/
7
 */
8
package org.dspace.scripts;
9

10
import java.sql.SQLException;
11
import java.util.ArrayList;
12
import java.util.Collections;
13
import java.util.Comparator;
14
import java.util.Date;
15
import java.util.List;
16
import java.util.regex.Pattern;
17

18
import org.apache.commons.lang3.StringUtils;
19
import org.apache.logging.log4j.Logger;
20
import org.dspace.content.ProcessStatus;
21
import org.dspace.content.dao.ProcessDAO;
22
import org.dspace.core.Context;
23
import org.dspace.core.LogManager;
24
import org.dspace.eperson.EPerson;
25
import org.dspace.scripts.service.ProcessService;
26
import org.springframework.beans.factory.annotation.Autowired;
27

28
/**
29
 * The implementation for the {@link ProcessService} class
30
 */
31
public class ProcessServiceImpl implements ProcessService {
1×
32

33
    private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(ProcessService.class);
1×
34

35
    @Autowired
36
    private ProcessDAO processDAO;
37

38
    @Override
39
    public Process create(Context context, EPerson ePerson, String scriptName,
40
                          List<DSpaceCommandLineParameter> parameters) throws SQLException {
41

42
        Process process = new Process();
1×
43
        process.setEPerson(ePerson);
1×
44
        process.setName(scriptName);
1×
45
        process.setParameters(DSpaceCommandLineParameter.concatenate(parameters));
1×
46
        process.setCreationTime(new Date());
1×
47
        Process createdProcess = processDAO.create(context, process);
1×
48
        log.info(LogManager.getHeader(context, "process_create",
1×
49
                                      "Process has been created for eperson with email " + ePerson.getEmail()
1×
50
                                          + " with ID " + createdProcess.getID() + " and scriptName " +
1×
51
                                          scriptName + " and parameters " + parameters));
52
        return createdProcess;
1×
53
    }
54

55
    @Override
56
    public Process find(Context context, int processId) throws SQLException {
57
        return processDAO.findByID(context, Process.class, processId);
1×
58
    }
59

60
    @Override
61
    public List<Process> findAll(Context context) throws SQLException {
62
        return processDAO.findAll(context, Process.class);
1×
63
    }
64

65
    @Override
66
    public List<Process> findAll(Context context, int limit, int offset) throws SQLException {
67
        return processDAO.findAll(context, limit, offset);
1×
68
    }
69

70
    @Override
71
    public List<Process> findAllSortByScript(Context context) throws SQLException {
NEW
72
        return processDAO.findAllSortByScript(context);
!
73
    }
74

75
    @Override
76
    public List<Process> findAllSortByStartTime(Context context) throws SQLException {
NEW
77
        List<Process> processes = findAll(context);
!
NEW
78
        Comparator<Process> comparing = Comparator
!
NEW
79
            .comparing(Process::getStartTime, Comparator.nullsLast(Comparator.naturalOrder()));
!
NEW
80
        comparing = comparing.thenComparing(Process::getID);
!
NEW
81
        processes.sort(comparing);
!
NEW
82
        return processes;
!
83
    }
84

85
    @Override
86
    public void start(Context context, Process process) throws SQLException {
87
        process.setProcessStatus(ProcessStatus.RUNNING);
1×
88
        process.setStartTime(new Date());
1×
89
        update(context, process);
1×
90
        log.info(LogManager.getHeader(context, "process_start", "Process with ID " + process.getID()
1×
91
            + " and name " + process.getName() + " has started"));
1×
92

93
    }
1×
94

95
    @Override
96
    public void fail(Context context, Process process) throws SQLException {
97
        process.setProcessStatus(ProcessStatus.FAILED);
1×
98
        process.setFinishedTime(new Date());
1×
99
        update(context, process);
1×
100
        log.info(LogManager.getHeader(context, "process_fail", "Process with ID " + process.getID()
1×
101
            + " and name " + process.getName() + " has failed"));
1×
102

103
    }
1×
104

105
    @Override
106
    public void complete(Context context, Process process) throws SQLException {
107
        process.setProcessStatus(ProcessStatus.COMPLETED);
1×
108
        process.setFinishedTime(new Date());
1×
109
        update(context, process);
1×
110
        log.info(LogManager.getHeader(context, "process_complete", "Process with ID " + process.getID()
1×
111
            + " and name " + process.getName() + " has been completed"));
1×
112

113
    }
1×
114

115
    @Override
116
    public void delete(Context context, Process process) throws SQLException {
117
        processDAO.delete(context, process);
1×
118
        log.info(LogManager.getHeader(context, "process_delete", "Process with ID " + process.getID()
1×
119
            + " and name " + process.getName() + " has been deleted"));
1×
120

121
    }
1×
122

123
    @Override
124
    public void update(Context context, Process process) throws SQLException {
125
        processDAO.save(context, process);
1×
126
    }
1×
127

128
    @Override
129
    public List<DSpaceCommandLineParameter> getParameters(Process process) {
130
        if (StringUtils.isBlank(process.getParameters())) {
1×
131
            return Collections.emptyList();
1×
132
        }
133

134
        String[] parameterArray = process.getParameters().split(Pattern.quote(DSpaceCommandLineParameter.SEPARATOR));
1×
135
        List<DSpaceCommandLineParameter> parameterList = new ArrayList<>();
1×
136

137
        for (String parameter : parameterArray) {
1×
138
            parameterList.add(new DSpaceCommandLineParameter(parameter));
1×
139
        }
140

141
        return parameterList;
1×
142
    }
143

144
    public int countTotal(Context context) throws SQLException {
145
        return processDAO.countRows(context);
1×
146
    }
147

148
}
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC