use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class DataSourceTypePointsLimit method checkLimit.
public static void checkLimit(String dataSourceType, ProcessResult response) {
for (DataSourceTypePointsLimit limit : ModuleRegistry.getLicenseEnforcements(DataSourceTypePointsLimit.class)) {
if (StringUtils.equals(dataSourceType, limit.getDataSourceType())) {
// Found a limit object.
ModuleLicense license = ModuleRegistry.getModule(limit.getModuleName()).license();
int pointLimit = -1;
if (license == null)
// No license.
pointLimit = limit.getNoLicenselimit();
else if (limit.getFeatureName() != null) {
try {
LicenseFeature feature = license.getFeature(limit.getFeatureName());
if (feature != null)
pointLimit = Integer.parseInt(feature.getValue());
} catch (NumberFormatException e) {
// If the feature is non-numeric, we assume that it is unlimited.
}
}
if (pointLimit != -1) {
// Find out how many points there are for this type of data source.
int count = DataPointDao.instance.countPointsForDataSourceType(dataSourceType);
// Apply count restriction.
if (count > pointLimit)
response.addGenericMessage("license.dataSourcePointLimit", pointLimit);
}
}
}
}
use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class AbstractPublisherModel method validate.
/*
* (non-Javadoc)
* @see com.serotonin.m2m2.web.mvc.rest.v1.model.AbstractRestModel#validate(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)
*/
public void validate(RestProcessResult<?> result) throws RestValidationFailedException {
ProcessResult validation = new ProcessResult();
this.data.validate(validation);
if (validation.getHasMessages()) {
result.addValidationMessages(validation);
throw new RestValidationFailedException(this, result);
}
}
use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class AbstractDataSourceModel method validate.
/*
* (non-Javadoc)
* @see com.serotonin.m2m2.web.mvc.rest.v1.model.AbstractRestModel#validate(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)
*/
public void validate(RestProcessResult<?> result) throws RestValidationFailedException {
ProcessResult validation = new ProcessResult();
this.data.validate(validation);
if (validation.getHasMessages()) {
result.addValidationMessages(validation);
throw new RestValidationFailedException(this, result);
}
}
use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class AbstractVoModel method validate.
/*
* (non-Javadoc)
* @see com.serotonin.m2m2.web.mvc.rest.v1.model.AbstractRestModel#validate(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)
*/
@Override
public boolean validate() {
ProcessResult validation = new ProcessResult();
this.data.validate(validation);
if (validation.getHasMessages()) {
// Add our messages to the list
for (ProcessMessage message : validation.getMessages()) {
if (message.getGenericMessage() != null) {
this.messages.add(new RestValidationMessage(message.getGenericMessage(), RestMessageLevel.ERROR, ""));
} else {
this.messages.add(new RestValidationMessage(message.getContextualMessage(), RestMessageLevel.ERROR, message.getContextKey()));
}
}
return false;
} else {
// Validated ok
return true;
}
}
use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.
the class Validatable method ensureValid.
/**
* Validates the object and throws a ValidationException if it is not valid
*
* @throws ValidationException
*/
public default void ensureValid() throws ValidationException {
ProcessResult response = new ProcessResult();
this.validate(response);
if (response.getHasMessages()) {
throw new ValidationException(response);
}
}
Aggregations