Program: 47337
Project: 47337
Buggy source:
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
  RepositoryFileImportBundle importBundle=(RepositoryFileImportBundle)bundle;
  ZipInputStream zipImportStream=new ZipInputStream(bundle.getInputStream());
  SolutionRepositoryImportSource importSource=new SolutionRepositoryImportSource(zipImportStream);
  LocaleFilesProcessor localeFilesProcessor=new LocaleFilesProcessor();
  setOverwriteFile(bundle.overwriteInRepository());
  IPlatformImporter importer=PentahoSystem.get(IPlatformImporter.class);
  cachedImports=new HashMap<String,RepositoryFileImportBundle.Builder>();
  ExportManifest manifest=getImportSession().getManifest();
  String manifestVersion=null;
  if (manifest != null) {
    manifestVersion=manifest.getManifestInformation().getManifestVersion();
  }
  if (manifest != null) {
    Map<String,List<String>> roleToUserMap=importUsers(manifest.getUserExports());
    importRoles(manifest.getRoleExports(),roleToUserMap);
    List<ExportManifestMetadata> metadataList=manifest.getMetadataList();
    for (    ExportManifestMetadata exportManifestMetadata : metadataList) {
      String domainId=exportManifestMetadata.getDomainId();
      boolean overWriteInRepository=isOverwriteFile();
      RepositoryFileImportBundle.Builder bundleBuilder=new RepositoryFileImportBundle.Builder().charSet("String_Node_Str").hidden(false).preserveDsw(bundle.isPreserveDsw()).overwriteFile(overWriteInRepository).mime("String_Node_Str").withParam("String_Node_Str",domainId);
      cachedImports.put(exportManifestMetadata.getFile(),bundleBuilder);
    }
    List<ExportManifestMondrian> mondrianList=manifest.getMondrianList();
    for (    ExportManifestMondrian exportManifestMondrian : mondrianList) {
      String catName=exportManifestMondrian.getCatalogName();
      Parameters parametersMap=exportManifestMondrian.getParameters();
      StringBuilder parametersStr=new StringBuilder();
      for (      String s : parametersMap.keySet()) {
        parametersStr.append(s).append("String_Node_Str").append(parametersMap.get(s)).append(sep);
      }
      RepositoryFileImportBundle.Builder bundleBuilder=new RepositoryFileImportBundle.Builder().charSet("String_Node_Str").hidden(false).name(catName).overwriteFile(isOverwriteFile()).mime("String_Node_Str").withParam("String_Node_Str",parametersStr.toString()).withParam("String_Node_Str",catName);
      String xmlaEnabled="String_Node_Str" + exportManifestMondrian.isXmlaEnabled();
      bundleBuilder.withParam("String_Node_Str",xmlaEnabled);
      cachedImports.put(exportManifestMondrian.getFile(),bundleBuilder);
      String annotationsFile=exportManifestMondrian.getAnnotationsFile();
      if (annotationsFile != null) {
        RepositoryFileImportBundle.Builder annotationsBundle=new RepositoryFileImportBundle.Builder().path(MondrianCatalogRepositoryHelper.ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catName).name("String_Node_Str").charSet("String_Node_Str").overwriteFile(isOverwriteFile()).mime("String_Node_Str").hidden(false).withParam("String_Node_Str",catName);
        cachedImports.put(annotationsFile,annotationsBundle);
      }
    }
  }
  importMetaStore(manifest,bundle.overwriteInRepository());
  for (  IRepositoryFileBundle file : importSource.getFiles()) {
    String fileName=file.getFile().getName();
    String actualFilePath=file.getPath();
    if (manifestVersion != null) {
      fileName=ExportFileNameEncoder.decodeZipFileName(fileName);
      actualFilePath=ExportFileNameEncoder.decodeZipFileName(actualFilePath);
    }
    String repositoryFilePath=RepositoryFilenameUtils.concat(PentahoPlatformImporter.computeBundlePath(actualFilePath),fileName);
    if (this.cachedImports.containsKey(repositoryFilePath)) {
      byte[] bytes=IOUtils.toByteArray(file.getInputStream());
      RepositoryFileImportBundle.Builder builder=cachedImports.get(repositoryFilePath);
      builder.input(new ByteArrayInputStream(bytes));
      importer.importFile(build(builder));
      continue;
    }
    RepositoryFileImportBundle.Builder bundleBuilder=new RepositoryFileImportBundle.Builder();
    InputStream bundleInputStream=null;
    String decodedFilePath=file.getPath();
    RepositoryFile decodedFile=file.getFile();
    if (manifestVersion != null) {
      decodedFile=new RepositoryFile.Builder(decodedFile).path(decodedFilePath).name(fileName).title(fileName).build();
      decodedFilePath=ExportFileNameEncoder.decodeZipFileName(file.getPath());
    }
    if (file.getFile().isFolder()) {
      bundleBuilder.mime("String_Node_Str");
      bundleBuilder.file(decodedFile);
      fileName=repositoryFilePath;
      repositoryFilePath=importBundle.getPath();
    }
 else {
      byte[] bytes=IOUtils.toByteArray(file.getInputStream());
      bundleInputStream=new ByteArrayInputStream(bytes);
      if (localeFilesProcessor.isLocaleFile(file,importBundle.getPath(),bytes)) {
        log.trace("String_Node_Str" + repositoryFilePath + "String_Node_Str");
        continue;
      }
      bundleBuilder.input(bundleInputStream);
      bundleBuilder.mime(solutionHelper.getMime(fileName));
      String filePath=(decodedFilePath.equals("String_Node_Str") || decodedFilePath.equals("String_Node_Str")) ? "String_Node_Str" : decodedFilePath;
      repositoryFilePath=RepositoryFilenameUtils.concat(importBundle.getPath(),filePath);
    }
    bundleBuilder.name(fileName);
    bundleBuilder.path(repositoryFilePath);
    String sourcePath;
    if (decodedFilePath.startsWith("String_Node_Str")) {
      sourcePath=RepositoryFilenameUtils.concat(decodedFilePath.substring(1),fileName);
    }
 else {
      if (file.getFile().isFolder()) {
        sourcePath=fileName;
      }
 else {
        sourcePath=RepositoryFilenameUtils.concat(decodedFilePath,fileName);
      }
    }
    if (manifest != null && manifest.getExportManifestEntity(sourcePath) == null && file.getFile().isFolder()) {
      continue;
    }
    getImportSession().setCurrentManifestKey(sourcePath);
    bundleBuilder.charSet(bundle.getCharset());
    bundleBuilder.overwriteFile(bundle.overwriteInRepository());
    bundleBuilder.hidden(isFileHidden(bundle,sourcePath));
    bundleBuilder.applyAclSettings(bundle.isApplyAclSettings());
    bundleBuilder.retainOwnership(bundle.isRetainOwnership());
    bundleBuilder.overwriteAclSettings(bundle.isOverwriteAclSettings());
    bundleBuilder.acl(getImportSession().processAclForFile(sourcePath));
    IPlatformImportBundle platformImportBundle=build(bundleBuilder);
    importer.importFile(platformImportBundle);
    if (bundleInputStream != null) {
      bundleInputStream.close();
      bundleInputStream=null;
    }
  }
  if (manifest != null) {
    List<JobScheduleRequest> scheduleList=manifest.getScheduleList();
    if (scheduleList != null) {
      SchedulerResource schedulerResource=new SchedulerResource();
      for (      JobScheduleRequest jobScheduleRequest : scheduleList) {
        try {
          Response response=createSchedulerJob(schedulerResource,jobScheduleRequest);
          if (response.getStatus() == Response.Status.OK.getStatusCode()) {
            if (response.getEntity() != null) {
              ImportSession.getSession().addImportedScheduleJobId(response.getEntity().toString());
            }
          }
        }
 catch (        Exception e) {
          throw new PlatformImportException(Messages.getInstance().getString("String_Node_Str",e.getMessage()));
        }
      }
    }
    List<org.pentaho.database.model.DatabaseConnection> datasourceList=manifest.getDatasourceList();
    if (datasourceList != null) {
      IDatasourceMgmtService datasourceMgmtSvc=PentahoSystem.get(IDatasourceMgmtService.class);
      for (      org.pentaho.database.model.DatabaseConnection databaseConnection : datasourceList) {
        if (databaseConnection.getDatabaseType() == null) {
          log.warn("String_Node_Str" + databaseConnection.getName() + "String_Node_Str");
          continue;
        }
        try {
          IDatabaseConnection existingDBConnection=datasourceMgmtSvc.getDatasourceByName(databaseConnection.getName());
          if (existingDBConnection != null && existingDBConnection.getName() != null) {
            if (isOverwriteFile()) {
              databaseConnection.setId(existingDBConnection.getId());
              datasourceMgmtSvc.updateDatasourceByName(databaseConnection.getName(),databaseConnection);
            }
          }
 else {
            datasourceMgmtSvc.createDatasource(databaseConnection);
          }
        }
 catch (        Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
  localeFilesProcessor.processLocaleFiles(importer);
}

Fixed version (ground truth):
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
  RepositoryFileImportBundle importBundle=(RepositoryFileImportBundle)bundle;
  ZipInputStream zipImportStream=new ZipInputStream(bundle.getInputStream());
  SolutionRepositoryImportSource importSource=new SolutionRepositoryImportSource(zipImportStream);
  LocaleFilesProcessor localeFilesProcessor=new LocaleFilesProcessor();
  setOverwriteFile(bundle.overwriteInRepository());
  IPlatformImporter importer=PentahoSystem.get(IPlatformImporter.class);
  cachedImports=new HashMap<String,RepositoryFileImportBundle.Builder>();
  ExportManifest manifest=getImportSession().getManifest();
  String manifestVersion=null;
  if (manifest != null) {
    manifestVersion=manifest.getManifestInformation().getManifestVersion();
  }
  if (manifest != null) {
    Map<String,List<String>> roleToUserMap=importUsers(manifest.getUserExports());
    importRoles(manifest.getRoleExports(),roleToUserMap);
    List<ExportManifestMetadata> metadataList=manifest.getMetadataList();
    for (    ExportManifestMetadata exportManifestMetadata : metadataList) {
      String domainId=exportManifestMetadata.getDomainId();
      boolean overWriteInRepository=isOverwriteFile();
      RepositoryFileImportBundle.Builder bundleBuilder=new RepositoryFileImportBundle.Builder().charSet("String_Node_Str").hidden(false).preserveDsw(bundle.isPreserveDsw()).overwriteFile(overWriteInRepository).mime("String_Node_Str").withParam("String_Node_Str",domainId);
      cachedImports.put(exportManifestMetadata.getFile(),bundleBuilder);
    }
    List<ExportManifestMondrian> mondrianList=manifest.getMondrianList();
    for (    ExportManifestMondrian exportManifestMondrian : mondrianList) {
      String catName=exportManifestMondrian.getCatalogName();
      Parameters parametersMap=exportManifestMondrian.getParameters();
      StringBuilder parametersStr=new StringBuilder();
      for (      String s : parametersMap.keySet()) {
        parametersStr.append(s).append("String_Node_Str").append(parametersMap.get(s)).append(sep);
      }
      RepositoryFileImportBundle.Builder bundleBuilder=new RepositoryFileImportBundle.Builder().charSet("String_Node_Str").hidden(false).name(catName).overwriteFile(isOverwriteFile()).mime("String_Node_Str").withParam("String_Node_Str",parametersStr.toString()).withParam("String_Node_Str",catName);
      String xmlaEnabled="String_Node_Str" + exportManifestMondrian.isXmlaEnabled();
      bundleBuilder.withParam("String_Node_Str",xmlaEnabled);
      cachedImports.put(exportManifestMondrian.getFile(),bundleBuilder);
      String annotationsFile=exportManifestMondrian.getAnnotationsFile();
      if (annotationsFile != null) {
        RepositoryFileImportBundle.Builder annotationsBundle=new RepositoryFileImportBundle.Builder().path(MondrianCatalogRepositoryHelper.ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catName).name("String_Node_Str").charSet("String_Node_Str").overwriteFile(isOverwriteFile()).mime("String_Node_Str").hidden(false).withParam("String_Node_Str",catName);
        cachedImports.put(annotationsFile,annotationsBundle);
      }
    }
  }
  importMetaStore(manifest,bundle.overwriteInRepository());
  for (  IRepositoryFileBundle file : importSource.getFiles()) {
    String fileName=file.getFile().getName();
    String actualFilePath=file.getPath();
    if (manifestVersion != null) {
      fileName=ExportFileNameEncoder.decodeZipFileName(fileName);
      actualFilePath=ExportFileNameEncoder.decodeZipFileName(actualFilePath);
    }
    String repositoryFilePath=RepositoryFilenameUtils.concat(PentahoPlatformImporter.computeBundlePath(actualFilePath),fileName);
    if (this.cachedImports.containsKey(repositoryFilePath)) {
      byte[] bytes=IOUtils.toByteArray(file.getInputStream());
      RepositoryFileImportBundle.Builder builder=cachedImports.get(repositoryFilePath);
      builder.input(new ByteArrayInputStream(bytes));
      importer.importFile(build(builder));
      continue;
    }
    RepositoryFileImportBundle.Builder bundleBuilder=new RepositoryFileImportBundle.Builder();
    InputStream bundleInputStream=null;
    String decodedFilePath=file.getPath();
    RepositoryFile decodedFile=file.getFile();
    if (manifestVersion != null) {
      decodedFile=new RepositoryFile.Builder(decodedFile).path(decodedFilePath).name(fileName).title(fileName).build();
      decodedFilePath=ExportFileNameEncoder.decodeZipFileName(file.getPath());
    }
    if (file.getFile().isFolder()) {
      bundleBuilder.mime("String_Node_Str");
      bundleBuilder.file(decodedFile);
      fileName=repositoryFilePath;
      repositoryFilePath=importBundle.getPath();
    }
 else {
      byte[] bytes=IOUtils.toByteArray(file.getInputStream());
      bundleInputStream=new ByteArrayInputStream(bytes);
      if (localeFilesProcessor.isLocaleFile(file,importBundle.getPath(),bytes)) {
        log.trace("String_Node_Str" + repositoryFilePath + "String_Node_Str");
        continue;
      }
      bundleBuilder.input(bundleInputStream);
      bundleBuilder.mime(solutionHelper.getMime(fileName));
      String filePath=(decodedFilePath.equals("String_Node_Str") || decodedFilePath.equals("String_Node_Str")) ? "String_Node_Str" : decodedFilePath;
      repositoryFilePath=RepositoryFilenameUtils.concat(importBundle.getPath(),filePath);
    }
    bundleBuilder.name(fileName);
    bundleBuilder.path(repositoryFilePath);
    String sourcePath;
    if (decodedFilePath.startsWith("String_Node_Str")) {
      sourcePath=RepositoryFilenameUtils.concat(decodedFilePath.substring(1),fileName);
    }
 else {
      if (file.getFile().isFolder()) {
        sourcePath=fileName;
      }
 else {
        sourcePath=RepositoryFilenameUtils.concat(decodedFilePath,fileName);
      }
    }
    if (manifest != null && manifest.getExportManifestEntity(sourcePath) == null && file.getFile().isFolder()) {
      continue;
    }
    getImportSession().setCurrentManifestKey(sourcePath);
    bundleBuilder.charSet(bundle.getCharset());
    bundleBuilder.overwriteFile(bundle.overwriteInRepository());
    bundleBuilder.hidden(isFileHidden(bundle,sourcePath));
    bundleBuilder.applyAclSettings(bundle.isApplyAclSettings());
    bundleBuilder.retainOwnership(bundle.isRetainOwnership());
    bundleBuilder.overwriteAclSettings(bundle.isOverwriteAclSettings());
    bundleBuilder.acl(getImportSession().processAclForFile(sourcePath));
    IPlatformImportBundle platformImportBundle=build(bundleBuilder);
    importer.importFile(platformImportBundle);
    if (bundleInputStream != null) {
      bundleInputStream.close();
      bundleInputStream=null;
    }
  }
  if (manifest != null) {
    List<JobScheduleRequest> scheduleList=manifest.getScheduleList();
    if (scheduleList != null) {
      SchedulerResource schedulerResource=new SchedulerResource();
      for (      JobScheduleRequest jobScheduleRequest : scheduleList) {
        try {
          Response response=createSchedulerJob(schedulerResource,jobScheduleRequest);
          if (response.getStatus() == Response.Status.OK.getStatusCode()) {
            if (response.getEntity() != null) {
              ImportSession.getSession().addImportedScheduleJobId(response.getEntity().toString());
            }
          }
        }
 catch (        Exception e) {
          if (jobScheduleRequest.getInputFile().contains("String_Node_Str") || jobScheduleRequest.getOutputFile().contains("String_Node_Str")) {
            log.info("String_Node_Str" + jobScheduleRequest.getInputFile());
            jobScheduleRequest.setInputFile(jobScheduleRequest.getInputFile().replaceAll("String_Node_Str","String_Node_Str"));
            jobScheduleRequest.setOutputFile(jobScheduleRequest.getOutputFile().replaceAll("String_Node_Str","String_Node_Str"));
            try {
              Response response=createSchedulerJob(schedulerResource,jobScheduleRequest);
              if (response.getStatus() == Response.Status.OK.getStatusCode()) {
                if (response.getEntity() != null) {
                  ImportSession.getSession().addImportedScheduleJobId(response.getEntity().toString());
                }
              }
            }
 catch (            Exception ex) {
              throw new PlatformImportException(Messages.getInstance().getString("String_Node_Str",e.getMessage()));
            }
          }
 else {
            throw new PlatformImportException(Messages.getInstance().getString("String_Node_Str",e.getMessage()));
          }
        }
      }
    }
    List<org.pentaho.database.model.DatabaseConnection> datasourceList=manifest.getDatasourceList();
    if (datasourceList != null) {
      IDatasourceMgmtService datasourceMgmtSvc=PentahoSystem.get(IDatasourceMgmtService.class);
      for (      org.pentaho.database.model.DatabaseConnection databaseConnection : datasourceList) {
        if (databaseConnection.getDatabaseType() == null) {
          log.warn("String_Node_Str" + databaseConnection.getName() + "String_Node_Str");
          continue;
        }
        try {
          IDatabaseConnection existingDBConnection=datasourceMgmtSvc.getDatasourceByName(databaseConnection.getName());
          if (existingDBConnection != null && existingDBConnection.getName() != null) {
            if (isOverwriteFile()) {
              databaseConnection.setId(existingDBConnection.getId());
              datasourceMgmtSvc.updateDatasourceByName(databaseConnection.getName(),databaseConnection);
            }
          }
 else {
            datasourceMgmtSvc.createDatasource(databaseConnection);
          }
        }
 catch (        Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
  localeFilesProcessor.processLocaleFiles(importer);
}