mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
05.03.2019 add986cff9c8e1a00428122a0d5515e6bd00120f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package de.micromata.borgbutler.server.rest.queue;
 
import de.micromata.borgbutler.BorgJob;
import de.micromata.borgbutler.jobs.AbstractJob;
import de.micromata.borgbutler.json.borg.ProgressInfo;
import de.micromata.borgbutler.server.user.UserUtils;
import lombok.Getter;
import lombok.Setter;
 
public class JsonJob {
    @Getter
    @Setter
    private boolean cancellationRequested;
    @Getter
    @Setter
    private AbstractJob.Status status;
    @Getter
    @Setter
    private String title;
    @Getter
    @Setter
    private String description;
    @Getter
    @Setter
    private String progressText;
    @Getter
    @Setter
    private ProgressInfo progressInfo;
    @Getter
    @Setter
    private String commandLineAsString;
 
    public JsonJob() {
    }
 
    public JsonJob(BorgJob<?> borgJob) {
        this.cancellationRequested = borgJob.isCancellationRequested();
        this.status = borgJob.getStatus();
        this.title = borgJob.getTitle();
        ProgressInfo progressInfo = borgJob.getProgressInfo();
        if (progressInfo != null) {
            this.progressInfo = progressInfo;
            buildProgressText();
        }
        this.commandLineAsString = borgJob.getCommandLineAsString();
        this.description = borgJob.getDescription();
    }
 
    /**
     * Builds and sets progressText from the progressInfo object if given.
     * @return progressText
     */
    public String buildProgressText() {
        if (progressInfo == null) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        if (progressInfo.getMessage() != null) {
            sb.append(progressInfo.getMessage());
        }
        if (progressInfo.getCurrent() > 0) {
            sb.append(" (").append(UserUtils.formatNumber(progressInfo.getCurrent()));
            if (progressInfo.getTotal() > 0) {
                sb.append("/").append(UserUtils.formatNumber(progressInfo.getTotal()));
            }
            sb.append(")");
        }
        if (progressInfo.isFinished()) {
            sb.append(" (finished)");
        }
        sb.append(".");
        progressText = sb.toString();
        return progressText;
    }
 
}