use of nikita.common.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionHateoasController method updateDocumentDescription.
// API - All PUT Requests (CRUD - UPDATE)
// Update a DocumentDescription
// PUT [contextPath][api]/arkivstruktur/dokumentobjekt/{systemID}
@ApiOperation(value = "Updates a DocumentDescription object", notes = "Returns the newly" + " update DocumentDescription object after it is persisted to the database", response = DocumentDescriptionHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "DocumentDescription " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = DocumentDescriptionHateoas.class), @ApiResponse(code = 201, message = "DocumentDescription " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = DocumentDescriptionHateoas.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 DocumentDescription"), @ApiResponse(code = 409, message = API_MESSAGE_CONFLICT), @ApiResponse(code = 500, message = API_MESSAGE_INTERNAL_SERVER_ERROR) })
@Counted
@RequestMapping(method = RequestMethod.PUT, value = SLASH + LEFT_PARENTHESIS + SYSTEM_ID + RIGHT_PARENTHESIS, consumes = { NOARK5_V4_CONTENT_TYPE_JSON })
public ResponseEntity<DocumentDescriptionHateoas> updateDocumentDescription(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemId of documentDescription to update.", required = true) @PathVariable("systemID") String systemID, @ApiParam(name = "documentDescription", value = "Incoming documentDescription object", required = true) @RequestBody DocumentDescription documentDescription) throws NikitaException {
validateForUpdate(documentDescription);
DocumentDescription updatedDocumentDescription = documentDescriptionService.handleUpdate(systemID, parseETAG(request.getHeader(ETAG)), documentDescription);
DocumentDescriptionHateoas documentDescriptionHateoas = new DocumentDescriptionHateoas(updatedDocumentDescription);
documentDescriptionHateoasHandler.addLinks(documentDescriptionHateoas, new Authorisation());
applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, updatedDocumentDescription));
return ResponseEntity.status(HttpStatus.CREATED).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).eTag(updatedDocumentDescription.getVersion().toString()).body(documentDescriptionHateoas);
}
use of nikita.common.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionService method getDocumentDescriptionOrThrow.
// All HELPER operations
/**
* 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 DocumentDescription back. If there is no valid
* DocumentDescription, an exception is thrown
*
* @param documentDescriptionSystemId
* @return
*/
protected DocumentDescription getDocumentDescriptionOrThrow(@NotNull String documentDescriptionSystemId) {
DocumentDescription documentDescription = documentDescriptionRepository.findBySystemId(documentDescriptionSystemId);
if (documentDescription == null) {
String info = INFO_CANNOT_FIND_OBJECT + " DocumentDescription, using systemId " + documentDescriptionSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
}
return documentDescription;
}
use of nikita.common.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionService method deleteEntity.
// All DELETE operations
@Override
public void deleteEntity(@NotNull String documentDescriptionSystemId) {
// See issue for a description of why this code was written this way
// https://github.com/HiOA-ABI/nikita-noark5-core/issues/82
DocumentDescription documentDescription = getDocumentDescriptionOrThrow(documentDescriptionSystemId);
Query q = entityManager.createNativeQuery("DELETE FROM record_document_description WHERE F_PK_DOCUMENT_DESCRIPTION_ID = :id ;");
q.setParameter("id", documentDescription.getId());
q.executeUpdate();
entityManager.remove(documentDescription);
entityManager.flush();
entityManager.clear();
}
use of nikita.common.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionService method createDocumentObjectAssociatedWithDocumentDescription.
// All CREATE operations
@Override
public DocumentObject createDocumentObjectAssociatedWithDocumentDescription(String documentDescriptionSystemId, DocumentObject documentObject) {
DocumentObject persistedDocumentObject = null;
DocumentDescription documentDescription = documentDescriptionRepository.findBySystemId(documentDescriptionSystemId);
if (documentDescription == null) {
String info = INFO_CANNOT_FIND_OBJECT + " DocumentDescription, using documentDescriptionSystemId " + documentDescriptionSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
} else {
documentObject.setReferenceDocumentDescription(documentDescription);
List<DocumentObject> documentObjects = documentDescription.getReferenceDocumentObject();
documentObjects.add(documentObject);
persistedDocumentObject = documentObjectService.save(documentObject);
}
return persistedDocumentObject;
}
use of nikita.common.model.noark5.v4.DocumentDescription in project nikita-noark5-core by HiOA-ABI.
the class RegistryEntryService method createDocumentDescriptionAssociatedWithRegistryEntry.
/*
TODO: Temp disabled!
private void associateCorrespondencePartTypeWithCorrespondencePart(@NotNull CorrespondencePart correspondencePart) {
CorrespondencePartType incomingCorrespondencePartType = correspondencePart.getCorrespondencePartType();
// It should never get this far with a null value
// It should be rejected at controller level
// The incoming CorrespondencePartType will not have @id field set. Therefore, we have to look it up
// in the database and make sure the proper CorrespondencePartType is associated with the CorrespondencePart
if (incomingCorrespondencePartType != null && incomingCorrespondencePartType.getCode() != null) {
CorrespondencePartType actualCorrespondencePartType =
correspondencePartTypeRepository.findByCode(incomingCorrespondencePartType.getCode());
if (actualCorrespondencePartType != null) {
correspondencePart.setCorrespondencePartType(actualCorrespondencePartType);
}
}
}
TODO: Temp disabled!
@Override
public List<CorrespondencePartPerson> getCorrespondencePartPersonAssociatedWithRegistryEntry(String systemID) {
RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
return registryEntry.getReferenceCorrespondencePartPerson();
}
@Override
public List<CorrespondencePartInternal> getCorrespondencePartInternalAssociatedWithRegistryEntry(String systemID) {
RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
return registryEntry.getReferenceCorrespondencePartInternal();
}
@Override
public List<CorrespondencePartUnit> getCorrespondencePartUnitAssociatedWithRegistryEntry(String systemID) {
RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
return registryEntry.getReferenceCorrespondencePartUnit();
}
*/
/* @Override
public CorrespondencePartPerson createCorrespondencePartPersonAssociatedWithRegistryEntry(
String systemID, CorrespondencePartPerson correspondencePart) {
RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
TODO: Temp disabled!
associateCorrespondencePartTypeWithCorrespondencePart(correspondencePart);
ContactInformation contactInformation = correspondencePart.getContactInformation();
if (null != contactInformation) {
NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(contactInformation);
NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(contactInformation);
}
SimpleAddress postalAddress = correspondencePart.getPostalAddress();
if (null != postalAddress) {
NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(postalAddress);
NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(postalAddress);
}
SimpleAddress residingAddress = correspondencePart.getResidingAddress();
if (null != residingAddress) {
NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(residingAddress);
NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(residingAddress);
}
NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(correspondencePart);
NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(correspondencePart);
// bidirectional relationship @ManyToMany, set both sides of relationship
registryEntry.getReferenceCorrespondencePartPerson().add(correspondencePart);
correspondencePart.getReferenceRegistryEntry().add(registryEntry);
return correspondencePartService.createNewCorrespondencePartPerson(correspondencePart);
return null;
}
*/
/*
TODO: Temp disabled!
@Override
public CorrespondencePartInternal createCorrespondencePartInternalAssociatedWithRegistryEntry(
String systemID, CorrespondencePartInternal correspondencePart) {
RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(correspondencePart);
NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(correspondencePart);
// bidirectional relationship @ManyToMany, set both sides of relationship
registryEntry.getReferenceCorrespondencePartInternal().add(correspondencePart);
correspondencePart.getReferenceRegistryEntry().add(registryEntry);
return correspondencePartService.createNewCorrespondencePartInternal(correspondencePart);
}
@Override
public CorrespondencePartUnit createCorrespondencePartUnitAssociatedWithRegistryEntry(
String systemID, CorrespondencePartUnit correspondencePart) {
RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
associateCorrespondencePartTypeWithCorrespondencePart(correspondencePart);
ContactInformation contactInformation = correspondencePart.getContactInformation();
if (null != contactInformation) {
NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(contactInformation);
NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(contactInformation);
}
SimpleAddress postalAddress = correspondencePart.getPostalAddress();
if (null != postalAddress) {
NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(postalAddress);
NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(postalAddress);
}
SimpleAddress businessAddress = correspondencePart.getBusinessAddress();
if (null != businessAddress) {
NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(businessAddress);
NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(businessAddress);
}
NoarkUtils.NoarkEntity.Create.setNikitaEntityValues(correspondencePart);
NoarkUtils.NoarkEntity.Create.setSystemIdEntityValues(correspondencePart);
// bidirectional relationship @ManyToMany, set both sides of relationship
registryEntry.getReferenceCorrespondencePartUnit().add(correspondencePart);
correspondencePart.getReferenceRegistryEntry().add(registryEntry);
return correspondencePartService.createNewCorrespondencePartUnit(correspondencePart);
}
*/
@Override
public DocumentDescription createDocumentDescriptionAssociatedWithRegistryEntry(String systemID, DocumentDescription documentDescription) {
RegistryEntry registryEntry = getRegistryEntryOrThrow(systemID);
ArrayList<Record> records = (ArrayList<Record>) documentDescription.getReferenceRecord();
// It should always be instaniated ... check this ...
if (records == null) {
records = new ArrayList<>();
documentDescription.setReferenceRecord(records);
}
records.add(registryEntry);
return documentDescriptionService.save(documentDescription);
}
Aggregations