Search in sources :

Example 1 with NikitaException

use of nikita.common.util.exceptions.NikitaException in project nikita-noark5-core by HiOA-ABI.

the class MetadataHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject metadataHateoas, JsonGenerator jgen) throws IOException {
    if (!(noarkSystemIdEntity instanceof IMetadataEntity)) {
        throw new NikitaException("Internal error when serialising " + noarkSystemIdEntity + " Not castable to nikita.common.model.noark5.v4.interfaces.entities.IMetadataEntity");
    }
    IMetadataEntity metadataEntity = (IMetadataEntity) noarkSystemIdEntity;
    jgen.writeStartObject();
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, metadataEntity);
    if (metadataEntity.getCode() != null) {
        jgen.writeStringField(CODE, metadataEntity.getCode());
    }
    if (metadataEntity.getDescription() != null) {
        jgen.writeStringField(DESCRIPTION, metadataEntity.getDescription());
    }
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, metadataHateoas.getLinks(metadataEntity));
    jgen.writeEndObject();
}
Also used : NikitaException(nikita.common.util.exceptions.NikitaException) IMetadataEntity(nikita.common.model.noark5.v4.interfaces.entities.IMetadataEntity)

Example 2 with NikitaException

use of nikita.common.util.exceptions.NikitaException 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 3 with NikitaException

use of nikita.common.util.exceptions.NikitaException 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)

Example 4 with NikitaException

use of nikita.common.util.exceptions.NikitaException in project nikita-noark5-core by HiOA-ABI.

the class CaseFileHateoasController method deleteCaseFileBySystemId.

// Delete a CaseFile identified by systemID
// DELETE [contextPath][api]/casehandling/saksmappe/{systemId}/
@ApiOperation(value = "Deletes a single CaseFile entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or CaseFile) 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> deleteCaseFileBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the caseFile to delete", required = true) @PathVariable("systemID") final String systemID) {
    CaseFile caseFile = caseFileService.findBySystemId(systemID);
    NoarkEntity parentEntity = caseFile.chooseParent();
    HateoasNoarkObject hateoasNoarkObject;
    if (parentEntity instanceof Series) {
        hateoasNoarkObject = new SeriesHateoas(parentEntity);
        seriesHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
    } else // TODO: Can a casefile have a Class as parent???
    if (parentEntity instanceof Class) {
        hateoasNoarkObject = new ClassHateoas(parentEntity);
        classHateoasHandler.addLinks(hateoasNoarkObject, new Authorisation());
    } else {
        throw new NikitaException("Internal error. Could not process " + request.getRequestURI());
    }
    caseFileService.deleteEntity(systemID);
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, caseFile));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
Also used : NikitaException(nikita.common.util.exceptions.NikitaException) Series(nikita.common.model.noark5.v4.Series) NoarkEntity(nikita.common.model.noark5.v4.NoarkEntity) ClassHateoas(nikita.common.model.noark5.v4.hateoas.ClassHateoas) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile) HateoasNoarkObject(nikita.common.model.noark5.v4.hateoas.HateoasNoarkObject) Authorisation(nikita.webapp.security.Authorisation) SeriesHateoas(nikita.common.model.noark5.v4.hateoas.SeriesHateoas) Class(nikita.common.model.noark5.v4.Class) 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 NikitaException

use of nikita.common.util.exceptions.NikitaException in project nikita-noark5-core by HiOA-ABI.

the class RegistryEntryHateoasController method getCorrespondencePartUnitTemplate.

