Search in sources :

Example 6 with ModelNotFoundException

use of com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException in project ma-core-public by infiniteautomation.

the class AbstractEventDetectorModelDeserializer method deserialize.

/* (non-Javadoc)
	 * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
	 */
@Override
public AbstractEventDetectorModel<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    JsonNode tree = jp.readValueAsTree();
    String typeName = tree.get("detectorType").asText();
    EventDetectorDefinition<?> def = ModuleRegistry.getEventDetectorDefinition(typeName);
    if (def == null)
        throw new ModelNotFoundException(typeName);
    AbstractEventDetectorModel<?> model = (AbstractEventDetectorModel<?>) mapper.treeToValue(tree, def.getModelClass());
    model.setDefinition(def);
    return model;
}
Also used : ModelNotFoundException(com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException) JsonNode(com.fasterxml.jackson.databind.JsonNode) AbstractEventDetectorModel(com.serotonin.m2m2.web.mvc.rest.v1.model.events.detectors.AbstractEventDetectorModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with ModelNotFoundException

use of com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException in project ma-core-public by infiniteautomation.

the class DataSourceModelDeserializer method deserialize.

/* (non-Javadoc)
	 * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
	 */
@Override
public AbstractDataSourceModel<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    JsonNode tree = jp.readValueAsTree();
    String typeName = tree.get("modelType").asText();
    DataSourceDefinition definition = ModuleRegistry.getDataSourceDefinition(typeName);
    if (definition == null)
        throw new ModelNotFoundException(typeName);
    AbstractDataSourceModel<?> model = (AbstractDataSourceModel<?>) mapper.treeToValue(tree, definition.getModelClass());
    // Set the definition here
    model.setDefinition(definition);
    return model;
}
Also used : AbstractDataSourceModel(com.serotonin.m2m2.web.mvc.rest.v1.model.dataSource.AbstractDataSourceModel) ModelNotFoundException(com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException) DataSourceDefinition(com.serotonin.m2m2.module.DataSourceDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with ModelNotFoundException

use of com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException in project ma-core-public by infiniteautomation.

the class EventTypeModelDeserializer method deserialize.

/*
     * (non-Javadoc)
     * 
     * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.
     * JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
     */
@Override
public EventTypeModel deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    JsonNode tree = jp.readValueAsTree();
    String typeName = tree.get("typeName").asText();
    if (StringUtils.isEmpty(typeName))
        throw new ModelNotFoundException(typeName);
    EventTypeModel model = null;
    switch(typeName) {
        case EventType.EventTypeNames.DATA_POINT:
            model = mapper.treeToValue(tree, DataPointEventTypeModel.class);
            break;
        case EventType.EventTypeNames.DATA_SOURCE:
            model = mapper.treeToValue(tree, DataSourceEventTypeModel.class);
            break;
        case EventType.EventTypeNames.AUDIT:
            model = mapper.treeToValue(tree, AuditEventTypeModel.class);
            break;
        case EventType.EventTypeNames.PUBLISHER:
            model = mapper.treeToValue(tree, PublisherEventTypeModel.class);
            break;
        case EventType.EventTypeNames.SYSTEM:
            model = mapper.treeToValue(tree, SystemEventTypeModel.class);
            break;
        case EventType.EventTypeNames.MISSING:
            model = mapper.treeToValue(tree, MissingEventTypeModel.class);
            break;
    }
    if (model == null) {
        EventTypeDefinition def = ModuleRegistry.getEventTypeDefinition(typeName);
        if (def == null)
            throw new ModelNotFoundException(typeName);
        return (EventTypeModel) mapper.treeToValue(tree, def.getModelClass());
    } else
        return model;
}
Also used : DataPointEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.DataPointEventTypeModel) SystemEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.SystemEventTypeModel) DataSourceEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.DataSourceEventTypeModel) AuditEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.AuditEventTypeModel) MissingEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.MissingEventTypeModel) EventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.EventTypeModel) PublisherEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.PublisherEventTypeModel) SystemEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.SystemEventTypeModel) DataSourceEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.DataSourceEventTypeModel) PublisherEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.PublisherEventTypeModel) ModelNotFoundException(com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException) MissingEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.MissingEventTypeModel) JsonNode(com.fasterxml.jackson.databind.JsonNode) EventTypeDefinition(com.serotonin.m2m2.module.EventTypeDefinition) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataPointEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.DataPointEventTypeModel) AuditEventTypeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.AuditEventTypeModel)

