Search in sources :

Example 6 with PlatformImportException

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;
}
Also used : Response(javax.ws.rs.core.Response) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileNotFoundException(java.io.FileNotFoundException) RepositoryException(org.pentaho.platform.api.repository.RepositoryException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 7 with PlatformImportException

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);
}
Also used : Response(javax.ws.rs.core.Response) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FormDataContentDisposition(com.sun.jersey.core.header.FormDataContentDisposition) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 8 with PlatformImportException

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);
}
Also used : PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) Test(org.junit.Test)

Example 9 with PlatformImportException

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);
}
Also used : PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 10 with PlatformImportException

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;
}
Also used : Response(javax.ws.rs.core.Response) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) AnalysisService(org.pentaho.platform.dataaccess.datasource.api.AnalysisService) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) Facet(org.codehaus.enunciate.Facet)

Aggregations

PlatformImportException (org.pentaho.platform.plugin.services.importer.PlatformImportException)11 Response (javax.ws.rs.core.Response)7 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)7 InputStream (java.io.InputStream)6 Test (org.junit.Test)6 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileResource (org.pentaho.platform.web.http.api.resources.FileResource)3 FormDataBodyPart (com.sun.jersey.multipart.FormDataBodyPart)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 RepositoryException (org.pentaho.platform.api.repository.RepositoryException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 StringInputStream (org.apache.tools.ant.filters.StringInputStream)1