コード例 #1
0
  @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);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, FileEntry fileEntry)
      throws Exception {

    Element fileEntryElement = portletDataContext.getExportDataElement(fileEntry);

    String fileEntryPath = ExportImportPathUtil.getModelPath(fileEntry);

    if (!fileEntry.isDefaultRepository()) {
      Repository repository = RepositoryLocalServiceUtil.getRepository(fileEntry.getRepositoryId());

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, fileEntry, repository, PortletDataContext.REFERENCE_TYPE_STRONG);

      portletDataContext.addClassedModel(fileEntryElement, fileEntryPath, fileEntry);

      long portletRepositoryClassNameId =
          PortalUtil.getClassNameId(PortletRepository.class.getName());

      if (repository.getClassNameId() != portletRepositoryClassNameId) {
        return;
      }
    }

    if (fileEntry.getFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext,
          fileEntry,
          fileEntry.getFolder(),
          PortletDataContext.REFERENCE_TYPE_PARENT);
    }

    LiferayFileEntry liferayFileEntry = (LiferayFileEntry) fileEntry;

    liferayFileEntry.setCachedFileVersion(fileEntry.getFileVersion());

    if (!portletDataContext.isPerformDirectBinaryImport()) {
      InputStream is = null;

      try {
        is = FileEntryUtil.getContentStream(fileEntry);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn("Unable to retrieve content for file entry " + fileEntry.getFileEntryId(), e);
        }
      }

      if (is == null) {
        fileEntryElement.detach();

        return;
      }

      try {
        String binPath = ExportImportPathUtil.getModelPath(fileEntry, fileEntry.getVersion());

        portletDataContext.addZipEntry(binPath, is);

        fileEntryElement.addAttribute("bin-path", binPath);
      } finally {
        try {
          is.close();
        } catch (IOException ioe) {
          _log.error(ioe, ioe);
        }
      }
    }

    if (portletDataContext.getBooleanParameter(
        DLPortletDataHandler.NAMESPACE, "previews-and-thumbnails")) {

      DLProcessorRegistryUtil.exportGeneratedFiles(portletDataContext, fileEntry, fileEntryElement);
    }

    exportMetaData(portletDataContext, fileEntryElement, fileEntry);

    portletDataContext.addClassedModel(
        fileEntryElement, fileEntryPath, liferayFileEntry, DLFileEntry.class);
  }