Search in sources :

Example 56 with Fonds

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) FondsHateoas(nikita.model.noark5.v4.hateoas.FondsHateoas) Fonds(nikita.model.noark5.v4.Fonds) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 57 with Fonds

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());
}
Also used : Fonds(nikita.model.noark5.v4.Fonds) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 58 with Fonds

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));
}
Also used : Fonds(nikita.model.noark5.v4.Fonds) ResultActions(org.springframework.test.web.servlet.ResultActions) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 59 with Fonds

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);
}
Also used : DocumentDescription(nikita.common.model.noark5.v4.DocumentDescription) Authorisation(nikita.webapp.security.Authorisation) ArrayList(java.util.ArrayList) RecordHateoas(nikita.common.model.noark5.v4.hateoas.RecordHateoas) Record(nikita.common.model.noark5.v4.Record) AfterNoarkEntityDeletedEvent(nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 60 with Fonds

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();
}
Also used : TypedQuery(javax.persistence.TypedQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) Fonds(nikita.common.model.noark5.v4.Fonds)

Aggregations

Fonds (nikita.model.noark5.v4.Fonds)28 Counted (com.codahale.metrics.annotation.Counted)27 ApiOperation (io.swagger.annotations.ApiOperation)27 ApiResponses (io.swagger.annotations.ApiResponses)27 Timed (com.codahale.metrics.annotation.Timed)18 Fonds (nikita.common.model.noark5.v4.Fonds)15 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)14 Authorisation (nikita.webapp.security.Authorisation)13 FondsHateoas (nikita.model.noark5.v4.hateoas.FondsHateoas)10 FondsHateoas (nikita.common.model.noark5.v4.hateoas.FondsHateoas)9 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)8 ArrayList (java.util.ArrayList)5 Series (nikita.model.noark5.v4.Series)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 List (java.util.List)4 FondsCreatorHateoas (nikita.common.model.noark5.v4.hateoas.FondsCreatorHateoas)4 SeriesHateoas (nikita.common.model.noark5.v4.hateoas.SeriesHateoas)4 INikitaEntity (nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity)4 FondsCreator (nikita.common.model.noark5.v4.FondsCreator)3