use of com.sun.jersey.multipart.FormDataBodyPart in project activityinfo by bedatadriven.
the class PoEditorClient method createUpload.
private FormDataBodyPart createUpload(List<PoTermUpdate> jsonFile) throws IOException {
byte[] jsonText = objectMapper.writeValueAsString(jsonFile).getBytes(Charsets.UTF_8);
FormDataContentDisposition disposition = FormDataContentDisposition.name("file").fileName("translations.json").creationDate(new Date()).modificationDate(new Date()).size(jsonText.length).build();
return new FormDataBodyPart(disposition, jsonText, MediaType.APPLICATION_JSON_TYPE);
}
use of com.sun.jersey.multipart.FormDataBodyPart in project data-access by pentaho.
the class MetadataServiceTest method testImportMetadataDatasourceError.
@Test
public void testImportMetadataDatasourceError() throws Exception {
String domainId = DOMAIN_ID;
InputStream metadataFile = mock(InputStream.class);
FormDataContentDisposition metadataFileInfo = mock(FormDataContentDisposition.class);
boolean overwrite = true;
FormDataBodyPart mockFormDataBodyPart = mock(FormDataBodyPart.class);
List<FormDataBodyPart> localeFiles = new ArrayList<FormDataBodyPart>();
localeFiles.add(mockFormDataBodyPart);
List<FormDataContentDisposition> localeFilesInfo = new ArrayList<FormDataContentDisposition>();
FormDataContentDisposition mockFormDataContentDisposition = mock(FormDataContentDisposition.class);
localeFilesInfo.add(mockFormDataContentDisposition);
FileResource mockFileResource = mock(FileResource.class);
Response mockResponse = mock(Response.class);
doNothing().when(metadataService).accessValidation();
when(metadataFile.read(any())).thenReturn(-1);
doReturn(mockFileResource).when(metadataService).createNewFileResource();
doReturn(mockResponse).when(mockFileResource).doGetReservedChars();
doReturn(null).when(mockResponse).getEntity();
doReturn("\t\n/").when(metadataService).objectToString(null);
doReturn("").when(metadataService).prohibitedSymbolMessage(domainId, mockFileResource);
try {
metadataService.importMetadataDatasource(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
fail();
} catch (PlatformImportException e) {
// expected
} catch (IllegalStateException e) {
// expected
}
verify(metadataService, times(1)).importMetadataDatasource(domainId, metadataFile, metadataFileInfo, overwrite, localeFiles, localeFilesInfo, null);
}
use of com.sun.jersey.multipart.FormDataBodyPart in project data-access by pentaho.
the class MetadataService method uploadMetadataFilesToTempDir.
public MetadataTempFilesListDto uploadMetadataFilesToTempDir(InputStream metadataFile, List<FormDataBodyPart> localeFiles) throws Exception {
List<InputStream> bundles = null;
List<String> fileNames = null;
if (localeFiles != null && localeFiles.size() != 0) {
bundles = new ArrayList<InputStream>();
fileNames = new ArrayList<String>();
for (FormDataBodyPart localeFile : localeFiles) {
InputStream inputStream = new ByteArrayInputStream(localeFile.getValueAs(byte[].class));
bundles.add(inputStream);
fileNames.add(localeFile.getFormDataContentDisposition().getFileName());
}
}
return uploadMetadataFilesToTempDir(metadataFile, bundles, fileNames);
}
use of com.sun.jersey.multipart.FormDataBodyPart in project data-access by pentaho.
the class DataSourcePublishIT method testPublishDSW.
@Test
public void testPublishDSW() throws Exception {
repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
final String domainID = "test.xmi";
final FileInputStream metadataFile = new FileInputStream("target/test-classes/test.xmi");
final boolean overwrite = true;
final RepositoryFileAclDto acl = generateACL(USERNAME_SUZY, RepositoryFileSid.Type.USER);
MultiPart part = new FormDataMultiPart().field("domainId", domainID).field("overwrite", String.valueOf(overwrite)).field("acl", marshalACL(acl)).bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("metadataFile").fileName("test.xmi").size(metadataFile.available()).build(), metadataFile, MediaType.TEXT_XML_TYPE));
WebResource webResource = resource();
ClientResponse postAnalysis = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + "import").type(MediaType.MULTIPART_FORM_DATA_TYPE).put(ClientResponse.class, part);
assertEquals(Response.Status.OK.getStatusCode(), postAnalysis.getStatus());
final RepositoryFileAclDto savedACL = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").get(ClientResponse.class).getEntity(RepositoryFileAclDto.class);
assertNotNull(savedACL);
repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
checkDSW(webResource, domainID, true);
repositoryBase.login(USERNAME_TIFFANY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
checkDSW(webResource, domainID, false);
repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
final ClientResponse changeACL = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").put(ClientResponse.class, generateACL(AUTHENTICATED_ROLE_NAME, RepositoryFileSid.Type.ROLE));
assertEquals(Response.Status.OK.getStatusCode(), changeACL.getStatus());
repositoryBase.login(USERNAME_TIFFANY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
checkDSW(webResource, domainID, true);
}
use of com.sun.jersey.multipart.FormDataBodyPart in project data-access by pentaho.
the class DataSourcePublishIT method testDSW_ACL.
@Test
public void testDSW_ACL() throws Exception {
repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
final String domainID = "test.xmi";
final FileInputStream metadataFile = new FileInputStream("target/test-classes/test.xmi");
final boolean overwrite = true;
MultiPart part = new FormDataMultiPart().field("domainId", domainID).field("overwrite", String.valueOf(overwrite)).bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("metadataFile").fileName("test.xmi").size(metadataFile.available()).build(), metadataFile, MediaType.TEXT_XML_TYPE));
WebResource webResource = resource();
final ClientResponse noDSW = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").get(ClientResponse.class);
assertEquals(Response.Status.CONFLICT.getStatusCode(), noDSW.getStatus());
ClientResponse postAnalysis = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + "import").type(MediaType.MULTIPART_FORM_DATA_TYPE).put(ClientResponse.class, part);
assertEquals(Response.Status.OK.getStatusCode(), postAnalysis.getStatus());
final ClientResponse noACL = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").get(ClientResponse.class);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), noACL.getStatus());
repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
checkDSW(webResource, domainID, true);
repositoryBase.login(singleTenantAdminUserName, defaultTenant, new String[] { repositoryBase.getTenantAdminRoleName(), AUTHENTICATED_ROLE_NAME });
final ClientResponse setSuzyACL = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").put(ClientResponse.class, generateACL(USERNAME_SUZY, RepositoryFileSid.Type.USER));
assertEquals(Response.Status.OK.getStatusCode(), setSuzyACL.getStatus());
repositoryBase.login(USERNAME_SUZY, defaultTenant, new String[] { AUTHENTICATED_ROLE_NAME });
checkDSW(webResource, domainID, true);
final ClientResponse noAccessACL = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "/acl").get(ClientResponse.class);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), noAccessACL.getStatus());
final ClientResponse noAccessACLNoDS = webResource.path(DATA_ACCESS_API_DATASOURCE_DSW + domainID + "_not_exist/acl").get(ClientResponse.class);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), noAccessACLNoDS.getStatus());
}
Aggregations