mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-13 14:12:11 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
c35c3192b5
4 files changed
+74
-23
No files matched your search
+2
-2
@@ -165,8 +165,8 @@ public class TestORCPublicCertificateDatabase {
|
||||
" extracted from certificates "+certificates, certificateHandle.isPresent());
|
||||
final String referenceNumber = certificateHandle.get().getReferenceNumber();
|
||||
final CertificateHandle handle = db.getCertificateHandle(referenceNumber);
|
||||
final ORCCertificate result = db.getCertificate(referenceNumber);
|
||||
assertNotNull("Unable to load certificate for reference number "+referenceNumber+" from handle "+certificateHandle);
|
||||
final ORCCertificate result = db.getCertificate(referenceNumber, handle.getFamily());
|
||||
assertNotNull("Unable to load certificate for reference number "+referenceNumber+" from handle "+certificateHandle, result);
|
||||
assertEquals(handle.getGPH(), result.getGPH().asSeconds(), 0.00001);
|
||||
// Use some tolerance as we found differences as much as 5s between the dxtDate in the handle coming from the XML search result
|
||||
// and the IssueDate field in the JSON. Both suggest to report millisecond accuracy, but dxtDate always seems to have the
|
||||
|
||||
+51
-12
@@ -3,6 +3,8 @@ package com.sap.sailing.domain.orc;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -95,6 +97,37 @@ import com.sap.sse.common.Util;
|
||||
public interface ORCPublicCertificateDatabase {
|
||||
ORCPublicCertificateDatabase INSTANCE = new ORCPublicCertificateDatabaseImpl();
|
||||
|
||||
public enum CertificateFamily {
|
||||
UNKNOWN(0, ""), ORC(1, "ORC"), SUPER_YACHT(2, "SY"), DOUBLE_HANDED(3, "DH"), MULTI_HULL(4, "Mu");
|
||||
|
||||
private final int familyId;
|
||||
private final String familyQueryParamValue;
|
||||
private final static Map<Integer, CertificateFamily> familyById;
|
||||
|
||||
static {
|
||||
familyById = new HashMap<>();
|
||||
for (final CertificateFamily family : values()) {
|
||||
familyById.put(family.getFamilyId(), family);
|
||||
}
|
||||
}
|
||||
|
||||
private CertificateFamily(int familyId, String familyQueryParamValue) {
|
||||
this.familyId = familyId;
|
||||
this.familyQueryParamValue = familyQueryParamValue;
|
||||
}
|
||||
|
||||
public int getFamilyId() {
|
||||
return familyId;
|
||||
}
|
||||
|
||||
public String getFamilyQueryParamValue() {
|
||||
return familyQueryParamValue;
|
||||
}
|
||||
|
||||
public static CertificateFamily fromId(int familyId) {
|
||||
return familyById.get(familyId);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Equality and hash code of such handles is based on the {@link #getReferenceNumber() reference number} only.
|
||||
*
|
||||
@@ -108,6 +141,7 @@ public interface ORCPublicCertificateDatabase {
|
||||
String getSSSID();
|
||||
UUID getDatInGID();
|
||||
String getReferenceNumber();
|
||||
CertificateFamily getFamily();
|
||||
String getYachtName();
|
||||
String getSailNumber();
|
||||
String getBoatClassName();
|
||||
@@ -140,15 +174,7 @@ public interface ORCPublicCertificateDatabase {
|
||||
Iterable<CertificateHandle> search(CountryCode country, Integer yearOfIssuance, String referenceNumber,
|
||||
String yachtName, String sailNumber, String boatClassName, boolean includeInvalid) throws Exception;
|
||||
|
||||
default Iterable<ORCCertificate> getCertificates(Iterable<CertificateHandle> handles) throws Exception {
|
||||
return Util.map(handles, handle->{
|
||||
try {
|
||||
return getCertificate(handle.getReferenceNumber());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
Iterable<ORCCertificate> getCertificates(Iterable<CertificateHandle> handles) throws Exception;
|
||||
|
||||
default Iterable<ORCCertificate> getCertificates(CertificateHandle... handles) throws Exception {
|
||||
return getCertificates(Arrays.asList(handles));
|
||||
@@ -160,10 +186,23 @@ public interface ORCPublicCertificateDatabase {
|
||||
|
||||
ORCCertificate searchForUpdate(ORCCertificate certificate) throws Exception;
|
||||
|
||||
ORCCertificate searchForUpdate(CertificateHandle certificate) throws Exception;
|
||||
|
||||
ORCCertificate getCertificate(String referenceNumber) throws Exception;
|
||||
ORCCertificate searchForUpdate(CertificateHandle certificateHandle) throws Exception;
|
||||
|
||||
/**
|
||||
* Searches for a default {@link CertificateFamily#ORC} certificate by the given {@code referenceNumber}.
|
||||
* Note that this may not find certificates of other families.
|
||||
*/
|
||||
default ORCCertificate getCertificate(String referenceNumber) throws Exception {
|
||||
return getCertificate(referenceNumber, CertificateFamily.ORC);
|
||||
}
|
||||
|
||||
ORCCertificate getCertificate(String referenceNumber, CertificateFamily family) throws Exception;
|
||||
|
||||
default ORCCertificate getCertificate(CertificateHandle certificateHandle) throws Exception {
|
||||
final Iterable<ORCCertificate> certificates = getCertificates(certificateHandle);
|
||||
return certificates.iterator().hasNext() ? certificates.iterator().next() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a lookup job that is forked into the background. The job will first try an exact lookup
|
||||
* with the parameters as specified. If one or more results are obtained this way, they are returned. If no
|
||||
|
||||
+20
-8
@@ -109,6 +109,7 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat
|
||||
private final Double gph;
|
||||
private final UUID datInGID;
|
||||
private final String referenceNumber;
|
||||
private final CertificateFamily family;
|
||||
private final String yachtName;
|
||||
private final String sailNumber;
|
||||
private final String boatClassName;
|
||||
@@ -122,9 +123,9 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat
|
||||
private final Boolean isValid;
|
||||
|
||||
public CertificateHandleImpl(CountryCode issuingCountry, String fileId, Double gph, String sssid,
|
||||
UUID datInGID, String referenceNumber, String yachtName, String sailNumber, String boatClassName,
|
||||
String designer, String builder, Integer yearBuilt, TimePoint issueDate, Integer certType,
|
||||
Boolean oneDesign, Boolean isProvisional, Boolean isValid) {
|
||||
UUID datInGID, String referenceNumber, CertificateFamily family, String yachtName, String sailNumber,
|
||||
String boatClassName, String designer, String builder, Integer yearBuilt, TimePoint issueDate,
|
||||
Integer certType, Boolean oneDesign, Boolean isProvisional, Boolean isValid) {
|
||||
super();
|
||||
this.issuingCountry = issuingCountry;
|
||||
this.fileId = fileId;
|
||||
@@ -132,6 +133,7 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat
|
||||
this.sssid = sssid;
|
||||
this.datInGID = datInGID;
|
||||
this.referenceNumber = referenceNumber;
|
||||
this.family = family;
|
||||
this.yachtName = yachtName;
|
||||
this.sailNumber = sailNumber;
|
||||
this.boatClassName = boatClassName;
|
||||
@@ -200,6 +202,11 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat
|
||||
return referenceNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CertificateFamily getFamily() {
|
||||
return family;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getYachtName() {
|
||||
return yachtName;
|
||||
@@ -330,6 +337,7 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat
|
||||
Double gph = null;
|
||||
UUID datInGID = null;
|
||||
String referenceNumber = null;
|
||||
CertificateFamily family = CertificateFamily.UNKNOWN;
|
||||
String yachtName = null;
|
||||
String sailNumber = null;
|
||||
String boatClassName = null;
|
||||
@@ -359,6 +367,9 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat
|
||||
case "RefNo":
|
||||
referenceNumber = child.getTextContent().trim();
|
||||
break;
|
||||
case "Family":
|
||||
family = child.getTextContent().trim().isEmpty() ? CertificateFamily.UNKNOWN : CertificateFamily.fromId(Integer.valueOf(child.getTextContent().trim()));
|
||||
break;
|
||||
case "YachtName":
|
||||
yachtName = child.getTextContent();
|
||||
break;
|
||||
@@ -400,8 +411,9 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new CertificateHandleImpl(issuingCountry, fileId, gph, sssid, datInGID, referenceNumber,
|
||||
yachtName, sailNumber, boatClassName, designer, builder, yearBuilt, issueDate, certType, isOneDesign, isProvisional, isValid);
|
||||
return new CertificateHandleImpl(issuingCountry, fileId, gph, sssid, datInGID, referenceNumber, family,
|
||||
yachtName, sailNumber, boatClassName, designer, builder, yearBuilt, issueDate, certType, isOneDesign,
|
||||
isProvisional, isValid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -471,8 +483,8 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat
|
||||
}
|
||||
|
||||
@Override
|
||||
public ORCCertificate getCertificate(String referenceNumber) throws Exception {
|
||||
final String queryParameters = "ext=json&RefNo="+referenceNumber;
|
||||
public ORCCertificate getCertificate(String referenceNumber, CertificateFamily family) throws Exception {
|
||||
final String queryParameters = "ext=json&RefNo="+referenceNumber+"&family="+family.getFamilyQueryParamValue();
|
||||
logger.fine("Obtaining certificate for reference number "+referenceNumber);
|
||||
final ORCCertificate result = getSingleCertificate(queryParameters);
|
||||
if (result == null) {
|
||||
@@ -501,7 +513,7 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat
|
||||
final Map<CertificateHandle, Future<ORCCertificate>> futures = new HashMap<>();
|
||||
for (final CertificateHandle handle : handles) {
|
||||
if (!handle.getReferenceNumber().trim().isEmpty()) {
|
||||
final FutureTask<ORCCertificate> task = new FutureTask<ORCCertificate>(()->getCertificate(handle.getReferenceNumber()));
|
||||
final FutureTask<ORCCertificate> task = new FutureTask<ORCCertificate>(()->getCertificate(handle.getReferenceNumber(), handle.getFamily()));
|
||||
final Thread backgroundExecutor = new Thread(task, "ORC certificate background download thread for "+handle.getReferenceNumber());
|
||||
backgroundExecutor.setDaemon(true);
|
||||
backgroundExecutor.start();
|
||||
|
||||
@@ -175,7 +175,7 @@ public class Activator implements BundleActivator {
|
||||
" before firing up replication automatically...");
|
||||
final List<Replicable<?, ?>> replicables = new ArrayList<>();
|
||||
for (String replicableIdAsString : replicableIdsAsStrings) {
|
||||
logger.info("Trying to obtain Replicable " + replicableIdAsString+", waiting if necessary");
|
||||
logger.info("Trying to obtain Replicable " + replicableIdAsString+", waiting if necessary");
|
||||
Replicable<?, ?> replicable = replicablesProvider.getReplicable(replicableIdAsString, /* wait */true);
|
||||
logger.info("Obtained Replicable " + replicableIdAsString);
|
||||
replicables.add(replicable);
|
||||
|
||||
Reference in new issue
Block a user