Search in sources :

Example 16 with WorkflowQuery

use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.

the class WorkflowsListProvider method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
    Map<String, String> workflowsList = new HashMap<String, String>();
    WorkflowQuery q = new WorkflowQuery();
    if (query != null) {
        if (query.getLimit().isSome())
            q.withCount(query.getLimit().get());
        if (query.getOffset().isSome())
            q.withStartPage(query.getOffset().get());
    }
    WorkflowInstance[] workflowInstances;
    try {
        workflowInstances = workflowService.getWorkflowInstances(q).getItems();
    } catch (WorkflowDatabaseException e) {
        logger.error("Error by querying the workflow instances from the DB: ", e);
        throw new ListProviderException(e.getMessage(), e.getCause());
    }
    for (WorkflowInstance w : workflowInstances) {
        workflowsList.put(Long.toString(w.getId()), w.getTitle() + " - " + w.getMediaPackage().getTitle());
    }
    return workflowsList;
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) HashMap(java.util.HashMap) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance)

Example 17 with WorkflowQuery

use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.

the class WorkflowPermissionsUpdatedEventHandler method handleEvent.

public void handleEvent(final SeriesItem seriesItem) {
    // A series or its ACL has been updated. Find any mediapackages with that series, and update them.
    logger.debug("Handling {}", seriesItem);
    String seriesId = seriesItem.getSeriesId();
    // We must be an administrative user to make this query
    final User prevUser = securityService.getUser();
    final Organization prevOrg = securityService.getOrganization();
    try {
        securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
        // Note: getWorkflowInstances will only return a given number of results (default 20)
        WorkflowQuery q = new WorkflowQuery().withSeriesId(seriesId);
        WorkflowSet result = workflowService.getWorkflowInstancesForAdministrativeRead(q);
        Integer offset = 0;
        while (result.size() > 0) {
            for (WorkflowInstance instance : result.getItems()) {
                if (!instance.isActive())
                    continue;
                Organization org = instance.getOrganization();
                securityService.setOrganization(org);
                MediaPackage mp = instance.getMediaPackage();
                // Update the series XACML file
                if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
                    // Build a new XACML file for this mediapackage
                    authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl());
                }
                // Update the series dublin core
                if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType())) {
                    DublinCoreCatalog seriesDublinCore = seriesItem.getMetadata();
                    mp.setSeriesTitle(seriesDublinCore.getFirst(DublinCore.PROPERTY_TITLE));
                    // Update the series dublin core
                    Catalog[] seriesCatalogs = mp.getCatalogs(MediaPackageElements.SERIES);
                    if (seriesCatalogs.length == 1) {
                        Catalog c = seriesCatalogs[0];
                        String filename = FilenameUtils.getName(c.getURI().toString());
                        URI uri = workspace.put(mp.getIdentifier().toString(), c.getIdentifier(), filename, dublinCoreService.serialize(seriesDublinCore));
                        c.setURI(uri);
                        // setting the URI to a new source so the checksum will most like be invalid
                        c.setChecksum(null);
                    }
                }
                // Remove the series catalog and isPartOf from episode catalog
                if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
                    mp.setSeries(null);
                    mp.setSeriesTitle(null);
                    for (Catalog c : mp.getCatalogs(MediaPackageElements.SERIES)) {
                        mp.remove(c);
                        try {
                            workspace.delete(c.getURI());
                        } catch (NotFoundException e) {
                            logger.info("No series catalog to delete found {}", c.getURI());
                        }
                    }
                    for (Catalog episodeCatalog : mp.getCatalogs(MediaPackageElements.EPISODE)) {
                        DublinCoreCatalog episodeDublinCore = DublinCoreUtil.loadDublinCore(workspace, episodeCatalog);
                        episodeDublinCore.remove(DublinCore.PROPERTY_IS_PART_OF);
                        String filename = FilenameUtils.getName(episodeCatalog.getURI().toString());
                        URI uri = workspace.put(mp.getIdentifier().toString(), episodeCatalog.getIdentifier(), filename, dublinCoreService.serialize(episodeDublinCore));
                        episodeCatalog.setURI(uri);
                        // setting the URI to a new source so the checksum will most like be invalid
                        episodeCatalog.setChecksum(null);
                    }
                }
                // Update the search index with the modified mediapackage
                workflowService.update(instance);
            }
            offset++;
            q = q.withStartPage(offset);
            result = workflowService.getWorkflowInstancesForAdministrativeRead(q);
        }
    } catch (WorkflowException e) {
        logger.warn(e.getMessage());
    } catch (UnauthorizedException e) {
        logger.warn(e.getMessage());
    } catch (IOException e) {
        logger.warn(e.getMessage());
    } finally {
        securityService.setOrganization(prevOrg);
        securityService.setUser(prevUser);
    }
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) WorkflowException(org.opencastproject.workflow.api.WorkflowException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 18 with WorkflowQuery

use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.

the class WorkflowServiceImplTest method testNegativeWorkflowQuery.

@Test
public void testNegativeWorkflowQuery() throws Exception {
    // Ensure that the database doesn't have any workflow instances
    Assert.assertEquals(0, service.countWorkflowInstances());
    Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery().withText("Climate").withCount(100).withStartPage(0)).size());
    startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
    startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
    startAndWait(failingDefinitionWithoutErrorHandler, mediapackage1, WorkflowState.FAILED);
    WorkflowSet succeededWorkflows = service.getWorkflowInstances(new WorkflowQuery().withState(WorkflowState.SUCCEEDED));
    Assert.assertEquals(2, succeededWorkflows.getItems().length);
    WorkflowSet failedWorkflows = service.getWorkflowInstances(new WorkflowQuery().withState(WorkflowState.FAILED));
    Assert.assertEquals(1, failedWorkflows.getItems().length);
    // Ensure that the "without" queries works
    WorkflowSet notFailedWorkflows = service.getWorkflowInstances(new WorkflowQuery().withoutState(WorkflowState.FAILED));
    Assert.assertEquals(2, notFailedWorkflows.getItems().length);
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) Test(org.junit.Test)

