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

knowledgepixels / nanodash / 19820983664

01 Dec 2025 11:24AM UTC coverage: 15.298% (+1.9%) from 13.36%
19820983664

push

github

web-flow
Merge pull request #313 from knowledgepixels/296-refactor-usage-of-pair-as-classes

Replace Pair with new class

591 of 4966 branches covered (11.9%)

Branch coverage included in aggregate %.

1559 of 9088 relevant lines covered (17.15%)

0.76 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.eclipse.rdf4j.model.IRI;
8
import org.nanopub.extra.services.ApiResponseEntry;
9

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

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

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

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

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

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

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

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

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

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

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

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

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

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

132

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

136
    /**
137
     * The predefined admin role.
138
     */
139
    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✔
140

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

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

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

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