Search in sources :

Example 61 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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 62 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission 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)

Example 63 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class AbstractRTDwr method save.

/**
 * Save the Process
 * @return
 */
@DwrPermission(admin = true)
@Override
public ProcessResult save(VO vo) {
    ProcessResult response = new ProcessResult();
    vo.validate(response);
    if (!response.getHasMessages()) {
        // Save it
        try {
            runtimeManager.save(vo);
        } catch (Exception e) {
            // Handle the exceptions.
            // TODO Clean up and generify these messages to some central place
            LOG.error(e);
            if (e instanceof DuplicateKeyException)
                response.addMessage(this.keyName + "Errors", new TranslatableMessage("dsEdit.alreadyExists"));
            else
                response.addMessage(this.keyName + "Errors", new TranslatableMessage("dsEdit.unableToSave"));
        }
    }
    response.addData("vo", vo);
    // In case there are errors
    response.addData("id", vo.getId());
    return response;
}
Also used : ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) 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 DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class BaseDwr method forcePointRead.

@DwrPermission(user = true)
public void forcePointRead(int pointId) {
    User user = Common.getUser();
    DataPointVO point = DataPointDao.instance.getDataPoint(pointId, false);
    // Check permissions.
    Permissions.ensureDataPointReadPermission(user, point);
    Common.runtimeManager.forcePointRead(pointId);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) User(com.serotonin.m2m2.vo.User) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 65 with DwrPermission

use of com.serotonin.m2m2.web.dwr.util.DwrPermission in project ma-core-public by infiniteautomation.

the class BaseDwr method initializeLongPoll.

@DwrPermission(anonymous = true)
public Map<String, Object> initializeLongPoll(int pollSessionId, LongPollRequest request) {
    LongPollData data = getLongPollData(pollSessionId, true);
    data.setRequest(request);
    return doLongPoll(pollSessionId);
}
Also used : LongPollData(com.serotonin.m2m2.web.dwr.longPoll.LongPollData) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Aggregations

DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)220 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)126 User (com.serotonin.m2m2.vo.User)56 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)47 ArrayList (java.util.ArrayList)35 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)24 HashMap (java.util.HashMap)21 StringStringPair (com.serotonin.db.pair.StringStringPair)11 SystemSettingsDao (com.serotonin.m2m2.db.dao.SystemSettingsDao)11 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)10 IOException (java.io.IOException)9 DateTime (org.joda.time.DateTime)9 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)9 AbstractVO (com.serotonin.m2m2.vo.AbstractVO)8 AnonymousUser (com.serotonin.m2m2.vo.AnonymousUser)8 LinkedHashMap (java.util.LinkedHashMap)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)7 ShareUser (com.serotonin.m2m2.view.ShareUser)7 ResultsWithTotal (com.serotonin.m2m2.db.dao.ResultsWithTotal)6 ReportVO (com.serotonin.m2m2.reports.vo.ReportVO)6