Search in sources :

Example 1 with TagImpl

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

the class TaggingManagerImpl method createAndPersistTag.

@Override
public Tag createAndPersistTag(Identity author, String tag, OLATResourceable ores, String subPath, String businessPath) {
    if (author == null || !StringHelper.containsNonWhitespace(tag) || ores.getResourceableId() == null || ores.getResourceableTypeName() == null) {
        throw new AssertException("A tag cannot be created and persisted without an author, tag and a valid OlatResourcable");
    }
    if (tag.length() > 128) {
        // truncate
        logWarn("tag was too long, truncated to 128 chars. Original: " + tag, null);
        tag = tag.substring(0, 125) + "...";
    }
    TagImpl t = new TagImpl();
    t.setAuthor(author);
    t.setTag(tag.trim());
    t.setResId(ores.getResourceableId());
    t.setResName(ores.getResourceableTypeName());
    t.setBusinessPath(businessPath);
    t.setResSubPath(subPath);
    dbInstance.saveObject(t);
    return t;
}
Also used : AssertException(org.olat.core.logging.AssertException) TagImpl(org.olat.core.commons.services.tagging.model.TagImpl)

Example 2 with TagImpl

use of org.olat.core.commons.services.tagging.model.TagImpl 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 3 with TagImpl

use of org.olat.core.commons.services.tagging.model.TagImpl 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 4 with TagImpl

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

the class TaggingManagerImpl method createAndPersistTag.

@Override
public Tag createAndPersistTag(Identity author, String tag, OLATResourceable ores, String subPath, String businessPath) {
    if (author == null || !StringHelper.containsNonWhitespace(tag) || ores.getResourceableId() == null || ores.getResourceableTypeName() == null) {
        throw new AssertException("A tag cannot be created and persisted without an author, tag and a valid OlatResourcable");
    }
    if (tag.length() > 128) {
        // truncate
        logWarn("tag was too long, truncated to 128 chars. Original: " + tag, null);
        tag = tag.substring(0, 125) + "...";
    }
    TagImpl t = new TagImpl();
    t.setAuthor(author);
    t.setTag(tag.trim());
    t.setResId(ores.getResourceableId());
    t.setResName(ores.getResourceableTypeName());
    t.setBusinessPath(businessPath);
    t.setResSubPath(subPath);
    dbInstance.saveObject(t);
    return t;
}
Also used : AssertException(org.olat.core.logging.AssertException) TagImpl(org.olat.core.commons.services.tagging.model.TagImpl)

Aggregations

TagImpl (org.olat.core.commons.services.tagging.model.TagImpl)4 Test (org.junit.Test)2 Tag (org.olat.core.commons.services.tagging.model.Tag)2 AssertException (org.olat.core.logging.AssertException)2