Search in sources :

Example 16 with Tag

use of org.olat.core.commons.services.tagging.model.Tag in project openolat by klemens.

the class TaggingManagerTest method testUpdateTag.

@Test
public void testUpdateTag() {
    String uuid = UUID.randomUUID().toString();
    TestOLATResource ores = new TestOLATResource(48l, uuid);
    Tag tag1 = taggingManager.createAndPersistTag(ident1, "TagUpdate1", ores, null, null);
    Tag tag2 = taggingManager.createAndPersistTag(ident1, "TagUpdate2", ores, null, null);
    dbInstance.commitAndCloseSession();
    assertNotNull(tag1);
    assertNotNull(tag2);
    List<Tag> tags = taggingManager.loadTagsForResource(ores, null, null);
    assertNotNull(tags);
    assertEquals(2, tags.size());
    ((TagImpl) tags.get(0)).setTag("TagUpdated1");
    taggingManager.updateTag(tags.get(0));
    ((TagImpl) tags.get(1)).setTag("TagUpdated2");
    taggingManager.updateTag(tags.get(1));
    dbInstance.commitAndCloseSession();
    List<Tag> updatedTags = taggingManager.loadTagsForResource(ores, null, null);
    assertNotNull(updatedTags);
    assertEquals(2, updatedTags.size());
    assertTrue(updatedTags.get(0).getTag().equals("TagUpdated1") || updatedTags.get(1).getTag().equals("TagUpdated1"));
    assertTrue(updatedTags.get(0).getTag().equals("TagUpdated2") || updatedTags.get(1).getTag().equals("TagUpdated2"));
}
Also used : TagImpl(org.olat.core.commons.services.tagging.model.TagImpl) Tag(org.olat.core.commons.services.tagging.model.Tag) Test(org.junit.Test)

Example 17 with Tag

use of org.olat.core.commons.services.tagging.model.Tag in project openolat by klemens.

the class TaggingManagerTest method testDeleteAllTag.

@Test
public void testDeleteAllTag() {
    String uuid = UUID.randomUUID().toString();
    TestOLATResource ores = new TestOLATResource(49l, uuid);
    Tag tag1 = taggingManager.createAndPersistTag(ident1, "TagDelete1", ores, "subPath1", null);
    Tag tag2 = taggingManager.createAndPersistTag(ident1, "TagDelete2", ores, "subPath2", null);
    Tag tag3 = taggingManager.createAndPersistTag(ident1, "TagDelete3", ores, "subPath3", "businessPath45");
    Tag tag4 = taggingManager.createAndPersistTag(ident1, "TagDelete3", ores, "subPath3", null);
    Tag tag5 = taggingManager.createAndPersistTag(ident1, "TagDelete4", ores, "subPath1", null);
    TestOLATResource oresMark = new TestOLATResource(50l, uuid);
    Tag tag6 = taggingManager.createAndPersistTag(ident1, "TagDelete1", oresMark, "subPath1", null);
    dbInstance.commitAndCloseSession();
    assertNotNull(tag1);
    assertNotNull(tag2);
    assertNotNull(tag3);
    assertNotNull(tag4);
    assertNotNull(tag5);
    assertNotNull(tag6);
    taggingManager.deleteTags(ores, "subPath1", null);
    dbInstance.commitAndCloseSession();
    List<Tag> deletedTags = taggingManager.loadTagsForResource(ores, null, null);
    assertNotNull(deletedTags);
    assertEquals(3, deletedTags.size());
    // remove an other one
    taggingManager.deleteTags(ores, "subPath3", "businessPath45");
    dbInstance.commitAndCloseSession();
    List<Tag> deletedTags2 = taggingManager.loadTagsForResource(ores, null, null);
    assertNotNull(deletedTags2);
    assertEquals(2, deletedTags2.size());
    // remove all tags of the resource
    taggingManager.deleteTags(ores, null, null);
    dbInstance.commitAndCloseSession();
    List<Tag> deletedTags3 = taggingManager.loadTagsForResource(ores, null, null);
    assertNotNull(deletedTags3);
    assertEquals(0, deletedTags3.size());
    // check that not all tags are deleted
    List<Tag> tagMark = taggingManager.loadTagsForResource(oresMark, null, null);
    assertNotNull(tagMark);
    assertEquals(1, tagMark.size());
}
Also used : Tag(org.olat.core.commons.services.tagging.model.Tag) Test(org.junit.Test)

