Search in sources :

Example 6 with DocumentObject

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

the class RecordHateoasController method createDefaultDocumentObject.

// Create a DocumentObject with default values
// GET [contextPath][api]/arkivstruktur/resgistrering/{systemId}/ny-dokumentobjekt
@ApiOperation(value = "Create a DocumentObject with default values", 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 + NEW_DOCUMENT_OBJECT, method = RequestMethod.GET)
public ResponseEntity<DocumentObjectHateoas> createDefaultDocumentObject(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) {
    DocumentObject defaultDocumentObject = new DocumentObject();
    // This is just temporary code as this will have to be replaced if this ever goes into production
    defaultDocumentObject.setMimeType(MediaType.APPLICATION_XML.toString());
    defaultDocumentObject.setVariantFormat(PRODUCTION_VERSION);
    defaultDocumentObject.setFormat("XML");
    DocumentObjectHateoas documentObjectHateoas = new DocumentObjectHateoas(defaultDocumentObject);
    documentObjectHateoasHandler.addLinksOnNew(documentObjectHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(documentObjectHateoas);
}
Also used : Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) DocumentObject(nikita.model.noark5.v4.DocumentObject) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with DocumentObject

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

the class DocumentObjectHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject documentObjectHateoas, JsonGenerator jgen) throws IOException {
    DocumentObject documentObject = (DocumentObject) noarkSystemIdEntity;
    jgen.writeStartObject();
    // handle DocumentObject properties
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, documentObject);
    if (documentObject.getVersionNumber() != null) {
        jgen.writeNumberField(DOCUMENT_OBJECT_VERSION_NUMBER, documentObject.getVersionNumber().intValue());
    }
    if (documentObject.getVariantFormat() != null) {
        jgen.writeStringField(DOCUMENT_OBJECT_VARIANT_FORMAT, documentObject.getVariantFormat());
    }
    if (documentObject.getFormat() != null) {
        jgen.writeStringField(DOCUMENT_OBJECT_FORMAT, documentObject.getFormat());
    }
    if (documentObject.getFormatDetails() != null) {
        jgen.writeStringField(DOCUMENT_OBJECT_FORMAT_DETAILS, documentObject.getFormatDetails());
    }
    CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, documentObject);
    if (documentObject.getReferenceDocumentFile() != null) {
        jgen.writeStringField(DOCUMENT_OBJECT_REFERENCE_DOCUMENT_FILE, documentObject.getReferenceDocumentFile());
    }
    if (documentObject.getChecksum() != null) {
        jgen.writeStringField(DOCUMENT_OBJECT_CHECKSUM, documentObject.getChecksum());
    }
    if (documentObject.getChecksumAlgorithm() != null) {
        jgen.writeStringField(DOCUMENT_OBJECT_CHECKSUM_ALGORITHM, documentObject.getChecksumAlgorithm());
    }
    if (documentObject.getFileSize() != null) {
        jgen.writeStringField(DOCUMENT_OBJECT_FILE_SIZE, Long.toString(documentObject.getFileSize()));
    }
    if (documentObject.getOriginalFilename() != null) {
        jgen.writeStringField(DOCUMENT_OBJECT_FILE_NAME, documentObject.getOriginalFilename());
    }
    if (documentObject.getMimeType() != null) {
        jgen.writeStringField(DOCUMENT_OBJECT_MIME_TYPE, documentObject.getMimeType());
    }
    CommonUtils.Hateoas.Serialize.printElectronicSignature(jgen, documentObject);
    CommonUtils.Hateoas.Serialize.printConversion(jgen, documentObject);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, documentObjectHateoas.getLinks(documentObject));
    jgen.writeEndObject();
}
Also used : DocumentObject(nikita.model.noark5.v4.DocumentObject)

Example 8 with DocumentObject

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

the class DocumentDescriptionService method createDocumentObjectAssociatedWithDocumentDescription.

// All CREATE operations
@Override
public DocumentObject createDocumentObjectAssociatedWithDocumentDescription(String documentDescriptionSystemId, DocumentObject documentObject) {
    DocumentObject persistedDocumentObject = null;
    DocumentDescription documentDescription = documentDescriptionRepository.findBySystemIdOrderBySystemId(documentDescriptionSystemId);
    if (documentDescription == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " DocumentDescription, using documentDescriptionSystemId " + documentDescriptionSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else {
        documentObject.setReferenceDocumentDescription(documentDescription);
        Set<DocumentObject> documentObjects = documentDescription.getReferenceDocumentObject();
        documentObjects.add(documentObject);
        persistedDocumentObject = documentObjectService.save(documentObject);
    }
    return persistedDocumentObject;
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription) DocumentObject(nikita.model.noark5.v4.DocumentObject) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 9 with DocumentObject

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

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

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