Skip to content

Commit

Permalink
Merge pull request #2781 from SCADA-LTS/fix/#2758_Fixed_xid_validatio…
Browse files Browse the repository at this point in the history
…n_error_handling

#2758 Fixed xid validation error handling
  • Loading branch information
Limraj authored Feb 14, 2024
2 parents 378a5e8 + b6f60ab commit 4b8c899
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 25 deletions.
4 changes: 4 additions & 0 deletions WebContent/WEB-INF/jsp/publisherEdit.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
for (var i=0; i<response.messages.length; i++)
showMessage(response.messages[i].contextKey +"Msg", response.messages[i].contextualMessage);
} else {
var errorMessages = document.getElementsByClassName("formError");
for (var j = 0; j < errorMessages.length; j++) {
errorMessages[j].innerHTML = '';
}
showMessage("message", "<fmt:message key="publisherEdit.saved"/>");
showHttpSenderTest();
}
Expand Down
6 changes: 6 additions & 0 deletions src/com/serotonin/mango/vo/event/CompoundEventDetectorVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import com.serotonin.util.StringUtils;
import com.serotonin.web.dwr.DwrResponseI18n;
import com.serotonin.web.i18n.LocalizableMessage;
import org.scada_lts.mango.service.CompoundEventDetectorService;
import org.scada_lts.utils.XidUtils;

