use of org.opencastproject.scheduler.api.TechnicalMetadataImpl in project opencast by opencast.
the class SchedulerServiceImpl method getTechnicalMetadata.
private TechnicalMetadata getTechnicalMetadata(ARecord record, Props p) {
final String agentId = record.getProperties().apply(Properties.getString(p.agent().name()));
final boolean optOut = record.getProperties().apply(Properties.getBoolean(p.optOut().name()));
final Date start = record.getProperties().apply(Properties.getDate(p.start().name()));
final Date end = record.getProperties().apply(Properties.getDate(p.end().name()));
final Set<String> presenters = getPresenters(record.getProperties().apply(getStringOpt(PRESENTERS_CONFIG)).getOr(""));
final Opt<String> recordingStatus = record.getProperties().apply(Properties.getStringOpt(p.recordingStatus().name()));
String caNamespace = CA_NAMESPACE;
String wfNamespace = WORKFLOW_NAMESPACE;
if (TRX_NAMESPACE.equals(p.namespace())) {
caNamespace = TRX_CA_NAMESPACE;
wfNamespace = TRX_WORKFLOW_NAMESPACE;
} else {
caNamespace = CA_NAMESPACE;
wfNamespace = WORKFLOW_NAMESPACE;
}
final Opt<Long> lastHeard = record.getProperties().apply(Properties.getLongOpt(p.recordingLastHeard().name()));
final Map<String, String> caMetadata = record.getProperties().filter(filterByNamespace._2(caNamespace)).group(toKey, toValue);
final Map<String, String> wfProperties = record.getProperties().filter(filterByNamespace._2(wfNamespace)).group(toKey, toValue);
Recording recording = null;
if (recordingStatus.isSome() && lastHeard.isSome())
recording = new RecordingImpl(record.getMediaPackageId(), recordingStatus.get(), lastHeard.get());
return new TechnicalMetadataImpl(record.getMediaPackageId(), agentId, start, end, optOut, presenters, wfProperties, caMetadata, Opt.nul(recording));
}
use of org.opencastproject.scheduler.api.TechnicalMetadataImpl in project opencast by opencast.
the class SchedulerServiceRemoteImpl method getTechnicalMetadata.
@Override
public TechnicalMetadata getTechnicalMetadata(String eventId) throws NotFoundException, UnauthorizedException, SchedulerException {
HttpGet get = new HttpGet(eventId.concat("/technical.json"));
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 with id '" + eventId + "' not found on remote scheduler service!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
logger.info("Unauthorized to get the technical metadata of the event {}.", eventId);
throw new UnauthorizedException("Unauthorized to get the technical metadata of the event " + eventId);
} else {
String technicalMetadataJson = EntityUtils.toString(response.getEntity(), UTF_8);
JSONObject json = (JSONObject) parser.parse(technicalMetadataJson);
final String recordingId = (String) json.get("id");
final Date start = new Date(DateTimeSupport.fromUTC((String) json.get("start")));
final Date end = new Date(DateTimeSupport.fromUTC((String) json.get("end")));
final boolean optOut = (Boolean) json.get("optOut");
final String location = (String) json.get("location");
final Set<String> presenters = new HashSet<>();
JSONArray presentersArr = (JSONArray) json.get("presenters");
for (int i = 0; i < presentersArr.size(); i++) {
presenters.add((String) presentersArr.get(i));
}
final Map<String, String> wfProperties = new HashMap<>();
JSONObject wfPropertiesObj = (JSONObject) json.get("wfProperties");
Set<Entry<String, String>> entrySet = wfPropertiesObj.entrySet();
for (Entry<String, String> entry : entrySet) {
wfProperties.put(entry.getKey(), entry.getValue());
}
final Map<String, String> agentConfig = new HashMap<>();
JSONObject agentConfigObj = (JSONObject) json.get("agentConfig");
entrySet = agentConfigObj.entrySet();
for (Entry<String, String> entry : entrySet) {
agentConfig.put(entry.getKey(), entry.getValue());
}
String status = (String) json.get("state");
String lastHeard = (String) json.get("lastHeardFrom");
Recording recording = null;
if (StringUtils.isNotBlank(status) && StringUtils.isNotBlank(lastHeard)) {
recording = new RecordingImpl(recordingId, status, DateTimeSupport.fromUTC(lastHeard));
}
final Opt<Recording> recordingOpt = Opt.nul(recording);
logger.info("Successfully get the technical metadata of event '{}' from the remote scheduler service", eventId);
return new TechnicalMetadataImpl(recordingId, location, start, end, optOut, presenters, wfProperties, agentConfig, recordingOpt);
}
}
} catch (NotFoundException e) {
throw e;
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SchedulerException("Unable to parse the technical metadata from remote scheduler service: " + e);
} finally {
closeConnection(response);
}
throw new SchedulerException("Unable to get the technical metadata from remote scheduler service");
}
use of org.opencastproject.scheduler.api.TechnicalMetadataImpl 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.scheduler.api.TechnicalMetadataImpl in project opencast by opencast.
the class EmailSchedulerConflictNotifierTest method testEmailSchedulerConflict.
@Test
public void testEmailSchedulerConflict() 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);
final Integer[] counter = new Integer[1];
counter[0] = 0;
SmtpService smtpService = new SmtpService() {
@Override
public void send(MimeMessage message) throws MessagingException {
counter[0]++;
}
};
conflictNotifier.setSmtpService(smtpService);
conflictNotifier.notifyConflicts(conflicts);
Assert.assertEquals(1, counter[0].intValue());
}
Aggregations