use of io.lumeer.api.model.Document in project engine by Lumeer.
the class DocumentFacade method getDocument.
public Document getDocument(String collectionId, String documentId) {
Collection collection = collectionDao.getCollectionById(collectionId);
permissionsChecker.checkRole(collection, Role.READ);
Document document = documentDao.getDocumentById(documentId);
DataDocument data = dataDao.getData(collection.getId(), documentId);
document.setData(data);
return document;
}
use of io.lumeer.api.model.Document in project engine by Lumeer.
the class DocumentFacade method createDocument.
public Document createDocument(String collectionId, Document document) {
Collection collection = collectionDao.getCollectionById(collectionId);
permissionsChecker.checkRole(collection, Role.WRITE);
DataDocument data = DocumentUtils.checkDocumentKeysValidity(document.getData());
Document storedDocument = createDocument(collection, document);
DataDocument storedData = dataDao.createData(collection.getId(), storedDocument.getId(), data);
storedDocument.setData(storedData);
updateCollectionMetadata(collection, data.keySet(), Collections.emptySet(), 1);
return storedDocument;
}
use of io.lumeer.api.model.Document in project engine by Lumeer.
the class DocumentFacade method updateDocument.
private Document updateDocument(Collection collection, String documentId) {
Document document = documentDao.getDocumentById(documentId);
document.setCollectionId(collection.getId());
document.setUpdatedBy(authenticatedUser.getCurrentUsername());
document.setUpdateDate(LocalDateTime.now());
document.setDataVersion(document.getDataVersion() + 1);
return documentDao.updateDocument(document.getId(), document);
}
use of io.lumeer.api.model.Document in project engine by Lumeer.
the class DocumentFacade method patchDocumentData.
public Document patchDocumentData(String collectionId, String documentId, DataDocument data) {
Collection collection = collectionDao.getCollectionById(collectionId);
permissionsChecker.checkRole(collection, Role.WRITE);
DataDocument oldData = dataDao.getData(collectionId, documentId);
Set<String> attributesToAdd = new HashSet<>(data.keySet());
attributesToAdd.removeAll(oldData.keySet());
updateCollectionMetadata(collection, attributesToAdd, Collections.emptySet(), 0);
// TODO archive the old document
DataDocument patchedData = dataDao.patchData(collection.getId(), documentId, data);
Document updatedDocument = updateDocument(collection, documentId);
updatedDocument.setData(patchedData);
return updatedDocument;
}
use of io.lumeer.api.model.Document in project engine by Lumeer.
the class ImportFacade method parseCSVFile.
private void parseCSVFile(Collection collection, String data) {
if (data == null || data.trim().isEmpty()) {
return;
}
CsvParserSettings settings = new CsvParserSettings();
settings.detectFormatAutomatically();
settings.setHeaderExtractionEnabled(true);
CsvParser parser = new CsvParser(settings);
parser.beginParsing(new StringReader(data));
String[] headers = Arrays.stream(parser.getRecordMetadata().headers()).filter(Objects::nonNull).toArray(String[]::new);
if (headers.length == 0) {
return;
}
int[] counts = new int[headers.length];
int documentsCount = 0;
List<Document> documents = new ArrayList<>();
String[] row;
while ((row = parser.parseNext()) != null) {
Document d = createDocumentFromRow(headers, row, counts);
addDocumentMetadata(collection, d);
documents.add(d);
if (documents.size() >= MAX_PARSED_DOCUMENTS) {
addDocumentsToDb(collection.getId(), documents);
documents.clear();
}
documentsCount++;
}
if (!documents.isEmpty()) {
addDocumentsToDb(collection.getId(), documents);
}
parser.stopParsing();
addCollectionMetadata(collection, headers, counts, documentsCount);
}
Aggregations