Search in sources :

Example 1 with FileItemDTO

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);
    });
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) FileItemDTO(org.apache.openmeetings.db.dto.file.FileItemDTO) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) ProcessResultList(org.apache.openmeetings.util.process.ProcessResultList) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with FileItemDTO

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);
}
Also used : ServiceResult(org.apache.openmeetings.db.dto.basic.ServiceResult) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileItemDTO(org.apache.openmeetings.db.dto.file.FileItemDTO) ArrayList(java.util.ArrayList) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) FileInputStream(java.io.FileInputStream)

Example 3 with FileItemDTO

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());
        }
    }
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileItemDTO(org.apache.openmeetings.db.dto.file.FileItemDTO) FileInputStream(java.io.FileInputStream) ProcessResultList(org.apache.openmeetings.util.process.ProcessResultList) Test(org.junit.Test)

Example 4 with FileItemDTO

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();
        }
    }
}
Also used : Graphics(java.awt.Graphics) FileItemDTO(org.apache.openmeetings.db.dto.file.FileItemDTO) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 5 with FileItemDTO

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());
}
Also used : RoomDTO(org.apache.openmeetings.db.dto.room.RoomDTO) FileItemDTO(org.apache.openmeetings.db.dto.file.FileItemDTO) Room(org.apache.openmeetings.db.entity.room.Room) RoomFileDTO(org.apache.openmeetings.db.dto.room.RoomFileDTO) Test(org.junit.Test)

Aggregations

FileItemDTO (org.apache.openmeetings.db.dto.file.FileItemDTO)5 Test (org.junit.Test)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 FileItem (org.apache.openmeetings.db.entity.file.FileItem)2 ProcessResultList (org.apache.openmeetings.util.process.ProcessResultList)2 Graphics (java.awt.Graphics)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 WebMethod (javax.jws.WebMethod)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)1 ServiceResult (org.apache.openmeetings.db.dto.basic.ServiceResult)1 RoomDTO (org.apache.openmeetings.db.dto.room.RoomDTO)1 RoomFileDTO (org.apache.openmeetings.db.dto.room.RoomFileDTO)1 BaseFileItem (org.apache.openmeetings.db.entity.file.BaseFileItem)1 Room (org.apache.openmeetings.db.entity.room.Room)1