From 5de54e916478fb9fa4888f59e2879ce49af71a67 Mon Sep 17 00:00:00 2001 From: David Leoni Date: Sun, 15 Nov 2015 18:22:18 +0100 Subject: [PATCH] now conf folder for tests is searched walking dirs - renamed NotFoundException -> JackanNotFoundException - partially solves https://github.com/opendatatrentino/jackan/issues/22 although logging properties are still looked only in project root conf --- docs/CHANGES.md | 2 + .../opendata/jackan/dcat/DcatFactory.java | 218 ++++++++--------- .../jackan/dcat/GreedyDcatFactory.java | 6 +- .../exceptions/CkanNotFoundException.java | 2 +- ...tion.java => JackanNotFoundException.java} | 10 +- .../jackan/test/JackanTestConfig.java | 224 ++++++++++++++---- 6 files changed, 295 insertions(+), 167 deletions(-) rename src/main/java/eu/trentorise/opendata/jackan/exceptions/{NotFoundException.java => JackanNotFoundException.java} (73%) diff --git a/docs/CHANGES.md b/docs/CHANGES.md index 67de2b0..14c7f60 100644 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -21,6 +21,7 @@ November 15th, 2015 - Adapted to [josman]( https://github.com/opendatatrentino/josman) docs structure - shaded dependencies not directly exposed in api (ie. apache http client) - improved test reporter +- jackan test config lookup now walks directory tree (but still logging config is searched only in project root :-/ - upgraded: * traceprov to 0.3.0 @@ -37,6 +38,7 @@ BREAKING CHANGES: - now requiring at least Java 7 - renamed namespace eu/trentorise/opendata/jackan/ckan to eu/trentorise/opendata/jackan/model +- moved JackanException to eu/trentorise/opendata/jackan/exceptions package. - renamed URL to Url in functions and fields. i.e. catalogURL -> catalogUrl, CkanClient.makeDatasetURL -> makeDatasetUrl, ... - renamed and split `CkanGroupStructure` into `CkanGroupOrgBase` and `CkanGroupOrg` - now Joda `DateTime` is not used anymore, for timestamps now we use `java.sql.Timestamp` diff --git a/src/main/java/eu/trentorise/opendata/jackan/dcat/DcatFactory.java b/src/main/java/eu/trentorise/opendata/jackan/dcat/DcatFactory.java index 4d32ad6..200625d 100644 --- a/src/main/java/eu/trentorise/opendata/jackan/dcat/DcatFactory.java +++ b/src/main/java/eu/trentorise/opendata/jackan/dcat/DcatFactory.java @@ -32,7 +32,7 @@ import static eu.trentorise.opendata.commons.validation.Preconditions.checkNotEmpty; import static eu.trentorise.opendata.commons.TodUtils.isNotEmpty; import eu.trentorise.opendata.jackan.exceptions.JackanException; -import eu.trentorise.opendata.jackan.exceptions.NotFoundException; +import eu.trentorise.opendata.jackan.exceptions.JackanNotFoundException; import eu.trentorise.opendata.jackan.model.CkanDataset; import eu.trentorise.opendata.jackan.model.CkanTag; import eu.trentorise.opendata.traceprov.TraceProvModule; @@ -135,7 +135,7 @@ protected String formatLanguages(Iterable locales) { /** * i.e. "[\"ca\", \"en\", \"es\"]" * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -155,7 +155,7 @@ protected List extractLanguages(CkanDataset dataset) { * Like {@link #extractFieldAsString(CkanDataset, String)} but also checks * for trimmed non-emptiness. * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -164,7 +164,7 @@ protected String extractFieldAsNonEmptyString(CkanDataset dataset, String field) String ret = extractFieldAsString(dataset, field).trim(); if (ret.isEmpty()) { - throw new NotFoundException("Couldn't find valid non-empty field " + field + " in CkanDataset"); + throw new JackanNotFoundException("Couldn't find valid non-empty field " + field + " in CkanDataset"); } else { return ret; } @@ -174,7 +174,7 @@ protected String extractFieldAsNonEmptyString(CkanDataset dataset, String field) * Like {@link #extractFieldAsString(CkanResource, String)} but also checks * for trimmed non-emptiness. * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -183,7 +183,7 @@ protected String extractFieldAsNonEmptyString(CkanResource resource, String fiel String ret = extractFieldAsString(resource, field).trim(); if (ret.isEmpty()) { - throw new NotFoundException("Couldn't find valid non-empty field " + field + " in CkanResource!"); + throw new JackanNotFoundException("Couldn't find valid non-empty field " + field + " in CkanResource!"); } else { return ret; } @@ -192,9 +192,9 @@ protected String extractFieldAsNonEmptyString(CkanResource resource, String fiel /** * Searches a field in {@link CkanDataset#getOthers() } and then in * {@link CkanDataset#getExtras() }. If search fails throws - * NotFoundException, even if field is found but has null value. + * JackanNotFoundException, even if field is found but has null value. * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -217,16 +217,16 @@ protected String extractFieldAsString(CkanDataset dataset, String field) { } if (candidateString == null) { - throw new NotFoundException("Can't find string field " + field + "!"); + throw new JackanNotFoundException("Can't find string field " + field + "!"); } return candidateString; } /** * Searches a field in {@link CkanResource#getOthers() }. If search fails - * throws NotFoundException, even if field is found but has null value. + * throws JackanNotFoundException, even if field is found but has null value. * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -245,7 +245,7 @@ protected String extractFieldAsString(CkanResource resource, String field) { } if (candidateString == null) { - throw new NotFoundException("Can't find string field " + field + "!"); + throw new JackanNotFoundException("Can't find string field " + field + "!"); } return candidateString; } @@ -253,9 +253,9 @@ protected String extractFieldAsString(CkanResource resource, String field) { /** * Searches a field in {@link CkanDataset#getOthers() } and then in * {@link CkanDataset#getExtras() }. If search fails throws - * NotFoundException, even if field is found but has null value. + * JackanNotFoundException, even if field is found but has null value. * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -276,7 +276,7 @@ protected Object extractFieldAsObject(CkanDataset dataset, String field) { } if (candidateObject == null) { - throw new NotFoundException("Can't find object field " + field + "!"); + throw new JackanNotFoundException("Can't find object field " + field + "!"); } return candidateObject; } @@ -285,7 +285,7 @@ protected Object extractFieldAsObject(CkanDataset dataset, String field) { * Tries to extract a string field from a CkanDataset and casts it to target * type * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -303,7 +303,7 @@ protected T extractField(CkanDataset dataset, String field, TypeReference * @see #extractField(eu.trentorise.opendata.jackan.model.CkanDataset, * java.lang.String, com.fasterxml.jackson.core.type.TypeReference) * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -341,7 +341,7 @@ protected String formatTimestamp(Timestamp timestamp) { */ private GeoJson calcGeoJson(String name, String description, String id, String spatialDump) { if (name.isEmpty() && description.isEmpty()) { - throw new NotFoundException("Could not find valid dataset spatial field nor natural language name!"); + throw new JackanNotFoundException("Could not find valid dataset spatial field nor natural language name!"); } if (name.isEmpty() && !description.isEmpty()) { return Feature.builder().setProperties(ImmutableMap.of("description", spatialDump)).setId(id).build(); @@ -360,7 +360,7 @@ private GeoJson calcGeoJson(String name, String description, String id, String s } /** - * @throws NotFoundException + * @throws JackanNotFoundException * if spatial is not found * @throws JackanException * for other errors. @@ -378,20 +378,20 @@ protected GeoJson extractSpatial(CkanDataset dataset) { try { id = extractFieldAsNonEmptyString(dataset, "spatial_uri").trim(); logger.info("Found dataset 'spatial_uri' field, will set it to '@id' field of GeoJSON-LD"); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logger.info("Couldn't find dataset 'spatial_uri' field"); } try { name = extractFieldAsNonEmptyString(dataset, "spatial_text").trim(); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logger.info( "Couldn't find dataset 'spatial_text' field (should hold the natural language name of the place)"); } try { spatial = extractFieldAsNonEmptyString(dataset, "spatial"); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logger.info("Could not find dataset 'spatial' field"); } @@ -422,7 +422,7 @@ protected GeoJson extractSpatial(CkanDataset dataset) { * @param locale * the locale of the theme names. If unknown pass * {@link Locale#ROOT} - * @throws NotFoundException + * @throws JackanNotFoundException * if needed fields are missing. * @throws JackanException * on generic error @@ -435,7 +435,7 @@ protected List extractThemes(CkanDataset dataset, Locale locale, St try { candidateLabels = extractField(dataset, "theme", new TypeReference>() { }); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { return ret; } for (String s : candidateLabels) { @@ -463,7 +463,7 @@ protected List extractThemes(CkanDataset dataset, Locale locale, St * @param catalogUrl * i.e. http://dati.trentino.it * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -473,14 +473,14 @@ protected String extractUri(CkanDataset dataset, String catalogUrl) { String uri = ""; try { uri = extractFieldAsNonEmptyString(dataset, URI_FIELD); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { } if (isTrimmedEmpty(uri)) { if (!isTrimmedEmpty(dataset.getId())) { return CkanClient.makeDatasetUrl(catalogUrl, dataset.getId()); } else { - throw new NotFoundException("Couldn't find any valid dataset uri!"); + throw new JackanNotFoundException("Couldn't find any valid dataset uri!"); } } else { return uri; @@ -491,7 +491,7 @@ protected String extractUri(CkanDataset dataset, String catalogUrl) { * Returns a string with values trying to respect ISO 8601 format for time * intervals: https://en.wikipedia.org/wiki/ISO_8601#Time_intervals * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -502,17 +502,17 @@ protected PeriodOfTime extractTemporal(CkanDataset dataset) { try { start = extractFieldAsNonEmptyString(dataset, "temporal_start").trim(); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logger.info("Couldn't find valid dataset field 'temporal_start'"); } try { end = extractFieldAsNonEmptyString(dataset, "temporal_end").trim(); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logger.info("Couldn't find valid dataset field 'temporal_end'"); } if (start.isEmpty() && end.isEmpty()) { - throw new NotFoundException("Couldn't find any valid temporal information!"); + throw new JackanNotFoundException("Couldn't find any valid temporal information!"); } try { @@ -525,7 +525,7 @@ protected PeriodOfTime extractTemporal(CkanDataset dataset) { /** * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -534,23 +534,23 @@ protected String extractIdentifier(CkanDataset dataset) { try { return extractFieldAsNonEmptyString(dataset, "identifier"); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { } try { return extractFieldAsNonEmptyString(dataset, "guid"); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { } if (!isTrimmedEmpty(dataset.getId())) { return dataset.getId().trim(); } - throw new NotFoundException("Couldn't find any valid identifier in the dataset!"); + throw new JackanNotFoundException("Couldn't find any valid identifier in the dataset!"); } /** * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -558,17 +558,17 @@ protected String extractIdentifier(CkanDataset dataset) { protected String extractIssued(CkanDataset dataset) { try { return extractFieldAsNonEmptyString(dataset, ISSUED); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { if (dataset.getMetadataCreated() != null) { return CkanClient.formatTimestamp(dataset.getMetadataCreated()); } } - throw new NotFoundException("Couldn't find valid 'issued' field"); + throw new JackanNotFoundException("Couldn't find valid 'issued' field"); } /** * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -576,12 +576,12 @@ protected String extractIssued(CkanDataset dataset) { protected String extractModified(CkanDataset dataset) { try { return extractFieldAsString(dataset, MODIFIED); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { if (dataset.getMetadataModified() != null) { return CkanClient.formatTimestamp(dataset.getMetadataModified()); } } - throw new NotFoundException("Couldn't find valid 'modified' field"); + throw new JackanNotFoundException("Couldn't find valid 'modified' field"); } /** @@ -589,7 +589,7 @@ protected String extractModified(CkanDataset dataset) { * dataset, without resorting to ckan group, organization or maintainer as * fallback. * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -600,19 +600,19 @@ protected FoafAgent extractPublisher(CkanDataset dataset, Locale locale) { try { pubBuilder.setUri(extractFieldAsNonEmptyString(dataset, "publisher_uri").trim()); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logger.info("Couldn't find valid field 'publisher_uri'"); } try { pubBuilder.setName(Dict.of(locale, extractFieldAsNonEmptyString(dataset, "publisher_name").trim())); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logger.info("Couldn't find valid field 'publisher_name'"); } try { pubBuilder.setMbox(extractFieldAsNonEmptyString(dataset, "publisher_email").trim()); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logger.info("Couldn't find valid field 'publisher_email'"); String candidateTitle = ""; @@ -628,14 +628,14 @@ protected FoafAgent extractPublisher(CkanDataset dataset, Locale locale) { try { pubBuilder.setHomepage(extractFieldAsNonEmptyString(dataset, "publisher_url").trim()); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logger.info("Couldn't find valid field 'publisher_url' for publisher homepage"); } FoafAgent ret = pubBuilder.build(); if (ret.equals(FoafAgent.of())) { - throw new NotFoundException("Couldn't find any valid field for a publisher!"); + throw new JackanNotFoundException("Couldn't find any valid field for a publisher!"); } else { return ret; } @@ -643,7 +643,7 @@ protected FoafAgent extractPublisher(CkanDataset dataset, Locale locale) { /** * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -654,14 +654,14 @@ protected VCard extractContactPoint(CkanDataset dataset) { try { cpb.setUri(extractFieldAsNonEmptyString(dataset, "contact_uri")); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logger.info("Couldn't find valid dataset contact uri, skipping it."); } String candidateContactName = ""; try { candidateContactName = extractFieldAsNonEmptyString(dataset, "contact_name"); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { if (dataset.getMaintainer() != null && !dataset.getMaintainer().trim().isEmpty()) { candidateContactName = dataset.getMaintainer().trim(); } else if (dataset.getAuthor() != null && !dataset.getAuthor().trim().isEmpty()) { @@ -677,7 +677,7 @@ protected VCard extractContactPoint(CkanDataset dataset) { String candidateContactEmail = ""; try { candidateContactEmail = extractFieldAsNonEmptyString(dataset, "contact_email"); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { if (dataset.getMaintainer() != null && !dataset.getMaintainer().trim().isEmpty()) { candidateContactEmail = dataset.getMaintainerEmail().trim(); } else if (dataset.getAuthor() != null && !dataset.getAuthor().trim().isEmpty()) { @@ -692,7 +692,7 @@ protected VCard extractContactPoint(CkanDataset dataset) { VCard ret = cpb.build(); if (ret.equals(VCard.of())) { - throw new NotFoundException("Couldn't find any valid contact info in dataset!"); + throw new JackanNotFoundException("Couldn't find any valid contact info in dataset!"); } else { return ret; } @@ -700,7 +700,7 @@ protected VCard extractContactPoint(CkanDataset dataset) { /** * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -709,7 +709,7 @@ protected List extractKeywords(CkanDataset dataset) { List ret = new ArrayList(); if (dataset.getTags() == null) { - throw new NotFoundException("Found null tags!"); + throw new JackanNotFoundException("Found null tags!"); } else { for (CkanTag tag : dataset.getTags()) { if (tag != null && !isTrimmedEmpty(tag.getName())) { @@ -734,7 +734,7 @@ protected static String trim(@Nullable String s) { /** * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -743,7 +743,7 @@ protected Dict extractTitle(CkanDataset dataset, Locale locale) { String s = trim(dataset.getTitle()); if (s.isEmpty()) { - throw new NotFoundException("Couldn't find valid title!"); + throw new JackanNotFoundException("Couldn't find valid title!"); } else { return Dict.of(locale, s); } @@ -752,7 +752,7 @@ protected Dict extractTitle(CkanDataset dataset, Locale locale) { /** * @param locale * if unknown pass {@link Locale#ROOT} - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -761,7 +761,7 @@ protected Dict extractDescription(CkanDataset dataset, Locale locale) { String s = trim(dataset.getNotes()); if (s.isEmpty()) { - throw new NotFoundException("Couldn't find valid notes!"); + throw new JackanNotFoundException("Couldn't find valid notes!"); } else { return Dict.of(locale, s); } @@ -774,7 +774,7 @@ protected String extractAccrualPeriodicity(CkanDataset dataset) { protected String extractLandingPage(CkanDataset dataset) { if (isTrimmedEmpty(dataset.getUrl())) { - throw new NotFoundException("Couldn't find valid url field in dataset!"); + throw new JackanNotFoundException("Couldn't find valid url field in dataset!"); } else { return dataset.getUrl(); } @@ -831,7 +831,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setAccrualPeriodicity(extractAccrualPeriodicity(dataset)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("accrualPeriodicity"); } catch (Exception ex) { logDatasetCantExtract("accrualPeriodicity", ex); @@ -839,7 +839,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setContactPoint(extractContactPoint(dataset)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("contactPoint"); } catch (Exception ex) { logDatasetCantExtract("contactPoint", ex); @@ -847,7 +847,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setDescription(extractDescription(dataset, locale)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("description"); } catch (Exception ex) { logDatasetCantExtract("description", ex); @@ -866,7 +866,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setIdentifier(extractIdentifier(dataset)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("identifier"); } catch (Exception ex) { logDatasetCantExtract("identifier", ex); @@ -874,7 +874,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setIssued(extractIssued(dataset)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind(ISSUED); } catch (Exception ex) { logDatasetCantExtract(ISSUED, ex); @@ -882,7 +882,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setKeywords(extractKeywords(dataset)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("keywords"); } catch (Exception ex) { logDatasetCantExtract("keywords", ex); @@ -891,7 +891,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setLandingPage(extractLandingPage(dataset)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("landingPage"); } catch (Exception ex) { logDatasetCantExtract("landingPage", ex); @@ -899,7 +899,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setLanguages(extractLanguages(dataset)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("language"); if (!Locale.ROOT.equals(locale)) { logger.log(Level.INFO, "Setting language field to provided locale {0}", locale); @@ -915,7 +915,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setModified(extractModified(dataset)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind(MODIFIED); } catch (Exception ex) { logDatasetCantExtract(MODIFIED, ex); @@ -923,7 +923,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setPublisher(extractPublisher(dataset, locale)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("publisher"); } catch (Exception ex) { logDatasetCantExtract("publisher", ex); @@ -931,7 +931,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setSpatial(extractSpatial(dataset)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("spatial"); } catch (Exception ex) { logDatasetCantExtract("spatial", ex); @@ -939,7 +939,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setTemporal(extractTemporal(dataset)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("temporal"); } catch (Exception ex) { logDatasetCantExtract("temporal", ex); @@ -947,7 +947,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setThemes(extractThemes(dataset, locale, sanitizedCatalogUrl)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind("theme"); } catch (Exception ex) { logDatasetCantExtract("theme", ex); @@ -955,7 +955,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setTitle(extractTitle(dataset, locale)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind(TITLE); } catch (Exception ex) { logDatasetCantExtract(TITLE, ex); @@ -963,7 +963,7 @@ public DcatDataset makeDataset(CkanDataset dataset, String catalogUrl, Locale lo try { ddb.setUri(extractUri(dataset, sanitizedCatalogUrl)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDatasetCantFind(URI_FIELD); } catch (Exception ex) { logDatasetCantExtract(URI_FIELD, ex); @@ -1002,7 +1002,7 @@ protected void logDistribCantExtract(String attribute, Throwable ex) { * i.e. http://dati.trentino.it * @param datasetId * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -1013,7 +1013,7 @@ protected String extractUri(CkanResource resource, String catalogUrl, String dat try { candidateUri = extractFieldAsString(resource, URI_FIELD).trim(); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { } @@ -1021,7 +1021,7 @@ protected String extractUri(CkanResource resource, String catalogUrl, String dat if (isNotEmpty(catalogUrl) && isNotEmpty(datasetId) && isNotEmpty(resource.getId())) { return CkanClient.makeResourceUrl(catalogUrl, datasetId, resource.getId()); } else { - throw new NotFoundException("Couldn't find valid 'uri' for resource!"); + throw new JackanNotFoundException("Couldn't find valid 'uri' for resource!"); } } else { return candidateUri; @@ -1053,7 +1053,7 @@ protected void postProcessDistribution(DcatDistribution.Builder distributionBuil } /** - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -1063,7 +1063,7 @@ protected String extractModified(CkanResource resource) { } /** - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -1073,7 +1073,7 @@ protected String extractIssued(CkanResource resource) { } /** - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -1082,12 +1082,12 @@ protected String extractAccessUrl(CkanResource resource) { if (!isTrimmedEmpty(resource.getUrl())) { return resource.getUrl().trim(); } else { - throw new NotFoundException("Couldn't find valid access url!"); + throw new JackanNotFoundException("Couldn't find valid access url!"); } } /** - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -1097,14 +1097,14 @@ protected String extractDownloadUrl(CkanResource resource) { } /** - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error */ protected int extractByteSize(CkanResource resource) { if (isTrimmedEmpty(resource.getSize())) { - throw new NotFoundException("Couldn't find valid size in resource!"); + throw new JackanNotFoundException("Couldn't find valid size in resource!"); } try { return Integer.parseInt(resource.getSize()); @@ -1117,7 +1117,7 @@ protected int extractByteSize(CkanResource resource) { /** * @param locale * if unknown pass {@link Locale#ROOT} - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -1126,7 +1126,7 @@ protected Dict extractDescription(CkanResource dataset, Locale locale) { String s = trim(dataset.getDescription()); if (s.isEmpty()) { - throw new NotFoundException("Couldn't find valid description!"); + throw new JackanNotFoundException("Couldn't find valid description!"); } else { return Dict.of(locale, s); } @@ -1134,14 +1134,14 @@ protected Dict extractDescription(CkanResource dataset, Locale locale) { /** * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error */ protected String extractFormat(CkanResource resource) { if (isTrimmedEmpty(resource.getFormat())) { - throw new NotFoundException("Couldn't find a valid format!"); + throw new JackanNotFoundException("Couldn't find a valid format!"); } else { return resource.getFormat().trim(); } @@ -1151,7 +1151,7 @@ protected String extractFormat(CkanResource resource) { * @param license * value used if resource does not already have a license field. * If unknown pass the empty string. - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -1159,15 +1159,15 @@ protected String extractFormat(CkanResource resource) { protected String extractLicense(CkanResource resource, String license) { try { extractFieldAsNonEmptyString(resource, "license"); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { if (isNotEmpty(license)) { return license; } else { - throw new NotFoundException("Couldn't find valid license in resource!", ex); + throw new JackanNotFoundException("Couldn't find valid license in resource!", ex); } } if (isTrimmedEmpty(license)) { - throw new NotFoundException("Couldn't find a valid license!"); + throw new JackanNotFoundException("Couldn't find a valid license!"); } else { return license.trim(); } @@ -1176,14 +1176,14 @@ protected String extractLicense(CkanResource resource, String license) { /** * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error */ protected String extractMediaType(CkanResource resource) { if (isTrimmedEmpty(resource.getMimetype())) { - throw new NotFoundException("Couldn't find a valid media type!"); + throw new JackanNotFoundException("Couldn't find a valid media type!"); } else { return resource.getMimetype(); } @@ -1192,7 +1192,7 @@ protected String extractMediaType(CkanResource resource) { /** * - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -1204,7 +1204,7 @@ protected String extractRights(CkanResource resource) { /** * @param locale * if unknown pass {@link Locale#ROOT} - * @throws NotFoundException + * @throws JackanNotFoundException * when not found * @throws JackanException * on generic error @@ -1212,7 +1212,7 @@ protected String extractRights(CkanResource resource) { protected Dict extractTitle(CkanResource resource, Locale locale) { if (isTrimmedEmpty(resource.getName())) { logger.info("Couldn't find valid distribution title, skipping it"); - throw new NotFoundException("Couldn't find a valid title!"); + throw new JackanNotFoundException("Couldn't find a valid title!"); } else { return Dict.of(locale, resource.getName().trim()); } @@ -1259,7 +1259,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setUri(extractUri(resource, sanitizedCatalogUrl, datasetIdOrName)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind(URI_FIELD); } catch (Exception ex) { logDistribCantExtract(URI_FIELD, ex); @@ -1267,7 +1267,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setAccessURL(extractAccessUrl(resource)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind("accessURL"); } catch (Exception ex) { logDistribCantExtract("accessURL", ex); @@ -1275,7 +1275,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setDownloadURL(extractDownloadUrl(resource)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind("downloadURL"); } catch (Exception ex) { logDistribCantExtract("downloadURL", ex); @@ -1283,7 +1283,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setByteSize(extractByteSize(resource)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind("byteSize"); } catch (Exception ex) { logDistribCantExtract("byteSize", ex); @@ -1293,7 +1293,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setDescription(extractDescription(resource, locale)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind("description"); } catch (Exception ex) { logDistribCantExtract("description", ex); @@ -1301,7 +1301,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setFormat(extractFormat(resource)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind("format"); } catch (Exception ex) { logDistribCantExtract("format", ex); @@ -1309,7 +1309,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setIssued(extractIssued(resource)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind(ISSUED); } catch (Exception ex) { logDistribCantExtract(ISSUED, ex); @@ -1317,7 +1317,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setLicense(extractLicense(resource, license)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind("license"); } catch (Exception ex) { logDistribCantExtract("license", ex); @@ -1325,7 +1325,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setModified(extractModified(resource)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind(MODIFIED); } catch (Exception ex) { logDistribCantExtract(MODIFIED, ex); @@ -1333,7 +1333,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setMediaType(extractMediaType(resource)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind("mediaType"); } catch (Exception ex) { logDistribCantExtract("mediaType", ex); @@ -1341,7 +1341,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setRights(extractRights(resource)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind("rights"); } catch (Exception ex) { logDistribCantExtract("rights", ex); @@ -1349,7 +1349,7 @@ public DcatDistribution makeDistribution(CkanResource resource, String catalogUR try { ddb.setTitle(extractTitle(resource, locale)); - } catch (NotFoundException ex) { + } catch (JackanNotFoundException ex) { logDistribCantFind(TITLE); } catch (Exception ex) { logDistribCantExtract(TITLE, ex); diff --git a/src/main/java/eu/trentorise/opendata/jackan/dcat/GreedyDcatFactory.java b/src/main/java/eu/trentorise/opendata/jackan/dcat/GreedyDcatFactory.java index bc73c5d..188b708 100644 --- a/src/main/java/eu/trentorise/opendata/jackan/dcat/GreedyDcatFactory.java +++ b/src/main/java/eu/trentorise/opendata/jackan/dcat/GreedyDcatFactory.java @@ -17,7 +17,7 @@ import com.google.common.annotations.Beta; import eu.trentorise.opendata.commons.Dict; -import eu.trentorise.opendata.jackan.exceptions.NotFoundException; +import eu.trentorise.opendata.jackan.exceptions.JackanNotFoundException; import eu.trentorise.opendata.jackan.CkanClient; import eu.trentorise.opendata.jackan.model.CkanDataset; import eu.trentorise.opendata.jackan.model.CkanGroup; @@ -107,11 +107,11 @@ protected String extractModified(CkanResource resource try { return super.extractModified(resource); } - catch (NotFoundException ex) { + catch (JackanNotFoundException ex) { if (!isTrimmedEmpty(resource.getLastModified())) { return resource.getLastModified(); } else { - throw new NotFoundException("Couldn't find modified nor lastModified valid fields in resource!", ex); + throw new JackanNotFoundException("Couldn't find modified nor lastModified valid fields in resource!", ex); } } } diff --git a/src/main/java/eu/trentorise/opendata/jackan/exceptions/CkanNotFoundException.java b/src/main/java/eu/trentorise/opendata/jackan/exceptions/CkanNotFoundException.java index 579f0f9..d3e8b0a 100644 --- a/src/main/java/eu/trentorise/opendata/jackan/exceptions/CkanNotFoundException.java +++ b/src/main/java/eu/trentorise/opendata/jackan/exceptions/CkanNotFoundException.java @@ -20,7 +20,7 @@ /** * Thrown when Ckan tells us something was not found. Notice this is not related - * to more generic {@link NotFoundException} + * to more generic {@link JackanNotFoundException} * * @author David Leoni */ diff --git a/src/main/java/eu/trentorise/opendata/jackan/exceptions/NotFoundException.java b/src/main/java/eu/trentorise/opendata/jackan/exceptions/JackanNotFoundException.java similarity index 73% rename from src/main/java/eu/trentorise/opendata/jackan/exceptions/NotFoundException.java rename to src/main/java/eu/trentorise/opendata/jackan/exceptions/JackanNotFoundException.java index 15e55e8..6442c57 100644 --- a/src/main/java/eu/trentorise/opendata/jackan/exceptions/NotFoundException.java +++ b/src/main/java/eu/trentorise/opendata/jackan/exceptions/JackanNotFoundException.java @@ -21,19 +21,19 @@ * * @author David Leoni */ -public class NotFoundException extends JackanException { +public class JackanNotFoundException extends JackanException { /** - * Creates the NotFoundException using the provided message + * Creates the JackanNotFoundException using the provided message */ - public NotFoundException(String msg) { + public JackanNotFoundException(String msg) { super(msg); } /** - * Creates the NotFoundException using the provided message and throwable + * Creates the JackanNotFoundException using the provided message and throwable */ - public NotFoundException(String msg, Throwable tr) { + public JackanNotFoundException(String msg, Throwable tr) { super(msg, tr); } diff --git a/src/test/java/eu/trentorise/opendata/jackan/test/JackanTestConfig.java b/src/test/java/eu/trentorise/opendata/jackan/test/JackanTestConfig.java index d45f153..15c18c6 100644 --- a/src/test/java/eu/trentorise/opendata/jackan/test/JackanTestConfig.java +++ b/src/test/java/eu/trentorise/opendata/jackan/test/JackanTestConfig.java @@ -20,9 +20,14 @@ import eu.trentorise.opendata.jackan.CheckedCkanClient; import eu.trentorise.opendata.jackan.CkanClient; import eu.trentorise.opendata.jackan.CkanClient.Builder; +import eu.trentorise.opendata.jackan.exceptions.JackanException; +import eu.trentorise.opendata.jackan.exceptions.JackanNotFoundException; +import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Properties; @@ -31,7 +36,6 @@ import javax.annotation.Nullable; - /** * * @author David Leoni @@ -43,7 +47,7 @@ public class JackanTestConfig { /** * Path to file containing jackan testing specific properties */ - public static final String TEST_PROPERTIES_PATH = "conf/jackan.test.properties"; + public static final String TEST_PROPERTIES_PATH = "jackan.test.properties"; private static final String OUTPUT_CKAN_PROPERTY = "jackan.test.ckan.output"; private static final String OUTPUT_CKAN_TOKEN_PROPERTY = "jackan.test.ckan.output-token"; @@ -68,9 +72,9 @@ public class JackanTestConfig { * By default tests will use {@link CheckedCkanClient} */ private String clientClass; - + private String proxy; - + private int timeout = CkanClient.DEFAULT_TIMEOUT; private TodConfig todConfig; @@ -80,7 +84,8 @@ private JackanTestConfig() { } /** - * @throws IllegalStateException if {@link #loadLogConfig()} didn't succeed. + * @throws IllegalStateException + * if {@link #loadLogConfig()} didn't succeed. */ public String getOutputCkan() { if (initialized) { @@ -91,7 +96,8 @@ public String getOutputCkan() { } /** - * @throws IllegalStateException if {@link #loadLogConfig()} didn't succeed. + * @throws IllegalStateException + * if {@link #loadLogConfig()} didn't succeed. */ public String getOutputCkanToken() { if (initialized) { @@ -107,115 +113,235 @@ public String getClientClass() { } else { throw new IllegalStateException("Jackan testing system was not properly initialized!"); } - + + } + + private static File confDir; + + /** + * Walks the parent directories until finds the conf folder. + * + * @return the conf folder + * @throws JackanNotFoundException + * if folder is not found. + */ + private static File findConfDir() { + + if (confDir == null) { + + File directory = new File(System.getProperty("user.dir")); + + boolean reachedFileSystemRoot = false; + while (!reachedFileSystemRoot) { + File candidateConf = new File(directory.getAbsolutePath() + File.separator + "conf"); + + System.out.println("Trying conf candidate " + candidateConf.getAbsolutePath()); + + if (directory.isDirectory() && directory.exists() && candidateConf.isDirectory() + && candidateConf.exists()) { + + System.out.println("Found conf folder at " + candidateConf.getAbsolutePath()); + confDir = candidateConf; + return confDir; + } else { + File parent = directory.getParentFile(); + if (parent != null) { + directory = parent; + } else { + reachedFileSystemRoot = true; + } + } + } + + throw new JackanException("Couldn't find conf folder!"); + } else { + return confDir; + } + } + + /** + * First searches in conf/ directory, then continues search in conf + * directories walking up to file system root. + * + * @param filepath + * Relative filepath with file name and extension included. i.e. + * abc/myfile.xml, which will be first searched in + * conf/abc/myfile.xml + * @throws JackanNotFoundException + * if no file is found + */ + private static File findConfFile(String filepath) { + checkNotEmpty(filepath, "Invalid filepath!"); + + File confDir = findConfDir(); + File candFile = new File(confDir + File.separator + filepath); + + if (candFile.exists()) { + return candFile; + } else { + /* + * candFile = new File( confDir + File.separator + ".." + + * File.separator + "conf-template" + File.separator + filepath); if + * (candFile.exists()) { return candFile; } + */ + throw new JackanNotFoundException("Can't find file " + filepath + " in conf dir: " + confDir); + } + + } + + /** + * Loads file. + * + * @param filepath + * relative or absolute path with complete file name, i.e. + * /etc/bla.xml or ../../bla.xml + * @throws JackanNotFoundException + * if file is not found + * @throws JackanException + * on generic error + */ + private InputStream loadConfFile(File file) { + + if (!file.exists()) { + throw new JackanException("Logback filepath " + file + " does not reference a file that exists"); + } else { + if (!file.isFile()) { + throw new JackanException("Logback filepath " + file + " exists, but does not reference a file"); + } else { + if (!file.canRead()) { + throw new JackanException( + "Logback filepath " + file + " exists and is a file, but cannot be read."); + } else { + + try { + return new FileInputStream(file); + } catch (FileNotFoundException e) { + throw new JackanNotFoundException("Couldn't find file " + file); + } + + } + } + } } - - /** * Loads logging config (see {@link TodConfig#loadLogConfig()}) and - * configuration for writing tests at path {@link #TEST_PROPERTIES_PATH} + * configuration for writing tests at path {@link #TEST_PROPERTIES_PATH}. + * NOTE: The latter config is searched in a smarter way by looking in the + * first conf/ folder found walking along directory tree. */ public void loadConfig() { TodConfig.loadLogConfig(this.getClass()); Logger logger = Logger.getLogger(JackanTestConfig.class.getName()); - //final InputStream inputStream = JackanTestConfig.class.getResourceAsStream("/" + TEST_PROPERTIES_PATH); + // final InputStream inputStream = + // JackanTestConfig.class.getResourceAsStream("/" + + // TEST_PROPERTIES_PATH); FileInputStream inputStream = null; try { + File jackanConfFile; try { - inputStream = new FileInputStream(TEST_PROPERTIES_PATH); - logger.log(Level.INFO, "Loaded test configuration file {0}", TEST_PROPERTIES_PATH); - } - catch (Exception ex) { - throw new IOException("Couldn't load Jackan test config file " + TEST_PROPERTIES_PATH + ", to enable writing tests please copy src/test/resources/jackan.test.properties to conf folder in the project root and edit as needed!", ex); + jackanConfFile = findConfFile(TEST_PROPERTIES_PATH); + inputStream = new FileInputStream(jackanConfFile); + logger.log(Level.INFO, "Loaded test configuration file {0}", jackanConfFile); + } catch (Exception ex) { + throw new IOException( + "Couldn't load Jackan test config file " + TEST_PROPERTIES_PATH + + ", to enable writing tests please copy src/test/resources/jackan.test.properties to conf folder in the project root and edit as needed!", + ex); } properties = new Properties(); properties.load(inputStream); - - @Nullable String timeoutString = properties.getProperty(TIMEOUT_PROPERTY); - if (timeoutString != null){ + + @Nullable + String timeoutString = properties.getProperty(TIMEOUT_PROPERTY); + if (timeoutString != null) { timeout = Integer.parseInt(timeoutString); } - + proxy = properties.getProperty(PROXY_PROPERTY); - + outputCkan = properties.getProperty(OUTPUT_CKAN_PROPERTY); - if (outputCkan == null || outputCkan.trim().isEmpty()) { - throw new IOException("Couldn't find property " + OUTPUT_CKAN_PROPERTY + " in configuration file " + TEST_PROPERTIES_PATH); + if (outputCkan == null || outputCkan.trim() + .isEmpty()) { + throw new IOException("Couldn't find property " + OUTPUT_CKAN_PROPERTY + " in configuration file " + + jackanConfFile); } else { logger.log(Level.INFO, "Will use {0} for CKAN write tests", outputCkan); } outputCkanToken = properties.getProperty(OUTPUT_CKAN_TOKEN_PROPERTY); - if (outputCkanToken == null || outputCkanToken.trim().isEmpty()) { - throw new IOException("COULDN'T FIND PROPERTY " + OUTPUT_CKAN_TOKEN_PROPERTY + " IN CONFIGURATION FILE " + TEST_PROPERTIES_PATH); + if (outputCkanToken == null || outputCkanToken.trim() + .isEmpty()) { + throw new IOException("COULDN'T FIND PROPERTY " + OUTPUT_CKAN_TOKEN_PROPERTY + " IN CONFIGURATION FILE " + + jackanConfFile); } else { logger.log(Level.INFO, "Will use token {0} for CKAN write tests", outputCkanToken); } clientClass = properties.getProperty(CLIENT_CLASS_PROPERTY); - if (clientClass == null || clientClass.trim().isEmpty()) { + if (clientClass == null || clientClass.trim() + .isEmpty()) { clientClass = CheckedCkanClient.class.getName(); logger.log(Level.INFO, "Will use default client class {0} for writing", clientClass); } else { clientClass = clientClass.trim(); logger.log(Level.INFO, "Will use client class {0} for writing", clientClass); } - - + // let's see if it doesn't explode.. try { makeClientInstanceForWriting(clientClass); - } catch (Exception ex){ + } catch (Exception ex) { throw new Exception("Could not make test instance for client class " + clientClass, ex); - } - + } + initialized = true; - } - catch (Exception e) { - logger.log(Level.SEVERE, "JACKAN ERROR - COULDN'T INITIALIZE TEST ENVIRONMENT PROPERLY! INTEGRATION TESTS (ESPECIALLY FOR WRITING) MIGHT FAIL BECAUSE OF THIS!!", e); + } catch (Exception e) { + logger.log(Level.SEVERE, + "JACKAN ERROR - COULDN'T INITIALIZE TEST ENVIRONMENT PROPERLY! INTEGRATION TESTS (ESPECIALLY FOR WRITING) MIGHT FAIL BECAUSE OF THIS!!", + e); } } /** - * Returns a default client instance for writing. + * Returns a default client instance for writing. */ public CkanClient makeClientInstanceForWriting() { return makeClientInstanceForWriting(clientClass); } - + public CkanClient makeClientInstanceForWriting(String clientClass) { checkNotEmpty(clientClass, "Invalid class string!"); - + Class forName; try { forName = Class.forName(clientClass); + } catch (Exception ex) { + throw new RuntimeException("Couldn't find client class " + clientClass + "!", ex); } - catch (Exception ex) { - throw new RuntimeException("Couldn't find client class " + clientClass + "!", ex); - } - + Method method; CkanClient.Builder builder; try { method = forName.getMethod("builder"); - builder = (Builder) method.invoke(null); - } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + builder = (Builder) method.invoke(null); + } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException("Could not find builder() static method in client class " + clientClass, ex); } - - return builder.setCatalogUrl(outputCkan) - .setCkanToken(outputCkanToken) - .setProxy(proxy) - .setTimeout(timeout) - .build(); + + return builder.setCatalogUrl(outputCkan) + .setCkanToken(outputCkanToken) + .setProxy(proxy) + .setTimeout(timeout) + .build(); } /**