From 12faddfc4765591bb8a461dda1400bbbef62c96a Mon Sep 17 00:00:00 2001 From: Arnei Date: Thu, 14 Mar 2024 10:39:07 +0100 Subject: [PATCH 1/2] Make tool work with Solr removal Over in Opencast, there is a pull request that makes changes to the Opencast Search Service, breaking the Annotation Tool: https://github.com/opencast/opencast/pull/5597 Since that pull request 5597 is all but assured to go into Opencast 16, this commit attempts to fix the errors that 5597 would introduce. --- frontend/js/integrations/search.js | 2 +- .../ExtendedAnnotationServiceJpaImpl.java | 17 +++++++--------- .../annotation/endpoint/TestRestService.java | 20 ++++++------------- pom.xml | 4 ++-- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/frontend/js/integrations/search.js b/frontend/js/integrations/search.js index fe64d75a0..8f84ed52e 100644 --- a/frontend/js/integrations/search.js +++ b/frontend/js/integrations/search.js @@ -87,7 +87,7 @@ define([ data: "id=" + mediaPackageId + "&limit=1", dataType: "json" }).then(function (data) { - return data["search-results"].result; + return data.result[0]; }); var mediaPackage = searchResult.then(function (result) { return result.mediapackage; diff --git a/opencast-backend/annotation-impl/src/main/java/org/opencast/annotation/impl/persistence/ExtendedAnnotationServiceJpaImpl.java b/opencast-backend/annotation-impl/src/main/java/org/opencast/annotation/impl/persistence/ExtendedAnnotationServiceJpaImpl.java index cf45a6060..de58ea219 100644 --- a/opencast-backend/annotation-impl/src/main/java/org/opencast/annotation/impl/persistence/ExtendedAnnotationServiceJpaImpl.java +++ b/opencast-backend/annotation-impl/src/main/java/org/opencast/annotation/impl/persistence/ExtendedAnnotationServiceJpaImpl.java @@ -60,12 +60,12 @@ import org.opencastproject.db.DBSession; import org.opencastproject.db.DBSessionFactory; import org.opencastproject.mediapackage.MediaPackage; -import org.opencastproject.search.api.SearchQuery; -import org.opencastproject.search.api.SearchResultItem; import org.opencastproject.search.api.SearchService; import org.opencastproject.security.api.AuthorizationService; import org.opencastproject.security.api.SecurityConstants; import org.opencastproject.security.api.SecurityService; +import org.opencastproject.security.api.UnauthorizedException; +import org.opencastproject.util.NotFoundException; import org.opencastproject.util.data.Effect; import org.opencastproject.util.data.Function; import org.opencastproject.util.data.Function0; @@ -1271,14 +1271,11 @@ public Boolean none() { @Override public Option findMediaPackage(String id) { - return head(searchService.getByQuery(new SearchQuery().withId(id)).getItems()).map( - new Function<>() { - @Override - public MediaPackage apply(SearchResultItem searchResultItem) { - return searchResultItem.getMediaPackage(); - } - } - ); + try { + return Option.some(searchService.get(id)); + } catch (NotFoundException | UnauthorizedException e) { + return Option.none(); + } } @Override diff --git a/opencast-backend/annotation-impl/src/test/java/org/opencast/annotation/endpoint/TestRestService.java b/opencast-backend/annotation-impl/src/test/java/org/opencast/annotation/endpoint/TestRestService.java index 6538a5668..12d92735b 100644 --- a/opencast-backend/annotation-impl/src/test/java/org/opencast/annotation/endpoint/TestRestService.java +++ b/opencast-backend/annotation-impl/src/test/java/org/opencast/annotation/endpoint/TestRestService.java @@ -22,9 +22,6 @@ import org.opencast.annotation.impl.persistence.ExtendedAnnotationServiceJpaImpl; import org.opencastproject.mediapackage.MediaPackage; -import org.opencastproject.search.api.SearchQuery; -import org.opencastproject.search.api.SearchResult; -import org.opencastproject.search.api.SearchResultItem; import org.opencastproject.search.api.SearchService; import org.opencastproject.security.api.AuthorizationService; import org.opencastproject.security.api.DefaultOrganization; @@ -47,7 +44,7 @@ public class TestRestService extends AbstractExtendedAnnotationsRestService { // Haven't found out who's responsible forf this but that's the way it is. public static final ExtendedAnnotationServiceJpaImpl extendedAnnotationService = new ExtendedAnnotationServiceJpaImpl(); - static { + static { extendedAnnotationService.setSearchService(getSearchService()); extendedAnnotationService.setSecurityService(getSecurityService()); extendedAnnotationService.setAuthorizationService(getAuthorizationService()); @@ -90,17 +87,12 @@ private static AuthorizationService getAuthorizationService() { private static SearchService getSearchService() { MediaPackage mediaPackage = EasyMock.createNiceMock(MediaPackage.class); - SearchResultItem searchResultItem = EasyMock.createNiceMock(SearchResultItem.class); - EasyMock.expect(searchResultItem.getMediaPackage()).andReturn(mediaPackage).anyTimes(); - EasyMock.replay(searchResultItem); - - SearchResult searchResult = EasyMock.createNiceMock(SearchResult.class); - EasyMock.expect(searchResult.getItems()).andReturn(new SearchResultItem[]{searchResultItem}).anyTimes(); - EasyMock.replay(searchResult); - SearchService searchService = EasyMock.createNiceMock(SearchService.class); - EasyMock.expect(searchService.getByQuery(EasyMock.anyObject(SearchQuery.class))) - .andReturn(searchResult).anyTimes(); + try { + EasyMock.expect(searchService.get(EasyMock.anyObject(String.class))).andReturn(mediaPackage).anyTimes(); + } catch (Exception e) { + // Do nothing. We just have to pretend to handle checked exceptions somehow to appease the compiler. + } EasyMock.replay(searchService); return searchService; } diff --git a/pom.xml b/pom.xml index c996da4dc..381f23e8c 100644 --- a/pom.xml +++ b/pom.xml @@ -67,8 +67,8 @@ UTF-8 - 14.0 - ;version="${opencast.build.version}" + 16-SNAPSHOT + ;version=16.0 From c8567d49a54cf58ebee6c71cc8a7371c440bda3a Mon Sep 17 00:00:00 2001 From: Julian Kniephoff Date: Mon, 17 Jun 2024 15:10:44 +0200 Subject: [PATCH 2/2] Address review comments --- .../org/opencast/annotation/endpoint/TestRestService.java | 6 ++++-- pom.xml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/opencast-backend/annotation-impl/src/test/java/org/opencast/annotation/endpoint/TestRestService.java b/opencast-backend/annotation-impl/src/test/java/org/opencast/annotation/endpoint/TestRestService.java index 12d92735b..9139ea847 100644 --- a/opencast-backend/annotation-impl/src/test/java/org/opencast/annotation/endpoint/TestRestService.java +++ b/opencast-backend/annotation-impl/src/test/java/org/opencast/annotation/endpoint/TestRestService.java @@ -26,8 +26,10 @@ import org.opencastproject.security.api.AuthorizationService; import org.opencastproject.security.api.DefaultOrganization; import org.opencastproject.security.api.SecurityService; +import org.opencastproject.security.api.UnauthorizedException; import org.opencastproject.security.api.User; import org.opencastproject.security.util.SecurityUtil; +import org.opencastproject.util.NotFoundException; import org.easymock.EasyMock; import org.junit.Ignore; @@ -44,7 +46,7 @@ public class TestRestService extends AbstractExtendedAnnotationsRestService { // Haven't found out who's responsible forf this but that's the way it is. public static final ExtendedAnnotationServiceJpaImpl extendedAnnotationService = new ExtendedAnnotationServiceJpaImpl(); - static { + static { extendedAnnotationService.setSearchService(getSearchService()); extendedAnnotationService.setSecurityService(getSecurityService()); extendedAnnotationService.setAuthorizationService(getAuthorizationService()); @@ -90,7 +92,7 @@ private static SearchService getSearchService() { SearchService searchService = EasyMock.createNiceMock(SearchService.class); try { EasyMock.expect(searchService.get(EasyMock.anyObject(String.class))).andReturn(mediaPackage).anyTimes(); - } catch (Exception e) { + } catch (UnauthorizedException | NotFoundException e) { // Do nothing. We just have to pretend to handle checked exceptions somehow to appease the compiler. } EasyMock.replay(searchService); diff --git a/pom.xml b/pom.xml index 381f23e8c..c7118be66 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ UTF-8 - 16-SNAPSHOT + 16.0 ;version=16.0