use of org.pentaho.metadata.util.XmiParser 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);
}
use of org.pentaho.metadata.util.XmiParser in project data-access by pentaho.
the class DataSourceWizardService method publishDsw.
public String publishDsw(String domainId, InputStream metadataFile, List<InputStream> localizeFiles, List<String> localizeFileNames, boolean overwrite, boolean checkConnection, RepositoryFileAclDto acl) throws PentahoAccessControlException, IllegalArgumentException, DswPublishValidationException, Exception {
if (!hasManageAccessCheck()) {
throw new PentahoAccessControlException();
}
if (!endsWith(domainId, METADATA_EXT)) {
// if doesn't end in case-sensitive '.xmi' there will be trouble later on
final String errorMsg = "domainId must end in " + METADATA_EXT;
throw new IllegalArgumentException(errorMsg);
}
if (localizeFiles == null ? (localizeFileNames != null) : (localizeFiles.size() != localizeFileNames.size())) {
throw new IllegalArgumentException("localizeFiles and localizeFileNames must have equal size");
}
if (metadataFile == null) {
throw new IllegalArgumentException("metadataFile is null");
}
if (!overwrite) {
final List<String> overwritten = getOverwrittenDomains(domainId);
if (!overwritten.isEmpty()) {
final String domainIds = StringUtils.join(overwritten, ",");
throw new DswPublishValidationException(DswPublishValidationException.Type.OVERWRITE_CONFLICT, domainIds);
}
}
XmiParser xmiParser = createXmiParser();
Domain domain = null;
try {
domain = xmiParser.parseXmi(metadataFile);
} catch (Exception e) {
throw new DswPublishValidationException(DswPublishValidationException.Type.INVALID_XMI, e.getMessage());
}
domain.setId(domainId);
if (checkConnection) {
final String connectionId = getMondrianDatasourceWrapper(domain);
// Left second check with non-escaped name for backward compatibility
if (datasourceMgmtSvc.getDatasourceByName(sanitizer.escape(connectionId)) == null && datasourceMgmtSvc.getDatasourceByName(connectionId) == null) {
final String msg = "connection not found: '" + connectionId + "'";
throw new DswPublishValidationException(Type.MISSING_CONNECTION, msg);
}
}
// build bundles
IPlatformImportBundle mondrianBundle = createMondrianDswBundle(domain, acl);
InputStream metadataIn = toInputStreamWrapper(domain, xmiParser);
IPlatformImportBundle metadataBundle = createMetadataDswBundle(domain, metadataIn, overwrite, acl);
// add localization bundles
if (localizeFiles != null) {
for (int i = 0; i < localizeFiles.size(); i++) {
IPlatformImportBundle localizationBundle = MetadataService.createNewRepositoryFileImportBundle(localizeFiles.get(i), localizeFileNames.get(i), domainId);
metadataBundle.getChildBundles().add(localizationBundle);
logger.info("created language file");
}
}
// do import
IPlatformImporter importer = getIPlatformImporter();
importer.importFile(metadataBundle);
logger.debug("imported metadata xmi");
importer.importFile(mondrianBundle);
logger.debug("imported mondrian schema");
// trigger refreshes
IPentahoSession session = getSession();
PentahoSystem.publish(session, METADATA_PUBLISHER);
PentahoSystem.publish(session, MONDRIAN_PUBLISHER);
logger.info("publishDsw: Published DSW with domainId='" + domainId + "'.");
return domainId;
}
use of org.pentaho.metadata.util.XmiParser in project data-access by pentaho.
the class MetadataService method isContainsModel.
public boolean isContainsModel(String tempFileName) throws Exception {
XmiParser xmiParser = new XmiParser();
byte[] is = IOUtils.toByteArray(createInputStreamFromFile(internalGetUploadDir() + File.separatorChar + tempFileName));
Domain domain = xmiParser.parseXmi(new java.io.ByteArrayInputStream(is));
return isContainsModel(domain);
}
use of org.pentaho.metadata.util.XmiParser in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepositoryTest method testSetXmiParser.
@Test
public void testSetXmiParser() throws Exception {
domainRepositorySpy.setXmiParser(null);
domainRepositorySpy.setXmiParser(new XmiParser());
}
use of org.pentaho.metadata.util.XmiParser in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepositoryTest method loadDomain.
/**
* Loads a "real" Pentaho Metadata Domain
*
* @param domainId
* @param domainFile
* @return
* @throws Exception
*/
private static Domain loadDomain(final String domainId, final String domainFile) throws Exception {
final InputStream in = PentahoMetadataDomainRepositoryTest.class.getResourceAsStream(domainFile);
final XmiParser parser = new XmiParser();
final Domain domain = parser.parseXmi(in);
domain.setId(domainId);
IOUtils.closeQuietly(in);
return domain;
}
Aggregations