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

knowledgepixels / nanodash / 19296044979

12 Nov 2025 11:33AM UTC coverage: 14.314% (+0.6%) from 13.678%
19296044979

push

github

ashleycaselli
docs(SpaceMemberRole): add missing javadoc annotations

540 of 4748 branches covered (11.37%)

Branch coverage included in aggregate %.

1394 of 8763 relevant lines covered (15.91%)

0.72 hits per line

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

59.7
src/main/java/com/knowledgepixels/nanodash/SpaceMemberRole.java
1
package com.knowledgepixels.nanodash;
2

3
import com.google.common.collect.Multimap;
4
import com.knowledgepixels.nanodash.template.Template;
5
import com.knowledgepixels.nanodash.template.TemplateData;
6
import org.eclipse.rdf4j.model.IRI;
7
import org.nanopub.extra.services.ApiResponseEntry;
8

9
import java.io.Serializable;
10
import java.util.stream.Stream;
11

12
/**
13
 * A role that a space member can have, with associated properties.
14
 */
15
public class SpaceMemberRole implements Serializable {
16

17
    private IRI id;
18
    private String label, name, title;
19
    private Template roleAssignmentTemplate = null;
6✔
20
    private IRI[] regularProperties, inverseProperties;
21

22
    /**
23
     * Construct a SpaceMemberRole from an API response entry.
24
     *
25
     * @param e The API response entry.
26
     */
27
    public SpaceMemberRole(ApiResponseEntry e) {
2✔
28
        this.id = Utils.vf.createIRI(e.get("role"));
7✔
29
        this.label = e.get("roleLabel");
5✔
30
        this.name = e.get("roleName");
5✔
31
        this.title = e.get("roleTitle");
5✔
32
        if (e.get("roleAssignmentTemplate") != null && !e.get("roleAssignmentTemplate").isBlank()) {
4!
33
            this.roleAssignmentTemplate = TemplateData.get().getTemplate(e.get("roleAssignmentTemplate"));
×
34
        }
35
        regularProperties = stringToIriArray(e.get("regularProperties"));
6✔
36
        inverseProperties = stringToIriArray(e.get("inverseProperties"));
6✔
37
    }
1✔
38

39
    private SpaceMemberRole(IRI id, String label, String name, String title, Template roleAssignmentTemplate, IRI[] regularProperties, IRI[] inverseProperties) {
2✔
40
        this.id = id;
3✔
41
        this.label = label;
3✔
42
        this.name = name;
3✔
43
        this.title = title;
3✔
44
        this.roleAssignmentTemplate = roleAssignmentTemplate;
3✔
45
        this.regularProperties = regularProperties;
3✔
46
        this.inverseProperties = inverseProperties;
3✔
47
    }
1✔
48

49
    /**
50
     * Check if this role is the admin role.
51
     *
52
     * @return True if this role is the admin role, false otherwise.
53
     */
54
    public boolean isAdminRole() {
55
        return id.equals(ADMIN_ROLE_IRI);
×
56
    }
57

58
    /**
59
     * Get the IRI of this role.
60
     *
61
     * @return The IRI of this role.
62
     */
63
    public IRI getId() {
64
        return id;
3✔
65
    }
66

67
    /**
68
     * Get the label of this role.
69
     *
70
     * @return The label of this role.
71
     */
72
    public String getLabel() {
73
        return label;
3✔
74
    }
75

76
    /**
77
     * Get the name of this role.
78
     *
79
     * @return The name of this role.
80
     */
81
    public String getName() {
82
        return name;
3✔
83
    }
84

85
    /**
86
     * Get the title of this role.
87
     *
88
     * @return The title of this role.
89
     */
90
    public String getTitle() {
91
        return title;
3✔
92
    }
93

94
    /**
95
     * Get the template used for assigning this role.
96
     *
97
     * @return The template used for assigning this role.
98
     */
99
    public Template getRoleAssignmentTemplate() {
100
        return roleAssignmentTemplate;
×
101
    }
102

103
    /**
104
     * Get the regular properties associated with this role.
105
     *
106
     * @return The regular properties associated with this role.
107
     */
108
    public IRI[] getRegularProperties() {
109
        return regularProperties;
3✔
110
    }
111

112
    /**
113
     * Get the inverse properties associated with this role.
114
     *
115
     * @return The inverse properties associated with this role.
116
     */
117
    public IRI[] getInverseProperties() {
118
        return inverseProperties;
3✔
119
    }
120

121
    /**
122
     * Add the role parameters to the given multimap.
123
     *
124
     * @param params The multimap to add the parameters to.
125
     */
126
    public void addRoleParams(Multimap<String, String> params) {
127
        for (IRI p : regularProperties) params.put("role", p.stringValue());
23✔
128
        for (IRI p : inverseProperties) params.put("invrole", p.stringValue());
23✔
129
    }
1✔
130

131
    /**
132
     * The IRI for the "hasAdmin" predicate.
133
     */
134
    public static final IRI HAS_ADMIN_PREDICATE = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasAdmin");
4✔
135
    private static final IRI ADMIN_ROLE_IRI = Utils.vf.createIRI("https://w3id.org/np/RA_eEJjQbxzSqYSwPzfjzOZi5sMPpUmHskFNsgJYSws8I/adminRole");
4✔
136
    private static final String ADMIN_ROLE_ASSIGNMENT_TEMPLATE_ID = "https://w3id.org/np/RAsOQ7k3GNnuUqZuLm57PWwWopQJR_4onnCpNR457CZg8";
137

138
    /**
139
     * The predefined admin role.
140
     */
141
    public static final SpaceMemberRole ADMIN_ROLE = new SpaceMemberRole(ADMIN_ROLE_IRI, "Admin role", "admin", "Admins", TemplateData.get().getTemplate(ADMIN_ROLE_ASSIGNMENT_TEMPLATE_ID), new IRI[]{}, new IRI[]{HAS_ADMIN_PREDICATE});
20✔
142

143
    /**
144
     * Convert a space-separated string of IRIs to an array of IRI objects.
145
     *
146
     * @param string The space-separated string of IRIs.
147
     * @return An array of IRI objects.
148
     */
149
    private static IRI[] stringToIriArray(String string) {
150
        if (string == null || string.isBlank()) return new IRI[]{};
5!
151
        return Stream.of(string.split(" ")).map(Utils.vf::createIRI).toArray(IRI[]::new);
17✔
152
    }
153

154
    /**
155
     * Check if the current user is a member of the given space.
156
     *
157
     * @param space The space to check.
158
     * @return True if the current user is a member of the space, false otherwise.
159
     */
160
    public static boolean isCurrentUserMember(Space space) {
161
        if (space == null) return false;
×
162
        IRI userIri = NanodashSession.get().getUserIri();
×
163
        if (userIri == null) return false;
×
164
        return space.isMember(userIri);
×
165
    }
166

167
    /**
168
     * Check if the current user is an admin of the given space.
169
     *
170
     * @param space The space to check.
171
     * @return True if the current user is an admin of the space, false otherwise.
172
     */
173
    public static boolean isCurrentUserAdmin(Space space) {
174
        if (space == null) return false;
×
175
        IRI userIri = NanodashSession.get().getUserIri();
×
176
        if (userIri == null) return false;
×
177
        if (space.getMemberRoles(userIri) == null) return false;
×
178
        return space.getMemberRoles(userIri).contains(SpaceMemberRole.ADMIN_ROLE);
×
179
    }
180

181
}
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

© 2026 Coveralls, Inc