Skip to content

Commit

Permalink
Merge pull request #2895 from SCADA-LTS/feature/#2773_Enhance_copy_pa…
Browse files Browse the repository at this point in the history
…ste_datapoint_properties_by_including_event_detectors2

#2773 enhance copy paste datapoint properties by including event detectors
  • Loading branch information
Limraj authored May 24, 2024
2 parents 4b7cca3 + 55bc43b commit bd73b17
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 40 deletions.
21 changes: 13 additions & 8 deletions WebContent/WEB-INF/jsp/dataSourceEdit.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@
if (typeof appendPointListColumnFunctions == 'function')
appendPointListColumnFunctions(pointListColumnHeaders, pointListColumnFunctions);
pointListColumnHeaders.push("");
pointListColumnHeaders.push(function(td) {
td.width = "8%";
});
pointListColumnFunctions.push(function(p) {
return writeImage("editImg"+ p.id, null, "icon_ds_edit", "<fmt:message key="pointDetails.editPoint"/>", "editPoint("+ p.id +")");
});
pointListColumnHeaders.push("");
pointListColumnFunctions.push(function(p) {
return writeImage("editImg"+ p.id, null, "icon_comp_edit", "<fmt:message key="pointEdit.props.props"/>", "window.location='data_point_edit.shtm?dpid="+ p.id +"'");
return writeImage("editImg" + p.id, null, "icon_ds_edit", "<fmt:message key='pointDetails.editPoint'/>", "editPoint(" + p.id + ")") +
writeImage("editImg" + p.id, null, "icon_comp_edit", "<fmt:message key='pointEdit.props.props'/>", "window.location='data_point_edit.shtm?dpid=" + p.id + "'") +
writeImage("editImg" + p.id, null, "icon_ds_add", "<fmt:message key='common.copy'/>", "copyDataPoint(" + ${dataSource.id} + ", " + p.id + ");");
});
var headers = $("pointListHeaders");
Expand Down Expand Up @@ -328,6 +326,13 @@
stopImageFader($("enableAllImg"));
writePointList(points);
}
function copyDataPoint(fromDataSourceId, dataPointId) {
return DataSourceEditDwr.copyDataPoint(fromDataSourceId, dataPointId, function(response) {
writePointList(response.data.points);
editPoint(response.data.id);
});
}
</script>

<table class="borderDiv marB subPageHeader" id="alarmsTable" style="display: block; max-height: 300px; overflow-y: auto; width: 59%;">
Expand Down
2 changes: 1 addition & 1 deletion WebContent/WEB-INF/tags/pointList.tag
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</td>

<td>
<div id="pointDetails" class="borderDiv marB" style="display: none; width: 100%;position: sticky;">
<div id="pointDetails" class="borderDiv marB" style="display: none; width: 100%;position: sticky;top: 0;">
<table width="100%">
<tr>
<td>
Expand Down
41 changes: 41 additions & 0 deletions src/com/serotonin/mango/rt/dataSource/DataSourceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.List;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.serotonin.mango.Common;
import com.serotonin.mango.DataTypes;
import com.serotonin.mango.rt.dataImage.types.AlphanumericValue;
import com.serotonin.mango.rt.dataImage.types.BinaryValue;
Expand All @@ -33,8 +35,15 @@
import com.serotonin.mango.view.text.MultistateRenderer;
import com.serotonin.mango.view.text.MultistateValue;
import com.serotonin.mango.view.text.TextRenderer;
import com.serotonin.mango.vo.DataPointVO;
import com.serotonin.mango.vo.dataSource.DataSourceVO;
import com.serotonin.mango.vo.event.PointEventDetectorVO;
import com.serotonin.util.StringUtils;
import com.serotonin.web.i18n.LocalizableException;
import com.serotonin.web.i18n.LocalizableMessage;
import org.scada_lts.ds.messaging.protocol.mqtt.MqttPointLocatorVO;
import org.scada_lts.mango.service.DataPointService;
import org.scada_lts.utils.MqttUtils;

