Search in sources :

Example 1 with MailingListModel

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();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) MailingListModel(com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with MailingListModel

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();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) MailingList(com.serotonin.m2m2.vo.mailingList.MailingList) List(java.util.List) MailingListModel(com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with MailingListModel

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);
    }
}
Also used : AddressEntryModel(com.serotonin.m2m2.web.mvc.rest.v1.model.email.AddressEntryModel) ModelNotFoundException(com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException) UserEntryModel(com.serotonin.m2m2.web.mvc.rest.v1.model.email.UserEntryModel) JsonNode(com.fasterxml.jackson.databind.JsonNode) MailingListModel(com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

MailingListModel (com.serotonin.m2m2.web.mvc.rest.v1.model.email.MailingListModel)3 MailingList (com.serotonin.m2m2.vo.mailingList.MailingList)2 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ModelNotFoundException (com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException)1 AddressEntryModel (com.serotonin.m2m2.web.mvc.rest.v1.model.email.AddressEntryModel)1 UserEntryModel (com.serotonin.m2m2.web.mvc.rest.v1.model.email.UserEntryModel)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1