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

statistics moved to conrtoller

parent 2209dcdb
......@@ -60,9 +60,12 @@ import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.ObjectExistsException;
import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException;
import lcsb.mapviewer.services.interfaces.IElementService;
import lcsb.mapviewer.services.interfaces.IFileService;
import lcsb.mapviewer.services.interfaces.IMeshService;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.interfaces.IProjectService;
import lcsb.mapviewer.services.interfaces.IReactionService;
import lcsb.mapviewer.services.interfaces.IUserService;
import lcsb.mapviewer.services.utils.CreateProjectParams;
......@@ -75,6 +78,9 @@ public class ProjectController extends BaseController {
private ServletContext context;
private ProjectRestImpl projectController;
private IProjectService projectService;
private IModelService modelService;
private IElementService elementService;
private IReactionService reactionService;
private IUserService userService;
private IFileService fileService;
private IMeshService meshService;
......@@ -84,7 +90,8 @@ public class ProjectController extends BaseController {
@Autowired
public ProjectController(ServletContext context, ProjectRestImpl projectController, IUserService userService, IProjectService projectService,
IMeshService meshService, List<Converter> modelConverters, IFileService fileService) {
IMeshService meshService, List<Converter> modelConverters, IFileService fileService, IElementService elementService, IReactionService reactionService,
IModelService modelService) {
this.context = context;
this.projectController = projectController;
this.userService = userService;
......@@ -92,6 +99,9 @@ public class ProjectController extends BaseController {
this.meshService = meshService;
this.modelConverters = modelConverters;
this.fileService = fileService;
this.elementService = elementService;
this.modelService = modelService;
this.reactionService = reactionService;
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
......@@ -431,7 +441,15 @@ public class ProjectController extends BaseController {
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
@GetMapping(value = "/{projectId}/statistics")
public Object getStatistics(@PathVariable(value = "projectId") String projectId) throws QueryException {
return projectController.getStatistics(projectId);
Map<String, Object> result = new TreeMap<>();
result.put("elementAnnotations", elementService.getAnnotationStatistics(projectId, "*"));
result.put("reactionAnnotations", reactionService.getAnnotationStatistics(projectId, "*"));
result.put("publications", modelService.getPublicationCount(projectId, "*"));
return result;
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
......@@ -546,41 +564,41 @@ public class ProjectController extends BaseController {
@RequestParam(value = "sortColumn", defaultValue = "id") LogSortColumn sortColumn,
@RequestParam(value = "sortOrder", defaultValue = "asc") String sortOrder,
@RequestParam(value = "search", defaultValue = "") String search) throws QueryException {
Project project = getProject(projectId);
Project project = getProject(projectId);
Comparator<LogEntry> comparator = getComparatorForColumn(sortColumn, sortOrder);
Comparator<LogEntry> comparator = getComparatorForColumn(sortColumn, sortOrder);
List<LogEntry> resultList = new ArrayList<>();
List<LogEntry> resultList = new ArrayList<>();
List<LogEntry> logEntries = getEntries(project, level);
List<LogEntry> logEntries = getEntries(project, level);
List<LogEntry> filteredList = new ArrayList<>();
List<LogEntry> filteredList = new ArrayList<>();
search = search.toLowerCase();
for (LogEntry entry : logEntries) {
if (isSearchResult(entry, search)) {
filteredList.add(entry);
}
}
if (comparator != null) {
filteredList.sort(comparator);
search = search.toLowerCase();
for (LogEntry entry : logEntries) {
if (isSearchResult(entry, search)) {
filteredList.add(entry);
}
}
if (comparator != null) {
filteredList.sort(comparator);
}
int index = 0;
for (LogEntry entry : filteredList) {
if (index >= start && index < start + length) {
resultList.add(entry);
}
index++;
int index = 0;
for (LogEntry entry : filteredList) {
if (index >= start && index < start + length) {
resultList.add(entry);
}
index++;
}
LogPage result = new LogPage();
result.data = resultList;
result.totalSize = logEntries.size();
result.filteredSize = filteredList.size();
result.start = start;
result.length = resultList.size();
return result;
LogPage result = new LogPage();
result.data = resultList;
result.totalSize = logEntries.size();
result.filteredSize = filteredList.size();
result.start = start;
result.length = resultList.size();
return result;
}
......
......@@ -14,7 +14,6 @@ import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.OperationNotAllowedException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.layout.ProjectBackground;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.user.ConfigurationElementType;
......@@ -50,21 +49,6 @@ public class ProjectRestImpl extends BaseRestImpl {
return project;
}
public Map<String, Object> getStatistics(String projectId) throws QueryException {
Map<String, Object> result = new TreeMap<>();
Map<MiriamType, Integer> elementAnnotations = elementService.getAnnotationStatistics(projectId, "*");
result.put("elementAnnotations", elementAnnotations);
Map<MiriamType, Integer> reactionAnnotations = reactionService.getAnnotationStatistics(projectId, "*");
result.put("reactionAnnotations", reactionAnnotations);
result.put("publications", getModelService().getPublicationCount(projectId, "*"));
return result;
}
public Project removeProject(String projectId, String path) throws QueryException {
Project project = getProjectByProjectId(projectId);
if (getConfigurationService().getConfigurationValue(ConfigurationElementType.DEFAULT_MAP)
......
......@@ -72,22 +72,6 @@ public class ProjectRestImplTest extends RestTestFunctions {
projectRest.getProject("unknown_model_id");
}
@Test
public void testGetStatistics() throws Exception {
createMockProjectRest("testFiles/model/sample.xml");
Map<String, Object> result = projectRest.getStatistics("sample");
Gson gson = new Gson();
assertNotNull(gson.toJson(result));
Map<?, ?> elementAnnotations = (Map<?, ?>) result.get("elementAnnotations");
assertEquals(elementAnnotations.get(MiriamType.CAS), 0);
assertTrue((Integer) elementAnnotations.get(MiriamType.ENTREZ) > 0);
Map<?, ?> reactionAnnotations = (Map<?, ?>) result.get("reactionAnnotations");
assertEquals(reactionAnnotations.get(MiriamType.ENTREZ), 0);
assertEquals(reactionAnnotations.get(MiriamType.PUBMED), 1);
}
private void createMockProjectRest(String string) throws Exception {
Model model = null;
Project project = null;
......
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