Example usage for com.liferay.portal.kernel.messaging Message getLong

List of usage examples for com.liferay.portal.kernel.messaging Message getLong

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.messaging Message getLong.

Prototype

public long getLong(String key) 

Source Link

Usage

From source file:com.liferay.adaptive.media.web.internal.background.task.OptimizeImagesBackgroundTaskStatusMessageTranslator.java

License:Open Source License

@Override
public void translate(BackgroundTaskStatus backgroundTaskStatus, Message message) {

    String phase = message.getString(OptimizeImagesBackgroundTaskConstants.PHASE);

    if (Validator.isNotNull(phase)) {
        setPhaseAttributes(backgroundTaskStatus, message);

        return;/* w w  w . j a v a 2 s. c  om*/
    }

    String className = message.getString(OptimizeImagesBackgroundTaskConstants.CLASS_NAME);

    backgroundTaskStatus.setAttribute(OptimizeImagesBackgroundTaskConstants.CLASS_NAME, className);

    long count = message.getLong(OptimizeImagesBackgroundTaskConstants.COUNT);

    backgroundTaskStatus.setAttribute(OptimizeImagesBackgroundTaskConstants.COUNT, count);

    long total = message.getLong(OptimizeImagesBackgroundTaskConstants.TOTAL);

    backgroundTaskStatus.setAttribute(OptimizeImagesBackgroundTaskConstants.TOTAL, total);

    int percentage = 100;

    if ((count != 0) && (total != 0)) {
        percentage = (int) (count / total);
    }

    backgroundTaskStatus.setAttribute("percentage", percentage);
}

From source file:com.liferay.adaptive.media.web.internal.background.task.OptimizeImagesBackgroundTaskStatusMessageTranslator.java

License:Open Source License

protected void setPhaseAttributes(BackgroundTaskStatus backgroundTaskStatus, Message message) {

    backgroundTaskStatus.setAttribute(ReindexBackgroundTaskConstants.COMPANY_ID,
            message.getLong(ReindexBackgroundTaskConstants.COMPANY_ID));
    backgroundTaskStatus.setAttribute(ReindexBackgroundTaskConstants.PHASE,
            message.getString(ReindexBackgroundTaskConstants.PHASE));
}

From source file:com.liferay.analytics.messaging.AnalyticsMessageListener.java

License:Open Source License

protected void doReceive(Message message) throws Exception {
    long companyId = message.getLong("companyId");
    long userId = message.getLong("userId");
    long anonymousUserId = message.getLong("anonymousUserId");
    String elementId = message.getString("elementId");
    String eventType = message.getString("event");
    String className = message.getString("className");
    long classPK = message.getLong("classPK");
    String referrerClassName = message.getString("referrerClassName");

    String[] values = StringUtil.split(message.getString("referrerClassPK"));

    long[] referrerClassPKs = GetterUtil.getLongValues(values);

    if (Validator.isNull(referrerClassName) || Validator.isNull(referrerClassPKs)) {

        referrerClassName = Layout.class.getName();
        referrerClassPKs = new long[] { message.getLong("plid") };
    }//from   w w w .  ja  va 2  s .  c om

    String clientIP = message.getString("clientIP");
    String userAgent = message.getString("userAgent");
    String languageId = message.getString("languageId");
    String URL = message.getString("layoutURL");
    String additionalInfo = message.getString("additionalInfo");

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setCompanyId(companyId);

    AnalyticsEventLocalServiceUtil.addAnalyticsEvent(userId, anonymousUserId, className, classPK,
            referrerClassName, referrerClassPKs, elementId, eventType, clientIP, userAgent, languageId, URL,
            additionalInfo, serviceContext);
}

From source file:com.liferay.contacts.messaging.HotDeployMessageListener.java

License:Open Source License

