Commit 6cb66510 authored by David Hoksza's avatar David Hoksza
Browse files

Working version of annotators parametrization

parent a51471d9
......@@ -30,7 +30,6 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
......
......@@ -73,6 +73,14 @@ public class KeggAnnotator extends ElementAnnotator implements IExternalService
+ " (GENE section in the KEGG enzyme record) should be imported."
+ " Currently ATH (Arabidopsis Thaliana) is supported.");
this.addParameterDefinition(paramDef);
this.addParameterDefinition(new AnnotatorParamDefinition("test string1", String.class, "test string1 comment"));
this.addParameterDefinition(new AnnotatorParamDefinition("test int1", Integer.class, "int1 comment"));
this.addParameterDefinition(new AnnotatorParamDefinition("test bool1", Boolean.class, "boolean comment"));
this.addParameterDefinition(new AnnotatorParamDefinition("test bool2", Boolean.class, "boolean comment 2"));
this.addParameterDefinition(new AnnotatorParamDefinition("test int2", Integer.class, "int2 comment"));
this.addParameterDefinition(new AnnotatorParamDefinition("test int3", Integer.class, "int3 comment"));
this.addParameterDefinition(new AnnotatorParamDefinition("test string2", String.class, "test string2 comment"));
}
@Override
......@@ -112,16 +120,6 @@ public class KeggAnnotator extends ElementAnnotator implements IExternalService
return status;
}
//private Boolean resourceInCollection(String resource, Collection<MiriamData> list) {
//
// for (MiriamData md: list) {
// if (md.getResource() == resource) {
// return true;
// }
//
// }
// return false;
//}
@Override
public void annotateElement(BioEntity object) throws AnnotatorException {
......
......@@ -57,18 +57,18 @@ ChooseAnnotatorsDialog.prototype.createGui = function () {
self.getElement().appendChild(content);
};
function onChangeParameterValue(element, user){
var value = element;
function onChangeParameterValue(element, user){
var name = $(element).siblings(".minerva-annotator-param-name").text();
var annotatorClassName = $(element).parent().parent().attr('name');
var data = new UserPreferences();
var annotatorsParams = {};
annotatorsParams[annotatorClassName] = {name: value};
annotatorsParams[annotatorClassName] = {};
annotatorsParams[annotatorClassName][name] = element.value;
data.setAnnotatorsParameters(annotatorsParams);
return ServerConnector.updateUserPreferences({user: user, preferences: data}).then(null, GuiConnector.alert);
return ServerConnector.updateUserPreferences({user: user, preferences: data}).then(null, GuiConnector.alert);
}
ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
......@@ -93,6 +93,7 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
var annotators = configuration.getElementAnnotators(elementType);
var selectedAnnotators = user.getPreferences().getElementAnnotators(elementType.className);
var existingAnnotatorsParameters = user.getPreferences().getAnnotatorsParameters();
for (var i = 0; i < annotators.length; i++) {
var annotator = annotators[i];
......@@ -103,6 +104,7 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
var paramsDefs = annotator.getParametersDefinitions();
if (paramsDefs.length > 0) {
annotatorsParams.appendChild(Functions.createElement({
type: "div",
className: "minerva-annotators-params-header",
......@@ -122,7 +124,7 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
}));
for (var k = 0; k < paramsDefs.length; k++) {
var param = paramsDefs[k];
var param = paramsDefs[k];
var paramElement = Functions.createElement({
type: "div",
className: "minerva-annotator-param"
......@@ -135,11 +137,20 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
}));
var paramValue;
var existingParamValue;
if (existingAnnotatorsParameters[annotator.getClassName()]) {
existingParamValue = existingAnnotatorsParameters[annotator.getClassName()][param.name]
}
console.log('existingParamValue', existingParamValue);
if (param.type.indexOf("String") >= 0) {
paramValue = Functions.createElement({
type: "textarea",
onchange: function(){return onChangeParameterValue(this, user);}
});
if (existingParamValue) paramValue.value = existingParamValue;
} else if (param.type.indexOf("Integer") >= 0) {
paramValue = Functions.createElement({
type: "input",
......@@ -157,7 +168,7 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
}
paramElement.appendChild(paramValue);
annotatorParams.appendChild(paramElement);
annotatorParams.appendChild(paramElement);
}
annotatorsParams.appendChild(annotatorParams);
......
......@@ -91,6 +91,14 @@ public class UserAnnotationSchema implements Serializable {
@OneToMany(mappedBy = "annotationSchema")
@OrderBy("id")
private List<UserClassAnnotators> classAnnotators = new ArrayList<>();
/**
* List of class annotators params.
*/
@Cascade({ CascadeType.ALL })
@OneToMany(mappedBy = "annotationSchema")
@OrderBy("id")
private List<UserAnnotatorsParams> annotatorsParams = new ArrayList<>();
/**
* List of valid annotations for given object type.
......@@ -158,6 +166,21 @@ public class UserAnnotationSchema implements Serializable {
public void setClassAnnotators(List<UserClassAnnotators> classAnnotators) {
this.classAnnotators = classAnnotators;
}
/**
* @return the annotatorsParams
*/
public List<UserAnnotatorsParams> getAnnotatorsParams() {
return annotatorsParams;
}
/**
* @param annotatorsParams
* the annotatorsParams to set
*/
public void setAnnotatorsParams(List<UserAnnotatorsParams> annotatorsParams) {
this.annotatorsParams = annotatorsParams;
}
/**
* @return the classValidAnnotators
......@@ -201,6 +224,42 @@ public class UserAnnotationSchema implements Serializable {
}
ca.setAnnotationSchema(this);
}
/**
* Adds (or updates) {@link UserAnnotatorsParams} information
* to {@link #annotatorsParams}.
*
* @param ap
* object to add/update
*/
public void addAnnotatorParam(UserAnnotatorsParams ap) {
if (ap.getAnnotatorClassName() == null) {
throw new InvalidArgumentException("Class name cannot be null");
}
if (ap.getParamName() == null) {
throw new InvalidArgumentException("Parameter name cannot be null");
}
if (ap.getParamValue() == null) {
throw new InvalidArgumentException("Parameter value cannot be null");
}
for (int i = 0; i < this.annotatorsParams.size(); i++) {
UserAnnotatorsParams params = this.annotatorsParams.get(i);
if (params.getAnnotatorClassName().equals(ap.getAnnotatorClassName()) &&
params.getParamName().equals(ap.getParamName())) {
this.annotatorsParams.get(i).setParamValue(ap.getParamValue());
} else {
ap.setAnnotationSchema(this);
this.annotatorsParams.add(ap);
}
}
if (this.annotatorsParams.size() == 0) {
ap.setAnnotationSchema(this);
this.annotatorsParams.add(ap);
}
}
/**
* Adds (or updates) {@link UserClassValidAnnotations valid annotation}
......
package lcsb.mapviewer.model.user;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
/**
* This class defines set of annotators parameters that are used by a user.
*
* @author David Hoksza
*
*/
@Entity
@Table(name = "annotators_params_table")
public class UserAnnotatorsParams implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Unique identifier in the database.
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idDb", unique = true, nullable = false)
private Integer id;
/**
* {@link UserAnnotationSchema} that defines which user is using this set of
* annotators.
*/
@ManyToOne
private UserAnnotationSchema annotationSchema;
/**
* Classname of the annotator {@link #paramName parameter} of which is being set to the {@link #paramValue value}.
*/
@Column(name = "annotator_classname", nullable = false)
private Class<?> annotatorClassName;
/**
* Parameter name to be set.
*/
@Column(name = "name", nullable = false)
private String paramName;
/**
* Parameter value to be set.
*/
@Column(name = "value", nullable = false)
private String paramValue;
/**
* Default constructor.
*/
public UserAnnotatorsParams() {
}
/**
* Default constructor.
*
* @param objectClass
* {@link #className}
* @param annotators
* {@link #annotators}
*/
public UserAnnotatorsParams(Class<?> annotatorClassName, String paramName, String paramValue) {
setAnnotatorClassName(annotatorClassName);
setParamName(paramName);
setParamValue(paramValue);
}
/**
* @return the id
* @see #id
*/
public Integer getId() {
return id;
}
/**
* @param id
* the id to set
* @see #id
*/
public void setId(Integer id) {
this.id = id;
}
/**
* @return the annotationSchema
* @see #annotationSchema
*/
public UserAnnotationSchema getAnnotationSchema() {
return annotationSchema;
}
/**
* @param annotationSchema
* the annotationSchema to set
* @see #annotationSchema
*/
public void setAnnotationSchema(UserAnnotationSchema annotationSchema) {
this.annotationSchema = annotationSchema;
}
/**
* @return the className
* @see #className
*/
public Class<?> getAnnotatorClassName() {
return annotatorClassName;
}
/**
* @param className
* the className to set
* @see #className
*/
public void setAnnotatorClassName(Class<?> annotatorClassName) {
this.annotatorClassName = annotatorClassName;
}
/**
* @return the parameter name
* @see #paramName
*/
public String getParamName() {
return paramName;
}
/**
* @param paramName
* the {@link UserAnnotatorsParams#paramName} to set
*/
public void setParamName(String paramName) {
this.paramName = paramName;
}
/**
* @return the parameter value
* @see #paramValue
*/
public String getParamValue() {
return paramValue;
}
/**
* @param parameter value
* the {@link UserAnnotatorsParams#paramValue} to set
*/
public void setParamValue(String paramValue) {
this.paramValue = paramValue;
}
}
DELETE FROM cache_type WHERE classname = 'lcsb.mapviewer.annotation.services.annotators.KeggAnnotator';
INSERT INTO cache_type(validity, classname) VALUES (365, 'lcsb.mapviewer.annotation.services.annotators.KeggAnnotator');
UPDATE class_annotator_annotators_table SET annotator_name = 'TAIR' WHERE annotator_name = 'TAIR Locus'
CREATE SEQUENCE annotators_params_table_iddb_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
CREATE TABLE annotators_params_table
(
iddb integer NOT NULL DEFAULT nextval('annotators_params_table_iddb_seq'::regclass),
annotationschema_iddb integer,
annotator_classname character varying(255) NOT NULL,
name character varying(255) NOT NULL,
value character varying(255) NOT NULL,
CONSTRAINT annotators_params_pkey PRIMARY KEY (iddb),
CONSTRAINT annotators_params_user_annotation_schema_fk FOREIGN KEY (annotationschema_iddb)
REFERENCES user_annotation_schema_table (iddb) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
\ No newline at end of file
......@@ -85,8 +85,9 @@
<value>lcsb.mapviewer.model.user.Configuration</value>
<value>lcsb.mapviewer.model.user.ObjectPrivilege</value>
<value>lcsb.mapviewer.model.user.User</value>
<value>lcsb.mapviewer.model.user.UserAnnotatorsParams</value>
<value>lcsb.mapviewer.model.user.UserAnnotationSchema</value>
<value>lcsb.mapviewer.model.user.UserClassAnnotators</value>
<value>lcsb.mapviewer.model.user.UserClassAnnotators</value>
<value>lcsb.mapviewer.model.user.UserClassValidAnnotations</value>
<value>lcsb.mapviewer.model.user.UserClassRequiredAnnotations</value>
......
......@@ -23,6 +23,7 @@ import lcsb.mapviewer.model.user.ObjectPrivilege;
import lcsb.mapviewer.model.user.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.model.user.UserAnnotationSchema;
import lcsb.mapviewer.model.user.UserAnnotatorsParams;
import lcsb.mapviewer.model.user.UserClassAnnotators;
import lcsb.mapviewer.model.user.UserClassRequiredAnnotations;
import lcsb.mapviewer.model.user.UserClassValidAnnotations;
......@@ -133,8 +134,29 @@ public class UserRestImpl extends BaseRestImpl {
result.put("element-annotators", prepareElementAnnotators(schema.getClassAnnotators()));
result.put("element-required-annotations", prepareRequiredAnnotations(schema.getClassRequiredAnnotators()));
result.put("element-valid-annotations", prepareValidAnnotations(schema.getClassValidAnnotators()));
result.put("annotators-parameters", prepareAnnotatorsParams(schema.getAnnotatorsParams()));
return result;
}
/**
* Prepares annotator parameters in the form of a map having annotators
* class names as keys and map of name:value pairs of given annotator as values.
* @param annotatorsParams
* @return
*/
private Map<String, Object> prepareAnnotatorsParams(List<UserAnnotatorsParams> annotatorsParams) {
Map<String, Object> result = new HashMap<>();
for (UserAnnotatorsParams param : annotatorsParams) {
String className = param.getAnnotatorClassName().getName();
Map<String, String> annotatorParams = (Map<String, String>)result.get(className);
if (annotatorParams == null) {
annotatorParams = new HashMap<>();
result.put(className, annotatorParams);
}
annotatorParams.put(param.getParamName(), param.getParamValue());
}
return result;
}
private Map<String, Object> prepareValidAnnotations(List<UserClassValidAnnotations> classValidAnnotators) {
Map<String, Object> result = new HashMap<>();
......@@ -164,8 +186,19 @@ public class UserRestImpl extends BaseRestImpl {
}
}
private void updateAnnotatorsParams(UserAnnotationSchema schema, Map<String, Object> data) {
private void updateAnnotatorsParams(UserAnnotationSchema schema, Map<String, Object> data) throws QueryException {
for (String annotatorClassname : data.keySet()) {
Map<String, Object> nameValueS = (Map<String, Object>)data.get(annotatorClassname);
for (String name: nameValueS.keySet()) {
String value = (String)nameValueS.get(name);
try {
UserAnnotatorsParams param = new UserAnnotatorsParams(Class.forName(annotatorClassname), name, value);
schema.addAnnotatorParam(param);
} catch (ClassNotFoundException e) {
throw new QueryException("Unknown annotator class name: " + annotatorClassname);
}
}
}
}
private Map<String, Object> prepareRequiredAnnotations(List<UserClassRequiredAnnotations> classRequiredAnnotators) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment