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

knowledgepixels / nanodash / 19473636483

18 Nov 2025 04:35PM UTC coverage: 14.513% (+0.2%) from 14.288%
19473636483

push

github

ashleycaselli
ci(deps): update action actions/setup-java to v5.0.0

542 of 4792 branches covered (11.31%)

Branch coverage included in aggregate %.

1437 of 8844 relevant lines covered (16.25%)

0.72 hits per line

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

53.42
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 com.knowledgepixels.nanodash.vocabulary.KPXL_TERMS;
7
import org.apache.commons.lang3.tuple.Pair;
8
import org.eclipse.rdf4j.model.IRI;
9
import org.nanopub.extra.services.ApiResponseEntry;
10

11
import java.io.Serializable;
12
import java.util.stream.Stream;
13

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

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

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

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

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

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

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

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

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

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

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

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

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

133

134
    private static final IRI ADMIN_ROLE_IRI = Utils.vf.createIRI("https://w3id.org/np/RA_eEJjQbxzSqYSwPzfjzOZi5sMPpUmHskFNsgJYSws8I/adminRole");
4✔
135
    private static final String ADMIN_ROLE_ASSIGNMENT_TEMPLATE_ID = "https://w3id.org/np/RAsOQ7k3GNnuUqZuLm57PWwWopQJR_4onnCpNR457CZg8";
136

137
    /**
138
     * The predefined admin role.
139
     */
140
    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[]{KPXL_TERMS.HAS_ADMIN_PREDICATE});
20✔
141

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

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

166
    /**
167
     * Check if the current user is an admin of the given space.
168
     *
169
     * @param space The space to check.
170
     * @return True if the current user is an admin of the space, false otherwise.
171
     */
172
    public static boolean isCurrentUserAdmin(Space space) {
173
        if (space == null) return false;
×
174
        IRI userIri = NanodashSession.get().getUserIri();
×
175
        if (userIri == null) return false;
×
176
        if (space.getMemberRoles(userIri) == null) return false;
×
177
        for (Pair<SpaceMemberRole, String> r : space.getMemberRoles(userIri)) {
×
178
            if (r.getLeft().isAdminRole()) return true;
×
179
        }
×
180
        return false;
×
181
    }
182

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