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;
}
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);
}
}
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;
}
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);
}
}
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);
}
}
}
Aggregations