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 {
StringBuilder errors = new StringBuilder();
BasicRecord basicRecord = new BasicRecord();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise general record properties
CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(basicRecord, objectNode, errors);
CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(basicRecord, objectNode, errors);
// Deserialize archivedBy
JsonNode currentNode = objectNode.get(N5ResourceMappings.RECORD_ARCHIVED_BY);
if (null != currentNode) {
basicRecord.setArchivedBy(currentNode.textValue());
objectNode.remove(N5ResourceMappings.RECORD_ARCHIVED_BY);
}
// Deserialize archivedDate
basicRecord.setArchivedDate(CommonUtils.Hateoas.Deserialize.deserializeDateTime(N5ResourceMappings.RECORD_ARCHIVED_DATE, objectNode, errors));
// Deserialize general basicRecord properties
// Deserialize recordId
currentNode = objectNode.get(N5ResourceMappings.BASIC_RECORD_ID);
if (null != currentNode) {
basicRecord.setRecordId(currentNode.textValue());
objectNode.remove(N5ResourceMappings.BASIC_RECORD_ID);
}
// Deserialize title (not using utils to preserve order)
currentNode = objectNode.get(N5ResourceMappings.TITLE);
if (null != currentNode) {
basicRecord.setTitle(currentNode.textValue());
objectNode.remove(N5ResourceMappings.TITLE);
}
// Deserialize officialTitle
currentNode = objectNode.get(N5ResourceMappings.FILE_PUBLIC_TITLE);
if (null != currentNode) {
basicRecord.setOfficialTitle(currentNode.textValue());
objectNode.remove(N5ResourceMappings.FILE_PUBLIC_TITLE);
}
// Deserialize description
currentNode = objectNode.get(N5ResourceMappings.DESCRIPTION);
if (null != currentNode) {
basicRecord.setDescription(currentNode.textValue());
objectNode.remove(N5ResourceMappings.DESCRIPTION);
}
CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(basicRecord, objectNode, errors);
CommonUtils.Hateoas.Deserialize.deserialiseAuthor(basicRecord, objectNode, errors);
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
errors.append("The basisregistrering you tried to create is malformed. The " + "following fields are not recognised as basisregistrering fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
}
if (0 < errors.length())
throw new NikitaMalformedInputDataException(errors.toString());
return basicRecord;
}
use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.
the class RegistryEntryDeserializer method deserialize.
@Override
public RegistryEntry deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
StringBuilder errors = new StringBuilder();
RegistryEntry registryEntry = new RegistryEntry();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise general record properties
CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(registryEntry, objectNode, errors);
CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(registryEntry, objectNode, errors);
// Deserialize archivedBy
JsonNode currentNode = objectNode.get(N5ResourceMappings.RECORD_ARCHIVED_BY);
if (null != currentNode) {
registryEntry.setArchivedBy(currentNode.textValue());
objectNode.remove(N5ResourceMappings.RECORD_ARCHIVED_BY);
}
// Deserialize archivedDate
registryEntry.setArchivedDate(CommonUtils.Hateoas.Deserialize.deserializeDateTime(N5ResourceMappings.RECORD_ARCHIVED_DATE, objectNode, errors));
// Deserialize general basicRecord properties
// Deserialize recordId
currentNode = objectNode.get(N5ResourceMappings.BASIC_RECORD_ID);
if (null != currentNode) {
registryEntry.setRecordId(currentNode.textValue());
objectNode.remove(N5ResourceMappings.BASIC_RECORD_ID);
}
// Deserialize title (not using utils to preserve order)
currentNode = objectNode.get(N5ResourceMappings.TITLE);
if (null != currentNode) {
registryEntry.setTitle(currentNode.textValue());
objectNode.remove(N5ResourceMappings.TITLE);
}
// Deserialize officialTitle
currentNode = objectNode.get(N5ResourceMappings.FILE_PUBLIC_TITLE);
if (null != currentNode) {
registryEntry.setOfficialTitle(currentNode.textValue());
objectNode.remove(N5ResourceMappings.FILE_PUBLIC_TITLE);
}
// Deserialize description
currentNode = objectNode.get(N5ResourceMappings.DESCRIPTION);
if (null != currentNode) {
registryEntry.setDescription(currentNode.textValue());
objectNode.remove(N5ResourceMappings.DESCRIPTION);
}
CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(registryEntry, objectNode, errors);
// Deserialize general registryEntry properties
// Deserialize recordYear
currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_YEAR);
if (null != currentNode) {
registryEntry.setRecordYear(Integer.valueOf(currentNode.intValue()));
objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_YEAR);
}
// Deserialize recordSequenceNumber
currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_SEQUENCE_NUMBER);
if (null != currentNode) {
registryEntry.setRecordSequenceNumber(Integer.valueOf(currentNode.intValue()));
objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_SEQUENCE_NUMBER);
}
// Deserialize registryEntryNumber
currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_NUMBER);
if (null != currentNode) {
registryEntry.setRegistryEntryNumber(Integer.valueOf(currentNode.intValue()));
objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_NUMBER);
}
// Deserialize registryEntryType
currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_TYPE);
if (null != currentNode) {
registryEntry.setRegistryEntryType(currentNode.textValue());
objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_TYPE);
} else {
errors.append("The journalpost you tried to create is missing journalposttype. ");
}
// Deserialize recordStatus
currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_STATUS);
if (null != currentNode) {
registryEntry.setRecordStatus(currentNode.textValue());
objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_STATUS);
} else {
errors.append("The journalpost you tried to create is missing journalstatus. ");
}
// Deserialize recordDate
registryEntry.setRecordDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_DATE, objectNode, errors, true));
// Deserialize documentDate
registryEntry.setDocumentDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_DOCUMENT_DATE, objectNode, errors));
// Deserialize receivedDate
registryEntry.setReceivedDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_RECEIVED_DATE, objectNode, errors));
// Deserialize sentDate
registryEntry.setSentDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_SENT_DATE, objectNode, errors));
// Deserialize dueDate
registryEntry.setDueDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_DUE_DATE, objectNode, errors));
// Deserialize freedomAssessmentDate
registryEntry.setFreedomAssessmentDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.REGISTRY_ENTRY_RECORD_FREEDOM_ASSESSMENT_DATE, objectNode, errors));
// Deserialize numberOfAttachments
currentNode = objectNode.get(N5ResourceMappings.REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
if (null != currentNode) {
registryEntry.setNumberOfAttachments(Integer.valueOf(currentNode.intValue()));
objectNode.remove(N5ResourceMappings.REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
}
// Deserialize loanedDate
registryEntry.setLoanedDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.CASE_LOANED_DATE, objectNode, errors));
// Deserialize loanedTo
currentNode = objectNode.get(N5ResourceMappings.CASE_LOANED_TO);
if (null != currentNode) {
registryEntry.setLoanedTo(currentNode.textValue());
objectNode.remove(N5ResourceMappings.CASE_LOANED_TO);
}
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
errors.append("The journalpost you tried to create is malformed. The " + "following fields are not recognised as journalpost fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]. ");
}
if (0 < errors.length())
throw new NikitaMalformedInputDataException(errors.toString());
return registryEntry;
}
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();
}
use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.
the class RegistryEntryDeserializer method deserialize.
@Override
public RegistryEntry deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
RegistryEntry registryEntry = new RegistryEntry();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise general record properties
CommonUtils.Hateoas.Deserialize.deserialiseNoarkSystemIdEntity(registryEntry, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseNoarkCreateEntity(registryEntry, objectNode);
// Deserialize archivedBy
JsonNode currentNode = objectNode.get(RECORD_ARCHIVED_BY);
if (null != currentNode) {
registryEntry.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());
registryEntry.setArchivedDate(parsedDate);
objectNode.remove(RECORD_ARCHIVED_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The journalpost object 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) {
registryEntry.setRecordId(currentNode.textValue());
objectNode.remove(BASIC_RECORD_ID);
}
// Deserialize title (not using utils to preserve order)
currentNode = objectNode.get(TITLE);
if (null != currentNode) {
registryEntry.setTitle(currentNode.textValue());
objectNode.remove(TITLE);
}
// Deserialize officialTitle
currentNode = objectNode.get(FILE_PUBLIC_TITLE);
if (null != currentNode) {
registryEntry.setOfficialTitle(currentNode.textValue());
objectNode.remove(FILE_PUBLIC_TITLE);
}
// Deserialize description
currentNode = objectNode.get(DESCRIPTION);
if (null != currentNode) {
registryEntry.setDescription(currentNode.textValue());
objectNode.remove(DESCRIPTION);
}
CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(registryEntry, objectNode);
// Deserialize general registryEntry properties
// Deserialize recordYear
currentNode = objectNode.get(REGISTRY_ENTRY_YEAR);
if (null != currentNode) {
registryEntry.setRecordYear(Integer.valueOf(currentNode.intValue()));
objectNode.remove(REGISTRY_ENTRY_YEAR);
}
// Deserialize recordSequenceNumber
currentNode = objectNode.get(REGISTRY_ENTRY_SEQUENCE_NUMBER);
if (null != currentNode) {
registryEntry.setRecordSequenceNumber(Integer.valueOf(currentNode.intValue()));
objectNode.remove(REGISTRY_ENTRY_SEQUENCE_NUMBER);
}
// Deserialize registryEntryNumber
currentNode = objectNode.get(REGISTRY_ENTRY_NUMBER);
if (null != currentNode) {
registryEntry.setRegistryEntryNumber(Integer.valueOf(currentNode.intValue()));
objectNode.remove(REGISTRY_ENTRY_NUMBER);
}
// Deserialize registryEntryType
currentNode = objectNode.get(REGISTRY_ENTRY_TYPE);
if (null != currentNode) {
registryEntry.setRegistryEntryType(currentNode.textValue());
objectNode.remove(REGISTRY_ENTRY_TYPE);
}
// Deserialize recordStatus
currentNode = objectNode.get(REGISTRY_ENTRY_STATUS);
if (null != currentNode) {
registryEntry.setRecordStatus(currentNode.textValue());
objectNode.remove(REGISTRY_ENTRY_STATUS);
}
// Deserialize recordDate
currentNode = objectNode.get(REGISTRY_ENTRY_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
registryEntry.setRecordDate(parsedDate);
objectNode.remove(REGISTRY_ENTRY_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed journaldato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize documentDate
currentNode = objectNode.get(REGISTRY_ENTRY_DOCUMENT_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
registryEntry.setDocumentDate(parsedDate);
objectNode.remove(REGISTRY_ENTRY_DOCUMENT_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed dokumentetsDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize receivedDate
currentNode = objectNode.get(REGISTRY_ENTRY_RECEIVED_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
registryEntry.setReceivedDate(parsedDate);
objectNode.remove(REGISTRY_ENTRY_RECEIVED_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed mottattDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize sentDate
currentNode = objectNode.get(REGISTRY_ENTRY_SENT_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
registryEntry.setSentDate(parsedDate);
objectNode.remove(REGISTRY_ENTRY_SENT_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed sendtDate. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize dueDate
currentNode = objectNode.get(REGISTRY_ENTRY_DUE_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
registryEntry.setDueDate(parsedDate);
objectNode.remove(REGISTRY_ENTRY_DUE_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed forfallsdato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize freedomAssessmentDate
currentNode = objectNode.get(REGISTRY_ENTRY_RECORD_FREEDOM_ASSESSMENT_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
registryEntry.setFreedomAssessmentDate(parsedDate);
objectNode.remove(REGISTRY_ENTRY_RECORD_FREEDOM_ASSESSMENT_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed offentlighetsvurdertDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize numberOfAttachments
currentNode = objectNode.get(REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
if (null != currentNode) {
registryEntry.setNumberOfAttachments(Integer.valueOf(currentNode.intValue()));
objectNode.remove(REGISTRY_ENTRY_NUMBER_OF_ATTACHMENTS);
}
// Deserialize loanedDate
currentNode = objectNode.get(CASE_LOANED_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
registryEntry.setLoanedDate(parsedDate);
objectNode.remove(CASE_LOANED_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The journalpost you tried to create " + "has a malformed utlaantDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize loanedTo
currentNode = objectNode.get(CASE_LOANED_TO);
if (null != currentNode) {
registryEntry.setLoanedTo(currentNode.textValue());
objectNode.remove(CASE_LOANED_TO);
}
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
throw new NikitaMalformedInputDataException("The journalpost you tried to create is malformed. The " + "following fields are not recognised as journalpost fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
}
return registryEntry;
}
use of nikita.model.noark5.v4.BasicRecord in project nikita-noark5-core by HiOA-ABI.
the class FileImportService method createBasicRecordAssociatedWithFile.
@Override
public BasicRecord createBasicRecordAssociatedWithFile(String fileSystemId, BasicRecord basicRecord) {
BasicRecord persistedBasicRecord = 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 {
basicRecord.setReferenceFile(file);
persistedBasicRecord = (BasicRecord) recordImportService.save(basicRecord);
}
return persistedBasicRecord;
}
Aggregations