Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit ab579648 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

Merge pull request #124 in EDELIVERY/smp from...

Merge pull request #124 in EDELIVERY/smp from bugfix/EDELIVERY-3617-null-schema-type-for-document-action to development

* commit 'bead86591fe7ef49b33dd9968d8252ada50cc980':
  Use StringUtils for converting string to lowercase
  added option for null document schema
parents 39b360b7 795cd864
No related branches found
No related tags found
No related merge requests found
......@@ -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"
......
......@@ -72,7 +72,7 @@ export class ServiceGroupMetadataDialogComponent implements OnInit {
value: this.current.documentIdentifierScheme,
disabled: this.editMode
},
[Validators.required]),
[]),
'xmlContent': new FormControl({value: ''}, [Validators.required]),
});
......
......@@ -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;
}
}
......@@ -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
......
......@@ -13,6 +13,7 @@
package eu.europa.ec.edelivery.smp.conversion;
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.springframework.beans.factory.annotation.Value;
......@@ -46,9 +47,9 @@ public class CaseSensitivityNormalizer {
}
public ParticipantIdentifierType normalizeParticipantIdentifier(String scheme, String value) {
if (!caseSensitiveParticipantSchemes.contains(scheme.toLowerCase())) {
scheme = scheme.toLowerCase();
value = value.toLowerCase();
if (!caseSensitiveParticipantSchemes.contains(StringUtils.lowerCase(scheme))) {
scheme = StringUtils.lowerCase(scheme);
value = StringUtils.lowerCase(value);
}
return new ParticipantIdentifierType(value, scheme);
}
......@@ -66,9 +67,9 @@ public class CaseSensitivityNormalizer {
}
public DocumentIdentifier normalizeDocumentIdentifier( String scheme, String value) {
if (!caseSensitiveDocumentSchemes.contains(scheme.toLowerCase())) {
scheme = scheme.toLowerCase();
value = value.toLowerCase();
if (!caseSensitiveDocumentSchemes.contains(StringUtils.lowerCase(scheme) )) {
scheme = StringUtils.lowerCase(scheme);
value = StringUtils.lowerCase(value);
}
return new DocumentIdentifier(value, scheme);
}
......
......@@ -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) {
......
......@@ -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!"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment