aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/organization/Issue.java
blob: 37356f2c2a6ae8cd496051d3ed0a851e9ac82796 (plain) (blame)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.organization;

import com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId;

import java.util.Objects;
import java.util.Optional;

/**
 * Represents an issue which needs to reported, typically from the controller, to a responsible party,
 * the identity of which is determined by the propertyId and, possibly, assignee fields.
 *
 * @author jvenstad
 */
public class Issue {

    private final String summary;
    private final String description;
    private final String label;
    private final User assignee;
    private final PropertyId propertyId;
    private final Type type;

    private Issue(String summary, String description, String label, User assignee, PropertyId propertyId, Type type) {
        if (summary.isEmpty()) throw new IllegalArgumentException("Issue summary can not be empty!");
        if (description.isEmpty()) throw new IllegalArgumentException("Issue description can not be empty!");
        Objects.requireNonNull(propertyId, "An issue must belong to a property!");

        this.summary = summary;
        this.description = description;
        this.label = label;
        this.assignee = assignee;
        this.propertyId = propertyId;
        this.type = type;
    }

    public Issue(String summary, String description, PropertyId propertyId) {
        this(summary, description, null, null, propertyId, Type.defect);
    }

    public Issue append(String appendage) {
        return new Issue(summary, description + appendage, label, assignee, propertyId, type);
    }

    public Issue with(String label) {
        return new Issue(summary, description, label, assignee, propertyId, type);
    }

    public Issue with(User assignee) {
        return new Issue(summary, description, label, assignee, propertyId, type);
    }

    public Issue with(PropertyId propertyId) {
        return new Issue(summary, description, label, assignee, propertyId, type);
    }

    public Issue with(Type type) {
        return new Issue(summary, description, label, assignee, propertyId, type);
    }

    public String summary() {
        return summary;
    }

    public String description() {
        return description;
    }

    public Optional<String> label() {
        return Optional.ofNullable(label);
    }

    public Optional<User> assignee() {
        return Optional.ofNullable(assignee);
    }

    public PropertyId propertyId() {
        return propertyId;
    }

    public Type type() {
        return type;
    }


    public enum Type {

        defect, // A defect which needs fixing.
        task    // A task the humans must perform.

    }

}