Search in sources :

Example 1 with Tuple

use of org.opencastproject.util.data.Tuple in project opencast by opencast.

the class EpisodeAclTransitionEntity method update.

EpisodeAclTransitionEntity update(final String episodeId, final String orgId, final Date applicationDate, final Option<ManagedAclEntity> managedAcl, final Option<ConfiguredWorkflowRef> workflow) {
    final EpisodeAclTransitionEntity self = this;
    run(EpisodeACLTransition.class, new EpisodeACLTransition() {

        @Override
        public String getEpisodeId() {
            self.episodeId = episodeId;
            return null;
        }

        @Override
        public Option<ManagedAcl> getAccessControlList() {
            self.managedAcl = managedAcl.getOrElseNull();
            return null;
        }

        @Override
        public boolean isDelete() {
            return false;
        }

        @Override
        public long getTransitionId() {
            return 0;
        }

        @Override
        public String getOrganizationId() {
            self.organizationId = orgId;
            return null;
        }

        @Override
        public Date getApplicationDate() {
            self.applicationDate = applicationDate;
            return null;
        }

        @Override
        public Option<ConfiguredWorkflowRef> getWorkflow() {
            final Tuple<Option<String>, Option<String>> s = splitConfiguredWorkflowRef(workflow);
            self.workflowId = s.getA().getOrElseNull();
            self.workflowParams = s.getB().getOrElseNull();
            return null;
        }

        @Override
        public boolean isDone() {
            self.done = done;
            return false;
        }
    });
    return self;
}
Also used : Option(org.opencastproject.util.data.Option) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) Date(java.util.Date) Tuple(org.opencastproject.util.data.Tuple)

Example 2 with Tuple

use of org.opencastproject.util.data.Tuple in project opencast by opencast.

the class SeriesAclTransitionEntity method update.

SeriesAclTransitionEntity update(final String seriesId, final String orgId, final Date applicationDate, final ManagedAclEntity managedAcl, final Option<ConfiguredWorkflowRef> workflow, final boolean override) {
    final SeriesAclTransitionEntity self = this;
    run(SeriesACLTransition.class, new SeriesACLTransition() {

        @Override
        public String getSeriesId() {
            self.seriesId = seriesId;
            return null;
        }

        @Override
        public ManagedAcl getAccessControlList() {
            self.managedAcl = managedAcl;
            return null;
        }

        @Override
        public boolean isOverride() {
            self.override = override;
            return false;
        }

        @Override
        public long getTransitionId() {
            return 0;
        }

        @Override
        public String getOrganizationId() {
            self.organizationId = orgId;
            return null;
        }

        @Override
        public Date getApplicationDate() {
            self.applicationDate = applicationDate;
            return null;
        }

        @Override
        public Option<ConfiguredWorkflowRef> getWorkflow() {
            final Tuple<Option<String>, Option<String>> s = splitConfiguredWorkflowRef(workflow);
            self.workflowId = s.getA().getOrElseNull();
            self.workflowParams = s.getB().getOrElseNull();
            return null;
        }

        @Override
        public boolean isDone() {
            self.done = done;
            return false;
        }
    });
    return this;
}
Also used : SeriesACLTransition(org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) Option(org.opencastproject.util.data.Option) Date(java.util.Date) Tuple(org.opencastproject.util.data.Tuple)

Example 3 with Tuple

use of org.opencastproject.util.data.Tuple in project opencast by opencast.

the class IndexServiceImplTest method testCreateEventInputNormalExpectsCreatedEvent.