protected void deploy(Message message) throws Exception {
    String servletContextName = message.getString("servletContextName");

    if (servletContextName.equals("chat-portlet")) {
        registerChatExtension();/*from   w w  w  .ja  v a 2 s .  c  om*/
    } else if (servletContextName.equals("contacts-portlet")) {
        long companyId = message.getLong("companyId");

        if (PortletLocalServiceUtil.hasPortlet(companyId, "1_WAR_chatportlet")) {

            registerChatExtension();
        }
    }
}

From source file:com.liferay.content.targeting.rule.score.points.messaging.AnalyticsMessageListener.java

License:Open Source License

protected void doReceive(Message message) throws Exception {
    Bundle bundle = FrameworkUtil.getBundle(getClass());

    if (bundle == null) {
        throw new UnavailableException("Can't find a reference to the OSGi bundle") {

            @Override//www.j a va 2s . co  m
            public boolean isPermanent() {
                return true;
            }
        };
    }

    ScorePointsAssigner scorePointsAssigner = ServiceTrackerUtil.getService(ScorePointsAssigner.class,
            bundle.getBundleContext());

    String className = message.getString("className");
    long classPK = message.getLong("classPK");
    long anonymousUserId = message.getLong("anonymousUserId");
    long groupId = message.getLong("scopeGroupId");

    try {
        scorePointsAssigner.assignPoints(groupId, anonymousUserId, className, classPK);
    } catch (NullPointerException npe) {
        _log.error("No score point assigners available");
    }
}

From source file:com.liferay.contenttargeting.rules.scorepoints.analytics.AnalyticsMessageListener.java

License:Open Source License

protected void doReceive(Message message) throws Exception {
    String className = message.getString("className");
    long classPK = message.getLong("classPK");
    long anonymousUserId = message.getLong("anonymousUserId");
    long groupId = message.getLong("groupId");

    ScorePointsAssigner.assignPoints(groupId, anonymousUserId, className, classPK);
}

From source file:com.liferay.mail.messaging.MailSynchronizationMessageListener.java

License:Open Source License

protected void flagMessage(Message message) throws Exception {
    long userId = message.getLong("userId");
    long accountId = message.getLong("accountId");
    String password = message.getString("password");
    long folderId = message.getLong("folderId");
    long messageId = message.getLong("messageId");
    int flag = message.getInteger("flag");
    boolean flagValue = message.getBoolean("flagValue");

    if (_log.isDebugEnabled()) {
        _log.debug("Flagging message for messageId " + messageId);
    }// ww w .ja  v  a 2 s.c  o m

    if (Validator.isNull(password)) {
        return;
    }

    Mailbox mailbox = MailboxFactoryUtil.getMailbox(userId, accountId, password);

    mailbox.updateFlags(folderId, new long[] { messageId }, flag, flagValue);
}

From source file:com.liferay.mail.messaging.MailSynchronizationMessageListener.java

License:Open Source License

protected void synchronize(Message message) throws Exception {
    long userId = message.getLong("userId");
    long accountId = message.getLong("accountId");
    String password = message.getString("password");
    long folderId = message.getLong("folderId");
    long messageId = message.getLong("messageId");
    int pageNumber = message.getInteger("pageNumber");
    int messagesPerPage = message.getInteger("messagesPerPage");

    if (_log.isDebugEnabled()) {
        _log.debug("Starting synch for accountId " + accountId + " folderId " + folderId + " and messageId "
                + messageId);//from ww w . jav a  2 s . c  om
    }

    try {
        if (!password.equals(StringPool.BLANK)) {
            Mailbox mailbox = MailboxFactoryUtil.getMailbox(userId, accountId, password);

            if (messageId != 0) {
                mailbox.synchronizeMessage(messageId);
            } else if (folderId != 0) {
                if (pageNumber != 0) {
                    mailbox.synchronizePage(folderId, pageNumber, messagesPerPage);
                } else {
                    mailbox.synchronizeFolder(folderId);
                }
            } else {
                mailbox.synchronize();
            }
        } else {
            if (_log.isDebugEnabled()) {
                _log.debug("Unable to acquire synch lock for accountId " + accountId + " and folderId "
                        + folderId + " and messageId " + messageId);
            }
        }
    } catch (NoSuchAccountException nsae) {
        if (_log.isDebugEnabled()) {
            _log.debug("Skipping syncronization of accountId " + accountId);
        }
    }
}

