-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Design of a Tag/Category capability using generics?
PostPosted: Thu Aug 17, 2006 7:09 am 
Newbie

Joined: Thu Aug 17, 2006 6:41 am
Posts: 3
Location: Sweden
Hi,

I'm looking into creating some classes that can be reused for adding tags/categories to objects. By that I mean something similar to gmails labels, act_as_taggable in RoR, basically assigning one or more tags/categories to a entity/data class.

Now that isn't too hard in a specific case but if there are multiple different annotated data classes that could be tagged (separately, different tags that are not shared among them data classes). It should be possible to make some reusable entity beans/interfaces/super classes for this shouldn't it?

Let's say I have Document, File and Link or similar entity beans. I would like to be able to assign one or more tags/categories to each row/instance of those.

Three Tag-classes, possibly all extending from the same superclass, could easily be used in a manytomany relationship to the specific data class to solve this. But that is not easy/reusable enough I think.

What if the Document entity class implemented a Taggable interface and we have a Tag<T> class?

Something along these lines:

Code:
public interface Tag<T> {

   @Id
   @Column(nullable = false, unique = true)
   public String getName();

   public void setName(String name);

   public String getDescription();

   public void setDescription(String description);

   public String toString();

   @ManyToMany(mappedBy = "tags")
   public Set<T> getTagged();

   public void setTagged(Set<T> tagged);

}

public interface Taggable<T> {

   @ManyToMany
   public Set<Tag<T>> getTags();

   public void setTags(Set<Tag<T>> tags);

}



and then we would have something along these lines:

Code:
@Entity
public class Document implements Serializable, Taggable<Document> {
...


But I need(?) a concrete subclass of Tag to make Hibernate happy I guess.

So we would need to Use DocumentTag etc still right? Even though those are trivial then:

Code:
public class DocumentTag extends AbstractTag<Document> {
}


But I can't wrap my mind around it correctly it seems. Any blatant misunderstandings in the above, pointers, ideas or suggestions?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 8:44 pm 
Newbie

Joined: Wed Aug 23, 2006 10:11 am
Posts: 9
I'm not sure I understand your model. Are there two different sets of tags for each client class (e.g., Document): The set of tags allowed for documents, and then the set of actual tags applied to each document? For example, the fact that Documents can have tags A, B, or C, and then the facts that Document 1 has tags A and B, Document 2 has tag B only, and Document 3 has tags A and C. If so, which are you modeling with your classes?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 25, 2006 3:15 am 
Newbie

Joined: Thu Aug 17, 2006 6:41 am
Posts: 3
Location: Sweden
Thanks for your reply!

Holy Joe wrote:
Are there two different sets of tags for each client class (e.g., Document): The set of tags allowed for documents, and then the set of actual tags applied to each document?


That is indeed one way of looking at it. But the tags need not be a "set of allowed tags" but that's not important I guess. What I mean is that the user can add new tags themselves and/or they might be preexisting tags. That is just an implementation detail though.

Use case scenario:
A user uploads a document. When uploading and/or afterwards the user can add different tags/labels/categories, whatever one would like to call them). For example adding the tags "car" and "racing" to that particular document.

Use case scenario 2:
A user wants to see all documents that have a tag/label/category "car".

The same thing happens if he uploads something else, a picture, a file etc etc. But the different tag sets are separate for different objects (documents and pictures don't share the same tag sets for example) . I was thinking that it might be possible to have a reusabale set of classes and interfaces by using generics.

Reusable in the programming sense, for multiple different projects for example, but also in a given project of course.

Let's say I one day create a web site hosting documents that can be tagged/labeled in the above way. The other day it's the same thing but I'm creating a totally different web site that has a picture upload capability where the users can label/tag the pictures with "humor", "car" etc. Or it might be an added requirement one day to have one of these sites also able to tag the users in the same way but the only relation it has to the previous tag-capability is the pattern. Completely different set of user and/or pre-defined tags.

Maybe it's just quicker to just make them separate for each project and/or object and from scratch. But I was thinking it was a nice idea to basically just add a "Taggable interface" or similar to the obejct that I would like to be able to assign zero or more tags/labels/categories to. Then also notify hibernate of a Tag<Document> subclass, bascially empty. Using generics it seems possible to do and hibernate allows me along way to do it, but I can't get the perfect solution 100% visualized for myself.. yet :) The empty Tag<Document> class extending/implementing Tag<?> for example, is it really necessary? I guess so.

My solution/tries so far got me this:

A Taggable<?> that the object that needs this capabilty has to implement with a specific instance, itself. So a Document class that would like to be able to get Tagged:

Code:
class Document implements Taggable<Document> {
...
}

class DocumentTag extends AbstractTag<Document> {

}

interface Tag<T> {
...
}


class AbstractTag<T> implements Tag<T> {
...
}


And the Taggable and Tag interfaces force them to implement the manytomany relationships get & set methods along with the annotation.

I think there is a mixin or something in Ruby on Rails or a plugin to RoR that does this and it would be nice to be able to do the same.

I would appreciate suggestions/feedback/comments/pointers etc!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 24, 2006 10:59 am 
Newbie

Joined: Fri Nov 24, 2006 10:41 am
Posts: 6
Hi pulsar, are you still interested to this problem?

I am trying to solve the same problem... so if you want we can try to solve it togheter.

Let me know,
bye bye


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 24, 2006 3:02 pm 
Newbie

Joined: Thu Aug 17, 2006 6:41 am
Posts: 3
Location: Sweden
pippo2006 wrote:
Hi pulsar, are you still interested to this problem?

I am trying to solve the same problem... so if you want we can try to solve it togheter.

Let me know,
bye bye


I haven't given this any thought after this, but I would indeed find it interesting.

The ruby/rails/active record inspiration I mentioned would be act_as_taggable module/plugin/whatever it is called. I can recommend reading about it and maybe even try it out.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 27, 2006 7:14 am 
Newbie

Joined: Fri Nov 24, 2006 10:41 am
Posts: 6
Quote:
I haven't given this any thought after this, but I would indeed find it interesting.

The ruby/rails/active record inspiration I mentioned would be act_as_taggable module/plugin/whatever it is called. I can recommend reading about it and maybe even try it out.


Ok pulsar, i will try to read about the Ruby's plugin,

many thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.