class FileTypeServiceImpl implements FileTypeService {

    @Override
    public FileType createFileType(FileTypeCreateRequest fileTypeCreateRequest)
    {
        // Perform the validation.
        validateFileTypeCreateRequest(fileTypeCreateRequest);

        // Ensure a file type with the specified file type code doesn't already exist.
        FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(fileTypeCreateRequest.getFileTypeCode());
        if (fileTypeEntity != null)
        {
            throw new AlreadyExistsException(
                String.format("Unable to create file type \"%s\" because it already exists.", fileTypeCreateRequest.getFileTypeCode()));
        }

        // Create a file type entity from the request information.
        fileTypeEntity = createFileTypeEntity(fileTypeCreateRequest);

        // Persist the new entity.
        fileTypeEntity = fileTypeDao.saveAndRefresh(fileTypeEntity);

        // Create and return the file type object from the persisted entity.
        return createFileTypeFromEntity(fileTypeEntity);
    }

}