Search in sources :

Example 6 with PublisherVO

use of com.serotonin.m2m2.vo.publish.PublisherVO in project ma-core-public by infiniteautomation.

the class PublisherImporter method importImpl.

@Override
protected void importImpl() {
    String xid = json.getString("xid");
    if (StringUtils.isBlank(xid))
        xid = ctx.getPublisherDao().generateUniqueXid();
    PublisherVO<?> vo = ctx.getPublisherDao().getPublisher(xid);
    if (vo == null) {
        String typeStr = json.getString("type");
        if (StringUtils.isBlank(typeStr))
            addFailureMessage("emport.publisher.missingType", xid, ModuleRegistry.getPublisherDefinitionTypes());
        else {
            PublisherDefinition def = ModuleRegistry.getPublisherDefinition(typeStr);
            if (def == null)
                addFailureMessage("emport.publisher.invalidType", xid, typeStr, ModuleRegistry.getPublisherDefinitionTypes());
            else {
                vo = def.baseCreatePublisherVO();
                vo.setXid(xid);
            }
        }
    }
    if (vo != null) {
        try {
            // The VO was found or successfully created. Finish reading it in.
            ctx.getReader().readInto(vo, json);
            // Now validate it. Use a new response object so we can distinguish errors in this vo from
            // other errors.
            ProcessResult voResponse = new ProcessResult();
            vo.validate(voResponse);
            if (voResponse.getHasMessages())
                setValidationMessages(voResponse, "emport.publisher.prefix", xid);
            else {
                // Sweet. Save it.
                boolean isnew = vo.isNew();
                if (Common.runtimeManager.getState() == RuntimeManager.RUNNING) {
                    Common.runtimeManager.savePublisher(vo);
                    addSuccessMessage(isnew, "emport.publisher.prefix", xid);
                } else {
                    addFailureMessage(new ProcessMessage("Runtime manager not running publisher with xid : " + vo.getXid() + " not saved."));
                }
            }
        } catch (TranslatableJsonException e) {
            addFailureMessage("emport.publisher.prefix", xid, e.getMsg());
        } catch (JsonException e) {
            addFailureMessage("emport.publisher.prefix", xid, getJsonExceptionMessage(e));
        }
    }
}
Also used : PublisherDefinition(com.serotonin.m2m2.module.PublisherDefinition) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) JsonException(com.serotonin.json.JsonException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ProcessMessage(com.serotonin.m2m2.i18n.ProcessMessage) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Example 7 with PublisherVO

use of com.serotonin.m2m2.vo.publish.PublisherVO in project ma-core-public by infiniteautomation.

the class EventType method getPublisher.

protected PublisherVO<?> getPublisher(JsonObject json, String name) throws JsonException {
    String xid = json.getString(name);
    if (xid == null)
        throw new TranslatableJsonException("emport.error.eventType.missing.reference", name);
    PublisherVO<?> pb = PublisherDao.instance.getPublisher(xid);
    if (pb == null)
        throw new TranslatableJsonException("emport.error.eventType.invalid.reference", name, xid);
    return pb;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Aggregations

ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)3 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)2 PublisherDefinition (com.serotonin.m2m2.module.PublisherDefinition)2 User (com.serotonin.m2m2.vo.User)2 EventTypeVO (com.serotonin.m2m2.vo.event.EventTypeVO)2 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JsonException (com.serotonin.json.JsonException)1 PublisherDao (com.serotonin.m2m2.db.dao.PublisherDao)1 ProcessMessage (com.serotonin.m2m2.i18n.ProcessMessage)1 Translations (com.serotonin.m2m2.i18n.Translations)1 EventTypeDefinition (com.serotonin.m2m2.module.EventTypeDefinition)1 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)1 AuditEventType (com.serotonin.m2m2.rt.event.type.AuditEventType)1 EventType (com.serotonin.m2m2.rt.event.type.EventType)1 SystemEventType (com.serotonin.m2m2.rt.event.type.SystemEventType)1 ScriptPermissions (com.serotonin.m2m2.rt.script.ScriptPermissions)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)1