use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getDublinCore.
@Override
public DublinCoreCatalog getDublinCore(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(eventId.concat("/dublincore.xml"));
HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
throw new NotFoundException("Event catalog '" + eventId + "' not found on remote scheduler service!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to get dublincore of the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to get dublincore of the event " + eventId);
} else {
DublinCoreCatalog dublinCoreCatalog = DublinCores.read(response.getEntity().getContent());
logger.info("Successfully get event dublincore {} from the remote scheduler service", eventId);
return dublinCoreCatalog;
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to parse event dublincore from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get event dublincore from remote scheduler service");
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class OcDublinCoreUtil method toCatalog.
/**
* Create a generic DublinCoreCatalog from an OcDublinCore.
* Fields are encoded according to the Opencast rules. This class provides functions for each DublinCore
* property that needs special encoding.
*/
public static DublinCoreCatalog toCatalog(final OcDublinCore source) {
// completeness assured by unit test
final DublinCoreCatalog target = DublinCores.mkOpencastEpisode().getCatalog();
for (String a : source.getAbstract()) target.set(DublinCore.PROPERTY_ABSTRACT, a);
for (String a : source.getAccessRights()) target.set(DublinCore.PROPERTY_ACCESS_RIGHTS, a);
for (String a : source.getAccrualMethod()) target.set(DublinCore.PROPERTY_ACCRUAL_METHOD, a);
for (String a : source.getAccrualPeriodicity()) target.set(DublinCore.PROPERTY_ACCRUAL_PERIODICITY, a);
for (String a : source.getAccrualPolicy()) target.set(DublinCore.PROPERTY_ACCRUAL_POLICY, a);
for (String a : source.getAlternative()) target.set(DublinCore.PROPERTY_ALTERNATIVE, a);
for (String a : source.getAudience()) target.set(DublinCore.PROPERTY_AUDIENCE, a);
for (String a : source.getAvailable()) target.set(DublinCore.PROPERTY_AVAILABLE, a);
for (String a : source.getBibliographicCitation()) target.set(DublinCore.PROPERTY_BIBLIOGRAPHIC_CITATION, a);
for (String a : source.getConformsTo()) target.set(DublinCore.PROPERTY_CONFORMS_TO, a);
for (String a : source.getContributor()) target.set(DublinCore.PROPERTY_CONTRIBUTOR, a);
for (String a : source.getCoverage()) target.set(DublinCore.PROPERTY_COVERAGE, a);
target.set(DublinCore.PROPERTY_CREATED, encodeCreated(source.getCreated()));
for (String a : source.getCreator()) target.set(DublinCore.PROPERTY_CREATOR, a);
for (Date a : source.getDate()) target.set(DublinCore.PROPERTY_DATE, encodeDate(a));
for (Date a : source.getDateAccepted()) target.set(DublinCore.PROPERTY_DATE_ACCEPTED, encodeDateAccepted(a));
for (Date a : source.getDateCopyrighted()) target.set(DublinCore.PROPERTY_DATE_COPYRIGHTED, encodeDateCopyrighted(a));
for (Date a : source.getDateSubmitted()) target.set(DublinCore.PROPERTY_DATE_SUBMITTED, encodeDateSubmitted(a));
for (String a : source.getDescription()) target.set(DublinCore.PROPERTY_DESCRIPTION, a);
for (String a : source.getEducationLevel()) target.set(DublinCore.PROPERTY_EDUCATION_LEVEL, a);
for (Long a : source.getExtent()) target.set(DublinCore.PROPERTY_EXTENT, encodeExtent(a));
for (String a : source.getFormat()) target.set(DublinCore.PROPERTY_FORMAT, a);
for (String a : source.getHasFormat()) target.set(DublinCore.PROPERTY_HAS_FORMAT, a);
for (String a : source.getHasPart()) target.set(DublinCore.PROPERTY_HAS_PART, a);
for (String a : source.getHasVersion()) target.set(DublinCore.PROPERTY_HAS_VERSION, a);
for (String a : source.getIdentifier()) target.set(DublinCore.PROPERTY_IDENTIFIER, a);
for (String a : source.getInstructionalMethod()) target.set(DublinCore.PROPERTY_INSTRUCTIONAL_METHOD, a);
for (String a : source.getIsFormatOf()) target.set(DublinCore.PROPERTY_IS_FORMAT_OF, a);
for (String a : source.getIsPartOf()) target.set(DublinCore.PROPERTY_IS_PART_OF, a);
for (String a : source.getIsReferencedBy()) target.set(DublinCore.PROPERTY_IS_REFERENCED_BY, a);
for (String a : source.getIsReplacedBy()) target.set(DublinCore.PROPERTY_IS_REPLACED_BY, a);
for (String a : source.getIsRequiredBy()) target.set(DublinCore.PROPERTY_IS_REQUIRED_BY, a);
for (String a : source.getIssued()) target.set(DublinCore.PROPERTY_ISSUED, a);
for (String a : source.getIsVersionOf()) target.set(DublinCore.PROPERTY_IS_VERSION_OF, a);
for (String a : source.getLanguage()) target.set(DublinCore.PROPERTY_LANGUAGE, a);
for (String a : source.getLicense()) target.set(DublinCore.PROPERTY_LICENSE, a);
for (String a : source.getMediator()) target.set(DublinCore.PROPERTY_MEDIATOR, a);
for (String a : source.getMedium()) target.set(DublinCore.PROPERTY_MEDIUM, a);
for (String a : source.getModified()) target.set(DublinCore.PROPERTY_MODIFIED, a);
for (String a : source.getProvenance()) target.set(DublinCore.PROPERTY_PROVENANCE, a);
for (String a : source.getPublisher()) target.set(DublinCore.PROPERTY_PUBLISHER, a);
for (String a : source.getReferences()) target.set(DublinCore.PROPERTY_REFERENCES, a);
for (String a : source.getRelation()) target.set(DublinCore.PROPERTY_RELATION, a);
for (String a : source.getReplaces()) target.set(DublinCore.PROPERTY_REPLACES, a);
for (String a : source.getRequires()) target.set(DublinCore.PROPERTY_REQUIRES, a);
for (String a : source.getRights()) target.set(DublinCore.PROPERTY_RIGHTS, a);
for (String a : source.getRightsHolder()) target.set(DublinCore.PROPERTY_RIGHTS_HOLDER, a);
for (String a : source.getSource()) target.set(DublinCore.PROPERTY_SOURCE, a);
for (String a : source.getSpatial()) target.set(DublinCore.PROPERTY_SPATIAL, a);
for (String a : source.getSubject()) target.set(DublinCore.PROPERTY_SUBJECT, a);
for (String a : source.getTableOfContents()) target.set(DublinCore.PROPERTY_TABLE_OF_CONTENTS, a);
for (String a : source.getTemporal()) target.set(DublinCore.PROPERTY_TEMPORAL, a);
target.set(DublinCore.PROPERTY_TITLE, source.getTitle());
for (String a : source.getType()) target.set(DublinCore.PROPERTY_TYPE, a);
for (String a : source.getValid()) target.set(DublinCore.PROPERTY_VALID, a);
return target;
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class CommentSchedulerConflictNotifierTest method testCommentSchedulerConflict.
@Test
public void testCommentSchedulerConflict() throws Exception {
Set<String> userIds = new HashSet<>();
userIds.add("user1");
userIds.add("user2");
Map<String, String> caProperties = new HashMap<String, String>();
caProperties.put("test", "true");
caProperties.put("clear", "all");
Map<String, String> wfProperties = new HashMap<String, String>();
wfProperties.put("test", "false");
wfProperties.put("skip", "true");
final String mpId = "1234";
final TechnicalMetadata technicalMetadata = new TechnicalMetadataImpl(mpId, "demo", new Date(), new Date(new Date().getTime() + 10 * 60 * 1000), false, userIds, wfProperties, caProperties, null);
final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
mp.setIdentifier(new IdImpl(mpId));
mp.add(DublinCores.mkOpencastEpisode().getCatalog());
DublinCoreCatalog extendedEvent = DublinCores.mkStandard();
extendedEvent.setFlavor(new MediaPackageElementFlavor("extended", "episode"));
mp.add(extendedEvent);
final SchedulerEvent schedulerEvent = EasyMock.createNiceMock(SchedulerEvent.class);
EasyMock.expect(schedulerEvent.getTechnicalMetadata()).andReturn(technicalMetadata).anyTimes();
EasyMock.expect(schedulerEvent.getMediaPackage()).andReturn(mp).anyTimes();
EasyMock.expect(schedulerEvent.getEventId()).andReturn(mpId).anyTimes();
EasyMock.expect(schedulerEvent.getVersion()).andReturn("2").anyTimes();
EasyMock.replay(schedulerEvent);
ConflictingEvent conflictingEvent = EasyMock.createNiceMock(ConflictingEvent.class);
EasyMock.expect(conflictingEvent.getOldEvent()).andReturn(schedulerEvent).anyTimes();
EasyMock.expect(conflictingEvent.getNewEvent()).andReturn(schedulerEvent).anyTimes();
EasyMock.expect(conflictingEvent.getConflictStrategy()).andReturn(Strategy.NEW).anyTimes();
EasyMock.replay(conflictingEvent);
List<ConflictingEvent> conflicts = new ArrayList<>();
conflicts.add(conflictingEvent);
EventCommentService eventCommentService = EasyMock.createNiceMock(EventCommentService.class);
EasyMock.expect(eventCommentService.updateComment(EasyMock.anyObject(EventComment.class))).andReturn(null).once();
EasyMock.replay(eventCommentService);
conflictNotifier.setEventCommentService(eventCommentService);
conflictNotifier.notifyConflicts(conflicts);
EasyMock.verify(eventCommentService);
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SchedulerRestService method startCapture.
@POST
@Path("capture/{agent}")
@RestQuery(name = "startcapture", description = "Create an immediate event", returnDescription = "If events were successfully generated, status CREATED is returned", pathParameters = { @RestParameter(name = "agent", isRequired = true, type = Type.STRING, description = "The agent identifier") }, restParameters = { @RestParameter(name = "workflowDefinitionId", isRequired = false, type = Type.STRING, description = "The workflow definition id to use") }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_CREATED, description = "Recording started"), @RestResponse(responseCode = HttpServletResponse.SC_NOT_FOUND, description = "There is no such agent"), @RestResponse(responseCode = HttpServletResponse.SC_CONFLICT, description = "The agent is already recording"), @RestResponse(responseCode = HttpServletResponse.SC_UNAUTHORIZED, description = "You do not have permission to start this immediate capture. Maybe you need to authenticate."), @RestResponse(responseCode = HttpServletResponse.SC_SERVICE_UNAVAILABLE, description = "The agent is not ready to communicate") })
public Response startCapture(@PathParam("agent") String agentId, @FormParam("workflowDefinitionId") String wfId) throws NotFoundException, UnauthorizedException {
if (service == null || agentService == null || prolongingService == null)
return Response.serverError().status(Response.Status.SERVICE_UNAVAILABLE).entity("Scheduler service is unavailable, please wait...").build();
// Lookup the agent. If it doesn't exist, add a temporary registration
boolean adHocRegistration = false;
try {
agentService.getAgent(agentId);
} catch (NotFoundException e) {
Properties adHocProperties = new Properties();
adHocProperties.put(AGENT_REGISTRATION_TYPE, AGENT_REGISTRATION_TYPE_ADHOC);
agentService.setAgentConfiguration(agentId, adHocProperties);
agentService.setAgentState(agentId, AgentState.CAPTURING);
adHocRegistration = true;
logger.info("Temporarily registered agent '{}' for ad-hoc recording", agentId);
}
try {
Date now = new Date();
Date temporaryEndDate = DateTime.now().plus(prolongingService.getInitialTime()).toDate();
try {
List<MediaPackage> events = service.findConflictingEvents(agentId, now, temporaryEndDate);
if (!events.isEmpty()) {
logger.info("An already existing event is in a conflict with the the one to be created on the agent {}!", agentId);
return Response.status(Status.CONFLICT).build();
}
} catch (SchedulerException e) {
logger.error("Unable to create immediate event on agent {}: {}", agentId, e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
String workflowId = defaultWorkflowDefinitionId;
if (StringUtils.isNotBlank(wfId))
workflowId = wfId;
Map<String, String> caProperties = new HashMap<>();
caProperties.put("org.opencastproject.workflow.definition", workflowId);
caProperties.put("event.location", agentId);
caProperties.put("event.title", "Capture now event");
// caProperties.put("org.opencastproject.workflow.config.captionHold", "false");
// caProperties.put("org.opencastproject.workflow.config.archiveOp", "true");
// caProperties.put("org.opencastproject.workflow.config.trimHold", "false");
// TODO default metadata? configurable?
// A temporal with start and end period is needed! As well PROPERTY_SPATIAL is needed
DublinCoreCatalog eventCatalog = DublinCores.mkOpencastEpisode().getCatalog();
eventCatalog.set(PROPERTY_TITLE, "Capture now event");
eventCatalog.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(now, temporaryEndDate), Precision.Second));
eventCatalog.set(PROPERTY_SPATIAL, agentId);
eventCatalog.set(PROPERTY_CREATED, EncodingSchemeUtils.encodeDate(new Date(), Precision.Minute));
// eventCatalog.set(PROPERTY_CREATOR, "demo");
// eventCatalog.set(PROPERTY_SUBJECT, "demo");
// eventCatalog.set(PROPERTY_LANGUAGE, "demo");
// eventCatalog.set(PROPERTY_CONTRIBUTOR, "demo");
// eventCatalog.set(PROPERTY_DESCRIPTION, "demo");
// TODO workflow properties
Map<String, String> wfProperties = new HashMap<>();
MediaPackage mediaPackage = null;
try {
mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
mediaPackage = addCatalog(workspace, IOUtils.toInputStream(eventCatalog.toXmlString(), "UTF-8"), "dublincore.xml", MediaPackageElements.EPISODE, mediaPackage);
prolongingService.schedule(agentId);
service.addEvent(now, temporaryEndDate, agentId, Collections.<String>emptySet(), mediaPackage, wfProperties, caProperties, Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
return Response.status(Status.CREATED).header("Location", serverUrl + serviceUrl + '/' + mediaPackage.getIdentifier().compact() + ".xml").build();
} catch (Exception e) {
prolongingService.stop(agentId);
if (e instanceof UnauthorizedException)
throw (UnauthorizedException) e;
logger.error("Unable to create immediate event on agent {}: {}", agentId, e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
} finally {
if (mediaPackage != null) {
for (MediaPackageElement elem : $(mediaPackage.getElements()).bind(MediaPackageSupport.Filters.byFlavor(MediaPackageElements.EPISODE).toFn())) {
try {
workspace.delete(elem.getURI());
} catch (NotFoundException e) {
logger.warn("Unable to find (and hence, delete), this mediapackage '{}' element '{}'", mediaPackage.getIdentifier(), elem.getIdentifier());
} catch (IOException e) {
chuck(e);
}
}
}
}
} catch (Throwable t) {
throw t;
} finally {
if (adHocRegistration) {
agentService.removeAgent(agentId);
logger.info("Removed temporary registration for agent '{}'", agentId);
}
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class CaptureNowProlongingService method prolongEvent.
/**
* Extends the current recording.
*
* @param event
* the recording's media package
* @param dublinCore
* the recording's dublin core catalog
* @param agentId
* the agent
* @throws UnauthorizedException
* if the event cannot be updated due to a lack of access rights
* @throws NotFoundException
* if the event cannot be found
* @throws SchedulerException
* if updating the scheduling data fails
* @throws IOException
* if updating the calendar to the worksapce fails
* @throws IllegalArgumentException
* if a URI cannot be created using the arguments provided
*/
public void prolongEvent(MediaPackage event, DublinCoreCatalog dublinCore, String agentId) throws UnauthorizedException, NotFoundException, SchedulerException, IllegalArgumentException, IOException {
String eventId = event.getIdentifier().compact();
DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(dublinCore.getFirst(DublinCore.PROPERTY_TEMPORAL));
Date prolongedEndDate = new DateTime(period.getEnd()).plus(getProlongingTime()).toDate();
dublinCore.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(period.getStart(), prolongedEndDate), Precision.Second));
List<MediaPackage> events = schedulerService.findConflictingEvents(agentId, period.getStart(), prolongedEndDate);
for (MediaPackage conflictMediaPackage : events) {
if (eventId.equals(conflictMediaPackage.getIdentifier().compact()))
continue;
Opt<DublinCoreCatalog> conflictingDc = DublinCoreUtil.loadEpisodeDublinCore(workspace, conflictMediaPackage);
if (conflictingDc.isNone())
continue;
Date conflictingStartDate = EncodingSchemeUtils.decodeMandatoryPeriod(conflictingDc.get().getFirst(DublinCore.PROPERTY_TEMPORAL)).getStart();
prolongedEndDate = new DateTime(conflictingStartDate).minusMinutes(1).toDate();
dublinCore.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(period.getStart(), prolongedEndDate), Precision.Second));
logger.info("A scheduled event is preventing the current recording on agent '{}' to be further extended. Extending to one minute before the conflicting event", agentId);
stop(agentId);
break;
}
// Update the episode dublin core
Catalog[] episodeCatalogs = event.getCatalogs(MediaPackageElements.EPISODE);
if (episodeCatalogs.length > 0) {
Catalog c = episodeCatalogs[0];
String filename = FilenameUtils.getName(c.getURI().toString());
URI uri = workspace.put(event.getIdentifier().toString(), c.getIdentifier(), filename, IOUtils.toInputStream(dublinCore.toXmlString(), "UTF-8"));
c.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
c.setChecksum(null);
}
schedulerService.updateEvent(eventId, Opt.<Date>none(), Opt.some(prolongedEndDate), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(event), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
}
Aggregations