Search in sources :

Example 11 with File

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) File(nikita.model.noark5.v4.File)

Example 12 with File

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;
}
Also used : Record(nikita.model.noark5.v4.Record) BasicRecord(nikita.model.noark5.v4.BasicRecord) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) File(nikita.model.noark5.v4.File)

Example 13 with File

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;
}
Also used : BasicRecord(nikita.model.noark5.v4.BasicRecord) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) File(nikita.model.noark5.v4.File)

Example 14 with File

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);
}
Also used : File(nikita.model.noark5.v4.File)

Example 15 with 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;
}
Also used : NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) File(nikita.common.model.noark5.v4.File)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)31 ApiOperation (io.swagger.annotations.ApiOperation)23 ApiResponses (io.swagger.annotations.ApiResponses)23 Timed (com.codahale.metrics.annotation.Timed)15 File (nikita.model.noark5.v4.File)14 Authorisation (nikita.webapp.security.Authorisation)14 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)13 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)13 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)10 File (nikita.common.model.noark5.v4.File)8 CaseFileHateoas (nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)8 CaseFileHateoas (nikita.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)8 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)7 List (java.util.List)5 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)5 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4