Search in sources :

Example 6 with FileItem

use of org.apache.openmeetings.db.entity.file.FileItem in project openmeetings by apache.

the class BackupImport method importFiles.

/*
	 * ##################### Import File-Explorer Items
	 */
private List<FileItem> importFiles(File f) throws Exception {
    log.info("Private message import complete, starting file explorer item import");
    List<FileItem> result = new ArrayList<>();
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer ser = new Persister(strategy, matcher);
    matcher.bind(Long.class, LongTransform.class);
    matcher.bind(Integer.class, IntegerTransform.class);
    registry.bind(Date.class, DateConverter.class);
    List<FileItem> list = readList(ser, f, "fileExplorerItems.xml", "fileExplorerItems", FileItem.class);
    for (FileItem file : list) {
        Long fId = file.getId();
        // We need to reset this as openJPA reject to store them otherwise
        file.setId(null);
        Long roomId = file.getRoomId();
        file.setRoomId(roomMap.containsKey(roomId) ? roomMap.get(roomId) : null);
        if (file.getOwnerId() != null) {
            file.setOwnerId(userMap.get(file.getOwnerId()));
        }
        if (file.getParentId() != null && file.getParentId().longValue() <= 0L) {
            file.setParentId(null);
        }
        if (Strings.isEmpty(file.getHash())) {
            file.setHash(UUID.randomUUID().toString());
        }
        file = fileItemDao.update(file);
        result.add(file);
        fileItemMap.put(fId, file.getId());
    }
    return result;
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) ArrayList(java.util.ArrayList) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 7 with FileItem

use of org.apache.openmeetings.db.entity.file.FileItem 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 8 with FileItem

use of org.apache.openmeetings.db.entity.file.FileItem in project openmeetings by apache.

the class FileItemDao method updateChilds.

private void updateChilds(FileItem f) {
    for (FileItem child : getByParent(f.getId())) {
        child.setOwnerId(f.getOwnerId());
        child.setRoomId(f.getRoomId());
        update(child);
        if (Type.Folder == f.getType()) {
            updateChilds(child);
        }
    }
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem)

Example 9 with FileItem

use of org.apache.openmeetings.db.entity.file.FileItem in project openmeetings by apache.

the class FileItemDao method move.

/**
 * @param id - id of file item to move
 * @param parentId - id of parent item
 * @param ownerId - id of item owner
 * @param roomId - id of room
 *
 * @return moved item
 */
public FileItem move(long id, long parentId, long ownerId, long roomId) {
    log.debug(".move() started");
    FileItem f = get(id);
    if (f == null) {
        return null;
    }
    if (parentId < 0) {
        if (parentId == -1) {
            // move to personal Folder
            f.setOwnerId(ownerId);
            f.setRoomId(null);
        } else {
            // move to public room folder
            f.setOwnerId(null);
            f.setRoomId(roomId);
        }
        f.setParentId(null);
    } else {
        f.setParentId(parentId);
        f.setOwnerId(null);
    }
    if (Type.Folder == f.getType()) {
        updateChilds(f);
    }
    return update(f);
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem)

Example 10 with FileItem

use of org.apache.openmeetings.db.entity.file.FileItem 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)

Aggregations

FileItem (org.apache.openmeetings.db.entity.file.FileItem)20 BaseFileItem (org.apache.openmeetings.db.entity.file.BaseFileItem)12 Path (javax.ws.rs.Path)4 ArrayList (java.util.ArrayList)3 Whiteboard (org.apache.openmeetings.db.dto.room.Whiteboard)3 Recording (org.apache.openmeetings.db.entity.record.Recording)3 ProcessResultList (org.apache.openmeetings.util.process.ProcessResultList)3 Serializer (org.simpleframework.xml.Serializer)3 Registry (org.simpleframework.xml.convert.Registry)3 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)3 Persister (org.simpleframework.xml.core.Persister)3 Strategy (org.simpleframework.xml.strategy.Strategy)3 File (java.io.File)2 WebMethod (javax.jws.WebMethod)2 DELETE (javax.ws.rs.DELETE)2 ServiceResult (org.apache.openmeetings.db.dto.basic.ServiceResult)2 FileItemDTO (org.apache.openmeetings.db.dto.file.FileItemDTO)2 RegistryMatcher (org.simpleframework.xml.transform.RegistryMatcher)2 JSONObject (com.github.openjson.JSONObject)1 FileInputStream (java.io.FileInputStream)1