Example usage for com.liferay.portal.kernel.util MapUtil getLong

List of usage examples for com.liferay.portal.kernel.util MapUtil getLong

Introduction

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

Prototype

public static long getLong(Map<String, ?> map, String key, long defaultValue) 

Source Link

Usage

From source file:com.liferay.adaptive.media.blogs.internal.exportimport.content.processor.AdaptiveMediaEmbeddedReferenceSet.java

License:Open Source License

public long importReference(String path) throws PortletDataException {
    long classPK = _embeddedReferences.get(path);

    StagedModelDataHandlerUtil.importReferenceStagedModel(_portletDataContext, _stagedModel, DLFileEntry.class,
            classPK);//  ww w  .j a v  a 2s . c om

    Map<Long, Long> dlFileEntryIds = (Map<Long, Long>) _portletDataContext
            .getNewPrimaryKeysMap(DLFileEntry.class);

    return MapUtil.getLong(dlFileEntryIds, classPK, classPK);
}

From source file:com.liferay.asset.categories.admin.web.internal.exportimport.data.handler.AssetCategoryStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, AssetCategory category)
        throws Exception {

    long userId = portletDataContext.getUserId(category.getUserUuid());

    Map<Long, Long> vocabularyIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(AssetVocabulary.class);

    long vocabularyId = MapUtil.getLong(vocabularyIds, category.getVocabularyId(), category.getVocabularyId());

    Map<Long, Long> categoryIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(AssetCategory.class);

    long parentCategoryId = MapUtil.getLong(categoryIds, category.getParentCategoryId(),
            category.getParentCategoryId());

    Element categoryElement = portletDataContext.getImportDataElement(category);

    List<Element> propertyElements = categoryElement.elements("property");

    String[] properties = new String[propertyElements.size()];

    for (int i = 0; i < propertyElements.size(); i++) {
        Element propertyElement = propertyElements.get(i);

        String key = propertyElement.attributeValue("key");
        String value = propertyElement.attributeValue("value");

        properties[i] = key.concat(AssetCategoryConstants.PROPERTY_KEY_VALUE_SEPARATOR).concat(value);
    }/*ww w  .  j  av  a2s. c  om*/

    ServiceContext serviceContext = createServiceContext(portletDataContext, category);

    AssetCategory importedCategory = null;

    AssetCategory existingCategory = fetchStagedModelByUuidAndGroupId(category.getUuid(),
            portletDataContext.getScopeGroupId());

    if (existingCategory == null) {
        String name = getCategoryName(null, portletDataContext.getScopeGroupId(), parentCategoryId,
                category.getName(), vocabularyId, 2);

        serviceContext.setUuid(category.getUuid());

        importedCategory = _assetCategoryLocalService.addCategory(userId, portletDataContext.getScopeGroupId(),
                parentCategoryId, getCategoryTitleMap(portletDataContext.getScopeGroupId(), category, name),
                category.getDescriptionMap(), vocabularyId, properties, serviceContext);
    } else {
        String name = getCategoryName(category.getUuid(), portletDataContext.getScopeGroupId(),
                parentCategoryId, category.getName(), vocabularyId, 2);

        importedCategory = _assetCategoryLocalService.updateCategory(userId, existingCategory.getCategoryId(),
                parentCategoryId, getCategoryTitleMap(portletDataContext.getScopeGroupId(), category, name),
                category.getDescriptionMap(), vocabularyId, properties, serviceContext);
    }

    categoryIds.put(category.getCategoryId(), importedCategory.getCategoryId());

    Map<String, String> categoryUuids = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(AssetCategory.class + ".uuid");

    categoryUuids.put(category.getUuid(), importedCategory.getUuid());

    portletDataContext.importPermissions(AssetCategory.class, category.getCategoryId(),
            importedCategory.getCategoryId());
}

From source file:com.liferay.asset.categories.navigation.web.internal.exportimport.portlet.preferences.processor.AssetCategoriesNavigationPortletPreferencesProcessor.java

License:Open Source License

