Example usage for com.liferay.portal.kernel.util ListUtil isNotNull

List of usage examples for com.liferay.portal.kernel.util ListUtil isNotNull

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util ListUtil isNotNull.

Prototype

public static boolean isNotNull(List<?> list) 

Source Link

Usage

From source file:com.liferay.osb.scv.user.mapper.internal.event.UpdateUsersEvent.java

License:Open Source License

public void handleResponse(Message message) throws Exception {
    if (_userMappingRulesMap.isEmpty()) {
        return;/*www.java  2  s  .  c om*/
    }

    MappingDataSource mappingDataSource = MappingDataSourceLocalServiceUtil
            .fetchMappingDataSource(_mappingDataSourceId);

    JSONObject sourceJSONObject = JSONFactoryUtil.createJSONObject(String.valueOf(message.getPayload()));

    JSONObject destinationJSONObject = JSONFactoryUtil.createJSONObject();

    Iterator<String> keys = sourceJSONObject.keys();

    while (keys.hasNext()) {
        String key = keys.next();

        List<UserMappingRule> userMappingRules = _userMappingRulesMap.get(key);

        if (ListUtil.isNotNull(userMappingRules)) {
            Set<String> processedKeys = new HashSet<>();

            JSONArray sourceModelJSONArray = sourceJSONObject.getJSONArray(key);

            JSONArray destinationModelJSONArray = JSONFactoryUtil.createJSONArray();

            for (int i = 0; i < sourceModelJSONArray.length(); i++) {
                JSONObject sourceModelJSONObject = sourceModelJSONArray.getJSONObject(i);
                JSONObject destinationModelJSONObject = JSONFactoryUtil.createJSONObject();

                for (UserMappingRule userMappingRule : userMappingRules) {
                    processedKeys.add(userMappingRule.getSourceField());

                    String value = sourceModelJSONObject.getString(userMappingRule.getSourceField());

                    if ((value != null) && !_override) {
                        destinationModelJSONObject.put(userMappingRule.getDestinationField(), value);
                    }
                }

                Iterator<String> allKeys = sourceModelJSONObject.keys();

                while (allKeys.hasNext()) {
                    String curKey = allKeys.next();

                    if (processedKeys.contains(curKey)) {
                        continue;
                    }

                    destinationModelJSONObject.put(curKey, sourceModelJSONObject.getString(curKey));
                }

                destinationModelJSONArray.put(destinationModelJSONObject);
            }

            destinationJSONObject.put(key, destinationModelJSONArray);
        }
    }

    if (destinationJSONObject.length() == 0) {
        return;
    }

    JSONArray sourceUserJSONArray = sourceJSONObject.getJSONArray("User");

    if ((mappingDataSource.getType() != MappingDataSourceConstants.CUSTOM)
            && !_userMappingRulesMap.containsKey("User") && (sourceUserJSONArray != null)) {

        JSONArray destinationUserJSONArray = JSONFactoryUtil.createJSONArray();

        for (int i = 0; i < sourceUserJSONArray.length(); i++) {
            JSONObject sourceUserJSONObject = sourceUserJSONArray.getJSONObject(i);
            JSONObject destinationUserJSONObject = JSONFactoryUtil.createJSONObject();

            keys = sourceUserJSONObject.keys();

            while (keys.hasNext()) {
                String key = keys.next();

                destinationUserJSONObject.put(key, sourceUserJSONObject.getString(key));
            }

            destinationUserJSONArray.put(destinationUserJSONObject);
        }

        destinationJSONObject.put("User", destinationUserJSONArray);
    }

    // START: TEMP CODE //

    Map<String, List<String>> map = new HashMap<>();

    map.put("User", Arrays.asList("emailAddress"));

    // END: TEMP CODE //

    UserProfileUtil.updateDataSourceEntries(_mappingDataSourceId, map, destinationJSONObject);
}