Search in sources :

Example 91 with TranslatableMessage

use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.

the class TranslatableMessageSerializer method serialize.

/* (non-Javadoc)
	 * @see com.fasterxml.jackson.databind.JsonSerializer#serialize(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider)
	 */
@Override
public void serialize(TranslatableMessage msg, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
    if (msg != null) {
        User user = Common.getHttpUser();
        Locale locale = user == null ? Common.getLocale() : user.getLocaleObject();
        jgen.writeString(msg.translate(Translations.getTranslations(locale)));
    } else
        jgen.writeNull();
}
Also used : Locale(java.util.Locale) User(com.serotonin.m2m2.vo.User)

Example 92 with TranslatableMessage

use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.

the class DataPointDao method checkAddPoint.

public void checkAddPoint() {
    IMangoLifecycle lifecycle = Providers.get(IMangoLifecycle.class);
    Integer limit = lifecycle.dataPointLimit();
    if (limit != null && this.countMonitor.getValue() >= limit) {
        String licenseType;
        if (Common.license() != null)
            licenseType = Common.license().getLicenseType();
        else
            licenseType = "Free";
        throw new LicenseViolatedException(new TranslatableMessage("license.dataPointLimit", licenseType, limit));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LicenseViolatedException(com.serotonin.m2m2.LicenseViolatedException) IMangoLifecycle(com.serotonin.m2m2.IMangoLifecycle) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 93 with TranslatableMessage

use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.

the class PointValueDaoSQL method updatePointValueAnnotation.

private void updatePointValueAnnotation(long id, int dataType, String svalue, SetPointSource source) {
    if (svalue == null && dataType == DataTypes.IMAGE)
        svalue = Long.toString(id);
    // Check if we need to create an annotation.
    TranslatableMessage sourceMessage = null;
    if (source != null)
        sourceMessage = source.getSetPointSourceMessage();
    if (svalue != null || sourceMessage != null) {
        String shortString = null;
        String longString = null;
        if (svalue != null) {
            if (svalue.length() > 128)
                longString = svalue;
            else
                shortString = svalue;
        }
        // 
        ejt.update(// 
        POINT_VALUE_ANNOTATION_UPDATE + "WHERE pointValueId = ?", // 
        new Object[] { shortString, longString, writeTranslatableMessage(sourceMessage), id }, new int[] { Types.VARCHAR, Types.CLOB, Types.CLOB, Types.INTEGER });
    }
}
Also used : TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 94 with TranslatableMessage

use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.

the class UserDao method deleteUser.

public void deleteUser(final int userId) {
    User user = getTransactionTemplate().execute(new TransactionCallback<User>() {

        @Override
        public User doInTransaction(TransactionStatus status) {
            User user = get(userId);
            Object[] args = new Object[] { userId };
            ejt.update("UPDATE userComments SET userId=null WHERE userId=?", args);
            ejt.update("DELETE FROM mailingListMembers WHERE userId=?", args);
            ejt.update("DELETE FROM userEvents WHERE userId=?", args);
            ejt.update("UPDATE events SET ackUserId=null, alternateAckSource=? WHERE ackUserId=?", new Object[] { new TranslatableMessage("events.ackedByDeletedUser").serialize(), userId });
            ejt.update("DELETE FROM users WHERE id=?", args);
            return user;
        }
    });
    AuditEventType.raiseDeletedEvent(AuditEventType.TYPE_USER, user);
    countMonitor.decrement();
    if (handler != null)
        handler.notify("delete", user);
    // Update User In Session
    MangoSecurityConfiguration.sessionRegistry.exireSessionsForUser(user);
    userCache.remove(user.getUsername());
}
Also used : User(com.serotonin.m2m2.vo.User) TransactionStatus(org.springframework.transaction.TransactionStatus) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 95 with TranslatableMessage

use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-core-public by infiniteautomation.

the class SetPointHandlerRT method raiseFailureEvent.

private void raiseFailureEvent(TranslatableMessage message, EventType et) {
    if (et != null && et.isSystemMessage()) {
        if (((SystemEventType) et).getSystemEventType().equals(SystemEventType.TYPE_SET_POINT_HANDLER_FAILURE)) {
            // The set point attempt failed for an event that is a set point handler failure in the first place.
            // Do not propagate the event, but rather just write a log message.
            LOG.warn("A set point event due to a set point handler failure itself failed. The failure event " + "has been discarded: " + message.translate(Common.getTranslations()));
            return;
        }
    }
    SystemEventType eventType = new SystemEventType(SystemEventType.TYPE_SET_POINT_HANDLER_FAILURE, vo.getId());
    if (StringUtils.isBlank(vo.getAlias()))
        message = new TranslatableMessage("event.setPointFailed", message);
    else
        message = new TranslatableMessage("event.setPointFailed.alias", vo.getAlias(), message);
    SystemEventType.raiseEvent(eventType, Common.timer.currentTimeMillis(), false, message);
}
Also used : SystemEventType(com.serotonin.m2m2.rt.event.type.SystemEventType) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Aggregations

TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)180 User (com.serotonin.m2m2.vo.User)53 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)52 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)52 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)33 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)33 IOException (java.io.IOException)28 HashMap (java.util.HashMap)27 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)24 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)22 ArrayList (java.util.ArrayList)22 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)20 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)20 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)19 BadRequestException (com.infiniteautomation.mango.rest.v2.exception.BadRequestException)18 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)17 File (java.io.File)16 URI (java.net.URI)16 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)12 ResponseEntity (org.springframework.http.ResponseEntity)11