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"));
}
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));
}
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());
}
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);
}
}
}
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());
}
Aggregations