diff --git a/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/AnnotationTestsConstants.java b/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/AnnotationTestsConstants.java index 9b2608c02..45face57a 100644 --- a/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/AnnotationTestsConstants.java +++ b/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/AnnotationTestsConstants.java @@ -82,6 +82,7 @@ public String get_TAG_STANDARD_TEST_VALUE_TARGET(String itemDataEndpoint) { public static final String SEMANTICTAG_ENTITY = "/semantictag/semantictag_entity.json"; public static final String SEMANTICTAG_AGENT_ENTITY = "/semantictag/semantictag_agent_entity.json"; public static final String SEMANTICTAG_VCARD_ADDRESS = "/semantictag/vcard_address.json"; + public static final String SEMANTICTAG_WRONG_MISSING_SCOPE = "/semantictag/wrong/web_resource_missing_scope.json"; public static final String TAG_CANONICAL = "/tag/canonical.json"; public static final String TAG_VIA_STRING = "/tag/via_string.json"; public static final String TAG_VIA_ARRAY = "/tag/via_array.json"; diff --git a/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/web/AnnotationCreateIT.java b/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/web/AnnotationCreateIT.java index 6522d500d..e19f9b102 100644 --- a/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/web/AnnotationCreateIT.java +++ b/annotation-tests/src/integration-test/java/eu/europeana/annotation/tests/web/AnnotationCreateIT.java @@ -436,6 +436,13 @@ void createWrongTag() throws Exception { assertEquals(response.getStatusCode().value(), HttpStatus.BAD_REQUEST.value()); } + @Test + void createSemanticTagWithMissingScope() throws Exception { + String requestBody = AnnotationTestUtils.getJsonStringInput(SEMANTICTAG_WRONG_MISSING_SCOPE); + ResponseEntity response = storeTestAnnotationByType(true, requestBody, WebAnnotationFields.TAG, null); + assertEquals(response.getStatusCode().value(), HttpStatus.BAD_REQUEST.value()); + } + @Test void createTagWithoutBody() throws Exception { diff --git a/annotation-tests/src/integration-test/resources/semantictag/wrong/web_resource_missing_scope.json b/annotation-tests/src/integration-test/resources/semantictag/wrong/web_resource_missing_scope.json new file mode 100644 index 000000000..d78df1ec6 --- /dev/null +++ b/annotation-tests/src/integration-test/resources/semantictag/wrong/web_resource_missing_scope.json @@ -0,0 +1,8 @@ +{ + "type": "Annotation", + "motivation": "tagging", + "body": "http://sws.geonames.org/2988507/", + "target": { + "source": "http://comhaltasarchive.ie/tracks/12535" + } +} \ No newline at end of file diff --git a/annotation-web/src/main/java/eu/europeana/annotation/web/validation/BaseAnnotationValidator.java b/annotation-web/src/main/java/eu/europeana/annotation/web/validation/BaseAnnotationValidator.java index e66bb2344..66cac82ae 100644 --- a/annotation-web/src/main/java/eu/europeana/annotation/web/validation/BaseAnnotationValidator.java +++ b/annotation-web/src/main/java/eu/europeana/annotation/web/validation/BaseAnnotationValidator.java @@ -601,6 +601,8 @@ protected void validateTag(Annotation webAnnotation) } else { validateTagWithValue(body); } + + validateTargetFields(webAnnotation.getTarget()); } protected void validateLinking(Annotation webAnnotation) @@ -800,7 +802,7 @@ private void validateTargetFields(List targets) throws PropertyValidatio } private void validateTargetSpecificResource(Target target) throws PropertyValidationException { - // source must both be present in the target, and beside it (scope or selector) as well + // source must be present in the target, and beside it (scope or selector) as well if (target.getSource() == null) { throw new PropertyValidationException(I18nConstantsAnnotation.MESSAGE_MISSING_MANDATORY_FIELD, I18nConstantsAnnotation.MESSAGE_MISSING_MANDATORY_FIELD,