Search in sources :

Example 1 with JsonEmportControlModel

use of com.serotonin.m2m2.web.mvc.rest.v1.model.emport.JsonEmportControlModel in project ma-modules-public by infiniteautomation.

the class JsonConfigImportWebSocketHandler method handleTextMessage.

@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) {
    try {
        User user = this.getUser(session);
        // TODO Can anyone cancel the import?
        if (user == null) {
            return;
        } else if (!user.isAdmin()) {
            if (session.isOpen()) {
                session.close(MangoWebSocketPublisher.NOT_AUTHORIZED);
            }
            return;
        }
        JsonEmportControlModel model = this.jacksonMapper.readValue(message.getPayload(), JsonEmportControlModel.class);
        if (model != null && model.isCancel()) {
            // Cancel the task if it is running
            this.controller.cancelImport(model.getResourceId());
        }
    } catch (Exception e) {
        try {
            this.sendErrorMessage(session, MangoWebSocketErrorType.SERVER_ERROR, new TranslatableMessage("rest.error.serverError", e.getMessage()));
        } catch (Exception e1) {
            LOG.error(e.getMessage(), e);
        }
    }
}
Also used : User(com.serotonin.m2m2.vo.User) JsonEmportControlModel(com.serotonin.m2m2.web.mvc.rest.v1.model.emport.JsonEmportControlModel) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Aggregations

TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 User (com.serotonin.m2m2.vo.User)1 JsonEmportControlModel (com.serotonin.m2m2.web.mvc.rest.v1.model.emport.JsonEmportControlModel)1