@Override
protected Long getImportPortletPreferencesNewValue(PortletDataContext portletDataContext, Class<?> clazz,
        long companyGroupId, Map<Long, Long> primaryKeys, String portletPreferencesOldValue) throws Exception {

    if (Validator.isNumber(portletPreferencesOldValue)) {
        long oldPrimaryKey = GetterUtil.getLong(portletPreferencesOldValue);

        return MapUtil.getLong(primaryKeys, oldPrimaryKey, oldPrimaryKey);
    }// w  w w .  j a  va2 s . com

    String className = clazz.getName();

    String[] oldValues = StringUtil.split(portletPreferencesOldValue, StringPool.POUND);

    String uuid = oldValues[0];

    long groupId = portletDataContext.getScopeGroupId();

    if (oldValues.length > 1) {
        Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class);

        groupId = MapUtil.getLong(groupIds, GetterUtil.getLong(oldValues[1]));
    }

    if (className.equals(AssetVocabulary.class.getName())) {
        AssetVocabulary assetVocabulary = _assetVocabularyLocalService
                .fetchAssetVocabularyByUuidAndGroupId(uuid, groupId);

        if (assetVocabulary != null) {
            return assetVocabulary.getVocabularyId();
        }
    }

    return null;
}

From source file:com.liferay.asset.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java

License:Open Source License

@Override
protected Long getImportPortletPreferencesNewValue(PortletDataContext portletDataContext, Class<?> clazz,
        long companyGroupId, Map<Long, Long> primaryKeys, String portletPreferencesOldValue) throws Exception {

    if (Validator.isNumber(portletPreferencesOldValue)) {
        long oldPrimaryKey = GetterUtil.getLong(portletPreferencesOldValue);

        return MapUtil.getLong(primaryKeys, oldPrimaryKey, oldPrimaryKey);
    }/*w  w  w. ja  va 2  s  .c  om*/

    String className = clazz.getName();

    String[] oldValues = StringUtil.split(portletPreferencesOldValue, StringPool.POUND);

    String uuid = oldValues[0];

    long groupId = portletDataContext.getScopeGroupId();

    if (oldValues.length > 1) {
        Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class);

        groupId = MapUtil.getLong(groupIds, GetterUtil.getLong(oldValues[1]), groupId);
    }

    if (className.equals(AssetCategory.class.getName())) {
        AssetCategory assetCategory = _assetCategoryLocalService.fetchAssetCategoryByUuidAndGroupId(uuid,
                groupId);

        if (assetCategory != null) {
            return assetCategory.getCategoryId();
        }
    } else if (className.equals(AssetVocabulary.class.getName())) {
        AssetVocabulary assetVocabulary = _assetVocabularyLocalService
                .fetchAssetVocabularyByUuidAndGroupId(uuid, groupId);

        if (assetVocabulary != null) {
            return assetVocabulary.getVocabularyId();
        }
    } else if (className.equals(DDMStructure.class.getName())) {
        DDMStructure ddmStructure = _ddmStructureLocalService.fetchDDMStructureByUuidAndGroupId(uuid, groupId);

        if (ddmStructure == null) {
            Map<String, String> structureUuids = (Map<String, String>) portletDataContext
                    .getNewPrimaryKeysMap(DDMStructure.class + ".ddmStructureUuid");

            String defaultStructureUuid = MapUtil.getString(structureUuids, uuid, uuid);

            ddmStructure = _ddmStructureLocalService.fetchDDMStructureByUuidAndGroupId(defaultStructureUuid,
                    groupId);
        }

        if (ddmStructure != null) {
            return ddmStructure.getStructureId();
        }
    } else if (className.equals(DLFileEntryType.class.getName())) {
        DLFileEntryType dlFileEntryType = _dlFileEntryTypeLocalService
                .fetchDLFileEntryTypeByUuidAndGroupId(uuid, groupId);

        if (dlFileEntryType == null) {
            Element rootElement = portletDataContext.getImportDataRootElement();

            Element element = portletDataContext.getReferenceElement(rootElement, clazz, companyGroupId, uuid,
                    PortletDataContext.REFERENCE_TYPE_DEPENDENCY);

            if (element != null) {
                String fileEntryTypeKey = element.attributeValue("file-entry-type-key");

                boolean preloaded = GetterUtil.getBoolean(element.attributeValue("preloaded"));

                if (preloaded) {
                    dlFileEntryType = _dlFileEntryTypeLocalService.fetchFileEntryType(companyGroupId,
                            fileEntryTypeKey);
                }
            }
        }

        if (dlFileEntryType != null) {
            return dlFileEntryType.getFileEntryTypeId();
        }
    }

    return null;
}

