Commit 2d4fc5e8 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

ConfigurationDto introduced

parent c3c340b4
Pipeline #46792 passed with stage
in 18 minutes and 53 seconds
package lcsb.mapviewer.modelutils.serializer;
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.modelutils.map.ClassTreeNode;
public class ClassTreeNodeSerializer extends JsonSerializer<ClassTreeNode> {
@Override
public void serialize(final ClassTreeNode node, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeStringField("className", node.getClazz().getName());
gen.writeStringField("name", node.getCommonName());
if (node.getParent() == null) {
gen.writeStringField("parentClass", null);
} else {
gen.writeStringField("parentClass", node.getParent().getClazz().getName());
}
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.api.configuration;
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.common.Pair;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.ImageGenerators;
public class AbstractImageGeneratorSerializer extends JsonSerializer<Class<? extends AbstractImageGenerator>> {
private static final ImageGenerators imageGenerators = new ImageGenerators();
@Override
public void serialize(final Class<? extends AbstractImageGenerator> clazz, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
for (Pair<String, Class<? extends AbstractImageGenerator>> pair: imageGenerators.getAvailableImageGenerators()) {
if (pair.getRight()==clazz) {
gen.writeStringField("name", pair.getLeft());
gen.writeStringField("handler", clazz.getCanonicalName());
gen.writeStringField("extension", imageGenerators.getExtension(clazz.getCanonicalName()));
}
}
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.api.configuration;
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.BioEntityField;
public class BioEntityFieldSerializer extends JsonSerializer<BioEntityField> {
@Override
public void serialize(final BioEntityField type, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeStringField("commonName", type.getCommonName());
gen.writeStringField("name", type.name());
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.api.configuration;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.TreeMap;
import java.util.stream.Collectors;
import javax.servlet.ServletContext;
......@@ -13,10 +19,15 @@ import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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;
......@@ -71,25 +82,25 @@ public class ConfigurationController extends BaseController {
}
@GetMapping(value = "/")
public Map<String, Object> getConfiguration(Authentication authentication) {
Map<String, Object> result = new TreeMap<>();
result.put("options", getOptions(authentication));
result.put("imageFormats", getImageFormats());
result.put("modelFormats", getModelFormats());
result.put("overlayTypes", getOverlayTypes());
result.put("elementTypes", getElementTypes());
result.put("reactionTypes", getReactionTypes());
result.put("miriamTypes", getMiriamTypes());
result.put("mapTypes", getMapTypes());
result.put("mapCanvasTypes", getMapCanvasTypes());
result.put("unitTypes", getUnitTypes());
result.put("modificationStateTypes", getModificationStateTypes());
result.put("privilegeTypes", getPrivilegeTypes());
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", getAnnotators());
result.put("bioEntityFields", getBioEntityFields());
public ConfigurationDto getConfiguration(Authentication authentication) {
ConfigurationDto result = new ConfigurationDto();
result.options = getOptions(authentication);
result.imageFormats = getImageFormats();
result.modelFormats = modelConverters;
result.overlayTypes = DataOverlayType.values();
result.elementTypes = getElementTypes();
result.reactionTypes = getReactionTypes();
result.miriamTypes = getMiriamTypes();
result.mapTypes = SubmodelType.values();
result.mapCanvasTypes = MapCanvasType.values();
result.unitTypes = SbmlUnitType.values();
result.modificationStateTypes = getModificationStateTypes();
result.privilegeTypes = getPrivilegeTypes();
result.version = configurationService.getSystemSvnVersion(context.getRealPath("/") + "META-INF/");
result.buildDate = configurationService.getSystemBuild(context.getRealPath("/") + "META-INF/");
result.gitHash = configurationService.getSystemGitVersion(context.getRealPath("/") + "META-INF/");
result.annotators = modelAnnotator.getAvailableAnnotators();
result.bioEntityFields = BioEntityField.values();
return result;
}
......@@ -185,51 +196,22 @@ public class ConfigurationController extends BaseController {
return configurationService.getValue(type);
}
public List<Map<String, Object>> getImageFormats() {
List<Map<String, Object>> result = new ArrayList<>();
public List<Class<? extends AbstractImageGenerator>> getImageFormats() {
List<Class<? extends AbstractImageGenerator>> result = new ArrayList<>();
ImageGenerators imageGenerators = new ImageGenerators();
List<Pair<String, Class<? extends AbstractImageGenerator>>> imageGeneratorList = imageGenerators
.getAvailableImageGenerators();
for (Pair<String, Class<? extends AbstractImageGenerator>> element : imageGeneratorList) {
Map<String, Object> row = new TreeMap<>();
row.put("name", element.getLeft());
row.put("handler", element.getRight().getCanonicalName());
row.put("extension", imageGenerators.getExtension(element.getRight()));
result.add(row);
}
return result;
}
public List<Map<String, Object>> getModelFormats() {
List<Map<String, Object>> result = new ArrayList<>();
for (Converter converter : modelConverters) {
Map<String, Object> row = new TreeMap<>();
row.put("name", converter.getCommonName());
row.put("handler", converter.getClass().getCanonicalName());
row.put("extension", converter.getFileExtension());
result.add(row);
for (Pair<String, Class<? extends AbstractImageGenerator>> element : imageGenerators.getAvailableImageGenerators()) {
result.add(element.getRight());
}
return result;
}
public List<Map<String, Object>> getOverlayTypes() {
List<Map<String, Object>> result = new ArrayList<>();
for (DataOverlayType type : DataOverlayType.values()) {
Map<String, Object> map = new TreeMap<>();
map.put("name", type.name());
result.add(map);
}
return result;
}
public Set<Map<String, String>> getElementTypes() {
private List<ClassTreeNode> getElementTypes() {
return getClassStringTypesList(Element.class);
}
private Set<Map<String, String>> getClassStringTypesList(Class<?> elementClass) {
Set<Map<String, String>> result = new LinkedHashSet<>();
private List<ClassTreeNode> getClassStringTypesList(Class<?> elementClass) {
List<ClassTreeNode> result = new ArrayList<>();
ElementUtils elementUtils = new ElementUtils();
ClassTreeNode top = elementUtils.getAnnotatedElementClassTree();
Queue<ClassTreeNode> queue = new LinkedList<>();
......@@ -238,138 +220,38 @@ public class ConfigurationController extends BaseController {
ClassTreeNode clazz = queue.poll();
queue.addAll(clazz.getChildren());
if (elementClass.isAssignableFrom(clazz.getClazz())) {
Map<String, String> row = new TreeMap<>();
row.put("className", clazz.getClazz().getName());
row.put("name", clazz.getCommonName());
if (clazz.getParent() == null) {
row.put("parentClass", null);
} else {
row.put("parentClass", clazz.getParent().getClazz().getName());
}
result.add(row);
result.add(clazz);
}
}
return result;
}
public Set<Map<String, String>> getReactionTypes() {
private List<ClassTreeNode> getReactionTypes() {
return getClassStringTypesList(Reaction.class);
}
public Map<String, Object> getMiriamTypes() {
Map<String, Object> result = new TreeMap<>();
private Map<String, MiriamType> getMiriamTypes() {
Map<String, MiriamType> result = new TreeMap<>();
for (MiriamType type : MiriamType.values()) {
result.put(type.name(), createMiriamTypeResponse(type));
result.put(type.name(), type);
}
return result;
}
private Map<String, Object> createMiriamTypeResponse(MiriamType type) {
Map<String, Object> result = new TreeMap<>();
result.put("commonName", type.getCommonName());
result.put("homepage", type.getDbHomepage());
result.put("registryIdentifier", type.getRegistryIdentifier());
result.put("uris", type.getUris());
return result;
}
public Object getModificationStateTypes() {
Map<String, Object> result = new TreeMap<>();
private Map<String, ModificationState> getModificationStateTypes() {
Map<String, ModificationState> result = new TreeMap<>();
for (ModificationState type : ModificationState.values()) {
result.put(type.name(), createModificationStateResponse(type));
result.put(type.name(), type);
}
return result;
}
private Map<String, Object> createModificationStateResponse(ModificationState type) {
Map<String, Object> result = new TreeMap<>();
result.put("commonName", type.getFullName());
result.put("abbreviation", type.getAbbreviation());
return result;
}
public List<Map<String, Object>> getMapTypes() {
List<Map<String, Object>> result = new ArrayList<>();
for (SubmodelType type : SubmodelType.values()) {
Map<String, Object> row = new TreeMap<>();
row.put("id", type.name());
row.put("name", type.getCommonName());
result.add(row);
}
return result;
}
public List<Map<String, Object>> getMapCanvasTypes() {
List<Map<String, Object>> result = new ArrayList<>();
for (MapCanvasType type : MapCanvasType.values()) {
Map<String, Object> row = new TreeMap<>();
row.put("id", type.name());
row.put("name", type.getCommonName());
result.add(row);
}
return result;
}
public List<Map<String, Object>> getUnitTypes() {
List<Map<String, Object>> result = new ArrayList<>();
for (SbmlUnitType type : SbmlUnitType.values()) {
Map<String, Object> row = new TreeMap<>();
row.put("id", type.name());
row.put("name", type.getCommonName());
result.add(row);
}
return result;
}
public List<Map<String, Object>> getBioEntityFields() {
List<Map<String, Object>> result = new ArrayList<>();
for (BioEntityField field : BioEntityField.values()) {
Map<String, Object> entry = new TreeMap<>();
entry.put("name", field.name());
entry.put("commonName", field.getCommonName());
result.add(entry);
}
return result;
}
public Map<String, Object> getPrivilegeTypes() {
Map<String, Object> result = new TreeMap<>();
private Map<String, PrivilegeType> getPrivilegeTypes() {
Map<String, PrivilegeType> result = new TreeMap<>();
for (PrivilegeType type : PrivilegeType.values()) {
result.put(type.name(), createPrivilegeTypeResponse(type));
result.put(type.name(), type);
}
return result;
}
private Map<String, Object> createPrivilegeTypeResponse(PrivilegeType type) {
Map<String, Object> result = new TreeMap<>();
result.put("commonName", type.getDescription());
if (type.getPrivilegeObjectType() != null) {
result.put("objectType", type.getPrivilegeObjectType().getSimpleName());
} else {
result.put("objectType", null);
}
result.put("valueType", "boolean");
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
package lcsb.mapviewer.api.configuration;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lcsb.mapviewer.annotation.services.annotators.ElementAnnotator;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
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.species.field.ModificationState;
import lcsb.mapviewer.model.overlay.DataOverlayType;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.ConfigurationOption;
import lcsb.mapviewer.model.user.annotator.BioEntityField;
import lcsb.mapviewer.modelutils.map.ClassTreeNode;
import lcsb.mapviewer.modelutils.serializer.ClassTreeNodeSerializer;
public class ConfigurationDto {
public List<ConfigurationOption> options;
@JsonSerialize(contentUsing = AbstractImageGeneratorSerializer.class)
public List<Class<? extends AbstractImageGenerator>> imageFormats;
@JsonSerialize(contentUsing = ConverterSerializer.class)
public List<Converter> modelFormats;
@JsonSerialize(contentUsing = DataOverlayTypeSerializer.class)
public DataOverlayType[] overlayTypes;
@JsonSerialize(contentUsing = ClassTreeNodeSerializer.class)
public List<ClassTreeNode> elementTypes;
@JsonSerialize(contentUsing = ClassTreeNodeSerializer.class)
public List<ClassTreeNode> reactionTypes;
@JsonSerialize(contentUsing = MiriamTypeSerializer.class)
public Map<String, MiriamType> miriamTypes;
@JsonSerialize(contentUsing = SubmodelTypeSerializer.class)
public SubmodelType[] mapTypes;
@JsonSerialize(contentUsing = MapCanvasTypeSerializer.class)
public MapCanvasType[] mapCanvasTypes;
@JsonSerialize(contentUsing = SbmlUnitTypeSerializer.class)
public SbmlUnitType[] unitTypes;
@JsonSerialize(contentUsing = ModificationStateSerializer.class)
public Map<String, ModificationState> modificationStateTypes;
@JsonSerialize(contentUsing = PrivilegeTypeSerializer.class)
public Map<String, PrivilegeType> privilegeTypes;
public String version;
public String buildDate;
public String gitHash;
@JsonSerialize(contentUsing = ElementAnnotatorSerializer.class)
public List<ElementAnnotator> annotators;
@JsonSerialize(contentUsing = BioEntityFieldSerializer.class)
public BioEntityField[] bioEntityFields;
}
package lcsb.mapviewer.api.configuration;
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.converter.Converter;
public class ConverterSerializer extends JsonSerializer<Converter> {
@Override
public void serialize(final Converter converter, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeStringField("name", converter.getCommonName());
gen.writeStringField("handler", converter.getClass().getCanonicalName());
gen.writeStringField("extension", converter.getFileExtension());
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.api.configuration;
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.overlay.DataOverlayType;
public class DataOverlayTypeSerializer extends JsonSerializer<DataOverlayType> {
@Override
public void serialize(final DataOverlayType type, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeStringField("name", type.name());
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.api.configuration;
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.annotation.services.annotators.ElementAnnotator;
public class ElementAnnotatorSerializer extends JsonSerializer<ElementAnnotator> {
@Override
public void serialize(final ElementAnnotator annotator, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeStringField("className", annotator.getClass().getName());
gen.writeStringField("name", annotator.getCommonName());
gen.writeStringField("description", annotator.getDescription());
gen.writeStringField("url", annotator.getUrl());
gen.writeObjectField("elementClassNames", annotator.getValidClasses());
gen.writeObjectField("parameters", annotator.createAnnotatorData().getAnnotatorParams());
gen.writeEndObject();
}
}
\ No newline at end of file
package lcsb.mapviewer.api.configuration;
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.graphics.MapCanvasType;
public class MapCanvasTypeSerializer extends JsonSerializer<MapCanvasType> {
@Override
public void serialize(final MapCanvasType type, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeStartObject();
gen.writeStringField("name", type.getCommonName());
gen.writeStringField("id", type.name());
gen.writeEndObject();
}
}
\ No newline at end of file
</
package lcsb.mapviewer.api.configuration;
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.map.MiriamType;
public class MiriamTypeSerializer extends JsonSerializer<MiriamType> {