diff --git a/smp-angular/src/app/service-group-edit/service-group-metadata-dialog/service-group-metadata-dialog.component.html b/smp-angular/src/app/service-group-edit/service-group-metadata-dialog/service-group-metadata-dialog.component.html index ca070b24d7994f15d9fe3b092d8564caf5f81f46..d1e73a67e924ee40aba211e874acf8f082fedcf2 100644 --- a/smp-angular/src/app/service-group-edit/service-group-metadata-dialog/service-group-metadata-dialog.component.html +++ b/smp-angular/src/app/service-group-edit/service-group-metadata-dialog/service-group-metadata-dialog.component.html @@ -28,7 +28,7 @@ <mat-form-field style="width:30%"> <input matInput placeholder="Document identifier scheme" name="documentScheme" id="documentScheme_id" - [formControl]="dialogForm.controls['documentIdentifierScheme']" maxlength="255" required> + [formControl]="dialogForm.controls['documentIdentifierScheme']" maxlength="255" > </mat-form-field> <mat-form-field style="width:55%"> <input matInput placeholder="Document identifier" name="documentIdentifier" id="documentIdentifier_id" diff --git a/smp-angular/src/app/service-group-edit/service-group-metadata-dialog/service-group-metadata-dialog.component.ts b/smp-angular/src/app/service-group-edit/service-group-metadata-dialog/service-group-metadata-dialog.component.ts index 93a0ae4dce5188fa8a7632ba34885188ad79554c..50fcfd9337018bf87f07dc094b912cb1761c46b7 100644 --- a/smp-angular/src/app/service-group-edit/service-group-metadata-dialog/service-group-metadata-dialog.component.ts +++ b/smp-angular/src/app/service-group-edit/service-group-metadata-dialog/service-group-metadata-dialog.component.ts @@ -72,7 +72,7 @@ export class ServiceGroupMetadataDialogComponent implements OnInit { value: this.current.documentIdentifierScheme, disabled: this.editMode }, - [Validators.required]), + []), 'xmlContent': new FormControl({value: ''}, [Validators.required]), }); diff --git a/smp-api/src/main/java/eu/europa/ec/smp/api/Identifiers.java b/smp-api/src/main/java/eu/europa/ec/smp/api/Identifiers.java index 76d3f8188f04afb90f05fe84749381d301009f45..da32eb4eb481d4e79576e913a21d1cb8a2140fff 100644 --- a/smp-api/src/main/java/eu/europa/ec/smp/api/Identifiers.java +++ b/smp-api/src/main/java/eu/europa/ec/smp/api/Identifiers.java @@ -14,6 +14,7 @@ package eu.europa.ec.smp.api; import eu.europa.ec.smp.api.exceptions.MalformedIdentifierException; +import org.apache.commons.lang3.StringUtils; import org.oasis_open.docs.bdxr.ns.smp._2016._05.DocumentIdentifier; import org.oasis_open.docs.bdxr.ns.smp._2016._05.ParticipantIdentifierType; import org.oasis_open.docs.bdxr.ns.smp._2016._05.ProcessIdentifier; @@ -34,6 +35,7 @@ public class Identifiers { private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("^(?<scheme>.+?)::(?<value>.+)$"); + public static ParticipantIdentifierType asParticipantId(String doubleColonDelimitedId) { String scheme = extract(doubleColonDelimitedId, "scheme"); String value = extract(doubleColonDelimitedId, "value"); @@ -41,9 +43,8 @@ public class Identifiers { } public static DocumentIdentifier asDocumentId(String doubleColonDelimitedId) { - String scheme = extract(doubleColonDelimitedId, "scheme"); - String value = extract(doubleColonDelimitedId, "value"); - return new DocumentIdentifier(value, scheme); + String[] res = splitIdentifier(doubleColonDelimitedId); + return new DocumentIdentifier(res[1], res[0]); } public static ProcessIdentifier asProcessId(String doubleColonDelimitedId) { @@ -57,7 +58,7 @@ public class Identifiers { } public static String asString(DocumentIdentifier docId) { - return String.format("%s::%s", docId.getScheme(), docId.getValue()); + return String.format("%s::%s", docId.getScheme()!=null?docId.getScheme():"", docId.getValue()); } public static String asUrlEncodedString(ParticipantIdentifierType participantId) { @@ -85,4 +86,32 @@ public class Identifiers { throw new MalformedIdentifierException(doubleColonDelimitedId, e); } } + + /** + * Method splits identifier at first occurance of double colon :: and returns array size of 2. The first value is + * schema and the second is identifier. If identifier is blank or with missing :: MalformedIdentifierException is thrown + * @param doubleColonDelimitedId + * @return array with two elements. First is schema and second is id + */ + private static String[] splitIdentifier(String doubleColonDelimitedId) { + String[] idResult = new String[2]; + if (StringUtils.isBlank(doubleColonDelimitedId)){ + throw new MalformedIdentifierException(doubleColonDelimitedId, null); + } + int delimiterIndex = doubleColonDelimitedId.indexOf("::"); + if (delimiterIndex<0){ + throw new MalformedIdentifierException(doubleColonDelimitedId, null); + } + idResult[0] = doubleColonDelimitedId.substring(0,delimiterIndex); + idResult[1] = doubleColonDelimitedId.substring(delimiterIndex+2); + + if (StringUtils.isBlank(idResult[1])){ + throw new MalformedIdentifierException(doubleColonDelimitedId, null); + } + + return idResult; + + } + + } diff --git a/smp-api/src/test/java/eu/europa/ec/smp/api/IdentifiersTest.java b/smp-api/src/test/java/eu/europa/ec/smp/api/IdentifiersTest.java index 64a37e8dd6a5e88ccc1f4259fc7cc49683343452..66eaaaeab90f428286982c0210adebbfd03d6512 100644 --- a/smp-api/src/test/java/eu/europa/ec/smp/api/IdentifiersTest.java +++ b/smp-api/src/test/java/eu/europa/ec/smp/api/IdentifiersTest.java @@ -66,6 +66,40 @@ public class IdentifiersTest { }; } + private static final Object[] negativeCases() { + return new Object[]{ + null, + "", + "a", + "abc", + "a:b", + "a::", + "ehealth-actorid-qns", + "urn:poland:ncpb", + "ehealth-resid-qns", + "epsos##services:extended:epsos:51", + "::a", + }; + } + + private static final Object[] documentTestCases() { + Object[] commonTests = testCases(); + Object[] res = new Object[commonTests.length+2]; + System.arraycopy(commonTests, 0,res, 0, commonTests.length ); + //add new test with empty schema + res[commonTests.length] = new Object[]{"::a","","a"}; + res[commonTests.length+1] = new Object[]{"::urn:ehealth:ncp::pt:ism","","urn:ehealth:ncp::pt:ism"}; + return res; + } + + private static final Object[] negativeDocumentCases() { + Object[] commonNegativeTests = negativeCases(); + Object[] res = new Object[commonNegativeTests.length-1]; // skip last one + System.arraycopy(commonNegativeTests, 0,res, 0, commonNegativeTests.length-1 ); + + return res; + } + @Test @Parameters(method = "testCases") @@ -79,7 +113,7 @@ public class IdentifiersTest { } @Test - @Parameters(method = "testCases") + @Parameters(method = "documentTestCases") public void testDocumentIdPositive(String input, String scheme, String value) { //when DocumentIdentifier documentId = Identifiers.asDocumentId(input); @@ -101,23 +135,6 @@ public class IdentifiersTest { } - - private static final Object[] negativeCases() { - return new Object[]{ - null, - "", - "a", - "abc", - "a:b", - "::a", - "a::", - "ehealth-actorid-qns", - "urn:poland:ncpb", - "ehealth-resid-qns", - "epsos##services:extended:epsos:51" - }; - } - @Test @Parameters(method = "negativeCases") public void testProcessIdNegative(String negativeInput) { @@ -133,7 +150,7 @@ public class IdentifiersTest { } @Test - @Parameters(method = "negativeCases") + @Parameters(method = "negativeDocumentCases") public void testDocumentIdNegative(String negativeInput) { try { //when diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/CaseSensitivityNormalizer.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/CaseSensitivityNormalizer.java index ddd5bb0c4fbdf7e0e1110c5de709a6612c90c90f..6b623275c7e53cee7bfdad83b1724c0cb171b385 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/CaseSensitivityNormalizer.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/CaseSensitivityNormalizer.java @@ -66,8 +66,10 @@ public class CaseSensitivityNormalizer { } public DocumentIdentifier normalizeDocumentIdentifier( String scheme, String value) { - if (!caseSensitiveDocumentSchemes.contains(scheme.toLowerCase())) { - scheme = scheme.toLowerCase(); + if (scheme== null || !caseSensitiveDocumentSchemes.contains(scheme.toLowerCase())) { + if (scheme!= null) { + scheme = scheme.toLowerCase(); + } value = value.toLowerCase(); } return new DocumentIdentifier(value, scheme); diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ServiceMetadataDao.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ServiceMetadataDao.java index 37f44a5fad879b4c472a976baffc9efa4ecfbf08..2651e82882f7cc5bdf0e2dbf67530a1d3d8717a5 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ServiceMetadataDao.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/dao/ServiceMetadataDao.java @@ -48,7 +48,7 @@ public class ServiceMetadataDao extends BaseDao<DBServiceMetadata> { query.setParameter("partcId", participantId); query.setParameter("partcSch", participantSchema); query.setParameter("docId", documentId); - query.setParameter("docSch", documentSchema); + query.setParameter("docSch", documentSchema==null?"":documentSchema); DBServiceMetadata res = query.getSingleResult(); return Optional.of(res); } catch (NoResultException e) { diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java index d50ca7eb7697ef24c27e2b4d303b3201058baa41..72cce2a00349f7420001d9c0248cb4c329f2505f 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/exceptions/ErrorCode.java @@ -10,6 +10,7 @@ package eu.europa.ec.edelivery.smp.exceptions; public enum ErrorCode { INVALID_ENCODING (500, "SMP:100",ErrorBusinessCode.TECHNICAL, "Unsupported or invalid encoding for %s!"), + SML_INVALID_IDENTIFIER (400,"SMP:101",ErrorBusinessCode.FORMAT_ERROR,"Malformed identifier, scheme and id should be delimited by double colon: %s "), // domain error NO_DOMAIN (500,"SMP:110",ErrorBusinessCode.TECHNICAL, "No domain configured on SMP, at least one domain is mandatory!"), @@ -35,7 +36,6 @@ public enum ErrorCode { INVALID_EXTENSION_FOR_SG (400,"SMP:132",ErrorBusinessCode.XSD_INVALID,"Invalid extension for service group (part. id: '%s', part. sch.: '%s'). Error: %s!"), DUPLICATE_DOMAIN_FOR_SG (400,"SMP:133",ErrorBusinessCode.INVALID_INPUT_DATA,"Repeated domain for Service group (part. id: '%s', part. sch.: '%s', domainCode %s, smlDomain %s).!"), MISSING_SG_ID (400,"SMP:134",ErrorBusinessCode.INVALID_INPUT_DATA,"Missing service group(part. id: '%s', part. sch.: '%s'!"), - INVALID_SG_ID (400,"SMP:135",ErrorBusinessCode.INVALID_INPUT_DATA,"Invalid Id for Service group(part. id: '%s', part. sch.: '%s', id %d).!"), @@ -50,6 +50,7 @@ public enum ErrorCode { // SML integration SML_INTEGRATION_EXCEPTION (500,"SMP:150",ErrorBusinessCode.TECHNICAL,"Could not create new DNS entry through SML! Error: %s "), + // XML_SIGNING_EXCEPTION (500,"SMP:500",ErrorBusinessCode.TECHNICAL,"Error occurred while signing response!"),