@Test
public void testCreateEventInputNormalExpectsCreatedEvent() throws Exception {
    String expectedTitle = "Test Event Creation";
    String username = "akm220";
    String org = "mh_default_org";
    String[] creators = new String[] {};
    Id mpId = new IdImpl("mp-id");
    String testResourceLocation = "/events/create-event.json";
    JSONObject metadataJson = (JSONObject) parser.parse(IOUtils.toString(IndexServiceImplTest.class.getResourceAsStream(testResourceLocation)));
    Capture<Catalog> result = EasyMock.newCapture();
    Capture<String> mediapackageIdResult = EasyMock.newCapture();
    Capture<String> catalogIdResult = EasyMock.newCapture();
    Capture<String> filenameResult = EasyMock.newCapture();
    Capture<InputStream> catalogResult = EasyMock.newCapture();
    Capture<String> mediapackageTitleResult = EasyMock.newCapture();
    SecurityService securityService = setupSecurityService(username, org);
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.put(EasyMock.capture(mediapackageIdResult), EasyMock.capture(catalogIdResult), EasyMock.capture(filenameResult), EasyMock.capture(catalogResult))).andReturn(new URI("catalog.xml"));
    EasyMock.replay(workspace);
    // Create Common Event Catalog UI Adapter
    CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
    // Setup mediapackage.
    MediaPackage mediapackage = EasyMock.createMock(MediaPackage.class);
    mediapackage.add(EasyMock.capture(result));
    EasyMock.expectLastCall();
    EasyMock.expect(mediapackage.getCatalogs(EasyMock.anyObject(MediaPackageElementFlavor.class))).andReturn(new Catalog[] {});
    EasyMock.expect(mediapackage.getIdentifier()).andReturn(mpId).anyTimes();
    EasyMock.expect(mediapackage.getCreators()).andReturn(creators);
    mediapackage.addCreator("");
    EasyMock.expectLastCall();
    mediapackage.setTitle(EasyMock.capture(mediapackageTitleResult));
    EasyMock.expectLastCall();
    EasyMock.expect(mediapackage.getElements()).andReturn(new MediaPackageElement[] {}).anyTimes();
    EasyMock.expect(mediapackage.getCatalogs(EasyMock.anyObject(MediaPackageElementFlavor.class))).andReturn(new Catalog[] {}).anyTimes();
    EasyMock.expect(mediapackage.getSeries()).andReturn(null).anyTimes();
    mediapackage.setSeries(EasyMock.anyString());
    mediapackage.setSeriesTitle(EasyMock.anyString());
    EasyMock.expectLastCall();
    EasyMock.replay(mediapackage);
    IngestService ingestService = setupIngestService(mediapackage, Capture.<InputStream>newInstance());
    // Setup Authorization Service
    Tuple<MediaPackage, Attachment> returnValue = new Tuple<MediaPackage, Attachment>(mediapackage, null);
    AuthorizationService authorizationService = EasyMock.createMock(AuthorizationService.class);
    EasyMock.expect(authorizationService.setAcl(EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(AclScope.class), EasyMock.anyObject(AccessControlList.class))).andReturn(returnValue);
    EasyMock.replay(authorizationService);
    // Run Test
    IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
    indexServiceImpl.setAuthorizationService(setupAuthorizationService(mediapackage));
    indexServiceImpl.setIngestService(ingestService);
    indexServiceImpl.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexServiceImpl.addCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexServiceImpl.setUserDirectoryService(noUsersUserDirectoryService);
    indexServiceImpl.setSecurityService(securityService);
    indexServiceImpl.setWorkspace(workspace);
    indexServiceImpl.createEvent(metadataJson, mediapackage);
    assertTrue("The catalog must be added to the mediapackage", result.hasCaptured());
    assertEquals("The catalog should have been added to the correct mediapackage", mpId.toString(), mediapackageIdResult.getValue());
    assertTrue("The catalog should have a new id", catalogIdResult.hasCaptured());
    assertTrue("The catalog should have a new filename", filenameResult.hasCaptured());
    assertTrue("The catalog should have been added to the input stream", catalogResult.hasCaptured());
    assertTrue("The mediapackage should have had its title updated", catalogResult.hasCaptured());
    assertEquals("The mediapackage title should have been updated.", expectedTitle, mediapackageTitleResult.getValue());
    assertTrue("The catalog should have been created", catalogResult.hasCaptured());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Attachment(org.opencastproject.mediapackage.Attachment) AclScope(org.opencastproject.security.api.AclScope) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) IngestService(org.opencastproject.ingest.api.IngestService) InputStream(java.io.InputStream) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) JSONObject(org.json.simple.JSONObject) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) Tuple(org.opencastproject.util.data.Tuple) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 4 with Tuple

use of org.opencastproject.util.data.Tuple in project opencast by opencast.

the class InboxScannerService method updated.

