use of nikita.common.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class FileService method findFileByOwnerPaginated.
// All READ operations
@Override
public List<File> findFileByOwnerPaginated(Integer top, Integer skip) {
if (top == null || top > maxPageSize) {
top = maxPageSize;
}
if (skip == null) {
skip = 0;
}
String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<File> criteriaQuery = criteriaBuilder.createQuery(File.class);
Root<File> from = criteriaQuery.from(File.class);
CriteriaQuery<File> select = criteriaQuery.select(from);
criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
TypedQuery<File> typedQuery = entityManager.createQuery(select);
typedQuery.setFirstResult(skip);
typedQuery.setMaxResults(maxPageSize);
return typedQuery.getResultList();
}
use of nikita.common.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class FileService method createRecordAssociatedWithFile.
@Override
public Record createRecordAssociatedWithFile(String fileSystemId, Record record) {
Record persistedRecord = null;
File file = fileRepository.findBySystemIdOrderBySystemId(fileSystemId);
if (file == null) {
String info = INFO_CANNOT_FIND_OBJECT + " File, using fileSystemId " + fileSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
} else {
record.setReferenceFile(file);
persistedRecord = recordService.save(record);
}
return persistedRecord;
}
use of nikita.common.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class FileService method createBasicRecordAssociatedWithFile.
@Override
public BasicRecord createBasicRecordAssociatedWithFile(String fileSystemId, BasicRecord basicRecord) {
BasicRecord persistedBasicRecord = null;
File file = fileRepository.findBySystemIdOrderBySystemId(fileSystemId);
if (file == null) {
String info = INFO_CANNOT_FIND_OBJECT + " File, using fileSystemId " + fileSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
} else {
basicRecord.setReferenceFile(file);
persistedBasicRecord = (BasicRecord) recordService.save(basicRecord);
}
return persistedBasicRecord;
}
use of nikita.common.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class FileService method updateFileSetTitle.
public File updateFileSetTitle(Long id, String newTitle) {
File file = fileRepository.findById(id);
file.setTitle(newTitle);
return fileRepository.save(file);
}
use of nikita.common.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class FileService method getFileOrThrow.
// All HELPER operations
/**
* Internal helper method. Rather than having a find and try catch in multiple methods, we have it here once.
* If you call this, be aware that you will only ever get a valid File back. If there is no valid
* File, an exception is thrown
*
* @param fileSystemId systemId of the file object you are looking for
* @return the newly found file object or null if it does not exist
*/
private File getFileOrThrow(@NotNull String fileSystemId) {
File file = fileRepository.findBySystemId(fileSystemId);
if (file == null) {
String info = INFO_CANNOT_FIND_OBJECT + " File, using systemId " + fileSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
}
return file;
}
Aggregations