diff --git a/modules/adopter-registration-impl/pom.xml b/modules/adopter-registration-impl/pom.xml index bd2c1e7bcb7..1eff4fd4335 100644 --- a/modules/adopter-registration-impl/pom.xml +++ b/modules/adopter-registration-impl/pom.xml @@ -86,6 +86,16 @@ org.osgi org.osgi.service.component.annotations + + org.elasticsearch + elasticsearch + ${elasticsearch.version} + + + org.opencastproject + opencast-dublincore + ${project.version} + diff --git a/modules/adopter-registration-impl/src/main/java/org/opencastproject/adopter/statistic/ScheduledDataCollector.java b/modules/adopter-registration-impl/src/main/java/org/opencastproject/adopter/statistic/ScheduledDataCollector.java index e10b78f2317..af62fc201fa 100644 --- a/modules/adopter-registration-impl/src/main/java/org/opencastproject/adopter/statistic/ScheduledDataCollector.java +++ b/modules/adopter-registration-impl/src/main/java/org/opencastproject/adopter/statistic/ScheduledDataCollector.java @@ -28,17 +28,15 @@ import org.opencastproject.adopter.statistic.dto.StatisticData; import org.opencastproject.assetmanager.api.AssetManager; import org.opencastproject.capture.admin.api.CaptureAgentStateService; -import org.opencastproject.mediapackage.MediaPackage; -import org.opencastproject.mediapackage.MediaPackageElementFlavor; -import org.opencastproject.search.api.SearchQuery; +import org.opencastproject.metadata.dublincore.DublinCore; +import org.opencastproject.metadata.dublincore.EncodingSchemeUtils; import org.opencastproject.search.api.SearchResult; -import org.opencastproject.search.api.SearchResultItem; +import org.opencastproject.search.api.SearchResultList; import org.opencastproject.search.api.SearchService; import org.opencastproject.security.api.DefaultOrganization; import org.opencastproject.security.api.Organization; import org.opencastproject.security.api.OrganizationDirectoryService; import org.opencastproject.security.api.SecurityService; -import org.opencastproject.security.api.UnauthorizedException; import org.opencastproject.security.api.User; import org.opencastproject.security.api.UserProvider; import org.opencastproject.security.util.SecurityUtil; @@ -48,6 +46,8 @@ import org.opencastproject.userdirectory.JpaUserAndRoleProvider; import org.opencastproject.userdirectory.JpaUserReferenceProvider; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.builder.SearchSourceBuilder; import org.osgi.framework.BundleContext; import org.osgi.framework.Version; import org.osgi.service.component.annotations.Activate; @@ -58,7 +58,6 @@ import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Timer; @@ -292,14 +291,6 @@ private String collectStatisticData(String adopterKey, String statisticKey) thro statisticData.setJobCount(serviceRegistry.count(null, null)); statisticData.setSeriesCount(seriesService.getSeriesCount()); - SearchQuery sq = new SearchQuery(); - sq.withId(""); - sq.withElementTags(new String[0]); - sq.withElementFlavors(new MediaPackageElementFlavor[0]); - sq.signURLs(false); - sq.includeEpisodes(true); - sq.includeSeries(false); - sq.withLimit(SEARCH_ITERATION_SIZE); List orgs = organizationDirectoryService.getOrganizations(); statisticData.setTenantCount(orgs.size()); @@ -313,28 +304,18 @@ private String collectStatisticData(String adopterKey, String statisticKey) thro int orgCAs = caStateService.getKnownAgents().size(); statisticData.setCACount(current + orgCAs); - //Calculate the total number of minutes for this org, add it to the total - current = statisticData.getTotalMinutes(); - long orgDuration = 0L; - long total = 0; - int offset = 0; - try { - do { - sq.withOffset(offset); - SearchResult sr = searchService.getForAdministrativeRead(sq); - offset += SEARCH_ITERATION_SIZE; - total = sr.getTotalSize(); - orgDuration = Arrays.stream(sr.getItems()) - .map(SearchResultItem::getMediaPackage) - .map(MediaPackage::getDuration) - .mapToLong(Long::valueOf) - .sum() / 1000L; - } while (offset + SEARCH_ITERATION_SIZE <= total); - } catch (UnauthorizedException e) { - //This should never happen, but... - logger.warn("Unable to calculate total minutes, unauthorized"); - } - statisticData.setTotalMinutes(current + orgDuration); + final SearchSourceBuilder q = new SearchSourceBuilder().query( + QueryBuilders.boolQuery() + .must(QueryBuilders.termQuery(SearchResult.TYPE, SearchService.IndexEntryType.Episode)) + .must(QueryBuilders.termQuery(SearchResult.ORG, org.getId())) + .must(QueryBuilders.termQuery(SearchResult.DELETED_DATE, "null"))); + final SearchResultList results = searchService.search(q); + long orgMilis = results.getHits().stream().map( + result -> EncodingSchemeUtils.decodeDuration( + result.getDublinCore().getFirst(DublinCore.PROPERTY_EXTENT))) + .filter(Objects::nonNull) + .reduce(Long::sum).orElse(0L); + statisticData.setTotalMinutes(statisticData.getTotalMinutes() + (orgMilis / 1000 / 60)); //Add the users for each org long currentUsers = statisticData.getUserCount(); diff --git a/modules/conductor/pom.xml b/modules/conductor/pom.xml index 377973908b2..bb9756098d0 100644 --- a/modules/conductor/pom.xml +++ b/modules/conductor/pom.xml @@ -89,6 +89,10 @@ commons-io commons-io + + org.apache.commons + commons-lang3 + org.slf4j slf4j-api diff --git a/modules/conductor/src/main/java/org/opencastproject/event/handler/SearchUpdatedEventHandler.java b/modules/conductor/src/main/java/org/opencastproject/event/handler/SearchUpdatedEventHandler.java index d5f1e2c4727..a7908170d2b 100644 --- a/modules/conductor/src/main/java/org/opencastproject/event/handler/SearchUpdatedEventHandler.java +++ b/modules/conductor/src/main/java/org/opencastproject/event/handler/SearchUpdatedEventHandler.java @@ -43,9 +43,6 @@ import org.opencastproject.metadata.dublincore.DublinCoreCatalogService; import org.opencastproject.metadata.dublincore.DublinCoreUtil; import org.opencastproject.search.api.SearchException; -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.AclScope; import org.opencastproject.security.api.AuthorizationService; @@ -209,18 +206,15 @@ public void handleEvent(final SeriesItem seriesItem) { try { securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg)); - SearchQuery q = new SearchQuery().withSeriesId(seriesId).withLimit(-1); - SearchResult result = searchService.getForAdministrativeRead(q); - - for (SearchResultItem item : result.getItems()) { - MediaPackage mp = item.getMediaPackage(); - Organization org = organizationDirectoryService.getOrganization(item.getOrganization()); + for (var seriesData: searchService.getSeries(seriesId)) { + var mp = seriesData.getRight(); + Organization org = seriesData.getLeft(); securityService.setOrganization(org); // If the security policy has been updated, make sure to distribute that change // to the distribution channels as well if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) { - if (seriesItem.getOverrideEpisodeAcl()) { + if (Boolean.TRUE.equals(seriesItem.getOverrideEpisodeAcl())) { MediaPackageElement[] distributedEpisodeAcls = mp.getElementsByFlavor(XACML_POLICY_EPISODE); authorizationService.removeAcl(mp, AclScope.Episode); diff --git a/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/PartialRetractEngageWorkflowOperationHandler.java b/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/PartialRetractEngageWorkflowOperationHandler.java index 208ba25c61a..ab190366b15 100644 --- a/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/PartialRetractEngageWorkflowOperationHandler.java +++ b/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/PartialRetractEngageWorkflowOperationHandler.java @@ -35,10 +35,10 @@ import org.opencastproject.mediapackage.Publication; import org.opencastproject.mediapackage.selector.SimpleElementSelector; import org.opencastproject.search.api.SearchException; -import org.opencastproject.search.api.SearchQuery; -import org.opencastproject.search.api.SearchResult; import org.opencastproject.search.api.SearchService; +import org.opencastproject.security.api.UnauthorizedException; import org.opencastproject.serviceregistry.api.ServiceRegistry; +import org.opencastproject.util.NotFoundException; import org.opencastproject.workflow.api.WorkflowInstance; import org.opencastproject.workflow.api.WorkflowOperationException; import org.opencastproject.workflow.api.WorkflowOperationHandler; @@ -53,10 +53,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Collection; -import java.util.HashSet; import java.util.List; -import java.util.Set; +import java.util.stream.Collectors; /** * Workflow operation for retracting parts of a media package from the engage player. @@ -118,45 +116,36 @@ public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobConte logger.info("Partially retracting {}", mediaPackage.getIdentifier()); List jobs; try { - SearchQuery query = new SearchQuery().withId(mediaPackage.getIdentifier().toString()); - query.includeEpisodes(true); - query.includeSeries(false); - SearchResult result = searchService.getByQuery(query); - if (result.size() == 0) { - logger.info("The search service doesn't know mediapackage {}", mediaPackage); + try { + searchMP = searchService.get(mediaPackage.getIdentifier().toString()); + } catch (NotFoundException e) { + logger.info("The search service doesn't know media package {}", mediaPackage); return createResult(mediaPackage, WorkflowOperationResult.Action.SKIP); - } else if (result.size() > 1) { - logger.warn("More than one mediapackage with id {} returned from search service", mediaPackage.getIdentifier()); - throw new WorkflowOperationException( - "More than one mediapackage with id " + mediaPackage.getIdentifier() + " found"); - } else { - searchMP = result.getItems()[0].getMediaPackage(); - Set retractElementIds = new HashSet<>(); - Collection retractElements = retractElementSelector.select(searchMP, false); - Publication publicationElement = findPublicationElement(mediaPackage); - - //Pull down the elements themselves - logger.debug("Found {} matching elements", retractElements.size()); - for (MediaPackageElement element : retractElements) { - retractElementIds.add(element.getIdentifier()); - logger.debug("Retracting {}", element.getIdentifier()); - } - jobs = retractElements(retractElementIds, searchMP); - if (jobs.size() < 1) { - logger.debug("No matching elements found"); - return createResult(mediaPackage, WorkflowOperationResult.Action.CONTINUE); - } + } catch (UnauthorizedException e) { + throw new WorkflowOperationException("Not allowed to access media package " + mediaPackage); + } + var retractElements = retractElementSelector.select(searchMP, false); + var retractElementIds = retractElements.stream() + .map(MediaPackageElement::getIdentifier) + .collect(Collectors.toSet()); + logger.debug("Found {} matching elements", retractElementIds.size()); + + // Pull down the elements themselves + jobs = retractElements(retractElementIds, searchMP); + if (jobs.size() < 1) { + logger.debug("No matching elements found"); + return createResult(mediaPackage, WorkflowOperationResult.Action.CONTINUE); + } - for (MediaPackageElement element : retractElements) { - logger.debug("Removing {} from mediapackage", element.getIdentifier()); - //Remove the element from the workflow mp - mediaPackage.remove(element); - searchMP.remove(element); - } + for (MediaPackageElement element : retractElements) { + logger.debug("Removing {} from mediapackage", element.getIdentifier()); + //Remove the element from the workflow mp + mediaPackage.remove(element); + searchMP.remove(element); } // Wait for retraction to finish - if (!waitForStatus(jobs.toArray(new Job[jobs.size()])).isSuccess()) { + if (!waitForStatus(jobs.toArray(new Job[0])).isSuccess()) { throw new WorkflowOperationException("The retract jobs did not complete successfully"); } Job deleteSearchJob = null; diff --git a/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/PublishEngageWorkflowOperationHandler.java b/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/PublishEngageWorkflowOperationHandler.java index bd0e692ba3d..9351b7e0a39 100644 --- a/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/PublishEngageWorkflowOperationHandler.java +++ b/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/PublishEngageWorkflowOperationHandler.java @@ -52,8 +52,6 @@ import org.opencastproject.metadata.dublincore.DublinCoreValue; import org.opencastproject.metadata.dublincore.DublinCoreXmlFormat; import org.opencastproject.search.api.SearchException; -import org.opencastproject.search.api.SearchQuery; -import org.opencastproject.search.api.SearchResult; import org.opencastproject.search.api.SearchService; import org.opencastproject.security.api.Organization; import org.opencastproject.security.api.OrganizationDirectoryService; @@ -265,7 +263,14 @@ public WorkflowOperationResult start(final WorkflowInstance workflowInstance, Jo // First check if mp exists in the search index and strategy is merge // to avoid leaving distributed elements around. - MediaPackage distributedMp = getDistributedMediapackage(mediaPackage.getIdentifier().toString()); + MediaPackage distributedMp = null; + try { + distributedMp = searchService.get(mediaPackage.getIdentifier().toString()); + } catch (NotFoundException e) { + logger.debug("No published mediapackage found for {}", mediaPackage.getIdentifier().toString()); + } catch (UnauthorizedException e) { + throw new WorkflowOperationException("Unauthorized for " + mediaPackage.getIdentifier().toString(), e); + } if (PUBLISH_STRATEGY_MERGE.equals(republishStrategy) && distributedMp == null) { logger.info("Skipping republish for {} since it is not currently published", mediaPackage.getIdentifier().toString()); @@ -691,23 +696,13 @@ private void applyTags(MediaPackageElement element, String[] tags) { } } - protected MediaPackage getDistributedMediapackage(String mediaPackageID) throws WorkflowOperationException { - MediaPackage mediaPackage = null; - SearchQuery query = new SearchQuery().withId(mediaPackageID); - query.includeEpisodes(true); - query.includeSeries(false); - SearchResult result = searchService.getByQuery(query); - if (result.size() == 0) { - logger.info("The search service doesn't know mediapackage {}.", mediaPackageID); - return mediaPackage; // i.e. null - } else if (result.size() > 1) { - logger.warn("More than one mediapackage with id {} returned from search service", mediaPackageID); - throw new WorkflowOperationException("More than one mediapackage with id " + mediaPackageID + " found"); - } else { - // else, merge the new with the existing (new elements will overwrite existing elements) - mediaPackage = result.getItems()[0].getMediaPackage(); + protected MediaPackage getDistributedMediaPackage(String mediaPackageID) throws UnauthorizedException { + try { + return searchService.get(mediaPackageID); + } catch (NotFoundException e) { + logger.info("The search service doesn't know media package {}.", mediaPackageID); + return null; } - return mediaPackage; } @@ -778,8 +773,8 @@ private void removePublicationElement(MediaPackage mediaPackage) { * @throws WorkflowOperationException */ private void retractFromEngage(MediaPackage distributedMediaPackage) throws WorkflowOperationException { - List jobs = new ArrayList(); - Set elementIds = new HashSet(); + List jobs = new ArrayList<>(); + Set elementIds = new HashSet<>(); try { if (distributedMediaPackage != null) { diff --git a/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/RetractEngageWorkflowOperationHandler.java b/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/RetractEngageWorkflowOperationHandler.java index 4a0f01f09f8..9c4365099ba 100644 --- a/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/RetractEngageWorkflowOperationHandler.java +++ b/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/RetractEngageWorkflowOperationHandler.java @@ -31,10 +31,9 @@ import org.opencastproject.mediapackage.MediaPackage; import org.opencastproject.mediapackage.MediaPackageElement; import org.opencastproject.mediapackage.Publication; -import org.opencastproject.search.api.SearchQuery; -import org.opencastproject.search.api.SearchResult; import org.opencastproject.search.api.SearchService; import org.opencastproject.serviceregistry.api.ServiceRegistry; +import org.opencastproject.util.NotFoundException; import org.opencastproject.workflow.api.AbstractWorkflowOperationHandler; import org.opencastproject.workflow.api.WorkflowInstance; import org.opencastproject.workflow.api.WorkflowOperationException; @@ -50,9 +49,10 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.HashSet; +import java.util.Arrays; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; /** * Workflow operation for retracting a media package from the engage player. @@ -166,27 +166,21 @@ public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobConte MediaPackage mediaPackage = workflowInstance.getMediaPackage(); List jobs; try { - SearchQuery query = new SearchQuery().withId(mediaPackage.getIdentifier().toString()); - SearchResult result = searchService.getByQuery(query); - if (result.size() == 0) { - logger.info("The search service doesn't know mediapackage {}", mediaPackage); + MediaPackage searchMediaPackage = null; + try { + searchMediaPackage = searchService.get(mediaPackage.getIdentifier().toString()); + } catch (NotFoundException e) { + logger.info("The search service doesn't know media package {}", mediaPackage); return createResult(mediaPackage, Action.SKIP); - } else if (result.size() > 1) { - logger.warn("More than one mediapackage with id {} returned from search service", mediaPackage.getIdentifier()); - throw new WorkflowOperationException("More than one mediapackage with id " + mediaPackage.getIdentifier() - + " found"); - } else { - Set retractElementIds = new HashSet(); - MediaPackage searchMediaPackage = result.getItems()[0].getMediaPackage(); - logger.info("Retracting media package {} from download/streaming distribution channel", searchMediaPackage); - for (MediaPackageElement element : searchMediaPackage.getElements()) { - retractElementIds.add(element.getIdentifier()); - } - jobs = retractElements(retractElementIds, searchMediaPackage); } + logger.info("Retracting media package {} from download/streaming distribution channel", searchMediaPackage); + var retractElementIds = Arrays.stream(searchMediaPackage.getElements()) + .map(MediaPackageElement::getIdentifier) + .collect(Collectors.toSet()); + jobs = retractElements(retractElementIds, searchMediaPackage); // Wait for retraction to finish - if (!waitForStatus(jobs.toArray(new Job[jobs.size()])).isSuccess()) { + if (!waitForStatus(jobs.toArray(new Job[0])).isSuccess()) { throw new WorkflowOperationException("One of the download/streaming retract job did not complete successfully"); } diff --git a/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/TagEngageWorkflowOperationHandler.java b/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/TagEngageWorkflowOperationHandler.java index 39c353e7f7f..8df80b3845d 100644 --- a/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/TagEngageWorkflowOperationHandler.java +++ b/modules/distribution-workflowoperation/src/main/java/org/opencastproject/workflow/handler/distribution/TagEngageWorkflowOperationHandler.java @@ -32,12 +32,11 @@ import org.opencastproject.mediapackage.Publication; import org.opencastproject.mediapackage.selector.SimpleElementSelector; import org.opencastproject.search.api.SearchException; -import org.opencastproject.search.api.SearchQuery; -import org.opencastproject.search.api.SearchResult; import org.opencastproject.search.api.SearchService; import org.opencastproject.security.api.UnauthorizedException; import org.opencastproject.serviceregistry.api.ServiceRegistry; import org.opencastproject.serviceregistry.api.ServiceRegistryException; +import org.opencastproject.util.NotFoundException; import org.opencastproject.workflow.api.AbstractWorkflowOperationHandler; import org.opencastproject.workflow.api.ConfiguredTagsAndFlavors; import org.opencastproject.workflow.api.WorkflowInstance; @@ -131,15 +130,12 @@ public WorkflowOperationResult start(WorkflowInstance instance, JobContext conte } // get published mp - SearchResult result = searchService.getByQuery(new SearchQuery().withId(mediaPackageId)); - if (result.size() == 0) { - throw new WorkflowOperationException( - "Media package " + mediaPackageId + " can't be updated in Search because it " + "isn't published."); - } else if (result.size() > 1) { - throw new WorkflowOperationException("Media package " + mediaPackageId + " can't be updated in Search because " - + "more than one media package with that id was found."); + MediaPackage mediaPackageForSearch = null; + try { + mediaPackageForSearch = searchService.get(mediaPackageId); + } catch (NotFoundException | UnauthorizedException e) { + throw new WorkflowOperationException(e); } - MediaPackage mediaPackageForSearch = result.getItems()[0].getMediaPackage(); // update tags & flavors in published mp Collection searchElements = mpeSelector.select(mediaPackageForSearch, false); diff --git a/modules/distribution-workflowoperation/src/test/java/org/opencastproject/workflow/handler/distribution/PublishEngageWorkflowOperationHandlerTest.java b/modules/distribution-workflowoperation/src/test/java/org/opencastproject/workflow/handler/distribution/PublishEngageWorkflowOperationHandlerTest.java index 2d433ea0fa5..4b691c50c80 100644 --- a/modules/distribution-workflowoperation/src/test/java/org/opencastproject/workflow/handler/distribution/PublishEngageWorkflowOperationHandlerTest.java +++ b/modules/distribution-workflowoperation/src/test/java/org/opencastproject/workflow/handler/distribution/PublishEngageWorkflowOperationHandlerTest.java @@ -36,15 +36,13 @@ import org.opencastproject.mediapackage.Track; import org.opencastproject.mediapackage.identifier.Id; import org.opencastproject.mediapackage.identifier.IdImpl; -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.DefaultOrganization; import org.opencastproject.security.api.JaxbOrganization; import org.opencastproject.security.api.Organization; import org.opencastproject.security.api.OrganizationDirectoryService; import org.opencastproject.serviceregistry.api.ServiceRegistry; +import org.opencastproject.util.NotFoundException; import org.opencastproject.workflow.api.WorkflowInstance; import org.opencastproject.workflow.api.WorkflowInstance.WorkflowState; import org.opencastproject.workflow.api.WorkflowOperationException; @@ -204,10 +202,8 @@ public Organization getOrgWithoutPlayerPath() { @Test public void testPublish() throws Exception { - SearchResult searchResult = EasyMock.createNiceMock(SearchResult.class); - EasyMock.expect(searchResult.size()).andReturn(0L).anyTimes(); - EasyMock.expect(searchService.getByQuery(EasyMock.anyObject(SearchQuery.class))).andReturn(searchResult).anyTimes(); - EasyMock.replay(searchService, searchResult); + EasyMock.expect(searchService.get(EasyMock.anyString())).andThrow(new NotFoundException("Not found")); + EasyMock.replay(searchService); EasyMock.expect(distributionService.distribute(EasyMock.anyObject(String.class), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(Set.class), EasyMock.anyBoolean())) @@ -251,15 +247,8 @@ public void testPublishMerge() throws Exception { .andReturn(distMergeJob); EasyMock.replay(distributionService); - SearchResultItem item = EasyMock.createNiceMock(SearchResultItem.class); - EasyMock.expect(item.getMediaPackage()).andReturn(mp).anyTimes(); - SearchResultItem[] items = new SearchResultItem[1]; - items[0] = item; - SearchResult searchResult = EasyMock.createNiceMock(SearchResult.class); - EasyMock.expect(searchResult.size()).andReturn(1L).anyTimes(); - EasyMock.expect(searchResult.getItems()).andReturn(items).anyTimes(); - EasyMock.expect(searchService.getByQuery(EasyMock.anyObject(SearchQuery.class))).andReturn(searchResult).anyTimes(); - EasyMock.replay(searchService, searchResult, item); + EasyMock.expect(searchService.get(EasyMock.anyString())).andReturn(mp).anyTimes(); + EasyMock.replay(searchService); operation.setConfiguration(PublishEngageWorkflowOperationHandler.DOWNLOAD_SOURCE_TAGS, "engage"); operation.setConfiguration(PublishEngageWorkflowOperationHandler.STRATEGY, @@ -309,15 +298,8 @@ public void testPublishMergeForceFlavors() throws Exception { .andReturn(distMergeJob); EasyMock.replay(distributionService); - SearchResultItem item = EasyMock.createNiceMock(SearchResultItem.class); - EasyMock.expect(item.getMediaPackage()).andReturn(mp).anyTimes(); - SearchResultItem[] items = new SearchResultItem[1]; - items[0] = item; - SearchResult searchResult = EasyMock.createNiceMock(SearchResult.class); - EasyMock.expect(searchResult.size()).andReturn(1L).anyTimes(); - EasyMock.expect(searchResult.getItems()).andReturn(items).anyTimes(); - EasyMock.expect(searchService.getByQuery(EasyMock.anyObject(SearchQuery.class))).andReturn(searchResult).anyTimes(); - EasyMock.replay(searchService, searchResult, item); + EasyMock.expect(searchService.get(EasyMock.anyString())).andReturn(mp).anyTimes(); + EasyMock.replay(searchService); operation.setConfiguration(PublishEngageWorkflowOperationHandler.DOWNLOAD_SOURCE_TAGS, "engage"); operation.setConfiguration(PublishEngageWorkflowOperationHandler.STRATEGY, @@ -359,11 +341,9 @@ public void testPublishMergeForceFlavors() throws Exception { } @Test - public void testPublishMergeSkip() throws WorkflowOperationException { - SearchResult searchResult = EasyMock.createNiceMock(SearchResult.class); - EasyMock.expect(searchResult.size()).andReturn(0L).anyTimes(); - EasyMock.expect(searchService.getByQuery(EasyMock.anyObject(SearchQuery.class))).andReturn(searchResult).anyTimes(); - EasyMock.replay(searchService, searchResult); + public void testPublishMergeSkip() throws Exception { + EasyMock.expect(searchService.get(EasyMock.anyString())).andThrow(new NotFoundException("Not found")).anyTimes(); + EasyMock.replay(searchService); operation.setConfiguration(PublishEngageWorkflowOperationHandler.DOWNLOAD_SOURCE_TAGS, "engage"); operation.setConfiguration(PublishEngageWorkflowOperationHandler.STRATEGY, diff --git a/modules/live-schedule-impl/src/main/java/org/opencastproject/liveschedule/impl/LiveScheduleServiceImpl.java b/modules/live-schedule-impl/src/main/java/org/opencastproject/liveschedule/impl/LiveScheduleServiceImpl.java index 64a46c05749..909a8e8a153 100644 --- a/modules/live-schedule-impl/src/main/java/org/opencastproject/liveschedule/impl/LiveScheduleServiceImpl.java +++ b/modules/live-schedule-impl/src/main/java/org/opencastproject/liveschedule/impl/LiveScheduleServiceImpl.java @@ -53,8 +53,6 @@ import org.opencastproject.metadata.dublincore.DublinCoreCatalog; import org.opencastproject.metadata.dublincore.DublinCoreCatalogService; import org.opencastproject.metadata.dublincore.EncodingSchemeUtils; -import org.opencastproject.search.api.SearchQuery; -import org.opencastproject.search.api.SearchResult; import org.opencastproject.search.api.SearchService; import org.opencastproject.security.api.AccessControlList; import org.opencastproject.security.api.AclScope; @@ -501,19 +499,12 @@ MediaPackage getMediaPackageFromSearch(String mediaPackageId) throws LiveSchedul securityService.setUser(SecurityUtil.createSystemUser(systemUserName, org)); try { // Look for the media package in the search index - SearchQuery query = new SearchQuery().withId(mediaPackageId); - SearchResult result = searchService.getForAdministrativeRead(query); - if (result.size() == 0) { - logger.debug("The search service doesn't know live mediapackage {}", mediaPackageId); - return null; - } else if (result.size() > 1) { - logger.warn("More than one live mediapackage with id {} returned from search service", mediaPackageId); - throw new LiveScheduleException("More than one live mediapackage with id " + mediaPackageId + " found"); - } - return result.getItems()[0].getMediaPackage(); + return searchService.get(mediaPackageId); } catch (UnauthorizedException e) { logger.warn("Unexpected unauthorized exception when querying the search index for mp {}", mediaPackageId, e); return null; + } catch (NotFoundException e) { + return null; } finally { securityService.setUser(prevUser); } diff --git a/modules/live-schedule-impl/src/test/java/org/opencastproject/liveschedule/impl/LiveScheduleServiceImplTest.java b/modules/live-schedule-impl/src/test/java/org/opencastproject/liveschedule/impl/LiveScheduleServiceImplTest.java index aacd709c4c6..8000cbcc5d4 100644 --- a/modules/live-schedule-impl/src/test/java/org/opencastproject/liveschedule/impl/LiveScheduleServiceImplTest.java +++ b/modules/live-schedule-impl/src/test/java/org/opencastproject/liveschedule/impl/LiveScheduleServiceImplTest.java @@ -50,8 +50,6 @@ import org.opencastproject.metadata.dublincore.DublinCoreCatalogService; import org.opencastproject.metadata.dublincore.DublinCoreValue; import org.opencastproject.metadata.dublincore.DublinCores; -import org.opencastproject.search.api.SearchResult; -import org.opencastproject.search.api.SearchResultImpl; import org.opencastproject.search.api.SearchService; import org.opencastproject.security.api.AccessControlEntry; import org.opencastproject.security.api.AccessControlList; @@ -70,6 +68,7 @@ import org.opencastproject.util.DateTimeSupport; import org.opencastproject.util.MimeType; import org.opencastproject.util.MimeTypes; +import org.opencastproject.util.NotFoundException; import org.opencastproject.util.data.Tuple; import org.opencastproject.workspace.api.Workspace; @@ -468,9 +467,9 @@ public void testGetSnapshot() throws Exception { @Test public void testGetMediaPackageFromSearch() throws Exception { - URI searchResultURI = LiveScheduleServiceImplTest.class.getResource("/search-result.xml").toURI(); - SearchResult searchResult = SearchResultImpl.valueOf(searchResultURI.toURL().openStream()); - EasyMock.expect(searchService.getForAdministrativeRead(EasyMock.anyObject())).andReturn(searchResult); + var id = new IdImpl(MP_ID); + var mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew(id); + EasyMock.expect(searchService.get(EasyMock.anyString())).andReturn(mediaPackage).anyTimes(); replayServices(); MediaPackage mp = service.getMediaPackageFromSearch(MP_ID); @@ -480,9 +479,7 @@ public void testGetMediaPackageFromSearch() throws Exception { @Test public void testGetMediaPackageFromSearchNotFound() throws Exception { - URI searchResultURI = LiveScheduleServiceImplTest.class.getResource("/search-result-empty.xml").toURI(); - SearchResult searchResult = SearchResultImpl.valueOf(searchResultURI.toURL().openStream()); - EasyMock.expect(searchService.getForAdministrativeRead(EasyMock.anyObject())).andReturn(searchResult); + EasyMock.expect(searchService.get(EasyMock.anyString())).andThrow(new NotFoundException("")).anyTimes(); replayServices(); MediaPackage mp = service.getMediaPackageFromSearch(MP_ID); @@ -738,9 +735,7 @@ public void testUpdateLiveEventNoChange() throws Exception { @Test public void testCreateOuUpdateLiveEventAlreadyPast() throws Exception { - URI searchResultURI = LiveScheduleServiceImplTest.class.getResource("/search-result-empty.xml").toURI(); - SearchResult searchResult = SearchResultImpl.valueOf(searchResultURI.toURL().openStream()); - EasyMock.expect(searchService.getForAdministrativeRead(EasyMock.anyObject())).andReturn(searchResult); + EasyMock.expect(searchService.get(EasyMock.anyString())).andThrow(new NotFoundException("")).anyTimes(); replayServices(); Assert.assertFalse(service.createOrUpdateLiveEvent(MP_ID, episodeDC)); @@ -749,9 +744,7 @@ public void testCreateOuUpdateLiveEventAlreadyPast() throws Exception { @Test public void testCreateOuUpdateLiveEventAlreadyPublished() throws Exception { - URI searchResultURI = LiveScheduleServiceImplTest.class.getResource("/no-live-search-result.xml").toURI(); - SearchResult searchResult = SearchResultImpl.valueOf(searchResultURI.toURL().openStream()); - EasyMock.expect(searchService.getForAdministrativeRead(EasyMock.anyObject())).andReturn(searchResult); + EasyMock.expect(searchService.get(EasyMock.anyString())).andThrow(new NotFoundException("")).anyTimes(); replayServices(); Assert.assertFalse(service.createOrUpdateLiveEvent(MP_ID, episodeDC)); diff --git a/modules/notification-workflowoperation/src/main/java/org/opencastproject/workflow/handler/notification/MediaPackagePostOperationHandler.java b/modules/notification-workflowoperation/src/main/java/org/opencastproject/workflow/handler/notification/MediaPackagePostOperationHandler.java index 63a46cd72e3..f44be4aa19f 100644 --- a/modules/notification-workflowoperation/src/main/java/org/opencastproject/workflow/handler/notification/MediaPackagePostOperationHandler.java +++ b/modules/notification-workflowoperation/src/main/java/org/opencastproject/workflow/handler/notification/MediaPackagePostOperationHandler.java @@ -24,10 +24,10 @@ import org.opencastproject.job.api.JobContext; import org.opencastproject.mediapackage.MediaPackage; import org.opencastproject.mediapackage.MediaPackageParser; -import org.opencastproject.search.api.SearchQuery; -import org.opencastproject.search.api.SearchResult; import org.opencastproject.search.api.SearchService; +import org.opencastproject.security.api.UnauthorizedException; import org.opencastproject.serviceregistry.api.ServiceRegistry; +import org.opencastproject.util.NotFoundException; import org.opencastproject.workflow.api.AbstractWorkflowOperationHandler; import org.opencastproject.workflow.api.WorkflowInstance; import org.opencastproject.workflow.api.WorkflowOperationException; @@ -101,15 +101,12 @@ public WorkflowOperationResult start(final WorkflowInstance workflowInstance, Jo // check if we need to replace the media package we got with the published // media package from the search service if (config.mpFromSearch()) { - SearchQuery searchQuery = new SearchQuery(); - searchQuery.withId(mp.getIdentifier().toString()); - SearchResult result = searchService.getByQuery(searchQuery); - if (result.size() != 1) { - throw new WorkflowOperationException("Received multiple results for identifier" - + "\"" + mp.getIdentifier().toString() + "\" from search service. "); - } logger.info("Getting media package from search service"); - mp = result.getItems()[0].getMediaPackage(); + try { + mp = searchService.get(mp.getIdentifier().toString()); + } catch (NotFoundException | UnauthorizedException e) { + throw new WorkflowOperationException("could not get media package " + mp + " from search service."); + } } logger.info("Submitting {} ({}) as {} to {}",