Search in sources :

Example 6 with NikitaException

use of nikita.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 nikita.model.noark5.v4.interfaces.entities.IMetadataEntity)) {
        throw new NikitaException("Internal error when serialising " + noarkSystemIdEntity + " Not castable to nikita.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.util.exceptions.NikitaException) IMetadataEntity(nikita.model.noark5.v4.interfaces.entities.IMetadataEntity)

Example 7 with NikitaException

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

the class FileImportService method createFile.

@Override
public File createFile(File file) {
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    if (username == null) {
        throw new NikitaException("Security context problem. username is null! Cannot continue with " + "this request!");
    }
    if (file.getCreatedDate() == null) {
        file.setCreatedDate(new Date());
    }
    if (file.getCreatedBy() == null) {
        file.setCreatedBy(username);
    }
    if (file.getOwnedBy() == null) {
        file.setOwnedBy(username);
    }
    file.setDeleted(false);
    return fileRepository.save(file);
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) Date(java.util.Date)

Example 8 with NikitaException

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

the class RegistryEntryImportService method save.

@Override
public RegistryEntry save(RegistryEntry registryEntry) {
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    if (username == null) {
        throw new NikitaException("Security context problem. username is null! Cannot continue with " + "this request!");
    }
    if (registryEntry.getCreatedDate() == null) {
        registryEntry.setCreatedDate(new Date());
    }
    if (registryEntry.getCreatedBy() == null) {
        registryEntry.setCreatedBy(username);
    }
    if (registryEntry.getOwnedBy() == null) {
        registryEntry.setOwnedBy(username);
    }
    registryEntry.setDeleted(false);
    registryEntryRepository.save(registryEntry);
    return registryEntry;
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) Date(java.util.Date)

Example 9 with NikitaException

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

the class SeriesImportService method save.

public Series save(Series series) {
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    if (username == null) {
        throw new NikitaException("Security context problem. username is null! Cannot continue with " + "this request!");
    }
    if (series.getCreatedDate() == null) {
        series.setCreatedDate(new Date());
    }
    if (series.getCreatedBy() == null) {
        series.setCreatedBy(username);
    }
    if (series.getOwnedBy() == null) {
        series.setOwnedBy(username);
    }
    series.setDeleted(false);
    return seriesRepository.save(series);
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) Date(java.util.Date)

Example 10 with NikitaException

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

the class BasicRecordHateoasController method deleteRecordBySystemId.

// Delete a Record identified by systemID
// DELETE [contextPath][api]/arkivstruktur/registrering/{systemId}/
@ApiOperation(value = "Deletes a single Record 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
@Timed
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.DELETE)
public ResponseEntity<HateoasNoarkObject> deleteRecordBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the record to delete", required = true) @PathVariable("systemID") final String systemID) {
    BasicRecord basicRecord = basicRecordService.findBySystemIdOrderBySystemId(systemID);
    NoarkEntity parentEntity = basicRecord.chooseParent();
    HateoasNoarkObject hateoasNoarkObject;
    if (parentEntity instanceof Series) {
        hateoasNoarkObject = new SeriesHateoas(parentEntity);
        seriesHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
    } else if (parentEntity instanceof File) {
        hateoasNoarkObject = new FileHateoas(parentEntity);
        fileHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
    } else if (parentEntity instanceof Class) {
        hateoasNoarkObject = new ClassHateoas(parentEntity);
        classHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
    } else {
        throw new NikitaException("Internal error. Could not process" + request.getRequestURI());
    }
    basicRecordService.deleteEntity(systemID);
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, basicRecord));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) Class(nikita.model.noark5.v4.Class) AfterNoarkEntityDeletedEvent(no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

NikitaException (nikita.util.exceptions.NikitaException)16 Counted (com.codahale.metrics.annotation.Counted)8 Timed (com.codahale.metrics.annotation.Timed)8 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)8 Date (java.util.Date)7 AfterNoarkEntityDeletedEvent (no.arkivlab.hioa.nikita.webapp.web.events.AfterNoarkEntityDeletedEvent)5 Class (nikita.model.noark5.v4.Class)4 NoarkEntity (nikita.model.noark5.v4.NoarkEntity)3 HateoasNoarkObject (nikita.model.noark5.v4.hateoas.HateoasNoarkObject)3 CorrespondencePartType (nikita.model.noark5.v4.metadata.CorrespondencePartType)3 ClassHateoas (nikita.model.noark5.v4.hateoas.ClassHateoas)2 ClassificationSystem (nikita.model.noark5.v4.ClassificationSystem)1 DocumentDescription (nikita.model.noark5.v4.DocumentDescription)1 DocumentObject (nikita.model.noark5.v4.DocumentObject)1 Record (nikita.model.noark5.v4.Record)1 Series (nikita.model.noark5.v4.Series)1 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)1 ClassificationSystemHateoas (nikita.model.noark5.v4.hateoas.ClassificationSystemHateoas)1