use of nikita.common.model.noark5.v4.hateoas.SeriesHateoas 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.common.model.noark5.v4.hateoas.SeriesHateoas 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.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 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\"}");
}
use of nikita.common.model.noark5.v4.hateoas.SeriesHateoas in project nikita-noark5-core by HiOA-ABI.
the class SeriesHateoasController method findAllSeries.
// Retrieve all Series (paginated)
// GET [contextPath][api]/arkivstruktur/arkivdel/{systemId}/klassifikasjonssystem/
@ApiOperation(value = "Retrieves multiple Series entities limited by ownership rights", notes = "The field skip" + "tells how many Series rows of the result set to ignore (starting at 0), while top tells how many rows" + " after skip to return. Note if the value of top is greater than system value " + " nikita-noark5-core.pagination.maxPageSize, then nikita-noark5-core.pagination.maxPageSize is used. ", response = SeriesHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Series list found", response = SeriesHateoas.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(method = RequestMethod.GET)
public ResponseEntity<SeriesHateoas> findAllSeries(HttpServletRequest request, @RequestParam(name = "top", required = false) Integer top, @RequestParam(name = "skip", required = false) Integer skip) {
String ownedBy = SecurityContextHolder.getContext().getAuthentication().getName();
SeriesHateoas seriesHateoas = new SeriesHateoas((List<INikitaEntity>) (List) seriesService.findByOwnedBy(ownedBy));
seriesHateoasHandler.addLinksOnRead(seriesHateoas, new Authorisation());
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(seriesHateoas);
}
Aggregations