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));
}
}
}
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);
}
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));
}
}
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());
}
Aggregations