use of org.olat.modules.portfolio.Category in project OpenOLAT by OpenOLAT.
the class AbstractPageListController method getCategories.
private List<String> getCategories(OLATResourceable ores, Map<OLATResourceable, List<Category>> categorizedElementMap) {
List<String> strings = null;
List<Category> categories = categorizedElementMap.get(ores);
if (categories != null && categories.size() > 0) {
strings = new ArrayList<>(categories.size());
for (Category category : categories) {
strings.add(category.getName());
}
}
return strings;
}
use of org.olat.modules.portfolio.Category in project OpenOLAT by OpenOLAT.
the class PortfolioServiceImpl method updateCategories.
private void updateCategories(OLATResourceable oresource, List<String> categories) {
List<Category> currentCategories = categoryDao.getCategories(oresource);
Map<String, Category> currentCategoryMap = new HashMap<>();
for (Category category : currentCategories) {
currentCategoryMap.put(category.getName(), category);
}
List<String> newCategories = new ArrayList<>(categories);
for (String newCategory : newCategories) {
if (!currentCategoryMap.containsKey(newCategory)) {
Category category = categoryDao.createAndPersistCategory(newCategory);
categoryDao.appendRelation(oresource, category);
}
}
for (Category currentCategory : currentCategories) {
String name = currentCategory.getName();
if (!newCategories.contains(name)) {
categoryDao.removeRelation(oresource, currentCategory);
}
}
}
use of org.olat.modules.portfolio.Category in project OpenOLAT by OpenOLAT.
the class MediaMetadataController method loadMetadata.
private void loadMetadata(VelocityContainer metaVC) {
metaVC.contextPut("media", media);
String author = userManager.getUserDisplayName(media.getAuthor());
metaVC.contextPut("author", author);
MediaHandler handler = portfolioService.getMediaHandler(media.getType());
String type = translate("artefact." + handler.getType());
metaVC.contextPut("mediaType", type);
String iconCssClass = handler.getIconCssClass(media);
if (StringHelper.containsNonWhitespace(iconCssClass)) {
metaVC.contextPut("mediaIconCssClass", iconCssClass);
}
if (media.getCollectionDate() != null) {
String collectionDate = Formatter.getInstance(getLocale()).formatDate(media.getCollectionDate());
metaVC.contextPut("collectionDate", collectionDate);
}
if (StringHelper.containsNonWhitespace(media.getMetadataXml())) {
Object metadata = MetadataXStream.get().fromXML(media.getMetadataXml());
metaVC.contextPut("metadata", metadata);
}
List<Category> categories = portfolioService.getCategories(media);
if (categories != null && categories.size() > 0) {
List<String> categoriesList = categories.stream().map(c -> c.getName()).collect(Collectors.toList());
metaVC.contextPut("categoriesList", categoriesList);
}
}
use of org.olat.modules.portfolio.Category in project OpenOLAT by OpenOLAT.
the class CategoryDAOTest method createCategory.
@Test
public void createCategory() {
Category category = categoryDao.createAndPersistCategory("Swag");
dbInstance.commitAndCloseSession();
Assert.assertNotNull(category);
Assert.assertNotNull(category.getKey());
Assert.assertNotNull(category.getCreationDate());
Assert.assertEquals("Swag", category.getName());
}
use of org.olat.modules.portfolio.Category in project OpenOLAT by OpenOLAT.
the class CategoryDAOTest method createRelationToCategory.
@Test
public void createRelationToCategory() {
Category category = categoryDao.createAndPersistCategory("Cool");
dbInstance.commitAndCloseSession();
// create relation
String rndType = UUID.randomUUID().toString();
OLATResourceable ores = OresHelper.createOLATResourceableInstance(rndType, 234l);
categoryDao.appendRelation(ores, category);
dbInstance.commitAndCloseSession();
// load relation
List<Category> categories = categoryDao.getCategories(ores);
Assert.assertNotNull(categories);
Assert.assertEquals(1, categories.size());
Assert.assertEquals(category, categories.get(0));
}
Aggregations