From df3da1cbd4ec0736c0d8e0bf4fe0d2e082fb4947 Mon Sep 17 00:00:00 2001
From: Joze RIHTARSIC <joze.RIHTARSIC@ext.ec.europa.eu>
Date: Fri, 2 Dec 2022 09:53:46 +0100
Subject: [PATCH] PR updates

---
 .../AbstractIdentifierFormatter.java          | 20 ++++++
 .../types/EBCorePartyIdFormatterType.java     | 61 +++++++++--------
 .../api/identifiers/types/FormatterType.java  | 13 +++-
 .../types/OasisSMPFormatterType.java          |  8 ++-
 .../types/TemplateFormatterType.java          | 22 +++++--
 .../types/EBCorePartyIdFormatterTypeTest.java |  8 ++-
 .../types/OasisSMPFormatterTypeTest.java      | 13 ++--
 .../smp/conversion/ServiceGroupConverter.java |  6 +-
 .../smp/data/dao/SMPRevisionListener.java     |  3 +-
 .../smp/data/ui/enums/SMPPropertyEnum.java    |  2 +-
 .../smp/services/ServiceGroupService.java     | 13 ++--
 .../ec/edelivery/smp/sml/SmlConnector.java    | 26 ++++----
 .../smp/sml/SmlConnectorDomainTest.java       | 65 +++++++++----------
 .../ServiceMetadataController.java            |  2 +-
 14 files changed, 161 insertions(+), 101 deletions(-)

diff --git a/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/AbstractIdentifierFormatter.java b/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/AbstractIdentifierFormatter.java
index ec81a50ce..a68ec98d8 100644
--- a/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/AbstractIdentifierFormatter.java
+++ b/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/AbstractIdentifierFormatter.java
@@ -82,6 +82,26 @@ public abstract class AbstractIdentifierFormatter<T> {
         return DEFAULT_FORMATTER.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 DEFAULT_FORMATTER.format(scheme, identifier, noDelimiterOnBlankScheme);
+    }
+
     /**
      * Parse identifier.
      * <p>
diff --git a/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/EBCorePartyIdFormatterType.java b/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/EBCorePartyIdFormatterType.java
index 38ea355a6..e8431c030 100644
--- a/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/EBCorePartyIdFormatterType.java
+++ b/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/EBCorePartyIdFormatterType.java
@@ -2,10 +2,12 @@ package eu.europa.ec.smp.api.identifiers.types;
 
 import eu.europa.ec.smp.api.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.startsWithIgnoreCase;
+import static org.apache.commons.lang3.StringUtils.*;
 
 
 /**
@@ -16,61 +18,70 @@ import static org.apache.commons.lang3.StringUtils.startsWithIgnoreCase;
  * <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)){
+        if (StringUtils.isBlank(scheme)) {
+            LOG.debug("EBCorePartyIdFormatterType does not support identifiers with Null/Blank scheme");
             return false;
         }
-        if (partyIdPrivate.startsWith("::")) {
-            partyIdPrivate = StringUtils.removeStart(partyIdPrivate, "::");
-        }
+        partyIdPrivate = removeStart(partyIdPrivate, OASIS_SMP_SEPARATOR);
+
         return startsWithIgnoreCase(partyIdPrivate, EBCORE_IDENTIFIER_PREFIX);
     }
 
     @Override
-    public boolean isType(final String value){
+    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 scheme + EBCORE_SEPARATOR + identifier;
+        return format(scheme, identifier, true);
     }
 
     @Override
     public String[] parse(final String value) {
 
-        String partyIdPrivate = value.trim();
-        if (partyIdPrivate.startsWith("::")) {
-            partyIdPrivate = StringUtils.removeStart(partyIdPrivate, "::");
-        }
-        // replace first double :: with  :
-        partyIdPrivate = StringUtils.replace(partyIdPrivate, "::",":", 1);
+        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 + ":");
-        boolean isUnregistered = StringUtils.startsWithIgnoreCase(partyIdPrivate,EBCORE_IDENTIFIER_PREFIX + EBCORE_IDENTIFIER_UNREGISTERED_SCHEME + ":");
-        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) +"!");
+        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_IDENTIFIER_PREFIX.length());
+        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', " +
@@ -93,14 +104,10 @@ public class EBCorePartyIdFormatterType implements FormatterType {
             result[1] = partyIdPrivate.substring(isPartDelimiter + 1).trim();
         }
 
-        //check if double colon was used for identifier separator in ebecoreid
-        if (result[1].startsWith(":")) {
-            result[1] = StringUtils.removeStart(result[1], ":");
-        }
-        //check if double colon was used for identifier separator in ebecoreid
-        if (result[0].endsWith(":")) {
-            result[0] = StringUtils.removeEnd(result[0], ":");
-        }
+        // 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;
     }
 }
\ No newline at end of file
diff --git a/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/FormatterType.java b/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/FormatterType.java
index b559e8d1d..fc8b16484 100644
--- a/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/FormatterType.java
+++ b/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/FormatterType.java
@@ -9,11 +9,22 @@ package eu.europa.ec.smp.api.identifiers.types;
  */
 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);