From source file:com.liferay.blogs.recent.bloggers.web.internal.exportimport.portlet.preferences.processor.RecentBloggersExportImportPortletPreferencesProcessor.java

License:Open Source License

@Override
protected Long getImportPortletPreferencesNewValue(PortletDataContext portletDataContext, Class<?> clazz,
        long companyGroupId, Map<Long, Long> primaryKeys, String portletPreferencesOldValue) throws Exception {

    if (Validator.isNumber(portletPreferencesOldValue)) {
        long oldPrimaryKey = GetterUtil.getLong(portletPreferencesOldValue);

        return MapUtil.getLong(primaryKeys, oldPrimaryKey, oldPrimaryKey);
    }//ww w  .  ja va  2  s .c om

    String className = clazz.getName();

    if (className.equals(Organization.class.getName())) {
        Organization organization = OrganizationUtil.fetchByUuid_C_First(portletPreferencesOldValue,
                portletDataContext.getCompanyId(), null);

        if (organization != null) {
            return organization.getOrganizationId();
        }
    }

    return null;
}

From source file:com.liferay.bookmarks.internal.exportimport.data.handler.BookmarksEntryStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, BookmarksEntry entry)
        throws Exception {

    Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(BookmarksFolder.class);

    long folderId = MapUtil.getLong(folderIds, entry.getFolderId(), entry.getFolderId());

    BookmarksEntry importedEntry = (BookmarksEntry) entry.clone();

    importedEntry.setGroupId(portletDataContext.getScopeGroupId());
    importedEntry.setFolderId(folderId);

    BookmarksEntry existingEntry = _stagedModelRepository.fetchStagedModelByUuidAndGroupId(entry.getUuid(),
            portletDataContext.getScopeGroupId());

    if (existingEntry == null) {
        importedEntry = _stagedModelRepository.addStagedModel(portletDataContext, importedEntry);
    } else {/*www.  j  ava2 s .co  m*/
        importedEntry.setEntryId(existingEntry.getEntryId());

        importedEntry = _stagedModelRepository.updateStagedModel(portletDataContext, importedEntry);
    }

    portletDataContext.importClassedModel(entry, importedEntry);
}

From source file:com.liferay.bookmarks.internal.exportimport.data.handler.BookmarksFolderStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, BookmarksFolder folder)
        throws Exception {

    Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(BookmarksFolder.class);

    long parentFolderId = MapUtil.getLong(folderIds, folder.getParentFolderId(), folder.getParentFolderId());

    BookmarksFolder importedFolder = (BookmarksFolder) folder.clone();

    importedFolder.setGroupId(portletDataContext.getScopeGroupId());
    importedFolder.setParentFolderId(parentFolderId);

    BookmarksFolder existingFolder = _stagedModelRepository.fetchStagedModelByUuidAndGroupId(folder.getUuid(),
            portletDataContext.getScopeGroupId());

    if (existingFolder == null) {
        importedFolder = _stagedModelRepository.addStagedModel(portletDataContext, importedFolder);
    } else {//from w  ww.ja va  2s.c o  m
        importedFolder.setFolderId(existingFolder.getFolderId());

        importedFolder = _stagedModelRepository.updateStagedModel(portletDataContext, importedFolder);
    }

    portletDataContext.importClassedModel(folder, importedFolder);
}

From source file:com.liferay.bookmarks.internal.exportimport.portlet.preferences.processor.BookmarksExportImportPortletPreferencesProcessor.java

License:Open Source License

