Search in sources :

Example 21 with DocumentObject

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

the class DocumentObjectService method findDocumentObjectByOwnerPaginated.

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

Example 22 with DocumentObject

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

the class DocumentObjectService method deleteEntity.

// All DELETE operations
@Override
public void deleteEntity(@NotNull String documentObjectSystemId) {
    DocumentObject documentObject = getDocumentObjectOrThrow(documentObjectSystemId);
    documentObjectRepository.delete(documentObject);
}
Also used : DocumentObject(nikita.model.noark5.v4.DocumentObject)

Example 23 with DocumentObject

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

the class DocumentObjectService method findDocumentObjectByAnyColumn.

// All READ operations
@Override
public List<DocumentObject> findDocumentObjectByAnyColumn(String column, String value) {
    String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<DocumentObject> criteriaQuery = criteriaBuilder.createQuery(DocumentObject.class);
    Root<DocumentObject> from = criteriaQuery.from(DocumentObject.class);
    CriteriaQuery<DocumentObject> select = criteriaQuery.select(from);
    if (column.equalsIgnoreCase(DOCUMENT_OBJECT_FILE_NAME)) {
        column = "originalFilename";
    }
    criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
    criteriaQuery.where(criteriaBuilder.equal(from.get(column), value));
    TypedQuery<DocumentObject> typedQuery = entityManager.createQuery(select);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) DocumentObject(nikita.model.noark5.v4.DocumentObject)

Example 24 with DocumentObject

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

the class DocumentObjectService method handleUpdate.

// All UPDATE operations
@Override
public DocumentObject handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull DocumentObject incomingDocumentObject) {
    DocumentObject existingDocumentObject = getDocumentObjectOrThrow(systemId);
    // Here copy all the values you are allowed to copy ....
    if (null != incomingDocumentObject.getFormat()) {
        existingDocumentObject.setFormat(incomingDocumentObject.getFormat());
    }
    if (null != incomingDocumentObject.getFormatDetails()) {
        existingDocumentObject.setFormatDetails(incomingDocumentObject.getFormatDetails());
    }
    if (null != incomingDocumentObject.getOriginalFilename()) {
        existingDocumentObject.setOriginalFilename(incomingDocumentObject.getOriginalFilename());
    }
    if (null != incomingDocumentObject.getVariantFormat()) {
        existingDocumentObject.setVariantFormat(incomingDocumentObject.getVariantFormat());
    }
    if (null != incomingDocumentObject.getVersionNumber()) {
        existingDocumentObject.setVersionNumber(incomingDocumentObject.getVersionNumber());
    }
    existingDocumentObject.setVersion(version);
    documentObjectRepository.save(existingDocumentObject);
    return existingDocumentObject;
}
Also used : DocumentObject(nikita.model.noark5.v4.DocumentObject)

Example 25 with DocumentObject

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

the class DocumentObjectService method getDocumentObjectOrThrow.

// 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 DocumentObject back. If there is no valid
     * DocumentObject, an exception is thrown
     *
     * @param documentObjectSystemId
     * @return
     */
protected DocumentObject getDocumentObjectOrThrow(@NotNull String documentObjectSystemId) {
    DocumentObject documentObject = documentObjectRepository.findBySystemIdOrderBySystemId(documentObjectSystemId);
    if (documentObject == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " DocumentObject, using systemId " + documentObjectSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return documentObject;
}
Also used : DocumentObject(nikita.model.noark5.v4.DocumentObject) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)20 ApiOperation (io.swagger.annotations.ApiOperation)20 ApiResponses (io.swagger.annotations.ApiResponses)20 DocumentObject (nikita.model.noark5.v4.DocumentObject)16 DocumentObject (nikita.common.model.noark5.v4.DocumentObject)15 Timed (com.codahale.metrics.annotation.Timed)10 Authorisation (nikita.webapp.security.Authorisation)9 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)9 DocumentObjectHateoas (nikita.common.model.noark5.v4.hateoas.DocumentObjectHateoas)7 DocumentObjectHateoas (nikita.model.noark5.v4.hateoas.DocumentObjectHateoas)7 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)6 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)6 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)3 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2