use of org.mifos.framework.image.domain.ImageInfo in project head by mifos.
the class ImageStorageManager method createImage.
public static ImageInfo createImage(InputStream in, String name) throws IOException {
if (in == null) {
return null;
}
String contentType;
contentType = URLConnection.guessContentTypeFromStream(in);
if (contentType == null) {
contentType = DEFAULT_CONTENT_TYPE;
}
byte[] data = InputStreamUtils.getBytes(in);
if (data.length == 0) {
return null;
}
String filePath = generateRandomSubDir() + name;
File file = new File(getStorageLocation() + filePath);
FileUtils.touch(file);
FileUtils.writeByteArrayToFile(file, data);
ImageInfo imInfo = new ImageInfo();
imInfo.setContentType(contentType);
imInfo.setLength(Long.valueOf(data.length));
imInfo.setPath(filePath);
return imInfo;
}
use of org.mifos.framework.image.domain.ImageInfo in project head by mifos.
the class ClientPhotoServiceDatabaseIntegrationTest method TestCRUD.
@Test
public void TestCRUD() {
final Long clientId = (long) this.testClient.getCustomerId().intValue();
/* Create */
final String data = "test string";
InputStream in = new ByteArrayInputStream(data.getBytes());
this.clientPhotoService.create(clientId, in);
ClientPhoto cp = this.clientPhotoService.read(clientId);
Assert.assertEquals(clientId, cp.getClientId());
ImageInfo imageInfo = cp.getImageInfo();
String path = imageInfo.getPath();
Assert.assertNotNull(imageInfo.getCustomerPictureEntity().getPicture());
Assert.assertNotNull(imageInfo.getContentType());
Assert.assertEquals(data.length(), imageInfo.getLength().intValue());
Assert.assertEquals(data, new String(this.clientPhotoService.getData(cp)));
/* Update */
final String otherData = "other test string";
in = new ByteArrayInputStream(otherData.getBytes());
this.clientPhotoService.update(clientId, in);
cp = this.clientPhotoService.read(clientId);
Assert.assertEquals(path, imageInfo.getPath());
Assert.assertNotNull(imageInfo.getContentType());
Assert.assertEquals(otherData.length(), imageInfo.getLength().intValue());
Assert.assertEquals(otherData, new String(this.clientPhotoService.getData(cp)));
Assert.assertTrue(this.clientPhotoService.delete(clientId));
/* Delete */
this.clientPhotoService.delete(clientId);
cp = this.clientPhotoService.read(clientId);
Assert.assertNull(cp);
}
use of org.mifos.framework.image.domain.ImageInfo in project head by mifos.
the class ClientPhotoServiceIntegrationTest method testCRUD.
@Test
public void testCRUD() {
String data = "test string";
InputStream in = new ByteArrayInputStream(data.getBytes());
Long clientId = 2342L;
clientPhotoService.create(clientId, in);
ClientPhoto cp = clientPhotoService.read(2342L);
Assert.assertEquals(clientId, cp.getClientId());
ImageInfo imageInfo = cp.getImageInfo();
String path = imageInfo.getPath();
Assert.assertNotNull(path);
Assert.assertNotNull(imageInfo.getContentType());
Assert.assertEquals(data.length(), imageInfo.getLength().intValue());
Assert.assertEquals(data, new String(clientPhotoService.getData(cp)));
String otherData = "other test string";
in = new ByteArrayInputStream(otherData.getBytes());
clientPhotoService.update(clientId, in);
Assert.assertEquals(path, imageInfo.getPath());
Assert.assertNotNull(imageInfo.getContentType());
Assert.assertEquals(otherData.length(), imageInfo.getLength().intValue());
Assert.assertEquals(otherData, new String(clientPhotoService.getData(cp)));
Assert.assertTrue(clientPhotoService.delete(clientId));
}
Aggregations