use of nikita.common.model.noark5.v4.metadata.FileType in project nikita-noark5-core by HiOA-ABI.
the class FileTypeService method findByDescription.
/**
* Retrieve all FileType that have a given description.
* <br>
* Note, this will be replaced by OData search.
*
* @param description Description of object you wish to retrieve. The
* whole text, this is an exact search.
* @return A list of FileType objects wrapped as a MetadataHateoas
* object
*/
@Override
public MetadataHateoas findByDescription(String description) {
MetadataHateoas metadataHateoas = new MetadataHateoas((List<INikitaEntity>) (List) fileTypeRepository.findByDescription(description), FILE_TYPE);
metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
return metadataHateoas;
}
use of nikita.common.model.noark5.v4.metadata.FileType in project nikita-noark5-core by HiOA-ABI.
the class FileTypeService method getFileTypeOrThrow.
/**
* 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 FileType object back. If there
* is no FileType object, a NoarkEntityNotFoundException exception
* is thrown
*
* @param systemId The systemId of the FileType object to retrieve
* @return the FileType object
*/
private FileType getFileTypeOrThrow(@NotNull String systemId) {
FileType fileType = fileTypeRepository.findBySystemId(systemId);
if (fileType == null) {
String info = INFO_CANNOT_FIND_OBJECT + " FileType, using " + "systemId " + systemId;
logger.error(info);
throw new NoarkEntityNotFoundException(info);
}
return fileType;
}
use of nikita.common.model.noark5.v4.metadata.FileType in project nikita-noark5-core by HiOA-ABI.
the class FileTypeService method createNewFileType.
// All CREATE operations
/**
* Persists a new FileType object to the database.
*
* @param fileType FileType object with values set
* @return the newly persisted FileType object wrapped as a
* MetadataHateoas object
*/
@Override
public MetadataHateoas createNewFileType(FileType fileType) {
fileType.setDeleted(false);
fileType.setOwnedBy(SecurityContextHolder.getContext().getAuthentication().getName());
MetadataHateoas metadataHateoas = new MetadataHateoas(fileTypeRepository.save(fileType));
metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
return metadataHateoas;
}
use of nikita.common.model.noark5.v4.metadata.FileType in project nikita-noark5-core by HiOA-ABI.
the class FileTypeService method handleUpdate.
/**
* Update a FileType identified by its systemId
* <p>
* Copy the values you are allowed to change, code and description
*
* @param systemId The systemId of the fileType object you wish to
* update
* @param fileType The updated fileType object. Note the values
* you are allowed to change are copied from this
* object. This object is not persisted.
* @return the updated fileType
*/
@Override
public MetadataHateoas handleUpdate(String systemId, Long version, FileType fileType) {
FileType existingFileType = getFileTypeOrThrow(systemId);
// Copy all the values you are allowed to copy ....
if (null != existingFileType.getCode()) {
existingFileType.setCode(existingFileType.getCode());
}
if (null != existingFileType.getDescription()) {
existingFileType.setDescription(existingFileType.getDescription());
}
// Note this can potentially result in a NoarkConcurrencyException
// exception
existingFileType.setVersion(version);
MetadataHateoas fileTypeHateoas = new MetadataHateoas(fileTypeRepository.save(existingFileType));
metadataHateoasHandler.addLinks(fileTypeHateoas, new Authorisation());
applicationEventPublisher.publishEvent(new AfterNoarkEntityUpdatedEvent(this, existingFileType));
return fileTypeHateoas;
}
use of nikita.common.model.noark5.v4.metadata.FileType in project nikita-noark5-core by HiOA-ABI.
the class FileTypeService method findAll.
// All READ operations
/**
* Retrieve a list of all FileType objects
*
* @return list of FileType objects wrapped as a
* MetadataHateoas object
*/
@Override
public MetadataHateoas findAll() {
MetadataHateoas metadataHateoas = new MetadataHateoas((List<INikitaEntity>) (List) fileTypeRepository.findAll(), FILE_TYPE);
metadataHateoasHandler.addLinks(metadataHateoas, new Authorisation());
return metadataHateoas;
}
Aggregations