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

kit-data-manager / pit-service / #105

pending completion
#105

Pull #61

github-actions

web-flow
Merge cdc987252 into 274f43ad5
Pull Request #61: Persist sandboxed pids

105 of 105 new or added lines in 5 files covered. (100.0%)

764 of 1477 relevant lines covered (51.73%)

0.52 hits per line

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

64.86
/src/main/java/edu/kit/datamanager/pit/pidsystem/impl/InMemoryIdentifierSystem.java
1
package edu.kit.datamanager.pit.pidsystem.impl;
2

3
import java.io.IOException;
4
import java.util.HashMap;
5
import java.util.Map;
6
import java.util.Set;
7

8
import edu.kit.datamanager.pit.common.PidNotFoundException;
9
import edu.kit.datamanager.pit.configuration.ApplicationProperties;
10
import edu.kit.datamanager.pit.domain.PIDRecord;
11
import edu.kit.datamanager.pit.domain.TypeDefinition;
12
import edu.kit.datamanager.pit.pidsystem.IIdentifierSystem;
13

14
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
17
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
18
import org.springframework.stereotype.Component;
19

20
/**
21
 * A simple basis for demonstrations or tests of the service. PIDs will be
22
 * stored in a HashMap and not stored anywhere else.
23
 */
24
@Component
25
@AutoConfigureAfter(value = ApplicationProperties.class)
26
@ConditionalOnExpression(
27
    "#{ '${pit.pidsystem.implementation}' eq T(edu.kit.datamanager.pit.configuration.ApplicationProperties.IdentifierSystemImpl).IN_MEMORY.name() }"
28
)
29
public class InMemoryIdentifierSystem implements IIdentifierSystem {
30

31
    private static final Logger LOG = LoggerFactory.getLogger(InMemoryIdentifierSystem.class);
1✔
32
    private Map<String, PIDRecord> records = new HashMap<>();
1✔
33

34
    public InMemoryIdentifierSystem() {
1✔
35
        LOG.warn("Using in-memory identifier system. REGISTERED PIDs ARE NOT STORED PERMANENTLY.");
1✔
36
    }
1✔
37

38
    @Override
39
    public boolean isIdentifierRegistered(String pid) throws IOException {
40
        return this.records.containsKey(pid);
1✔
41
    }
42

43
    @Override
44
    public PIDRecord queryAllProperties(String pid) throws IOException {
45
        PIDRecord record = this.records.get(pid);
1✔
46
        if (record == null) { return null; }
1✔
47
        return record;
1✔
48
    }
49

50
    @Override
51
    public String queryProperty(String pid, TypeDefinition typeDefinition) throws IOException {
52
        PIDRecord record = this.records.get(pid);
1✔
53
        if (record == null) { throw new PidNotFoundException(pid); }
1✔
54
        if (!record.hasProperty(typeDefinition.getIdentifier())) { return null; }
1✔
55
        return record.getPropertyValue(typeDefinition.getIdentifier());
1✔
56
    }
57
    
58
    @Override
59
    public String registerPID(PIDRecord record) throws IOException {
60
        int counter = 0;
1✔
61
        do {
62
            int hash = record.getEntries().hashCode() + counter;
1✔
63
            record.setPid("sandboxed/" + hash);
1✔
64
            counter++;
1✔
65
        } while (this.records.containsKey(record.getPid()));
1✔
66
        this.records.put(record.getPid(), record);
1✔
67
        LOG.debug("Registered record with PID: {}", record.getPid());
1✔
68
        return record.getPid();
1✔
69
    }
70

71
    @Override
72
    public boolean updatePID(PIDRecord record) throws IOException {
73
        if (this.records.containsKey(record.getPid())) {
1✔
74
            this.records.put(record.getPid(), record);
1✔
75
            return true;
1✔
76
        }
77
        return false;
×
78
    }
79

80
    @Override
81
    public PIDRecord queryByType(String pid, TypeDefinition typeDefinition) throws IOException {
82
        PIDRecord allProps = this.queryAllProperties(pid);
×
83
        if (allProps == null) {return null;}
×
84
        // only return properties listed in the type def
85
        Set<String> typeProps = typeDefinition.getAllProperties();
×
86
        PIDRecord result = new PIDRecord();
×
87
        for (String propID : allProps.getPropertyIdentifiers()) {
×
88
            if (typeProps.contains(propID)) {
×
89
                String[] values = allProps.getPropertyValues(propID);
×
90
                for (String value : values) {
×
91
                    result.addEntry(propID, "", value);
×
92
                }
93
            }
94
        }
×
95
        return result;
×
96
    }
97

98
    @Override
99
    public boolean deletePID(String pid) {
100
        throw new UnsupportedOperationException("Deleting PIDs is against the P in PID.");
×
101
    }
102
}
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

© 2025 Coveralls, Inc