diff --git a/annotation/.classpath b/annotation/.classpath index 71a86ecfe6e0f3ee403397c37963606b5852c085..fae1a2b37d5e3386c9651caedb78b9bd107715bd 100644 --- a/annotation/.classpath +++ b/annotation/.classpath @@ -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"/> diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/KeggAnnotator.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/KeggAnnotator.java index d02dab68420999703a8bf06da4fb3df3754883a1..95f7c6be70dd753e142dbbfa1108596251446ded 100644 --- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/KeggAnnotator.java +++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/annotators/KeggAnnotator.java @@ -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 { diff --git a/frontend-js/src/main/js/gui/admin/ChooseAnnotatorsDialog.js b/frontend-js/src/main/js/gui/admin/ChooseAnnotatorsDialog.js index 322d356fffb6be4bd58920298e40692410da5ed2..b5c8cd956340fb6f24b2118cefc06eb3aa602dd9 100644 --- a/frontend-js/src/main/js/gui/admin/ChooseAnnotatorsDialog.js +++ b/frontend-js/src/main/js/gui/admin/ChooseAnnotatorsDialog.js @@ -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); diff --git a/model/src/main/java/lcsb/mapviewer/model/user/UserAnnotationSchema.java b/model/src/main/java/lcsb/mapviewer/model/user/UserAnnotationSchema.java index 2e919ca9930498c3eae0de35228e854c58ec84cf..e892d82d38466dbc33b1089f8934921fbe173f71 100644 --- a/model/src/main/java/lcsb/mapviewer/model/user/UserAnnotationSchema.java +++ b/model/src/main/java/lcsb/mapviewer/model/user/UserAnnotationSchema.java @@ -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} diff --git a/model/src/main/java/lcsb/mapviewer/model/user/UserAnnotatorsParams.java b/model/src/main/java/lcsb/mapviewer/model/user/UserAnnotatorsParams.java new file mode 100644 index 0000000000000000000000000000000000000000..36822aaafc57918c2f5cead97fffdefe634798fc --- /dev/null +++ b/model/src/main/java/lcsb/mapviewer/model/user/UserAnnotatorsParams.java @@ -0,0 +1,166 @@ +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; + } +} diff --git a/persist/src/db/12.0.0/fix_db_20180125.sql b/persist/src/db/12.0.0/fix_db_20180125.sql index dcc8ee57e39e438781ef7a05e2633d6774345537..9be36abf2fdb54f2a6d8aaea885d9c0af10fa4ee 100644 --- a/persist/src/db/12.0.0/fix_db_20180125.sql +++ b/persist/src/db/12.0.0/fix_db_20180125.sql @@ -1,3 +1,5 @@ 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' + diff --git a/persist/src/db/12.0.0/fix_db_20180126.sql b/persist/src/db/12.0.0/fix_db_20180126.sql new file mode 100644 index 0000000000000000000000000000000000000000..1c227560daf96ef5325474e27cc5007e8b7f1b6d --- /dev/null +++ b/persist/src/db/12.0.0/fix_db_20180126.sql @@ -0,0 +1,19 @@ +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 diff --git a/persist/src/main/resources/applicationContext-persist.xml b/persist/src/main/resources/applicationContext-persist.xml index 718f752f950dbf2dd1f2886e95842d24a54e4b5c..a4c758484060b50253fa9d42cfbed876dcacb874 100644 --- a/persist/src/main/resources/applicationContext-persist.xml +++ b/persist/src/main/resources/applicationContext-persist.xml @@ -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> diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/users/UserRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/users/UserRestImpl.java index 0dd97ad5f6c08a59e50694a418a6e7c4630bc6b6..c105de496996c1cc7beb497a6120d635e745d5b8 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/users/UserRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/users/UserRestImpl.java @@ -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) {