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

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

13 Nov 2023 05:22PM UTC coverage: 72.606% (+11.8%) from 60.79%
#324

push

github

web-flow
Merge pull request #174 from kit-data-manager/dev-v2

Development branch for v2.0.0

136 of 205 new or added lines in 14 files covered. (66.34%)

4 existing lines in 3 files now uncovered.

872 of 1201 relevant lines covered (72.61%)

0.73 hits per line

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

76.92
/src/main/java/edu/kit/datamanager/pit/pidsystem/IIdentifierSystem.java
1
package edu.kit.datamanager.pit.pidsystem;
2

3
import edu.kit.datamanager.pit.common.ExternalServiceException;
4
import edu.kit.datamanager.pit.common.InvalidConfigException;
5
import edu.kit.datamanager.pit.common.PidAlreadyExistsException;
6
import edu.kit.datamanager.pit.common.PidNotFoundException;
7
import edu.kit.datamanager.pit.common.RecordValidationException;
8
import edu.kit.datamanager.pit.domain.PIDRecord;
9
import edu.kit.datamanager.pit.domain.TypeDefinition;
10
import edu.kit.datamanager.pit.pidgeneration.PidSuffix;
11

12
import java.util.Collection;
13
import java.util.Optional;
14

15
/**
16
 * Main abstraction interface towards the identifier system containing
17
 * registered identifiers and associated state information.
18
 *
19
 */
