use of com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel in project ma-modules-public by infiniteautomation.
the class MailingListRestController method get.
@ApiOperation(value = "Get Mailing List by XID", notes = "Returns a Mailing List")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/{xid}")
public ResponseEntity<MailingListModel> get(@ApiParam(value = "Valid mailing list xid", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<MailingListModel> result = new RestProcessResult<MailingListModel>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
MailingList list = this.dao.getMailingList(xid);
if (list != null) {
MailingListModel model = new MailingListModel(list);
return result.createResponseEntity(model);
} else {
result.addRestMessage(getDoesNotExistMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel in project ma-modules-public by infiniteautomation.
the class MailingListRestController method getAll.
@ApiOperation(value = "Get Mailing List", notes = "Returns all Mailing Lists, eventually will be RQL endpoint")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" })
public ResponseEntity<List<MailingListModel>> getAll(HttpServletRequest request) {
RestProcessResult<List<MailingListModel>> result = new RestProcessResult<List<MailingListModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
List<MailingList> lists = this.dao.getMailingLists();
if (lists != null) {
List<MailingListModel> models = new ArrayList<MailingListModel>();
for (MailingList list : lists) {
models.add(new MailingListModel(list));
}
return result.createResponseEntity(models);
} else {
result.addRestMessage(getDoesNotExistMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel in project ma-modules-public by infiniteautomation.
the class EmailRecipientModelDeserializer method deserialize.
/* (non-Javadoc)
* @see com.fasterxml.jackson.databind.JsonDeserializer#deserialize(com.fasterxml.jackson.core.JsonParser, com.fasterxml.jackson.databind.DeserializationContext)
*/
@Override
public EmailRecipientModel<?> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode tree = jp.readValueAsTree();
String type = tree.get("type").asText();
int code = EmailRecipient.TYPE_CODES.getId(type);
switch(code) {
case EmailRecipient.TYPE_ADDRESS:
return (AddressEntryModel) mapper.treeToValue(tree, AddressEntryModel.class);
case EmailRecipient.TYPE_MAILING_LIST:
return (MailingListModel) mapper.treeToValue(tree, MailingListModel.class);
case EmailRecipient.TYPE_USER:
return (UserEntryModel) mapper.treeToValue(tree, UserEntryModel.class);
default:
throw new ModelNotFoundException(type);
}
}
Aggregations