Search in sources :

Example 1 with NoarkEntity

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

the class DocumentDescriptionHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkEntity, HateoasNoarkObject documentDescriptionHateoas, JsonGenerator jgen) throws IOException {
    DocumentDescription documentDescription = (DocumentDescription) noarkEntity;
    jgen.writeStartObject();
    // handle DocumentDescription properties
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, documentDescription);
    if (documentDescription.getDocumentType() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE, documentDescription.getDocumentType());
    }
    if (documentDescription.getDocumentStatus() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_STATUS, documentDescription.getDocumentStatus());
    }
    CommonUtils.Hateoas.Serialize.printTitleAndDescription(jgen, documentDescription);
    if (documentDescription.getDocumentNumber() != null) {
        jgen.writeNumberField(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER, documentDescription.getDocumentNumber().intValue());
    }
    CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, documentDescription);
    if (documentDescription.getAssociationDate() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE, Serialize.formatDate(documentDescription.getAssociationDate()));
    }
    if (documentDescription.getAssociatedWithRecordAs() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS, documentDescription.getAssociatedWithRecordAs());
    }
    CommonUtils.Hateoas.Serialize.printComment(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printDisposal(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printDisposalUndertaken(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printDeletion(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printScreening(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printClassified(jgen, documentDescription);
    if (documentDescription.getStorageLocation() != null) {
        jgen.writeStringField(STORAGE_LOCATION, documentDescription.getStorageLocation());
    }
    CommonUtils.Hateoas.Serialize.printElectronicSignature(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, documentDescriptionHateoas.getLinks(documentDescription));
    jgen.writeEndObject();
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription)

Example 2 with NoarkEntity

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

the class DocumentDescriptionHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkEntity, HateoasNoarkObject documentDescriptionHateoas, JsonGenerator jgen) throws IOException {
    DocumentDescription documentDescription = (DocumentDescription) noarkEntity;
    jgen.writeStartObject();
    // handle DocumentDescription properties
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, documentDescription);
    if (documentDescription.getDocumentType() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE, documentDescription.getDocumentType());
    }
    if (documentDescription.getDocumentStatus() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_STATUS, documentDescription.getDocumentStatus());
    }
    CommonUtils.Hateoas.Serialize.printTitleAndDescription(jgen, documentDescription);
    if (documentDescription.getDocumentNumber() != null) {
        jgen.writeNumberField(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER, documentDescription.getDocumentNumber().intValue());
    }
    CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, documentDescription);
    if (documentDescription.getAssociationDate() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE, Serialize.formatDate(documentDescription.getAssociationDate()));
    }
    if (documentDescription.getAssociationDate() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_ASSOCIATION_BY, documentDescription.getAssociatedBy());
    }
    if (documentDescription.getAssociatedWithRecordAs() != null) {
        jgen.writeStringField(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS, documentDescription.getAssociatedWithRecordAs());
    }
    CommonUtils.Hateoas.Serialize.printComment(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printDisposal(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printDisposalUndertaken(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printDeletion(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printScreening(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printClassified(jgen, documentDescription);
    if (documentDescription.getStorageLocation() != null) {
        jgen.writeStringField(STORAGE_LOCATION, documentDescription.getStorageLocation());
    }
    CommonUtils.Hateoas.Serialize.printElectronicSignature(jgen, documentDescription);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, documentDescriptionHateoas.getLinks(documentDescription));
    jgen.writeEndObject();
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription)

Example 3 with NoarkEntity

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

the class OdataTest method testOdata.

@RequestMapping(method = RequestMethod.GET, value = "arkivstruktur/{\\w*}")
public ResponseEntity<String> testOdata(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response) throws Exception {
    String uqueryString = request.getQueryString();
    String decoded = URLDecoder.decode(uqueryString, UTF_8);
    StringBuffer originalRequest = request.getRequestURL();
    originalRequest.append("?" + decoded);
    CharStream stream = CharStreams.fromString(originalRequest.toString());
    ODataLexer lexer = new ODataLexer(stream);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ODataParser parser = new ODataParser(tokens);
    ParseTree tree = parser.odataURL();
    ParseTreeWalker walker = new ParseTreeWalker();
    // Make the HQL Statement
    NikitaODataToHQLWalker hqlWalker = new NikitaODataToHQLWalker();
    walker.walk(hqlWalker, tree);
    Session session = entityManager.unwrap(org.hibernate.Session.class);
    Query query = hqlWalker.getHqlStatment(session);
    String queryString = query.getQueryString();
    System.out.println(queryString);
    List<NoarkEntity> list = query.getResultList();
    return ResponseEntity.status(HttpStatus.CREATED).body(list.toString());
}
Also used : ODataParser(nikita.webapp.odata.ODataParser) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Query(org.hibernate.query.Query) NoarkEntity(nikita.common.model.noark5.v4.NoarkEntity) CharStream(org.antlr.v4.runtime.CharStream) ODataLexer(nikita.webapp.odata.ODataLexer) NikitaODataToHQLWalker(nikita.webapp.odata.NikitaODataToHQLWalker) ParseTree(org.antlr.v4.runtime.tree.ParseTree) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) Session(org.hibernate.Session) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with NoarkEntity

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

the class DocumentObjectHateoasController method deleteDocumentObjectBySystemId.

// Delete a DocumentObject identified by systemID
// DELETE [contextPath][api]/arkivstruktur/dokumentobjekt/{systemId}/
@ApiOperation(value = "Deletes a single DocumentObject entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or Record) returned", response = HateoasNoarkObject.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<HateoasNoarkObject> deleteDocumentObjectBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentObject to delete", required = true) @PathVariable("systemID") final String systemID) {
    DocumentObject documentObject = documentObjectService.findBySystemId(systemID);
    NoarkEntity parentEntity = documentObject.chooseParent();
    documentObjectService.deleteEntity(systemID);
    HateoasNoarkObject hateoasNoarkObject;
    if (parentEntity instanceof DocumentDescription) {
        hateoasNoarkObject = new DocumentDescriptionHateoas(parentEntity);
        documentDescriptionHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
    } else if (parentEntity instanceof Record) {
        hateoasNoarkObject = new RecordHateoas(parentEntity);
        recordHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
    } else {
        throw new NikitaException("Internal error. Could process" + request.getRequestURI());
    }
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, documentObject));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
Also used : NikitaException(nikita.common.util.exceptions.NikitaException) NoarkEntity(nikita.common.model.noark5.v4.NoarkEntity) DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) HateoasNoarkObject(nikita.common.model.noark5.v4.hateoas.HateoasNoarkObject) Authorisation(nikita.webapp.security.Authorisation) DocumentDescriptionHateoas(nikita.common.model.noark5.v4.hateoas.DocumentDescriptionHateoas) RecordHateoas(nikita.common.model.noark5.v4.hateoas.RecordHateoas) DocumentObject(nikita.common.model.noark5.v4.DocumentObject) 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 5 with NoarkEntity

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

