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

knowledgepixels / nanodash / 23138432878

16 Mar 2026 10:09AM UTC coverage: 15.99% (+0.2%) from 15.811%
23138432878

push

github

web-flow
Merge pull request #402 from knowledgepixels/fix/401-bounded-api-cache

Fix unbounded memory growth and resource exhaustion

717 of 5509 branches covered (13.02%)

Branch coverage included in aggregate %.

1810 of 10295 relevant lines covered (17.58%)

2.39 hits per line

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

18.52
src/main/java/com/knowledgepixels/nanodash/domain/IndividualAgent.java
1
package com.knowledgepixels.nanodash.domain;
2

3
import com.knowledgepixels.nanodash.NanodashSession;
4
import com.knowledgepixels.nanodash.Utils;
5
import com.knowledgepixels.nanodash.ViewDisplay;
6
import org.eclipse.rdf4j.model.IRI;
7
import org.nanopub.Nanopub;
8

9
import com.google.common.cache.Cache;
10
import com.google.common.cache.CacheBuilder;
11

12
import java.util.Set;
13
import java.util.concurrent.TimeUnit;
14

15
// TODO Merge this class with User or otherwise make them aligned.
16
public class IndividualAgent extends AbstractResourceWithProfile {
17

18
    private static final Cache<String, IndividualAgent> instanceMap = CacheBuilder.newBuilder()
9✔
19
        .maximumSize(10_000)
9✔
20
        .expireAfterAccess(24, TimeUnit.HOURS)
3✔
21
        .build();
6✔
22

23
    public static IndividualAgent get(String id) {
24
        IndividualAgent cached = instanceMap.getIfPresent(id);
×
25
        if (cached == null) {
×
26
            cached = new IndividualAgent(id);
×
27
            instanceMap.put(id, cached);
×
28
        }
29
        return cached;
×
30
    }
31

32
    private IndividualAgent(String id) {
33
        super(id);
×
34
    }
×
35

36
    /**
37
     * Checks if a given string represents a user ID.
38
     *
39
     * @param userId The string to check.
40
     * @return True if the string represents a user ID, false otherwise.
41
     */
42
    public static boolean isUser(String userId) {
43
        return User.getUserData().isUser(userId);
12✔
44
    }
45

46
    /**
47
     * Checks if a given IRI represents a software agent.
48
     *
49
     * @param userIri The IRI to check.
50
     * @return True if the IRI represents a software agent, false otherwise.
51
     */
52
    public static boolean isSoftware(IRI userIri) {
53
        return User.getUserData().isSoftware(userIri);
×
54
    }
55

56
    @Override
57
    public String getNanopubId() {
58
        // FIXME this will be removed in the future
59
        return null;
×
60
    }
61

62
    @Override
63
    public Nanopub getNanopub() {
64
        // FIXME this will be removed in the future
65
        return null;
×
66
    }
67

68
    @Override
69
    public String getNamespace() {
70
        // FIXME this will be removed in the future
71
        return null;
×
72
    }
73

74
    /**
75
     * Checks if this user is the currently logged-in user.
76
     *
77
     * @return True if this user is the currently logged-in user, false otherwise.
78
     */
79
    public boolean isCurrentUser() {
80
        IRI userIri = NanodashSession.get().getUserIri();
×
81
        if (userIri == null) {
×
82
            return false;
×
83
        }
84
        return getId().equals(userIri.stringValue());
×
85
    }
86

87
    @Override
88
    public String getLabel() {
89
        try {
90
            return User.getUserData().getShortDisplayName(Utils.vf.createIRI(getId()));
×
91
        } catch (Exception ex) {
×
92
        }
93
        return getId();
×
94
    }
95

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