use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.
the class AnalysisService method createPlatformBundle.
/**
* helper method to create the platform bundle used by the Jcr repository
*
* @param parameters
* @param dataInputStream
* @param catalogName
* @param overWriteInRepository
* @param fileName
* @param xmlaEnabled
* @param acl acl information for the data source. This parameter is optional.
* @return IPlatformImportBundle
*/
private IPlatformImportBundle createPlatformBundle(String parameters, InputStream dataInputStream, String catalogName, boolean overWriteInRepository, String fileName, boolean xmlaEnabled, RepositoryFileAclDto acl) {
byte[] bytes = null;
try {
bytes = IOUtils.toByteArray(dataInputStream);
if (bytes.length == 0 && catalogName != null) {
MondrianCatalogRepositoryHelper helper = new MondrianCatalogRepositoryHelper(PentahoSystem.get(IUnifiedRepository.class));
Map<String, InputStream> fileData = helper.getModrianSchemaFiles(catalogName);
dataInputStream = fileData.get("schema.xml");
bytes = IOUtils.toByteArray(dataInputStream);
}
} catch (IOException e) {
logger.error(e);
}
String datasource = getValue(parameters, "Datasource");
String domainId = this.determineDomainCatalogName(parameters, catalogName, fileName, new ByteArrayInputStream(bytes));
String sep = ";";
if (StringUtils.isEmpty(parameters)) {
parameters = "Provider=mondrian";
parameters += sep + DATASOURCE_NAME + "=" + datasource;
parameters += sep + ENABLE_XMLA + "=" + xmlaEnabled;
}
RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder().input(new ByteArrayInputStream(bytes)).charSet(UTF_8).hidden(false).name(domainId).overwriteFile(overWriteInRepository).mime(MONDRIAN_MIME_TYPE).withParam(PARAMETERS, parameters).withParam(DOMAIN_ID, domainId);
if (acl != null) {
bundleBuilder.acl(repositoryFileAclAdapter.unmarshal(acl)).applyAclSettings(true);
}
bundleBuilder.withParam(ENABLE_XMLA, Boolean.toString(xmlaEnabled));
IPlatformImportBundle bundle = bundleBuilder.build();
return bundle;
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.
the class AnalysisService method putMondrianSchema.
public void putMondrianSchema(InputStream dataInputStream, FormDataContentDisposition schemaFileInfo, // Optional
String catalogName, // Optional
String origCatalogName, // Optional
String datasourceName, boolean overwrite, boolean xmlaEnabledFlag, String parameters, RepositoryFileAclDto acl) throws PentahoAccessControlException, PlatformImportException, Exception {
accessValidation();
String fileName = schemaFileInfo.getFileName();
// sanity check to prevent common mistake - import of .xmi files.
// See BISERVER-12815
fileNameValidation(fileName);
ZipInputStream zis = null;
ByteArrayOutputStream mondrian = null;
ByteArrayOutputStream annotations = null;
if (fileName.endsWith(ZIP_EXTENSION)) {
zis = new ZipInputStream(dataInputStream);
ZipEntry ze = null;
int len = 0;
while ((ze = zis.getNextEntry()) != null) {
if (ze.getName().endsWith(MONDRIAN_FILE_EXTENSION)) {
IOUtils.copy(zis, mondrian = new ByteArrayOutputStream());
} else if (ze.getName().equals(ANNOTATIONS_FILE)) {
IOUtils.copy(zis, annotations = new ByteArrayOutputStream());
}
zis.closeEntry();
}
if (mondrian != null) {
dataInputStream = new ByteArrayInputStream(mondrian.toByteArray());
}
}
try {
processMondrianImport(dataInputStream, catalogName, origCatalogName, overwrite, xmlaEnabledFlag, parameters, fileName, acl);
if (annotations != null) {
String catName = (catalogName != null) ? catalogName : fileName.substring(0, fileName.indexOf('.'));
ByteArrayInputStream annots = new ByteArrayInputStream(annotations.toByteArray());
IPlatformImportBundle mondrianBundle = new RepositoryFileImportBundle.Builder().input(annots).path(ANNOTATION_FOLDER + catName).name(ANNOTATIONS_FILE).charSet("UTF-8").overwriteFile(true).mime("text/xml").withParam("domain-id", catName).build();
// do import
importer.importFile(mondrianBundle);
logger.debug("imported mondrian annotations");
annots.close();
}
} finally {
if (zis != null) {
zis.close();
}
if (mondrian != null) {
mondrian.close();
}
if (annotations != null) {
annotations.close();
}
}
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.
the class AnalysisService method processMondrianImport.
/**
* This is the main method that handles the actual Import Handler to persist to PUR
*
* @param dataInputStream
* @param catalogName
* @param overwrite
* @param xmlaEnabledFlag
* @param parameters
* @param fileName
* @param acl acl information for the data source. This parameter is optional.
* @throws PlatformImportException
*/
protected void processMondrianImport(InputStream dataInputStream, String catalogName, String origCatalogName, boolean overwrite, boolean xmlaEnabledFlag, String parameters, String fileName, RepositoryFileAclDto acl) throws PlatformImportException {
boolean overWriteInRepository = determineOverwriteFlag(parameters, overwrite);
IPlatformImportBundle bundle = createPlatformBundle(parameters, dataInputStream, catalogName, overWriteInRepository, fileName, xmlaEnabledFlag, acl);
if (isChangeCatalogName(origCatalogName, bundle)) {
IMondrianCatalogService catalogService = PentahoSystem.get(IMondrianCatalogService.class, PentahoSessionHolder.getSession());
catalogService.removeCatalog(origCatalogName, PentahoSessionHolder.getSession());
}
if (isOverwriteAnnotations(parameters, overWriteInRepository)) {
IMondrianCatalogService catalogService = PentahoSystem.get(IMondrianCatalogService.class, PentahoSessionHolder.getSession());
List<MondrianCatalog> catalogs = catalogService.listCatalogs(PentahoSessionHolder.getSession(), false);
for (MondrianCatalog catalog : catalogs) {
if (catalog.getName().equals(bundle.getName())) {
catalogService.removeCatalog(bundle.getName(), PentahoSessionHolder.getSession());
break;
}
}
}
importer.importFile(bundle);
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto 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.platform.api.repository2.unified.webservices.RepositoryFileAclDto in project data-access by pentaho.
the class DataSourceWizardService method setDSWAcl.
/**
* Set ACL to both Mondrian Catalog and Metadata Schema
*
* @param dswId dsw id
* @param aclDto ACL
* @throws PentahoAccessControlException
* @throws FileNotFoundException
*/
public void setDSWAcl(String dswId, RepositoryFileAclDto aclDto) throws PentahoAccessControlException, FileNotFoundException {
checkDSWExists(dswId);
if (!endsWith(dswId, 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);
}
final RepositoryFileAcl acl = aclDto == null ? null : repositoryFileAclAdapter.unmarshal(aclDto);
if (aclAwareMondrianCatalogService != null) {
aclAwareMondrianCatalogService.setAclFor(dswId.substring(0, dswId.lastIndexOf(METADATA_EXT)), acl);
}
if (aclAwarePentahoMetadataDomainRepositoryImporter != null) {
aclAwarePentahoMetadataDomainRepositoryImporter.setAclFor(dswId, acl);
}
flushDataSources();
}
Aggregations