Search in sources :

Example 6 with BasicRecord

use of nikita.common.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordService method findBasicRecordByOwnerPaginated.

// All READ operations
@Override
public List<BasicRecord> findBasicRecordByOwnerPaginated(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<BasicRecord> criteriaQuery = criteriaBuilder.createQuery(BasicRecord.class);
    Root<BasicRecord> from = criteriaQuery.from(BasicRecord.class);
    CriteriaQuery<BasicRecord> select = criteriaQuery.select(from);
    criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
    TypedQuery<BasicRecord> typedQuery = entityManager.createQuery(select);
    typedQuery.setFirstResult(skip);
    typedQuery.setMaxResults(maxPageSize);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BasicRecord(nikita.model.noark5.v4.BasicRecord)

Example 7 with BasicRecord

use of nikita.common.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordService method deleteEntity.

// All DELETE operations
@Override
public void deleteEntity(@NotNull String basicRecordSystemId) {
    BasicRecord basicRecord = getBasicRecordOrThrow(basicRecordSystemId);
    basicRecordRepository.delete(basicRecord);
}
Also used : BasicRecord(nikita.model.noark5.v4.BasicRecord)

Example 8 with BasicRecord

use of nikita.common.model.noark5.v4.BasicRecord 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 9 with BasicRecord

use of nikita.common.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordService method deleteEntity.

// All DELETE operations
@Override
public void deleteEntity(@NotNull String basicRecordSystemId) {
    BasicRecord basicRecord = getBasicRecordOrThrow(basicRecordSystemId);
    basicRecordRepository.delete(basicRecord);
}
Also used : BasicRecord(nikita.common.model.noark5.v4.BasicRecord)

Example 10 with BasicRecord

use of nikita.common.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.

the class FileService method createBasicRecordAssociatedWithFile.

@Override
public BasicRecord createBasicRecordAssociatedWithFile(String fileSystemId, BasicRecord basicRecord) {
    BasicRecord persistedBasicRecord;
    File file = fileRepository.findBySystemId(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.common.model.noark5.v4.BasicRecord) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) File(nikita.common.model.noark5.v4.File)

Aggregations

BasicRecord (nikita.model.noark5.v4.BasicRecord)8 BasicRecord (nikita.common.model.noark5.v4.BasicRecord)7 Counted (com.codahale.metrics.annotation.Counted)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)3 Timed (com.codahale.metrics.annotation.Timed)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 NikitaMalformedInputDataException (nikita.common.util.exceptions.NikitaMalformedInputDataException)2 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)2 File (nikita.model.noark5.v4.File)2 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)2 Authorisation (nikita.webapp.security.Authorisation)2 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1