Example 19 with WorkflowQuery

use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.

the class WorkflowServiceImplTest method testGetWorkflowByWildcardMatching.

@Test
public void testGetWorkflowByWildcardMatching() throws Exception {
    String searchTerm = "another";
    String searchTermWithoutQuotes = "yet another";
    String searchTermInQuotes = "\"" + searchTermWithoutQuotes + "\"";
    String title = "just" + searchTerm + " " + searchTermInQuotes + " rev129";
    // Ensure that the database doesn't have any workflow instances
    Assert.assertEquals(0, service.countWorkflowInstances());
    mediapackage1.setTitle(title);
    startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
    WorkflowSet workflowsWithTitle = service.getWorkflowInstances(new WorkflowQuery().withTitle(searchTerm));
    Assert.assertEquals(1, workflowsWithTitle.getTotalCount());
    WorkflowSet workflowsWithQuotedTitle = service.getWorkflowInstances(new WorkflowQuery().withTitle(searchTermInQuotes));
    Assert.assertEquals(1, workflowsWithQuotedTitle.getTotalCount());
    WorkflowSet workflowsWithUnQuotedTitle = service.getWorkflowInstances(new WorkflowQuery().withTitle(searchTermWithoutQuotes));
    Assert.assertEquals(1, workflowsWithUnQuotedTitle.getTotalCount());
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) Test(org.junit.Test)

Example 20 with WorkflowQuery

use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.

the class WorkflowServiceImplTest method testGetWorkflowSort.

@Test
public void testGetWorkflowSort() throws Exception {
    String contributor1 = "foo";
    String contributor2 = "bar";
    String contributor3 = "baz";
    // Ensure that the database doesn't have any workflow instances
    Assert.assertEquals(0, service.countWorkflowInstances());
    // set contributors (a multivalued field)
    mediapackage1.addContributor(contributor1);
    mediapackage1.addContributor(contributor2);
    mediapackage2.addContributor(contributor2);
    mediapackage2.addContributor(contributor3);
    // run the workflows
    startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
    startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
    WorkflowSet workflowsWithContributor1 = service.getWorkflowInstances(new WorkflowQuery().withContributor(contributor1));
    WorkflowSet workflowsWithContributor2 = service.getWorkflowInstances(new WorkflowQuery().withContributor(contributor2));
    WorkflowSet workflowsWithContributor3 = service.getWorkflowInstances(new WorkflowQuery().withContributor(contributor3));
    Assert.assertEquals(1, workflowsWithContributor1.getTotalCount());
    Assert.assertEquals(2, workflowsWithContributor2.getTotalCount());
    Assert.assertEquals(1, workflowsWithContributor3.getTotalCount());
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) Test(org.junit.Test)

Aggregations

WorkflowQuery (org.opencastproject.workflow.api.WorkflowQuery)30 WorkflowSet (org.opencastproject.workflow.api.WorkflowSet)18 Test (org.junit.Test)17 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)16 NotFoundException (org.opencastproject.util.NotFoundException)9 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)8 ArrayList (java.util.ArrayList)5 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)5 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)4 WorkflowParsingException (org.opencastproject.workflow.api.WorkflowParsingException)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Organization (org.opencastproject.security.api.Organization)3 User (org.opencastproject.security.api.User)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 WorkflowException (org.opencastproject.workflow.api.WorkflowException)3 WorkflowStateException (org.opencastproject.workflow.api.WorkflowStateException)3 IOException (java.io.IOException)2