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

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

20 Jan 2025 03:56PM UTC coverage: 75.383% (+3.0%) from 72.4%
#443

Pull #218

github

web-flow
Merge 991e6ae09 into 459f0c036
Pull Request #218: Type-Api support and validation speedup

257 of 322 new or added lines in 18 files covered. (79.81%)

3 existing lines in 2 files now uncovered.

885 of 1174 relevant lines covered (75.38%)

0.75 hits per line

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

61.11
/src/main/java/edu/kit/datamanager/pit/pitservice/impl/TypingService.java
1
package edu.kit.datamanager.pit.pitservice.impl;
2

3
import edu.kit.datamanager.pit.common.InvalidConfigException;
4
import edu.kit.datamanager.pit.common.PidAlreadyExistsException;
5
import edu.kit.datamanager.pit.common.PidNotFoundException;
6
import edu.kit.datamanager.pit.common.RecordValidationException;
7

8
import java.util.Collection;
9
import java.util.Optional;
10

11
import edu.kit.datamanager.pit.pidsystem.IIdentifierSystem;
12
import edu.kit.datamanager.pit.typeregistry.AttributeInfo;
13
import edu.kit.datamanager.pit.typeregistry.ITypeRegistry;
14
import edu.kit.datamanager.pit.pitservice.ITypingService;
15
import edu.kit.datamanager.pit.pitservice.IValidationStrategy;
16
import edu.kit.datamanager.pit.common.ExternalServiceException;
17
import edu.kit.datamanager.pit.domain.Operations;
18
import edu.kit.datamanager.pit.domain.PIDRecord;
19

20
import java.util.concurrent.CancellationException;
21
import java.util.concurrent.CompletionException;
22

23
import org.slf4j.Logger;
24
import org.slf4j.LoggerFactory;
25
import org.springframework.beans.factory.annotation.Autowired;
26

27
/**
28
 * Core implementation class that offers the combined higher-level services
29
 * through a type registry and an identifier system.
30
 *
31
 */
32
public class TypingService implements ITypingService {
33

34
    private static final Logger LOG = LoggerFactory.getLogger(TypingService.class);
1✔
35
    private static final String LOG_MSG_TYPING_SERVICE_MISCONFIGURED = "Typing service misconfigured.";
36
    private static final String LOG_MSG_QUERY_TYPE = "Querying for type with identifier {}.";
37

38
    protected final IIdentifierSystem identifierSystem;
39
    protected final ITypeRegistry typeRegistry;
40

41
    /**
42
     * A validation strategy. Will never be null.
43
     * 
44
     * ApplicationProperties::defaultValidationStrategy there is always either a
45
     * default strategy or a noop strategy assigned. Therefore, autowiring will
46
     * always work. Assigning null is done to avoid warnings on constructor.
47
     */
48
    @Autowired
1✔
49
    protected IValidationStrategy defaultStrategy = null;
50

51
    public TypingService(IIdentifierSystem identifierSystem, ITypeRegistry typeRegistry) {
52
        super();
1✔
53
        this.identifierSystem = identifierSystem;
1✔
54
        this.typeRegistry = typeRegistry;
1✔
55
    }
1✔
56

57
    @Override
58
    public Optional<String> getPrefix() {
59
        return this.identifierSystem.getPrefix();
1✔
60
    }
61

62
    @Override
63
    public void setValidationStrategy(IValidationStrategy strategy) {
64
        this.defaultStrategy = strategy;
1✔
65
    }
1✔
66

67
    @Override
68
    public void validate(PIDRecord pidRecord)
69
            throws RecordValidationException, ExternalServiceException {
70
        this.defaultStrategy.validate(pidRecord);
1✔
71
    }
1✔
72

73
    @Override
74
    public boolean isPidRegistered(String pid) throws ExternalServiceException {
75
        LOG.trace("Performing isIdentifierRegistered({}).", pid);
1✔
76
        return identifierSystem.isPidRegistered(pid);
1✔
77
    }
78

79
    @Override
80
    public String registerPidUnchecked(final PIDRecord pidRecord) throws PidAlreadyExistsException, ExternalServiceException {
81
        LOG.trace("Performing registerPID({}).", pidRecord);
1✔
82
        return identifierSystem.registerPidUnchecked(pidRecord);
1✔
83
    }
84

85
    @Override
86
    public boolean deletePid(String pid) throws ExternalServiceException {
87
        LOG.trace("Performing deletePID({}).", pid);
×
NEW
88
        return identifierSystem.deletePid(pid);
×
89
    }
90

91
    @Override
92
    public PIDRecord queryPid(String pid) throws PidNotFoundException, ExternalServiceException {
93
        return queryPid(pid, false);
1✔
94
    }
95

96
    public PIDRecord queryPid(String pid, boolean includePropertyNames)
97
            throws PidNotFoundException, ExternalServiceException {
98
        LOG.trace("Performing queryAllProperties({}, {}).", pid, includePropertyNames);
1✔
99
        PIDRecord pidInfo = identifierSystem.queryPid(pid);
1✔
100

101
        if (includePropertyNames) {
1✔
102
            enrichPIDInformationRecord(pidInfo);
×
103
        }
104
        return pidInfo;
1✔
105
    }
106

107
    private void enrichPIDInformationRecord(PIDRecord pidInfo) {
108
        // enrich record by querying type registry for all property definitions
109
        // to get the property names
110
        for (String typeIdentifier : pidInfo.getPropertyIdentifiers()) {
×
111
            AttributeInfo attributeInfo;
112
            try {
NEW
113
                attributeInfo = this.typeRegistry.queryAttributeInfo(typeIdentifier).join();
×
NEW
114
            } catch (CompletionException | CancellationException ex) {
×
115
                // TODO convert exceptions like in validation service.
116
                throw new InvalidConfigException(LOG_MSG_TYPING_SERVICE_MISCONFIGURED);
×
117
            }
×
118

NEW
119
            if (attributeInfo != null) {
×
NEW
120
                pidInfo.setPropertyName(typeIdentifier, attributeInfo.name());
×
121
            } else {
122
                pidInfo.setPropertyName(typeIdentifier, typeIdentifier);
×
123
            }
124
        }
×
125
    }
×
126

127
    @Override
128
    public boolean updatePid(PIDRecord pidRecord) throws PidNotFoundException, ExternalServiceException, RecordValidationException {
129
        return this.identifierSystem.updatePid(pidRecord);
1✔
130
    }
131

132
    @Override
133
    public Collection<String> resolveAllPidsOfPrefix() throws ExternalServiceException, InvalidConfigException {
134
        return this.identifierSystem.resolveAllPidsOfPrefix();
×
135
    }
136

137
    public Operations getOperations()  {
138
        return new Operations(this.typeRegistry, this.identifierSystem);
1✔
139
    }
140

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