From source file:com.liferay.osb.scv.user.mapper.internal.messaging.UserMapperMessageListener.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
protected void doReceive(Message message) throws Exception {
    String responseId = message.getResponseId();

    Event event = EventManager.getEvent(responseId);

    if (event != null) {
        event.handleResponse(message);/* ww  w.ja v  a  2 s. com*/

        return;
    }

    String method = message.getString("method");
    long mappingDataSourceId = message.getLong("mappingDataSourceId");

    if (method.equals("addData")) {
        List<UserMappingRule> userMappingRules = null;

        MappingDataSource mappingDataSource = MappingDataSourceLocalServiceUtil
                .fetchMappingDataSource(mappingDataSourceId);

        if (mappingDataSource.getType() == MappingDataSourceConstants.CUSTOM) {

            userMappingRules = UserMappingRuleLocalServiceUtil.getUserMappingRules(mappingDataSourceId);
        } else {
            userMappingRules = UserMappingRuleLocalServiceUtil.getUserMappingRules(mappingDataSourceId,
                    FrequencyUtil.INSTANT);
        }

        event = new UpdateUsersEvent(mappingDataSourceId, userMappingRules);

        event.handleResponse(message);
    } else if (method.equals("addDataSource")) {
        String name = message.getString("name");
        String url = message.getString("url");

        long type = MappingDataSourceConstants.CUSTOM;

        if (!Validator.isBlank(url)) {
            type = MappingDataSourceConstants.LIFERAY;
        }

        String login = message.getString("login");
        String password = message.getString("password");
        String availableFields = message.getString("availableFields");

        MappingDataSource mappingDataSource = MappingDataSourceServiceUtil.addMappingDataSource(name, url,
                login, password, type, availableFields);

        Message responseMessage = MessageBusUtil.createResponseMessage(message);

        responseMessage.setPayload(mappingDataSource.getMappingDataSourceId());

        MessageBusUtil.sendMessage(responseMessage.getDestinationName(), responseMessage);
    } else if (method.equals("addUserMappingRule")) {
        String modelName = message.getString("modelName");
        String sourceField = message.getString("sourceField");
        String destinationField = message.getString("destinationField");

        UserMappingRuleServiceUtil.addUserMappingRule(mappingDataSourceId, 0, modelName, sourceField,
                destinationField, FrequencyUtil.ONCE, false);
    } else if (method.equals("getFields")) {
        GetFieldsEvent getFieldsEvent = new GetFieldsEvent(mappingDataSourceId);

        getFieldsEvent.run();
    }
}

From source file:com.liferay.ruon.messaging.RUONMessageListener.java

License:Open Source License

protected void getPresences(Message message) throws Exception {
    long userId = message.getLong("userId");
    boolean online = true;
    Locale locale = (Locale) message.get("locale");

    List<Presence> presences = PresenceLocalServiceUtil.getPresences(userId, online);

    JSONObject payloadJSON = JSONFactoryUtil.createJSONObject();

    JSONArray presencesJSON = JSONFactoryUtil.createJSONArray();

    payloadJSON.put("presencesJSON", presencesJSON);

    for (Presence presence : presences) {
        Converter converter = _converters.get(presence.getNetworkId());

        if (converter == null) {
            continue;
        }/*from   w w w  .j a va 2s  . c  o m*/

        Map<String, Object> input = new HashMap<String, Object>();

        input.put("userId", userId);
        input.put("online", online);
        input.put("locale", locale);

        Object output = converter.convert(input);

        JSONObject presenceJSON = JSONFactoryUtil.createJSONObject();

        presenceJSON.put("userId", userId);
        presenceJSON.put("online", online);
        presenceJSON.put("output", String.valueOf(output));

        presencesJSON.put(presenceJSON);
    }

    message.setPayload(payloadJSON);

    MessageBusUtil.sendMessage(message.getResponseDestination(), message);
}