Search in sources :

Example 11 with DocumentObject

use of nikita.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 12 with DocumentObject

use of nikita.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 13 with DocumentObject

use of nikita.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)

Example 14 with DocumentObject

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

the class NoarkImportService method checkAndSetDefaultValues.

/**
     *
     * Check a Noark entity (fonds, series, file, etc) for valid properties and set any values that have not been set
     * that should be set with default values.
     *
     * @param entity
     * @throws Exception
     */
public void checkAndSetDefaultValues(INoarkGeneralEntity entity) throws Exception {
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    // Not all Noark objects, i.e DocumentDescription and DocumentObject have a documentMedium property
    if (entity instanceof IDocumentMedium) {
        if (!NoarkUtils.NoarkEntity.Create.checkDocumentMediumValid(((IDocumentMedium) entity))) {
            logger.error("Document medium not a valid document medium. Assigned value is " + ((IDocumentMedium) entity).getDocumentMedium());
        // An exception will be thrown  by checkDocumentMediumValid if not valid
        //TODO: Look at the logic here, as a change checkDocumentMediumValid kinda makes
        // the if redundant
        }
    }
    // uniqueness via systemId
    if (entity.getSystemId() == null) {
        entity.setSystemId(UUID.randomUUID().toString());
    } else if (entity.getSystemId().length() != Constants.UUIDLength) {
        String randomUUID = UUID.randomUUID().toString();
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a valid UUID. Original value [" + entity.getSystemId() + entity.toString() + "] is being changed and assigned with [" + randomUUID + "]");
        entity.setSystemId(randomUUID);
    }
    if (entity.getCreatedDate() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdDate value. createdDate is being set to [" + new Date().toString() + "]");
        entity.setCreatedDate(new Date());
    }
    if (entity.getCreatedBy() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdBy value. createdBy is being set to [" + username + "]");
        entity.setCreatedBy(username);
    }
    if (entity.getOwnedBy() == null) {
        logger.info("Noark object of type [ " + entity.getClass().getName() + "] does not have a createdBy value. createdBy is being set to [" + username + "]");
        entity.setOwnedBy(username);
    }
    entity.setDeleted(false);
}
Also used : IDocumentMedium(nikita.model.noark5.v4.interfaces.IDocumentMedium) Date(java.util.Date)

Example 15 with DocumentObject

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

the class DocumentDescriptionHateoasController method findAllDocumentDescriptionAssociatedWithRecord.

// Retrieve all DocumentObjects associated with a DocumentDescription identified by systemId
// GET [contextPath][api]/arkivstruktur/dokumentbeskrivelse/{systemId}/dokumentobjekt
@ApiOperation(value = "Retrieves a list of DocumentObjects associated with a DocumentDescription", response = DocumentObjectHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentObject returned", response = DocumentObjectHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + DOCUMENT_OBJECT, method = RequestMethod.GET)
public ResponseEntity<DocumentObjectHateoas> findAllDocumentDescriptionAssociatedWithRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the file to retrieve associated Record", required = true) @PathVariable("systemID") final String systemID) {
    DocumentDescription documentDescription = documentDescriptionService.findBySystemIdOrderBySystemId(systemID);
    if (documentDescription == null) {
        throw new NoarkEntityNotFoundException("Could not find DocumentDescription object with systemID " + systemID);
    }
    DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(new ArrayList<>(documentDescription.getReferenceDocumentObject()));
    documentObjectHateoasHandler.addLinks(documentObjectHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentObjectHateoas);
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription) DocumentObjectHateoas(nikita.model.noark5.v4.hateoas.DocumentObjectHateoas) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

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