// synchronized with activate(ComponentContext)
@Override
public synchronized void updated(Dictionary properties) throws ConfigurationException {
    // build scanner configuration
    final String orgId = getCfg(properties, USER_ORG);
    final String userId = getCfg(properties, USER_NAME);
    final String mediaFlavor = getCfg(properties, MEDIA_FLAVOR);
    final String workflowDefinition = getCfg(properties, WORKFLOW_DEFINITION);
    final Map<String, String> workflowConfig = getCfgAsMap(properties, WORKFLOW_CONFIG);
    final int interval = getCfgAsInt(properties, INBOX_POLL);
    final File inbox = new File(getCfg(properties, INBOX_PATH));
    if (!inbox.isDirectory()) {
        try {
            FileUtils.forceMkdir(inbox);
        } catch (IOException e) {
            throw new ConfigurationException(INBOX_PATH, String.format("%s does not exists and could not be created", inbox.getAbsolutePath()));
        }
    }
    /* We need to be able to read from the inbox to get files from there */
    if (!inbox.canRead()) {
        throw new ConfigurationException(INBOX_PATH, String.format("Cannot read from %s", inbox.getAbsolutePath()));
    }
    /* We need to be able to write to the inbox to remove files after they have been ingested */
    if (!inbox.canWrite()) {
        throw new ConfigurationException(INBOX_PATH, String.format("Cannot write to %s", inbox.getAbsolutePath()));
    }
    final int maxthreads = option(cc.getBundleContext().getProperty("org.opencastproject.inbox.threads")).bind(Strings.toInt).getOrElse(1);
    final Option<SecurityContext> secCtx = getUserAndOrganization(securityService, orgDir, orgId, userDir, userId).bind(new Function<Tuple<User, Organization>, Option<SecurityContext>>() {

        @Override
        public Option<SecurityContext> apply(Tuple<User, Organization> a) {
            return some(new SecurityContext(securityService, a.getB(), a.getA()));
        }
    });
    // Only setup new inbox if security context could be aquired
    if (secCtx.isSome()) {
        // remove old file install configuration
        fileInstallCfg.foreach(removeFileInstallCfg);
        // set up new file install config
        fileInstallCfg = some(configureFileInstall(cc.getBundleContext(), inbox, interval));
        // create new scanner
        ingestor = some(new Ingestor(ingestService, workingFileRepository, secCtx.get(), workflowDefinition, workflowConfig, mediaFlavor, inbox, maxthreads));
        logger.info("Now watching inbox {}", inbox.getAbsolutePath());
    } else {
        logger.warn("Cannot create security context for user {}, organization {}. " + "Either the organization or the user does not exist", userId, orgId);
    }
}
Also used : User(org.opencastproject.security.api.User) SecurityUtil.getUserAndOrganization(org.opencastproject.security.util.SecurityUtil.getUserAndOrganization) Organization(org.opencastproject.security.api.Organization) IOException(java.io.IOException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SecurityContext(org.opencastproject.security.util.SecurityContext) Option(org.opencastproject.util.data.Option) File(java.io.File) Tuple(org.opencastproject.util.data.Tuple)

Example 5 with Tuple

use of org.opencastproject.util.data.Tuple in project opencast by opencast.

the class RestUtils method getFromAndToDateRange.

/**
 * Parse the UTC format date range string to two Date objects to represent a range of dates.
 * <p>
 * Sample UTC date range format string:<br>
 * i.e. yyyy-MM-ddTHH:mm:ssZ/yyyy-MM-ddTHH:mm:ssZ e.g. 2014-09-27T16:25Z/2014-09-27T17:55Z
 * </p>
 *
 * @param fromToDateRange
 *          The string that represents the UTC formed date range.
 * @return A Tuple with the two Dates
 * @throws IllegalArgumentException
 *           Thrown if the input string is malformed
 */
public static Tuple<Date, Date> getFromAndToDateRange(String fromToDateRange) {
    String[] dates = fromToDateRange.split("/");
    if (dates.length != 2) {
        logger.warn("The date range '{}' is malformed", fromToDateRange);
        throw new IllegalArgumentException("The date range string is malformed");
    }
    Date fromDate = null;
    try {
        fromDate = new Date(DateTimeSupport.fromUTC(dates[0]));
    } catch (Exception e) {
        logger.warn("Unable to parse from date parameter '{}'", dates[0]);
        throw new IllegalArgumentException("Unable to parse from date parameter");
    }
    Date toDate = null;
    try {
        toDate = new Date(DateTimeSupport.fromUTC(dates[1]));
    } catch (Exception e) {
        logger.warn("Unable to parse to date parameter '{}'", dates[1]);
        throw new IllegalArgumentException("Unable to parse to date parameter");
    }
    return new Tuple<Date, Date>(fromDate, toDate);
}
Also used : Date(java.util.Date) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) Tuple(org.opencastproject.util.data.Tuple)

Aggregations

Tuple (org.opencastproject.util.data.Tuple)28 ArrayList (java.util.ArrayList)11 Date (java.util.Date)9 MediaPackage (org.opencastproject.mediapackage.MediaPackage)9 NotFoundException (org.opencastproject.util.NotFoundException)8 Test (org.junit.Test)7 IOException (java.io.IOException)6 URI (java.net.URI)6 Job (org.opencastproject.job.api.Job)5 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)5 HashMap (java.util.HashMap)4 JSONObject (org.json.simple.JSONObject)4 LaidOutElement (org.opencastproject.composer.api.LaidOutElement)4 Dimension (org.opencastproject.composer.layout.Dimension)4 Catalog (org.opencastproject.mediapackage.Catalog)4 AccessControlList (org.opencastproject.security.api.AccessControlList)4 File (java.io.File)3 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3 MultiShapeLayout (org.opencastproject.composer.layout.MultiShapeLayout)3