Commit 31163db5 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

rest API uses new data structures for logs

parent 1130dd0f
......@@ -113,4 +113,8 @@ public class ProjectLogEntry implements Serializable {
this.type = type;
}
public int getId() {
return id;
}
}
......@@ -17,11 +17,13 @@ import lcsb.mapviewer.annotation.services.MeSHParser;
import lcsb.mapviewer.annotation.services.annotators.AnnotatorException;
import lcsb.mapviewer.api.*;
import lcsb.mapviewer.api.projects.models.publications.PublicationsRestImpl;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.zip.*;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectLogEntry;
import lcsb.mapviewer.model.cache.FileEntry;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.graphics.MapCanvasType;
......@@ -578,30 +580,13 @@ public class ProjectRestImpl extends BaseRestImpl {
}
private List<LogEntry> getEntries(Project project, String level) {
throw new NotImplementedException();
// List<LogEntry> result = new ArrayList<>();
// int id = 0;
// for (String s : project.getWarnings()) {
// if (!s.isEmpty()) {
// if (level.equalsIgnoreCase("warning") || level.equals("")) {
// result.add(new LogEntry(id, s, "WARNING"));
// }
// id++;
// }
// }
// String errors = project.getErrors();
// if (errors == null) {
// errors = "";
// }
// for (String s : errors.split("\n")) {
// if (!s.isEmpty()) {
// if (level.equalsIgnoreCase("error") || level.equals("")) {
// result.add(new LogEntry(id, s, "ERROR"));
// }
// id++;
// }
// }
// return result;
List<LogEntry> result = new ArrayList<>();
for (ProjectLogEntry s : project.getLogEntries()) {
if (level == null || level.equals("*") || level.equalsIgnoreCase(s.getSeverity())) {
result.add(new LogEntry(s));
}
}
return result;
}
private Comparator<LogEntry> getComparatorForColumn(LogSortColumn sortColumnEnum, String sortOrder)
......@@ -612,13 +597,25 @@ public class ProjectRestImpl extends BaseRestImpl {
} else {
orderFactor = 1;
}
StringComparator stringComparator = new StringComparator();
if (sortColumnEnum == null) {
return null;
} else if (sortColumnEnum.equals(LogSortColumn.ID)) {
return (o1, o2) -> o1.id.compareTo(o2.id) * orderFactor;
} else if (sortColumnEnum.equals(LogSortColumn.CONTENT)) {
return (o1, o2) -> o1.content.compareTo(o2.content) * orderFactor;
} else if (sortColumnEnum.equals(LogSortColumn.LEVEL)) {
return (o1, o2) -> o1.level.compareTo(o2.level) * orderFactor;
} else if (sortColumnEnum.equals(LogSortColumn.MAP_NAME)) {
return (o1, o2) -> stringComparator.compare(o1.mapName, o2.mapName) * orderFactor;
} else if (sortColumnEnum.equals(LogSortColumn.OBJECT_CLASS)) {
return (o1, o2) -> stringComparator.compare(o1.objectClass, o2.objectClass) * orderFactor;
} else if (sortColumnEnum.equals(LogSortColumn.OBJECT_IDENTIFIER)) {
return (o1, o2) -> stringComparator.compare(o1.objectIdentifier, o2.objectIdentifier) * orderFactor;
} else if (sortColumnEnum.equals(LogSortColumn.SOURCE)) {
return (o1, o2) -> stringComparator.compare(o1.source, o2.source) * orderFactor;
} else if (sortColumnEnum.equals(LogSortColumn.TYPE)) {
return (o1, o2) -> stringComparator.compare(o1.type, o2.type) * orderFactor;
} else {
throw new QueryException("Sort order not implemented for: " + sortColumnEnum);
}
......@@ -714,6 +711,12 @@ public class ProjectRestImpl extends BaseRestImpl {
private enum LogSortColumn {
ID("id"),
LEVEL("level"),
TYPE("type"),
OBJECT_IDENTIFIER("objectIdentifier"),
OBJECT_CLASS("objectClass"),
MAP_NAME("mapName"),
SOURCE("source"),
CONTENT("content");
private String commonName;
......@@ -730,13 +733,22 @@ public class ProjectRestImpl extends BaseRestImpl {
private static final long serialVersionUID = 1L;
public Integer id;
public String content;
@SuppressWarnings("unused")
public String level;
public LogEntry(int id, String content, String level) {
this.id = id;
this.content = content;
this.level = level;
public String type;
public String objectIdentifier;
public String objectClass;
public String mapName;
public String source;
public LogEntry(ProjectLogEntry s) {
this.id = s.getId();
this.content = s.getContent();
this.level = s.getSeverity();
this.type = s.getType().toString();
this.objectIdentifier = s.getObjectIdentifier();
this.objectClass = s.getObjectClass();
this.mapName = s.getMapName();
this.source = s.getSource();
}
}
......
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