Search in sources :

Example 6 with ProcessResultList

use of org.apache.openmeetings.util.process.ProcessResultList 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 7 with ProcessResultList

use of org.apache.openmeetings.util.process.ProcessResultList in project openmeetings by apache.

the class UploadDialog method onSubmit.

@Override
protected void onSubmit(AjaxRequestTarget target) {
    List<FileUpload> ful = uploadField.getFileUploads();
    if (ful != null) {
        boolean clean = cleanWb.getModelObject();
        for (FileUpload fu : ful) {
            FileItem f = new FileItem();
            f.setSize(fu.getSize());
            f.setName(fu.getClientFileName());
            BaseFileItem parent = roomFiles.getLastSelected();
            if (parent == null || !(parent instanceof FileItem)) {
                f.setOwnerId(getUserId());
            } else {
                f.setRoomId(parent.getRoomId());
                f.setOwnerId(parent.getOwnerId());
                f.setGroupId(parent.getGroupId());
                if (parent.getId() != null) {
                    f.setParentId(BaseFileItem.Type.Folder == parent.getType() ? parent.getId() : parent.getParentId());
                }
            }
            f.setInsertedBy(getUserId());
            try {
                ProcessResultList logs = processor.processFile(f, fu.getInputStream());
                for (ProcessResult res : logs.getJobs()) {
                    fileLogDao.add(res.getProcess(), f, res);
                }
                room.getSidebar().updateFiles(target);
                if (logs.hasError()) {
                    form.error(getString("convert.errors.file"));
                } else {
                    if (toWb.getModelObject()) {
                        room.getWb().sendFileToWb(f, clean);
                        clean = false;
                    }
                }
            } catch (Exception e) {
                form.error(e.getMessage());
            } finally {
                fu.closeStreams();
                fu.delete();
            }
        }
        if (form.hasError()) {
            onError(target);
        } else {
            close(target, null);
        }
    }
}
Also used : BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) FileItem(org.apache.openmeetings.db.entity.file.FileItem) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) ProcessResult(org.apache.openmeetings.util.process.ProcessResult) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload) ProcessResultList(org.apache.openmeetings.util.process.ProcessResultList)

Aggregations

ProcessResultList (org.apache.openmeetings.util.process.ProcessResultList)7 File (java.io.File)4 FileItem (org.apache.openmeetings.db.entity.file.FileItem)3 ArrayList (java.util.ArrayList)2 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)2 FileItemDTO (org.apache.openmeetings.db.dto.file.FileItemDTO)2 BaseFileItem (org.apache.openmeetings.db.entity.file.BaseFileItem)2 Recording (org.apache.openmeetings.db.entity.record.Recording)2 RecordingMetaData (org.apache.openmeetings.db.entity.record.RecordingMetaData)2 StoredFile (org.apache.openmeetings.util.StoredFile)2 ProcessResult (org.apache.openmeetings.util.process.ProcessResult)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 WebMethod (javax.jws.WebMethod)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 FileUtils.copyInputStreamToFile (org.apache.commons.io.FileUtils.copyInputStreamToFile)1 User (org.apache.openmeetings.db.entity.user.User)1