use of org.apache.openmeetings.db.dto.file.FileItemDTO in project openmeetings by apache.
the class FileWebService method add.
/**
* to add a folder to the private drive, set parentId = 0 and isOwner to 1/true and
* externalUserId/externalUserType to a valid user
*
* @param sid
* The SID of the User. This SID must be marked as logged in
* @param file
* the The file to be added
* @param stream
* the The file to be added
* @return - Object created
*/
@WebMethod
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/")
public FileItemDTO add(@WebParam(name = "sid") @QueryParam("sid") String sid, @Multipart(value = "file", type = MediaType.APPLICATION_JSON) @WebParam(name = "file") FileItemDTO file, @Multipart(value = "stream", type = MediaType.APPLICATION_OCTET_STREAM, required = false) @WebParam(name = "stream") InputStream stream) {
return performCall(sid, User.Right.Room, sd -> {
FileItem f = file == null ? null : file.get();
if (f == null || f.getId() != null) {
throw new ServiceException("Bad id");
}
f.setInsertedBy(sd.getUserId());
if (stream != null) {
try {
ProcessResultList result = fileProcessor.processFile(f, stream);
if (result.hasError()) {
throw new ServiceException(result.getLogMessage());
}
} catch (Exception e) {
throw new ServiceException(e.getMessage());
}
} else {
f = fileDao.update(f);
}
return new FileItemDTO(f);
});
}
use of org.apache.openmeetings.db.dto.file.FileItemDTO in project openmeetings by apache.
the class AbstractWebServiceTest method createVerifiedFile.
public CallResult<FileItemDTO> createVerifiedFile(File fsFile, String name, BaseFileItem.Type type) throws IOException {
ServiceResult r = login();
FileItemDTO f1 = null;
try (InputStream is = new FileInputStream(fsFile)) {
FileItemDTO file = new FileItemDTO().setName(name).setHash(UUID.randomUUID().toString()).setType(type);
List<Attachment> atts = new ArrayList<>();
atts.add(new Attachment("file", MediaType.APPLICATION_JSON, file));
atts.add(new Attachment("stream", MediaType.APPLICATION_OCTET_STREAM, is));
f1 = getClient(getFileUrl()).path("/").query("sid", r.getMessage()).type(MediaType.MULTIPART_FORM_DATA_TYPE).postCollection(atts, Attachment.class, FileItemDTO.class);
assertNotNull("Valid FileItem should be returned", f1);
assertNotNull("Valid FileItem should be returned", f1.getId());
}
return new CallResult<>(r.getMessage(), f1);
}
use of org.apache.openmeetings.db.dto.file.FileItemDTO in project openmeetings by apache.
the class TestFileProcessor method testProcessJpeg.
@Test
public void testProcessJpeg() throws Exception {
for (String ext : new String[] { null, "txt", "png" }) {
FileItem f = new FileItemDTO().setName(String.format(FILE_NAME_FMT, FILE_NAME, ext)).setHash(UUID.randomUUID().toString()).setType(BaseFileItem.Type.Recording).get();
try (InputStream is = new FileInputStream(getDefaultProfilePicture())) {
ProcessResultList result = processor.processFile(f, is);
assertFalse("Conversion should be successful", result.hasError());
assertEquals("Type should be image", BaseFileItem.Type.Image, f.getType());
}
}
}
use of org.apache.openmeetings.db.dto.file.FileItemDTO in project openmeetings by apache.
the class TestFileService method addFileTest.
@Test
@Category(NonJenkinsTests.class)
public void addFileTest() throws IOException {
File img = null;
try {
img = File.createTempFile("omtest", ".jpg");
final Integer width = 150;
final Integer height = 100;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.drawString("Hello World!!!", 10, 20);
ImageIO.write(image, "jpg", img);
CallResult<FileItemDTO> cr = createVerifiedFile(img, "test.txt", BaseFileItem.Type.Presentation);
assertEquals("Type should be Image", BaseFileItem.Type.Image, cr.getObj().getType());
assertEquals("Width should be determined", width, cr.getObj().getWidth());
assertEquals("Height should be Image", height, cr.getObj().getHeight());
} finally {
if (img != null && img.exists()) {
img.delete();
}
}
}
use of org.apache.openmeetings.db.dto.file.FileItemDTO in project openmeetings by apache.
the class TestRoomService method testCreateWithFiles2.
@Test
public void testCreateWithFiles2() throws IOException {
// lets create real file
CallResult<FileItemDTO> fileCall = createVerifiedFile(getDefaultProfilePicture(), "img.jpg", BaseFileItem.Type.Image);
Room.Type type = Room.Type.presentation;
String name = "Unit Test Ext Room4";
String comment = "Unit Test Ext Room Comments4";
RoomDTO r = new RoomDTO();
r.setType(type);
r.setName(name);
r.setComment(comment);
r.setCapacity(CAPACITY);
RoomFileDTO rf = new RoomFileDTO();
// not existent
rf.setFileId(fileCall.getObj().getId());
r.getFiles().add(rf);
CallResult<RoomDTO> res = createAndValidate(fileCall.getSid(), r);
assertFalse("Room files should NOT be empty", res.getObj().getFiles().isEmpty());
}
Aggregations