Search in sources :

Example 6 with MultiPart

use of com.sun.jersey.multipart.MultiPart in project atlas by apache.

the class AtlasBaseClient method importData.

public AtlasImportResult importData(AtlasImportRequest request, String absoluteFilePath) throws AtlasServiceException {
    FileDataBodyPart filePart = new FileDataBodyPart("data", new File(absoluteFilePath));
    MultiPart multipartEntity = new FormDataMultiPart().field("request", AtlasType.toJson(request), MediaType.APPLICATION_JSON_TYPE).bodyPart(filePart);
    return callAPI(IMPORT, AtlasImportResult.class, multipartEntity);
}
Also used : MultiPart(com.sun.jersey.multipart.MultiPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) File(java.io.File) FileDataBodyPart(com.sun.jersey.multipart.file.FileDataBodyPart)

Example 7 with MultiPart

use of com.sun.jersey.multipart.MultiPart in project data-access by pentaho.

the class DataSourcePublishIT method testAnalysis_ACL.

@Test
public void testAnalysis_ACL() throws Exception {
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final String catalogID = "FoodMart";
    final InputStream uploadAnalysis = new FileInputStream("target/test-classes/schema.xml");
    final boolean overwrite = true;
    final boolean xmlaEnabledFlag = false;
    final String parameters = "DataSource=" + catalogID + ";EnableXmla=" + xmlaEnabledFlag + ";overwrite=" + overwrite;
    MultiPart part = new FormDataMultiPart().field("catalogName", catalogID).field("datasourceName", catalogID).field("overwrite", String.valueOf(overwrite)).field("xmlaEnabledFlag", String.valueOf(xmlaEnabledFlag)).field("parameters", parameters).bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("uploadAnalysis").fileName("schema.xml").size(uploadAnalysis.available()).build(), uploadAnalysis, MediaType.TEXT_XML_TYPE));
    WebResource webResource = resource();
    final ClientResponse noAnalysis = webResource.path(DATA_ACCESS_API_DATASOURCE_ANALYSIS + catalogID + "/acl").get(ClientResponse.class);
    assertEquals(Response.Status.CONFLICT.getStatusCode(), noAnalysis.getStatus());
    ClientResponse postAnalysis = webResource.path("data-access/api/mondrian/postAnalysis").type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, part);
    assertEquals(Response.Status.OK.getStatusCode(), postAnalysis.getStatus());
    final ClientResponse noACL = webResource.path(DATA_ACCESS_API_DATASOURCE_ANALYSIS + catalogID + "/acl").get(ClientResponse.class);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), noACL.getStatus());
    repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkAnalysis(webResource, catalogID, true);
    repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
    final ClientResponse changeACL = webResource.path(DATA_ACCESS_API_DATASOURCE_ANALYSIS + catalogID + "/acl").put(ClientResponse.class, generateACL(USERNAME_SUZY, RepositoryFileSid.Type.USER));
    assertEquals(Response.Status.OK.getStatusCode(), changeACL.getStatus());
    repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
    checkAnalysis(webResource, catalogID, true);
    final ClientResponse noAccessACL = webResource.path(DATA_ACCESS_API_DATASOURCE_ANALYSIS + catalogID + "/acl").get(ClientResponse.class);
    assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), noAccessACL.getStatus());
    final ClientResponse noAccessACLNoDS = webResource.path(DATA_ACCESS_API_DATASOURCE_ANALYSIS + catalogID + "_not_exist/acl").get(ClientResponse.class);
    assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), noAccessACLNoDS.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) MultiPart(com.sun.jersey.multipart.MultiPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FormDataBodyPart(com.sun.jersey.multipart.FormDataBodyPart) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) WebResource(com.sun.jersey.api.client.WebResource) FileInputStream(java.io.FileInputStream) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Aggregations

FormDataMultiPart (com.sun.jersey.multipart.FormDataMultiPart)7 MultiPart (com.sun.jersey.multipart.MultiPart)7 ClientResponse (com.sun.jersey.api.client.ClientResponse)6 WebResource (com.sun.jersey.api.client.WebResource)6 FormDataBodyPart (com.sun.jersey.multipart.FormDataBodyPart)6 JerseyTest (com.sun.jersey.test.framework.JerseyTest)6 FileInputStream (java.io.FileInputStream)6 Test (org.junit.Test)6 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)3 InputStream (java.io.InputStream)2 FileDataBodyPart (com.sun.jersey.multipart.file.FileDataBodyPart)1 File (java.io.File)1