Commit dbd13f64 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

annotator serialization moved to controller

parent 7ce63914
......@@ -4,7 +4,10 @@ import java.io.Serializable;
import javax.persistence.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.model.user.AnnotatorParamDefinition;
import lcsb.mapviewer.modelutils.serializer.model.user.annotator.AnnotatorConfigParameterSerializer;
/**
* This class defines set of annotators parameters that are used by a user.
......@@ -14,6 +17,7 @@ import lcsb.mapviewer.model.user.AnnotatorParamDefinition;
*/
@Entity
@DiscriminatorValue("CONFIG_PARAMETER")
@JsonSerialize(using = AnnotatorConfigParameterSerializer.class)
public class AnnotatorConfigParameter extends AnnotatorParameter implements Serializable {
/**
......
......@@ -2,7 +2,10 @@ package lcsb.mapviewer.model.user.annotator;
import javax.persistence.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.modelutils.serializer.model.user.annotator.AnnotatorInputParameterSerializer;
/**
* Definition of annotator input. It describes which property/identifier should
......@@ -13,6 +16,7 @@ import lcsb.mapviewer.model.map.MiriamType;
*/
@Entity
@DiscriminatorValue("INPUT_PARAMETER")
@JsonSerialize(using = AnnotatorInputParameterSerializer.class)
public class AnnotatorInputParameter extends AnnotatorParameter {
/**
*
......
......@@ -2,7 +2,10 @@ package lcsb.mapviewer.model.user.annotator;
import javax.persistence.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.modelutils.serializer.model.user.annotator.AnnotatorOutputParameterSerializer;
/**
* Definition of annotator output. It describes which property/identifier should
......@@ -13,6 +16,7 @@ import lcsb.mapviewer.model.map.MiriamType;
*/
@Entity
@DiscriminatorValue("OUTPUT_PARAMETER")
@JsonSerialize(using = AnnotatorOutputParameterSerializer.class)
public class AnnotatorOutputParameter extends AnnotatorParameter {
/**
*
......
package lcsb.mapviewer.modelutils.serializer.model.user.annotator;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lcsb.mapviewer.model.user.annotator.AnnotatorConfigParameter;
public class AnnotatorConfigParameterSerializer extends JsonSerializer<AnnotatorConfigParameter> {
@Override
public void serialize(final AnnotatorConfigParameter configParameter, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeStringField("type", configParameter.getType().name());
gen.writeStringField("name", configParameter.getType().name());
gen.writeStringField("commonName", configParameter.getType().getName());
if (configParameter.getType().getType() != null) {
gen.writeStringField("inputType", configParameter.getType().getType().getName());
}
gen.writeStringField("description", configParameter.getType().getDescription());
gen.writeStringField("value", configParameter.getValue());
gen.writeNumberField("order", configParameter.getOrderPosition());
gen.writeStringField("type", "CONFIG");
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.modelutils.serializer.model.user.annotator;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lcsb.mapviewer.model.user.annotator.AnnotatorInputParameter;
public class AnnotatorInputParameterSerializer extends JsonSerializer<AnnotatorInputParameter> {
@Override
public void serialize(final AnnotatorInputParameter configParameter, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
if (configParameter.getField() != null) {
gen.writeStringField("field", configParameter.getField().name());
}
if (configParameter.getIdentifierType() != null) {
gen.writeStringField("annotation_type", configParameter.getIdentifierType().name());
}
gen.writeNumberField("order", configParameter.getOrderPosition());
gen.writeStringField("type", "INPUT");
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.modelutils.serializer.model.user.annotator;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lcsb.mapviewer.model.user.annotator.AnnotatorOutputParameter;
public class AnnotatorOutputParameterSerializer extends JsonSerializer<AnnotatorOutputParameter> {
@Override
public void serialize(final AnnotatorOutputParameter configParameter, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
if (configParameter.getField() != null) {
gen.writeStringField("field", configParameter.getField().name());
}
if (configParameter.getIdentifierType() != null) {
gen.writeStringField("annotation_type", configParameter.getIdentifierType().name());
}
gen.writeNumberField("order", configParameter.getOrderPosition());
gen.writeStringField("type", "OUTPUT");
gen.writeEndObject();
}
}
\ No newline at end of file
......@@ -429,61 +429,6 @@ public abstract class BaseRestImpl {
this.pubmedParser = pubmedParser;
}
/**
* 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
*/
protected List<Map<String, Object>> prepareAnnotatorsParams(List<AnnotatorParameter> annotatorsParams) {
List<Map<String, Object>> result = new ArrayList<>();
for (AnnotatorParameter param : annotatorsParams) {
Map<String, Object> annotatorParams;
if (param instanceof AnnotatorConfigParameter) {
annotatorParams = prepareConfigParameter((AnnotatorConfigParameter) param);
} else if (param instanceof AnnotatorInputParameter) {
annotatorParams = prepareInputParameter((AnnotatorInputParameter) param);
} else if (param instanceof AnnotatorOutputParameter) {
annotatorParams = prepareOutputParameter((AnnotatorOutputParameter) param);
} else {
throw new NotImplementedException();
}
result.add(annotatorParams);
}
return result;
}
public Map<String, Object> prepareConfigParameter(AnnotatorConfigParameter configParameter) {
Map<String, Object> annotatorParams = new TreeMap<>();
annotatorParams.put("name", configParameter.getType().name());
annotatorParams.put("commonName", configParameter.getType().getName());
annotatorParams.put("inputType", configParameter.getType().getType());
annotatorParams.put("description", configParameter.getType().getDescription());
annotatorParams.put("value", configParameter.getValue());
annotatorParams.put("order", configParameter.getOrderPosition());
annotatorParams.put("type", "CONFIG");
return annotatorParams;
}
public Map<String, Object> prepareInputParameter(AnnotatorInputParameter configParameter) {
Map<String, Object> annotatorParams = new TreeMap<>();
annotatorParams.put("field", configParameter.getField());
annotatorParams.put("annotation_type", configParameter.getIdentifierType());
annotatorParams.put("order", configParameter.getOrderPosition());
annotatorParams.put("type", "INPUT");
return annotatorParams;
}
public Map<String, Object> prepareOutputParameter(AnnotatorOutputParameter configParameter) {
Map<String, Object> annotatorParams = new TreeMap<>();
annotatorParams.put("field", configParameter.getField());
annotatorParams.put("annotation_type", configParameter.getIdentifierType());
annotatorParams.put("order", configParameter.getOrderPosition());
annotatorParams.put("type", "OUTPUT");
return annotatorParams;
}
public String prepareDate(Calendar creationDate) {
if (creationDate == null) {
return null;
......
......@@ -16,6 +16,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.web.bind.annotation.*;
import lcsb.mapviewer.annotation.services.ModelAnnotator;
import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator;
import lcsb.mapviewer.annotation.services.dapi.DapiConnectionException;
import lcsb.mapviewer.annotation.services.dapi.dto.UserDto;
import lcsb.mapviewer.api.BaseController;
......@@ -82,7 +83,7 @@ public class ConfigurationController extends BaseController {
result.put("version", configurationService.getSystemSvnVersion(context.getRealPath("/") + "META-INF/"));
result.put("buildDate", configurationService.getSystemBuild(context.getRealPath("/") + "META-INF/"));
result.put("gitHash", configurationService.getSystemGitVersion(context.getRealPath("/") + "META-INF/"));
result.put("annotators", configurationRestImpl.getAnnotators());
result.put("annotators", getAnnotators());
result.put("bioEntityFields", getBioEntityFields());
return result;
}
......@@ -301,4 +302,23 @@ public class ConfigurationController extends BaseController {
return result;
}
public List<Map<String, Object>> getAnnotators() {
List<Map<String, Object>> result = new ArrayList<>();
for (ElementAnnotator annotator : modelAnnotator.getAvailableAnnotators()) {
result.add(prepareAnnotator(annotator));
}
return result;
}
private Map<String, Object> prepareAnnotator(ElementAnnotator annotator) {
Map<String, Object> result = new TreeMap<>();
result.put("className", annotator.getClass().getName());
result.put("name", annotator.getCommonName());
result.put("description", annotator.getDescription());
result.put("url", annotator.getUrl());
result.put("elementClassNames", annotator.getValidClasses());
result.put("parameters", annotator.createAnnotatorData().getAnnotatorParams());
return result;
}
}
\ No newline at end of file
......@@ -10,27 +10,14 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.annotation.services.ModelAnnotator;
import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator;
import lcsb.mapviewer.annotation.services.dapi.DapiConnectionException;
import lcsb.mapviewer.annotation.services.dapi.DapiConnector;
import lcsb.mapviewer.annotation.services.dapi.dto.ReleaseDto;
import lcsb.mapviewer.annotation.services.dapi.dto.UserDto;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.graphics.MapCanvasType;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.kinetics.SbmlUnitType;
import lcsb.mapviewer.model.map.model.SubmodelType;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.field.ModificationState;
import lcsb.mapviewer.model.overlay.DataOverlayType;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.ConfigurationOption;
import lcsb.mapviewer.model.user.annotator.BioEntityField;
import lcsb.mapviewer.modelutils.map.ClassTreeNode;
import lcsb.mapviewer.modelutils.map.ElementUtils;
import lcsb.mapviewer.services.ObjectExistsException;
import lcsb.mapviewer.services.QueryException;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
......@@ -74,7 +61,6 @@ public class ConfigurationRestImpl extends BaseRestImpl {
this.configurationService = configurationService;
}
public ConfigurationOption updateOption(String option, Map<String, Object> data) throws QueryException {
ConfigurationElementType type = ConfigurationElementType.valueOf(option);
String value = (String) data.get("value");
......@@ -141,23 +127,4 @@ public class ConfigurationRestImpl extends BaseRestImpl {
configurationService.setConfigurationValue(ConfigurationElementType.DAPI_LOGIN, user.getLogin());
configurationService.setConfigurationValue(ConfigurationElementType.DAPI_PASSWORD, user.getPassword());
}
public List<Map<String, Object>> getAnnotators() {
List<Map<String, Object>> result = new ArrayList<>();
for (ElementAnnotator annotator : modelAnnotator.getAvailableAnnotators()) {
result.add(prepareAnnotator(annotator));
}
return result;
}
private Map<String, Object> prepareAnnotator(ElementAnnotator annotator) {
Map<String, Object> result = new TreeMap<>();
result.put("className", annotator.getClass().getName());
result.put("name", annotator.getCommonName());
result.put("description", annotator.getDescription());
result.put("url", annotator.getUrl());
result.put("elementClassNames", annotator.getValidClasses());
result.put("parameters", prepareAnnotatorsParams(annotator.createAnnotatorData().getAnnotatorParams()));
return result;
}
}
......@@ -288,7 +288,7 @@ public class UserRestImpl extends BaseRestImpl {
result.put("annotatorClass", annotatorData.getAnnotatorClassName().getName());
result.put("id", annotatorData.getId());
result.put("order", annotatorData.getOrderIndex());
result.put("parameters", prepareAnnotatorsParams(annotatorData.getAnnotatorParams()));
result.put("parameters", annotatorData.getAnnotatorParams());
return result;
}
......
......@@ -71,16 +71,6 @@ public class BaseRestImplTest extends RestTestFunctions {
assertNotNull(response);
}
@Test
public void testPrepareAnnotatorsParams() throws Exception {
BaseRestImpl controller = Mockito.mock(BaseRestImpl.class, CALLS_REAL_METHODS);
for (ElementAnnotator annotator : annotators) {
AnnotatorData annotatorData = annotator.createAnnotatorData();
List<Map<String, Object>> data = controller.prepareAnnotatorsParams(annotatorData.getAnnotatorParams());
assertEquals(annotatorData.getAnnotatorParams().size(), data.size());
}
}
@Test
public void testCreateAnnotationWithNonNumericValues() throws Exception {
BaseRestImpl controller = Mockito.mock(BaseRestImpl.class, CALLS_REAL_METHODS);
......
......@@ -84,42 +84,6 @@ public class UserRestImplTest extends RestTestFunctions {
assertNotNull(response);
}
@Test
public void testParseInputField() throws Exception {
AnnotatorInputParameter object = userRestImpl.parseInputParameter(
userRestImpl.prepareInputParameter(new AnnotatorInputParameter(BioEntityField.ABBREVIATION)));
assertNotNull(object);
}
@Test
public void testParseInputAnnotation() throws Exception {
AnnotatorInputParameter object = userRestImpl.parseInputParameter(
userRestImpl.prepareInputParameter(new AnnotatorInputParameter(MiriamType.BiGG_COMPARTMENT)));
assertNotNull(object);
}
@Test
public void testParseOutputField() throws Exception {
AnnotatorParameter object = userRestImpl.parseOutputParameter(
userRestImpl.prepareOutputParameter(new AnnotatorOutputParameter(BioEntityField.ABBREVIATION)));
assertNotNull(object);
}
@Test
public void testParseOutputAnnotation() throws Exception {
AnnotatorParameter object = userRestImpl.parseOutputParameter(
userRestImpl.prepareOutputParameter(new AnnotatorOutputParameter(MiriamType.BiGG_COMPARTMENT)));
assertNotNull(object);
}
@Test
public void testParseConfigAnnotation() throws Exception {
AnnotatorParameter object = userRestImpl.parseConfigParameter(
userRestImpl.prepareConfigParameter(
new AnnotatorConfigParameter(AnnotatorParamDefinition.KEGG_ORGANISM_IDENTIFIER, null)));
assertNotNull(object);
}
@Test
public void testPrepareGuiPreferencesSimple() throws Exception {
Map<String, Object> response = userRestImpl.prepareGuiPreferences(new HashSet<>());
......
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