use of org.pentaho.platform.plugin.services.importer.PlatformImportException 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.plugin.services.importer.PlatformImportException in project pentaho-platform by pentaho.
the class RepositoryPublishResourceTest method testWriteFileError.
@Test
public void testWriteFileError() throws Exception {
String pathId = "pathId";
InputStream fileContents = mock(InputStream.class);
Boolean overwriteFile = Boolean.TRUE;
FormDataContentDisposition mockFormDataContentDisposition = mock(FormDataContentDisposition.class);
Response mockUnauthorizedResponse = mock(Response.class);
doReturn(mockUnauthorizedResponse).when(repositoryPublishResource).buildStatusResponse(UNAUTHORIZED, PlatformImportException.PUBLISH_USERNAME_PASSWORD_FAIL);
int errorStatus = 0;
Response mockPreconditionFailedResponse = mock(Response.class);
doReturn(mockPreconditionFailedResponse).when(repositoryPublishResource).buildStatusResponse(PRECONDITION_FAILED, errorStatus);
Response mockServerErrorResponse = mock(Response.class);
doReturn(mockServerErrorResponse).when(repositoryPublishResource).buildServerErrorResponse(PUBLISH_GENERAL_ERROR);
// Test 1
Exception mockPentahoAccessControlException = mock(PentahoAccessControlException.class);
doThrow(mockPentahoAccessControlException).when(repositoryPublishResource.repositoryPublishService).writeFile(pathId, fileContents, overwriteFile);
Response testResponse = repositoryPublishResource.writeFile(pathId, fileContents, overwriteFile, mockFormDataContentDisposition);
assertEquals(mockUnauthorizedResponse, testResponse);
// Test 2
PlatformImportException mockPlatformImportException = mock(PlatformImportException.class);
doReturn(errorStatus).when(mockPlatformImportException).getErrorStatus();
doThrow(mockPlatformImportException).when(repositoryPublishResource.repositoryPublishService).writeFile(pathId, fileContents, overwriteFile);
testResponse = repositoryPublishResource.writeFile(pathId, fileContents, overwriteFile, mockFormDataContentDisposition);
assertEquals(mockPreconditionFailedResponse, testResponse);
// Test 3
Exception mockException = mock(RuntimeException.class);
doThrow(mockException).when(repositoryPublishResource.repositoryPublishService).writeFile(pathId, fileContents, overwriteFile);
testResponse = repositoryPublishResource.writeFile(pathId, fileContents, overwriteFile, mockFormDataContentDisposition);
assertEquals(mockServerErrorResponse, testResponse);
verify(repositoryPublishResource.repositoryPublishService, times(3)).writeFile(pathId, fileContents, overwriteFile);
verify(repositoryPublishResource, times(1)).buildStatusResponse(UNAUTHORIZED, PlatformImportException.PUBLISH_USERNAME_PASSWORD_FAIL);
verify(repositoryPublishResource, times(1)).buildStatusResponse(PRECONDITION_FAILED, errorStatus);
verify(repositoryPublishResource, times(1)).buildServerErrorResponse(PUBLISH_GENERAL_ERROR);
}
use of org.pentaho.platform.plugin.services.importer.PlatformImportException in project pentaho-platform by pentaho.
the class RepositoryPublishResourceTest method writeFileWithEncodedName_Returns412_OnPlatformImportException.
@Test
public void writeFileWithEncodedName_Returns412_OnPlatformImportException() throws Exception {
final int someCode = 50;
testWriteFileWithEncodedName_OnError(new PlatformImportException("import exception", someCode), PRECONDITION_FAILED, someCode);
}
use of org.pentaho.platform.plugin.services.importer.PlatformImportException in project data-access by pentaho.
the class MetadataService method importMetadataDatasource.
public void importMetadataDatasource(String domainId, InputStream metadataFile, FormDataContentDisposition metadataFileInfo, boolean overwrite, List<FormDataBodyPart> localeFiles, List<FormDataContentDisposition> localeFilesInfo, RepositoryFileAclDto acl) throws PentahoAccessControlException, PlatformImportException, Exception {
if (StringUtils.isEmpty(domainId)) {
throw new PlatformImportException(Messages.getString("MetadataDatasourceService.ERROR_005_DOMAIN_NAME_EMPTY"));
}
List<InputStream> localeFileStreams = null;
List<String> localeFileNames = null;
if (localeFiles != null) {
localeFileStreams = new ArrayList<InputStream>();
localeFileNames = new ArrayList<String>();
for (int i = 0; i < localeFiles.size(); i++) {
logger.info("create language file");
InputStream inputStream = createNewByteArrayInputStream(localeFiles.get(i).getValueAs(byte[].class));
localeFileStreams.add(inputStream);
localeFileNames.add(localeFilesInfo.get(i).getFileName());
}
}
importMetadataDatasource(domainId, metadataFile, overwrite, localeFileStreams, localeFileNames, acl);
}
use of org.pentaho.platform.plugin.services.importer.PlatformImportException in project data-access by pentaho.
the class AnalysisDatasourceService method putMondrianSchema.
/**
* This is used by PUC to use a Jersey put to import a Mondrian Schema XML into PUR
*
* @param dataInputStream
* @param schemaFileInfo
* @param catalogName
* @param datasourceName
* @param overwrite
* @param xmlaEnabledFlag
* @param parameters
* @param acl acl information for the data source. This parameter is optional.
* @return this method returns a response of "3" for success, 8 if exists, etc.
* @throws PentahoAccessControlException
*/
@PUT
@Path("/putSchema")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response putMondrianSchema(@FormDataParam(UPLOAD_ANALYSIS) InputStream dataInputStream, @FormDataParam(UPLOAD_ANALYSIS) FormDataContentDisposition schemaFileInfo, // Optional
@FormDataParam(CATALOG_NAME) 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 {
AnalysisService service = new AnalysisService();
boolean overWriteInRepository = "True".equalsIgnoreCase(overwrite) ? true : false;
boolean xmlaEnabled = "True".equalsIgnoreCase(xmlaEnabledFlag) ? true : false;
service.putMondrianSchema(dataInputStream, 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 = Response.ok().status(statusCode).type(MediaType.TEXT_PLAIN).build();
logger.debug("putMondrianSchema Response " + response);
return response;
}
Aggregations