use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectService method findDocumentObjectByOwnerPaginated.
@Override
public List<DocumentObject> findDocumentObjectByOwnerPaginated(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<DocumentObject> criteriaQuery = criteriaBuilder.createQuery(DocumentObject.class);
Root<DocumentObject> from = criteriaQuery.from(DocumentObject.class);
CriteriaQuery<DocumentObject> select = criteriaQuery.select(from);
criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
TypedQuery<DocumentObject> typedQuery = entityManager.createQuery(select);
typedQuery.setFirstResult(skip);
typedQuery.setMaxResults(maxPageSize);
return typedQuery.getResultList();
}
use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectService method deleteEntity.
// All DELETE operations
@Override
public void deleteEntity(@NotNull String documentObjectSystemId) {
DocumentObject documentObject = getDocumentObjectOrThrow(documentObjectSystemId);
documentObjectRepository.delete(documentObject);
}
use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectService method findDocumentObjectByAnyColumn.
// All READ operations
@Override
public List<DocumentObject> findDocumentObjectByAnyColumn(String column, String value) {
String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<DocumentObject> criteriaQuery = criteriaBuilder.createQuery(DocumentObject.class);
Root<DocumentObject> from = criteriaQuery.from(DocumentObject.class);
CriteriaQuery<DocumentObject> select = criteriaQuery.select(from);
if (column.equalsIgnoreCase(DOCUMENT_OBJECT_FILE_NAME)) {
column = "originalFilename";
}
criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
criteriaQuery.where(criteriaBuilder.equal(from.get(column), value));
TypedQuery<DocumentObject> typedQuery = entityManager.createQuery(select);
return typedQuery.getResultList();
}
use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectService method handleUpdate.
// All UPDATE operations
@Override
public DocumentObject handleUpdate(@NotNull String systemId, @NotNull Long version, @NotNull DocumentObject incomingDocumentObject) {
DocumentObject existingDocumentObject = getDocumentObjectOrThrow(systemId);
// Here copy all the values you are allowed to copy ....
if (null != incomingDocumentObject.getFormat()) {
existingDocumentObject.setFormat(incomingDocumentObject.getFormat());
}
if (null != incomingDocumentObject.getFormatDetails()) {
existingDocumentObject.setFormatDetails(incomingDocumentObject.getFormatDetails());
}
if (null != incomingDocumentObject.getOriginalFilename()) {
existingDocumentObject.setOriginalFilename(incomingDocumentObject.getOriginalFilename());
}
if (null != incomingDocumentObject.getVariantFormat()) {
existingDocumentObject.setVariantFormat(incomingDocumentObject.getVariantFormat());
}
if (null != incomingDocumentObject.getVersionNumber()) {
existingDocumentObject.setVersionNumber(incomingDocumentObject.getVersionNumber());
}
existingDocumentObject.setVersion(version);
documentObjectRepository.save(existingDocumentObject);
return existingDocumentObject;
}
use of nikita.common.model.noark5.v4.DocumentObject in project nikita-noark5-core by HiOA-ABI.
the class DocumentObjectService method getDocumentObjectOrThrow.
// 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 DocumentObject back. If there is no valid
* DocumentObject, an exception is thrown
*
* @param documentObjectSystemId
* @return
*/
protected DocumentObject getDocumentObjectOrThrow(@NotNull String documentObjectSystemId) {
DocumentObject documentObject = documentObjectRepository.findBySystemIdOrderBySystemId(documentObjectSystemId);
if (documentObject == null) {
String info = INFO_CANNOT_FIND_OBJECT + " DocumentObject, using systemId " + documentObjectSystemId;
logger.info(info);
throw new NoarkEntityNotFoundException(info);
}
return documentObject;
}
Aggregations