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

CalendarSerializer implemented

parent 2c77b592
package lcsb.mapviewer.model.map.model;
import java.io.Serializable;
import java.util.*;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
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.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlTransient;
import org.apache.logging.log4j.LogManager;
......@@ -16,7 +36,9 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.kinetics.*;
import lcsb.mapviewer.model.map.kinetics.SbmlFunction;
import lcsb.mapviewer.model.map.kinetics.SbmlParameter;
import lcsb.mapviewer.model.map.kinetics.SbmlUnit;
import lcsb.mapviewer.model.map.layout.BlockDiagram;
import lcsb.mapviewer.model.map.layout.ElementGroup;
import lcsb.mapviewer.model.map.layout.graphics.Layer;
......
package lcsb.mapviewer.modelutils.serializer;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
public class CalendarSerializer extends JsonSerializer<Calendar> {
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
public void serialize(final Calendar entry, final JsonGenerator gen,
final SerializerProvider serializers)
throws IOException {
gen.writeString(dateFormat.format(entry.getTime()));
}
}
\ No newline at end of file
......@@ -68,8 +68,6 @@ public abstract class BaseRestImpl {
private Transformer mathMlTransformer;
private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
protected Map<String, Object> okStatus() {
return new TreeMap<>();
}
......@@ -397,21 +395,6 @@ public abstract class BaseRestImpl {
this.pubmedParser = pubmedParser;
}
public String prepareDate(Calendar creationDate) {
if (creationDate == null) {
return null;
}
return dateFormat.format(creationDate.getTime());
}
public List<String> prepareDates(List<Calendar> modificationDates) {
List<String> result = new ArrayList<>();
for (Calendar calendar : modificationDates) {
result.add(prepareDate(calendar));
}
return result;
}
protected Integer parseInteger(Object value, String fieldName) throws QueryException {
if (value instanceof Integer) {
return (Integer) value;
......
......@@ -154,7 +154,7 @@ public class ProjectRestImpl extends BaseRestImpl {
result.put("name", project.getName());
result.put("owner", project.getOwner().getLogin());
result.put("projectId", project.getProjectId());
result.put("creationDate", super.prepareDate(project.getCreationDate()));
result.put("creationDate", project.getCreationDate());
result.put("mapCanvasType", project.getMapCanvasType());
result.put("overviewImageViews", project.getOverviewImages());
......
......@@ -103,8 +103,8 @@ public class ModelRestImpl extends BaseRestImpl {
result.put("submodelType", SubmodelType.UNKNOWN);
result.put("references", createAnnotations(model.getMiriamData()));
result.put("authors", model.getAuthors());
result.put("creationDate", super.prepareDate(model.getCreationDate()));
result.put("modificationDates", super.prepareDates(model.getModificationDates()));
result.put("creationDate", model.getCreationDate());
result.put("modificationDates", model.getModificationDates());
result.put("description", model.getNotes());
return result;
}
......
package lcsb.mapviewer.web.config;
import java.util.Calendar;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import lcsb.mapviewer.api.SpringRestApiConfig;
import lcsb.mapviewer.modelutils.serializer.CalendarSerializer;
@Configuration
@EnableWebMvc
......@@ -26,6 +39,16 @@ public class SpringWebConfig implements WebMvcConfigurer {
this.interceptors = interceptors;
}
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
for (HttpMessageConverter<?> converter : converters) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter m = (MappingJackson2HttpMessageConverter) converter;
m.getObjectMapper().registerModule(new SimpleModule().addSerializer(Calendar.class, new CalendarSerializer()));
}
}
}
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
......@@ -60,8 +83,8 @@ public class SpringWebConfig implements WebMvcConfigurer {
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
ObjectMapper mapper = new ObjectMapper();
return mapper;
return mapper;
}
}
......@@ -8,6 +8,7 @@ import java.util.*;
import org.apache.commons.lang3.StringUtils;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.restdocs.payload.JsonFieldType;
import org.springframework.restdocs.payload.ResponseFieldsSnippet;
import org.springframework.stereotype.Component;
......@@ -51,7 +52,7 @@ public class ProjectSnippets {
.type("string"),
fieldWithPath("creationDate")
.description("when project was uploaded")
.type("string"),
.type(JsonFieldType.STRING),
subsectionWithPath("disease")
.description("identifier of the disease")
.type("Reference")
......
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