use of nikita.common.model.noark5.v4.casehandling.CaseFile in project nikita-noark5-core by HiOA-ABI.
the class CaseFileService method findCaseFileByOwnerPaginated.
// All READ operations
@Override
public List<CaseFile> findCaseFileByOwnerPaginated(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<CaseFile> criteriaQuery = criteriaBuilder.createQuery(CaseFile.class);
Root<CaseFile> from = criteriaQuery.from(CaseFile.class);
CriteriaQuery<CaseFile> select = criteriaQuery.select(from);
criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
TypedQuery<CaseFile> typedQuery = entityManager.createQuery(select);
typedQuery.setFirstResult(skip);
typedQuery.setMaxResults(maxPageSize);
return typedQuery.getResultList();
}
use of nikita.common.model.noark5.v4.casehandling.CaseFile in project nikita-noark5-core by HiOA-ABI.
the class CaseFileService method getCaseFileOrThrow.
// All HELPER operations
/**
* 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 CaseFile back. If there is no valid
* CaseFile, an exception is thrown
*
* @param caseFileSystemId
* @return
*/
protected CaseFile getCaseFileOrThrow(@NotNull String caseFileSystemId) {
CaseFile caseFile = caseFileRepository.findBySystemIdOrderBySystemId(caseFileSystemId);
if (caseFile == null) {
String info = INFO_CANNOT_FIND_OBJECT + " CaseFile, using systemId " + caseFileSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
}
return caseFile;
}
use of nikita.common.model.noark5.v4.casehandling.CaseFile in project nikita-noark5-core by HiOA-ABI.
the class CaseFileService method createRegistryEntryAssociatedWithCaseFile.
@Override
public RegistryEntry createRegistryEntryAssociatedWithCaseFile(@NotNull String fileSystemId, @NotNull RegistryEntry registryEntry) {
CaseFile caseFile = getCaseFileOrThrow(fileSystemId);
// bidirectional relationship @OneToMany and @ManyToOne, set both sides of relationship
registryEntry.setReferenceFile(caseFile);
caseFile.getReferenceRecord().add(registryEntry);
return registryEntryService.save(registryEntry);
}
use of nikita.common.model.noark5.v4.casehandling.CaseFile in project nikita-noark5-core by HiOA-ABI.
the class CaseFileService method handleUpdate.
// All UPDATE operations
@Override
public CaseFile handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull CaseFile incomingCaseFile) {
CaseFile existingCaseFile = getCaseFileOrThrow(systemId);
// Copy all the values you are allowed to copy ....
if (null != incomingCaseFile.getDescription()) {
existingCaseFile.setDescription(incomingCaseFile.getDescription());
}
if (null != incomingCaseFile.getTitle()) {
existingCaseFile.setTitle(incomingCaseFile.getTitle());
}
if (null != incomingCaseFile.getAdministrativeUnit()) {
existingCaseFile.setAdministrativeUnit(incomingCaseFile.getAdministrativeUnit());
}
if (null != incomingCaseFile.getRecordsManagementUnit()) {
existingCaseFile.setRecordsManagementUnit(incomingCaseFile.getRecordsManagementUnit());
}
if (null != incomingCaseFile.getCaseResponsible()) {
existingCaseFile.setCaseResponsible(incomingCaseFile.getCaseResponsible());
}
if (null != incomingCaseFile.getCaseSequenceNumber()) {
existingCaseFile.setCaseSequenceNumber(incomingCaseFile.getCaseSequenceNumber());
}
existingCaseFile.setVersion(version);
caseFileRepository.save(existingCaseFile);
return existingCaseFile;
}
use of nikita.common.model.noark5.v4.casehandling.CaseFile in project nikita-noark5-core by HiOA-ABI.
the class CaseFileDeserializer method deserialize.
@Override
public CaseFile deserialize(JsonParser jsonParser, DeserializationContext dc) throws IOException {
StringBuilder errors = new StringBuilder();
CaseFile caseFile = new CaseFile();
ObjectNode objectNode = mapper.readTree(jsonParser);
// Deserialise properties for File
CommonUtils.Hateoas.Deserialize.deserialiseNoarkEntity(caseFile, objectNode, errors);
CommonUtils.Hateoas.Deserialize.deserialiseDocumentMedium(caseFile, objectNode, errors);
CommonUtils.Hateoas.Deserialize.deserialiseStorageLocation(caseFile, objectNode, errors);
CommonUtils.Hateoas.Deserialize.deserialiseKeyword(caseFile, objectNode, errors);
// Deserialize fileId
JsonNode currentNode = objectNode.get(N5ResourceMappings.FILE_ID);
if (null != currentNode) {
caseFile.setFileId(currentNode.textValue());
objectNode.remove(N5ResourceMappings.FILE_ID);
}
// Deserialize officialTitle
currentNode = objectNode.get(N5ResourceMappings.FILE_PUBLIC_TITLE);
if (null != currentNode) {
caseFile.setOfficialTitle(currentNode.textValue());
objectNode.remove(N5ResourceMappings.FILE_PUBLIC_TITLE);
}
caseFile.setReferenceCrossReference(CommonUtils.Hateoas.Deserialize.deserialiseCrossReferences(objectNode, errors));
CommonUtils.Hateoas.Deserialize.deserialiseComments(caseFile, objectNode, errors);
caseFile.setReferenceDisposal(CommonUtils.Hateoas.Deserialize.deserialiseDisposal(objectNode, errors));
caseFile.setReferenceScreening(CommonUtils.Hateoas.Deserialize.deserialiseScreening(objectNode, errors));
caseFile.setReferenceClassified(CommonUtils.Hateoas.Deserialize.deserialiseClassified(objectNode, errors));
// Deserialise general properties for CaseFile
// Deserialize caseYear
currentNode = objectNode.get(N5ResourceMappings.CASE_YEAR);
if (null != currentNode) {
caseFile.setCaseYear(Integer.valueOf(currentNode.intValue()));
objectNode.remove(N5ResourceMappings.CASE_YEAR);
}
// Deserialize caseSequenceNumber
currentNode = objectNode.get(N5ResourceMappings.CASE_SEQUENCE_NUMBER);
if (null != currentNode) {
caseFile.setCaseSequenceNumber(Integer.valueOf(currentNode.intValue()));
objectNode.remove(N5ResourceMappings.CASE_SEQUENCE_NUMBER);
}
// Deserialize caseDate
caseFile.setCaseDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.CASE_DATE, objectNode, errors));
// Deserialize administrativeUnit
currentNode = objectNode.get(N5ResourceMappings.ADMINISTRATIVE_UNIT);
if (null != currentNode) {
caseFile.setAdministrativeUnit(currentNode.textValue());
objectNode.remove(N5ResourceMappings.ADMINISTRATIVE_UNIT);
}
// Deserialize caseResponsible
currentNode = objectNode.get(N5ResourceMappings.CASE_RESPONSIBLE);
if (null != currentNode) {
caseFile.setCaseResponsible(currentNode.textValue());
objectNode.remove(N5ResourceMappings.CASE_RESPONSIBLE);
}
// Deserialize recordsManagementUnit
currentNode = objectNode.get(N5ResourceMappings.CASE_RECORDS_MANAGEMENT_UNIT);
if (null != currentNode) {
caseFile.setRecordsManagementUnit(currentNode.textValue());
objectNode.remove(N5ResourceMappings.CASE_RECORDS_MANAGEMENT_UNIT);
}
// Deserialize caseStatus
currentNode = objectNode.get(N5ResourceMappings.CASE_STATUS);
if (null != currentNode) {
caseFile.setCaseStatus(currentNode.textValue());
objectNode.remove(N5ResourceMappings.CASE_STATUS);
}
// Deserialize loanedDate
caseFile.setLoanedDate(CommonUtils.Hateoas.Deserialize.deserializeDate(N5ResourceMappings.CASE_LOANED_DATE, objectNode, errors));
// Deserialize loanedTo
currentNode = objectNode.get(N5ResourceMappings.CASE_LOANED_TO);
if (null != currentNode) {
caseFile.setLoanedTo(currentNode.textValue());
objectNode.remove(N5ResourceMappings.CASE_LOANED_TO);
}
// Deserialize referenceSeries
currentNode = objectNode.get(N5ResourceMappings.REFERENCE_SERIES);
if (null != currentNode) {
Series series = new Series();
String systemID = currentNode.textValue();
if (systemID != null) {
series.setSystemId(systemID);
}
caseFile.setReferenceSeries(series);
objectNode.remove(N5ResourceMappings.REFERENCE_SERIES);
}
// If there are additional throw a malformed input exception
if (objectNode.size() != 0) {
errors.append("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, errors));
caseFile.setReferencePrecedence(CommonUtils.Hateoas.Deserialize.deserialisePrecedences(objectNode, errors));
if (0 < errors.length())
throw new NikitaMalformedInputDataException(errors.toString());
return caseFile;
}
Aggregations