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

...
Kai Reinhard
10.01.2018 5c6ef91b43f0b0cc225b1a5b8abdc08b670a9317
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
package de.micromata.borgbutler.server.rest;
 
import de.micromata.borgbutler.cache.ButlerCache;
import de.micromata.borgbutler.json.JsonUtils;
import de.micromata.borgbutler.json.borg.Repository;
import org.apache.commons.collections4.CollectionUtils;
 
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.List;
 
@Path("/repos")
public class ReposRest {
    @GET
    @Path("refresh")
    @Produces(MediaType.TEXT_PLAIN)
    /**
     * Reloads all templates on the server.
     * @return "OK"
     */
    public String refresh() {
        ButlerCache.getInstance().getRepoInfoCache().clearAndReset();
        return "OK";
    }
 
    @GET
    @Path("repo")
    @Produces(MediaType.APPLICATION_JSON)
    /**
     *
     * @param id
     * @param prettyPrinter If true then the json output will be in pretty format.
     * @see JsonUtils#toJson(Object, boolean)
     */
    public String getTemplate(@QueryParam("id") String id, @QueryParam("prettyPrinter") boolean prettyPrinter) {
        Repository repository = ButlerCache.getInstance().getRepository(id);
        return JsonUtils.toJson(repository, prettyPrinter);
    }
 
    @GET
    @Path("list")
    @Produces(MediaType.APPLICATION_JSON)
    /**
     *
     * @param prettyPrinter If true then the json output will be in pretty format.
     * @see JsonUtils#toJson(Object, boolean)
     */
    public String getList(@QueryParam("prettyPrinter") boolean prettyPrinter) {
        List<Repository> repositories = ButlerCache.getInstance().getAllRepositories();
        if (CollectionUtils.isEmpty(repositories)) {
            return "";
        }
        return JsonUtils.toJson(repositories, prettyPrinter);
    }
}