Search in sources :

Example 1 with MetadataTempFilesListDto

use of org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto in project data-access by pentaho.

the class DataSourceWizardServiceTest method testPublishDswFromTemp.

@Test
public void testPublishDswFromTemp() throws Exception {
    InputStream metadataFile = getClass().getClassLoader().getResourceAsStream(TEST_XMI_FILE_PATH);
    boolean overwrite = true;
    boolean checkConnection = false;
    XmiParser mockXmiParser = mock(XmiParser.class);
    Domain mockDomain = mock(Domain.class);
    InputStream mockInputStream = mock(InputStream.class);
    IPlatformImportBundle mockMetadataBundle = mock(IPlatformImportBundle.class);
    IPlatformImportBundle mockMondrianBundle = mock(IPlatformImportBundle.class);
    IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    final RepositoryFileAclDto aclDto = new RepositoryFileAclDto();
    aclDto.setOwner("owner");
    aclDto.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    doReturn(true).when(dataSourceWizardService).hasManageAccessCheck();
    doReturn(true).when(dataSourceWizardService).endsWith(anyString(), anyString());
    doReturn(mockXmiParser).when(dataSourceWizardService).createXmiParser();
    doReturn(mockDomain).when(mockXmiParser).parseXmi(metadataFile);
    doReturn(mockInputStream).when(dataSourceWizardService).toInputStreamWrapper(mockDomain, mockXmiParser);
    doReturn(mockMetadataBundle).when(dataSourceWizardService).createMetadataDswBundle(mockDomain, mockInputStream, overwrite, aclDto);
    doReturn(mockMondrianBundle).when(dataSourceWizardService).createMondrianDswBundle(mockDomain, aclDto);
    doReturn(mockIPlatformImporter).when(dataSourceWizardService).getIPlatformImporter();
    doReturn(mockIPentahoSession).when(dataSourceWizardService).getSession();
    doReturn(metadataFile).when(dataSourceWizardService).createInputStreamFromFile(anyString());
    MetadataTempFilesListDto fileList = new MetadataTempFilesListDto();
    fileList.setXmiFileName(XMI_TEMP_FILE_NAME);
    String list = "{\"xmiFileName\":\"" + XMI_TEMP_FILE_NAME + "\"}";
    String response = dataSourceWizardService.publishDswFromTemp(DOMAIN_ID, fileList, overwrite, checkConnection, aclDto);
    assertEquals(DOMAIN_ID + DataSourceWizardService.METADATA_EXT, response);
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) MetadataTempFilesListDto(org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) XmiParser(org.pentaho.metadata.util.XmiParser) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 2 with MetadataTempFilesListDto

use of org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto in project data-access by pentaho.

the class MetadataServiceTest method testIsContainsModel.

private void testIsContainsModel(final boolean isContainsValue) throws Exception {
    InputStream metadataFile = getClass().getClassLoader().getResourceAsStream(TEST_XMI_FILE_PATH);
    fillServiceMock(DOMAIN_ID, metadataFile);
    doReturn(isContainsValue).when(metadataService).isContainsModel(any(Domain.class));
    doReturn(metadataFile).when(metadataService).createInputStreamFromFile(any(String.class));
    MetadataTempFilesListDto fileList = new MetadataTempFilesListDto();
    fileList.setXmiFileName(XMI_TEMP_FILE_NAME);
    assertEquals(metadataService.isContainsModel(XMI_TEMP_FILE_NAME), isContainsValue);
}
Also used : MetadataTempFilesListDto(org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto) ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain)

Example 3 with MetadataTempFilesListDto

use of org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto in project data-access by pentaho.

the class MetadataService method uploadMetadataFilesToTempDir.

public MetadataTempFilesListDto uploadMetadataFilesToTempDir(InputStream metadataFile, List<InputStream> localeFileStreams, List<String> localeFileNames) throws Exception {
    String fileName = uploadFile(metadataFile);
    MetadataTempFilesListDto dto = new MetadataTempFilesListDto();
    dto.setXmiFileName(fileName);
    logger.info("metadata file uploaded: " + fileName);
    if (localeFileStreams != null && localeFileStreams.size() != 0) {
        List<MetadataTempFilesListBundleDto> bundles = new ArrayList<MetadataTempFilesListBundleDto>();
        int cntr = 0;
        for (InputStream inputStream : localeFileStreams) {
            fileName = uploadFile(inputStream);
            MetadataTempFilesListBundleDto bundle = new MetadataTempFilesListBundleDto(localeFileNames.get(cntr), fileName);
            bundles.add(bundle);
            logger.info("locale file uploaded: " + fileName);
            cntr++;
        }
        dto.setBundles(bundles);
    }
    return dto;
}
Also used : MetadataTempFilesListDto(org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) MetadataTempFilesListBundleDto(org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListBundleDto)

Example 4 with MetadataTempFilesListDto

use of org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto in project data-access by pentaho.

the class MetadataServiceTest method testImportMetadataFromTemp.

@Test
public void testImportMetadataFromTemp() throws Exception {
    final boolean IS_CONTAINS_MODEL = true;
    InputStream metadataFile = mock(InputStream.class);
    boolean overwrite = true;
    when(metadataFile.read(any())).thenReturn(-1);
    fillServiceMock(DOMAIN_ID, metadataFile);
    doReturn(IS_CONTAINS_MODEL).when(metadataService).isContainsModel(any(Domain.class));
    doReturn(metadataFile).when(metadataService).createInputStreamFromFile(anyString());
    MetadataTempFilesListDto fileList = new MetadataTempFilesListDto();
    fileList.setXmiFileName(XMI_TEMP_FILE_NAME);
    metadataService.importMetadataFromTemp(DOMAIN_ID, fileList, overwrite, null);
    verify(metadataService, times(1)).importMetadataDatasource(DOMAIN_ID, metadataFile, overwrite, new ArrayList<InputStream>(), new ArrayList<String>(), null);
}
Also used : MetadataTempFilesListDto(org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto) ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Example 5 with MetadataTempFilesListDto

use of org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto in project data-access by pentaho.

the class MetadataServiceTest method testUploadMetadataFilesToTempDir.

@Test
public void testUploadMetadataFilesToTempDir() throws Exception {
    InputStream metadataFile = mock(InputStream.class);
    fillServiceMock(DOMAIN_ID, metadataFile);
    doReturn(new StringInputStream("")).when(metadataService).createInputStreamFromFile(any(String.class));
    doReturn(XMI_TEMP_FILE_NAME).when(metadataService).uploadFile(any(InputStream.class));
    MetadataTempFilesListDto res = metadataService.uploadMetadataFilesToTempDir(metadataFile, null, null);
    assertEquals(res.getXmiFileName(), XMI_TEMP_FILE_NAME);
}
Also used : StringInputStream(org.apache.tools.ant.filters.StringInputStream) MetadataTempFilesListDto(org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto) ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.apache.tools.ant.filters.StringInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)5 MetadataTempFilesListDto (org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListDto)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 FileInputStream (java.io.FileInputStream)4 Matchers.anyString (org.mockito.Matchers.anyString)4 StringInputStream (org.apache.tools.ant.filters.StringInputStream)3 Test (org.junit.Test)3 Domain (org.pentaho.metadata.model.Domain)3 ArrayList (java.util.ArrayList)1 XmiParser (org.pentaho.metadata.util.XmiParser)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)1 MetadataTempFilesListBundleDto (org.pentaho.platform.dataaccess.datasource.api.resources.MetadataTempFilesListBundleDto)1 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)1 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)1