void doAddContent(HttpServletRequest request, HttpServletResponse response, int serviceCall) throws ServletException, IOException { IOServices ioServices = getIOServices(); RecordsFlushing recordsFlushing = getRecordsFlushing(request); User user = getUserServices().getUserInCollection("admin", COLLECTION); List<Record> records = getRandomFolders(1, serviceCall); if (!records.isEmpty()) { ContentManager contentManager = getContentServices(); MetadataSchemaTypes types = getSchemaTypes(COLLECTION); MetadataSchema documentSchema = types.getSchema(Document.DEFAULT_SCHEMA); Document document = new Document(getRecordServices().newRecordWithSchema(documentSchema), types); int qtyOfFiles = allPdfFiles.size(); int index = setup.getRandom().nextInt(qtyOfFiles); File file = allPdfFiles.get(index); BufferedInputStream inputStream = new BufferedInputStream(ioServices.newFileInputStream(file, CONTENT_TO_ADD_STREAM)); ContentVersionDataSummary dataSummary = getContentServices().upload(inputStream); document.setTitle(file.getName()); document.setContent(contentManager.createMajor(user, file.getName(), dataSummary)); document.setFolder(records.get(0).getId()); Transaction transaction = new Transaction(asList(document.getWrappedRecord())); transaction.setRecordFlushing(recordsFlushing); transaction.setOptimisticLockingResolution(OptimisticLockingResolution.EXCEPTION); try { getRecordServices().execute(transaction); } catch (RecordServicesException e) { throw new RuntimeException(e); } IOUtils.closeQuietly(inputStream); } }