20
public interface IIdentifierSystem {
21

22
    /**
23
     * Returns the configured prefix of this PID system.
24
     * 
25
     * If this system can create PIDs, the prefix is the one it uses to create PIDs.
26
     * Otherwise, it does not return a prefix.
27
     * 
28
     * @return the prefix this system uses to create PIDs, if it can create PIDs,
29
     *         empty otherwise.
30
     */
31
    public Optional<String> getPrefix();
32

33
    /**
34
     * Appends the given PID to the prefix, if possible.
35
     * 
36
     * It may not be possible if no prefix is present, or if the PID already starts
37
     * with a the prefix. The returnes String is then exaxtly the same.
38
     * 
39
     * @param pid the PID to append to the prefix.
40
     * @return the PID with the prefix appended, if possible.
41
     * @throws InvalidConfigException if the system can n.
42
     */
43
    public default String appendPrefixIfAbsent(String pid) throws InvalidConfigException {
44
        Optional<String> prefix = this.getPrefix();
1✔
45
        if (prefix.isPresent() && !pid.startsWith(prefix.get())) {
1✔
46
            return new PidSuffix(pid).getWithPrefix(prefix.get());
1✔
47
        } else {
48
            return pid;
×
49
        }
50
    }
51

52
    /**
53
     * Checks whether the given PID is already registered.
54
     *
55
     * @param pid the PID to check.
56
     * @return true, if the PID is registered, false otherwise.
57
     * @throws ExternalServiceException on commonication errors or errors on other
58
     *         services.
59
     */
60
    public boolean isIdentifierRegistered(String pid) throws ExternalServiceException;
61

62
    /**
63
     * Checks whether the given PID is already registered.
64
     * 
65
     * Assumes the PID to be the configured prefix of the system combined with the
66
     * given suffix.
67
     * 
68
     * @param suffix the given suffix, which, appended to the configured prefix,
69
     *        forms the PID to check.
70
     * @return true, if the PID is registered, false otherwise.
71
     * @throws ExternalServiceException on commonication errors or errors on other
72
     *         services.
73
     * @throws InvalidConfigException if there is no prefix configured to append to
74
     *         the suffix.
75
     */
76
    public default boolean isIdentifierRegistered(PidSuffix suffix) throws ExternalServiceException, InvalidConfigException {
77
        String prefix = getPrefix().orElseThrow(() -> new InvalidConfigException("This system cannot create PIDs."));
1✔
78
        return isIdentifierRegistered(suffix.getWithPrefix(prefix));
1✔
79
    }
80

81
    /**
82
     * Queries all properties from the given PID, independent of types.
83
     *
84
     * @param pid the PID to query the properties from.
85
     * @return a PID information record with its PID and attribute-value-pairs. The
86
     *         property names will be empty strings. Contains all property values
87
     *         present in the record of the given PID.
88
     * @throws PidNotFoundException if the pid is not registered.
89
     * @throws ExternalServiceException on commonication errors or errors on other
90
     *         services.
91
     */
92
    public PIDRecord queryAllProperties(String pid) throws PidNotFoundException, ExternalServiceException;
93

94
    /**
95
     * Queries a single property from the given PID.
96
     *
97
     * @param pid the PID to query from.
98
     * @param typeDefinition the type to query.
99
     * @return the property value or null if there is no property of given name
100
     * defined in this PID record.
101
     * @throws PidNotFoundException if PID is not registered.
102
     * @throws ExternalServiceException if an error occured in communication with
103
     *         other services.
104
     */
105
    public String queryProperty(String pid, TypeDefinition typeDefinition) throws PidNotFoundException, ExternalServiceException;
106

107
    /**
108
     * Registers a new PID with given property values. The method takes the PID from
109
     * the record and treats it as a suffix.
110
     * 
111
     * The method must process the given PID using the
112
     * {@link #registerPID(PIDRecord)} method.
113
     *
114
     * @param pidRecord contains the initial PID record.
115
     * @return the PID that was assigned to the record.
116
     * @throws PidAlreadyExistsException if the PID already exists
117
     * @throws ExternalServiceException if an error occured in communication with
118
     *         other services.
119
     * @throws RecordValidationException if record validation errors occurred.
120
     */
121
    public default String registerPID(final PIDRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException, RecordValidationException {
122
        if (pidRecord.getPid() == null) {
1✔
NEW
123
            throw new RecordValidationException(pidRecord, "PID must not be null.");
×
124
        }
125
        if (pidRecord.getPid().isEmpty()) {
1✔
NEW
126
            throw new RecordValidationException(pidRecord, "PID must not be empty.");
×
127
        }
128
        pidRecord.setPid(
1✔
129
            appendPrefixIfAbsent(pidRecord.getPid())
1✔
130
        );
131
        return registerPidUnchecked(pidRecord);
1✔
132
    }
133

134
    /**
135
     * Registers the given record with its given PID, without applying any checks.
136
     * Recommended to use {@link #registerPID(PIDRecord)} instead.
137
     * 
138
     * As an implementor, you can assume the PID to be not null, valid,
139
     * non-registered, and prefixed.
140
     * 
141
     * @param pidRecord the record to register.
142
     * @return the PID that was assigned to the record.
143
     * @throws PidAlreadyExistsException if the PID already exists
144
     * @throws ExternalServiceException if an error occured in communication with
145
     *         other services.
146
     */
147
    public String registerPidUnchecked(final PIDRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException;
148

149
    /**
150
     * Updates an existing record with the new given values. If the PID in the given
151
     * record is not valid, it will return false.
152
     * 
153
     * @param pidRecord Assumes an existing, valid PID inside this record.
154
     * @return false if there was no existing, valid PID in this record.
155
     * @throws PidNotFoundException if PID is not registered.
156
     * @throws ExternalServiceException if an error occured in communication with
157
     *         other services.
158
     * @throws RecordValidationException if record validation errors occurred.
159
     */
160
    public boolean updatePID(PIDRecord pidRecord) throws PidNotFoundException, ExternalServiceException, RecordValidationException;
161

162
    /**
163
     * Queries all properties of a given type available from the given PID. If
164
     * optional properties are present, they will be returned as well. If there are
165
     * mandatory properties missing (i.e. the record of the given PID does not fully
166
     * conform to the type), the method will NOT fail but simply return only those
167
     * properties that are present.
168
     *
169
     * @param pid the PID to query the type from.
170
     * @param typeDefinition the type to query.
171
     * @return a PID information record with property identifiers mapping to values.
172
     *         The property names will not be available (empty Strings). Contains
173
     *         all property values present in the record of the given PID that are
174
     *         also specified by the type (mandatory or optional).
175
     * @throws PidNotFoundException if the pid is not registered.
176
     * @throws ExternalServiceException if an error occured in communication with
177
     *         other services.
178
     */
179
    public PIDRecord queryByType(String pid, TypeDefinition typeDefinition) throws PidNotFoundException, ExternalServiceException;
180

181
    /**
182
     * Remove the given PID.
183
     * 
184
     * Obviously, this method is only for testing purposes, since we should not
185
     * delete persistent identifiers.
186
     *
187
     * @param pid the PID to delete.
188
     * @return true if the identifier was deleted, false if it did not exist.
189
     */
190
    public boolean deletePID(String pid) throws ExternalServiceException;
191

192
    /**
193
     * Returns all PIDs which are registered for the configured prefix.
194
     * 
195
     * The result may be very large, use carefully.
196
     * 
197
     * @return all PIDs which are registered for the configured prefix.
198
     */
199
    public Collection<String> resolveAllPidsOfPrefix() throws ExternalServiceException, InvalidConfigException;
200
}
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