Search in sources :

Example 1 with ProcessResult

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);
            }
        }
    }
}
Also used : ModuleLicense(com.serotonin.m2m2.util.license.ModuleLicense) LicenseFeature(com.serotonin.m2m2.util.license.LicenseFeature)

Example 2 with ProcessResult

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);
    }
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) RestValidationFailedException(com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)

Example 3 with ProcessResult

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);
    }
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) RestValidationFailedException(com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)

Example 4 with ProcessResult

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;
    }
}
Also used : RestValidationMessage(com.serotonin.m2m2.web.mvc.rest.v1.message.RestValidationMessage) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage)

Example 5 with ProcessResult

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);
    }
}
Also used : ValidationException(com.serotonin.m2m2.vo.exception.ValidationException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult)

Aggregations

ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)165 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)132 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)31 User (com.serotonin.m2m2.vo.User)31 ArrayList (java.util.ArrayList)28 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)27 JsonException (com.serotonin.json.JsonException)21 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)20 JsonObject (com.serotonin.json.type.JsonObject)13 HashMap (java.util.HashMap)12 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)11 StringStringPair (com.serotonin.db.pair.StringStringPair)9 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)9 IOException (java.io.IOException)9 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)8 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)8 AbstractVO (com.serotonin.m2m2.vo.AbstractVO)8 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)8 SystemSettingsDao (com.serotonin.m2m2.db.dao.SystemSettingsDao)7 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)7