use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.
the class LiveScheduleServiceImplTest method testReplaceVariables.
@Test
public void testReplaceVariables() throws Exception {
replayServices();
MediaPackageElementFlavor flavor = new MediaPackageElementFlavor("presenter", "delivery");
String expectedStreamName = MP_ID + "-" + CAPTURE_AGENT_NAME + "-presenter-delivery-stream-3840x1080_suffix";
String actualStreamName = service.replaceVariables(MP_ID, CAPTURE_AGENT_NAME, STREAM_NAME, flavor, "3840x1080");
Assert.assertEquals(expectedStreamName, actualStreamName);
}
use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.
the class IndexServiceImplTest method testAddAssetsToMp.
@Test
public void testAddAssetsToMp() throws org.json.simple.parser.ParseException, IOException, ConfigurationException, MediaPackageException, HandleException, IngestException, NotFoundException {
MediaPackage mediapackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
JSONArray assetMetadata = (JSONArray) new JSONParser().parse("[{\"id\":\"attachment_attachment_notes\", " + "\"title\": \"class handout notes\"," + "\"flavorType\": \"attachment\"," + "\"flavorSubType\": \"notes\"," + "\"type\": \"attachment\"}]");
// a test asset input stream
List<String> assetList = new LinkedList<String>();
assetList.add("attachment_attachment_notes");
MediaPackageElementFlavor elemflavor = new MediaPackageElementFlavor("attachment_attachment_notes", "*");
MediaPackageElementFlavor newElemflavor = new MediaPackageElementFlavor("attachment", "notes");
// Set up the mock Ingest Service's attachment
Attachment attachment = new AttachmentImpl();
attachment.setFlavor(elemflavor);
mediapackage.add(attachment);
// Run Test
IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
indexServiceImpl.setIngestService(setupIngestService(mediapackage, Capture.<InputStream>newInstance()));
mediapackage = indexServiceImpl.updateMpAssetFlavor(assetList, mediapackage, assetMetadata, true);
assertTrue("The mediapackage attachment has the updated flavor", mediapackage.getAttachments(newElemflavor).length == 1);
}
use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.
the class IngestRestService method addMediaPackageElement.
protected Response addMediaPackageElement(HttpServletRequest request, MediaPackageElement.Type type) {
MediaPackageElementFlavor flavor = null;
InputStream in = null;
try {
String fileName = null;
MediaPackage mp = null;
Long startTime = null;
String[] tags = null;
/* Only accept multipart/form-data */
if (!ServletFileUpload.isMultipartContent(request)) {
logger.trace("request isn't multipart-form-data");
return Response.serverError().status(Status.BAD_REQUEST).build();
}
boolean isDone = false;
for (FileItemIterator iter = new ServletFileUpload().getItemIterator(request); iter.hasNext(); ) {
FileItemStream item = iter.next();
String fieldName = item.getFieldName();
if (item.isFormField()) {
if ("flavor".equals(fieldName)) {
String flavorString = Streams.asString(item.openStream(), "UTF-8");
logger.trace("flavor: {}", flavorString);
if (flavorString != null) {
flavor = MediaPackageElementFlavor.parseFlavor(flavorString);
}
} else if ("tags".equals(fieldName)) {
String tagsString = Streams.asString(item.openStream(), "UTF-8");
logger.trace("tags: {}", tagsString);
tags = tagsString.split(",");
} else if ("mediaPackage".equals(fieldName)) {
try {
String mediaPackageString = Streams.asString(item.openStream(), "UTF-8");
logger.trace("mediaPackage: {}", mediaPackageString);
mp = factory.newMediaPackageBuilder().loadFromXml(mediaPackageString);
} catch (MediaPackageException e) {
logger.debug("Unable to parse the 'mediaPackage' parameter: {}", ExceptionUtils.getMessage(e));
return Response.serverError().status(Status.BAD_REQUEST).build();
}
} else if ("startTime".equals(fieldName) && "/addPartialTrack".equals(request.getPathInfo())) {
String startTimeString = Streams.asString(item.openStream(), "UTF-8");
logger.trace("startTime: {}", startTime);
try {
startTime = Long.parseLong(startTimeString);
} catch (Exception e) {
logger.debug("Unable to parse the 'startTime' parameter: {}", ExceptionUtils.getMessage(e));
return Response.serverError().status(Status.BAD_REQUEST).build();
}
}
} else {
if (flavor == null) {
/* A flavor has to be specified in the request prior the video file */
logger.debug("A flavor has to be specified in the request prior to the content BODY");
return Response.serverError().status(Status.BAD_REQUEST).build();
}
fileName = item.getName();
in = item.openStream();
isDone = true;
}
if (isDone) {
break;
}
}
/*
* Check if we actually got a valid request including a message body and a valid mediapackage to attach the
* element to
*/
if (in == null || mp == null || MediaPackageSupport.sanityCheck(mp).isSome()) {
return Response.serverError().status(Status.BAD_REQUEST).build();
}
switch(type) {
case Attachment:
mp = ingestService.addAttachment(in, fileName, flavor, tags, mp);
break;
case Catalog:
mp = ingestService.addCatalog(in, fileName, flavor, tags, mp);
break;
case Track:
if (startTime == null) {
mp = ingestService.addTrack(in, fileName, flavor, tags, mp);
} else {
mp = ingestService.addPartialTrack(in, fileName, flavor, startTime, mp);
}
break;
default:
throw new IllegalStateException("Type must be one of track, catalog, or attachment");
}
return Response.ok(MediaPackageParser.getAsXml(mp)).build();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.
the class EventCatalogUIAdapterTest method setUp.
@Before
public void setUp() throws URISyntaxException, NotFoundException, IOException, ListProviderException {
TreeMap<String, String> collection = new TreeMap<String, String>();
collection.put("Entry 1", "Value 1");
collection.put("Entry 2", "Value 2");
collection.put("Entry 3", "Value 3");
BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
EasyMock.replay(bundleContext);
listProvidersService = EasyMock.createMock(ListProvidersService.class);
EasyMock.expect(listProvidersService.getList(EasyMock.anyString(), EasyMock.anyObject(ResourceListQueryImpl.class), EasyMock.anyObject(Organization.class), EasyMock.anyBoolean())).andReturn(collection).anyTimes();
EasyMock.expect(listProvidersService.isTranslatable(EasyMock.anyString())).andThrow(new ListProviderException("not implemented")).anyTimes();
EasyMock.expect(listProvidersService.getDefault(EasyMock.anyString())).andThrow(new ListProviderException("not implemented")).anyTimes();
EasyMock.replay(listProvidersService);
Properties props = new Properties();
InputStream in = getClass().getResourceAsStream("/catalog-adapter/event.properties");
props.load(in);
in.close();
eventProperties = PropertiesUtil.toDictionary(props);
mediaPackageElementFlavor = new MediaPackageElementFlavor(FLAVOR_STRING.split("/")[0], FLAVOR_STRING.split("/")[1]);
URI eventDublincoreURI = getClass().getResource("/catalog-adapter/event-dublincore.xml").toURI();
workspace = EasyMock.createMock(Workspace.class);
EasyMock.expect(workspace.read(eventDublincoreURI)).andAnswer(() -> new FileInputStream(new File(eventDublincoreURI)));
EasyMock.replay(workspace);
Catalog eventCatalog = EasyMock.createMock(Catalog.class);
EasyMock.expect(eventCatalog.getURI()).andReturn(eventDublincoreURI).anyTimes();
EasyMock.replay(eventCatalog);
Catalog[] catalogs = { eventCatalog };
mediapackage = EasyMock.createMock(MediaPackage.class);
EasyMock.expect(mediapackage.getCatalogs(mediaPackageElementFlavor)).andReturn(catalogs).anyTimes();
EasyMock.replay(mediapackage);
dictionary = new Hashtable<String, String>();
dictionary.put(CONF_ORGANIZATION_KEY, ORGANIZATION_STRING);
dictionary.put(CONF_FLAVOR_KEY, FLAVOR_STRING);
dictionary.put(CONF_TITLE_KEY, TITLE_STRING);
dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_INPUT_ID_KEY, title);
dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_LABEL_KEY, label);
dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_TYPE_KEY, type);
dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_READ_ONLY_KEY, readOnly);
dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_REQUIRED_KEY, required);
dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_LIST_PROVIDER_KEY, listProvider);
dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_COLLECTION_ID_KEY, collectionID);
}
use of org.opencastproject.mediapackage.MediaPackageElementFlavor in project opencast by opencast.
the class IngestRestServiceTest method testAddMediaPackageTrackWithStartTime.
@Test
public void testAddMediaPackageTrackWithStartTime() throws Exception {
IngestService ingestService = EasyMock.createNiceMock(IngestService.class);
EasyMock.expect(ingestService.addPartialTrack((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), EasyMock.anyLong(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew()).once();
EasyMock.expect(ingestService.addTrack((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (String[]) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew()).once();
EasyMock.replay(ingestService);
restService.setIngestService(ingestService);
MockHttpServletRequest request = newPartialMockRequest();
request.setPathInfo("/addTrack");
Response response = restService.addMediaPackageTrack(request);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
request = newPartialMockRequest();
request.setPathInfo("/addPartialTrack");
response = restService.addMediaPackageTrack(request);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
EasyMock.verify(ingestService);
}
Aggregations