use of nikita.common.model.noark5.v4.metadata.DocumentType 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.common.model.noark5.v4.metadata.DocumentType in project nikita-noark5-core by HiOA-ABI.
the class DocumentTypeService method findByDescription.
/**
* Retrieve all documentType that have a given description.
* <br>
* Note, this will be replaced by OData search.
*
* @param description
* @return A list of documentType objects wrapped as a MetadataHateoas
* object
*/
@Override
public MetadataHateoas findByDescription(String description) {
MetadataHateoas metadataHateoas = new MetadataHateoas((List<INikitaEntity>) (List) documentTypeRepository.findByDescription(description), DOCUMENT_TYPE);
metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
return metadataHateoas;
}
use of nikita.common.model.noark5.v4.metadata.DocumentType in project nikita-noark5-core by HiOA-ABI.
the class DocumentTypeService method generateDefaultDocumentType.
/**
* Generate a default DocumentType object
*
* @return the DocumentType object wrapped as a DocumentTypeHateoas object
*/
@Override
public DocumentType generateDefaultDocumentType() {
DocumentType documentType = new DocumentType();
documentType.setCode(TEMPLATE_DOCUMENT_TYPE_CODE);
documentType.setDescription(TEMPLATE_DOCUMENT_TYPE_DESCRIPTION);
return documentType;
}
use of nikita.common.model.noark5.v4.metadata.DocumentType in project nikita-noark5-core by HiOA-ABI.
the class DocumentTypeService method getDocumentTypeOrThrow.
/**
* 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 DocumentType object back. If there
* is no DocumentType object, a NoarkEntityNotFoundException exception
* is thrown
*
* @param systemId The systemId of the DocumentType object to retrieve
* @return the DocumentType object
*/
private DocumentType getDocumentTypeOrThrow(@NotNull String systemId) {
DocumentType documentType = documentTypeRepository.findBySystemId(systemId);
if (documentType == null) {
String info = INFO_CANNOT_FIND_OBJECT + " DocumentType, using " + "systemId " + systemId;
logger.error(info);
throw new NoarkEntityNotFoundException(info);
}
return documentType;
}
use of nikita.common.model.noark5.v4.metadata.DocumentType in project nikita-noark5-core by HiOA-ABI.
the class DocumentTypeService method find.
// find by systemId
/**
* Retrieve a single documentType object identified by systemId
*
* @param systemId
* @return single documentType object wrapped as a MetadataHateoas object
*/
@Override
public MetadataHateoas find(String systemId) {
MetadataHateoas metadataHateoas = new MetadataHateoas(documentTypeRepository.save(documentTypeRepository.findBySystemId(systemId)));
metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
return metadataHateoas;
}
Aggregations