// Create a suggested CorrespondencePartUnit (like a template) object with default values (nothing persisted)
// GET [contextPath][api]/casehandling/journalpost/{systemId}/ny-korrespondansepartenhet
@ApiOperation(value = "Suggests the contents of a new CorrespondencePart object", notes = "Returns a pre-filled CorrespondencePart object" + " with values relevant for the logged-in user", response = CorrespondencePartUnitHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "CorrespondencePart " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = CorrespondencePartUnitHateoas.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(method = RequestMethod.GET, value = { SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_CORRESPONDENCE_PART_UNIT })
public ResponseEntity<CorrespondencePartUnitHateoas> getCorrespondencePartUnitTemplate(HttpServletRequest request) throws NikitaException {
    CorrespondencePartUnit suggestedCorrespondencePart = new CorrespondencePartUnit();
    CorrespondencePartType correspondencePartType = correspondencePartTypeService.findByCode(CORRESPONDENCE_PART_CODE_EA);
    if (correspondencePartType == null) {
        throw new NikitaException("Internal error, metadata missing. [" + CORRESPONDENCE_PART_CODE_EA + "] returns no value");
    }
    suggestedCorrespondencePart.setCorrespondencePartType(correspondencePartType);
    PostalAddress postalAddress = new PostalAddress();
    postalAddress.setAddressType(POSTAL_ADDRESS);
    postalAddress.setAddressLine1("ADRL1: 744 Evergreen Terrace");
    postalAddress.setAddressLine2("ADRL2: 744 Evergreen Terrace");
    postalAddress.setAddressLine3("ADRL3: 744 Evergreen Terrace");
    postalAddress.setCountryCode("US");
    postalAddress.setPostalNumber(new PostalNumber("12345"));
    postalAddress.setPostalTown("Springfield");
    suggestedCorrespondencePart.setPostalAddress(postalAddress);
    BusinessAddress businessAddress = new BusinessAddress();
    businessAddress.setAddressType(BUSINESS_ADDRESS);
    businessAddress.setAddressLine1("ADRL1: 745 Evergreen Terrace");
    businessAddress.setAddressLine2("ADRL2: 745 Evergreen Terrace");
    businessAddress.setAddressLine3("ADRL3: 745 Evergreen Terrace");
    businessAddress.setCountryCode("US");
    businessAddress.setPostalNumber(new PostalNumber("12345"));
    businessAddress.setPostalTown("Springfield");
    suggestedCorrespondencePart.setBusinessAddress(businessAddress);
    suggestedCorrespondencePart.setContactPerson("Frank Contact Person Grimes");
    ContactInformation contactInformation = new ContactInformation();
    contactInformation.setEmailAddress("nikita@example.com");
    contactInformation.setMobileTelephoneNumber("123456789");
    contactInformation.setTelephoneNumber("987654321");
    suggestedCorrespondencePart.setContactInformation(contactInformation);
    suggestedCorrespondencePart.setName("Frank Grimes");
    CorrespondencePartUnitHateoas correspondencePartHateoas = new CorrespondencePartUnitHateoas(suggestedCorrespondencePart);
    correspondencePartHateoasHandler.addLinksOnTemplate(correspondencePartHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(correspondencePartHateoas);
}
Also used : NikitaException(nikita.common.util.exceptions.NikitaException) Authorisation(nikita.webapp.security.Authorisation) CorrespondencePartType(nikita.common.model.noark5.v4.metadata.CorrespondencePartType) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

NikitaException (nikita.common.util.exceptions.NikitaException)9 Counted (com.codahale.metrics.annotation.Counted)8 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 Authorisation (nikita.webapp.security.Authorisation)8 AfterNoarkEntityDeletedEvent (nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)5 Class (nikita.common.model.noark5.v4.Class)4 NoarkEntity (nikita.common.model.noark5.v4.NoarkEntity)3 HateoasNoarkObject (nikita.common.model.noark5.v4.hateoas.HateoasNoarkObject)3 CorrespondencePartType (nikita.common.model.noark5.v4.metadata.CorrespondencePartType)3 ClassHateoas (nikita.common.model.noark5.v4.hateoas.ClassHateoas)2 ClassificationSystem (nikita.common.model.noark5.v4.ClassificationSystem)1 DocumentDescription (nikita.common.model.noark5.v4.DocumentDescription)1 DocumentObject (nikita.common.model.noark5.v4.DocumentObject)1 Record (nikita.common.model.noark5.v4.Record)1 Series (nikita.common.model.noark5.v4.Series)1 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)1 ClassificationSystemHateoas (nikita.common.model.noark5.v4.hateoas.ClassificationSystemHateoas)1 DocumentDescriptionHateoas (nikita.common.model.noark5.v4.hateoas.DocumentDescriptionHateoas)1 RecordHateoas (nikita.common.model.noark5.v4.hateoas.RecordHateoas)1