Search in sources :

Example 86 with ProcessResult

use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.

the class SystemSettingsDwr method saveThreadPoolSettings.

@DwrPermission(admin = true)
public ProcessResult saveThreadPoolSettings(int highPriorityCorePoolSize, int highPriorityMaxPoolSize, int medPriorityCorePoolSize, int lowPriorityCorePoolSize) {
    ProcessResult response = new ProcessResult();
    SystemSettingsDao systemSettingsDao = SystemSettingsDao.instance;
    if (highPriorityCorePoolSize > 0) {
        systemSettingsDao.setIntValue(SystemSettingsDao.HIGH_PRI_CORE_POOL_SIZE, highPriorityCorePoolSize);
    } else {
        response.addContextualMessage(SystemSettingsDao.HIGH_PRI_CORE_POOL_SIZE, "validate.greaterThanZero");
    }
    if (highPriorityMaxPoolSize < BackgroundProcessing.HIGH_PRI_MAX_POOL_SIZE_MIN) {
        response.addContextualMessage(SystemSettingsDao.HIGH_PRI_MAX_POOL_SIZE, "validate.greaterThanOrEqualTo", BackgroundProcessing.HIGH_PRI_MAX_POOL_SIZE_MIN);
    } else if (highPriorityMaxPoolSize < highPriorityCorePoolSize) {
        response.addContextualMessage(SystemSettingsDao.HIGH_PRI_MAX_POOL_SIZE, "systemSettings.threadPools.validate.maxPoolMustBeGreaterThanCorePool");
    } else {
        systemSettingsDao.setIntValue(SystemSettingsDao.HIGH_PRI_MAX_POOL_SIZE, highPriorityMaxPoolSize);
    }
    // core pool thread is available
    if (medPriorityCorePoolSize >= BackgroundProcessing.MED_PRI_MAX_POOL_SIZE_MIN) {
        // Due to the pool type we should set these to the same values
        systemSettingsDao.setIntValue(SystemSettingsDao.MED_PRI_CORE_POOL_SIZE, medPriorityCorePoolSize);
    } else {
        response.addContextualMessage(SystemSettingsDao.MED_PRI_CORE_POOL_SIZE, "validate.greaterThanOrEqualTo", BackgroundProcessing.MED_PRI_MAX_POOL_SIZE_MIN);
    }
    if (lowPriorityCorePoolSize >= BackgroundProcessing.LOW_PRI_MAX_POOL_SIZE_MIN) {
        systemSettingsDao.setIntValue(SystemSettingsDao.LOW_PRI_CORE_POOL_SIZE, lowPriorityCorePoolSize);
    } else {
        response.addContextualMessage(SystemSettingsDao.LOW_PRI_CORE_POOL_SIZE, "validate.greaterThanOrEqualTo", BackgroundProcessing.LOW_PRI_MAX_POOL_SIZE_MIN);
    }
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) SystemSettingsDao(com.serotonin.m2m2.db.dao.SystemSettingsDao) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 87 with ProcessResult

use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.

the class TemplateDwr method getDataPointTemplate.

/**
 * Save a template
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getDataPointTemplate(int id) {
    ProcessResult result = new ProcessResult();
    result.addData("template", dao.get(id));
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 88 with ProcessResult

use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.

the class TemplateDwr method getNewDataPointTemplate.

/**
 * Get a new Data Point Template
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getNewDataPointTemplate() {
    ProcessResult response = new ProcessResult();
    DataPointPropertiesTemplateVO vo = new DataPointPropertiesTemplateVO();
    vo.setDefinition(new DataPointPropertiesTemplateDefinition());
    response.addData("vo", vo);
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) DataPointPropertiesTemplateDefinition(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateDefinition) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 89 with ProcessResult

use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.

the class TemplateDwr method saveDataPointTemplate.

/**
 * Save a Data Point template
 * @return
 */
@DwrPermission(user = true)
public ProcessResult saveDataPointTemplate(DataPointPropertiesTemplateVO vo) {
    ProcessResult response = new ProcessResult();
    if (vo.getXid() == null) {
        vo.setXid(dao.generateUniqueXid());
    }
    // we need a name for validation so set XID and name to the same thing.
    if (StringUtils.isEmpty(vo.getName())) {
        vo.setName(vo.getXid());
    }
    vo.validate(response);
    if (!response.getHasMessages()) {
        try {
            dao.save(vo);
            updateDataPointsUsingTemplate(vo, response);
        } catch (Exception e) {
            // Handle the exceptions.
            LOG.error(e);
            String context = vo.getName();
            if (context == null) {
                context = vo.getXid();
            }
            if (context == null) {
                context = vo.getXid();
            }
            if (context == null) {
                context = Integer.toString(vo.getId());
            }
            if (e instanceof DuplicateKeyException)
                response.addContextualMessage(context, "table.edit.alreadyExists");
            else
                response.addContextualMessage(context, "table.edit.unableToSave", e.getMessage());
        }
    }
    response.addData("vo", vo);
    // Add in case it fails
    response.addData("id", vo.getId());
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 90 with ProcessResult

use of com.serotonin.m2m2.i18n.ProcessResult in project ma-core-public by infiniteautomation.

the class TemplateDwr method getDataPointTemplates.

/**
 * Save a template
 * @return
 */
@DwrPermission(user = true)
public ProcessResult getDataPointTemplates(int dataTypeId) {
    ProcessResult result = new ProcessResult();
    List<DataPointPropertiesTemplateVO> templates = dao.getDataPointTemplatesByDataTypeId(dataTypeId);
    result.addData(TemplateDao.instance.tableName, templates);
    return result;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

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