use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class DataSourceWizardService method removeDSW.
public void removeDSW(String dswId) throws PentahoAccessControlException {
try {
ensureDataAccessPermissionCheck();
} catch (ConnectionServiceException e) {
throw new PentahoAccessControlException();
}
Domain domain = metadataDomainRepository.getDomain(dswId);
ModelerWorkspace model = createModelerWorkspace();
model.setDomain(domain);
LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
if (logicalModel == null) {
logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
}
if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
try {
mondrianCatalogService.removeCatalog(catalogRef, getSession());
} catch (MondrianCatalogServiceException e) {
logger.warn("Failed to remove mondrian catalog", e);
}
}
try {
dswService.deleteLogicalModel(domain.getId(), logicalModel.getId());
} catch (DatasourceServiceException ex) {
logger.warn("Failed to remove logical model", ex);
}
metadataDomainRepository.removeDomain(dswId);
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class AnalysisResource method putSchema.
/**
* Import Analysis Schema.
*
* <p><b>Example Request:</b><br />
* PUT pentaho/plugin/data-access/api/datasource/analysis/catalog/SampleSchema
* <br /><b>PUT data:</b>
* <pre function="syntax.xml">
* ------WebKitFormBoundaryNLNb246RTFIn1elY
* Content-Disposition: form-data; name="uploadAnalysis"; filename="SampleData2.mondrian.xml"
* Content-Type: text/xml
*
* <?xml version="1.0"?>
* <Schema name="SampleData2">
* <!-- Shared dimensions -->
*
* <Dimension name="Region">
* <Hierarchy hasAll="true" allMemberName="All Regions">
* <Table name="QUADRANT_ACTUALS"/>
* <Level name="Region" column="REGION" uniqueMembers="true"/>
* </Hierarchy>
* </Dimension>
* <Dimension name="Department">
* <Hierarchy hasAll="true" allMemberName="All Departments">
* <Table name="QUADRANT_ACTUALS"/>
* <Level name="Department" column="DEPARTMENT" uniqueMembers="true"/>
* </Hierarchy>
* </Dimension>
*
* <Dimension name="Positions">
* <Hierarchy hasAll="true" allMemberName="All Positions">
* <Table name="QUADRANT_ACTUALS"/>
* <Level name="Positions" column="POSITIONTITLE" uniqueMembers="true"/>
* </Hierarchy>
* </Dimension>
*
* <Cube name="Quadrant Analysis">
* <Table name="QUADRANT_ACTUALS"/>
* <DimensionUsage name="Region" source="Region"/>
* <DimensionUsage name="Department" source="Department" />
* <DimensionUsage name="Positions" source="Positions" />
* <Measure name="Actual" column="ACTUAL" aggregator="sum" formatString="#,###.00"/>
* <Measure name="Budget" column="BUDGET" aggregator="sum" formatString="#,###.00"/>
* <Measure name="Variance" column="VARIANCE" aggregator="sum" formatString="#,###.00"/>
* <!-- <CalculatedMember name="Variance Percent" dimension="Measures" formula="([Measures].[Variance]/[Measures].[Budget])*100" /> -->
* </Cube>
*
* </Schema>
*
* ------WebKitFormBoundaryNLNb246RTFIn1elY
* Content-Disposition: form-data; name="parameters"
*
* DataSource=SampleData2;overwrite=true
* ------WebKitFormBoundaryNLNb246RTFIn1elY
* Content-Disposition: form-data; name="schemaFileInfo"
*
* test.xml
* ------WebKitFormBoundaryNLNb246RTFIn1elY
* Content-Disposition: form-data; name="catalogName"
*
* Catalog Name
* ------WebKitFormBoundaryNLNb246RTFIn1elY
* Content-Disposition: form-data; name="xmlaEnabledFlag"
*
* true
* ------WebKitFormBoundaryNLNb246RTFIn1elY--
* </pre>
* </p>
*
* @param catalog (optional) The catalog name.
* @param uploadAnalysis A Mondrian schema XML file.
* @param schemaFileInfo User selected name for the file.
* @param origCatalogName (optional) The original catalog name.
* @param datasourceName (optional) The datasource name.
* @param overwrite Flag for overwriting existing version of the file.
* @param xmlaEnabledFlag Is XMLA enabled or not.
* @param parameters Import parameters.
* @param acl acl information for the data source. This parameter is optional.
*
* @return Response containing the success of the method.
*
* <p><b>Example Response:</b></p>
* <pre function="syntax.xml">
* 200
* </pre>
*/
@PUT
@Path("/catalog/{catalogId : .+}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
@StatusCodes({ @ResponseCode(code = 409, condition = "Content already exists (use overwrite flag to force)"), @ResponseCode(code = 401, condition = "Import failed because publish is prohibited"), @ResponseCode(code = 500, condition = "Unspecified general error has occurred"), @ResponseCode(code = 412, condition = "Analysis datasource import failed. Error code or message included in response entity"), @ResponseCode(code = 403, condition = "Access Control Forbidden"), @ResponseCode(code = 201, condition = "Indicates successful import") })
public Response putSchema(// Optional
@PathParam(CATALOG_ID) String catalog, @FormDataParam(UPLOAD_ANALYSIS) InputStream uploadAnalysis, @FormDataParam(UPLOAD_ANALYSIS) FormDataContentDisposition schemaFileInfo, // Optional
@FormDataParam(ORIG_CATALOG_NAME) String origCatalogName, // Optional
@FormDataParam(DATASOURCE_NAME) String datasourceName, @FormDataParam(OVERWRITE_IN_REPOS) Boolean overwrite, @FormDataParam(XMLA_ENABLED_FLAG) Boolean xmlaEnabledFlag, @FormDataParam(PARAMETERS) String parameters, @FormDataParam(DATASOURCE_ACL) RepositoryFileAclDto acl) throws PentahoAccessControlException {
try {
service.putMondrianSchema(uploadAnalysis, schemaFileInfo, catalog, origCatalogName, datasourceName, overwrite, xmlaEnabledFlag, parameters, acl);
Response response = Response.status(Response.Status.CREATED).build();
logger.debug("putMondrianSchema Response " + response);
return response;
} catch (PentahoAccessControlException pac) {
int statusCode = PlatformImportException.PUBLISH_USERNAME_PASSWORD_FAIL;
logger.error("Error putMondrianSchema " + pac.getMessage() + " status = " + statusCode);
throw new ResourceUtil.AccessControlException(pac.getMessage());
} catch (PlatformImportException pe) {
if (pe.getErrorStatus() == PlatformImportException.PUBLISH_PROHIBITED_SYMBOLS_ERROR) {
throw new ResourceUtil.PublishProhibitedException(pe.getMessage());
} else {
String msg = pe.getMessage();
logger.error("Error import analysis: " + msg + " status = " + pe.getErrorStatus());
Throwable throwable = pe.getCause();
if (throwable != null) {
msg = throwable.getMessage();
logger.error("Root cause: " + msg);
}
int status = pe.getErrorStatus();
if (status == 8) {
throw new ResourceUtil.ContentAlreadyExistsException(msg);
} else {
throw new ResourceUtil.ImportFailedException(msg);
}
}
} catch (Exception e) {
int statusCode = PlatformImportException.PUBLISH_GENERAL_ERROR;
logger.error("Error putMondrianSchema " + e.getMessage() + " status = " + statusCode);
throw new ResourceUtil.UnspecifiedErrorException(e.getMessage());
}
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class AnalysisResource method importMondrianSchema.
public Response importMondrianSchema(@FormDataParam(UPLOAD_ANALYSIS) InputStream uploadAnalysis, @FormDataParam(UPLOAD_ANALYSIS) FormDataContentDisposition schemaFileInfo, // Optional
@FormDataParam(CATALOG_ID) String catalogName, // Optional
@FormDataParam(ORIG_CATALOG_NAME) String origCatalogName, // Optional
@FormDataParam(DATASOURCE_NAME) String datasourceName, @FormDataParam(OVERWRITE_IN_REPOS) String overwrite, @FormDataParam(XMLA_ENABLED_FLAG) String xmlaEnabledFlag, @FormDataParam(PARAMETERS) String parameters, @FormDataParam(DATASOURCE_ACL) RepositoryFileAclDto acl) throws PentahoAccessControlException {
Response response = null;
int statusCode = PlatformImportException.PUBLISH_GENERAL_ERROR;
try {
boolean overWriteInRepository = "True".equalsIgnoreCase(overwrite);
boolean xmlaEnabled = "True".equalsIgnoreCase(xmlaEnabledFlag);
service.putMondrianSchema(uploadAnalysis, schemaFileInfo, catalogName, origCatalogName, datasourceName, overWriteInRepository, xmlaEnabled, parameters, acl);
statusCode = SUCCESS;
} catch (PentahoAccessControlException pac) {
logger.error(pac.getMessage());
statusCode = PlatformImportException.PUBLISH_USERNAME_PASSWORD_FAIL;
} catch (PlatformImportException pe) {
statusCode = pe.getErrorStatus();
logger.error("Error putMondrianSchema " + pe.getMessage() + " status = " + statusCode);
} catch (Exception e) {
logger.error("Error putMondrianSchema " + e.getMessage());
statusCode = PlatformImportException.PUBLISH_GENERAL_ERROR;
}
response = buildOkResponse(String.valueOf(statusCode));
logger.debug("putMondrianSchema Response " + response);
return response;
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class MetadataDatasourceService method storeDomain.
/**
* @param metadataFile
* Input stream for the metadata.xmi
* @param domainId
* Unique identifier for the metadata datasource
*
* @return Response containing the success of the method
*
* @throws PentahoAccessControlException
* Thrown when validation of access fails
*/
@PUT
@Path("/storeDomain")
@Consumes({ MediaType.APPLICATION_OCTET_STREAM, TEXT_PLAIN })
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response storeDomain(InputStream metadataFile, @QueryParam("domainId") String domainId) throws PentahoAccessControlException {
try {
DatasourceService.validateAccess();
PentahoMetadataDomainRepository metadataImporter = new PentahoMetadataDomainRepository(PentahoSystem.get(IUnifiedRepository.class));
metadataImporter.storeDomain(metadataFile, domainId, true);
return Response.ok("SUCCESS").type(MediaType.TEXT_PLAIN).build();
} catch (PentahoAccessControlException e) {
return Response.serverError().entity(e.toString()).build();
} catch (Exception e) {
return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_001_METADATA_DATASOURCE_ERROR")).build();
}
}
use of org.pentaho.platform.api.engine.PentahoAccessControlException in project data-access by pentaho.
the class MetadataDatasourceService method uploadServletImportMetadataDatasource.
/**
* @param localizeBundleEntries
* @param domainId
* Unique identifier for the metadata datasource
* @param metadataFile
* Input stream for the metadata.xmi
*
* @return Response containing the success of the method
*
* @throws PentahoAccessControlException
* Thrown when validation of access fails
*/
@PUT
@Path("/uploadServletImport")
@Consumes({ TEXT_PLAIN })
@Produces("text/plain")
@Deprecated
@Facet(name = "Unsupported")
public Response uploadServletImportMetadataDatasource(String localizeBundleEntries, @QueryParam("domainId") String domainId, @QueryParam("metadataFile") String metadataFile) throws PentahoAccessControlException {
try {
DatasourceService.validateAccess();
} catch (PentahoAccessControlException e) {
return Response.serverError().entity(e.toString()).build();
}
IMetadataDomainRepository metadataDomainRepository = PentahoSystem.get(IMetadataDomainRepository.class, PentahoSessionHolder.getSession());
PentahoMetadataDomainRepository metadataImporter = new PentahoMetadataDomainRepository(PentahoSystem.get(IUnifiedRepository.class));
CsvUtils csvUtils = new CsvUtils();
boolean validPropertyFiles = true;
StringBuffer invalidFiles = new StringBuffer();
try {
String TMP_FILE_PATH = File.separatorChar + "system" + File.separatorChar + "tmp" + File.separatorChar;
String sysTmpDir = PentahoSystem.getApplicationContext().getSolutionPath(TMP_FILE_PATH);
FileInputStream metadataInputStream = new FileInputStream(sysTmpDir + File.separatorChar + metadataFile);
metadataImporter.storeDomain(metadataInputStream, domainId, true);
metadataDomainRepository.getDomain(domainId);
StringTokenizer bundleEntriesParam = new StringTokenizer(localizeBundleEntries, ";");
while (bundleEntriesParam.hasMoreTokens()) {
String localizationBundleElement = bundleEntriesParam.nextToken();
StringTokenizer localizationBundle = new StringTokenizer(localizationBundleElement, "=");
String localizationFileName = localizationBundle.nextToken();
String localizationFile = localizationBundle.nextToken();
if (localizationFileName.endsWith(".properties")) {
String encoding = csvUtils.getEncoding(localizationFile);
if (ENCODINGS.contains(encoding)) {
for (final Pattern propertyBundlePattern : patterns) {
final Matcher propertyBundleMatcher = propertyBundlePattern.matcher(localizationFileName);
if (propertyBundleMatcher.matches()) {
FileInputStream bundleFileInputStream = new FileInputStream(sysTmpDir + File.separatorChar + localizationFile);
metadataImporter.addLocalizationFile(domainId, propertyBundleMatcher.group(2), bundleFileInputStream, true);
break;
}
}
} else {
validPropertyFiles = false;
invalidFiles.append(localizationFileName);
}
} else {
validPropertyFiles = false;
invalidFiles.append(localizationFileName);
}
}
if (!validPropertyFiles) {
return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_002_PROPERTY_FILES_ERROR") + invalidFiles.toString()).build();
}
return Response.ok("SUCCESS").type(MediaType.TEXT_PLAIN).build();
} catch (Exception e) {
metadataImporter.removeDomain(domainId);
return Response.serverError().entity(Messages.getString("MetadataDatasourceService.ERROR_001_METADATA_DATASOURCE_ERROR")).build();
}
}
Aggregations