Commit d5ebee6f authored by oleg.pahhomov's avatar oleg.pahhomov

SA0140-380 add debugging endpoint for graph data

parent 27aca6e8
......@@ -54,6 +54,7 @@ spring:
- ElementServiceCache_findAllDashboardRegions
- FilterService_getDbFilters
- GraphService_filterData
- GraphService_fullData
- GraphTypeServiceCache_findAllByWidget
- StatLinksService_getLinks
- StatDimensionsService_getDimensions
......
......@@ -3,8 +3,12 @@ package ee.stat.dashboard.controller.admin;
public enum FilterType {
FILTER, SKIP_USER, SKIP_USER_AND_FILTER;
public boolean skipUser() {
return this == SKIP_USER || this == SKIP_USER_AND_FILTER;
public boolean filterUser(){
return this == FILTER;
}
public boolean filterGraph() {
return !skipFilter();
}
public boolean skipFilter() {
......
......@@ -29,6 +29,7 @@ import static ee.stat.dashboard.controller.admin.FilterType.SKIP_USER_AND_FILTER
import static ee.stat.dashboard.controller.admin.FilterType.SKIP_USER;
import static ee.stat.dashboard.controller.publics.DashboardWidgetController.*;
import static ee.stat.dashboard.util.ResponseUtil.badRequest;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
@RestController
@RequestMapping("/admin/widget")
......@@ -88,16 +89,26 @@ public class WidgetAdminController {
@Secured(RoleString.ADMIN)
public Response<WidgetAdminResponse> save(@RequestBody WidgetAdminResponse widget) {
Long save = widgetAdminService.save(widget);
widgetAdminService.buildNewDiagram(widget);
return of(widgetAdminService.findById(save));
String calculationMessage = widgetAdminService.buildNewDiagram(widget);
WidgetAdminResponse byId = widgetAdminService.findById(save);
if (isNotEmpty(calculationMessage)){
byId.setCalculationProblem(true);
byId.setCalculationProblemMessage(calculationMessage);
}
return of(byId);
}
@PutMapping(path = "/{widgetId}")
@Secured(RoleString.ADMIN)
public Response<WidgetAdminResponse> update(@PathVariable Long widgetId, @RequestBody WidgetAdminResponse widget) {
Long update = widgetAdminService.update(widgetId, widget);
widgetAdminService.buildNewDiagram(widget);
return of(widgetAdminService.findById(update));
String calculationMessage = widgetAdminService.buildNewDiagram(widget);
WidgetAdminResponse byId = widgetAdminService.findById(update);
if (isNotEmpty(calculationMessage)){
byId.setCalculationProblem(true);
byId.setCalculationProblemMessage(calculationMessage);
}
return of(byId);
}
@DeleteMapping(path = "/{widgetId}")
......
......@@ -27,8 +27,7 @@ import ee.stat.dashboard.service.widget.diagram.DiagramBuilder;
import ee.stat.dashboard.service.widget.importer.WidgetImportUtil;
import ee.stat.dashboard.util.StatDateUtil;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
......@@ -41,10 +40,12 @@ import java.util.List;
import static ee.stat.dashboard.util.ResponseUtil.badRequest;
import static ee.stat.dashboard.util.StatListUtil.first;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
@Slf4j
@Service
@AllArgsConstructor
@Transactional
......@@ -108,8 +109,14 @@ public class WidgetAdminService {
return adminResponse;
}
public void buildNewDiagram(WidgetAdminResponse widget) {
diagramBuilder.createNewDiagram(widget.getId());
public String buildNewDiagram(WidgetAdminResponse widget) {
try {
diagramBuilder.createNewDiagramForUpdater(widget.getId());
return "";
} catch (Exception e) {
log.error("error creating diagram for widget {}: {}", widget.getId(), e.getMessage(), e);
return format("Error creating diagram for widget %s: %s", e.getClass(), e.getMessage());
}
}
public Long save(WidgetAdminResponse widget) {
......
......@@ -4,6 +4,7 @@ import ee.stat.dashboard.model.widget.front.enums.FilterDisplay;
import ee.stat.dashboard.service.admin.widget.dto.FilterAdminDto;
import ee.stat.dashboard.service.admin.widget.dto.FilterValueAdminDto;
import ee.stat.dashboard.service.admin.widget.dto.GraphTypeAdminDto;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.stereotype.Service;
import static ee.stat.dashboard.util.ResponseUtil.badRequest;
......@@ -24,6 +25,15 @@ public class GraphTypeValidator {
if (countOfAxis != 1) {
throw badRequest("graphType", "If filters are defined only 1 axis must be set").get();
}
if (graphTypeDto.getType().isLineOrBarOrStackedOrArea()) {
if (!axisIsTime(graphTypeDto)) {
throw badRequest("graphType", "Line, Bar, Stacked or Area should have axis set as time").get();
}
} else if (graphTypeDto.getType().isMapOrVerticalOrPieOrTreemapOrRadarOrPyramid()) {
if (axisIsTime(graphTypeDto)) {
throw badRequest("graphType", "Map, Vertical, Pie, Treemap, Radar or Pyramid should have axis set NOT as time").get();
}
}
long countOfLegends = graphTypeDto.getFilters().stream().filter(f -> f.getType().equals(FilterDisplay.LEGEND)).count();
if (countOfLegends > 1) {
throw badRequest("graphType", "If filters are defined up to 1 legend can be set").get();
......@@ -53,6 +63,12 @@ public class GraphTypeValidator {
}
}
private boolean axisIsTime(GraphTypeAdminDto graphTypeDto) {
return graphTypeDto.getFilters().stream()
.filter(f -> f.getType().equals(FilterDisplay.AXIS))
.anyMatch(f -> isTrue(f.getTime()));
}
public void validateFilter(FilterAdminDto filterDto) {
if (filterDto.getType() == null) {
throw badRequest("filter", "no type").get();
......
......@@ -46,6 +46,8 @@ public class WidgetAdminResponse {
private String statisticianJobLinkEn;
private StatDbAdminDto statDb;
private ExcelAdminDto excel;
private Boolean calculationProblem;
private String calculationProblemMessage;
private List<DashboardAdminResponse> dashboards;
private List<DomainAdminResponse> elements;
......
......@@ -36,6 +36,7 @@ import ee.stat.dashboard.service.statsync.dto.StatDbResponse;
import ee.stat.dashboard.service.widget.importer.dto.ImportResult;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
......@@ -140,9 +141,7 @@ public class WidgetSaveImporter {
List<FilterValue> values = getTimeFilterValues(savedWidget, savedGraph, filter, newFilter);
values.forEach(v -> v.setOrderNr(values.indexOf(v)));
if (!newFilter.getType().isMenu()) {
values.forEach(v -> v.setSelected(false));
}
updateSelected(newFilter, values);
saveValues(filterRepository.save(newFilter), values);
newFilter.setValues(values);
newFilters.add(newFilter);
......@@ -150,6 +149,16 @@ public class WidgetSaveImporter {
return notTime(newFilters);
}
private void updateSelected(Filter newFilter, List<FilterValue> values) {
if (newFilter.getType().isMenu()) {
if (CollectionUtils.isNotEmpty(values) && values.stream().noneMatch(FilterValue::isSelected)) {
values.get(0).setSelected(true);
}
} else {
values.forEach(v -> v.setSelected(false));
}
}
private List<Filter> saveMapFilters(ImportResult result, Widget savedWidget, GraphType savedGraph) {
List<Filter> filters = notEmpty(result);
filters.add(timeFilter(FilterDisplay.MENU, result.getFilters().size()));
......@@ -162,9 +171,7 @@ public class WidgetSaveImporter {
List<FilterValue> values = getFilterValues(savedWidget, savedGraph, newFilter);
values.forEach(v -> v.setOrderNr(values.indexOf(v)));
if (!newFilter.getType().isMenu()) {
values.forEach(v -> v.setSelected(false));
}
updateSelected(newFilter, values);
saveValues(filterRepository.save(newFilter), values);
newFilter.setValues(values);
newFilters.add(newFilter);
......
......@@ -43,7 +43,6 @@ public class FilterService {
return filters.stream()
.filter(filter -> filter.getType().logicFilter())
.map(filter -> mapWithValues(filter, lang, filter.getValues()))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
......
......@@ -57,9 +57,9 @@ public class WidgetService {
private ElementService elementService;
public WidgetResponse findById(Long id, Long dashboardId, Long ehakId, Language lang, String graphType,
StatUser user, Map<String, String> params, FilterType filter) {
StatUser user, Map<String, String> params, FilterType filterType) {
Widget widget = findWidget(id, dashboardId);
return mapWidget(widget, dashboardId, ehakId, lang, graphType, user, params, filter);
return mapWidget(widget, dashboardId, ehakId, lang, graphType, user, params, filterType);
}
public WidgetResponse findByWidgetIdOnly(Long id, Language lang, String graphType,
......@@ -113,7 +113,7 @@ public class WidgetService {
.graphType(graphType)
.build();
if (filterType.skipUser()) {
if (filterType.filterUser()) {
if (isNotEmpty(graphTypes.getUserGraphTypes())) {
UserWidgetDto preferences = userWidgetPreferencesService.convert(dto.getGraphTypes());
dto.setPreferences(preferences);
......@@ -125,10 +125,10 @@ public class WidgetService {
}
}
if (filterType.skipFilter()) {
dto.setDiagram(graphService.fullData(data, filters));
} else {
if (filterType.filterGraph()) {
dto.setDiagram(graphService.filterData(data, filters));
} else {
dto.setDiagram(graphService.fullData(data, filters));
}
return dto;
}
......
......@@ -132,6 +132,10 @@
<appender-ref ref="CacheFile"/>
</logger>
<logger name="org.springframework.cache.interceptor.CacheAspectSupport" level="TRACE">
<appender-ref ref="CacheFile"/>
</logger>
<logger name="ee.stat.dashboard.config.logging.meta" level="DEBUG" additivity="false">
<appender-ref ref="MetaRequestFile"/>
</logger>
......
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