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);
}
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);
}
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;
}
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;
}
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);
}
}
}
Aggregations