Example 18 with Tag

use of org.olat.core.commons.services.tagging.model.Tag in project openolat by klemens.

the class TaggingManagerTest method testRetrieveTags.

@Test
public void testRetrieveTags() {
    String uuid = UUID.randomUUID().toString();
    TestOLATResource ores = new TestOLATResource(47l, uuid);
    Tag tag1 = taggingManager.createAndPersistTag(ident1, "TagGroup1", ores, null, null);
    Tag tag2 = taggingManager.createAndPersistTag(ident1, "TagGroup2", ores, null, null);
    Tag tag3 = taggingManager.createAndPersistTag(ident2, "TagGroup2", ores, null, null);
    Tag tag4 = taggingManager.createAndPersistTag(ident3, "TagGroup2", ores, null, null);
    dbInstance.commitAndCloseSession();
    assertNotNull(tag1);
    assertNotNull(tag2);
    assertNotNull(tag3);
    assertNotNull(tag4);
    List<String> tags = taggingManager.getTagsAsString(ident1, ores, null, null);
    assertNotNull(tags);
    assertEquals(2, tags.size());
    assertTrue(tags.contains("TagGroup1"));
    assertTrue(tags.contains("TagGroup2"));
}
Also used : Tag(org.olat.core.commons.services.tagging.model.Tag) Test(org.junit.Test)

Example 19 with Tag

use of org.olat.core.commons.services.tagging.model.Tag in project openolat by klemens.

the class TaggingManagerImpl method loadTagsForResource.

@Override
public List<Tag> loadTagsForResource(OLATResourceable ores, String subPath, String businessPath) {
    if (ores.getResourceableId() == null)
        return null;
    StringBuilder sb = new StringBuilder();
    sb.append("select tag from ").append(TagImpl.class.getName()).append(" tag where tag.resId=:resId and tag.resName=:resName");
    if (subPath != null) {
        sb.append(" and tag.subPath=:subPath");
    }
    if (businessPath != null) {
        sb.append(" and tag.businessPath=:businessPath");
    }
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setLong("resId", ores.getResourceableId());
    query.setString("resName", ores.getResourceableTypeName());
    if (subPath != null) {
        query.setString("subPath", subPath);
    }
    if (businessPath != null) {
        query.setString("businessPath", businessPath);
    }
    @SuppressWarnings("unchecked") List<Tag> tags = query.list();
    return tags;
}
Also used : DBQuery(org.olat.core.commons.persistence.DBQuery) Tag(org.olat.core.commons.services.tagging.model.Tag)

Example 20 with Tag

use of org.olat.core.commons.services.tagging.model.Tag in project openolat by klemens.

the class TaggingManagerImpl method getResourcesByTags.

@Override
public HashSet<OLATResourceable> getResourcesByTags(List<Tag> tagList) {
    if (tagList == null || tagList.size() == 0)
        return null;
    StringBuilder sb = new StringBuilder();
    sb.append("select tag from ").append(TagImpl.class.getName()).append(" tag where tag in ( :tagList )");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setParameterList("tagList", tagList);
    @SuppressWarnings("unchecked") List<Tag> resList = query.list();
    HashSet<OLATResourceable> oresList = new HashSet<OLATResourceable>();
    for (Iterator<Tag> iterator = resList.iterator(); iterator.hasNext(); ) {
        Tag tag = iterator.next();
        OLATResourceable ores = tag.getOLATResourceable();
        oresList.add(ores);
    }
    return oresList;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) DBQuery(org.olat.core.commons.persistence.DBQuery) Tag(org.olat.core.commons.services.tagging.model.Tag) HashSet(java.util.HashSet)

Aggregations

Tag (org.olat.core.commons.services.tagging.model.Tag)20 Test (org.junit.Test)14 DBQuery (org.olat.core.commons.persistence.DBQuery)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TagImpl (org.olat.core.commons.services.tagging.model.TagImpl)2