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