@Override
public PortletPreferences processImportPortletPreferences(PortletDataContext portletDataContext,
        PortletPreferences portletPreferences) throws PortletDataException {

    long rootFolderId = GetterUtil.getLong(portletPreferences.getValue("rootFolderId", null));

    if (rootFolderId <= 0) {
        return portletPreferences;
    }/*  w  w w  . j ava 2  s. c  om*/

    String rootFolderPath = ExportImportPathUtil.getModelPath(portletDataContext,
            BookmarksFolder.class.getName(), rootFolderId);

    BookmarksFolder folder = (BookmarksFolder) portletDataContext.getZipEntryAsObject(rootFolderPath);

    StagedModelDataHandlerUtil.importStagedModel(portletDataContext, folder);

    Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(BookmarksFolder.class);

    rootFolderId = MapUtil.getLong(folderIds, rootFolderId, rootFolderId);

    try {
        portletPreferences.setValue("rootFolderId", String.valueOf(rootFolderId));
    } catch (ReadOnlyException roe) {
        throw new PortletDataException("Unable to update preference \"rootFolderId\"", roe);
    }

    return portletPreferences;
}

From source file:com.liferay.calendar.internal.exportimport.data.handler.CalendarBookingStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, CalendarBooking calendarBooking)
        throws Exception {

    long userId = portletDataContext.getUserId(calendarBooking.getUserUuid());

    Map<Long, Long> calendarIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Calendar.class);

    long calendarId = MapUtil.getLong(calendarIds, calendarBooking.getCalendarId(),
            calendarBooking.getCalendarId());

    long parentCalendarBookingId = CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT;

    if (!calendarBooking.isMasterBooking()) {
        Map<Long, Long> calendarBookingIds = (Map<Long, Long>) portletDataContext
                .getNewPrimaryKeysMap(CalendarBooking.class);

        parentCalendarBookingId = MapUtil.getLong(calendarBookingIds,
                calendarBooking.getParentCalendarBookingId(), calendarBooking.getParentCalendarBookingId());
    }//www.  ja v a2s.  com

    long recurringCalendarBookingId = CalendarBookingConstants.RECURRING_CALENDAR_BOOKING_ID_DEFAULT;

    if (!calendarBooking.isMasterRecurringBooking()) {
        recurringCalendarBookingId = calendarBooking.getRecurringCalendarBookingId();
    }

    ServiceContext serviceContext = portletDataContext.createServiceContext(calendarBooking);

    CalendarBooking importedCalendarBooking = null;

    if (portletDataContext.isDataStrategyMirror()) {
        CalendarBooking existingCalendarBooking = fetchStagedModelByUuidAndGroupId(calendarBooking.getUuid(),
                portletDataContext.getScopeGroupId());

        if (existingCalendarBooking == null) {
            serviceContext.setUuid(calendarBooking.getUuid());

            importedCalendarBooking = _calendarBookingLocalService.addCalendarBooking(userId, calendarId,
                    new long[0], parentCalendarBookingId, recurringCalendarBookingId,
                    calendarBooking.getTitleMap(), calendarBooking.getDescriptionMap(),
                    calendarBooking.getLocation(), calendarBooking.getStartTime(), calendarBooking.getEndTime(),
                    calendarBooking.isAllDay(), calendarBooking.getRecurrence(),
                    calendarBooking.getFirstReminder(), calendarBooking.getFirstReminderType(),
                    calendarBooking.getSecondReminder(), calendarBooking.getSecondReminderType(),
                    serviceContext);
        } else {
            importedCalendarBooking = _calendarBookingLocalService.updateCalendarBooking(userId,
                    existingCalendarBooking.getCalendarBookingId(), calendarId, calendarBooking.getTitleMap(),
                    calendarBooking.getDescriptionMap(), calendarBooking.getLocation(),
                    calendarBooking.getStartTime(), calendarBooking.getEndTime(), calendarBooking.isAllDay(),
                    calendarBooking.getRecurrence(), calendarBooking.getFirstReminder(),
                    calendarBooking.getFirstReminderType(), calendarBooking.getSecondReminder(),
                    calendarBooking.getSecondReminderType(), serviceContext);
        }
    } else {
        importedCalendarBooking = _calendarBookingLocalService.addCalendarBooking(userId, calendarId,
                new long[0], parentCalendarBookingId, recurringCalendarBookingId, calendarBooking.getTitleMap(),
                calendarBooking.getDescriptionMap(), calendarBooking.getLocation(),
                calendarBooking.getStartTime(), calendarBooking.getEndTime(), calendarBooking.isAllDay(),
                calendarBooking.getRecurrence(), calendarBooking.getFirstReminder(),
                calendarBooking.getFirstReminderType(), calendarBooking.getSecondReminder(),
                calendarBooking.getSecondReminderType(), serviceContext);
    }

    // The root discussion message is not automatically imported when
    // importing a calendar booking

    List<Element> mbMessageElements = portletDataContext.getReferenceElements(calendarBooking, MBMessage.class);

    if (ListUtil.isNotEmpty(mbMessageElements)) {
        _mbMessageLocalService.addDiscussionMessage(userId, importedCalendarBooking.getUserName(),
                importedCalendarBooking.getGroupId(), CalendarBooking.class.getName(),
                importedCalendarBooking.getCalendarBookingId(), WorkflowConstants.ACTION_PUBLISH);
    }

    portletDataContext.importClassedModel(calendarBooking, importedCalendarBooking);
}

