Search in sources :

Example 1 with NikitaException

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

the class CaseFileImportService method save.

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

Example 2 with NikitaException

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

the class DocumentDescriptionImportService method save.

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

Example 3 with NikitaException

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

the class FondsImportService method createNewFonds.

// All CREATE operations
/**
     * Persists a new fonds object to the database. It's assumed the caller has a valid fonds object. Minimal error
     * checking occurs here.
     *
     * @param fonds fonds object with some values set
     * @return the newly persisted fonds object
     */
@Override
public Fonds createNewFonds(Fonds fonds) {
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    if (username == null) {
        throw new NikitaException("Security context problem. username is null! Cannot continue with " + "this request!");
    }
    if (fonds.getCreatedDate() == null) {
        fonds.setCreatedDate(new Date());
    }
    if (fonds.getCreatedBy() == null) {
        fonds.setCreatedBy(username);
    }
    if (fonds.getOwnedBy() == null) {
        fonds.setOwnedBy(username);
    }
    fonds.setDeleted(false);
    return fondsRepository.save(fonds);
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) Date(java.util.Date)

Example 4 with NikitaException

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

the class RecordImportService method save.

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

Example 5 with NikitaException

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

the class RegistryEntryHateoasController method getCorrespondencePartInternalTemplate.

// Create a suggested CorrespondencePartInternal (like a template) object with default values (nothing persisted)
// GET [contextPath][api]/casehandling/journalpost/{systemId}/ny-korrespondansepartintern
@ApiOperation(value = "Suggests the contents of a new CorrespondencePartInternal object", notes = "Returns a pre-filled CorrespondencePartInternal object" + " with values relevant for the logged-in user", response = CorrespondencePartInternalHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "CorrespondencePart " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = CorrespondencePartInternalHateoas.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(method = RequestMethod.GET, value = { SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_CORRESPONDENCE_PART_INTERNAL })
public ResponseEntity<String> getCorrespondencePartInternalTemplate(HttpServletRequest request) throws NikitaException {
    CorrespondencePartInternal suggestedCorrespondencePart = new CorrespondencePartInternal();
    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);
    // The reason this is not implemented is that we are missing AdministrativeUnit and multiple users
    CorrespondencePartInternalHateoas correspondencePartHateoas = new CorrespondencePartInternalHateoas(suggestedCorrespondencePart);
    correspondencePartHateoasHandler.addLinksOnTemplate(correspondencePartHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body("");
}
Also used : NikitaException(nikita.util.exceptions.NikitaException) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) CorrespondencePartType(nikita.model.noark5.v4.metadata.CorrespondencePartType) 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