Search in sources :

Example 51 with Series

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

the class SeriesService method createFileAssociatedWithSeries.

@Override
public File createFileAssociatedWithSeries(String seriesSystemId, File file) {
    File 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 {
        file.setReferenceSeries(series);
        persistedFile = fileService.createFile(file);
    }
    return persistedFile;
}
Also used : Series(nikita.common.model.noark5.v4.Series) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) File(nikita.common.model.noark5.v4.File) CaseFile(nikita.common.model.noark5.v4.casehandling.CaseFile) NoarkEntityEditWhenClosedException(nikita.common.util.exceptions.NoarkEntityEditWhenClosedException)

Example 52 with Series

use of nikita.model.noark5.v4.Series 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 53 with Series

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

the class SeriesHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject seriesHateoas, JsonGenerator jgen) throws IOException {
    Series series = (Series) noarkSystemIdEntity;
    jgen.writeStartObject();
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, series);
    CommonUtils.Hateoas.Serialize.printTitleAndDescription(jgen, series);
    if (series.getSeriesStatus() != null) {
        jgen.writeStringField(SERIES_STATUS, series.getSeriesStatus());
    }
    CommonUtils.Hateoas.Serialize.printDocumentMedium(jgen, series);
    CommonUtils.Hateoas.Serialize.printStorageLocation(jgen, series);
    CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, series);
    CommonUtils.Hateoas.Serialize.printFinaliseEntity(jgen, series);
    if (series.getSeriesStartDate() != null) {
        jgen.writeStringField(SERIES_START_DATE, Serialize.formatDate(series.getSeriesStartDate()));
    }
    if (series.getSeriesEndDate() != null) {
        jgen.writeStringField(SERIES_END_DATE, Serialize.formatDate(series.getSeriesEndDate()));
    }
    if (series.getReferencePrecursor() != null && series.getReferencePrecursor().getSystemId() != null) {
        jgen.writeStringField(SERIES_PRECURSOR, series.getReferencePrecursor().getSystemId());
    }
    if (series.getReferenceSuccessor() != null && series.getReferenceSuccessor().getSystemId() != null) {
        jgen.writeStringField(SERIES_SUCCESSOR, series.getReferenceSuccessor().getSystemId());
    }
    CommonUtils.Hateoas.Serialize.printDisposal(jgen, series);
    CommonUtils.Hateoas.Serialize.printDisposalUndertaken(jgen, series);
    CommonUtils.Hateoas.Serialize.printDeletion(jgen, series);
    CommonUtils.Hateoas.Serialize.printScreening(jgen, series);
    CommonUtils.Hateoas.Serialize.printClassified(jgen, series);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, seriesHateoas.getLinks(series));
    jgen.writeEndObject();
}
Also used : Series(nikita.common.model.noark5.v4.Series)

Example 54 with Series

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

the class FondsHateoasController method createFondsCreatorAssociatedWithFonds.

// Create a FondsCreator and associate it with the Fonds identified by systemId
// API - All GET Requests (CRUD - READ)
// POST [contextPath][api]/arkivstruktur/arkiv/{systemId}/ny-arkivskaper
@ApiOperation(value = "Persists a FondsCreator associated with the given Fonds " + "systemId", notes = "Returns the newly created FondsCreator after it was " + "associated with a Fonds and persisted to the database", response = FondsCreatorHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "FondsCreator " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = FondsCreatorHateoas.class), @ApiResponse(code = 201, message = "FondsCreator " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = FondsCreatorHateoas.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 " + "FondsCreator"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = FONDS + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_FONDS_CREATOR, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<FondsCreatorHateoas> createFondsCreatorAssociatedWithFonds(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of fonds to associate the series with.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "fondsCreator", value = "Incoming fondsCreator object", required = true) @RequestBody FondsCreator fondsCreator) throws NikitaException {
    validateForCreate(fondsCreator);
    FondsCreatorHateoas fondsCreatorHateoas = fondsService.createFondsCreatorAssociatedWithFonds(systemID, fondsCreator);
    return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(fondsCreatorHateoas.getEntityVersion().toString()).body(fondsCreatorHateoas);
}
Also used : FondsCreatorHateoas(nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 55 with Series

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

the class RecordHateoasController 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
@RequestMapping(value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, method = RequestMethod.DELETE)
public ResponseEntity<String> 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) {
    Record record = recordService.findBySystemId(systemID);
    /*  NoarkEntity parentEntity = record.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 nikita.webapp.util.exceptions.NikitaException("Internal error. Could not process"
                    + request.getRequestURI());
        } */
    recordService.deleteEntity(systemID);
    applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, record));
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body("{\"status\": \"deleted\"}");
}
Also used : 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)

Aggregations

Counted (com.codahale.metrics.annotation.Counted)29 Series (nikita.model.noark5.v4.Series)20 ApiOperation (io.swagger.annotations.ApiOperation)18 ApiResponses (io.swagger.annotations.ApiResponses)18 Timed (com.codahale.metrics.annotation.Timed)16 Authorisation (nikita.webapp.security.Authorisation)13 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)13 Series (nikita.common.model.noark5.v4.Series)11 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)11 CaseFile (nikita.model.noark5.v4.casehandling.CaseFile)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 CaseFile (nikita.common.model.noark5.v4.casehandling.CaseFile)6 Fonds (nikita.model.noark5.v4.Fonds)6 NoarkEntityEditWhenClosedException (nikita.util.exceptions.NoarkEntityEditWhenClosedException)6 List (java.util.List)5 SeriesHateoas (nikita.common.model.noark5.v4.hateoas.SeriesHateoas)5 CaseFileHateoas (nikita.common.model.noark5.v4.hateoas.casehandling.CaseFileHateoas)5 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)5 SeriesHateoas (nikita.model.noark5.v4.hateoas.SeriesHateoas)5