Skip to content

Commit

Permalink
Merge pull request #3030 from SCADA-LTS/feature/#3027_Added_configura…
Browse files Browse the repository at this point in the history
…ble_length_of_point_names_in_reports

#3027 Added configurable length of point names in reports
  • Loading branch information
Limraj authored Oct 21, 2024
2 parents 4e0264f + 5466bc0 commit 5f8fbf1
Show file tree
Hide file tree
Showing 26 changed files with 262 additions and 91 deletions.
8 changes: 8 additions & 0 deletions WebContent/WEB-INF/jsp/systemSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
$set(sel, settings.<c:out value="<%= SystemSettingsDAO.LANGUAGE %>"/>);
$set("<c:out value="<%= SystemSettingsDAO.TOP_DESCRIPTION_PREFIX %>"/>", settings.<c:out value="<%= SystemSettingsDAO.TOP_DESCRIPTION_PREFIX %>"/>);
$set("<c:out value="<%= SystemSettingsDAO.TOP_DESCRIPTION %>"/>", settings.<c:out value="<%= SystemSettingsDAO.TOP_DESCRIPTION %>"/>);
$set("<c:out value="<%= SystemSettingsDAO.DATA_POINT_EXTENDED_NAME_LENGTH_IN_REPORTS_LIMIT %>"/>", settings.<c:out value="<%= SystemSettingsDAO.DATA_POINT_EXTENDED_NAME_LENGTH_IN_REPORTS_LIMIT %>"/>);
});
<%--
Expand Down Expand Up @@ -313,6 +314,7 @@
$get("<c:out value="<%= SystemSettingsDAO.WEB_RESOURCE_GRAPHICS_PATH %>"/>"),
$get("<c:out value="<%= SystemSettingsDAO.WEB_RESOURCE_UPLOADS_PATH %>"/>"),
$get("<c:out value="<%= SystemSettingsDAO.EVENT_ASSIGN_ENABLED %>"/>"),
$get("<c:out value="<%= SystemSettingsDAO.DATA_POINT_EXTENDED_NAME_LENGTH_IN_REPORTS_LIMIT %>"/>"),
function(response) {
stopImageFader("saveMiscSettingsImg");
if (response.hasMessages)
Expand Down Expand Up @@ -1018,6 +1020,12 @@
<input id="<c:out value="<%= SystemSettingsDAO.EVENT_ASSIGN_ENABLED %>"/>" type="checkbox" />
</td>
</tr>
<tr>
<td class="formLabelRequired"><spring:message code="systemsettings.reports.dataPointExtendedNameLengthLimit"/></td>
<td class="formField">
<input id="<c:out value="<%= SystemSettingsDAO.DATA_POINT_EXTENDED_NAME_LENGTH_IN_REPORTS_LIMIT %>"/>" type="number" class="formShort"/>
</td>
</tr>
<tr>
<td colspan="2" id="miscMessage" class="formError"></td>
</tr>
Expand Down
4 changes: 3 additions & 1 deletion src/com/serotonin/mango/rt/maint/work/ReportWorkItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.serotonin.util.StringUtils;
import com.serotonin.web.i18n.LocalizableMessage;
import org.scada_lts.dao.report.ReportInstancePointDAO;
import org.scada_lts.mango.service.SystemSettingsService;

import static com.serotonin.mango.util.LoggingUtils.*;
import static com.serotonin.mango.util.SendUtils.sendMsg;
Expand Down Expand Up @@ -207,8 +208,9 @@ public void workSuccess() {
String inlinePrefix = "R" + System.currentTimeMillis() + "-"
+ reportInstance.getId() + "-";

SystemSettingsService service = new SystemSettingsService();
// We are creating an email from the result. Create the content.
final ReportChartCreator creator = new ReportChartCreator(bundle);
final ReportChartCreator creator = new ReportChartCreator(bundle, service);
creator.createContent(reportInstance, reportDao, inlinePrefix,
reportConfig.isIncludeData());

Expand Down
12 changes: 10 additions & 2 deletions src/com/serotonin/mango/vo/report/ImageChartUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.scada_lts.dao.SystemSettingsDAO;
import com.serotonin.mango.util.mindprod.StripEntities;
import com.serotonin.util.StringUtils;
import org.scada_lts.mango.service.SystemSettingsService;

import static org.scada_lts.serorepl.utils.StringUtils.truncate;

Expand Down Expand Up @@ -224,9 +225,16 @@ public static int calculateLinesNumber(List<String> pointStatisticsNames, int li
return linesNumber;
}

@Deprecated(since = "2.8.0")
public static String calculatePointNameForReport(String extendedName) {
if(extendedName.length() > ReportChartCreator.getDataPointExtendedNameLengthLimit()) {
return truncate(extendedName, "...", ReportChartCreator.getDataPointExtendedNameLengthLimit());
SystemSettingsService settings = new SystemSettingsService();
return truncatePointNameForReport(extendedName, settings);
}

public static String truncatePointNameForReport(String extendedName, SystemSettingsService systemSettingsService) {
int dataPointExtendedNameLengthInReportsLimit = systemSettingsService.getDataPointExtendedNameLengthInReportsLimit();
if(extendedName.length() > dataPointExtendedNameLengthInReportsLimit) {
return truncate(extendedName, "...", dataPointExtendedNameLengthInReportsLimit);
}
return extendedName;
}
Expand Down
17 changes: 14 additions & 3 deletions src/com/serotonin/mango/vo/report/ReportChartCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jfree.data.time.TimeSeries;
import org.scada_lts.mango.service.SystemSettingsService;
import org.scada_lts.utils.ColorUtils;
import com.serotonin.mango.util.DateUtils;

Expand All @@ -59,7 +60,6 @@ public class ReportChartCreator {
private static final int IMAGE_HEIGHT_PIXELS = 400;
private static final int POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS = 20;
private static final int LINE_LENGTH_IN_LEGEND_LIMIT = 161;
private static final int DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT = 64;
public static final String IMAGE_CONTENT_ID = "reportChart.png";

public static final int POINT_IMAGE_WIDTH_PIXELS = 440;
Expand All @@ -77,8 +77,17 @@ public class ReportChartCreator {

final ResourceBundle bundle;

private final SystemSettingsService systemSettingsService;

@Deprecated(since = "2.8.0")
public ReportChartCreator(ResourceBundle bundle) {
this.bundle = bundle;
this.systemSettingsService = new SystemSettingsService();
}

public ReportChartCreator(ResourceBundle bundle, SystemSettingsService systemSettingsService) {
this.bundle = bundle;
this.systemSettingsService = systemSettingsService;
}

/**
Expand Down Expand Up @@ -148,7 +157,7 @@ else if (pointStat.getDiscreteTimeSeries() != null)
model.put("chartName", IMAGE_SERVLET + chartName);
}
int consolidatedChartHeight = ImageChartUtils.calculateHeightChart(pointStatistics, IMAGE_HEIGHT_PIXELS,
POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS, LINE_LENGTH_IN_LEGEND_LIMIT, DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT);
POINT_LABEL_HEIGHT_IN_LEGEND_PIXELS, LINE_LENGTH_IN_LEGEND_LIMIT, systemSettingsService.getDataPointExtendedNameLengthInReportsLimit());
imageData = ImageChartUtils.getChartData(ptsc, true, IMAGE_WIDTH_PIXELS, consolidatedChartHeight);
}

Expand Down Expand Up @@ -259,8 +268,10 @@ public List<PointStatistics> getPointStatistics() {
return pointStatistics;
}

@Deprecated(since = "2.8.0")
public static int getDataPointExtendedNameLengthLimit(){
return DATA_POINT_EXTENDED_NAME_LENGTH_LIMIT;
SystemSettingsService settings = new SystemSettingsService();
return settings.getDataPointExtendedNameLengthInReportsLimit();
}

public static int getLineLengthInLegendLimit() {
Expand Down
5 changes: 4 additions & 1 deletion src/com/serotonin/mango/vo/report/ReportPointInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.serotonin.mango.rt.dataImage.types.MangoValue;
import com.serotonin.mango.view.text.TextRenderer;
import org.scada_lts.mango.service.SystemSettingsService;
import org.scada_lts.web.beans.ApplicationBeans;

/**
* @author Matthew Lohbihler
Expand All @@ -38,7 +40,8 @@ public String getExtendedName() {
return deviceName + " - " + pointName;
}
public String getExtendedNameForReport() {
return ImageChartUtils.calculatePointNameForReport(getExtendedName());
SystemSettingsService systemSettingsService = ApplicationBeans.getBean("systemSettingsService", SystemSettingsService.class);
return ImageChartUtils.truncatePointNameForReport(getExtendedName(), systemSettingsService);
}
public int getReportPointId() {
return reportPointId;
Expand Down
76 changes: 17 additions & 59 deletions src/com/serotonin/mango/web/dwr/SystemSettingsDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.scada_lts.mango.service.SystemSettingsService;
import org.scada_lts.utils.ColorUtils;
import org.scada_lts.web.mvc.api.json.JsonSettingsHttp;
import org.scada_lts.serorepl.utils.StringUtils;

import java.io.File;
import java.net.SocketTimeoutException;
Expand Down Expand Up @@ -183,6 +182,8 @@ public Map<String, Object> getSettings() {
systemSettingsService.getSystemInfoSettings().getTopDescription());
settings.put(SystemSettingsDAO.TOP_DESCRIPTION_PREFIX,
systemSettingsService.getSystemInfoSettings().getTopDescriptionPrefix());
settings.put(SystemSettingsDAO.DATA_POINT_EXTENDED_NAME_LENGTH_IN_REPORTS_LIMIT,
systemSettingsService.getMiscSettings().getDataPointExtendedNameLengthInReportsLimit());
return settings;
}

Expand Down Expand Up @@ -336,66 +337,23 @@ public DwrResponseI18n saveMiscSettings(int uiPerformance, String dataPointRtVal
boolean workItemsReportingEnabled, boolean workItemsReportingItemsPerSecondEnabled,
int workItemsReportingItemsPerSecondLimit, int threadsNameAdditionalLength,
String webResourceGraphicsPath, String webResourceUploadsPath,
boolean eventAssignEnabled) {
boolean eventAssignEnabled, int pointExtendedNameLengthInReportsLimit) {
Permissions.ensureAdmin();
SystemSettingsDAO systemSettingsDAO = new SystemSettingsDAO();
DwrResponseI18n response = new DwrResponseI18n();
if(uiPerformance < 0) {
response.addContextualMessage(SystemSettingsDAO.UI_PERFORMANCE, "validate.invalidValue");
return response;
} else {
systemSettingsDAO.setIntValue(SystemSettingsDAO.UI_PERFORMANCE, uiPerformance);
}
systemSettingsDAO.setValue(SystemSettingsDAO.DATAPOINT_RUNTIME_VALUE_SYNCHRONIZED,
String.valueOf(dataPointRtValueSynchronized));

systemSettingsDAO.setBooleanValue(SystemSettingsDAO.VIEW_FORCE_FULL_SCREEN_MODE, viewEnableFullScreen);
systemSettingsDAO.setBooleanValue(SystemSettingsDAO.VIEW_HIDE_SHORTCUT_DISABLE_FULL_SCREEN, viewHideShortcutDisableFullScreen);
if(eventPendingLimit < 0) {
response.addContextualMessage(SystemSettingsDAO.EVENT_PENDING_LIMIT, "validate.invalidValue");
} else {
systemSettingsDAO.setIntValue(SystemSettingsDAO.EVENT_PENDING_LIMIT, eventPendingLimit);
}
systemSettingsDAO.setBooleanValue(SystemSettingsDAO.EVENT_PENDING_CACHE_ENABLED, eventPendingCacheEnabled);
if(eventPendingLimit < 0) {
response.addContextualMessage(SystemSettingsDAO.THREADS_NAME_ADDITIONAL_LENGTH, "validate.invalidValue");
} else {
systemSettingsDAO.setIntValue(SystemSettingsDAO.THREADS_NAME_ADDITIONAL_LENGTH, threadsNameAdditionalLength);
}
systemSettingsDAO.setBooleanValue(SystemSettingsDAO.WORK_ITEMS_REPORTING_ENABLED, workItemsReportingEnabled);
if(workItemsReportingEnabled) {
systemSettingsDAO.setBooleanValue(SystemSettingsDAO.WORK_ITEMS_REPORTING_ITEMS_PER_SECOND_ENABLED, workItemsReportingItemsPerSecondEnabled);
if(workItemsReportingItemsPerSecondEnabled) {
if (workItemsReportingItemsPerSecondLimit < 0) {
response.addContextualMessage(SystemSettingsDAO.WORK_ITEMS_REPORTING_ITEMS_PER_SECOND_LIMIT, "validate.invalidValue");
} else {
systemSettingsDAO.setIntValue(SystemSettingsDAO.WORK_ITEMS_REPORTING_ITEMS_PER_SECOND_LIMIT, workItemsReportingItemsPerSecondLimit);
}
} else {
systemSettingsDAO.setIntValue(SystemSettingsDAO.WORK_ITEMS_REPORTING_ITEMS_PER_SECOND_LIMIT, 0);
}
} else {
systemSettingsDAO.setBooleanValue(SystemSettingsDAO.WORK_ITEMS_REPORTING_ITEMS_PER_SECOND_ENABLED, false);
systemSettingsDAO.setIntValue(SystemSettingsDAO.WORK_ITEMS_REPORTING_ITEMS_PER_SECOND_LIMIT, 0);
}
if (webResourceGraphicsPath != null && (StringUtils.isEmpty(webResourceGraphicsPath)
|| (webResourceGraphicsPath.endsWith("graphics")
|| webResourceGraphicsPath.endsWith("graphics" + File.separator)))) {
systemSettingsDAO.setValue(SystemSettingsDAO.WEB_RESOURCE_GRAPHICS_PATH, webResourceGraphicsPath);
}
else {
response.addContextualMessage(SystemSettingsDAO.WEB_RESOURCE_GRAPHICS_PATH, "systemsettings.webresource.graphics.path.wrong", File.separator);
}
if (webResourceUploadsPath != null && (StringUtils.isEmpty(webResourceUploadsPath)
|| (webResourceUploadsPath.endsWith("uploads")
|| webResourceUploadsPath.endsWith("uploads" + File.separator)))) {
systemSettingsDAO.setValue(SystemSettingsDAO.WEB_RESOURCE_UPLOADS_PATH, webResourceUploadsPath);
}
else {
response.addContextualMessage(SystemSettingsDAO.WEB_RESOURCE_UPLOADS_PATH, "systemsettings.webresource.uploads.path.wrong", File.separator);
}
SystemSettingsService systemSettingsService = new SystemSettingsService();
systemSettingsService.saveEventAssignEnabled(eventAssignEnabled);
DwrResponseI18n response = new DwrResponseI18n();
systemSettingsService.saveUiPerformanceMisc(uiPerformance, response);
systemSettingsService.saveDataPointRuntimeValueSynchronizedMisc(dataPointRtValueSynchronized);
systemSettingsService.saveViewForceFullScreenModeMisc(viewEnableFullScreen);
systemSettingsService.saveViewHideShortcutDisableFullScreenMisc(viewHideShortcutDisableFullScreen);
systemSettingsService.saveEventPendingCacheEnabledMisc(eventPendingCacheEnabled);
systemSettingsService.saveEventPendingLimitMisc(eventPendingLimit, response);
systemSettingsService.saveThreadsNameAdditionalLengthMisc(threadsNameAdditionalLength, response);
systemSettingsService.saveWorkItemsReportingMisc(workItemsReportingItemsPerSecondEnabled, workItemsReportingItemsPerSecondLimit,
workItemsReportingEnabled, response);
systemSettingsService.saveResourceGraphicsPathMisc(webResourceGraphicsPath, response);
systemSettingsService.saveResourceUploadsPathMisc(webResourceUploadsPath, response);
systemSettingsService.saveDataPointExtendedNameLengthInReportsLimitMisc(pointExtendedNameLengthInReportsLimit, response);
systemSettingsService.saveEventAssignEnabledMisc(eventAssignEnabled);
return response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.scada_lts.mango.service.SystemSettingsService;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.mvc.AbstractController;
Expand Down Expand Up @@ -51,7 +52,8 @@ protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpSer
User user = Common.getUser(request);
Permissions.ensureReportInstancePermission(user, instance);

ReportChartCreator creator = new ReportChartCreator(Common.getBundle(request));
SystemSettingsService service = new SystemSettingsService();
ReportChartCreator creator = new ReportChartCreator(Common.getBundle(request), service);
creator.createContent(instance, reportDao, null, false);

Map<String, byte[]> imageData = new HashMap<String, byte[]>();
Expand Down
2 changes: 2 additions & 0 deletions src/org/scada_lts/dao/SystemSettingsDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public class SystemSettingsDAO {
public static final String TOP_DESCRIPTION_PREFIX = "topDescriptionPrefix";
public static final String TOP_DESCRIPTION = "topDescription";
public static final String CUSTOM_CSS_CONTENT = "customCssContent";
public static final String DATA_POINT_EXTENDED_NAME_LENGTH_IN_REPORTS_LIMIT = "dataPointExtendedNameLengthInReportsLimit";

// @formatter:off
private static final String SELECT_SETTING_VALUE_WHERE = ""
Expand Down Expand Up @@ -420,6 +421,7 @@ public String getDatabaseSchemaVersion(String key, String defaultValue) {
DEFAULT_VALUES.put(TOP_DESCRIPTION, "");
DEFAULT_VALUES.put(TOP_DESCRIPTION_PREFIX, "");
DEFAULT_VALUES.put(CUSTOM_CSS_CONTENT, SystemSettingsUtils.getCustomCssContent());
DEFAULT_VALUES.put(DATA_POINT_EXTENDED_NAME_LENGTH_IN_REPORTS_LIMIT, SystemSettingsUtils.getDataPointExtendedNameLengthInReportsLimit());
}

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED, rollbackFor = SQLException.class)
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/mango/service/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public EventService() {
eventDAO = new EventDAO();
userEventDAO = new UserEventDAO();
userCommentDAO = ApplicationBeans.getUserCommentDaoBean();
systemSettingsService = new SystemSettingsService();
systemSettingsService = ApplicationBeans.getBean("systemSettingsService", SystemSettingsService.class);
}

class UserPendingEventRetriever extends AbstractBeforeAfterWorkItem implements Runnable {
Expand Down
Loading

0 comments on commit 5f8fbf1

Please sign in to comment.