use of org.olat.core.commons.services.tagging.model.Tag in project openolat by klemens.
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 klemens.
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());
}
use of org.olat.core.commons.services.tagging.model.Tag in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class SimpleTagProposalManagerTest method testSimpleProposalManager.
@Test
public void testSimpleProposalManager() {
// create some tags to populate the DB
TestOLATResource ores = new TestOLATResource();
Tag tag1 = taggingManager.createAndPersistTag(ident, "Hello", ores, null, null);
Tag tag2 = taggingManager.createAndPersistTag(ident, "world", ores, null, null);
Tag tag3 = taggingManager.createAndPersistTag(ident, "Jupiter", ores, null, null);
dbInstance.commitAndCloseSession();
assertNotNull(tag1);
assertNotNull(tag2);
assertNotNull(tag3);
String text = "Hello world, i'm from Jupiter, especially from Titan. It's a nice world, a little cold, but definitively nice";
List<String> proposedTags = simpleTagProposalManager.proposeTagsForInputText(text, true);
assertNotNull(proposedTags);
assertTrue(2 < proposedTags.size());
assertTrue(proposedTags.contains("Hello"));
assertTrue(proposedTags.contains("world"));
assertTrue(proposedTags.contains("Jupiter"));
}
use of org.olat.core.commons.services.tagging.model.Tag in project openolat by klemens.
the class SimpleTagProposalManagerTest method testSimpleProposalManager.
@Test
public void testSimpleProposalManager() {
// create some tags to populate the DB
TestOLATResource ores = new TestOLATResource();
Tag tag1 = taggingManager.createAndPersistTag(ident, "Hello", ores, null, null);
Tag tag2 = taggingManager.createAndPersistTag(ident, "world", ores, null, null);
Tag tag3 = taggingManager.createAndPersistTag(ident, "Jupiter", ores, null, null);
dbInstance.commitAndCloseSession();
assertNotNull(tag1);
assertNotNull(tag2);
assertNotNull(tag3);
String text = "Hello world, i'm from Jupiter, especially from Titan. It's a nice world, a little cold, but definitively nice";
List<String> proposedTags = simpleTagProposalManager.proposeTagsForInputText(text, true);
assertNotNull(proposedTags);
assertTrue(2 < proposedTags.size());
assertTrue(proposedTags.contains("Hello"));
assertTrue(proposedTags.contains("world"));
assertTrue(proposedTags.contains("Jupiter"));
}
Aggregations