Search in sources :

Example 1 with Category

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;
}
Also used : Category(org.olat.modules.portfolio.Category)

Example 2 with Category

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);
        }
    }
}
Also used : Category(org.olat.modules.portfolio.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 3 with Category

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);
    }
}
Also used : Formatter(org.olat.core.util.Formatter) PortfolioService(org.olat.modules.portfolio.PortfolioService) WindowControl(org.olat.core.gui.control.WindowControl) Autowired(org.springframework.beans.factory.annotation.Autowired) Component(org.olat.core.gui.components.Component) Collectors(java.util.stream.Collectors) UserManager(org.olat.user.UserManager) Event(org.olat.core.gui.control.Event) BasicController(org.olat.core.gui.control.controller.BasicController) List(java.util.List) MetadataXStream(org.olat.modules.portfolio.manager.MetadataXStream) Category(org.olat.modules.portfolio.Category) Media(org.olat.modules.portfolio.Media) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) MediaHandler(org.olat.modules.portfolio.MediaHandler) StringHelper(org.olat.core.util.StringHelper) UserRequest(org.olat.core.gui.UserRequest) Category(org.olat.modules.portfolio.Category) MediaHandler(org.olat.modules.portfolio.MediaHandler)

Example 4 with Category

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());
}
Also used : Category(org.olat.modules.portfolio.Category) Test(org.junit.Test)

Example 5 with Category

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));
}
Also used : Category(org.olat.modules.portfolio.Category) OLATResourceable(org.olat.core.id.OLATResourceable) Test(org.junit.Test)

Aggregations

Category (org.olat.modules.portfolio.Category)26 ArrayList (java.util.ArrayList)14 OLATResourceable (org.olat.core.id.OLATResourceable)14 List (java.util.List)12 HashMap (java.util.HashMap)8 Collectors (java.util.stream.Collectors)8 Test (org.junit.Test)8 UserRequest (org.olat.core.gui.UserRequest)8 Component (org.olat.core.gui.components.Component)8 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)8 Event (org.olat.core.gui.control.Event)8 WindowControl (org.olat.core.gui.control.WindowControl)8 Identity (org.olat.core.id.Identity)8 StringHelper (org.olat.core.util.StringHelper)8 Media (org.olat.modules.portfolio.Media)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Map (java.util.Map)6 Set (java.util.Set)6 FormItem (org.olat.core.gui.components.form.flexible.FormItem)6 FormItemContainer (org.olat.core.gui.components.form.flexible.FormItemContainer)6