use of org.olat.modules.taxonomy.model.TaxonomyRefImpl in project openolat by klemens.
the class DocumentPoolNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
try {
SubscriptionInfo si;
String taxonomyKey = documentPoolModule.getTaxonomyTreeKey();
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews) && StringHelper.isLong(taxonomyKey)) {
Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(new Long(taxonomyKey)));
if (taxonomy == null) {
return notificationsManager.getNoSubscriptionInfo();
}
Identity identity = subscriber.getIdentity();
Roles roles = securityManager.getRoles(identity);
boolean isTaxonomyAdmin = roles.isOLATAdmin();
Translator translator = Util.createPackageTranslator(DocumentPoolMainController.class, locale);
String templates = translator.translate("document.pool.templates");
TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(taxonomy, identity, null, isTaxonomyAdmin, documentPoolModule.isTemplatesDirectoryEnabled(), templates, locale);
TreeModel model = builder.buildTreeModel();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItemForPublisher(), null);
new TreeVisitor(node -> {
TaxonomyTreeNode tNode = (TaxonomyTreeNode) node;
if (tNode.getTaxonomyLevel() != null && tNode.isDocumentsLibraryEnabled() && tNode.isCanRead()) {
VFSContainer container = taxonomyService.getDocumentsLibrary(tNode.getTaxonomyLevel());
String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][TaxonomyLevel:" + tNode.getTaxonomyLevel().getKey() + "][path=";
createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
} else if (tNode.getType() == TaxonomyTreeNodeType.templates) {
VFSContainer container = taxonomyService.getDocumentsLibrary(taxonomy);
String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][Templates:0s][path=";
createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
}
}, model.getRootNode(), false).visitAll();
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Cannot create document pool notifications for subscriber: " + subscriber.getKey(), e);
return notificationsManager.getNoSubscriptionInfo();
}
}
use of org.olat.modules.taxonomy.model.TaxonomyRefImpl in project OpenOLAT by OpenOLAT.
the class SearchControllerFactory method getBusinessPathLabel.
@Override
public String getBusinessPathLabel(String token, List<String> allTokens, Locale locale) {
try {
String[] splitted = token.split("[:]");
if (splitted != null && splitted.length == 2) {
String tokenType = splitted[0];
String tokenKey = splitted[1];
if ("RepositoryEntry".equals(tokenType)) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(Long.parseLong(tokenKey));
return re.getDisplayname();
}
if ("CourseNode".equals(tokenType)) {
String repoKey = allTokens.get(0).split("[:]")[1];
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(Long.parseLong(repoKey));
if (re != null) {
ICourse course = CourseFactory.loadCourse(re);
CourseNode courseNode = course.getRunStructure().getNode(tokenKey);
return courseNode.getShortTitle();
}
}
if ("Identity".equals(tokenType)) {
IdentityShort identity = BaseSecurityManager.getInstance().loadIdentityShortByKey(Long.parseLong(tokenKey));
return UserManager.getInstance().getUserDisplayName(identity);
}
if ("BusinessGroup".equals(tokenType)) {
BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(Long.parseLong(tokenKey));
return bg == null ? "" : bg.getName();
}
if ("Taxonomy".equals(tokenType)) {
Taxonomy taxonomy = CoreSpringFactory.getImpl(TaxonomyService.class).getTaxonomy(new TaxonomyRefImpl(Long.parseLong(tokenKey)));
return taxonomy == null ? "" : taxonomy.getDisplayName();
}
if ("TaxonomyLevel".equals(tokenType)) {
TaxonomyLevel level = CoreSpringFactory.getImpl(TaxonomyService.class).getTaxonomyLevel(new TaxonomyLevelRefImpl(Long.parseLong(tokenKey)));
return level == null ? "" : level.getDisplayName();
}
Translator translator = Util.createPackageTranslator(this.getClass(), locale);
if ("DocumentPool".equals(tokenType)) {
return translator.translate("DocumentPool");
}
if ("Templates".equals(tokenType)) {
return translator.translate("Templates");
}
if ("userfolder".equals(tokenType)) {
return translator.translate("type.identity.publicfolder");
}
String translated = translator.translate(tokenType);
if (translated == null || translated.length() > 64) {
// no translation, translator return an error
return token;
}
return translated;
}
} catch (Exception ex) {
log.warn("Problem to decipher business path token: " + token, ex);
}
return token;
}
use of org.olat.modules.taxonomy.model.TaxonomyRefImpl in project OpenOLAT by OpenOLAT.
the class DocumentPoolNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
try {
SubscriptionInfo si;
String taxonomyKey = documentPoolModule.getTaxonomyTreeKey();
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews) && StringHelper.isLong(taxonomyKey)) {
Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(new Long(taxonomyKey)));
if (taxonomy == null) {
return notificationsManager.getNoSubscriptionInfo();
}
Identity identity = subscriber.getIdentity();
Roles roles = securityManager.getRoles(identity);
boolean isTaxonomyAdmin = roles.isOLATAdmin();
Translator translator = Util.createPackageTranslator(DocumentPoolMainController.class, locale);
String templates = translator.translate("document.pool.templates");
TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(taxonomy, identity, null, isTaxonomyAdmin, documentPoolModule.isTemplatesDirectoryEnabled(), templates, locale);
TreeModel model = builder.buildTreeModel();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItemForPublisher(), null);
new TreeVisitor(node -> {
TaxonomyTreeNode tNode = (TaxonomyTreeNode) node;
if (tNode.getTaxonomyLevel() != null && tNode.isDocumentsLibraryEnabled() && tNode.isCanRead()) {
VFSContainer container = taxonomyService.getDocumentsLibrary(tNode.getTaxonomyLevel());
String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][TaxonomyLevel:" + tNode.getTaxonomyLevel().getKey() + "][path=";
createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
} else if (tNode.getType() == TaxonomyTreeNodeType.templates) {
VFSContainer container = taxonomyService.getDocumentsLibrary(taxonomy);
String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][Templates:0s][path=";
createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
}
}, model.getRootNode(), false).visitAll();
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Cannot create document pool notifications for subscriber: " + subscriber.getKey(), e);
return notificationsManager.getNoSubscriptionInfo();
}
}
use of org.olat.modules.taxonomy.model.TaxonomyRefImpl in project OpenOLAT by OpenOLAT.
the class DocumentPoolModuleWebService method getTaxonomyWebService.
@Path("{taxonomyKey}")
public TaxonomyWebService getTaxonomyWebService(@PathParam("taxonomyKey") Long taxonomyKey, @Context HttpServletRequest httpRequest) {
Roles roles = getRoles(httpRequest);
if (!roles.isOLATAdmin()) {
throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
}
if (taxonomyKey == null || taxonomyKey.longValue() <= 0) {
throw new WebApplicationException(Response.serverError().status(Status.BAD_REQUEST).build());
}
TaxonomyService taxonomyService = CoreSpringFactory.getImpl(TaxonomyService.class);
Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(taxonomyKey));
if (taxonomy == null) {
throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
}
return new TaxonomyWebService(taxonomy);
}
use of org.olat.modules.taxonomy.model.TaxonomyRefImpl in project OpenOLAT by OpenOLAT.
the class DocumentPoolIndexer method doIndex.
@Override
public void doIndex(SearchResourceContext parentResourceContext, Object object, OlatFullIndexer indexerWriter) throws IOException, InterruptedException {
String taxonomyTreeKey = documentPoolModule.getTaxonomyTreeKey();
if (StringHelper.isLong(taxonomyTreeKey)) {
Long taxonomyKey = new Long(taxonomyTreeKey);
Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(taxonomyKey));
OLATResourceable docPoolOres = OresHelper.createOLATResourceableInstanceWithoutCheck(getSupportedTypeName(), 0l);
SearchResourceContext searchResourceContext = new SearchResourceContext(parentResourceContext);
searchResourceContext.setBusinessControlFor(docPoolOres);
searchResourceContext.setTitle(taxonomy.getDisplayName());
searchResourceContext.setDescription(taxonomy.getDescription());
searchResourceContext.setLastModified(taxonomy.getLastModified());
searchResourceContext.setCreatedDate(taxonomy.getCreationDate());
doIndexTaxonomyLibrary(searchResourceContext, taxonomy, indexerWriter);
}
}
Aggregations