From source file:com.liferay.calendar.internal.exportimport.data.handler.CalendarNotificationTemplateStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext,
        CalendarNotificationTemplate calendarNotificationTemplate) throws Exception {

    long userId = portletDataContext.getUserId(calendarNotificationTemplate.getUserUuid());

    Map<Long, Long> calendarIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Calendar.class);

    long calendarId = MapUtil.getLong(calendarIds, calendarNotificationTemplate.getCalendarId(),
            calendarNotificationTemplate.getCalendarId());

    NotificationType notificationType = NotificationType
            .parse(calendarNotificationTemplate.getNotificationType());
    NotificationTemplateType notificationTemplateType = NotificationTemplateType
            .parse(calendarNotificationTemplate.getNotificationTemplateType());

    ServiceContext serviceContext = portletDataContext.createServiceContext(calendarNotificationTemplate);

    CalendarNotificationTemplate importedCalendarNotificationTemplate = null;

    String body = _calendarNotificationTemplateExportImportContentProcessor.replaceImportContentReferences(
            portletDataContext, calendarNotificationTemplate, calendarNotificationTemplate.getBody());

    if (portletDataContext.isDataStrategyMirror()) {
        CalendarNotificationTemplate existingCalendarNotificationTemplate = fetchStagedModelByUuidAndGroupId(
                calendarNotificationTemplate.getUuid(), portletDataContext.getScopeGroupId());

        if (existingCalendarNotificationTemplate == null) {
            serviceContext.setUuid(calendarNotificationTemplate.getUuid());

            importedCalendarNotificationTemplate = _calendarNotificationTemplateLocalService
                    .addCalendarNotificationTemplate(userId, calendarId, notificationType,
                            calendarNotificationTemplate.getNotificationTypeSettings(),
                            notificationTemplateType, calendarNotificationTemplate.getSubject(), body,
                            serviceContext);
        } else {//from  w  w  w  .java  2s  .  c  om
            importedCalendarNotificationTemplate = _calendarNotificationTemplateLocalService
                    .updateCalendarNotificationTemplate(
                            existingCalendarNotificationTemplate.getCalendarNotificationTemplateId(),
                            calendarNotificationTemplate.getNotificationTypeSettings(),
                            calendarNotificationTemplate.getSubject(), body, serviceContext);
        }
    } else {
        importedCalendarNotificationTemplate = _calendarNotificationTemplateLocalService
                .addCalendarNotificationTemplate(userId, calendarId, notificationType,
                        calendarNotificationTemplate.getNotificationTypeSettings(), notificationTemplateType,
                        calendarNotificationTemplate.getSubject(), body, serviceContext);
    }

    portletDataContext.importClassedModel(calendarNotificationTemplate, importedCalendarNotificationTemplate);
}