use of nikita.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class CaseFileDeserializer method deserialize.
@Override
public CaseFile deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
CaseFile caseFile = new CaseFile();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise properties for File
CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(caseFile, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(caseFile, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(caseFile, objectNode);
CommonUtils.Hateoas.Deserialize.deserialiseKeyword(caseFile, objectNode);
// Deserialize fileId
JsonNode currentNode = objectNode.get(FILE_ID);
if (null != currentNode) {
caseFile.setFileId(currentNode.textValue());
objectNode.remove(FILE_ID);
}
// Deserialize officialTitle
currentNode = objectNode.get(FILE_PUBLIC_TITLE);
if (null != currentNode) {
caseFile.setOfficialTitle(currentNode.textValue());
objectNode.remove(FILE_PUBLIC_TITLE);
}
caseFile.setReferenceCrossReference(CommonUtils.Hateoas.Deserialize.deserialiseCrossReferences(objectNode));
CommonUtils.Hateoas.Deserialize.deserialiseComments(caseFile, objectNode);
caseFile.setReferenceDisposal(CommonUtils.Hateoas.Deserialize.deserialiseDisposal(objectNode));
caseFile.setReferenceScreening(CommonUtils.Hateoas.Deserialize.deserialiseScreening(objectNode));
caseFile.setReferenceClassified(CommonUtils.Hateoas.Deserialize.deserialiseClassified(objectNode));
// Deserialise general properties for CaseFile
// Deserialize caseYear
currentNode = objectNode.get(CASE_YEAR);
if (null != currentNode) {
caseFile.setCaseYear(Integer.valueOf(currentNode.intValue()));
objectNode.remove(CASE_YEAR);
}
// Deserialize caseSequenceNumber
currentNode = objectNode.get(CASE_SEQUENCE_NUMBER);
if (null != currentNode) {
caseFile.setCaseSequenceNumber(Integer.valueOf(currentNode.intValue()));
objectNode.remove(CASE_SEQUENCE_NUMBER);
}
// Deserialize caseDate
currentNode = objectNode.get(CASE_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
caseFile.setCaseDate(parsedDate);
objectNode.remove(CASE_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The saksmappe you tried to create " + "has a malformed saksDato. Make sure format is " + NOARK_DATE_FORMAT_PATTERN);
}
}
// Deserialize administrativeUnit
currentNode = objectNode.get(ADMINISTRATIVE_UNIT);
if (null != currentNode) {
caseFile.setAdministrativeUnit(currentNode.textValue());
objectNode.remove(ADMINISTRATIVE_UNIT);
}
// Deserialize caseResponsible
currentNode = objectNode.get(CASE_RESPONSIBLE);
if (null != currentNode) {
caseFile.setCaseResponsible(currentNode.textValue());
objectNode.remove(CASE_RESPONSIBLE);
}
// Deserialize recordsManagementUnit
currentNode = objectNode.get(CASE_RECORDS_MANAGEMENT_UNIT);
if (null != currentNode) {
caseFile.setRecordsManagementUnit(currentNode.textValue());
objectNode.remove(CASE_RECORDS_MANAGEMENT_UNIT);
}
// Deserialize caseStatus
currentNode = objectNode.get(CASE_STATUS);
if (null != currentNode) {
caseFile.setCaseStatus(currentNode.textValue());
objectNode.remove(CASE_STATUS);
}
// Deserialize loanedDate
currentNode = objectNode.get(CASE_LOANED_DATE);
if (null != currentNode) {
try {
Date parsedDate = Deserialize.parseDateFormat(currentNode.textValue());
caseFile.setLoanedDate(parsedDate);
objectNode.remove(CASE_LOANED_DATE);
} catch (ParseException e) {
throw new NikitaMalformedInputDataException("The saksmappe 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) {
caseFile.setLoanedTo(currentNode.textValue());
objectNode.remove(CASE_LOANED_TO);
}
// Deserialize referenceSeries
currentNode = objectNode.get(REFERENCE_SERIES);
if (null != currentNode) {
Series series = new Series();
String systemID = currentNode.textValue();
if (systemID != null) {
series.setSystemId(systemID);
}
caseFile.setReferenceSeries(series);
objectNode.remove(REFERENCE_SERIES);
}
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
throw new NikitaMalformedInputDataException("The saksmappe object you tried to create is malformed. The " + "following fields are not recognised as saksmappe fields [" + CommonUtils.Hateoas.Deserialize.checkNodeObjectEmpty(objectNode) + "]");
}
caseFile.setReferenceCaseParty(CommonUtils.Hateoas.Deserialize.deserialiseCaseParties(objectNode));
caseFile.setReferencePrecedence(CommonUtils.Hateoas.Deserialize.deserialisePrecedences(objectNode));
return caseFile;
}
use of nikita.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class FileHateoasSerializer method serializeNoarkEntity.
@Override
public void serializeNoarkEntity(INikitaEntity noarkSystemIdEntity, HateoasNoarkObject fileHateoas, JsonGenerator jgen) throws IOException {
File file = (File) noarkSystemIdEntity;
jgen.writeStartObject();
CommonUtils.Hateoas.Serialize.printSystemIdEntity(jgen, file);
CommonUtils.Hateoas.Serialize.printStorageLocation(jgen, file);
if (file.getFileId() != null) {
jgen.writeStringField(FILE_ID, file.getFileId());
if (file.getTitle() != null) {
jgen.writeStringField(TITLE, file.getTitle());
}
if (file.getOfficialTitle() != null) {
jgen.writeStringField(FILE_PUBLIC_TITLE, file.getOfficialTitle());
}
if (file.getDescription() != null) {
jgen.writeStringField(DESCRIPTION, file.getDescription());
}
}
CommonUtils.Hateoas.Serialize.printDocumentMedium(jgen, file);
CommonUtils.Hateoas.Serialize.printKeyword(jgen, file);
CommonUtils.Hateoas.Serialize.printCreateEntity(jgen, file);
CommonUtils.Hateoas.Serialize.printFinaliseEntity(jgen, file);
if (file.getReferenceSeries() != null && file.getReferenceSeries().getSystemId() != null) {
jgen.writeStringField(REFERENCE_SERIES, file.getReferenceSeries().getSystemId());
}
//TODO: CommonCommonUtils.Hateoas.Serialize.printCrossReference(jgen, file.getReferenceCrossReference());
CommonUtils.Hateoas.Serialize.printComment(jgen, file);
CommonUtils.Hateoas.Serialize.printDisposal(jgen, file);
CommonUtils.Hateoas.Serialize.printScreening(jgen, file);
CommonUtils.Hateoas.Serialize.printClassified(jgen, file);
CommonUtils.Hateoas.Serialize.printHateoasLinks(jgen, fileHateoas.getLinks(file));
jgen.writeEndObject();
}
use of nikita.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class FileService method findFileByOwnerPaginated.
// All READ operations
@Override
public List<File> findFileByOwnerPaginated(Integer top, Integer skip) {
if (top == null || top > maxPageSize) {
top = maxPageSize;
}
if (skip == null) {
skip = 0;
}
String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<File> criteriaQuery = criteriaBuilder.createQuery(File.class);
Root<File> from = criteriaQuery.from(File.class);
CriteriaQuery<File> select = criteriaQuery.select(from);
criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
TypedQuery<File> typedQuery = entityManager.createQuery(select);
typedQuery.setFirstResult(skip);
typedQuery.setMaxResults(maxPageSize);
return typedQuery.getResultList();
}
use of nikita.model.noark5.v4.File 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;
}
use of nikita.model.noark5.v4.File in project nikita-noark5-core by HiOA-ABI.
the class FileService 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) recordService.save(basicRecord);
}
return persistedBasicRecord;
}
Aggregations