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