Search in sources :

Example 1 with TechnicalMetadataImpl

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));
}
Also used : TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) Recording(org.opencastproject.scheduler.api.Recording) Date(java.util.Date)

Example 2 with TechnicalMetadataImpl

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");
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) HttpGet(org.apache.http.client.methods.HttpGet) JSONArray(org.json.simple.JSONArray) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) RecordingImpl(org.opencastproject.scheduler.api.RecordingImpl) Date(java.util.Date) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Entry(java.util.Map.Entry) Opt(com.entwinemedia.fn.data.Opt) JSONObject(org.json.simple.JSONObject) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) Recording(org.opencastproject.scheduler.api.Recording) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with TechnicalMetadataImpl

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);
}
Also used : ConflictingEvent(org.opencastproject.scheduler.api.ConflictingEvent) HashMap(java.util.HashMap) TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) ArrayList(java.util.ArrayList) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Date(java.util.Date) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SchedulerEvent(org.opencastproject.scheduler.api.SchedulerEvent) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) EventCommentService(org.opencastproject.event.comment.EventCommentService) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with TechnicalMetadataImpl

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());
}
Also used : ConflictingEvent(org.opencastproject.scheduler.api.ConflictingEvent) HashMap(java.util.HashMap) TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) ArrayList(java.util.ArrayList) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Date(java.util.Date) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SchedulerEvent(org.opencastproject.scheduler.api.SchedulerEvent) SmtpService(org.opencastproject.kernel.mail.SmtpService) MimeMessage(javax.mail.internet.MimeMessage) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Date (java.util.Date)4 TechnicalMetadataImpl (org.opencastproject.scheduler.api.TechnicalMetadataImpl)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 MediaPackage (org.opencastproject.mediapackage.MediaPackage)2 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)2 IdImpl (org.opencastproject.mediapackage.identifier.IdImpl)2 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)2 ConflictingEvent (org.opencastproject.scheduler.api.ConflictingEvent)2 Recording (org.opencastproject.scheduler.api.Recording)2 RecordingImpl (org.opencastproject.scheduler.api.RecordingImpl)2 SchedulerEvent (org.opencastproject.scheduler.api.SchedulerEvent)2 TechnicalMetadata (org.opencastproject.scheduler.api.TechnicalMetadata)2 Opt (com.entwinemedia.fn.data.Opt)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 MimeMessage (javax.mail.internet.MimeMessage)1