Commit 6224f7fb authored by Piotr Gawron's avatar Piotr Gawron
Browse files

use proper datastructures instead of manually creating json

parent 75f2e09c
......@@ -2,7 +2,14 @@ package lcsb.mapviewer.model.user;
import java.io.Serializable;
import javax.persistence.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
/**
* This class defines GUI preference for the {@link User}.
......@@ -26,7 +33,8 @@ public class UserGuiPreference implements Serializable {
private Integer id;
/**
* {@link UserAnnotationSchema} that defines which user is using this parameter.
* {@link UserAnnotationSchema} that defines which user is using this
* parameter.
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "annotation_schema_id")
......@@ -44,6 +52,15 @@ public class UserGuiPreference implements Serializable {
@Column(nullable = false, length = 255)
private String value;
public UserGuiPreference() {
}
public UserGuiPreference(String key, String value) {
this.key = key;
this.value = value;
}
public UserAnnotationSchema getAnnotationSchema() {
return annotationSchema;
}
......
......@@ -21,7 +21,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -55,6 +54,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lcsb.mapviewer.annotation.services.annotators.UniprotAnnotator;
import lcsb.mapviewer.api.users.UserPreferencesDTO;
import lcsb.mapviewer.api.users.UserRestImpl;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.BioEntity;
......@@ -69,11 +69,15 @@ import lcsb.mapviewer.model.user.AnnotatorParamDefinition;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.ResetPasswordToken;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.model.user.UserAnnotationSchema;
import lcsb.mapviewer.model.user.UserClassAnnotators;
import lcsb.mapviewer.model.user.UserClassRequiredAnnotations;
import lcsb.mapviewer.model.user.UserClassValidAnnotations;
import lcsb.mapviewer.model.user.UserGuiPreference;
import lcsb.mapviewer.model.user.annotator.AnnotatorConfigParameter;
import lcsb.mapviewer.model.user.annotator.AnnotatorData;
import lcsb.mapviewer.model.user.annotator.AnnotatorInputParameter;
import lcsb.mapviewer.model.user.annotator.AnnotatorOutputParameter;
import lcsb.mapviewer.model.user.annotator.AnnotatorParameter;
import lcsb.mapviewer.model.user.annotator.BioEntityField;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.user.ResetPasswordTokenDao;
......@@ -939,17 +943,14 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
public void updateProjectUploadPreferences() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
Map<String, Object> data = new HashMap<>();
Map<String, Object> preferences = new HashMap<>();
data.put("preferences", preferences);
Map<String, Object> uploadPreferences = new HashMap<>();
preferences.put("project-upload", uploadPreferences);
uploadPreferences.put("validate-miriam", true);
uploadPreferences.put("annotate-model", true);
uploadPreferences.put("cache-data", true);
uploadPreferences.put("auto-resize", true);
uploadPreferences.put("semantic-zooming-contains-multiple-overlays", true);
uploadPreferences.put("sbgn", true);
UserAnnotationSchema preferences = new UserAnnotationSchema();
UserPreferencesDTO data = new UserPreferencesDTO(preferences);
preferences.setValidateMiriamTypes(true);
preferences.setAnnotateModel(true);
preferences.setCacheData(true);
preferences.setAutoResizeMap(true);
preferences.setSemanticZoomContainsMultipleOverlays(true);
preferences.setSbgnFormat(true);
RequestBuilder request = patch("/api/users/{login}:updatePreferences", TEST_USER_LOGIN)
.contentType(MediaType.APPLICATION_JSON)
......@@ -971,29 +972,17 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
public void updateElementAnnotatorsPreferences() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
Map<String, Object> data = new HashMap<>();
Map<String, Object> preferences = new HashMap<>();
data.put("preferences", preferences);
Map<String, Object> elementAnnotators = new HashMap<>();
preferences.put("element-annotators", elementAnnotators);
List<Object> annotators = new ArrayList<>();
elementAnnotators.put("lcsb.mapviewer.model.map.species.Gene", annotators);
Map<String, Object> uniprotAnnotator = new HashMap<>();
annotators.add(uniprotAnnotator);
uniprotAnnotator.put("annotatorClass", UniprotAnnotator.class.getCanonicalName());
List<AnnotatorParameter> parameters = new ArrayList<>();
uniprotAnnotator.put("parameters", parameters);
parameters.add(new AnnotatorInputParameter(null, MiriamType.UNIPROT));
parameters.add(new AnnotatorInputParameter(BioEntityField.NAME, MiriamType.UNIPROT));
parameters.add(new AnnotatorOutputParameter(MiriamType.HGNC_SYMBOL));
parameters.add(new AnnotatorOutputParameter(MiriamType.UNIPROT));
parameters.add(new AnnotatorOutputParameter(MiriamType.EC));
parameters.add(new AnnotatorOutputParameter(MiriamType.ENTREZ));
parameters.add(new AnnotatorConfigParameter(AnnotatorParamDefinition.KEGG_ORGANISM_IDENTIFIER, "XXX"));
int order = 0;
for (AnnotatorParameter object : parameters) {
object.setOrderPosition(order++);
}
UserAnnotationSchema preferences = new UserAnnotationSchema();
UserPreferencesDTO data = new UserPreferencesDTO(preferences);
AnnotatorData uniprotAnnotator = new AnnotatorData(UniprotAnnotator.class);
uniprotAnnotator.addAnnotatorParameter(new AnnotatorInputParameter(null, MiriamType.UNIPROT));
uniprotAnnotator.addAnnotatorParameter(new AnnotatorInputParameter(BioEntityField.NAME, MiriamType.UNIPROT));
uniprotAnnotator.addAnnotatorParameter(new AnnotatorOutputParameter(MiriamType.HGNC_SYMBOL));
uniprotAnnotator.addAnnotatorParameter(new AnnotatorOutputParameter(MiriamType.UNIPROT));
uniprotAnnotator.addAnnotatorParameter(new AnnotatorOutputParameter(MiriamType.EC));
uniprotAnnotator.addAnnotatorParameter(new AnnotatorOutputParameter(MiriamType.ENTREZ));
uniprotAnnotator.addAnnotatorParameter(new AnnotatorConfigParameter(AnnotatorParamDefinition.KEGG_ORGANISM_IDENTIFIER, "XXX"));
preferences.addClassAnnotator(new UserClassAnnotators(Gene.class, Arrays.asList(uniprotAnnotator)));
RequestBuilder request = patch("/api/users/{login}:updatePreferences", TEST_USER_LOGIN)
.contentType(MediaType.APPLICATION_JSON)
......@@ -1020,19 +1009,11 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
public void updateElementRequiredAnnotationsPreferences() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
Map<String, Object> data = new HashMap<>();
Map<String, Object> preferences = new HashMap<>();
data.put("preferences", preferences);
Map<String, Object> elementAnnotators = new HashMap<>();
preferences.put("element-required-annotations", elementAnnotators);
Map<String, Object> annotations = new HashMap<>();
elementAnnotators.put(Protein.class.getCanonicalName(), annotations);
annotations.put("require-at-least-one", true);
annotations.put("annotation-list", Arrays.asList(MiriamType.HGNC, MiriamType.HGNC_SYMBOL));
annotations = new HashMap<>();
elementAnnotators.put(SimpleMolecule.class.getCanonicalName(), annotations);
annotations.put("require-at-least-one", false);
annotations.put("annotation-list", Arrays.asList(MiriamType.CHEBI));
UserAnnotationSchema preferences = new UserAnnotationSchema();
UserPreferencesDTO data = new UserPreferencesDTO(preferences);
preferences.addClassRequiredAnnotations(new UserClassRequiredAnnotations(Protein.class, Arrays.asList(MiriamType.HGNC, MiriamType.HGNC_SYMBOL)));
preferences.addClassRequiredAnnotations(new UserClassRequiredAnnotations(SimpleMolecule.class, Arrays.asList(MiriamType.CHEBI)));
preferences.getClassRequiredAnnotators().get(1).setRequireAtLeastOneAnnotation(false);
RequestBuilder request = patch("/api/users/{login}:updatePreferences", TEST_USER_LOGIN)
.contentType(MediaType.APPLICATION_JSON)
......@@ -1055,12 +1036,9 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
public void updateElementValidAnnotationsPreferences() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
Map<String, Object> data = new HashMap<>();
Map<String, Object> preferences = new HashMap<>();
data.put("preferences", preferences);
Map<String, Object> elementAnnotations = new HashMap<>();
preferences.put("element-valid-annotations", elementAnnotations);
elementAnnotations.put(Gene.class.getCanonicalName(), Arrays.asList(MiriamType.HGNC));
UserAnnotationSchema preferences = new UserAnnotationSchema();
UserPreferencesDTO data = new UserPreferencesDTO(preferences);
preferences.addClassValidAnnotations(new UserClassValidAnnotations(Gene.class, Arrays.asList(MiriamType.HGNC)));
RequestBuilder request = patch("/api/users/{login}:updatePreferences", TEST_USER_LOGIN)
.contentType(MediaType.APPLICATION_JSON)
......@@ -1082,12 +1060,9 @@ public class UserControllerIntegrationTest extends ControllerIntegrationTest {
public void updateGuiPreferences() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
Map<String, Object> data = new HashMap<>();
Map<String, Object> preferences = new HashMap<>();
data.put("preferences", preferences);
Map<String, Object> elementAnnotations = new HashMap<>();
preferences.put("gui-preferences", elementAnnotations);
elementAnnotations.put("admin-projects-datatable-order", "1-asc");
UserAnnotationSchema preferences = new UserAnnotationSchema();
UserPreferencesDTO data = new UserPreferencesDTO(preferences);
data.preferences.addGuiPreference(new UserGuiPreference("admin-projects-datatable-order", "1-asc"));
RequestBuilder request = patch("/api/users/{login}:updatePreferences", TEST_USER_LOGIN)
.content(objectMapper.writeValueAsString(data))
......
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