Search in sources :

Example 46 with Series

use of nikita.model.noark5.v4.Series 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
@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.findBySystemId(systemID);
    NoarkEntity parentEntity = basicRecord.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());
    }
    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.common.util.exceptions.NikitaException) Authorisation(nikita.webapp.security.Authorisation) 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 47 with Series

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

the class FondsService method createSeriesAssociatedWithFonds.

/**
 * Persists a new Series object to the database. Some values are set in
 * the incoming payload (e.g. title) and some are set by the core. owner,
 * createdBy, createdDate are automatically set by the core.
 * <p>
 * First we try to locate the fonds to associate the Series with. If the
 * fonds does not exist a NoarkEntityNotFoundException exception is
 * thrown. Then we check that the fonds does not have children fonds. If it
 * does an NoarkInvalidStructureException exception is thrown. After that
 * we check that the Fonds object is not already closed.
 *
 * @param fondsSystemId The systemId of the fonds object to associate a
 *                      Series with
 * @param series        The incoming Series object
 * @return the newly persisted series object wrapped as a SeriesHateoas
 * object
 */
@Override
public SeriesHateoas createSeriesAssociatedWithFonds(@NotNull String fondsSystemId, @NotNull Series series) {
    Fonds fonds = getFondsOrThrow(fondsSystemId);
    checkFondsNotClosed(fonds);
    checkFondsDoesNotContainSubFonds(fonds);
    series.setReferenceFonds(fonds);
    SeriesHateoas seriesHateoas = new SeriesHateoas(seriesService.save(series));
    seriesHateoasHandler.addLinks(seriesHateoas, new Authorisation());
    applicationEventPublisher.publishEvent(new AfterNoarkEntityCreatedEvent(this, fonds));
    return seriesHateoas;
}
Also used : AfterNoarkEntityCreatedEvent(nikita.webapp.web.events.AfterNoarkEntityCreatedEvent) Authorisation(nikita.webapp.security.Authorisation) SeriesHateoas(nikita.common.model.noark5.v4.hateoas.SeriesHateoas) Fonds(nikita.common.model.noark5.v4.Fonds)

Example 48 with Series

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

the class FondsService method findSeriesAssociatedWithFonds.

/**
 * Retrieve a list of Series objects associated with a given Fonds
 * from the database. First we try to locate the Fonds object. If the
 * Fonds object does not exist a NoarkEntityNotFoundException exception
 * is thrown that the caller has to deal with.
 * <p>
 * If any Series objects exist, they are wrapped in a SeriesHateoas
 * object and returned to the caller.
 *
 * @param fondsSystemId The systemId of the Fonds object that you want to
 *                      retrieve associated Series objects
 * @return the list of Series objects wrapped as a SeriesHateoas object
 */
@Override
public SeriesHateoas findSeriesAssociatedWithFonds(@NotNull String fondsSystemId) {
    Fonds fonds = getFondsOrThrow(fondsSystemId);
    SeriesHateoas seriesHateoas = new SeriesHateoas((List<INikitaEntity>) (List) fonds.getReferenceSeries());
    seriesHateoasHandler.addLinks(seriesHateoas, new Authorisation());
    return seriesHateoas;
}
Also used : INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) SeriesHateoas(nikita.common.model.noark5.v4.hateoas.SeriesHateoas) Fonds(nikita.common.model.noark5.v4.Fonds) List(java.util.List)

Example 49 with Series

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

the class SeriesService method handleUpdate.

// All UPDATE operations
@Override
public Series handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull Series incomingSeries) {
    Series existingSeries = getSeriesOrThrow(systemId);
    // Here copy all the values you are allowed to copy ....
    if (null != existingSeries.getDescription()) {
        existingSeries.setDescription(incomingSeries.getDescription());
    }
    if (null != incomingSeries.getTitle()) {
        existingSeries.setTitle(incomingSeries.getTitle());
    }
    if (null != incomingSeries.getDocumentMedium()) {
        existingSeries.setDocumentMedium(existingSeries.getDocumentMedium());
    }
    existingSeries.setVersion(version);
    seriesRepository.save(existingSeries);
    return existingSeries;
}
Also used : Series(nikita.common.model.noark5.v4.Series)

Example 50 with Series

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

the class SeriesService method getSeriesOrThrow.

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

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