/**
* @author Matthew Lohbihler
Expand Down Expand Up @@ -152,4 +161,36 @@ public static MangoValue getValue(String valueStr, int dataTypeId,

return null;
}

public static DataPointVO copyAndSaveDataPoint(DataSourceVO<?> dataSource, DataPointVO dataPoint, DataPointService dataPointService) {
DataPointVO dataPointCopy = dataPoint.copy();
dataPointCopy.setId(Common.NEW_ID);
dataPointCopy.setXid(new DataPointService().generateUniqueXid());
dataPointCopy.setName(generateCopyName(Common.getBundle(), dataPoint.getName(), 250));
dataPointCopy.setDataSourceId(dataSource.getId());
dataPointCopy.setDataSourceName(dataSource.getName());
dataPointCopy.setDeviceName(dataSource.getName());
dataPointCopy.setEnabled(false);
dataPointCopy.getComments().clear();

if(dataPointCopy.getPointLocator() instanceof MqttPointLocatorVO) {
MqttPointLocatorVO pointLocator = dataPointCopy.getPointLocator();
pointLocator.setClientId(MqttUtils.generateUniqueClientId());
}

//Copy event detectors
for (PointEventDetectorVO pointEventDetector: dataPointCopy.getEventDetectors()) {
pointEventDetector.setId(Common.NEW_ID);
pointEventDetector.setXid(new DataPointService().generateEventDetectorUniqueXid(dataPointCopy.getId()));
pointEventDetector.njbSetDataPoint(dataPointCopy);
}
dataPointService.saveDataPoint(dataPointCopy);
//Copy permissions
dataPointService.copyPermissions(dataPoint.getId(), dataPointCopy.getId());
return dataPointCopy;
}

public static String generateCopyName(ResourceBundle bundle, String name, int length) {
return StringUtils.truncate(LocalizableMessage.getMessage(bundle, "common.copyPrefix", name), length);
}
}
17 changes: 17 additions & 0 deletions src/com/serotonin/mango/web/dwr/DataSourceEditDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
import org.scada_lts.serial.SerialPortService;
import org.scada_lts.serial.SerialPortWrapperAdapter;

import static com.serotonin.mango.rt.dataSource.DataSourceUtils.copyAndSaveDataPoint;
import static com.serotonin.mango.util.LoggingScriptUtils.infoErrorExecutionScript;
import static com.serotonin.mango.util.SqlDataSourceUtils.createSqlDataSourceVO;
import static org.scada_lts.utils.AlarmLevelsDwrUtils.*;
Expand Down Expand Up @@ -2969,4 +2970,20 @@ public DwrResponseI18n saveRadiuinoPointLocator(int id, String xid,
String name, RadiuinoPointLocatorVO locator) {
return validatePoint(id, xid, name, locator, null);
}

public DwrResponseI18n copyDataPoint(final int dataSourceId, final int dataPointId) {
DataSourceService dataSourceService = new DataSourceService();
DataSourceVO<?> dataSource = dataSourceService.getDataSource(dataSourceId);

DataPointService dataPointService = new DataPointService();
DataPointVO dataPoint = dataPointService.getDataPoint(dataPointId);

DataPointVO dataPointCopy = copyAndSaveDataPoint(dataSource, dataPoint, new DataPointService());
DwrResponseI18n response = new DwrResponseI18n();

response.addData("points", getPoints());
response.addData("id", dataPointCopy.getId());

return response;
}
}
35 changes: 4 additions & 31 deletions src/org/scada_lts/mango/service/DataSourceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,17 @@
import com.serotonin.mango.vo.DataPointVO;
import com.serotonin.mango.vo.User;
import com.serotonin.mango.vo.dataSource.DataSourceVO;
import com.serotonin.mango.vo.event.PointEventDetectorVO;
import com.serotonin.util.StringUtils;
import com.serotonin.web.i18n.LocalizableMessage;
import org.scada_lts.dao.DAO;
import org.scada_lts.dao.DataPointDAO;
import org.scada_lts.dao.DataSourceDAO;
import org.scada_lts.dao.MaintenanceEventDAO;
import org.scada_lts.dao.model.ScadaObjectIdentifier;
import org.scada_lts.ds.messaging.protocol.mqtt.MqttPointLocatorVO;
import org.scada_lts.ds.state.UserChangeEnableStateDs;
import org.scada_lts.ds.state.UserCpChangeEnableStateDs;
import org.scada_lts.mango.adapter.MangoDataSource;
import org.scada_lts.mango.adapter.MangoPointHierarchy;
import org.scada_lts.permissions.service.GetDataSourcesWithAccess;
import org.scada_lts.permissions.service.GetObjectsWithAccess;
import org.scada_lts.utils.MqttUtils;
import org.scada_lts.web.beans.ApplicationBeans;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.stereotype.Service;
Expand All @@ -52,6 +47,8 @@
import java.util.ResourceBundle;
import java.util.stream.Collectors;

import static com.serotonin.mango.rt.dataSource.DataSourceUtils.copyAndSaveDataPoint;
import static com.serotonin.mango.rt.dataSource.DataSourceUtils.generateCopyName;
import static org.scada_lts.permissions.service.GetDataPointsWithAccess.filteringByAccess;

/**
Expand Down Expand Up @@ -204,7 +201,7 @@ public int copyDataSource(final int dataSourceId, final ResourceBundle bundle) {
dataSourceCopy.setState(new UserCpChangeEnableStateDs());

//TODO seroUtils
dataSourceCopy.setName(StringUtils.truncate(LocalizableMessage.getMessage(bundle, "common.copyPrefix", dataSource.getName()), 40));
dataSourceCopy.setName(generateCopyName(bundle, dataSource.getName(), 40));

saveDataSource(dataSourceCopy);

Expand All @@ -213,31 +210,7 @@ public int copyDataSource(final int dataSourceId, final ResourceBundle bundle) {

//Copy points
for (DataPointVO dataPoint: dataPointService.getDataPoints(dataSourceId, null)) {
DataPointVO dataPointCopy = dataPoint.copy();
dataPointCopy.setId(Common.NEW_ID);
dataPointCopy.setXid(new DataPointService().generateUniqueXid());
dataPointCopy.setName(dataPoint.getName());
dataPointCopy.setDataSourceId(dataSourceCopy.getId());
dataPointCopy.setDataSourceName(dataSourceCopy.getName());
dataPointCopy.setDeviceName(dataSourceCopy.getName());
dataPointCopy.setEnabled(dataSourceCopy.isEnabled());
dataPointCopy.getComments().clear();

if(dataPointCopy.getPointLocator() instanceof MqttPointLocatorVO) {
MqttPointLocatorVO pointLocator = dataPointCopy.getPointLocator();
pointLocator.setClientId(MqttUtils.generateUniqueClientId());
}
dataPointService.saveDataPoint(dataPointCopy);

//Copy event detectors
for (PointEventDetectorVO pointEventDetector: dataPointCopy.getEventDetectors()) {
pointEventDetector.setId(Common.NEW_ID);
pointEventDetector.setXid(new DataPointService().generateEventDetectorUniqueXid(dataPointCopy.getId()));
pointEventDetector.njbSetDataPoint(dataPointCopy);
}
dataPointService.saveDataPoint(dataPointCopy);
//Copy permissions
dataPointService.copyPermissions(dataPoint.getId(), dataPointCopy.getId());
copyAndSaveDataPoint(dataSourceCopy, dataPoint, dataPointService);
}
return dataSourceCopy.getId();
}
Expand Down

0 comments on commit bd73b17

Please sign in to comment.