Search in sources :

Example 1 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
@Timed
@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((ArrayList<INikitaEntity>) (ArrayList) basicRecordService.findBasicRecordByOwnerPaginated(top, skip));
    basicRecordHateoasHandler.addLinks(basicRecordHateoas, request, new Authorisation());
    return ResponseEntity.status(HttpStatus.OK).allow(CommonUtils.WebUtils.getMethodsForRequestOrThrow(request.getServletPath())).body(basicRecordHateoas);
}
Also used : INikitaEntity(nikita.model.noark5.v4.interfaces.entities.INikitaEntity) Authorisation(no.arkivlab.hioa.nikita.webapp.security.Authorisation) ArrayList(java.util.ArrayList) Counted(com.codahale.metrics.annotation.Counted) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with BasicRecord

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

the class BasicRecordDeserializer method deserialize.

@Override
public BasicRecord deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    BasicRecord basicRecord = new BasicRecord();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(basicRecord, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(basicRecord, objectNode);
    // Deserialize archivedBy
    JsonNode currentNode = objectNode.get(RECORD_ARCHIVED_BY);
    if (null != currentNode) {
        basicRecord.setArchivedBy(currentNode.textValue());
        objectNode.remove(RECORD_ARCHIVED_BY);
    }
    // Deserialize archivedDate
    currentNode = objectNode.get(RECORD_ARCHIVED_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateTimeFormat(currentNode.textValue());
            basicRecord.setArchivedDate(parsedDate);
            objectNode.remove(RECORD_ARCHIVED_DATE);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The basisregistrering you tried to create " + "has a malformed arkivertDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
    }
    // Deserialize general basicRecord properties
    // Deserialize recordId
    currentNode = objectNode.get(BASIC_RECORD_ID);
    if (null != currentNode) {
        basicRecord.setRecordId(currentNode.textValue());
        objectNode.remove(BASIC_RECORD_ID);
    }
    // Deserialize title (not using utils to preserve order)
    currentNode = objectNode.get(TITLE);
    if (null != currentNode) {
        basicRecord.setTitle(currentNode.textValue());
        objectNode.remove(TITLE);
    }
    // Deserialize  officialTitle
    currentNode = objectNode.get(FILE_PUBLIC_TITLE);
    if (null != currentNode) {
        basicRecord.setOfficialTitle(currentNode.textValue());
        objectNode.remove(FILE_PUBLIC_TITLE);
    }
    // Deserialize description
    currentNode = objectNode.get(DESCRIPTION);
    if (null != currentNode) {
        basicRecord.setDescription(currentNode.textValue());
        objectNode.remove(DESCRIPTION);
    }
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(basicRecord, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseAuthor(basicRecord, objectNode);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The basisregistrering you tried to create is malformed. The " + "following fields are not recognised as basisregistrering fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return basicRecord;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BasicRecord(nikita.model.noark5.v4.BasicRecord) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) Date(java.util.Date) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 3 with BasicRecord

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

the class BasicRecordHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject basicRecordHateoas, JsonGenerator jgen) throws IOException {
    BasicRecord basicRecord = (BasicRecord) noarkSystemIdEntity;
    jgen.writeStartObject();
    // handle the record properties first
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, basicRecord);
    CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, basicRecord);
    if (basicRecord.getArchivedDate() != null) {
        jgen.writeStringField(RECORD_ARCHIVED_DATE, Serialize.formatDateTime(basicRecord.getArchivedDate()));
    }
    if (basicRecord.getArchivedBy() != null) {
        jgen.writeStringField(RECORD_ARCHIVED_BY, basicRecord.getArchivedBy());
    }
    CommonUtils.Hateoas.Serialize.printDisposal(jgen, basicRecord);
    CommonUtils.Hateoas.Serialize.printScreening(jgen, basicRecord);
    CommonUtils.Hateoas.Serialize.printClassified(jgen, basicRecord);
    // handle general basicRecord properties
    if (basicRecord.getTitle() != null) {
        jgen.writeStringField(TITLE, basicRecord.getTitle());
    }
    if (basicRecord.getOfficialTitle() != null) {
        jgen.writeStringField(FILE_PUBLIC_TITLE, basicRecord.getOfficialTitle());
    }
    if (basicRecord.getDescription() != null) {
        jgen.writeStringField(DESCRIPTION, basicRecord.getDescription());
    }
    CommonUtils.Hateoas.Serialize.printKeyword(jgen, basicRecord);
    CommonUtils.Hateoas.Serialize.printDocumentMedium(jgen, basicRecord);
    CommonUtils.Hateoas.Serialize.printStorageLocation(jgen, basicRecord);
    CommonUtils.Hateoas.Serialize.printComment(jgen, basicRecord);
    // TODO: FIX THIS CommonCommonUtils.Hateoas.Serialize.printCrossReference(jgen, basicRecord);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, basicRecordHateoas.getLinks(basicRecord));
    jgen.writeEndObject();
}
Also used : BasicRecord(nikita.model.noark5.v4.BasicRecord)

Example 4 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.findBySystemIdOrderBySystemId(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.model.noark5.v4.BasicRecord) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException)

Example 5 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.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