@Override protected void doImportStagedModel( PortletDataContext portletDataContext, DLFileEntryType fileEntryType) throws Exception { long userId = portletDataContext.getUserId(fileEntryType.getUserUuid()); List<Element> ddmStructureReferenceElements = portletDataContext.getReferenceElements( fileEntryType, com.liferay.dynamic.data.mapping.model.DDMStructure.class); long[] ddmStructureIdsArray = new long[ddmStructureReferenceElements.size()]; Map<Long, Long> ddmStructureIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap( com.liferay.dynamic.data.mapping.model.DDMStructure.class); for (int i = 0; i < ddmStructureReferenceElements.size(); i++) { Element ddmStructureReferenceElement = ddmStructureReferenceElements.get(i); long ddmStructureId = GetterUtil.getLong(ddmStructureReferenceElement.attributeValue("class-pk")); ddmStructureIdsArray[i] = MapUtil.getLong(ddmStructureIds, ddmStructureId); } ServiceContext serviceContext = portletDataContext.createServiceContext(fileEntryType); DLFileEntryType importedDLFileEntryType = null; Element element = portletDataContext.getImportDataStagedModelElement(fileEntryType); boolean preloaded = GetterUtil.getBoolean(element.attributeValue("preloaded")); if (portletDataContext.isDataStrategyMirror()) { DLFileEntryType existingDLFileEntryType = fetchExistingFileEntryType( fileEntryType.getUuid(), portletDataContext.getScopeGroupId(), fileEntryType.getFileEntryTypeKey(), preloaded); if (existingDLFileEntryType == null) { serviceContext.setUuid(fileEntryType.getUuid()); importedDLFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType( userId, portletDataContext.getScopeGroupId(), fileEntryType.getFileEntryTypeKey(), fileEntryType.getNameMap(), fileEntryType.getDescriptionMap(), ddmStructureIdsArray, serviceContext); } else { DLFileEntryTypeLocalServiceUtil.updateFileEntryType( userId, existingDLFileEntryType.getFileEntryTypeId(), fileEntryType.getNameMap(), fileEntryType.getDescriptionMap(), ddmStructureIdsArray, serviceContext); importedDLFileEntryType = DLFileEntryTypeLocalServiceUtil.fetchDLFileEntryType( existingDLFileEntryType.getFileEntryTypeId()); } } else { importedDLFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType( userId, portletDataContext.getScopeGroupId(), fileEntryType.getFileEntryTypeKey(), fileEntryType.getNameMap(), fileEntryType.getDescriptionMap(), ddmStructureIdsArray, serviceContext); } portletDataContext.importClassedModel(fileEntryType, importedDLFileEntryType); if (preloaded) { return; } String importedDLFileEntryDDMStructureKey = DLUtil.getDDMStructureKey(importedDLFileEntryType); List<DDMStructure> importedDDMStructures = importedDLFileEntryType.getDDMStructures(); for (DDMStructure importedDDMStructure : importedDDMStructures) { String ddmStructureKey = importedDDMStructure.getStructureKey(); if (!DLUtil.isAutoGeneratedDLFileEntryTypeDDMStructureKey(ddmStructureKey)) { continue; } if (ddmStructureKey.equals(importedDLFileEntryDDMStructureKey)) { continue; } com.liferay.dynamic.data.mapping.model.DDMStructure ddmStructure = _ddmStructureLocalService.getDDMStructure(importedDDMStructure.getStructureId()); ddmStructure.setStructureKey(importedDLFileEntryDDMStructureKey); _ddmStructureLocalService.updateDDMStructure(ddmStructure); } }
@Override protected void doImportStagedModel( PortletDataContext portletDataContext, DLFileEntryType fileEntryType) throws Exception { long userId = portletDataContext.getUserId(fileEntryType.getUserUuid()); List<Element> ddmStructureElements = portletDataContext.getReferenceDataElements(fileEntryType, DDMStructure.class); for (Element ddmStructureElement : ddmStructureElements) { StagedModelDataHandlerUtil.importStagedModel(portletDataContext, ddmStructureElement); } List<Element> ddmStructureReferenceElements = portletDataContext.getReferenceElements(fileEntryType, DDMStructure.class); long[] ddmStructureIdsArray = new long[ddmStructureReferenceElements.size()]; Map<Long, Long> ddmStructureIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DDMStructure.class); for (int i = 0; i < ddmStructureReferenceElements.size(); i++) { Element ddmStructureReferenceElement = ddmStructureReferenceElements.get(i); long ddmStructureId = GetterUtil.getLong(ddmStructureReferenceElement.attributeValue("class-pk")); ddmStructureIdsArray[i] = MapUtil.getLong(ddmStructureIds, ddmStructureId); } ServiceContext serviceContext = portletDataContext.createServiceContext(fileEntryType, DLPortletDataHandler.NAMESPACE); DLFileEntryType importedDLFileEntryType = null; if (portletDataContext.isDataStrategyMirror()) { DLFileEntryType existingDLFileEntryType = DLFileEntryTypeLocalServiceUtil.fetchDLFileEntryTypeByUuidAndGroupId( fileEntryType.getUuid(), portletDataContext.getScopeGroupId()); if (existingDLFileEntryType == null) { existingDLFileEntryType = DLFileEntryTypeLocalServiceUtil.fetchDLFileEntryTypeByUuidAndGroupId( fileEntryType.getUuid(), portletDataContext.getCompanyGroupId()); } if (existingDLFileEntryType == null) { serviceContext.setUuid(fileEntryType.getUuid()); importedDLFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType( userId, portletDataContext.getScopeGroupId(), fileEntryType.getFileEntryTypeKey(), fileEntryType.getNameMap(), fileEntryType.getDescriptionMap(), ddmStructureIdsArray, serviceContext); } else if (portletDataContext.isCompanyStagedGroupedModel(existingDLFileEntryType)) { return; } else { DLFileEntryTypeLocalServiceUtil.updateFileEntryType( userId, existingDLFileEntryType.getFileEntryTypeId(), fileEntryType.getNameMap(), fileEntryType.getDescriptionMap(), ddmStructureIdsArray, serviceContext); } } else { importedDLFileEntryType = DLFileEntryTypeLocalServiceUtil.addFileEntryType( userId, portletDataContext.getScopeGroupId(), fileEntryType.getFileEntryTypeKey(), fileEntryType.getNameMap(), fileEntryType.getDescriptionMap(), ddmStructureIdsArray, serviceContext); } portletDataContext.importClassedModel( fileEntryType, importedDLFileEntryType, DLPortletDataHandler.NAMESPACE); String importedDLFileEntryDDMStructureKey = DLUtil.getDDMStructureKey(importedDLFileEntryType); List<DDMStructure> importedDDMStructures = importedDLFileEntryType.getDDMStructures(); for (DDMStructure importedDDMStructure : importedDDMStructures) { String ddmStructureKey = importedDDMStructure.getStructureKey(); if (!DLUtil.isAutoGeneratedDLFileEntryTypeDDMStructureKey(ddmStructureKey)) { continue; } if (ddmStructureKey.equals(importedDLFileEntryDDMStructureKey)) { continue; } importedDDMStructure.setStructureKey(importedDLFileEntryDDMStructureKey); DDMStructureLocalServiceUtil.updateDDMStructure(importedDDMStructure); } }