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

knowledgepixels / nanodash / 18314058366

07 Oct 2025 01:20PM UTC coverage: 13.943% (+0.5%) from 13.489%
18314058366

push

github

tkuhn
feat(Spaces): Support for roleAssignmentTemplate in Space member roles

454 of 4182 branches covered (10.86%)

Branch coverage included in aggregate %.

1202 of 7695 relevant lines covered (15.62%)

0.7 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 java.io.Serializable;
4
import java.util.stream.Stream;
5

6
import org.eclipse.rdf4j.model.IRI;
7
import org.nanopub.extra.services.ApiResponseEntry;
8

9
import com.google.common.collect.Multimap;
10
import com.knowledgepixels.nanodash.template.Template;
11
import com.knowledgepixels.nanodash.template.TemplateData;
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
    public boolean isAdminRole() {
51
        return id.equals(ADMIN_ROLE_IRI);
×
52
    }
53

54
    /**
55
     * Get the IRI of this role.
56
     *
57
     * @return The IRI of this role.
58
     */
59
    public IRI getId() {
60
        return id;
3✔
61
    }
62

63
    /**
64
     * Get the label of this role.
65
     *
66
     * @return The label of this role.
67
     */
68
    public String getLabel() {
69
        return label;
3✔
70
    }
71

72
    /**
73
     * Get the name of this role.
74
     *
75
     * @return The name of this role.
76
     */
77
    public String getName() {
78
        return name;
3✔
79
    }
80

81
    /**
82
     * Get the title of this role.
83
     *
84
     * @return The title of this role.
85
     */
86
    public String getTitle() {
87
        return title;
3✔
88
    }
89

90
    public Template getRoleAssignmentTemplate() {
91
        return roleAssignmentTemplate;
×
92
    }
93

94
    /**
95
     * Get the regular properties associated with this role.
96
     *
97
     * @return The regular properties associated with this role.
98
     */
99
    public IRI[] getRegularProperties() {
100
        return regularProperties;
3✔
101
    }
102

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

112
    /**
113
     * Add the role parameters to the given multimap.
114
     *
115
     * @param params The multimap to add the parameters to.
116
     */
117
    public void addRoleParams(Multimap<String, String> params) {
118
        for (IRI p : regularProperties) params.put("role", p.stringValue());
23✔
119
        for (IRI p : inverseProperties) params.put("invrole", p.stringValue());
23✔
120
    }
1✔
121

122
    /**
123
     * The IRI for the "hasAdmin" predicate.
124
     */
125
    public static final IRI HAS_ADMIN_PREDICATE = Utils.vf.createIRI("https://w3id.org/kpxl/gen/terms/hasAdmin");
4✔
126
    private static final IRI ADMIN_ROLE_IRI = Utils.vf.createIRI("https://w3id.org/np/RA_eEJjQbxzSqYSwPzfjzOZi5sMPpUmHskFNsgJYSws8I/adminRole");
4✔
127
    private static final String ADMIN_ROLE_ASSIGNMENT_TEMPLATE_ID = "https://w3id.org/np/RAsOQ7k3GNnuUqZuLm57PWwWopQJR_4onnCpNR457CZg8";
128

129
    /**
130
     * The predefined admin role.
131
     */
132
    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✔
133

134
    private static IRI[] stringToIriArray(String string) {
135
        if (string == null || string.isBlank()) return new IRI[]{};
5!
136
        return Stream.of(string.split(" ")).map(s -> Utils.vf.createIRI(s)).toArray(IRI[]::new);
17✔
137
    }
138

139

140
    public static boolean isCurrentUserMember(Space space) {
141
        if (space == null) return false;
×
142
        IRI userIri = NanodashSession.get().getUserIri();
×
143
        if (userIri == null) return false;
×
144
        return space.isMember(userIri);
×
145
    }
146

147
    public static boolean isCurrentUserAdmin(Space space) {
148
        if (space == null) return false;
×
149
        IRI userIri = NanodashSession.get().getUserIri();
×
150
        if (userIri == null) return false;
×
151
        if (space.getMemberRoles(userIri) == null) return false;
×
152
        return space.getMemberRoles(userIri).contains(SpaceMemberRole.ADMIN_ROLE);
×
153
    }
154

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