use of org.olat.core.commons.modules.bc.FileInfo in project OpenOLAT by OpenOLAT.
the class FolderNotificationsHandler method createSubscriptionInfo.
/**
* @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
* java.util.Locale, java.util.Date)
*/
@Override
public SubscriptionInfo createSubscriptionInfo(final Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
String genericBusinessPath = p.getBusinessPath() + "[path=";
SubscriptionInfo si;
// there could be news for me, investigate deeper
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
if ("CourseModule".equals(p.getResName())) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
}
String folderRoot = p.getData();
final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot, compareDate);
final Translator translator = Util.createPackageTranslator(FolderNotificationsHandler.class, locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItem(p, translator), null);
SubscriptionListItem subListItem;
for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
FileInfo fi = it_infos.next();
String title = fi.getRelPath();
// known exclude prefixes
if (title != null && title.indexOf("/.") != -1 && FileUtils.isMetaFilename(title)) {
// skip this file, continue with next item in folder
continue;
}
MetaInfo metaInfo = fi.getMetaInfo();
String iconCssClass = null;
if (metaInfo != null) {
if (metaInfo.getTitle() != null) {
title += " (" + metaInfo.getTitle() + ")";
}
iconCssClass = metaInfo.getIconCssClass();
}
Identity ident = fi.getAuthor();
Date modDate = fi.getLastModified();
String desc = translator.translate("notifications.entry", new String[] { title, NotificationHelper.getFormatedName(ident) });
String urlToSend = null;
String businessPath = null;
if (p.getBusinessPath() != null) {
businessPath = genericBusinessPath + fi.getRelPath() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
si.addSubscriptionListItem(subListItem);
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Error creating folder's notifications for subscriber: " + subscriber.getKey(), e);
checkPublisher(subscriber.getPublisher());
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.modules.bc.FileInfo in project OpenOLAT by OpenOLAT.
the class PFNotifications method gatherItems.
private void gatherItems(Identity participant, Publisher p, CourseEnvironment courseEnv, CourseNode node) {
Path folderRoot = Paths.get(courseEnv.getCourseBaseContainer().getRelPath(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant));
final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot.toString(), compareDate);
SubscriptionListItem subListItem;
for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
FileInfo fi = it_infos.next();
MetaInfo metaInfo = fi.getMetaInfo();
String filePath = fi.getRelPath();
Date modDate = fi.getLastModified();
String action = "upload";
try {
Path basepath = courseEnv.getCourseBaseContainer().getBasefile().toPath();
Path completepath = Paths.get(basepath.toString(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant), filePath);
BasicFileAttributes attrs = Files.readAttributes(completepath, BasicFileAttributes.class);
if (attrs.creationTime().toMillis() < attrs.lastModifiedTime().toMillis()) {
action = "modify";
}
} catch (IOException ioe) {
log.error("IOException", ioe);
}
String forby = translator.translate("notifications.entry." + (filePath.contains(PFManager.FILENAME_DROPBOX) ? "by" : "for"));
String userDisplayName = userManager.getUserDisplayName(participant);
String desc = translator.translate("notifications.entry." + action, new String[] { filePath, forby, userDisplayName });
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = null;
if (metaInfo != null) {
iconCssClass = metaInfo.getIconCssClass();
}
if (metaInfo != null && !metaInfo.getName().startsWith(".")) {
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
items.add(subListItem);
}
}
}
use of org.olat.core.commons.modules.bc.FileInfo in project OpenOLAT by OpenOLAT.
the class AbstractTaskNotificationHandler method createSubscriptionInfo.
/**
* @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
* java.util.Locale, java.util.Date)
*/
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
// there could be news for me, investigate deeper
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
String folderRoot = p.getData();
if (isLogDebugEnabled()) {
logDebug("folderRoot=", folderRoot);
}
final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot, compareDate);
final Translator translator = Util.createPackageTranslator(AbstractTaskNotificationHandler.class, locale);
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", p.getResId()), false);
if (re == null) {
if (!checkPublisher(p)) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} else if (re.getRepositoryEntryStatus().isClosed()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate(getNotificationHeaderKey(), new String[] { displayName }), getCssClassIcon()), null);
SubscriptionListItem subListItem;
for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
FileInfo fi = it_infos.next();
MetaInfo metaInfo = fi.getMetaInfo();
String filePath = fi.getRelPath();
if (isLogDebugEnabled())
logDebug("filePath=", filePath);
String fullUserName = getUserNameFromFilePath(metaInfo, filePath);
Date modDate = fi.getLastModified();
String desc = translator.translate(getNotificationEntryKey(), new String[] { filePath, fullUserName });
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = null;
if (metaInfo != null) {
iconCssClass = metaInfo.getIconCssClass();
}
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
si.addSubscriptionListItem(subListItem);
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
getLogger().error("Cannot create task notifications for subscriber: " + subscriber.getKey(), e);
checkPublisher(p);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.modules.bc.FileInfo in project openolat by klemens.
the class PFNotifications method gatherItems.
private void gatherItems(Identity participant, Publisher p, CourseEnvironment courseEnv, CourseNode node) {
Path folderRoot = Paths.get(courseEnv.getCourseBaseContainer().getRelPath(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant));
final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot.toString(), compareDate);
SubscriptionListItem subListItem;
for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
FileInfo fi = it_infos.next();
MetaInfo metaInfo = fi.getMetaInfo();
String filePath = fi.getRelPath();
Date modDate = fi.getLastModified();
String action = "upload";
try {
Path basepath = courseEnv.getCourseBaseContainer().getBasefile().toPath();
Path completepath = Paths.get(basepath.toString(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant), filePath);
BasicFileAttributes attrs = Files.readAttributes(completepath, BasicFileAttributes.class);
if (attrs.creationTime().toMillis() < attrs.lastModifiedTime().toMillis()) {
action = "modify";
}
} catch (IOException ioe) {
log.error("IOException", ioe);
}
String forby = translator.translate("notifications.entry." + (filePath.contains(PFManager.FILENAME_DROPBOX) ? "by" : "for"));
String userDisplayName = userManager.getUserDisplayName(participant);
String desc = translator.translate("notifications.entry." + action, new String[] { filePath, forby, userDisplayName });
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = null;
if (metaInfo != null) {
iconCssClass = metaInfo.getIconCssClass();
}
if (metaInfo != null && !metaInfo.getName().startsWith(".")) {
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
items.add(subListItem);
}
}
}
use of org.olat.core.commons.modules.bc.FileInfo in project openolat by klemens.
the class DocumentPoolNotificationsHandler method createSubscriptionInfo.
private void createSubscriptionInfo(VFSContainer container, String prefixBusinessPath, Date compareDate, SubscriptionInfo si, Publisher p, Translator translator) {
List<FileInfo> fInfos = FolderManager.getFileInfos(((OlatRelPathImpl) container).getRelPath(), compareDate);
for (FileInfo infos : fInfos) {
String title = infos.getRelPath();
// known exclude prefixes
if (title != null && title.indexOf("/.") != -1 && FileUtils.isMetaFilename(title)) {
// skip this file, continue with next item in folder
continue;
}
MetaInfo metaInfo = infos.getMetaInfo();
String iconCssClass = null;
if (metaInfo != null) {
if (metaInfo.getTitle() != null) {
title += " (" + metaInfo.getTitle() + ")";
}
iconCssClass = metaInfo.getIconCssClass();
}
Identity ident = infos.getAuthor();
Date modDate = infos.getLastModified();
String desc = translator.translate("notifications.document.entry", new String[] { title, NotificationHelper.getFormatedName(ident) });
String urlToSend = null;
String businessPath = null;
if (p.getBusinessPath() != null) {
businessPath = prefixBusinessPath + infos.getRelPath() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
si.addSubscriptionListItem(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass));
}
}
Aggregations