Skip to content

Commit

Permalink
Merge branch 'feature/414-jee10'
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Ohr committed Mar 14, 2024
2 parents 75b39c7 + da4f3f0 commit 34c5629
Show file tree
Hide file tree
Showing 28 changed files with 296 additions and 410 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build IPF Gazelle with Maven
name: Build IPF Gazelle with Maven with Java 17

on: [push, pull_request]

Expand All @@ -8,18 +8,15 @@ env:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 11, 17 ]
name: Java ${{ matrix.java }} build
name: Java 17 build
timeout-minutes: 90
steps:
- uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ matrix.java }}
distribution: 'temurin'
java-version: 17
cache: 'maven'
- name: Build with Maven
run: mvn -B clean package --file pom.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Unmarshaller;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -78,11 +78,11 @@ public CachingGazelleProfileRule(ConformanceProfile profile) {
@Override
public ValidationException[] apply(Message message) {
try {
ConformanceProfile profile = this.profile == null ? guessGazelleProfile(iheTransaction, message) : this.profile;
var profile = this.profile == null ? guessGazelleProfile(iheTransaction, message) : this.profile;
if (profile == null) {
return failed("No matching profile could be loaded for message of type " + message.getClass().getName());
}
GazelleProfileRule rule = parseProfile(message.getParser().getHapiContext(), profile.profileInfo().profileId());
var rule = parseProfile(message.getParser().getHapiContext(), profile.profileInfo().profileId());
if (rule == null) {
return failed("Cannot parse conformance profile " + profile.profileInfo().profileId() + " for message of type " + message.getClass().getName());
}
Expand All @@ -99,41 +99,38 @@ public ValidationException[] apply(Message message) {
* @param hapiContext HapiContext from the message
* @param profileId profile id
* @return GazelleProfileRule
* @throws JAXBException
* @throws IOException
*/
protected GazelleProfileRule parseProfile(HapiContext hapiContext, String profileId) throws JAXBException, IOException {

GazelleProfileRule validator = VALIDATOR_CACHE.get(profileId);
var validator = VALIDATOR_CACHE.get(profileId);
if (validator != null) return validator;

// Several threads could attempt to load the same profile, but this should only happen at the very
// beginning. As a benefit we don't need any locking here.
LOG.debug("Conformance Profile {} requested, but has not been parsed yet", profileId);
GazelleProfileRule loaded = loadRule(hapiContext, profileId);
var loaded = loadRule(hapiContext, profileId);

if (VALIDATOR_CACHE.putIfAbsent(profileId, loaded) == null) {
LOG.debug("Added conformance profile {} to cache", profileId);
return loaded;
} else {
LOG.debug("Parsed conformance profile {}, but was already added");
LOG.debug("Parsed conformance profile {}, but was already added", profileId);
return VALIDATOR_CACHE.get(profileId);
}

}

protected GazelleProfileRule loadRule(HapiContext hapiContext, String profileId) throws JAXBException, IOException {
String profileString = hapiContext.getProfileStore().getProfile(profileId);
HL7V2XConformanceProfile conformanceProfile =
var profileString = hapiContext.getProfileStore().getProfile(profileId);
var conformanceProfile =
(HL7V2XConformanceProfile) getUnmarshaller().unmarshal(new ByteArrayInputStream(profileString.getBytes()));
GazelleProfileRule validator = new GazelleProfileRule(conformanceProfile);
return validator;
return new GazelleProfileRule(conformanceProfile);
}

// Unmarshaller are not thread-safe, but creation should happen only once for each profile
private Unmarshaller getUnmarshaller() {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(HL7V2XConformanceProfile.class);
var jaxbContext = JAXBContext.newInstance(HL7V2XConformanceProfile.class);
return jaxbContext.createUnmarshaller();
} catch (JAXBException jaxbException) {
throw new RuntimeException(jaxbException.getMessage());
Expand Down
Loading

0 comments on commit 34c5629

Please sign in to comment.