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;
}
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;
}
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;
}
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());
}
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;
}
Aggregations