use of nikita.common.model.noark5.v4.Fonds in project nikita-noark5-core by HiOA-ABI.
the class FondsImportController method createFondsAssociatedWithFonds.
// TODO: Doublecheck this logic
@ApiOperation(value = "Persists a child Fonds object", notes = "Returns the newly" + " created child Fonds object after it is persisted to the database", response = FondsHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Fonds " + API_MESSAGE_OBJECT_ALREADY_PERSISTED, response = FondsHateoas.class), @ApiResponse(code = 201, message = "Fonds " + API_MESSAGE_OBJECT_SUCCESSFULLY_CREATED, response = FondsHateoas.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 Fonds"), @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
@Timed
@RequestMapping(method = RequestMethod.POST, value = FONDS + SLASH + LEFT_PARENTHESIS + "fondsSystemId" + RIGHT_PARENTHESIS + SLASH + NEW_FONDS)
public ResponseEntity<FondsHateoas> createFondsAssociatedWithFonds(@ApiParam(name = "parentFondsSystemId", value = "systemId of parent fonds to associate the fonds with.", required = true) @PathVariable String parentFondsSystemId, @ApiParam(name = "fonds", value = "Incoming fonds object", required = true) @RequestBody Fonds fonds) throws NikitaException {
Fonds createdFonds = fondsImportService.createFondsAssociatedWithFonds(parentFondsSystemId, fonds);
FondsHateoas fondsHateoas = new FondsHateoas(createdFonds);
return new ResponseEntity<>(fondsHateoas, HttpStatus.CREATED);
}
use of nikita.common.model.noark5.v4.Fonds in project nikita-noark5-core by HiOA-ABI.
the class ApplicationTests method createFondsObject.
/**
* Test ability to create a correct fonds object with required administration. Expected return value
* is 200 OK and the original Fonds object
*/
@Test
@WithMockUser(username = "admin", roles = { "USER", "ADMIN" })
public void createFondsObject() throws Exception {
String fondsTitle = "Test fonds title ";
String fondsDescription = "Test fonds description. This fonds should be automatically deleted after tests are undertaken";
Fonds fonds = new Fonds();
fonds.setTitle(fondsTitle);
fonds.setDescription(fondsDescription);
fonds.setDocumentMedium(DOCUMENT_MEDIUM_ELECTRONIC);
mockMvc.perform(post("/" + HATEOAS_API_PATH + "/" + FONDS).contentType(MediaType.APPLICATION_JSON_VALUE).content(objectMapper.writeValueAsString(fonds))).andExpect(status().isOk());
}
use of nikita.common.model.noark5.v4.Fonds in project nikita-noark5-core by HiOA-ABI.
the class ApplicationTests method getFondsObject.
@Test
@WithMockUser(username = "admin", roles = { "USER", "ADMIN" })
public void getFondsObject() throws Exception {
String fondsTitle = "Test fonds title ";
String fondsDescription = "Test fonds description. This fonds should be automatically deleted after tests are undertaken";
Fonds fonds = new Fonds();
fonds.setTitle(fondsTitle);
fonds.setDescription(fondsDescription);
fonds.setDocumentMedium(DOCUMENT_MEDIUM_ELECTRONIC);
ResultActions result = mockMvc.perform(get("/" + HATEOAS_API_PATH + "/" + FONDS + "/1")).andExpect(status().isOk()).andDo(print()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$.title").value(fondsTitle));
}
use of nikita.common.model.noark5.v4.Fonds in project nikita-noark5-core by HiOA-ABI.
the class DocumentDescriptionHateoasController method deleteDocumentDescriptionBySystemId.
// Delete a DocumentDescription identified by systemID
// DELETE [contextPath][api]/arkivstruktur/dokumentobjekt/{systemId}/
@ApiOperation(value = "Deletes a single DocumentDescription entity identified by systemID", response = RecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "Parent Fonds returned", response = RecordHateoas.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<RecordHateoas> deleteDocumentDescriptionBySystemId(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @ApiParam(name = "systemID", value = "systemID of the documentDescription to delete", required = true) @PathVariable("systemID") final String systemID) {
DocumentDescription documentDescription = documentDescriptionService.findBySystemId(systemID);
List<Record> record = new ArrayList<>();
record.addAll(documentDescription.getReferenceRecord());
documentDescriptionService.deleteEntity(systemID);
RecordHateoas recordHateoas = new RecordHateoas((List) record);
/*RecordHateoas recordHateoas = new RecordHateoas(
(List<INikitaEntity>)
(List)record); */
// RecordHateoas recordHateoas = new RecordHateoas(
// (List<INikitaEntity>) (List)record);
recordHateoasHandler.addLinks(recordHateoas, new Authorisation());
applicationEventPublisher.publishEvent(new AfterNoarkEntityDeletedEvent(this, documentDescription));
return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(recordHateoas);
}
use of nikita.common.model.noark5.v4.Fonds in project nikita-noark5-core by HiOA-ABI.
the class FondsService method deleteEntity.
// All DELETE operations
/**
* Deletes a Fonds object 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. Note that as there is a @ManyToMany relationship between
* Fonds and FondsCreator with a join table, we first have to
* disassociate the link between Fonds and FondsCreator or we hit a
* foreign key constraint issue. The same applies for Fonds and
* StorageLocation.
* <p>
* In order to minimise problems that could be caused with table and
* column names changing, constants are used to define relevant column
* and table names.
* <p>
* The approach is is discussed in a nikita github issue
* https://github.com/HiOA-ABI/nikita-noark5-core/issues/82
*
* @param fondsSystemId The systemId of the fonds object to retrieve
*/
@Override
public void deleteEntity(@NotNull String fondsSystemId) {
Fonds fonds = getFondsOrThrow(fondsSystemId);
// Disassociate any links between Fonds and FondsCreator
Query q = entityManager.createNativeQuery("DELETE FROM " + TABLE_FONDS_FONDS_CREATOR + " WHERE " + FOREIGN_KEY_FONDS_PK + " = :id ;");
q.setParameter("id", fonds.getId());
q.executeUpdate();
// Disassociate any links between Fonds and StorageLocation
q = entityManager.createNativeQuery("DELETE FROM " + TABLE_STORAGE_LOCATION + " WHERE " + FOREIGN_KEY_FONDS_PK + " = :id ;");
q.setParameter("id", fonds.getId());
q.executeUpdate();
// Next get hibernate to delete the Fonds object
entityManager.remove(fonds);
entityManager.flush();
entityManager.clear();
}
Aggregations