Search in sources :

Example 11 with FileItem

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

the class CleanupHelper method getFileUnit.

public static CleanupEntityUnit getFileUnit(final FileItemDao fileDao) {
    File parent = OmFileHelper.getUploadFilesDir();
    List<File> invalid = new ArrayList<>();
    List<File> deleted = new ArrayList<>();
    int missing = 0;
    for (File f : list(parent, null)) {
        FileItem item = fileDao.getByHash(f.getName());
        if (item == null) {
            invalid.add(f);
        } else if (item.isDeleted()) {
            deleted.add(f);
        }
    }
    for (FileItem item : fileDao.get()) {
        if (!item.isDeleted() && !item.exists()) {
            missing++;
        }
    }
    return new CleanupEntityUnit(parent, invalid, deleted, missing);
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) ArrayList(java.util.ArrayList) File(java.io.File)

Example 12 with FileItem

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

the class BackupImport method performImport.

public void performImport(InputStream is) throws Exception {
    userMap.clear();
    groupMap.clear();
    calendarMap.clear();
    appointmentMap.clear();
    roomMap.clear();
    messageFolderMap.clear();
    userContactMap.clear();
    fileMap.clear();
    messageFolderMap.put(INBOX_FOLDER_ID, INBOX_FOLDER_ID);
    messageFolderMap.put(SENT_FOLDER_ID, SENT_FOLDER_ID);
    messageFolderMap.put(TRASH_FOLDER_ID, TRASH_FOLDER_ID);
    File f = unzip(is);
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    RegistryMatcher matcher = new RegistryMatcher();
    Serializer simpleSerializer = new Persister(strategy, matcher);
    matcher.bind(Long.class, LongTransform.class);
    registry.bind(Date.class, DateConverter.class);
    BackupVersion ver = getVersion(simpleSerializer, f);
    importConfigs(f);
    importGroups(f, simpleSerializer);
    Long defaultLdapId = importLdap(f, simpleSerializer);
    importOauth(f, simpleSerializer);
    importUsers(f, defaultLdapId);
    importRooms(f);
    importRoomGroups(f);
    importChat(f);
    importCalendars(f);
    importAppointments(f);
    importMeetingMembers(f);
    importRecordings(f);
    importPrivateMsgFolders(f, simpleSerializer);
    importContacts(f);
    importPrivateMsgs(f);
    List<FileItem> files = importFiles(f);
    importPolls(f);
    importRoomFiles(f);
    log.info("Room files import complete, starting copy of files and folders");
    /*
		 * ##################### Import real files and folders
		 */
    importFolders(f);
    if (ver.compareTo(BackupVersion.get("4.0.0")) < 0) {
        for (BaseFileItem bfi : files) {
            if (bfi.isDeleted()) {
                continue;
            }
            if (BaseFileItem.Type.Presentation == bfi.getType()) {
                convertOldPresentation((FileItem) bfi);
                fileItemDao._update(bfi);
            }
            if (BaseFileItem.Type.WmlFile == bfi.getType()) {
                try {
                    Whiteboard wb = WbConverter.convert((FileItem) bfi);
                    wb.save(bfi.getFile().toPath());
                } catch (Exception e) {
                    log.error("Unexpected error while converting WB", e);
                }
            }
        }
    }
    log.info("File explorer item import complete, clearing temp files");
    FileUtils.deleteDirectory(f);
}
Also used : RegistryMatcher(org.simpleframework.xml.transform.RegistryMatcher) Registry(org.simpleframework.xml.convert.Registry) IOException(java.io.IOException) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) FileItem(org.apache.openmeetings.db.entity.file.FileItem) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) Persister(org.simpleframework.xml.core.Persister) StoredFile(org.apache.openmeetings.util.StoredFile) File(java.io.File) RoomFile(org.apache.openmeetings.db.entity.room.RoomFile) Whiteboard(org.apache.openmeetings.db.dto.room.Whiteboard) Serializer(org.simpleframework.xml.Serializer)

Example 13 with FileItem

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

the class BaseFileItemConverter method read.

@Override
public BaseFileItem read(InputNode node) throws Exception {
    long oldId = toLong(node.getValue());
    long newId = idMap.containsKey(oldId) ? idMap.get(oldId) : oldId;
    BaseFileItem r = fileDao.get(newId);
    return r == null ? new FileItem() : r;
}
Also used : BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) BaseFileItem(org.apache.openmeetings.db.entity.file.BaseFileItem) FileItem(org.apache.openmeetings.db.entity.file.FileItem)

Example 14 with FileItem

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

the class RoomResourceReference method getFileItem.

@Override
protected FileItem getFileItem(Attributes attr) {
    PageParameters params = attr.getParameters();
    StringValue _id = params.get("id");
    String uid = params.get("uid").toString();
    Long id = null;
    try {
        id = _id.toOptionalLong();
    } catch (NumberFormatException e) {
    // no-op expected
    }
    WebSession ws = WebSession.get();
    Client c = cm.get(uid);
    if (id == null || !ws.isSignedIn() || c == null) {
        return null;
    }
    FileItem f = (FileItem) fileDao.getAny(id);
    if (f == null) {
        return null;
    }
    String ruid = params.get("ruid").toString();
    String wuid = params.get("wuid").toString();
    if (c.getRoom() != null) {
        Whiteboards wbs = wbManager.get(c.getRoom().getId());
        if (!Strings.isEmpty(wuid) && !Strings.isEmpty(ruid) && ruid.equals(wbs.getUid())) {
            for (Entry<Long, Whiteboard> e : wbs.getWhiteboards().entrySet()) {
                JSONObject file = e.getValue().get(wuid);
                if (file != null && f.getId().equals(file.optLong(ATTR_FILE_ID))) {
                    // item IS on WB
                    return f;
                }
            }
        }
    }
    if (f.getGroupId() != null && groupUserDao.isUserInGroup(f.getGroupId(), getUserId())) {
        return f;
    }
    return null;
}
Also used : FileItem(org.apache.openmeetings.db.entity.file.FileItem) WebSession(org.apache.openmeetings.web.app.WebSession) Whiteboards(org.apache.openmeetings.db.dto.room.Whiteboards) JSONObject(com.github.openjson.JSONObject) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) StringValue(org.apache.wicket.util.string.StringValue) Client(org.apache.openmeetings.db.entity.basic.Client) Whiteboard(org.apache.openmeetings.db.dto.room.Whiteboard)

Example 15 with FileItem

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

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