use of nikita.model.noark5.v4.Record 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;
}
use of nikita.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;
}
use of nikita.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();
}
use of nikita.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();
}
use of nikita.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;
}
Aggregations