Search in sources :

Example 1 with Tag

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

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 2 with Tag

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

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)

Example 3 with Tag

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

the class TaggingManagerTest method testSetTag.

@Test
public void testSetTag() {
    TestOLATResource ores = new TestOLATResource(45l, "Artefact");
    Tag tag = taggingManager.createAndPersistTag(ident1, "Tag1", ores, "SubPath", "BusinessPath");
    dbInstance.commitAndCloseSession();
    assertNotNull(tag);
    assertEquals("Tag1", tag.getTag());
    assertNotNull(tag.getOLATResourceable());
    assertEquals(new Long(45l), tag.getOLATResourceable().getResourceableId());
    assertEquals("Artefact", tag.getOLATResourceable().getResourceableTypeName());
    assertEquals("SubPath", tag.getResSubPath());
    assertEquals("BusinessPath", tag.getBusinessPath());
}
Also used : Tag(org.olat.core.commons.services.tagging.model.Tag) Test(org.junit.Test)

Example 4 with Tag

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

the class TaggingManagerTest method testDeleteTag.

@Test
public void testDeleteTag() {
    String uuid = UUID.randomUUID().toString();
    TestOLATResource ores = new TestOLATResource(49l, uuid);
    Tag tag1 = taggingManager.createAndPersistTag(ident1, "TagDelete1", ores, null, null);
    Tag tag2 = taggingManager.createAndPersistTag(ident1, "TagDelete2", ores, null, null);
    dbInstance.commitAndCloseSession();
    assertNotNull(tag1);
    assertNotNull(tag2);
    List<Tag> tagsToDelete = taggingManager.loadTagsForResource(ores, null, null);
    assertNotNull(tagsToDelete);
    assertEquals(2, tagsToDelete.size());
    taggingManager.deleteTag(tagsToDelete.get(0));
    taggingManager.deleteTag(tagsToDelete.get(1));
    dbInstance.commitAndCloseSession();
    List<Tag> deletedTags = taggingManager.loadTagsForResource(ores, null, null);
    assertNotNull(deletedTags);
    assertEquals(0, deletedTags.size());
}
Also used : Tag(org.olat.core.commons.services.tagging.model.Tag) Test(org.junit.Test)

Example 5 with Tag

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

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)

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