/**
* @author Matthew Lohbihler
Expand Down Expand Up @@ -77,6 +79,10 @@ public String getTypeKey() {
}

public void validate(DwrResponseI18n response) {

CompoundEventDetectorService compoundEventDetectorService = new CompoundEventDetectorService();
XidUtils.validateXid(response, compoundEventDetectorService::isXidUnique, xid, id);

if (StringUtils.isEmpty(name))
response.addContextualMessage("name", "compoundDetectors.validation.nameRequired");

Expand Down
5 changes: 5 additions & 0 deletions src/com/serotonin/mango/vo/event/EventHandlerVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.serotonin.web.i18n.LocalizableMessage;
import org.scada_lts.mango.service.EventService;
import org.scada_lts.mango.service.ScriptService;
import org.scada_lts.utils.XidUtils;

@JsonRemoteEntity
public class EventHandlerVO implements Serializable,
Expand Down Expand Up @@ -383,6 +384,10 @@ public String getTypeKey() {
}

public void validate(DwrResponseI18n response) {

EventService eventService = new EventService();
XidUtils.validateXid(response, eventService::isXidUnique, xid, id);

if (handlerType == TYPE_SET_POINT) {
DataPointVO dp = new DataPointDao().getDataPoint(targetPointId);

Expand Down
6 changes: 6 additions & 0 deletions src/com/serotonin/mango/vo/event/MaintenanceEventVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.serotonin.web.dwr.DwrResponseI18n;
import com.serotonin.web.i18n.LocalizableMessage;
import com.serotonin.web.taglib.DateFunctions;
import org.scada_lts.mango.service.MaintenanceEventService;
import org.scada_lts.utils.XidUtils;

@JsonRemoteEntity
public class MaintenanceEventVO implements ChangeComparable<MaintenanceEventVO>, JsonSerializable {
Expand Down Expand Up @@ -423,6 +425,10 @@ public String getTypeKey() {
}

public void validate(DwrResponseI18n response) {

MaintenanceEventService maintenanceEventService = new MaintenanceEventService();
XidUtils.validateXid(response, maintenanceEventService::isXidUnique, xid, id);

if (StringUtils.isLengthGreaterThan(alias, 50))
response.addContextualMessage("alias", "maintenanceEvents.validate.aliasTooLong");

Expand Down
6 changes: 6 additions & 0 deletions src/com/serotonin/mango/vo/event/ScheduledEventVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import com.serotonin.web.dwr.DwrResponseI18n;
import com.serotonin.web.i18n.LocalizableMessage;
import com.serotonin.web.taglib.DateFunctions;
import org.scada_lts.mango.service.ScheduledEventService;
import org.scada_lts.utils.XidUtils;

/**
* @author Matthew Lohbihler
Expand Down Expand Up @@ -277,6 +279,10 @@ public String getTypeKey() {
}

public void validate(DwrResponseI18n response) {

ScheduledEventService scheduledEventService = new ScheduledEventService();
XidUtils.validateXid(response, scheduledEventService::isXidUnique, xid, id);

if (StringUtils.isLengthGreaterThan(alias, 50))
response.addContextualMessage("alias", "scheduledEvents.validate.aliasTooLong");

Expand Down
6 changes: 6 additions & 0 deletions src/com/serotonin/mango/vo/link/PointLinkVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.serotonin.mango.vo.DataPointVO;
import com.serotonin.web.dwr.DwrResponseI18n;
import com.serotonin.web.i18n.LocalizableMessage;
import org.scada_lts.mango.service.PointLinkService;
import org.scada_lts.utils.XidUtils;

/**
* @author Matthew Lohbihler
Expand Down Expand Up @@ -129,6 +131,10 @@ public String getTypeKey() {
}

public void validate(DwrResponseI18n response) {

PointLinkService pointLinkService = new PointLinkService();
XidUtils.validateXid(response, pointLinkService::isXidUnique, xid, id);

if (sourcePointId == 0)
response.addContextualMessage("sourcePointId", "pointLinks.validate.sourceRequired");
if (targetPointId == 0)
Expand Down
6 changes: 6 additions & 0 deletions src/com/serotonin/mango/vo/mailingList/MailingList.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import com.serotonin.mango.Common;
import com.serotonin.util.StringUtils;
import com.serotonin.web.dwr.DwrResponseI18n;
import org.scada_lts.mango.service.MailingListService;
import org.scada_lts.service.CommunicationChannelTypable;
import org.scada_lts.utils.XidUtils;

@JsonRemoteEntity
public class MailingList extends EmailRecipient {
Expand Down Expand Up @@ -152,6 +154,10 @@ public void appendAllAddresses(Set<String> addresses, CommunicationChannelTypabl
}

public void validate(DwrResponseI18n response) {

MailingListService mailingListService = new MailingListService();
XidUtils.validateXid(response, mailingListService::isXidUnique, xid, id);

// Check that required fields are present.
if (StringUtils.isEmpty(name))
response.addContextualMessage("name", "mailingLists.validate.nameRequired");
Expand Down
5 changes: 0 additions & 5 deletions src/com/serotonin/mango/web/dwr/CompoundEventsDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ public DwrResponseI18n saveCompoundEvent(int id, String xid, String name, int al

CompoundEventDetectorDao compoundEventDetectorDao = new CompoundEventDetectorDao();

if (StringUtils.isEmpty(xid))
response.addContextualMessage("xid", "validate.required");
else if (!compoundEventDetectorDao.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");

ced.validate(response);

// Save it
Expand Down
5 changes: 0 additions & 5 deletions src/com/serotonin/mango/web/dwr/MailingListsDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ public DwrResponseI18n saveMailingList(int id, String xid, String name,
ml.setCronPattern(cronPattern);
ml.setCollectInactiveEmails(collectInactiveEmails);

if (StringUtils.isEmpty(xid))
response.addContextualMessage("xid", "validate.required");
else if (!mailingListDao.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");

ml.validate(response);

if (!response.getHasMessages()) {
Expand Down
5 changes: 0 additions & 5 deletions src/com/serotonin/mango/web/dwr/MaintenanceEventsDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ public DwrResponseI18n saveMaintenanceEvent(int id, String xid, int dataSourceId
DwrResponseI18n response = new DwrResponseI18n();
MaintenanceEventDao maintenanceEventDao = new MaintenanceEventDao();

if (StringUtils.isEmpty(xid))
response.addContextualMessage("xid", "validate.required");
else if (!maintenanceEventDao.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");

e.validate(response);

// Save the maintenance event
Expand Down
5 changes: 0 additions & 5 deletions src/com/serotonin/mango/web/dwr/PointLinksDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ public DwrResponseI18n savePointLink(int id, String xid, int sourcePointId, int
DwrResponseI18n response = new DwrResponseI18n();
PointLinkDao pointLinkDao = new PointLinkDao();

if (StringUtils.isEmpty(xid))
response.addContextualMessage("xid", "validate.required");
else if (!pointLinkDao.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");

vo.validate(response);

// Save it
Expand Down
5 changes: 0 additions & 5 deletions src/com/serotonin/mango/web/dwr/ScheduledEventsDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ public DwrResponseI18n saveScheduledEvent(int id, String xid, String alias, int
DwrResponseI18n response = new DwrResponseI18n();
ScheduledEventDao scheduledEventDao = new ScheduledEventDao();

if (StringUtils.isEmpty(xid))
response.addContextualMessage("xid", "validate.required");
else if (!scheduledEventDao.isXidUnique(xid, id))
response.addContextualMessage("xid", "validate.xidUsed");

se.validate(response);

// Save the scheduled event
Expand Down

0 comments on commit 4b8c899

Please sign in to comment.