Search in sources :

Example 11 with BasicRecord

use of nikita.model.noark5.v4.BasicRecord 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
@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.findBySystemId(systemID);
    NoarkEntity parentEntity = basicRecord.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 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);
}
Also used : NikitaException(nikita.common.util.exceptions.NikitaException) Authorisation(nikita.webapp.security.Authorisation) Class(nikita.common.model.noark5.v4.Class) AfterNoarkEntityDeletedEvent(nikita.webapp.web.events.AfterNoarkEntityDeletedEvent) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with BasicRecord

use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordHateoasController method findAllBasicRecord.

@ApiOperation(value = "Retrieves multiple BasicRecord entities limited by ownership rights", notes = "The field skip" + "tells how many BasicRecord 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 = BasicRecordHateoas.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "BasicRecord list found", response = BasicRecordHateoas.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<BasicRecordHateoas> findAllBasicRecord(final UriComponentsBuilder uriBuilder, HttpServletRequest request, final HttpServletResponse response, @RequestParam(name = "top", required = false) Integer top, @RequestParam(name = "skip", required = false) Integer skip) {
    BasicRecordHateoas basicRecordHateoas = new BasicRecordHateoas((List<INikitaEntity>) (List) basicRecordService.findBasicRecordByOwnerPaginated(top, skip));
    basicRecordHateoasHandler.addLinks(basicRecordHateoas, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(basicRecordHateoas);
}
Also used : INikitaEntity(nikita.common.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(nikita.webapp.security.Authorisation) List(java.util.List) Counted(com.codahale.metrics.annotation.Counted) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 13 with BasicRecord

use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordService method handleUpdate.

// All UPDATE operations
@Override
public BasicRecord handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull BasicRecord incomingBasicRecord) {
    BasicRecord existingBasicRecord = getBasicRecordOrThrow(systemId);
    // Here copy all the values you are allowed to copy ....
    if (null != incomingBasicRecord.getDescription()) {
        existingBasicRecord.setDescription(incomingBasicRecord.getDescription());
    }
    if (null != incomingBasicRecord.getTitle()) {
        existingBasicRecord.setTitle(incomingBasicRecord.getTitle());
    }
    if (null != incomingBasicRecord.getDocumentMedium()) {
        existingBasicRecord.setDocumentMedium(existingBasicRecord.getDocumentMedium());
    }
    existingBasicRecord.setVersion(version);
    basicRecordRepository.save(existingBasicRecord);
    return existingBasicRecord;
}
Also used : BasicRecord(nikita.common.model.noark5.v4.BasicRecord)

Example 14 with BasicRecord

use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordService method getBasicRecordOrThrow.

// 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 BasicRecord back. If there is no valid
 * BasicRecord, an exception is thrown
 *
 * @param basicRecordSystemId
 * @return
 */
protected BasicRecord getBasicRecordOrThrow(@NotNull String basicRecordSystemId) {
    BasicRecord basicRecord = basicRecordRepository.findBySystemId(basicRecordSystemId);
    if (basicRecord == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " BasicRecord, using systemId " + basicRecordSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    }
    return basicRecord;
}
Also used : BasicRecord(nikita.common.model.noark5.v4.BasicRecord) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException)

Example 15 with BasicRecord

use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.

the class BasicRecordService method findBasicRecordByOwnerPaginated.

// All READ operations
@Override
public List<BasicRecord> findBasicRecordByOwnerPaginated(Integer top, Integer skip) {
    if (top == null || top > maxPageSize) {
        top = maxPageSize;
    }
    if (skip == null) {
        skip = 0;
    }
    String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BasicRecord> criteriaQuery = criteriaBuilder.createQuery(BasicRecord.class);
    Root<BasicRecord> from = criteriaQuery.from(BasicRecord.class);
    CriteriaQuery<BasicRecord> select = criteriaQuery.select(from);
    criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
    TypedQuery<BasicRecord> typedQuery = entityManager.createQuery(select);
    typedQuery.setFirstResult(skip);
    typedQuery.setMaxResults(top);
    return typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) BasicRecord(nikita.common.model.noark5.v4.BasicRecord)

Aggregations

BasicRecord (nikita.model.noark5.v4.BasicRecord)8 BasicRecord (nikita.common.model.noark5.v4.BasicRecord)7 Counted (com.codahale.metrics.annotation.Counted)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ApiOperation (io.swagger.annotations.ApiOperation)4 ApiResponses (io.swagger.annotations.ApiResponses)4 NoarkEntityNotFoundException (nikita.util.exceptions.NoarkEntityNotFoundException)3 Timed (com.codahale.metrics.annotation.Timed)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 NikitaMalformedInputDataException (nikita.common.util.exceptions.NikitaMalformedInputDataException)2 NoarkEntityNotFoundException (nikita.common.util.exceptions.NoarkEntityNotFoundException)2 File (nikita.model.noark5.v4.File)2 NikitaMalformedInputDataException (nikita.util.exceptions.NikitaMalformedInputDataException)2 Authorisation (nikita.webapp.security.Authorisation)2 Authorisation (no.arkivlab.hioa.nikita.webapp.security.Authorisation)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1