use of nikita.common.model.noark5.v4.hateoas.SeriesHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsHateoasController method findSeriesAssociatedWithFonds.
// Get all Series associated with Fonds identified by systemId
// GET [contextPath][api]/arkivstruktur/arkiv/{systemId}/arkivdel/
@ApiOperation(value = "Retrieves the Series associated with a Fonds identified by a systemId", response = Series.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Series returned", response = Series.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(value = FONDS + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + SERIES + SLASH, method = RequestMethod.GET)
public ResponseEntity<SeriesHateoas> findSeriesAssociatedWithFonds(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of Fonds that has Series associated with it.", required = true) @PathVariable("systemID") final String systemID) {
Fonds fonds = fondsService.findBySystemIdOrderBySystemId(systemID);
if (fonds == null) {
throw new NoarkEntityNotFoundException("Could not find series object with systemID " + systemID);
}
SeriesHateoas seriesHateoas = new SeriesHateoas(new ArrayList<>(fonds.getReferenceSeries()));
seriesHateoasHandler.addLinks(seriesHateoas, request, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(seriesHateoas);
}
use of nikita.common.model.noark5.v4.hateoas.SeriesHateoas 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();
}
use of nikita.common.model.noark5.v4.hateoas.SeriesHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsService method generateDefaultSeries.
/**
* Generate a Default Fonds object that can be associated with the
* identified Fonds.
* <br>
* Note. Ideally this method would be configurable based on the logged in
* user and the business area they are working with. A generic Noark core
* like this does not have scope for that kind of functionality.
*
* @param fondsSystemId The systemId of the Fonds object you wish to
* generate a default Series for
* @return the Series object wrapped as a SeriesHateoas object
*/
@Override
public SeriesHateoas generateDefaultSeries(@NotNull String fondsSystemId) {
Series defaultSeries = new Series();
defaultSeries.setSeriesStatus(STATUS_OPEN);
defaultSeries.setDocumentMedium(DOCUMENT_MEDIUM_ELECTRONIC);
defaultSeries.setTitle("Default Series object generated by nikita " + "that can be associated with Fonds with systemID " + fondsSystemId);
SeriesHateoas seriesHateoas = new SeriesHateoas(defaultSeries);
seriesHateoasHandler.addLinksOnNew(seriesHateoas, new Authorisation());
return seriesHateoas;
}
use of nikita.common.model.noark5.v4.hateoas.SeriesHateoas in project nikita-noark5-core by HiOA-ABI.
the class FileHateoasController method deleteFileBySystemId.
// Delete a File identified by systemID
// DELETE [contextPath][api]/arkivstruktur/mappe/{systemId}/
@ApiOperation(value = "Deletes a single File entity identified by systemID", response = HateoasNoarkObject.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent entity (DocumentDescription or File) 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> deleteFileBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the file to delete", required = true) @PathVariable("systemID") final String systemID) {
File file = fileService.findBySystemId(systemID);
NoarkEntity parentEntity = file.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());
}
fileService.deleteEntity(systemID);
applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, file));
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(hateoasNoarkObject);
}
use of nikita.common.model.noark5.v4.hateoas.SeriesHateoas in project nikita-noark5-core by HiOA-ABI.
the class FondsHateoasController method createSeriesAssociatedWithFonds.
// Create a Series and associate it with the Fonds identified by systemId
// POST [contextPath][api]/arkivstruktur/arkiv/{systemId}/ny-arkivdel
@ApiOperation(value = "Persists a Series object associated with the given Fonds" + " systemId", notes = "Returns the newly created Series object after it was " + "associated with a Fonds object and persisted to the " + "database", response = SeriesHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Series " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = SeriesHateoas.class), @ApiResponse(code = 201, message = "Series" + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = SeriesHateoas.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 " + "Series"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR), @ApiResponse(code = 501, message = API_MESSAGE_NOT_IMPLEMENTED) })
@Counted
@RequestMapping(method = RequestMethod.POST, value = FONDS + SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS + SLASH + NEW_SERIES, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<SeriesHateoas> createSeriesAssociatedWithFonds(HttpServletRequest request, @ApiParam(name = "systemID", value = "systemId of fonds to associate the series with.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "series", value = "Incoming series object", required = true) @RequestBody Series series) throws NikitaException {
validateForCreate(series);
SeriesHateoas seriesHateoas = fondsService.createSeriesAssociatedWithFonds(systemID, series);
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(seriesHateoas.getEntityVersion().toString()).body(seriesHateoas);
}
Aggregations