diff --git a/smp-resource-extensions/pom.xml b/smp-resource-extensions/pom.xml index 26ff1819b8ef0ec9c9d6d391ea5f539cfb0beb54..5a033ef10ab0bfd9f886c82dcc052bc68c7df763 100644 --- a/smp-resource-extensions/pom.xml +++ b/smp-resource-extensions/pom.xml @@ -12,7 +12,8 @@ ~ See the Licence for the specific language governing permissions and limitations under the Licence. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>eu.europa.ec.edelivery</groupId> @@ -23,7 +24,9 @@ <artifactId>smp-resource-extensions</artifactId> <name>smp-resource-extensions</name> <packaging>pom</packaging> - <description>The sub-project contains SMP examples of API and SPI implementations. Currently, SPI payload validation example.</description> + <description>The sub-project contains SMP examples of API and SPI implementations. Currently, SPI payload validation + example. + </description> <modules> <module>oasis-smp-spi</module> <module>oasis-cppa3-spi</module> diff --git a/smp-server-library/pom.xml b/smp-server-library/pom.xml index 403df0fc6ec2ea0e79c516a81d09acba78a5f059..8b53b2bfb2e9fad2682654570d7fd138dfde13a6 100644 --- a/smp-server-library/pom.xml +++ b/smp-server-library/pom.xml @@ -39,6 +39,10 @@ <groupId>eu.europa.ec.edelivery</groupId> <artifactId>edelivery-springsecurity-2-way-ssl-auth</artifactId> </dependency> + <dependency> + <groupId>eu.europa.ec.dynamic-discovery</groupId> + <artifactId>dynamic-discovery-client</artifactId> + </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> @@ -145,11 +149,9 @@ <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> </dependency> - <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> - <version>4.5.14</version> </dependency> <dependency> <groupId>org.apache.santuario</groupId> diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/IdentifierService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/IdentifierService.java index d412bdefb02c9c5a4b5aa80e106393fe5ba087c1..1d45677e42a2a10e480092d2c0a28387f12601dc 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/IdentifierService.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/IdentifierService.java @@ -13,9 +13,9 @@ package eu.europa.ec.edelivery.smp.conversion; +import eu.europa.ec.dynamicdiscovery.model.identifiers.types.EBCorePartyIdFormatterType; import eu.europa.ec.edelivery.smp.identifiers.Identifier; import eu.europa.ec.edelivery.smp.identifiers.IdentifierFormatter; -import eu.europa.ec.edelivery.smp.identifiers.types.EBCorePartyIdFormatterType; import eu.europa.ec.edelivery.smp.logging.SMPLogger; import eu.europa.ec.edelivery.smp.logging.SMPLoggerFactory; import eu.europa.ec.edelivery.smp.services.ConfigurationService; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/MalformedIdentifierException.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/MalformedIdentifierException.java deleted file mode 100644 index 1d80b108b79108ce8bc7d96a8efebf9d14d20db3..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/MalformedIdentifierException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2017 European Commission | CEF eDelivery - * - * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * - * You may obtain a copy of the Licence attached in file: LICENCE-EUPL-v1.2.pdf - * - * Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and limitations under the Licence. - */ - -package eu.europa.ec.edelivery.smp.exceptions; - -/** - * Thrown when used identifier does not fulfill requirements specified in OASIS SMP specs: - * http://docs.oasis-open.org/bdxr/bdx-smp/v1.0/bdx-smp-v1.0.html - * - * Created by gutowpa on 12/01/2017. - */ -public class MalformedIdentifierException extends IllegalArgumentException { - - private static String buildMessage(String malformedId){ - return "Malformed identifier, scheme and id should be delimited by double colon: "+malformedId; - } - - public MalformedIdentifierException(String malformedId, Exception cause){ - super(buildMessage(malformedId), cause); - } - - public MalformedIdentifierException(String message){ - super(message); - } -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/AbstractIdentifierFormatter.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/AbstractIdentifierFormatter.java deleted file mode 100644 index ea8b442888c7780f26eb3e2a72bbdce461779967..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/AbstractIdentifierFormatter.java +++ /dev/null @@ -1,279 +0,0 @@ -package eu.europa.ec.edelivery.smp.identifiers; - - -import eu.europa.ec.edelivery.smp.exceptions.MalformedIdentifierException; -import eu.europa.ec.edelivery.smp.identifiers.types.FormatterType; -import eu.europa.ec.edelivery.smp.identifiers.types.OasisSMPFormatterType; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.util.UriUtils; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.apache.commons.lang3.StringUtils.*; - -/** - * Formatter for printing and parsing identifier objects. - * <p> - * This class provides parsing and formatting method for identifier objects as: - * ParticipantIdentifierType, DocumentIdentifier, and ProcessIdentifier. - * - * <b>Parsing the identifier</b> - * Parse method tries to detect the scheme and identifier part of the identifier string using the - * regular expression and separator sequence. - * The regular expression allows setting complex parsing templates, while the split separator is much raster. - * - * <ul> - * <li>Using <b>Regular expressing:</b>Regular expression uses named groups <scheme> and <identifier> to identify the scheme and identifier. - * if the regular expression is null or does not match, the parsing fallback to "split" with separator." - * </li> - * <li>Using <b>separator:</b>Separator splits regular expression on the first occurrence of the 'separator' sequence.</li> - * </ul> - * If no parsing is successful, then the scheme is set to null, and the identifier part has the input value. - * In case the schemeMandatory is set to true and the scheme is null, the MalformedIdentifierException is thrown. - * - * @author Joze Rihtarsic - * @since 5.0 - */ -public abstract class AbstractIdentifierFormatter<T> { - private static final Logger LOG = LoggerFactory.getLogger(AbstractIdentifierFormatter.class); - - protected static final FormatterType DEFAULT_FORMATTER = new OasisSMPFormatterType(); - - protected boolean schemeMandatory = false; - protected Pattern schemeValidationPattern; - protected List<String> caseSensitiveSchemas; - protected List<FormatterType> formatterTypes = new ArrayList<>(); - - protected FormatterType defaultFormatter; - - - /** - * Formats the object according to formatTemplate. If template is 'blank' the scheme and identifier are concatenated - * with separator - * - * @param value Identifier object to format it to string - * @return String representation of the identifier - */ - public String format(T value) { - return format(getSchemeFromObject(value), getIdentifierFromObject(value)); - } - - /** - * Formats the object according to formatTemplate. If template is 'blank' the scheme and identifier are concatenated - * with separator - * - * @param scheme scheme part to format it to string - * @param identifier Identifier part to format it to string - * @return String representation of the identifier - */ - public String format(String scheme, String identifier) { - // find the formatter - Optional<FormatterType> optionalFormatterType = formatterTypes.stream().filter(formatterType -> - formatterType.isTypeByScheme(scheme)).findFirst(); - - if (optionalFormatterType.isPresent()) { - return optionalFormatterType.get().format(scheme, identifier); - } - return getDefaultFormatter().format(scheme, identifier); - } - - /** - * Formats the object according to formatTemplate. If template is 'blank' the scheme and identifier are concatenated - * with separator - * - * @param scheme scheme part to format it to string - * @param identifier Identifier part to format it to string - * @param noDelimiterOnBlankScheme if true not delimiter is added when scheme is blankl - * @return String representation of the identifier - */ - public String format(String scheme, String identifier, boolean noDelimiterOnBlankScheme) { - // find the formatter - Optional<FormatterType> optionalFormatterType = formatterTypes.stream().filter(formatterType -> - formatterType.isTypeByScheme(scheme)).findFirst(); - - if (optionalFormatterType.isPresent()) { - return optionalFormatterType.get().format(scheme, identifier, noDelimiterOnBlankScheme); - } - return getDefaultFormatter().format(scheme, identifier, noDelimiterOnBlankScheme); - } - - /** - * Parse identifier. - * <p> - * Method parse the identifier. - * - * @param value - * @return - */ - public T parse(final String value) { - if (isBlank(value)) { - throw new MalformedIdentifierException("Can not parse empty identifier value!"); - } - - String pValue = trim(value); - - // find the formatter - Optional<FormatterType> optionalFormatterType = formatterTypes.stream().filter(formatterType -> - formatterType.isType(pValue)).findFirst(); - - String[] parseResult; - if (optionalFormatterType.isPresent()) { - parseResult = optionalFormatterType.get().parse(pValue); - } else { - parseResult = getDefaultFormatter().parse(pValue); - } - boolean isSchemeBlank = isBlank(parseResult[0]); - if (isSchemeMandatory() && isSchemeBlank) { - throw new MalformedIdentifierException("Invalid Identifier: [" + pValue + "]. Can not detect schema!"); - } - - if (!isSchemeBlank && schemeValidationPattern != null) { - Matcher schemeMatcher = schemeValidationPattern.matcher(parseResult[0]); - if (!schemeMatcher.matches()) { - throw new MalformedIdentifierException("Invalid Identifier: [" + pValue + "]. Scheme does not match pattern: [" + schemeValidationPattern.pattern() + "]!"); - } - } - - return createObject(parseResult[0], parseResult[1]); - } - - /** - * Method parses the object then it validates if scheme is case sensitive and lower case the values accordingly. - * - * @param value - * @return - */ - public T normalizeIdentifier(final String value) { - T result = parse(value); - String schema = getSchemeFromObject(result); - - if (isCaseInsensitiveSchema(schema)) { - String identifier = getIdentifierFromObject(result); - updateObject(result, lowerCase(schema), lowerCase(identifier)); - } - - return result; - } - - /** - * Method normalize the identifier using the format/parse and sets schema and identifier to lower case if - * identifier is case insensitive. - * - * <ul> - * <li><b>eDelivery example:</b> scheme [null], party id: [urn:oasis:names:tc:ebcore:partyid-type:iso6523:0088:123456789]</li> - * <li><b>oasis SMP example:</b> scheme [urn:oasis:names:tc:ebcore:partyid-type:iso6523], party id: [0088:123456789]</li> - * <li><b>ebCore party ID example:</b>scheme [urn:oasis:names:tc:ebcore:partyid-type:iso6523:0088], party id: [123456789]/li> - * </ul> - * <p> - * Must always result in the same normalized object: - * scheme [urn:oasis:names:tc:ebcore:partyid-type:iso6523:0088]: party id: [123456789] - * - * @param value - * @return - */ - public T normalize(final T value) { - return normalize(getSchemeFromObject(value),getIdentifierFromObject(value)); - } - - public T normalize(String scheme, String identifier) { - return normalizeIdentifier(format(scheme, identifier)); - } - - /** - * Return true if identifier schema is not defined in list of case sensitive schemas, else return false. - * - * @param schema - * @return - */ - public boolean isCaseInsensitiveSchema(String schema) { - if (StringUtils.isEmpty(schema)) { - LOG.debug("Empty/null schemas are case insensitive."); - return true; - } - if (caseSensitiveSchemas == null || caseSensitiveSchemas.isEmpty()) { - LOG.debug("Case sensitive schemas are not configure. return default value [false] for schema's [{}] case sensitive validation!", schema); - return true; - } - return caseSensitiveSchemas.stream().noneMatch(schema::equalsIgnoreCase); - } - - public String urlEncodedFormat(T value) { - return urlEncode(format(value)); - } - - public String urlEncode(String s) { - return UriUtils.encode(s, UTF_8.name()); - } - - protected abstract String getSchemeFromObject(T object); - - protected abstract String getIdentifierFromObject(T object); - - protected abstract T createObject(String scheme, String identifier); - - protected abstract void updateObject(T object, String scheme, String identifier); - - - - - public List<String> getCaseSensitiveSchemas() { - return caseSensitiveSchemas; - } - - public AbstractIdentifierFormatter<T> caseSensitiveSchemas(List<String> caseSensitiveSchemas) { - this.caseSensitiveSchemas = caseSensitiveSchemas; - return this; - } - - public void setCaseSensitiveSchemas(List<String> caseSensitiveSchemas) { - this.caseSensitiveSchemas = caseSensitiveSchemas; - } - - public boolean isSchemeMandatory() { - return schemeMandatory; - } - - public void setSchemeMandatory(boolean schemeMandatory) { - this.schemeMandatory = schemeMandatory; - } - - public Pattern getSchemeValidationPattern() { - return schemeValidationPattern; - } - - public void setSchemeValidationPattern(Pattern schemeValidationPattern) { - this.schemeValidationPattern = schemeValidationPattern; - } - public void addFormatterTypes(FormatterType ... formatterTypes) { - if (formatterTypes ==null) { - return; - } - if (this.formatterTypes == null) { - this.formatterTypes = new ArrayList<>(); - } - this.formatterTypes.addAll(Arrays.asList(formatterTypes)); - } - - public List<FormatterType> getFormatterTypes() { - return formatterTypes; - } - - public FormatterType getDefaultFormatter() { - if (defaultFormatter == null) { - defaultFormatter = DEFAULT_FORMATTER; - } - return defaultFormatter; - } - - public void setDefaultFormatter(FormatterType defaultFormatter) { - this.defaultFormatter = defaultFormatter; - } -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/IdentifierFormatter.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/IdentifierFormatter.java index 7da3e9a9a8040d9a6648b2179957f1bd09aa5a12..5e6ca6e2e590bf35599ecea42b198947c870658a 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/IdentifierFormatter.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/IdentifierFormatter.java @@ -1,6 +1,8 @@ package eu.europa.ec.edelivery.smp.identifiers; -import eu.europa.ec.edelivery.smp.identifiers.types.FormatterType; +import eu.europa.ec.dynamicdiscovery.model.identifiers.AbstractIdentifierFormatter; +import eu.europa.ec.dynamicdiscovery.model.identifiers.types.AbstractFormatterType; +import eu.europa.ec.dynamicdiscovery.model.identifiers.types.FormatterType; import java.util.ArrayList; import java.util.Arrays; @@ -54,7 +56,7 @@ public class IdentifierFormatter extends AbstractIdentifierFormatter<Identifier> List<String> caseSensitiveSchemas; FormatterType[] formatterTypes = null; - FormatterType defaultFormatter; + AbstractFormatterType defaultFormatter; public Builder schemeMandatory(boolean schemeMandatory) { this.schemeMandatory = schemeMandatory; @@ -79,7 +81,7 @@ public class IdentifierFormatter extends AbstractIdentifierFormatter<Identifier> return this; } - public void setDefaultFormatter(FormatterType defaultFormatter) { + public void setDefaultFormatter(AbstractFormatterType defaultFormatter) { this.defaultFormatter = defaultFormatter; } @@ -89,7 +91,9 @@ public class IdentifierFormatter extends AbstractIdentifierFormatter<Identifier> identifierFormatter.setCaseSensitiveSchemas(caseSensitiveSchemas); identifierFormatter.setSchemeValidationPattern(schemeValidationPattern); identifierFormatter.addFormatterTypes(formatterTypes); - identifierFormatter.setDefaultFormatter(defaultFormatter); + if (defaultFormatter != null) { + identifierFormatter.setDefaultFormatter(defaultFormatter); + } return identifierFormatter; } } diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterType.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterType.java deleted file mode 100644 index a88da801543f6e2ba316d1883eb56173cb918f0f..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterType.java +++ /dev/null @@ -1,113 +0,0 @@ -package eu.europa.ec.edelivery.smp.identifiers.types; - -import eu.europa.ec.edelivery.smp.exceptions.MalformedIdentifierException; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; - -import static org.apache.commons.lang3.StringUtils.*; - - -/** - * EBCorePartyID implementation Formatter type. The formatter supports - * - * <ul> - * <li><b>Basic:</b>urn:oasis:names:tc:ebcore:partyid-type:<catalog-identifier>:(<scheme-in-catalog>)?:<scheme-specific-identifier></li> - * <li><b>"Empty "SMP scheme" started with double colon (eDelivery URL variant):</b> ::urn:oasis:names:tc:ebcore:partyid-type:<catalog-identifier>:(<scheme-in-catalog>)?:<scheme-specific-identifier></li> - * <li><b>Double colon separator (Oasis SMP variant):</b> urn:oasis:names:tc:ebcore:partyid-type:<catalog-identifier>::(<scheme-in-catalog>)?:<scheme-specific-identifier></li> - * </ul> - * <p> - * Currently allowed <catalog-identifier> are iso6523 and unregistered - * - * @author Joze Rihtarsic - * @since 5.0 - */ -public class EBCorePartyIdFormatterType implements FormatterType { - private static final Logger LOG = LoggerFactory.getLogger(EBCorePartyIdFormatterType.class); - - public static final String EBCORE_IDENTIFIER_PREFIX = "urn:oasis:names:tc:ebcore:partyid-type:"; - public static final String EBCORE_IDENTIFIER_ISO6523_SCHEME = "iso6523"; - public static final String EBCORE_IDENTIFIER_UNREGISTERED_SCHEME = "unregistered"; - private static final String EBCORE_SEPARATOR = ":"; - private static final String OASIS_SMP_SEPARATOR = "::"; - - - @Override - public boolean isTypeByScheme(final String scheme) { - String partyIdPrivate = StringUtils.trim(scheme); - if (StringUtils.isBlank(scheme)) { - LOG.debug("EBCorePartyIdFormatterType does not support identifiers with Null/Blank scheme"); - return false; - } - partyIdPrivate = removeStart(partyIdPrivate, OASIS_SMP_SEPARATOR); - - return startsWithIgnoreCase(partyIdPrivate, EBCORE_IDENTIFIER_PREFIX); - } - - @Override - public boolean isType(final String value) { - // the value should start with valid scheme - return isTypeByScheme(value); - } - - @Override - public String format(String scheme, String identifier, boolean noDelimiterOnEmptyScheme) { - return (isBlank(scheme) && noDelimiterOnEmptyScheme ? "" : trimToEmpty(scheme) + EBCORE_SEPARATOR) + trimToEmpty(identifier); - } - - @Override - public String format(final String scheme, final String identifier) { - return format(scheme, identifier, true); - } - - @Override - public String[] parse(final String value) { - - String partyIdPrivate = trimToEmpty(value); - // ebcore party can start with OASIS_SMP_SEPARATOR - remove it of exists. - partyIdPrivate = removeStart(partyIdPrivate, OASIS_SMP_SEPARATOR); - - // replace first OASIS_SMP_SEPARATOR :: with OASIS_SMP_SEPARATOR - partyIdPrivate = StringUtils.replace(partyIdPrivate, OASIS_SMP_SEPARATOR, EBCORE_SEPARATOR, 1); - - if (!StringUtils.startsWithIgnoreCase(partyIdPrivate, EBCORE_IDENTIFIER_PREFIX)) { - throw new MalformedIdentifierException(value, null); - } - boolean isIso6523 = StringUtils.startsWithIgnoreCase(partyIdPrivate, EBCORE_IDENTIFIER_PREFIX + EBCORE_IDENTIFIER_ISO6523_SCHEME +EBCORE_SEPARATOR); - boolean isUnregistered = StringUtils.startsWithIgnoreCase(partyIdPrivate, EBCORE_IDENTIFIER_PREFIX + EBCORE_IDENTIFIER_UNREGISTERED_SCHEME + EBCORE_SEPARATOR); - if (!isIso6523 && !isUnregistered) { - throw new MalformedIdentifierException("Invalid ebCore id [" + partyIdPrivate + "] ebcoreId <scheme-in-catalog> must be must one from the list " + Arrays.asList(EBCORE_IDENTIFIER_ISO6523_SCHEME, EBCORE_IDENTIFIER_UNREGISTERED_SCHEME) + "!"); - } - - int isSchemeDelimiter = partyIdPrivate.indexOf(EBCORE_SEPARATOR, EBCORE_IDENTIFIER_PREFIX.length()); - if (isSchemeDelimiter < 0) { - // invalid scheme - throw new MalformedIdentifierException(String.format("Invalid ebCore id [%s] ebcoreId must have prefix 'urn:oasis:names:tc:ebcore:partyid-type', " + - "and parts <catalog-identifier>, <scheme-in-catalog>, <scheme-specific-identifier> separated by colon. " + - "Example: urn:oasis:names:tc:ebcore:partyid-type:<catalog-identifier>:(<scheme-in-catalog>)?:<scheme-specific-identifier>.", partyIdPrivate)); - } - int isPartDelimiter = partyIdPrivate.indexOf(':', isSchemeDelimiter + 1); - - String[] result = new String[2]; - if (isPartDelimiter < 0 && isIso6523) { // for iso scheme-in-catalog is mandatory - // invalid scheme - throw new MalformedIdentifierException(String.format("Invalid ebCore id [%s] ebcoreId must have prefix 'urn:oasis:names:tc:ebcore:partyid-type', " + - "and parts <catalog-identifier>, <scheme-in-catalog>, <scheme-specific-identifier> separated by colon. " + - "Example: urn:oasis:names:tc:ebcore:partyid-type:<catalog-identifier>:(<scheme-in-catalog>)?:<scheme-specific-identifier>.", partyIdPrivate)); - } else if (isPartDelimiter < 0) { - result[0] = partyIdPrivate.substring(0, isSchemeDelimiter).trim(); - result[1] = partyIdPrivate.substring(isSchemeDelimiter + 1).trim(); - } else { - result[0] = partyIdPrivate.substring(0, isPartDelimiter).trim(); - result[1] = partyIdPrivate.substring(isPartDelimiter + 1).trim(); - } - - // Final cleaning: remove separator on end of scheme part and start of id part - result[1] = removeStart(result[1], EBCORE_SEPARATOR); - result[0] = StringUtils.removeEnd(result[0], EBCORE_SEPARATOR); - - return result; - } -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/FormatterType.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/FormatterType.java deleted file mode 100644 index 70df69ad9cbde56b5cd640489ae9dbe7a122aab9..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/FormatterType.java +++ /dev/null @@ -1,31 +0,0 @@ -package eu.europa.ec.edelivery.smp.identifiers.types; - - -/** - * Formatter type interface for formatting and parsing party identifiers - * - * @author Joze Rihtarsic - * @since 5.0 - */ -public interface FormatterType { - - /** - * Method returns true if scheme is supported by the formatter for parsing and formatting, else it return false:. - * @param scheme identifier scheme part - * @return return true if identifier is supported by the formatter else return false - */ - boolean isTypeByScheme(final String scheme); - - /** - * Method returns true if identifier is supported by the formatter for parsing and formatting, else it return false:. - * @param value identifier value - * @return return true if identifier is supported by the formatter else return false - */ - boolean isType(final String value); - - String format(final String scheme, final String identifier); - String format(final String scheme, final String identifier, boolean noDelimiterOnEmptyScheme); - - // always returns array size 2 with first element as scheme and second as identifier part. - String[] parse(final String value); -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterType.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterType.java deleted file mode 100644 index c306de66053617f8d6f7434689efe9f1d2eccb4c..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterType.java +++ /dev/null @@ -1,51 +0,0 @@ -package eu.europa.ec.edelivery.smp.identifiers.types; - -import org.apache.commons.lang3.StringUtils; - -import static org.apache.commons.lang3.StringUtils.*; - -/** - * Simple OSASIS SMP party identifier formatter. - * - * @author Joze Rihtarsic - * @since 5.0 - */ -public class OasisSMPFormatterType implements FormatterType { - private static final String SEPARATOR = "::"; - - @Override - public boolean isTypeByScheme(final String scheme) { - // by default format all identifier as defined in OasisSMP - return true; - } - - @Override - public boolean isType(final String value){ - // the value should start with valid scheme - return true; - } - - @Override - public String format(String scheme, String identifier, boolean noDelimiterOnEmptyScheme) { - return (isBlank(scheme) && noDelimiterOnEmptyScheme ? "" : trimToEmpty(scheme) + SEPARATOR) + trimToEmpty(identifier); - - } - - @Override - public String format(final String scheme, final String identifier) { - // for OASIS SMP 1.0 the separator :: is mandatory also when scheme is null! - return format(scheme, identifier, false); - } - - @Override - public String[] parse(final String value) { - String pValue = trim(value); - String[] splitValue = StringUtils.splitByWholeSeparatorPreserveAllTokens(pValue, SEPARATOR, 2); - // if only one value is returned set it to identifier - // else the first element is scheme and second identifier - String scheme = trim(splitValue.length == 1 ? null : splitValue[0]); - String identifier = trim(splitValue[splitValue.length == 1 ? 0 : 1]); - return new String[]{trimToNull(scheme), trimToNull(identifier)}; - - } -} diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterType.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterType.java deleted file mode 100644 index c5deb783fd7d78472d5c1da9ec24f75b5f8a03da..0000000000000000000000000000000000000000 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterType.java +++ /dev/null @@ -1,96 +0,0 @@ -package eu.europa.ec.edelivery.smp.identifiers.types; - -import eu.europa.ec.edelivery.smp.exceptions.MalformedIdentifierException; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static org.apache.commons.lang3.StringUtils.trim; - -/** - * Configurable formatter for parsing and serializing identifiers. - * <p> - * Example for formatTemplate "${" + SPLIT_GROUP_SCHEME_NAME + "}:${" + SPLIT_GROUP_SCHEME_NAME + "}"; - * - * @author Joze Rihtarsic - * @since 5.0 - */ -public class TemplateFormatterType implements FormatterType { - private static final Logger LOG = LoggerFactory.getLogger(TemplateFormatterType.class); - public static final String SPLIT_GROUP_SCHEME_NAME = "scheme"; - public static final String SPLIT_GROUP_IDENTIFIER_NAME = "identifier"; - protected static final String[] REPLACE_TAGS = new String[]{"${" + SPLIT_GROUP_SCHEME_NAME + "}", "${" + SPLIT_GROUP_IDENTIFIER_NAME + "}"}; - - private final Pattern splitRegularExpression; - private final Pattern schemaPattern; - private final String formatTemplate; - - public TemplateFormatterType(Pattern matchSchema, String formatTemplate, Pattern splitRegularExpression) { - this.schemaPattern = matchSchema; - this.formatTemplate = formatTemplate; - this.splitRegularExpression = splitRegularExpression; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isTypeByScheme(final String scheme) { - if (StringUtils.isBlank(scheme)) { - LOG.debug("TemplateFormatterType does not support identifiers with Null/Blank scheme"); - return false; - } - Matcher matcher = schemaPattern.matcher(scheme); - return matcher.matches(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isType(final String value) { - if (StringUtils.isBlank(value)) { - LOG.debug("Formatter does not support Null/Blank identifiers "); - return false; - } - Matcher matcher = schemaPattern.matcher(value); - return matcher.matches(); - } - - @Override - public String format(String scheme, String identifier, boolean noDelimiterOnEmptyScheme) { - return StringUtils.replaceEach(formatTemplate, REPLACE_TAGS, new String[]{scheme, identifier}); - - } - - @Override - public String format(final String scheme, final String identifier) { - return format(scheme, identifier, false); - } - - @Override - public String[] parse(final String value) { - String partyIdPrivate = value.trim(); - Matcher matcher = splitRegularExpression.matcher(trim(partyIdPrivate)); - if (!matcher.matches()) { - throw new MalformedIdentifierException("Identifier: [" + partyIdPrivate + "] does not match regular expression [" + splitRegularExpression.pattern() + "]"); - } - return new String[]{ - getGroupByName(matcher, SPLIT_GROUP_SCHEME_NAME), - getGroupByName(matcher, SPLIT_GROUP_IDENTIFIER_NAME) - }; - } - - private String getGroupByName(Matcher matcher, String groupName) { - String result = null; - try { - result = matcher.group(groupName); - } catch (IllegalArgumentException arg) { - LOG.debug("Group [{}] was not found for pattern: [{}].", groupName, matcher.pattern()); - } - return result; - } -} diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterFormatTests.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterFormatTests.java index 57b5845c15bf3027d8b6f62414abb43c23c7f14f..916ced2e0e68ca2bc72c636ccce3f3afa3ff2f50 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterFormatTests.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterFormatTests.java @@ -1,7 +1,7 @@ package eu.europa.ec.edelivery.smp.identifiers; -import eu.europa.ec.edelivery.smp.identifiers.types.EBCorePartyIdFormatterType; +import eu.europa.ec.dynamicdiscovery.model.identifiers.types.EBCorePartyIdFormatterType; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterParseTests.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterParseTests.java index 546372d0bede9f075587a875658ee4d43ac5b170..693aff6d0cdf6c62b71f11388a6d27bd3772e6c9 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterParseTests.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/ParticipantIdentifierFormatterParseTests.java @@ -1,7 +1,7 @@ package eu.europa.ec.edelivery.smp.identifiers; -import eu.europa.ec.edelivery.smp.identifiers.types.EBCorePartyIdFormatterType; +import eu.europa.ec.dynamicdiscovery.model.identifiers.types.EBCorePartyIdFormatterType; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,6 +47,7 @@ public class ParticipantIdentifierFormatterParseTests { {"ebCore with no catalog", true, " urn:oasis:names:tc:ebcore:partyid-type:0088123456789", null, null}, }); } + // input parameters @Parameterized.Parameter public String name; diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterTypeTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterTypeTest.java index 394cdffee95f21078a8835e2b7d92c4575108ef2..b69861cb91c0fc5f59fe1a0142016b4898443321 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterTypeTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/EBCorePartyIdFormatterTypeTest.java @@ -1,6 +1,7 @@ package eu.europa.ec.edelivery.smp.identifiers.types; -import eu.europa.ec.edelivery.smp.exceptions.MalformedIdentifierException; +import eu.europa.ec.dynamicdiscovery.exception.MalformedIdentifierException; +import eu.europa.ec.dynamicdiscovery.model.identifiers.types.EBCorePartyIdFormatterType; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; import org.junit.Test; @@ -123,9 +124,9 @@ public class EBCorePartyIdFormatterTypeTest { @Test - public void isTypeByScheme() { + public void isSchemeValid() { - boolean result = testInstance.isTypeByScheme(schemaPart); + boolean result = testInstance.isSchemeValid(schemaPart); assertEquals(isEBCorePartyId, result); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterTypeTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterTypeTest.java index 8995c69d759cd756d0edebd45ffd2d703a63d854..a7b24205f192337de2ab1a8b6a7f7d80d8d0dab9 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterTypeTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/OasisSMPFormatterTypeTest.java @@ -1,5 +1,6 @@ package eu.europa.ec.edelivery.smp.identifiers.types; +import eu.europa.ec.dynamicdiscovery.model.identifiers.types.OasisSMPFormatterType; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; import org.junit.Test; @@ -70,9 +71,9 @@ public class OasisSMPFormatterTypeTest { @Test - public void isTypeByScheme() { + public void isSchemeValid() { - boolean result = testInstance.isTypeByScheme(schemaPart); + boolean result = testInstance.isSchemeValid(schemaPart); assertEquals(isValidPartyId, result); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterTypeTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterTypeTest.java index 09e3ebec1b701307069fccc9f2ee8628391cd48a..1d033dd1ac28a1e975714fc97c70ff302d315f0e 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterTypeTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/identifiers/types/TemplateFormatterTypeTest.java @@ -1,5 +1,6 @@ package eu.europa.ec.edelivery.smp.identifiers.types; +import eu.europa.ec.dynamicdiscovery.model.identifiers.types.TemplateFormatterType; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; import org.junit.Test; @@ -75,9 +76,9 @@ public class TemplateFormatterTypeTest { @Test - public void isTypeByScheme() { + public void isSchemeValid() { - boolean result = testInstance.isTypeByScheme(schemaPart); + boolean result = testInstance.isSchemeValid(schemaPart); assertEquals(isValidPartyId, result); } diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceServiceTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceServiceTest.java index cdb8ae53c293100016d60e0c44a56ad167cae266..17c98bc024bf2c9a56069a33b26311edd151d070 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceServiceTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/services/resource/ResourceServiceTest.java @@ -1,9 +1,9 @@ package eu.europa.ec.edelivery.smp.services.resource; +import eu.europa.ec.dynamicdiscovery.exception.MalformedIdentifierException; import eu.europa.ec.edelivery.smp.auth.SMPUserDetails; import eu.europa.ec.edelivery.smp.data.dao.AbstractJunit5BaseDao; import eu.europa.ec.edelivery.smp.data.model.user.DBUser; -import eu.europa.ec.edelivery.smp.exceptions.MalformedIdentifierException; import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; import eu.europa.ec.edelivery.smp.servlet.ResourceAction; import eu.europa.ec.edelivery.smp.servlet.ResourceRequest; diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/AbstractErrorControllerAdvice.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/AbstractErrorControllerAdvice.java index a2e4d7e4d6274c23f00992eca841555b32cdf9a7..ccb4bb9c66a59be7cd4f5c205143e72c8c2fb13d 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/AbstractErrorControllerAdvice.java +++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/error/AbstractErrorControllerAdvice.java @@ -1,11 +1,11 @@ package eu.europa.ec.edelivery.smp.error; +import eu.europa.ec.dynamicdiscovery.exception.MalformedIdentifierException; import eu.europa.ec.edelivery.smp.data.ui.exceptions.ErrorResponseRO; import eu.europa.ec.edelivery.smp.error.exceptions.SMPResponseStatusException; import eu.europa.ec.edelivery.smp.exceptions.BadRequestException; import eu.europa.ec.edelivery.smp.exceptions.ErrorBusinessCode; -import eu.europa.ec.edelivery.smp.exceptions.MalformedIdentifierException; import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdviceTest.java b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdviceTest.java index b7762609730f8fff4a96b9054d6f818083e60c74..35cb1f83e72418b0ae48448e59c7c160cf8c70b5 100644 --- a/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdviceTest.java +++ b/smp-webapp/src/test/java/eu/europa/ec/edelivery/smp/error/ServiceErrorControllerAdviceTest.java @@ -1,9 +1,9 @@ package eu.europa.ec.edelivery.smp.error; +import eu.europa.ec.dynamicdiscovery.exception.MalformedIdentifierException; import eu.europa.ec.edelivery.smp.error.xml.ErrorResponse; import eu.europa.ec.edelivery.smp.exceptions.BadRequestException; import eu.europa.ec.edelivery.smp.exceptions.ErrorBusinessCode; -import eu.europa.ec.edelivery.smp.exceptions.MalformedIdentifierException; import org.junit.Test; import org.springframework.http.ResponseEntity; import org.springframework.security.access.AccessDeniedException; @@ -38,7 +38,7 @@ public class ServiceErrorControllerAdviceTest { @Test public void handleMalformedIdentifierException() { - ResponseEntity re = testIntance.handleMalformedIdentifierException(new MalformedIdentifierException("MalformedIdentifierExceptionMessage", null)); + ResponseEntity re = testIntance.handleMalformedIdentifierException(new MalformedIdentifierException("MalformedIdentifierExceptionMessage", null)); assertEquals(BAD_REQUEST, re.getStatusCode()); assertEquals(ErrorBusinessCode.FORMAT_ERROR.toString(), ((ErrorResponse)re.getBody()).getBusinessCode()); diff --git a/smp-wls-deploy/pom.xml b/smp-wls-deploy/pom.xml index ce1bd2e83ff9c023699bbe1e6098dac15516987f..f2bdf8a3ba2c53f20315972cfc94236c45caedd3 100644 --- a/smp-wls-deploy/pom.xml +++ b/smp-wls-deploy/pom.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>eu.europa.ec.edelivery</groupId>