use of nikita.util.exceptions.NikitaException in project nikita-noark5-core by HiOA-ABI.
the class MetadataHateoasSerializer method serializeNoarkEntity.
@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject metadataHateoas, JsonGenerator jgen) throws IOException {
if (!(noarkSystemIdEntity instanceof nikita.model.noark5.v4.interfaces.entities.IMetadataEntity)) {
throw new NikitaException("Internal error when serialising " + noarkSystemIdEntity + " Not castable to nikita.model.noark5.v4.interfaces.entities.IMetadataEntity");
}
IMetadataEntity metadataEntity = (IMetadataEntity) noarkSystemIdEntity;
jgen.writeStartObject();
CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, metadataEntity);
if (metadataEntity.getCode() != null) {
jgen.writeStringField(CODE, metadataEntity.getCode());
}
if (metadataEntity.getDescription() != null) {
jgen.writeStringField(DESCRIPTION, metadataEntity.getDescription());
}
CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, metadataHateoas.getLinks(metadataEntity));
jgen.writeEndObject();
}
use of nikita.util.exceptions.NikitaException in project nikita-noark5-core by HiOA-ABI.
the class FileImportService method createFile.
@Override
public File createFile(File file) {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
if (username == null) {
throw new NikitaException("Security context problem. username is null! Cannot continue with " + "this request!");
}
if (file.getCreatedDate() == null) {
file.setCreatedDate(new Date());
}
if (file.getCreatedBy() == null) {
file.setCreatedBy(username);
}
if (file.getOwnedBy() == null) {
file.setOwnedBy(username);
}
file.setDeleted(false);
return fileRepository.save(file);
}
use of nikita.util.exceptions.NikitaException in project nikita-noark5-core by HiOA-ABI.
the class RegistryEntryImportService method save.
@Override
public RegistryEntry save(RegistryEntry registryEntry) {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
if (username == null) {
throw new NikitaException("Security context problem. username is null! Cannot continue with " + "this request!");
}
if (registryEntry.getCreatedDate() == null) {
registryEntry.setCreatedDate(new Date());
}
if (registryEntry.getCreatedBy() == null) {
registryEntry.setCreatedBy(username);
}
if (registryEntry.getOwnedBy() == null) {
registryEntry.setOwnedBy(username);
}
registryEntry.setDeleted(false);
registryEntryRepository.save(registryEntry);
return registryEntry;
}
use of nikita.util.exceptions.NikitaException in project nikita-noark5-core by HiOA-ABI.
the class SeriesImportService method save.
public Series save(Series series) {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
if (username == null) {
throw new NikitaException("Security context problem. username is null! Cannot continue with " + "this request!");
}
if (series.getCreatedDate() == null) {
series.setCreatedDate(new Date());
}
if (series.getCreatedBy() == null) {
series.setCreatedBy(username);
}
if (series.getOwnedBy() == null) {
series.setOwnedBy(username);
}
series.setDeleted(false);
return seriesRepository.save(series);
}
use of nikita.util.exceptions.NikitaException 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
@Timed
@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.findBySystemIdOrderBySystemId(systemID);
NoarkEntity parentEntity = basicRecord.chooseParent();
HateoasNoarkObject hateoasNoarkObject;
if (parentEntity instanceof Series) {
hateoasNoarkObject = new SeriesHateoas(parentEntity);
seriesHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
} else if (parentEntity instanceof File) {
hateoasNoarkObject = new FileHateoas(parentEntity);
fileHateoasHandler.addLinks(hateoasNoarkObject, request, new Authorisation());
} else if (parentEntity instanceof Class) {
hateoasNoarkObject = new ClassHateoas(parentEntity);
classHateoasHandler.addLinks(hateoasNoarkObject, request, 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);
}
Aggregations