Search in sources :

Example 31 with CaseFile

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

the class CaseFileService method getCaseFileOrThrow.

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

Example 32 with CaseFile

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

the class CaseFileService method findCaseFileByOwnerPaginated.

// All READ operations
@Override
public List<CaseFile> findCaseFileByOwnerPaginated(Integer top, Integer skip) {
    if (top == null || top > maxPageSize) {
        top = maxPageSize;
    }
    if (skip == null) {
        skip = 0;
    }
    String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<CaseFile> criteriaQuery = criteriaBuilder.createQuery(CaseFile.class);
    Root<CaseFile> from = criteriaQuery.from(CaseFile.class);
    CriteriaQuery<CaseFile> select = criteriaQuery.select(from);
    criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
    TypedQuery<CaseFile> typedQuery = entityManager.createQuery(select);
    typedQuery.setFirstResult(skip);
    typedQuery.setMaxResults(top);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile)

Example 33 with CaseFile

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

the class SeriesService method createCaseFileAssociatedWithSeries.

// All CREATE operations
@Override
public CaseFile createCaseFileAssociatedWithSeries(String seriesSystemId, CaseFile caseFile) {
    CaseFile persistedFile = null;
    Series series = seriesRepository.findBySystemId(seriesSystemId);
    if (series == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " Series, using seriesSystemId " + seriesSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else if (series.getSeriesStatus() != null && series.getSeriesStatus().equals(STATUS_CLOSED)) {
        String info = INFO_CANNOT_ASSOCIATE_WITH_CLOSED_OBJECT + ". Series with seriesSystemId " + seriesSystemId + "has status " + STATUS_CLOSED;
        logger.info(info);
        throw new NoarkEntityEditWhenClosedException(info);
    } else {
        caseFile.setReferenceSeries(series);
        persistedFile = caseFileService.save(caseFile);
    }
    return persistedFile;
}
Also used : Series(nikita.common.model.noark5.v4.Series) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) NoarkEntityEditWhenClosedException(nikita.common.util.exceptions.NoarkEntityEditWhenClosedException)

Example 34 with CaseFile

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

the class SeriesHateoasController method createCaseFileAssociatedWithSeries.

// Create a new casefile
// POST [contextPath][api]/arkivstruktur/arkivdel/{systemId}/ny-saksmappe/
// This currently is not supported in the standard, but probably will be later
@ApiOperation(value = "Persists a CaseFile object associated with the given Series systemId", notes = "Returns " + "the newly created caseFile object after it was associated with a Series object and persisted to " + "the database", response = CaseFileHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = CaseFileHateoas.class), @ApiResponse(code = 201, message = "File " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = CaseFileHateoas.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 CaseFile"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_CASE_FILE, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<CaseFileHateoas> createCaseFileAssociatedWithSeries(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of series to associate the caseFile with", required = true) @PathVariable String systemID, @ApiParam(name = "caseFile", value = "Incoming caseFile object", required = true) @RequestBody CaseFile caseFile) throws NikitaException {
    validateForCreate(caseFile);
    CaseFile createdCaseFile = seriesService.createCaseFileAssociatedWithSeries(systemID, caseFile);
    CaseFileHateoas caseFileHateoas = new CaseFileHateoas(createdCaseFile);
    caseFileHateoasHandler.addLinks(caseFileHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdCaseFile));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdCaseFile.getVersion().toString()).body(caseFileHateoas);
}
Also used : CaseFileHateoas(nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas) AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile) Authorisation(nikita.webapp.security.Authorisation) Counted(com.codahale.metrics.annotation.Counted)

Example 35 with CaseFile

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

the class SeriesHateoasController method createFileAssociatedWithSeries.

// API - All POST Requests (CRUD - CREATE)
// Create a new file
// POST [contextPath][api]/arkivstruktur/arkivdel/ny-mappe/
@ApiOperation(value = "Persists a File object associated with the given Series systemId", notes = "Returns the " + "newly created file object after it was associated with a Series object and persisted to the database", response = FileHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "File " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = FileHateoas.class), @ApiResponse(code = 201, message = "File " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = FileHateoas.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 File"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_FILE, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FileHateoas> createFileAssociatedWithSeries(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of series to associate the caseFile with", required = true) @PathVariable String systemID, @ApiParam(name = "File", value = "Incoming file object", required = true) @RequestBody File file) throws NikitaException {
    validateForCreate(file);
    File createdFile = seriesService.createFileAssociatedWithSeries(systemID, file);
    FileHateoas fileHateoas = new FileHateoas(createdFile);
    fileHateoasHandler.addLinks(fileHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, createdFile));
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(createdFile.getVersion().toString()).body(fileHateoas);
}
Also used : AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(nikita.webapp.security.Authorisation) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile) CaseFileHateoas(nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas) Counted(com.codahale.metrics.annotation.Counted)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)18 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)17 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)15 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Timed (com.codahale.metrics.annotation.Timed)9 Authorisation (nikita.webapp.security.Authorisation)9 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)9 CaseFileHateoas (nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)7 CaseFileHateoas (nikita.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)7 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)6 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)4 Series (nikita.model.noark5.v4.Series)4 List (java.util.List)3 Series (nikita.common.model.noark5.v4.Series)3 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2