-    // check if formatter can parse the value
+
+    /**
+     * 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-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/OasisSMPFormatterType.java b/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/OasisSMPFormatterType.java
index b8bd3fd60..50e9c94cf 100644
--- a/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/OasisSMPFormatterType.java
+++ b/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/OasisSMPFormatterType.java
@@ -25,10 +25,16 @@ public class OasisSMPFormatterType implements FormatterType {
         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 (isEmpty(scheme) ? "" : scheme) + SEPARATOR + identifier;
+        return format(scheme, identifier, false);
     }
 
     @Override
diff --git a/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/TemplateFormatterType.java b/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/TemplateFormatterType.java
index 8d425bb4b..812d3ebd4 100644
--- a/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/TemplateFormatterType.java
+++ b/smp-api/src/main/java/eu/europa/ec/smp/api/identifiers/types/TemplateFormatterType.java
@@ -24,9 +24,9 @@ public class TemplateFormatterType implements FormatterType {
     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 + "}"};
 
-    Pattern splitRegularExpression;
-    Pattern schemaPattern;
-    String formatTemplate;
+    private final Pattern splitRegularExpression;
+    private final Pattern schemaPattern;
+    private final String formatTemplate;
 
     public TemplateFormatterType(Pattern matchSchema, String formatTemplate, Pattern splitRegularExpression) {
         this.schemaPattern = matchSchema;
@@ -34,18 +34,26 @@ public class TemplateFormatterType implements FormatterType {
         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);
@@ -53,8 +61,14 @@ public class TemplateFormatterType implements FormatterType {
     }
 
     @Override
-    public String format(final String scheme, final String identifier) {
+    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
diff --git a/smp-api/src/test/java/eu/europa/ec/smp/api/identifiers/types/EBCorePartyIdFormatterTypeTest.java b/smp-api/src/test/java/eu/europa/ec/smp/api/identifiers/types/EBCorePartyIdFormatterTypeTest.java
index b26cf9cff..e6daa95e4 100644
--- a/smp-api/src/test/java/eu/europa/ec/smp/api/identifiers/types/EBCorePartyIdFormatterTypeTest.java
+++ b/smp-api/src/test/java/eu/europa/ec/smp/api/identifiers/types/EBCorePartyIdFormatterTypeTest.java
@@ -10,7 +10,7 @@ import org.junit.runners.Parameterized;
 import java.util.Arrays;
 import java.util.Collection;
 
-import static org.apache.commons.lang3.StringUtils.trim;
+import static org.apache.commons.lang3.StringUtils.*;
 import static org.junit.Assert.*;
 
 /**
@@ -143,8 +143,10 @@ public class EBCorePartyIdFormatterTypeTest {
             return;
         }
 
-        String result = testInstance.format(idPart, schemaPart);
-        assertEquals(trim(idPart) + ":" + trim(schemaPart), result);
+        String result = testInstance.format(schemaPart, idPart);
+
+        String schema = trimToEmpty(schemaPart);
+        assertEquals(schema + ":" + trimToEmpty(idPart), result);
     }
 
     @Test
diff --git a/smp-api/src/test/java/eu/europa/ec/smp/api/identifiers/types/OasisSMPFormatterTypeTest.java b/smp-api/src/test/java/eu/europa/ec/smp/api/identifiers/types/OasisSMPFormatterTypeTest.java
index cfd111a6c..7deac8c8e 100644
--- a/smp-api/src/test/java/eu/europa/ec/smp/api/identifiers/types/OasisSMPFormatterTypeTest.java
+++ b/smp-api/src/test/java/eu/europa/ec/smp/api/identifiers/types/OasisSMPFormatterTypeTest.java
@@ -10,7 +10,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.regex.Pattern;
 
-import static org.apache.commons.lang3.StringUtils.trim;
+import static org.apache.commons.lang3.StringUtils.*;
 import static org.junit.Assert.*;
 
 /**
@@ -22,7 +22,7 @@ public class OasisSMPFormatterTypeTest {
 
 
     @Parameterized.Parameters(name = "{index}: {0}")
-    public static Collection participantIdentifierPositiveCases() {
+    public static Collection<Object> participantIdentifierPositiveCases() {
         return Arrays.asList(new Object[][]{
                 {
                         "Valid peppol party identifier",
@@ -91,8 +91,13 @@ public class OasisSMPFormatterTypeTest {
             return;
         }
 
-        String result = testInstance.format(idPart, schemaPart);
-        assertEquals(trim(idPart) + "::" + trim(schemaPart), result);
+        String result = testInstance.format(schemaPart, idPart);
+        String resultNoDelimiterForNullSchema = testInstance.format(schemaPart, idPart, true);
+
+        String schema = trimToEmpty(schemaPart);
+        assertEquals(schema + "::" + trim(idPart), result);
+
+        assertEquals((isEmpty(schema)?"":schema + "::") + trim(idPart), resultNoDelimiterForNullSchema);
     }
 
     @Test
diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverter.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverter.java
index fbc646d36..7a0199100 100644
--- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverter.java
+++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/ServiceGroupConverter.java
@@ -40,7 +40,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
  *  Purpose of class is to test ServiceGroupService base methods
  *
  * @author migueti
- * @since 3.0.0.
+ * @since 3.0.0
  */
 public class ServiceGroupConverter {
 
@@ -72,8 +72,8 @@ public class ServiceGroupConverter {
     /**
      * Method unmarshal ServiceGroup from xml string
      *
-     * @param serviceGroupXml
-     * @return
+     * @param serviceGroupXml service group xml
+     * @return java object Object
      */
     public static ServiceGroup unmarshal(String serviceGroupXml) {
         try {
diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/SMPRevisionListener.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/SMPRevisionListener.java
index e1ef341a5..24c0136f7 100644
--- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/SMPRevisionListener.java
+++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/SMPRevisionListener.java
@@ -1,7 +1,6 @@
 package eu.europa.ec.edelivery.smp.data.dao;
 
 import eu.europa.ec.edelivery.smp.data.model.DBRevisionLog;
-import eu.europa.ec.edelivery.smp.services.ServiceGroupService;
 import org.apache.commons.lang3.StringUtils;
 import org.hibernate.envers.RevisionListener;
 import org.slf4j.Logger;
@@ -13,7 +12,7 @@ import java.time.OffsetDateTime;
 
 public class SMPRevisionListener implements RevisionListener {
 
-    private static final Logger LOG = LoggerFactory.getLogger(ServiceGroupService.class);
+    private static final Logger LOG = LoggerFactory.getLogger(SMPRevisionListener.class);
 
     @Override
     public void newRevision(Object revisionEntity) {
diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/enums/SMPPropertyEnum.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/enums/SMPPropertyEnum.java
index bd8474759..8c504ca2e 100644
--- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/enums/SMPPropertyEnum.java
+++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/ui/enums/SMPPropertyEnum.java
@@ -37,7 +37,7 @@ public enum SMPPropertyEnum {
             OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, STRING),
 
     PARTC_SCH_VALIDATION_REGEXP("identifiersBehaviour.ParticipantIdentifierScheme.validationRegex", "^$|^(?!^.{26})([a-z0-9]+-[a-z0-9]+-[a-z0-9]+)$|^urn:oasis:names:tc:ebcore:partyid-type:(iso6523|unregistered)(:.+)?$",
-            "Url expression for validating the participant schema!",
+            "Regular expression for validating the participant schema!",
             OPTIONAL, NOT_ENCRYPTED, NO_RESTART_NEEDED, REGEXP),
     PARTC_SCH_REGEXP_MSG("identifiersBehaviour.ParticipantIdentifierScheme.validationRegexMessage",
             "Participant scheme must start with:urn:oasis:names:tc:ebcore:partyid-type:(iso6523:|unregistered:) OR must be up to 25 characters long with form [domain]-[identifierArea]-[identifierType] (ex.: 'busdox-actorid-upis') and may only contain the following characters: [a-z0-9].", "Error message for UI",
diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java
index f923a7025..a180872cb 100644
--- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java
+++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/services/ServiceGroupService.java
@@ -40,7 +40,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.xml.bind.JAXBException;
 import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
 import java.util.regex.Pattern;
@@ -50,15 +49,16 @@ import static java.net.URLDecoder.decode;
 import static org.apache.commons.lang3.StringUtils.isNotBlank;
 
 /**
- *  Purpose of class is to test ServiceGroupService base methods
+ * Purpose of class is to test ServiceGroupService base methods
  *
  * @author gutowpa
- * @since 3.0.0.
+ * @since 3.0.0
  */
 @Service
 public class ServiceGroupService {
 
 
+
     private static final String UTF_8 = "UTF-8";
 
     private static final SMPLogger LOG = SMPLoggerFactory.getLogger(ServiceGroupService.class);
@@ -289,7 +289,8 @@ public class ServiceGroupService {
      * empty ServiceMetadataReferenceCollectionType. If extension can not be converted to jaxb object than
      * ConversionException is thrown.
      *
-     * @param dsg - database service group entity
+     * @param dsg                - database service group entity
+     * @param concatenatePartyId - regular expression if servicegroup in party identifier must be concatenate and returned in string value.
      * @return Oasis ServiceGroup entity or null if parameter is null
      */
     public ServiceGroup toServiceGroup(DBServiceGroup dsg, Pattern concatenatePartyId) {
@@ -302,7 +303,7 @@ public class ServiceGroupService {
         String schema = dsg.getParticipantScheme();
         String value = dsg.getParticipantIdentifier();
 
-        if (StringUtils.isNotBlank(schema) &&  concatenatePartyId!=null && concatenatePartyId.matcher(schema).matches()) {
+        if (StringUtils.isNotBlank(schema) && concatenatePartyId != null && concatenatePartyId.matcher(schema).matches()) {
             value = identifierService.formatParticipant(schema, value);
             schema = null;
         }
@@ -317,7 +318,7 @@ public class ServiceGroupService {
                         dsg.getParticipantScheme(), ExceptionUtils.getRootCauseMessage(e));
             }
         }
-        serviceGroup.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType(new ArrayList()));
+        serviceGroup.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
         return serviceGroup;
     }
 }
diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/sml/SmlConnector.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/sml/SmlConnector.java
index c5211dad4..f6cb2c301 100644
--- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/sml/SmlConnector.java
+++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/sml/SmlConnector.java
@@ -56,7 +56,6 @@ import javax.xml.ws.handler.MessageContext;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.*;
-import java.util.regex.Pattern;
 
 import static eu.europa.ec.edelivery.smp.conversion.SmlIdentifierConverter.toBusdoxParticipantId;
 import static eu.europa.ec.edelivery.smp.exceptions.SMLErrorMessages.*;
@@ -92,7 +91,6 @@ public class SmlConnector implements ApplicationContextAware {
     private ApplicationContext ctx;
 
 
-
     public boolean registerInDns(ParticipantIdentifierType normalizedParticipantId, DBDomain domain) {
 
 
@@ -176,31 +174,30 @@ public class SmlConnector implements ApplicationContextAware {
             smlSmpRequest.getPublisherEndpoint().setPhysicalAddress(smpPhysicalAddress);
             smlSmpRequest.setServiceMetadataPublisherID(domain.getSmlSmpId());
             getSMPManagerWSClient(domain).create(smlSmpRequest);
-            return true;
         } catch (BadRequestFault e) {
-            return processSMLErrorMessage(e, domain);
+            processSMLErrorMessage(e, domain);
         } catch (Exception e) {
             LOG.error(e.getClass().getName() + "" + e.getMessage(), e);
             throw new SMPRuntimeException(ErrorCode.SML_INTEGRATION_EXCEPTION, e, ExceptionUtils.getRootCauseMessage(e));
         }
+        // if not error is thrown - the registration is done OK.
+        return true;
     }
 
-    private boolean processSMLErrorMessage(BadRequestFault e, DBDomain domain) {
+    private void processSMLErrorMessage(BadRequestFault e, DBDomain domain) {
         if (!isOkMessage(domain, e.getMessage())) {
             LOG.error(e.getMessage(), e);
             throw new SMPRuntimeException(ErrorCode.SML_INTEGRATION_EXCEPTION, e, ExceptionUtils.getRootCauseMessage(e));
         }
         LOG.warn(e.getMessage(), e);
-        return true;
     }
 
-    private boolean processSMLErrorMessage(NotFoundFault e, DBDomain domain) {
+    private void processSMLErrorMessage(NotFoundFault e, DBDomain domain) {
         if (!isOkMessage(domain, e.getMessage())) {
             LOG.error(e.getMessage(), e);
             throw new SMPRuntimeException(ErrorCode.SML_INTEGRATION_EXCEPTION, e, ExceptionUtils.getRootCauseMessage(e));
         }
         LOG.warn(e.getMessage(), e);
-        return true;
     }
 
     /**
@@ -248,18 +245,17 @@ public class SmlConnector implements ApplicationContextAware {
         }
     }
 
-    public boolean unregisterDomain(DBDomain domain) {
+    public void unregisterDomain(DBDomain domain) {
         if (!configurationService.isSMLIntegrationEnabled()) {
-            return true;
+            return;
         }
         LOG.info("Removing SMP id (Domain) from BDMSL: {} ", domain.getDomainCode());
         try {
             getSMPManagerWSClient(domain).delete(domain.getSmlSmpId());
-            return true;
         } catch (BadRequestFault e) {
-            return processSMLErrorMessage(e, domain);
+            processSMLErrorMessage(e, domain);
         } catch (NotFoundFault e) {
-            return processSMLErrorMessage(e, domain);
+            processSMLErrorMessage(e, domain);
         } catch (Exception e) {
             LOG.error(e.getClass().getName() + "" + e.getMessage(), e);
             throw new SMPRuntimeException(ErrorCode.SML_INTEGRATION_EXCEPTION, e, ExceptionUtils.getRootCauseMessage(e));
@@ -342,7 +338,7 @@ public class SmlConnector implements ApplicationContextAware {
         }
 
         if (!clientCertAuthentication && !useTLS) {
-            LOG.warn("SML integration is wrongly configured. Uses 2-way-SSL HTTPS but URL is not HTTPS! Url: {}.", urlSMPManagment.toString());
+            LOG.warn("SML integration is wrongly configured. Uses 2-way-SSL HTTPS but URL is not HTTPS! Url: [{}].", urlSMPManagment);
         }
 
         HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
@@ -439,7 +435,7 @@ public class SmlConnector implements ApplicationContextAware {
         LOG.info("Configuring proxy for BDMSL integration client: {}:{}@{}:{}", proxyUser, "******", proxyServer, proxyPort.isPresent() ? proxyPort.get() : "");
         httpConduit.getClient().setProxyServerType(ProxyServerType.HTTP);
         httpConduit.getClient().setProxyServer(proxyServer);
-        proxyPort.ifPresent(integer -> httpConduit.getClient().setProxyServerPort(integer));
+        proxyPort.ifPresent(port -> httpConduit.getClient().setProxyServerPort(port));
 
         if (!StringUtils.isBlank(proxyUser)) {
             ProxyAuthorizationPolicy proxyAuth = new ProxyAuthorizationPolicy();
diff --git a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorDomainTest.java b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorDomainTest.java
index 0e99e9a65..840dafb84 100644
--- a/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorDomainTest.java
+++ b/smp-server-library/src/test/java/eu/europa/ec/edelivery/smp/sml/SmlConnectorDomainTest.java
@@ -14,32 +14,33 @@
 
 package eu.europa.ec.edelivery.smp.sml;
 
-        import eu.europa.ec.bdmsl.ws.soap.BadRequestFault;
-        import eu.europa.ec.bdmsl.ws.soap.InternalErrorFault;
-        import eu.europa.ec.bdmsl.ws.soap.NotFoundFault;
-        import eu.europa.ec.bdmsl.ws.soap.UnauthorizedFault;
-        import eu.europa.ec.edelivery.smp.config.SmlIntegrationConfiguration;
-        import eu.europa.ec.edelivery.smp.data.model.DBDomain;
-        import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
-        import eu.europa.ec.edelivery.smp.services.AbstractServiceIntegrationTest;
-        import eu.europa.ec.edelivery.smp.services.ConfigurationService;
-        import org.junit.Before;
-        import org.junit.Rule;
-        import org.junit.Test;
-        import org.junit.rules.ExpectedException;
-        import org.junit.runner.RunWith;
-        import org.mockito.Mockito;
-        import org.springframework.beans.factory.annotation.Autowired;
-        import org.springframework.test.context.ContextConfiguration;
-        import org.springframework.test.context.junit4.SpringRunner;
-        import org.springframework.test.util.ReflectionTestUtils;
-
-        import java.util.UUID;
-
-        import static eu.europa.ec.edelivery.smp.sml.SmlConnectorTestConstants.*;
-        import static org.junit.Assert.*;
-        import static org.mockito.ArgumentMatchers.any;
-        import static org.mockito.Mockito.verify;
+import eu.europa.ec.bdmsl.ws.soap.BadRequestFault;
+import eu.europa.ec.bdmsl.ws.soap.InternalErrorFault;
+import eu.europa.ec.bdmsl.ws.soap.NotFoundFault;
+import eu.europa.ec.bdmsl.ws.soap.UnauthorizedFault;
+import eu.europa.ec.edelivery.smp.config.SmlIntegrationConfiguration;
+import eu.europa.ec.edelivery.smp.data.model.DBDomain;
+import eu.europa.ec.edelivery.smp.exceptions.SMPRuntimeException;
+import eu.europa.ec.edelivery.smp.services.AbstractServiceIntegrationTest;
+import eu.europa.ec.edelivery.smp.services.ConfigurationService;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.UUID;
+
+import static eu.europa.ec.edelivery.smp.sml.SmlConnectorTestConstants.*;
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
 
 /**
  * Created by JRC
@@ -67,7 +68,7 @@ public class SmlConnectorDomainTest extends AbstractServiceIntegrationTest {
         testInstance = Mockito.spy(testInstance);
         // default behaviour
         Mockito.doNothing().when(testInstance).configureClient(any(), any(), any());
-        ReflectionTestUtils.setField(testInstance,"configurationService",configurationService);
+        ReflectionTestUtils.setField(testInstance, "configurationService", configurationService);
         Mockito.doReturn(true).when(configurationService).isSMLIntegrationEnabled();
         mockSml.reset();
     }
@@ -127,10 +128,9 @@ public class SmlConnectorDomainTest extends AbstractServiceIntegrationTest {
     @Test
     public void testDomainUnregisterFromDns() throws UnauthorizedFault, NotFoundFault, InternalErrorFault, BadRequestFault {
         //when
-        boolean result = testInstance.unregisterDomain(DEFAULT_DOMAIN);
+        testInstance.unregisterDomain(DEFAULT_DOMAIN);
 
         //then
-        assertTrue(result);
         assertEquals(1, mockSml.getSmpManagerClientMocks().size());
         verify(mockSml.getSmpManagerClientMocks().get(0)).delete(any());
         Mockito.verifyNoMoreInteractions(mockSml.getSmpManagerClientMocks().toArray());
@@ -177,9 +177,8 @@ public class SmlConnectorDomainTest extends AbstractServiceIntegrationTest {
         //when
         BadRequestFault ex = new BadRequestFault(ERROR_SMP_NOT_EXISTS);
         mockSml.setThrowException(ex);
-        boolean suc = testInstance.unregisterDomain(DEFAULT_DOMAIN);
 
-        assertTrue(suc);
+        Assertions.assertDoesNotThrow(() -> testInstance.unregisterDomain(DEFAULT_DOMAIN););
     }
 
     @Test
@@ -200,7 +199,7 @@ public class SmlConnectorDomainTest extends AbstractServiceIntegrationTest {
     @Test
     public void testGetSmlClientKeyAliasForDomain() {
 
-        DBDomain domain  = new DBDomain();
+        DBDomain domain = new DBDomain();
         domain.setSmlClientKeyAlias(UUID.randomUUID().toString());
         domain.setSmlClientCertAuth(false);
 
@@ -212,7 +211,7 @@ public class SmlConnectorDomainTest extends AbstractServiceIntegrationTest {
     @Test
     public void testGetSmlClientKeyAliasForDomainNulForSingleKey() {
 
-        DBDomain domain  = new DBDomain();
+        DBDomain domain = new DBDomain();
         domain.setSmlClientKeyAlias(null);
         domain.setSmlClientCertAuth(false);
 
diff --git a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java
index 93161ee34..868d36861 100644
--- a/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java
+++ b/smp-webapp/src/main/java/eu/europa/ec/edelivery/smp/controllers/ServiceMetadataController.java
@@ -42,7 +42,7 @@ import static org.springframework.http.ResponseEntity.ok;
 
 /**
  * @author gutowpa
- * @since 3.0.0.
+ * @since 3.0.0
  */
 @RestController
 @RequestMapping("/{serviceGroupId}/services/{serviceMetadataId}")
-- 
GitLab