Search in sources :

Example 6 with LicenseViolatedException

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

the class DataPointDwr method saveFull.

/**
 * Not currently being used, see DataSourceEditDwr
 *
 * Save the VO AND FDAO Data
 *
 * Conversion for the VO must be added by extending DwrConversionDefinition
 *
 * @return
 */
@Override
@DwrPermission(user = true)
public ProcessResult saveFull(DataPointVO vo) {
    // TODO combine with save()
    ProcessResult response = new ProcessResult();
    if (vo.getXid() == null) {
        vo.setXid(dao.generateUniqueXid());
    }
    vo.validate(response);
    if (!response.getHasMessages()) {
        // TODO            DataPointDefaulter defaulter = null;
        try {
            Common.runtimeManager.saveDataPoint(vo);
        // TODO             if (defaulter != null)
        // defaulter.postSave(vo);
        } catch (LicenseViolatedException e) {
            LOG.error(e);
            response.addMessage(e.getErrorMessage());
        } 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 : LicenseViolatedException(com.serotonin.m2m2.LicenseViolatedException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) LicenseViolatedException(com.serotonin.m2m2.LicenseViolatedException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 7 with LicenseViolatedException

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

the class EventDetectorImporter method importImpl.

@Override
protected void importImpl() {
    String dataPointXid = json.getString("dataPointXid");
    DataPointVO dpvo;
    // Everyone is in the same thread so no synchronization on dataPointMap required.
    if (dataPointMap.containsKey(dataPointXid))
        dpvo = dataPointMap.get(dataPointXid);
    else if (StringUtils.isEmpty(dataPointXid) || (dpvo = DataPointDao.instance.getByXid(dataPointXid)) == null) {
        addFailureMessage("emport.error.missingPoint", dataPointXid);
        return;
    } else {
        dataPointMap.put(dataPointXid, dpvo);
        // We're only going to use this to house event detectors imported in the eventDetectors object.
        dpvo.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>());
    }
    String typeStr = json.getString("type");
    if (typeStr == null)
        addFailureMessage("emport.error.ped.missingAttr", "type");
    EventDetectorDefinition<?> def = ModuleRegistry.getEventDetectorDefinition(typeStr);
    if (def == null) {
        addFailureMessage("emport.error.ped.invalid", "type", typeStr, ModuleRegistry.getEventDetectorDefinitionTypes());
        return;
    }
    JsonArray handlerXids = json.getJsonArray("handlers");
    if (handlerXids != null)
        for (int k = 0; k < handlerXids.size(); k += 1) {
            AbstractEventHandlerVO<?> eh = EventHandlerDao.instance.getByXid(handlerXids.getString(k));
            if (eh == null) {
                addFailureMessage("emport.eventHandler.missing", handlerXids.getString(k));
                return;
            }
        }
    AbstractEventDetectorVO<?> importing = def.baseCreateEventDetectorVO();
    importing.setDefinition(def);
    String xid = json.getString("xid");
    // Create a new one
    importing.setId(Common.NEW_ID);
    importing.setXid(xid);
    AbstractPointEventDetectorVO<?> dped = (AbstractPointEventDetectorVO<?>) importing;
    dped.njbSetDataPoint(dpvo);
    dpvo.getEventDetectors().add(dped);
    try {
        ctx.getReader().readInto(importing, json);
    // try {
    // if(Common.runtimeManager.getState() == RuntimeManager.RUNNING){
    // Common.runtimeManager.saveDataPoint(dpvo);
    // addSuccessMessage(isNew, "emport.eventDetector.prefix", xid);
    // }else{
    // addFailureMessage(new ProcessMessage("Runtime Manager not running point with xid: " + xid + " not saved."));
    // }
    // } catch(LicenseViolatedException e) {
    // addFailureMessage(new ProcessMessage(e.getErrorMessage()));
    // }
    } catch (TranslatableJsonException e) {
        addFailureMessage("emport.eventDetector.prefix", xid, e.getMsg());
    } catch (JsonException e) {
        addFailureMessage("emport.eventDetector.prefix", xid, getJsonExceptionMessage(e));
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) JsonArray(com.serotonin.json.type.JsonArray) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ArrayList(java.util.ArrayList) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)

Aggregations

LicenseViolatedException (com.serotonin.m2m2.LicenseViolatedException)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)5 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)3 DataPointPropertiesTemplateVO (com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO)3 JsonException (com.serotonin.json.JsonException)2 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)2 ArrayList (java.util.ArrayList)2 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 JsonArray (com.serotonin.json.type.JsonArray)1 IMangoLifecycle (com.serotonin.m2m2.IMangoLifecycle)1 DataPointDao (com.serotonin.m2m2.db.dao.DataPointDao)1 PostEmailRunnable (com.serotonin.m2m2.email.PostEmailRunnable)1 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)1 Translations (com.serotonin.m2m2.i18n.Translations)1 ReportDao (com.serotonin.m2m2.reports.ReportDao)1 ReportPointVO (com.serotonin.m2m2.reports.vo.ReportPointVO)1 PointStatistics (com.serotonin.m2m2.reports.web.ReportChartCreator.PointStatistics)1