Example 9 with ModelNotFoundException

use of com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException in project ma-core-public by infiniteautomation.

the class PublishedPointModelDeserializer method deserialize.

/* (non-Javadoc)
	 * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
	 */
@Override
public AbstractPublishedPointModel<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    JsonNode tree = jp.readValueAsTree();
    // Get the model type which is of the form PUB-POINT-{publisher type name}
    String typeName = tree.get("modelType").asText();
    if (typeName != null)
        typeName = typeName.split("PUB-POINT-")[1];
    PublisherDefinition definition = ModuleRegistry.getPublisherDefinition(typeName);
    if (definition == null)
        throw new ModelNotFoundException("PUB-POINT-" + typeName);
    return (AbstractPublishedPointModel<?>) mapper.treeToValue(tree, definition.getPublishedPointModelClass());
}
Also used : PublisherDefinition(com.serotonin.m2m2.module.PublisherDefinition) ModelNotFoundException(com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractPublishedPointModel(com.serotonin.m2m2.web.mvc.rest.v1.model.publisher.AbstractPublishedPointModel)

Example 10 with ModelNotFoundException

use of com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException in project ma-core-public by infiniteautomation.

the class PublisherModelDeserializer method deserialize.

/* (non-Javadoc)
	 * @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
	 */
@Override
public AbstractPublisherModel<?, ?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    JsonNode tree = jp.readValueAsTree();
    String typeName = tree.get("modelType").asText();
    PublisherDefinition definition = ModuleRegistry.getPublisherDefinition(typeName);
    if (definition == null)
        throw new ModelNotFoundException(typeName);
    AbstractPublisherModel<?, ?> model = (AbstractPublisherModel<?, ?>) mapper.treeToValue(tree, definition.getPublisherModelClass());
    // Set the definition here
    model.setDefinition(definition);
    return model;
}
Also used : PublisherDefinition(com.serotonin.m2m2.module.PublisherDefinition) ModelNotFoundException(com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException) AbstractPublisherModel(com.serotonin.m2m2.web.mvc.rest.v1.model.publisher.AbstractPublisherModel) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ModelNotFoundException (com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 ModelDefinition (com.serotonin.m2m2.module.ModelDefinition)2 PublisherDefinition (com.serotonin.m2m2.module.PublisherDefinition)2 VirtualSerialPortConfig (com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig)1 DataSourceDefinition (com.serotonin.m2m2.module.DataSourceDefinition)1 EventTypeDefinition (com.serotonin.m2m2.module.EventTypeDefinition)1 AbstractDataSourceModel (com.serotonin.m2m2.web.mvc.rest.v1.model.dataSource.AbstractDataSourceModel)1 AddressEntryModel (com.serotonin.m2m2.web.mvc.rest.v1.model.email.AddressEntryModel)1 MailingListModel (com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel)1 UserEntryModel (com.serotonin.m2m2.web.mvc.rest.v1.model.email.UserEntryModel)1 AuditEventTypeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.AuditEventTypeModel)1 DataPointEventTypeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.DataPointEventTypeModel)1 DataSourceEventTypeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.DataSourceEventTypeModel)1 EventTypeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.EventTypeModel)1 MissingEventTypeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.MissingEventTypeModel)1 PublisherEventTypeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.PublisherEventTypeModel)1 SystemEventTypeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.eventType.SystemEventTypeModel)1 AbstractEventDetectorModel (com.serotonin.m2m2.web.mvc.rest.v1.model.events.detectors.AbstractEventDetectorModel)1