Search in sources :

Example 1 with Option

use of org.opencastproject.util.data.Option 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 Option

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

the class AclServiceImpl method applyAclToEpisode.

@Override
public boolean applyAclToEpisode(String episodeId, AccessControlList acl, Option<ConfiguredWorkflowRef> workflow) throws AclServiceException {
    try {
        Option<MediaPackage> mediaPackage = Option.none();
        if (assetManager != null)
            mediaPackage = getFromAssetManagerByMpId(episodeId);
        Option<AccessControlList> aclOpt = Option.option(acl);
        // the episode service is the source of authority for the retrieval of media packages
        for (final MediaPackage episodeSvcMp : mediaPackage) {
            aclOpt.fold(new Option.EMatch<AccessControlList>() {

                // set the new episode ACL
                @Override
                public void esome(final AccessControlList acl) {
                    // update in episode service
                    MediaPackage mp = authorizationService.setAcl(episodeSvcMp, AclScope.Episode, acl).getA();
                    if (assetManager != null)
                        assetManager.takeSnapshot(mp);
                }

                // if none EpisodeACLTransition#isDelete returns true so delete the episode ACL
                @Override
                public void enone() {
                    // update in episode service
                    MediaPackage mp = authorizationService.removeAcl(episodeSvcMp, AclScope.Episode);
                    if (assetManager != null)
                        assetManager.takeSnapshot(mp);
                }
            });
            // apply optional workflow
            for (ConfiguredWorkflowRef workflowRef : workflow) applyWorkflow(list(episodeSvcMp), workflowRef);
            return true;
        }
        // not found
        return false;
    } catch (Exception e) {
        logger.error("Error applying episode ACL", e);
        throw new AclServiceException(e);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Option(org.opencastproject.util.data.Option) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 3 with Option

use of org.opencastproject.util.data.Option 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 4 with Option

use of org.opencastproject.util.data.Option 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 Option

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

the class WorkspaceImpl method downloadIfNecessary.

/**
 * Download content of <code>uri</code> to file <code>dst</code> only if necessary, i.e. either the file does not yet
 * exist in the workspace or a newer version is available at <code>uri</code>.
 *
 * @return the file
 */
private File downloadIfNecessary(final URI src, final File dst) throws IOException, NotFoundException {
    HttpGet get = createGetRequest(src, dst);
    while (true) {
        // run the http request and handle its response
        final Either<Exception, Either<String, Option<File>>> result = trustedHttpClient.<Either<String, Option<File>>>runner(get).run(handleDownloadResponse(src, dst));
        // right: there's an expected result
        for (Either<String, Option<File>> a : result.right()) {
            // right: either a file could be found or not
            for (Option<File> ff : a.right()) {
                for (File f : ff) {
                    return f;
                }
                FileUtils.deleteQuietly(dst);
                // none
                throw new NotFoundException();
            }
            // left: file will be ready later
            for (String token : a.left()) {
                get = createGetRequest(src, dst, tuple("token", token));
                sleep(60000);
            }
        }
        // left: an exception occurred
        for (Exception e : result.left()) {
            logger.warn(format("Could not copy %s to %s: %s", src.toString(), dst.getAbsolutePath(), e.getMessage()));
            FileUtils.deleteQuietly(dst);
            throw new NotFoundException(e);
        }
    }
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Either(org.opencastproject.util.data.Either) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(org.opencastproject.util.NotFoundException) Option(org.opencastproject.util.data.Option) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException)

Aggregations

Option (org.opencastproject.util.data.Option)12 Date (java.util.Date)4 File (java.io.File)3 IOException (java.io.IOException)3 Test (org.junit.Test)3 NotFoundException (org.opencastproject.util.NotFoundException)3 Tuple (org.opencastproject.util.data.Tuple)3 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)2 MediaPackage (org.opencastproject.mediapackage.MediaPackage)2 Either (org.opencastproject.util.data.Either)2 Function (org.opencastproject.util.data.Function)2 ConfiguredWorkflowRef (org.opencastproject.workflow.api.ConfiguredWorkflowRef)2 JsonPath (com.jayway.restassured.path.json.JsonPath)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Properties (java.util.Properties)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 HttpGet (org.apache.http.client.methods.HttpGet)1