Skip to content
rkboyce edited this page Jul 22, 2013 · 9 revisions

The Post It Model directory contains the classes that encode the annotation and domain model. In the case of the Post it, the model is pretty simple and is defined by two classes: the MPostItAnnotation and the PostitType. The former encodes the model and the latter the allowed types of post it.

Every class modeling annotation need to extend the class MAnnotation. In the case of MPostItAnnotation the model is simple and characterized by two components: a textual description (MContentAsRdf) and a type (PostitType):

public class MPostItAnnotation extends MAnnotation {

	protected static final String LABEL = "Post it";
	public static final String TYPE = "ao:PostIt";
	
	private PostitType type;
	private MContentAsRdf body;
	
	public MContentAsRdf getBody() {
		return body;
	}
	public void setBody(MContentAsRdf body) {
		this.body = body;
	}
	public PostitType getType() {
		return type;
	}
	public void setType(PostitType type) {
		this.type = type;
	}
	public String getText() {
		return body.getChars();
	}
	public void setText(String text) {
		body.setChars(text);
	}
	
	@Override
	public String getLabel() {
		return LABEL;
	}
	
	@Override
	public String getAnnotationType() {
		return TYPE;
	}
}

If we look carefully to the code, we can split it into two sections. The model basic info have to be implemented by contract as consequence of the class extending MAnnotation:

// Textual human readable label of the plugin
protected static final String LABEL = "Post it";
// Type of the plugin
public static final String TYPE = "ao:PostIt";

// Getters
@Override
public String getLabel() {
	return LABEL;
}
	
@Override
public String getAnnotationType() {
	return TYPE;
}

The actual Post It annotation components are the textual content and the type:

	private PostitType type;
	private MContentAsRdf body;
	
	public MContentAsRdf getBody() {
		return body;
	}
	public void setBody(MContentAsRdf body) {
		this.body = body;
	}
	public PostitType getType() {
		return type;
	}
	public void setType(PostitType type) {
		this.type = type;
	}
	public String getText() {
		return body.getChars();
	}
	public void setText(String text) {
		body.setChars(text);
	}

The model of an annotation can be defined as needed. However, we have two recommendations:

  1. when dealing with strings, we recommend the use of the MContentAsRdf model that allows to better detail the textual content with the format.
  2. when dealing with ontological/vocabulary terms, we recommend the use of the MLinkedResource model that allows to specify label, description, synonyms and the source of the term.

Note: If you are interested in understanding more about the choice of using Content As Rdf, see Embedded Content in the Open Annotation Specification

One more thing...

The new annotation class needs to be registered in AnnotationFactory.java so that the factory can create instances. To do this, add the libraries at the top of the file:

import org.mindinformatics.gwt.domeo.plugins.annotation.postit.model.MPostItAnnotation; import org.mindinformatics.gwt.domeo.plugins.annotation.postit.model.PostitType;

...then write a the set of create methods required to managing annotations of this type at an appropriate location within the file:

//  POST ITS -----------------------------------------------------------
// -----------------------------------------------------------------------
public static MPostItAnnotation createPostIt(
		MAnnotationSet set, IAgent creator, ISoftware tool, 
		MGenericResource target, MSelector selector,
		PostitType type, String body) 
{
	MPostItAnnotation ann = new MPostItAnnotation();
	ann.setLocalId(getLocalId());
	ann.setUuid(getUuid());
	ann.setIndividualUri(getUrn(ann.getUuid()));
	ann.setCreator(creator);
	ann.setCreatedOn(new Date());
	ann.setSelector(selector);
	ann.setType(type);
	ann.setBody(createContentAsRdf(body));
	ann.setNewVersion(true);
	ann.setTool(tool);
	return ann;
}
    	
public static MContentAsRdf createContentAsRdf(String text) {
	MContentAsRdf body = new MContentAsRdf();
	body.setIndividualUri(getUuid());
	body.setFormat("text/plain");
	body.setChars(text);
	return body;
}

public static MTargetSelector createTargetSelector(IAgent creator, 
		MGenericResource target) {
	MTargetSelector selector = new MTargetSelector();
	selector.setCreator(creator);
	selector.setCreatedOn(new Date());
	selector.setTarget(target);
	selector.setLocalId(getLocalId());
	selector.setUuid(getUuid());
	selector.setUri(getUrn(selector.getUuid()));
	return selector;
}

public static MTargetSelector cloneTargetSelector(
	String individualUri, MGenericResource target) 
{
	MTargetSelector sel = new MTargetSelector();
	sel.setLocalId(getLocalId());
	sel.setUuid("");
	sel.setUri(individualUri);
	sel.setTarget(target);
	return sel;
}

public static MPostItAnnotation createPostIt(
		MAnnotationSet set, IAgent creator, ISoftware tool, 
		PostitType type, String body) 
{
	MPostItAnnotation ann = new MPostItAnnotation();
	ann.setLocalId(getLocalId());
	ann.setUuid(getUuid());
	ann.setIndividualUri(getUrn(ann.getUuid()));
	ann.setCreator(creator);
	ann.setCreatedOn(new Date());
	ann.setType(type);
	ann.setBody(createContentAsRdf(body));
	ann.setNewVersion(true);
	ann.setTool(tool);
	return ann;
}

public static MPostItAnnotation createPostIt(IDomeo domeo,
		MAnnotationSet set, IAgent creator, ISoftware tool, 
		MGenericResource target, 
		PostitType type, String body) 
{
	MImageInDocumentSelector selector = new MImageInDocumentSelector();
	selector.setCreator(creator);
	selector.setCreatedOn(new Date());
	selector.setTarget(target);
	selector.setLocalId(getLocalId());
	selector.setUuid(getUuid());
	selector.setUri(getUrn(selector.getUuid()));
	selector.setContext(domeo.getAnnotationPersistenceManager().getCurrentResource());
	
	MPostItAnnotation ann = new MPostItAnnotation();
	ann.setLocalId(getLocalId());
	ann.setUuid(getUuid());
	ann.setIndividualUri(getUrn(ann.getUuid()));

	//ann.setTarget(target);
	//ann.setSelector(createTargetSelector(creator, target));
	ann.setSelector(selector);
	ann.setCreator(creator);
	ann.setCreatedOn(new Date());
	ann.setType(type);
	ann.setBody(createContentAsRdf(body));
	ann.setNewVersion(true);
	ann.setTool(tool);
	return ann;
}

public static MPostItAnnotation clonePostIt(
		String individualUri, String lineageUri,
		Date createdOn, Date lastSavedOn, 
		MAnnotationSet set, IAgent creator, ISoftware tool, 
		String versionNumber, String previousVersion,
		MGenericResource target, ArrayList<MSelector> selectors,
		String label, MContentAsRdf body, PostitType type) 
{
	MPostItAnnotation ann = new MPostItAnnotation();
	ann.setLocalId(getLocalId());
	ann.setUuid("");
	ann.setLineageUri(lineageUri);
	ann.setIndividualUri(individualUri);
	ann.setCreator(creator);
	ann.setCreatedOn(createdOn);
	ann.setLastSavedOn(lastSavedOn);
	ann.setVersionNumber(versionNumber);
	ann.setPreviousVersion(previousVersion);
	ann.getSelectors().addAll(selectors);
	ann.setBody(body);
	ann.setType(type);
	ann.setTool(tool);
	ann.setHasChanged(false);
	return ann;
}