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

knowledgepixels / nanodash / 19368829457

14 Nov 2025 03:12PM UTC coverage: 14.107% (+0.4%) from 13.676%
19368829457

push

github

tkuhn
feat(SpaceUserList): Show source nanopubs for Space memberships

535 of 4786 branches covered (11.18%)

Branch coverage included in aggregate %.

1385 of 8824 relevant lines covered (15.7%)

0.7 hits per line

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

54.05
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

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
     * The IRI for the "hasAdmin" predicate.
135
     */
136
    public static final IRI HAS_ADMIN_PREDICATE = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasAdmin");
4✔
137
    private static final IRI ADMIN_ROLE_IRI = Utils.vf.createIRI("https://w3id.org/np/RA_eEJjQbxzSqYSwPzfjzOZi5sMPpUmHskFNsgJYSws8I/adminRole");
4✔
138
    private static final String ADMIN_ROLE_ASSIGNMENT_TEMPLATE_ID = "https://w3id.org/np/RAsOQ7k3GNnuUqZuLm57PWwWopQJR_4onnCpNR457CZg8";
139

140
    /**
141
     * The predefined admin role.
142
     */
143
    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✔
144

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

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

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

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