Search in sources :

Example 61 with ProcessResult

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

the class AbstractDwr method getCopy.

@DwrPermission(user = true)
public ProcessResult getCopy(int id) {
    // Get a Full Copy
    VO vo = dao.getFull(id);
    ProcessResult response = new ProcessResult();
    String name = StringUtils.abbreviate(TranslatableMessage.translate(getTranslations(), "common.copyPrefix", vo.getName()), 40);
    // Setup the Copy
    VO copy = (VO) vo.copy();
    copy.setId(Common.NEW_ID);
    copy.setName(name);
    copy.setXid(dao.generateUniqueXid());
    response.addData("vo", copy);
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) AbstractVO(com.serotonin.m2m2.vo.AbstractVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 62 with ProcessResult

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

the class AbstractDwr method get.

/* (non-Javadoc)
     * @see com.deltamation.mango.downtime.web.AbstractBasicDwr#get(int)
     */
@DwrPermission(user = true)
@Override
public ProcessResult get(int id) {
    VO vo;
    if (id == Common.NEW_ID) {
        vo = dao.getNewVo();
    } else {
        vo = dao.get(id);
    }
    ProcessResult response = new ProcessResult();
    response.addData("vo", vo);
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) AbstractVO(com.serotonin.m2m2.vo.AbstractVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 63 with ProcessResult

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

the class AbstractDwr method saveFull.

/**
 * Save the VO AND FDAO Data
 *
 * Conversion for the VO must be added by extending DwrConversionDefinition
 *
 * @return
 */
@DwrPermission(admin = true)
public ProcessResult saveFull(VO vo) {
    // TODO combine with save()
    ProcessResult response = new ProcessResult();
    if (vo.getXid() == null) {
        vo.setXid(dao.generateUniqueXid());
    }
    vo.validate(response);
    if (!response.getHasMessages()) {
        try {
            dao.saveFull(vo);
        } 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) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 64 with ProcessResult

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

the class AbstractDwr method save.

/**
 * Save the VO
 *
 * Conversion for the VO must be added by extending DwrConversionDefinition
 *
 * @return
 */
@DwrPermission(admin = true)
public ProcessResult save(VO vo) {
    ProcessResult response = new ProcessResult();
    if (vo.getXid() == null) {
        vo.setXid(dao.generateUniqueXid());
    }
    vo.validate(response);
    if (!response.getHasMessages()) {
        try {
            dao.save(vo);
        } catch (Exception e) {
            // Handle the exceptions.
            LOG.error(e);
            String context = vo.getName();
            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) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 65 with ProcessResult

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

the class AbstractRTDwr method getCopy.

@SuppressWarnings("unchecked")
@DwrPermission(user = true)
@Override
public ProcessResult getCopy(int id) {
    ProcessResult response = super.getCopy(id);
    // Ensure he isn't running
    ((AbstractActionVO<?>) response.getData().get("vo")).setEnabled(false);
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) AbstractActionVO(com.serotonin.m2m2.vo.AbstractActionVO) 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