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

LogPage class introduced

parent 2e0109c3
package lcsb.mapviewer.api.projects;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
......@@ -42,6 +43,7 @@ import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.zip.ZipEntryFile;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectLogEntry;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.graphics.MapCanvasType;
import lcsb.mapviewer.model.map.MiriamData;
......@@ -445,10 +447,46 @@ public class ProjectController extends BaseController {
.body(file.getFileContent());
}
static class LogPage {
public List<LogEntry> data;
public int totalSize;
public int filteredSize;
public Integer start;
public int length;
}
static class LogEntry implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public Integer id;
public String content;
public String 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();
}
}
@PreAuthorize("hasAuthority('IS_ADMIN')" +
" or hasAuthority('IS_CURATOR') and hasAuthority('READ_PROJECT:' + #projectId)")
@GetMapping(value = "/{projectId}/logs/")
public Map<String, Object> getLogs(
public LogPage getLogs(
@PathVariable(value = "projectId") String projectId,
@RequestParam(value = "level", defaultValue = "*") String level,
@RequestParam(value = "start", defaultValue = "0") String start,
......
package lcsb.mapviewer.api.projects;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
......@@ -15,6 +14,8 @@ import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.OperationNotAllowedException;
import lcsb.mapviewer.api.projects.ProjectController.LogEntry;
import lcsb.mapviewer.api.projects.ProjectController.LogPage;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectLogEntry;
......@@ -79,7 +80,7 @@ public class ProjectRestImpl extends BaseRestImpl {
return getProject(projectId);
}
public Map<String, Object> getLogs(String projectId, String level, String startString, Integer length,
public LogPage getLogs(String projectId, String level, String startString, Integer length,
String sortColumn, String sortOrder, String search) throws QueryException {
Project project = getProjectByProjectId(projectId);
......@@ -111,12 +112,12 @@ public class ProjectRestImpl extends BaseRestImpl {
index++;
}
Map<String, Object> result = new TreeMap<>();
result.put("data", resultList);
result.put("totalSize", logEntries.size());
result.put("filteredSize", filteredList.size());
result.put("start", start);
result.put("length", resultList.size());
LogPage result = new LogPage();
result.data = resultList;
result.totalSize = logEntries.size();
result.filteredSize = filteredList.size();
result.start = start;
result.length = resultList.size();
return result;
}
......@@ -230,32 +231,6 @@ public class ProjectRestImpl extends BaseRestImpl {
}
}
private class LogEntry implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public Integer id;
public String content;
public String 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();
}
}
public List<ProjectBackground> getBackgrounds(String projectId) throws ObjectNotFoundException {
List<ProjectBackground> result = getProjectByProjectId(projectId).getProjectBackgrounds();
for (ProjectBackground projectBackground : result) {
......
......@@ -105,13 +105,4 @@ public class ProjectRestImplTest extends RestTestFunctions {
projectRest = Mockito.spy(_projectRest);
}
@Test
public void testGetLogs() throws Exception {
createMockProjectRest("testFiles/model/sample.xml");
Map<String, Object> result = projectRest.getLogs("sample", "", "0", 10, "id", "asc", "");
assertNotNull(result);
Gson gson = new Gson();
assertNotNull(gson.toJson(result));
}
}
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