the class FileHateoasController method deleteFileBySystemId.

// Delete a File identified by systemID
// DELETE [contextPath][api]/arkivstruktur/mappe/{systemId}/
@ApiOperation(value = "Deletes a single File entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or File) returned", response = HateoasNoarkObject.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<HateoasNoarkObject> deleteFileBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the file to delete", required = true) @PathVariable("systemID") final String systemID) {
    File file = fileService.findBySystemId(systemID);
    NoarkEntity parentEntity = file.chooseParent();
    HateoasNoarkObject hateoasNoarkObject;
    if (parentEntity instanceof Series) {
        hateoasNoarkObject = new SeriesHateoas(parentEntity);
        seriesHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
    } else if (parentEntity instanceof File) {
        hateoasNoarkObject = new FileHateoas(parentEntity);
        fileHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
    } else if (parentEntity instanceof Class) {
        hateoasNoarkObject = new ClassHateoas(parentEntity);
        classHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
    } else {
        throw new NikitaException("Internal error. Could not process" + request.getRequestURI());
    }
    fileService.deleteEntity(systemID);
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, file));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
Also used : NikitaException(nikita.common.util.exceptions.NikitaException) Authorisation(nikita.webapp.security.Authorisation) Class(nikita.common.model.noark5.v4.Class) CaseFileHateoas(nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas) AfterNoarkEntityDeletedEvent(nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)12 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Timed (com.codahale.metrics.annotation.Timed)6 AfterNoarkEntityDeletedEvent (nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)6 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)6 NikitaException (nikita.common.util.exceptions.NikitaException)5 NikitaException (nikita.util.exceptions.NikitaException)5 Authorisation (nikita.webapp.security.Authorisation)5 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)5 Class (nikita.common.model.noark5.v4.Class)4 NoarkEntity (nikita.common.model.noark5.v4.NoarkEntity)4 Class (nikita.model.noark5.v4.Class)4 HateoasNoarkObject (nikita.common.model.noark5.v4.hateoas.HateoasNoarkObject)3 NoarkEntity (nikita.model.noark5.v4.NoarkEntity)3 HateoasNoarkObject (nikita.model.noark5.v4.hateoas.HateoasNoarkObject)3 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)2 Record (nikita.common.model.noark5.v4.Record)2 ClassHateoas (nikita.common.model.noark5.v4.hateoas.ClassHateoas)2 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)2