Search in sources :

Example 26 with DocumentDescription

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

the class DocumentDescriptionHateoasController method deleteDocumentDescriptionBySystemId.

// Delete a DocumentDescription identified by systemID
// DELETE [contextPath][api]/arkivstruktur/dokumentobjekt/{systemId}/
@ApiOperation(value = "Deletes a single DocumentDescription entity identified by systemID", response = RecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent Fonds returned", response = RecordHateoas.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
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.DELETE)
public ResponseEntity<RecordHateoas> deleteDocumentDescriptionBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentDescription to delete", required = true) @PathVariable("systemID") final String systemID) {
    DocumentDescription documentDescription = documentDescriptionService.findBySystemId(systemID);
    List<Record> record = new ArrayList<>();
    record.addAll(documentDescription.getReferenceRecord());
    documentDescriptionService.deleteEntity(systemID);
    RecordHateoas recordHateoas = new RecordHateoas((List) record);
    /*RecordHateoas recordHateoas = new RecordHateoas(
                (List<INikitaEntity>)
                        (List)record); */
    // RecordHateoas recordHateoas = new RecordHateoas(
    // (List<INikitaEntity>) (List)record);
    recordHateoasHandler.addLinks(recordHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, documentDescription));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(recordHateoas);
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) Authorisation(nikita.webapp.security.Authorisation) ArrayList(java.util.ArrayList) RecordHateoas(nikita.common.model.noark5.v4.hateoas.RecordHateoas) Record(nikita.common.model.noark5.v4.Record) AfterNoarkEntityDeletedEvent(nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 27 with DocumentDescription

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

the class DocumentDescriptionHateoasController method updateDocumentDescription.

// API - All PUT Requests (CRUD - UPDATE)
// Update a DocumentDescription
// PUT [contextPath][api]/arkivstruktur/dokumentobjekt/{systemID}
@ApiOperation(value = "Updates a DocumentDescription object", notes = "Returns the newly" + " update DocumentDescription object after it is persisted to the database", response = DocumentDescriptionHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentDescription " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = DocumentDescriptionHateoas.class), @ApiResponse(code = 201, message = "DocumentDescription " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = DocumentDescriptionHateoas.class), @ApiResponse(code = 401, message = API_MESSAGE_UNAUTHENTICATED_USER), @ApiResponse(code = 403, message = API_MESSAGE_UNAUTHORISED_FOR_USER), @ApiResponse(code = 404, message = API_MESSAGE_PARENT_DOES_NOT_EXIST + " of type DocumentDescription"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.PUT, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<DocumentDescriptionHateoas> updateDocumentDescription(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of documentDescription to update.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "documentDescription", value = "Incoming documentDescription object", required = true) @RequestBody DocumentDescription documentDescription) throws NikitaException {
    validateForUpdate(documentDescription);
    DocumentDescription updatedDocumentDescription = documentDescriptionService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), documentDescription);
    DocumentDescriptionHateoas documentDescriptionHateoas = new DocumentDescriptionHateoas(updatedDocumentDescription);
    documentDescriptionHateoasHandler.addLinks(documentDescriptionHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedDocumentDescription));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedDocumentDescription.getVersion().toString()).body(documentDescriptionHateoas);
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) Authorisation(nikita.webapp.security.Authorisation) DocumentDescriptionHateoas(nikita.common.model.noark5.v4.hateoas.DocumentDescriptionHateoas) AfterNoarkEntityUpdatedEvent(nikita.webapp.web.events.AfterNoarkEntityUpdatedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 28 with DocumentDescription

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

the class DocumentDescriptionService method getDocumentDescriptionOrThrow.

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

Example 29 with DocumentDescription

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

the class DocumentDescriptionService method deleteEntity.

// All DELETE operations
@Override
public void deleteEntity(@NotNull String documentDescriptionSystemId) {
    // See issue for a description of why this code was written this way
    // https://github.com/HiOA-ABI/nikita-noark5-core/issues/82
    DocumentDescription documentDescription = getDocumentDescriptionOrThrow(documentDescriptionSystemId);
    Query q = entityManager.createNativeQuery("DELETE FROM record_document_description WHERE F_PK_DOCUMENT_DESCRIPTION_ID  = :id ;");
    q.setParameter("id", documentDescription.getId());
    q.executeUpdate();
    entityManager.remove(documentDescription);
    entityManager.flush();
    entityManager.clear();
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) Query(javax.persistence.Query)

Example 30 with DocumentDescription

use of nikita.model.noark5.v4.DocumentDescription 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.findBySystemId(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);
        List<DocumentObject> documentObjects = documentDescription.getReferenceDocumentObject();
        documentObjects.add(documentObject);
        persistedDocumentObject = documentObjectService.save(documentObject);
    }
    return persistedDocumentObject;
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) DocumentObject(nikita.common.model.noark5.v4.DocumentObject) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)34 ApiOperation (io.swagger.annotations.ApiOperation)34 ApiResponses (io.swagger.annotations.ApiResponses)34 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)18 Timed (com.codahale.metrics.annotation.Timed)17 Authorisation (nikita.webapp.security.Authorisation)15 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)15 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)14 Record (nikita.model.noark5.v4.Record)8 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)8 AfterNoarkEntityDeletedEvent (nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)8 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)7 ArrayList (java.util.ArrayList)6 Record (nikita.common.model.noark5.v4.Record)6 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)6 NikitaException (nikita.common.util.exceptions.NikitaException)5 NikitaException (nikita.util.exceptions.NikitaException)5 List (java.util.List)4 Class (nikita.common.model.noark5.v4.Class)4 DocumentDescriptionHateoas (nikita.common.model.noark5.v4.hateoas.DocumentDescriptionHateoas)4