Search in sources :

Example 1 with ConflictingEvent

use of org.opencastproject.scheduler.api.ConflictingEvent in project opencast by opencast.

the class CommentSchedulerConflictNotifier method notifyConflicts.

@Override
public void notifyConflicts(List<ConflictingEvent> conflicts) {
    for (ConflictingEvent c : conflicts) {
        StringBuilder sb = new StringBuilder("This scheduled event has been overwritten with conflicting (data from the scheduling source OR manual changes). ");
        if (Strategy.OLD.equals(c.getConflictStrategy())) {
            sb.append("Find below the new version:").append(CharUtils.LF);
            sb.append(CharUtils.LF);
            sb.append(toHumanReadableString(workspace, getEventCatalogUIAdapterFlavors(), c.getNewEvent()));
        } else {
            sb.append("Find below the preceding version:").append(CharUtils.LF);
            sb.append(CharUtils.LF);
            sb.append(toHumanReadableString(workspace, getEventCatalogUIAdapterFlavors(), c.getOldEvent()));
        }
        try {
            EventComment comment = EventComment.create(Option.<Long>none(), c.getNewEvent().getEventId(), securityService.getOrganization().getId(), sb.toString(), securityService.getUser(), COMMENT_REASON, false);
            eventCommentService.updateComment(comment);
        } catch (EventCommentException e) {
            logger.error("Unable to create a comment on the event {}: {}", c.getOldEvent().getEventId(), ExceptionUtils.getStackTrace(e));
        }
    }
}
Also used : EventComment(org.opencastproject.event.comment.EventComment) ConflictingEvent(org.opencastproject.scheduler.api.ConflictingEvent) EventCommentException(org.opencastproject.event.comment.EventCommentException)

Example 2 with ConflictingEvent

use of org.opencastproject.scheduler.api.ConflictingEvent 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 3 with ConflictingEvent

use of org.opencastproject.scheduler.api.ConflictingEvent in project opencast by opencast.

the class EmailSchedulerConflictNotifier method notifyConflicts.

@Override
public void notifyConflicts(List<ConflictingEvent> conflicts) {
    if (StringUtils.isBlank(recipient)) {
        // Abort if the recipient is not properly configured
        return;
    }
    String adminBaseUrl = securityService.getOrganization().getProperties().get(OpencastConstants.ADMIN_URL_ORG_PROPERTY);
    if (StringUtils.isBlank(adminBaseUrl))
        adminBaseUrl = serverUrl;
    String eventDetailsUrl = UrlSupport.concat(adminBaseUrl, "admin-ng/index.html#/events/events?modal=event-details&tab=general&resourceId=");
    StringBuilder sb = new StringBuilder();
    int i = 1;
    for (ConflictingEvent c : conflicts) {
        sb.append(i).append(". ");
        if (Strategy.OLD.equals(c.getConflictStrategy())) {
            sb.append("This scheduled event has been overwritten with conflicting (data from the scheduling source OR manual changes). Find below the new version:").append(CharUtils.LF);
            sb.append(CharUtils.LF);
            String humanReadableString = toHumanReadableString(workspace, getEventCatalogUIAdapterFlavors(), c.getNewEvent());
            sb.append(humanReadableString.replaceFirst(c.getNewEvent().getEventId(), eventDetailsUrl.concat(c.getNewEvent().getEventId())));
            sb.append(CharUtils.LF);
        } else {
            sb.append("This scheduled event has been overwritten with conflicting (data from the scheduling source OR manual changes). Find below the preceding version:").append(CharUtils.LF);
            sb.append(CharUtils.LF);
            String humanReadableString = toHumanReadableString(workspace, getEventCatalogUIAdapterFlavors(), c.getOldEvent());
            sb.append(humanReadableString.replaceFirst(c.getOldEvent().getEventId(), eventDetailsUrl.concat(c.getOldEvent().getEventId())));
            sb.append(CharUtils.LF);
        }
        i++;
    }
    // Create the mail message
    try {
        MimeMessage message = smptService.createMessage();
        message.addRecipient(RecipientType.TO, new InternetAddress(recipient));
        message.setSubject(subject);
        message.setText(template.replace("${recordings}", sb.toString()));
        message.saveChanges();
        smptService.send(message);
        logger.info("E-mail scheduler conflict notification sent to {}", recipient);
    } catch (MessagingException e) {
        logger.error("Unable to send email scheduler conflict notification: {}", ExceptionUtils.getStackTrace(e));
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) ConflictingEvent(org.opencastproject.scheduler.api.ConflictingEvent) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) SchedulerUtil.toHumanReadableString(org.opencastproject.scheduler.impl.SchedulerUtil.toHumanReadableString)

Example 4 with ConflictingEvent

use of org.opencastproject.scheduler.api.ConflictingEvent 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

ConflictingEvent (org.opencastproject.scheduler.api.ConflictingEvent)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 MimeMessage (javax.mail.internet.MimeMessage)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 SchedulerEvent (org.opencastproject.scheduler.api.SchedulerEvent)2 TechnicalMetadata (org.opencastproject.scheduler.api.TechnicalMetadata)2 TechnicalMetadataImpl (org.opencastproject.scheduler.api.TechnicalMetadataImpl)2 MessagingException (javax.mail.MessagingException)1 InternetAddress (javax.mail.internet.InternetAddress)1 EventComment (org.opencastproject.event.comment.EventComment)1 EventCommentException (org.opencastproject.event.comment.EventCommentException)1 EventCommentService (org.opencastproject.event.comment.EventCommentService)1 SmtpService (org.opencastproject.kernel.mail.SmtpService)1