Skip to content

Commit

Permalink
small refactoring + integration tests for copyright #EA-371
Browse files Browse the repository at this point in the history
  • Loading branch information
gsergiu committed Mar 6, 2024
1 parent 7beb345 commit 513b160
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,8 @@ public Set<String> checkDuplicateAnnotations(Annotation anno, boolean noSelfDupp
List<SolrQuery> queries = new ArrayList<>();
switch (anno.getMotivationType()) {
case TRANSCRIBING :
queries.add(solrUniquenessQueryTranscriptions(anno, noSelfDupplicate));
break;
case TRANSLATING :
case TRANSLATING :
//the motivation is the passed as parameter, can use the same method for transcriptions and annotations
queries.add(solrUniquenessQueryTranscriptions(anno, noSelfDupplicate));
break;
case CAPTIONING :
Expand All @@ -527,9 +526,9 @@ else if(BodyInternalTypes.isSimpleTagBody(anno.getBody().getInternalType())) {
queries.add(solrUniquenessQuerySimpleTagging(anno, noSelfDupplicate));
}
break;
// case LINKING :
// query=solrUniquenessQueryLinking(anno, noSelfCheck);
// break;
case LINKING :
//skip for now because the multiple targets introduce issues on semantic level query=solrUniquenessQueryLinking(anno, noSelfCheck);
break;
case LINKFORCONTRIBUTING :
queries.add(solrUniquenessQueryLinkForContributing(anno, noSelfDupplicate));
break;
Expand Down Expand Up @@ -566,6 +565,12 @@ else if(BodyInternalTypes.isSimpleTagBody(anno.getBody().getInternalType())) {
return responseAnnoIds;
}

/**
* creates uniqueness soll query for transcriptions or translations
* @param anno
* @param noSelfDupplicate
* @return
*/
private SolrQuery solrUniquenessQueryTranscriptions(Annotation anno, boolean noSelfDupplicate) {
SolrQuery query = new SolrQuery();
query.setQuery(WebAnnotationModelFields.MOTIVATION + ":\"" + anno.getMotivationType().getOaType() + "\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public String get_TAG_STANDARD_TEST_VALUE_TARGET(String itemDataEndpoint) {
public static final String TRANSCRIPTION_MINIMAL = "/transcription/minimal.json";

public static final String TRANSLATION_MINIMAL = "/translation/minimal.json";
public static final String TRANSLATION_COPYRIGHT = "/translation/translation-coypright.json";


public static final String SUBTITLE_MINIMAL = "/subtitle/minimal.json";
public static final String SUBTITLE_WITH_COYRIGHT= "/subtitle/subtitle-copyright.json";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package eu.europeana.annotation.tests.web;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.stanbol.commons.exception.JsonParseException;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import eu.europeana.annotation.definitions.model.Annotation;
import eu.europeana.annotation.definitions.model.vocabulary.MotivationTypes;
import eu.europeana.annotation.definitions.model.vocabulary.ResourceTypes;
import eu.europeana.annotation.tests.AbstractIntegrationTest;
import eu.europeana.annotation.tests.utils.AnnotationTestUtils;

Expand Down Expand Up @@ -38,4 +43,34 @@ public void createMinimalTranslation() throws Exception {
// validate the reflection of input in output!
AnnotationTestUtils.validateOutputAgainstInput(storedAnno, inputAnno);
}

@Test
void createTranscriptionWithCopyright() throws Exception {

String requestBody = AnnotationTestUtils.getJsonStringInput(TRANSLATION_COPYRIGHT);
Annotation inputAnno = parseTranslation(requestBody);

Annotation storedAnno = createTestAnnotation(TRANSLATION_COPYRIGHT, true, USER_PROVIDER_SAZ);
assertNotNull(storedAnno);
addToCreatedAnnotations(storedAnno.getIdentifier());

// validate the reflection of input in output!
AnnotationTestUtils.validateOutputAgainstInput(storedAnno, inputAnno);

assertEquals(ResourceTypes.FULL_TEXT_RESOURCE.name(), storedAnno.getBody().getInternalType());
assertEquals(inputAnno.getBody().getEdmRights(), storedAnno.getBody().getEdmRights());

}

@Test
void createTranscriptionWithCopyrightNotOwner() throws Exception {

//creation should fail if the user is not the owner
ResponseEntity<String> response = storeTestAnnotation(TRANSLATION_COPYRIGHT, true, USER_REGULAR);

assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
//the error must indicate the invalid field
assertTrue(response.getBody().contains("body.edmRights"));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "FullTextResource",
"language": "de",
"format": "text/plain",
"value": "... complete transcribed text in HTML ...",
"value": "... complete translation as plain text ...",
"edmRights": "http://creativecommons.org/licenses/by-sa/1.0/"
},
"target": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"motivation": "translating",
"body": {
"type": "FullTextResource",
"language": "de",
"format": "text/plain",
"value": "... complete translation as plain text ...",
"edmRights": "http://mylicence.org/copywrited"
},
"target": {
"scope": "http://data.europeana.eu/item/saz-collections/item1",
"source": "https://ekultura.hr/purl/url/ADOD2JWHV3ZIITL7G23TPHGZLC7BYYT4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -469,15 +469,11 @@ public void validateWebAnnotation(Annotation webAnnotation, Authentication authe
validateTag(webAnnotation);
break;
case TRANSCRIBING:
validateTranscription(webAnnotation, authentication);
break;
case TRANSLATING:
validateTranscription(webAnnotation, authentication);
validateTranscriptionOrTranslation(webAnnotation, authentication);
break;
case SUBTITLING:
validateSubtitleOrCaption(webAnnotation, authentication);
break;
case CAPTIONING:
case CAPTIONING:
validateSubtitleOrCaption(webAnnotation, authentication);
break;
case LINKFORCONTRIBUTING:
Expand Down Expand Up @@ -631,7 +627,7 @@ protected void validateDescribing(Annotation webAnnotation)
* @throws RequestBodyValidationException
* @throws PropertyValidationException
*/
protected void validateTranscription(Annotation webAnnotation, Authentication authentication)
protected void validateTranscriptionOrTranslation(Annotation webAnnotation, Authentication authentication)
throws ParamValidationI18NException, RequestBodyValidationException,
PropertyValidationException {
validateBodyExists(webAnnotation.getBody());
Expand Down

0 comments on commit 513b160

Please sign in to comment.