@Override
  protected PortletPreferences doProcessImportPortletPreferences(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    portletDataContext.importPortletPermissions(WikiPermission.RESOURCE_NAME);

    StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, WikiNode.class);

    StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, WikiPage.class);

    long nodeId = GetterUtil.getLong(portletPreferences.getValue("nodeId", StringPool.BLANK));

    if (nodeId > 0) {
      Map<Long, Long> nodeIds =
          (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(WikiNode.class);

      nodeId = MapUtil.getLong(nodeIds, nodeId, nodeId);

      portletPreferences.setValue("nodeId", String.valueOf(nodeId));
    }

    return portletPreferences;
  }
Пример #2
0
  @Override
  protected PortletPreferences doProcessImportPortletPreferences(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    portletDataContext.importPortletPermissions(DDLPermission.RESOURCE_NAME);

    StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, DDLRecordSet.class);

    long importedRecordSetId = GetterUtil.getLong(portletPreferences.getValue("recordSetId", null));
    long importedDisplayDDMTemplateId =
        GetterUtil.getLong(portletPreferences.getValue("displayDDMTemplateId", null));
    long importedFormDDMTemplateId =
        GetterUtil.getLong(portletPreferences.getValue("formDDMTemplateId", null));

    Map<Long, Long> recordSetIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DDLRecordSet.class);

    long recordSetId = MapUtil.getLong(recordSetIds, importedRecordSetId, importedRecordSetId);

    Map<Long, Long> templateIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DDMTemplate.class);

    long displayDDMTemplateId =
        MapUtil.getLong(templateIds, importedDisplayDDMTemplateId, importedDisplayDDMTemplateId);

    long formDDMTemplateId =
        MapUtil.getLong(templateIds, importedFormDDMTemplateId, importedFormDDMTemplateId);

    portletPreferences.setValue("recordSetId", String.valueOf(recordSetId));
    portletPreferences.setValue("displayDDMTemplateId", String.valueOf(displayDDMTemplateId));
    portletPreferences.setValue("formDDMTemplateId", String.valueOf(formDDMTemplateId));

    return portletPreferences;
  }
  @Override
  protected void doImportStagedModel(
      PortletDataContext portletDataContext, DLFileEntryType fileEntryType) throws Exception {

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

    StagedModelDataHandlerUtil.importReferenceStagedModels(
        portletDataContext, fileEntryType, DDMStructure.class);

    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);

    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;
      }

      importedDDMStructure.setStructureKey(importedDLFileEntryDDMStructureKey);

      DDMStructureLocalServiceUtil.updateDDMStructure(importedDDMStructure);
    }
  }
  protected void doImportStagedModel(
      PortletDataContext portletDataContext, CalendarResource calendarResource) throws Exception {

    prepareLanguagesForImport(calendarResource);

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

    StagedModelDataHandlerUtil.importReferenceStagedModels(
        portletDataContext, calendarResource, Calendar.class);

    long classPK = getClassPK(portletDataContext, calendarResource, userId);
    Map<Locale, String> calendarResourceNameMap =
        getCalendarResourceNameMap(portletDataContext, calendarResource);

    ServiceContext serviceContext = portletDataContext.createServiceContext(calendarResource);

    CalendarResource importedCalendarResource = null;

    if (portletDataContext.isDataStrategyMirror()) {
      CalendarResource existingCalendarResource =
          CalendarResourceLocalServiceUtil.fetchCalendarResourceByUuidAndGroupId(
              calendarResource.getUuid(), portletDataContext.getScopeGroupId());

      if (existingCalendarResource == null) {
        existingCalendarResource =
            CalendarResourceLocalServiceUtil.fetchCalendarResource(
                calendarResource.getClassNameId(), classPK);
      }

      if (existingCalendarResource == null) {
        serviceContext.setUuid(calendarResource.getUuid());

        importedCalendarResource =
            CalendarResourceLocalServiceUtil.addCalendarResource(
                userId,
                portletDataContext.getScopeGroupId(),
                calendarResource.getClassNameId(),
                classPK,
                calendarResource.getClassUuid(),
                calendarResource.getCode(),
                calendarResourceNameMap,
                calendarResource.getDescriptionMap(),
                calendarResource.isActive(),
                serviceContext);
      } else {
        importedCalendarResource =
            CalendarResourceLocalServiceUtil.updateCalendarResource(
                existingCalendarResource.getCalendarResourceId(),
                calendarResource.getNameMap(),
                calendarResource.getDescriptionMap(),
                calendarResource.isActive(),
                serviceContext);
      }
    } else {
      importedCalendarResource =
          CalendarResourceLocalServiceUtil.addCalendarResource(
              userId,
              portletDataContext.getScopeGroupId(),
              calendarResource.getClassNameId(),
              classPK,
              calendarResource.getClassUuid(),
              calendarResource.getCode(),
              calendarResourceNameMap,
              calendarResource.getDescriptionMap(),
              calendarResource.isActive(),
              serviceContext);
    }

    updateCalendars(portletDataContext, calendarResource, importedCalendarResource);

    portletDataContext.importClassedModel(calendarResource, importedCalendarResource);
  }
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, Repository repository)
      throws Exception {

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

    ServiceContext serviceContext = portletDataContext.createServiceContext(repository);

    Repository importedRepository = null;

    Element repositoryElement = portletDataContext.getImportDataStagedModelElement(repository);

    try {
      boolean hidden = GetterUtil.getBoolean(repositoryElement.attributeValue("hidden"));

      if (portletDataContext.isDataStrategyMirror()) {
        Repository existingRepository =
            RepositoryLocalServiceUtil.fetchRepositoryByUuidAndGroupId(
                repository.getUuid(), portletDataContext.getScopeGroupId());

        if (existingRepository == null) {
          existingRepository =
              RepositoryLocalServiceUtil.fetchRepository(
                  portletDataContext.getScopeGroupId(), repository.getName());
        }

        long classNameId = 0;

        if (existingRepository != null) {
          classNameId = existingRepository.getClassNameId();
        }

        if ((existingRepository == null)
            || (classNameId != PortalUtil.getClassNameId(LiferayRepository.class))) {

          serviceContext.setUuid(repository.getUuid());

          importedRepository =
              RepositoryLocalServiceUtil.addRepository(
                  userId,
                  portletDataContext.getScopeGroupId(),
                  repository.getClassNameId(),
                  DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
                  repository.getName(),
                  repository.getDescription(),
                  repository.getPortletId(),
                  repository.getTypeSettingsProperties(),
                  hidden,
                  serviceContext);
        } else {
          RepositoryLocalServiceUtil.updateRepository(
              existingRepository.getRepositoryId(),
              repository.getName(),
              repository.getDescription());

          importedRepository = existingRepository;
        }
      } else {
        importedRepository =
            RepositoryLocalServiceUtil.addRepository(
                userId,
                portletDataContext.getScopeGroupId(),
                repository.getClassNameId(),
                DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
                repository.getName(),
                repository.getDescription(),
                repository.getPortletId(),
                repository.getTypeSettingsProperties(),
                hidden,
                serviceContext);
      }
    } catch (Exception e) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "Unable to connect to repository {name="
                + repository.getName()
                + ", typeSettings="
                + repository.getTypeSettingsProperties()
                + "}",
            e);
      }
    }

    portletDataContext.importClassedModel(repository, importedRepository);

    StagedModelDataHandlerUtil.importReferenceStagedModels(
        portletDataContext, repository, RepositoryEntry.class);
  }