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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations