public RepositoryFileDto updateFile(
     RepositoryFileDto file, NodeRepositoryFileDataDto data, String versionMessage) {
   return repositoryFileAdapter.marshal(
       repo.updateFile(
           repositoryFileAdapter.unmarshal(file),
           nodeRepositoryFileDataAdapter.unmarshal(data),
           versionMessage));
 }
コード例 #2
0
  /**
   * Copies the file bundle into the repository
   *
   * @param bundle
   * @param bundlePath
   * @param bundlePathName
   * @param file
   * @param comment
   */
  protected boolean copyFileToRepository(
      final ImportSource.IRepositoryFileBundle bundle,
      final String bundlePathName,
      final String repositoryPath,
      final RepositoryFile file,
      final String comment) {
    // Compute the file extension
    final String name = bundle.getFile().getName();
    final String ext = RepositoryFilenameUtils.getExtension(name);
    if (StringUtils.isEmpty(ext)) {
      log.debug("Skipping file without extension: " + bundlePathName);
      return false;
    }

    // Check the mime type
    final String mimeType = bundle.getMimeType();
    if (mimeType == null) {
      log.debug("Skipping file without mime-type: " + bundlePathName);
      return false;
    }

    // Find the converter
    final Converter converter = converters.get(ext);
    if (converter == null) {
      log.debug("Skipping file without converter: " + bundlePathName);
      return false;
    }

    // Copy the file into the repository
    try {
      log.trace("copying file to repository: " + bundlePathName);
      IRepositoryFileData data =
          converter.convert(bundle.getInputStream(), bundle.getCharset(), mimeType);
      if (null == file) {
        final boolean hidden = !executableTypes.contains(ext.toLowerCase());
        log.trace("\tsetting hidden=" + hidden + " for file with extension " + ext.toLowerCase());
        createFile(bundle, repositoryPath, hidden, data, comment);
      } else {
        repository.updateFile(file, data, comment);
      }
      return true;
    } catch (IOException e) {
      log.warn(
          messages.getString("DefaultImportHandler.WARN_0003_IOEXCEPTION", name),
          e); // TODO make sure string
      // exists
      return false;
    }
  }
コード例 #3
0
  @Override
  public void addLocalizationFile(
      final String domainId,
      final String locale,
      final InputStream inputStream,
      final boolean overwrite)
      throws DomainStorageException {
    if (logger.isDebugEnabled()) {
      logger.debug("addLocalizationFile(" + domainId + ", " + locale + ", inputStream)");
    }
    if (null != inputStream) {
      if (StringUtils.isEmpty(domainId) || StringUtils.isEmpty(locale)) {
        throw new IllegalArgumentException(
            messages.getErrorString(
                "PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
      }

      lock.writeLock().lock();
      try {
        // Check for duplicates
        final RepositoryFile localeFile = metadataMapping.getLocaleFile(domainId, locale);
        if (!overwrite && localeFile != null) {
          throw new DomainStorageException(
              messages.getErrorString(
                  "PentahoMetadataDomainRepository.ERROR_0009_LOCALE_ALREADY_EXISTS",
                  domainId,
                  locale),
              null);
        }

        final SimpleRepositoryFileData data =
            new SimpleRepositoryFileData(inputStream, DEFAULT_ENCODING, LOCALE_MIME_TYPE);
        if (localeFile == null) {
          final RepositoryFile newLocaleFile = createUniqueFile(domainId, locale, data);
          metadataMapping.addLocale(domainId, locale, newLocaleFile);
        } else {
          repository.updateFile(localeFile, data, null);
        }
        // This invalidates any cached information
        flushDomains();
      } finally {
        lock.writeLock().unlock();
      }
    }
  }
コード例 #4
0
  @Override
  public void storeDomain(
      InputStream inputStream, String domainId, boolean overwrite, RepositoryFileAcl acl)
      throws DomainIdNullException, DomainAlreadyExistsException, DomainStorageException {
    if (logger.isDebugEnabled()) {
      logger.debug(String.format("storeDomain(inputStream, %s, %s, %s)", domainId, overwrite, acl));
    }
    if (null == inputStream) {
      throw new IllegalArgumentException();
    }
    if (StringUtils.isEmpty(domainId)) {
      throw new DomainIdNullException(
          messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0001_DOMAIN_ID_NULL"));
    }

    // Check to see if the domain already exists
    final RepositoryFile domainFile = getMetadataRepositoryFile(domainId);
    if (!overwrite && domainFile != null) {
      final String errorString =
          messages.getErrorString(
              "PentahoMetadataDomainRepository.ERROR_0002_DOMAIN_ALREADY_EXISTS", domainId);
      logger.error(errorString);
      throw new DomainAlreadyExistsException(errorString);
    }

    // Check if this is valid xml
    InputStream inputStream2;
    String xmi;
    try {
      // try to see if the xmi can be parsed (ie, check if it's valid xmi)
      // first, convert our input stream to a string
      StringBuilder stringBuilder = new StringBuilder();
      BufferedReader reader =
          new BufferedReader(new InputStreamReader(inputStream, DEFAULT_ENCODING));
      try {
        while ((xmi = reader.readLine()) != null) {
          stringBuilder.append(xmi);
        }
      } finally {
        inputStream.close();
      }

      if (!isDomainIdXmiEqualsOrNotPresent(domainId, getDomainIdFromXmi(stringBuilder))) {
        domainId = replaceDomainId(stringBuilder, domainId);
      }

      xmi = stringBuilder.toString();
      // now, try to see if the xmi can be parsed (ie, check if it's valid xmi)
      byte[] xmiBytes = xmi.getBytes(DEFAULT_ENCODING);
      inputStream2 = new java.io.ByteArrayInputStream(xmiBytes);
      xmiParser.parseXmi(inputStream2);
      // xmi is valid. Create a new inputstream for the actual import action.
      inputStream2.reset();
    } catch (Exception ex) {
      logger.error(ex.getMessage());
      // throw new
      // DomainStorageException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0010_ERROR_PARSING_XMI"),
      // ex);
      java.io.ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      ex.printStackTrace(new java.io.PrintStream(byteArrayOutputStream));
      throw new DomainStorageException(byteArrayOutputStream.toString(), ex);
    }

    final SimpleRepositoryFileData data =
        new SimpleRepositoryFileData(inputStream2, DEFAULT_ENCODING, DOMAIN_MIME_TYPE);
    final RepositoryFile newDomainFile;
    if (domainFile == null) {
      newDomainFile = createUniqueFile(domainId, null, data);
    } else {
      newDomainFile = repository.updateFile(domainFile, data, null);
    }

    // This invalidates any caching
    flushDomains();

    getAclHelper().setAclFor(newDomainFile, acl);
  }