Search in sources :

Example 41 with Record

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

the class DocumentDescriptionDeserializer method deserialize.

@Override
public DocumentDescription deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
    DocumentDescription documentDescription = new DocumentDescription();
    ObjectNode objectNode = mapper.readTree(jsonParser);
    // Deserialise general record properties
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(documentDescription, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(documentDescription, objectNode);
    CommonUtils.Hateoas.Deserialize.deserialiseNoarkTitleDescriptionEntity(documentDescription, objectNode);
    // Deserialize documentType
    JsonNode currentNode = objectNode.get(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
    if (null != currentNode) {
        documentDescription.setDocumentType(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_DOCUMENT_TYPE);
    }
    // Deserialize documentStatus
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_STATUS);
    if (null != currentNode) {
        documentDescription.setDocumentStatus(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_STATUS);
    }
    // Deserialize associatedWithRecordAs
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
    if (null != currentNode) {
        documentDescription.setAssociatedWithRecordAs(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATED_WITH_RECORD_AS);
    }
    // Deserialize documentNumber
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
    if (null != currentNode) {
        documentDescription.setDocumentNumber(Integer.valueOf(currentNode.intValue()));
        objectNode.remove(DOCUMENT_DESCRIPTION_DOCUMENT_NUMBER);
    }
    // Deserialize associationDate
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE);
    if (null != currentNode) {
        try {
            Date parsedDate = Deserialize.parseDateTimeFormat(currentNode.textValue());
            documentDescription.setAssociationDate(parsedDate);
        } catch (ParseException e) {
            throw new NikitaMalformedInputDataException("The dokumentbeskrivelse you tried to create " + "has a malformed tilknyttetDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
        }
        objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATION_DATE);
    }
    // Deserialize associatedBy
    currentNode = objectNode.get(DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
    if (null != currentNode) {
        documentDescription.setAssociatedBy(currentNode.textValue());
        objectNode.remove(DOCUMENT_DESCRIPTION_ASSOCIATED_BY);
    }
    // Deserialize storageLocation
    currentNode = objectNode.get(STORAGE_LOCATION);
    if (null != currentNode) {
        documentDescription.setStorageLocation(currentNode.textValue());
        objectNode.remove(STORAGE_LOCATION);
    }
    // Deserialize general documentDescription properties
    CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(documentDescription, objectNode);
    // If there are additional throw a malformed input exception
    if (objectNode.size() != 0) {
        throw new NikitaMalformedInputDataException("The dokumentbeskrivelse you tried to create is malformed. The " + "following fields are not recognised as dokumentbeskrivelse fields[" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
    }
    return documentDescription;
}
Also used : DocumentDescription(nikita.model.noark5.v4.DocumentDescription) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ParseException(java.text.ParseException) Date(java.util.Date) NikitaMalformedInputDataException(nikita.util.exceptions.NikitaMalformedInputDataException)

Example 42 with Record

use of nikita.common.model.noark5.v4.Record 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 43 with Record

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

the class RecordHateoasSerializer method serializeNoarkEntity.

@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject recordHateoas, JsonGenerator jgen) throws IOException {
    Record record = (Record) noarkSystemIdEntity;
    jgen.writeStartObject();
    CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, record);
    CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, record);
    if (record.getArchivedDate() != null) {
        jgen.writeStringField(RECORD_ARCHIVED_DATE, Serialize.formatDateTime(record.getArchivedDate()));
    }
    if (record.getArchivedBy() != null) {
        jgen.writeStringField(RECORD_ARCHIVED_BY, record.getArchivedBy());
    }
    CommonUtils.Hateoas.Serialize.printDisposal(jgen, record);
    CommonUtils.Hateoas.Serialize.printScreening(jgen, record);
    CommonUtils.Hateoas.Serialize.printClassified(jgen, record);
    CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, recordHateoas.getLinks(record));
    jgen.writeEndObject();
}
Also used : Record(nikita.model.noark5.v4.Record)

Example 44 with Record

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

the class FileService method createRecordAssociatedWithFile.

@Override
public Record createRecordAssociatedWithFile(String fileSystemId, Record record) {
    Record persistedRecord = null;
    File file = fileRepository.findBySystemIdOrderBySystemId(fileSystemId);
    if (file == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " File, using fileSystemId " + fileSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else {
        record.setReferenceFile(file);
        persistedRecord = recordService.save(record);
    }
    return persistedRecord;
}
Also used : Record(nikita.model.noark5.v4.Record) BasicRecord(nikita.model.noark5.v4.BasicRecord) NoarkEntityNotFoundException(nikita.util.exceptions.NoarkEntityNotFoundException) File(nikita.model.noark5.v4.File)

Example 45 with Record

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

the class FileService method createRecordAssociatedWithFile.

@Override
public Record createRecordAssociatedWithFile(String fileSystemId, Record record) {
    Record persistedRecord;
    File file = fileRepository.findBySystemId(fileSystemId);
    if (file == null) {
        String info = INFO_CANNOT_FIND_OBJECT + " File, using fileSystemId " + fileSystemId;
        logger.info(info);
        throw new NoarkEntityNotFoundException(info);
    } else {
        record.setReferenceFile(file);
        persistedRecord = recordService.save(record);
    }
    return persistedRecord;
}
Also used : BasicRecord(nikita.common.model.noark5.v4.BasicRecord) Record(nikita.common.model.noark5.v4.Record) NoarkEntityNotFoundException(nikita.common.util.exceptions.NoarkEntityNotFoundException) File(nikita.common.model.noark5.v4.File)

Aggregations

Test (org.junit.Test)60 Record (org.orcid.jaxb.model.record_v2.Record)49 Counted (com.codahale.metrics.annotation.Counted)28 ApiOperation (io.swagger.annotations.ApiOperation)27 ApiResponses (io.swagger.annotations.ApiResponses)27 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)21 Person (org.orcid.jaxb.model.record_v2.Person)20 Record (nikita.model.noark5.v4.Record)19 Email (org.orcid.jaxb.model.record_v2.Email)19 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)18 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)18 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)18 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)18 Address (org.orcid.jaxb.model.record_v2.Address)18 Keyword (org.orcid.jaxb.model.record_v2.Keyword)18 OtherName (org.orcid.jaxb.model.record_v2.OtherName)18 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)18 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)18 Name (org.orcid.jaxb.model.record_v2.Name)17 PeerReviewSummary (org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary)16