Search in sources :

Example 6 with Tag

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

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

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

the class TaggingManagerTest method testRetrieveDBTags.

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

Example 8 with Tag

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

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

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

the class EPArtefactManager method setArtefactTags.

protected void setArtefactTags(Identity identity, AbstractArtefact artefact, List<String> tags) {
    if (tags == null)
        return;
    // wrap concrete artefact as abstract-artefact to get the correct resName for the tag
    OLATResourceable artefactOres = OresHelper.createOLATResourceableInstance(AbstractArtefact.class, artefact.getKey());
    List<Tag> oldTags = taggingManager.loadTagsForResource(artefactOres, null, null);
    List<String> oldTagStrings = new ArrayList<String>();
    List<String> tagsToAdd = new ArrayList<String>(tags.size());
    tagsToAdd.addAll(tags);
    if (oldTags != null) {
        // there might be no tags yet
        for (Tag oTag : oldTags) {
            if (tags.contains(oTag.getTag())) {
                // still existing, nothing to do
                oldTagStrings.add(oTag.getTag());
                tagsToAdd.remove(oTag.getTag());
            } else {
                // tag was deleted, remove it
                taggingManager.deleteTag(oTag);
            }
        }
    }
    // look for all given tags, add the ones yet missing
    for (String tag : tagsToAdd) {
        if (StringHelper.containsNonWhitespace(tag)) {
            taggingManager.createAndPersistTag(identity, tag, artefactOres, null, null);
        }
    }
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) Tag(org.olat.core.commons.services.tagging.model.Tag)

Example 10 with Tag

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

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)

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