use of io.lumeer.api.model.AuditRecord in project engine by Lumeer.
the class AuditFacade method decodeWithTitle.
private List<AuditRecord> decodeWithTitle(final Collection collection, final List<AuditRecord> auditRecords) {
var documentsIds = auditRecords.stream().map(AuditRecord::getResourceId).collect(toSet());
var defaultAttribute = CollectionUtil.getDefaultAttribute(collection);
var defaultAttributeId = defaultAttribute != null ? defaultAttribute.getId() : "";
var defaultConstraint = Utils.computeIfNotNull(defaultAttribute, Attribute::getConstraint);
Map<String, Object> documentValues = new HashMap<>();
Map<String, Object> defaultValues = Collections.emptyMap();
if (!defaultAttributeId.isEmpty()) {
defaultValues = dataDao.getData(collection.getId(), documentsIds, defaultAttributeId).stream().collect(toMap(DataDocument::getId, d -> d.get(defaultAttributeId)));
}
for (AuditRecord auditRecord : auditRecords) {
decode(collection, auditRecord);
decodeTitle(auditRecord, defaultAttributeId, defaultConstraint, defaultValues, documentValues);
}
return auditRecords;
}
use of io.lumeer.api.model.AuditRecord in project engine by Lumeer.
the class DailyTaskProcessor method process.
// every day at 4:03 am
@Schedule(hour = "4", minute = "3")
public void process() {
final List<Organization> organizations = organizationDao.getAllOrganizations();
final LumeerS3Client lumeerS3Client = new LumeerS3Client(configurationProducer);
final FileAttachmentAdapter fileAttachmentAdapter = new FileAttachmentAdapter(lumeerS3Client, fileAttachmentDao, configurationProducer.getEnvironment().name());
final List<FileAttachment> attachmentsToDelete = new ArrayList<>();
log.info(String.format("Running for %d organizations.", organizations.size()));
organizations.forEach(organization -> {
final DataStorage userDataStorage = getDataStorage(organization.getId());
var limits = paymentFacade.getCurrentServiceLimits(organization);
var cleanOlderThan = ZonedDateTime.now().minusDays(limits.getAuditDays());
final DaoContextSnapshot orgDao = getDaoContextSnapshot(userDataStorage, new Workspace(organization, null));
final List<Project> projects = orgDao.getProjectDao().getAllProjects();
projects.forEach(project -> {
final DaoContextSnapshot projDao = getDaoContextSnapshot(userDataStorage, new Workspace(organization, project));
List<AuditRecord> deletedAuditRecords = projDao.getAuditDao().findAuditRecords(cleanOlderThan, AuditType.Deleted);
final List<FileAttachment> projectAttachmentsToDelete = new ArrayList<>();
Set<String> documentIds = deletedAuditRecords.stream().filter(record -> ResourceType.DOCUMENT.equals(record.getResourceType())).map(AuditRecord::getResourceId).collect(Collectors.toSet());
projectAttachmentsToDelete.addAll(fileAttachmentAdapter.getAllFileAttachments(organization, project, documentIds, FileAttachment.AttachmentType.DOCUMENT));
Set<String> linkIds = deletedAuditRecords.stream().filter(record -> ResourceType.LINK.equals(record.getResourceType())).map(AuditRecord::getResourceId).collect(Collectors.toSet());
projectAttachmentsToDelete.addAll(fileAttachmentAdapter.getAllFileAttachments(organization, project, linkIds, FileAttachment.AttachmentType.LINK));
if (projectAttachmentsToDelete.size() > 0) {
log.info(String.format("Will remove %d attachments on %s/%s.", projectAttachmentsToDelete.size(), organization.getCode(), organization.getCode()));
}
attachmentsToDelete.addAll(projectAttachmentsToDelete);
projDao.getAuditDao().cleanAuditRecords(cleanOlderThan);
});
});
if (attachmentsToDelete.size() > 0) {
log.info(String.format("Removing %d attachments.", attachmentsToDelete.size()));
fileAttachmentAdapter.removeFileAttachments(attachmentsToDelete);
}
}
use of io.lumeer.api.model.AuditRecord in project engine by Lumeer.
the class AuditFacade method revertAudit.
public void revertAudit(final String auditRecordId) {
final Payment.ServiceLevel level = getServiceLevel();
if (level.equals(Payment.ServiceLevel.FREE)) {
throw new UnsupportedOperationException("Reverting audit log entries is not available on the free plan.");
}
final AuditRecord record = auditDao.getAuditRecord(auditRecordId);
switch(record.getResourceType()) {
case DOCUMENT:
checkRevertDocumentAudit(record);
return;
case LINK:
checkRevertLinkAudit(record);
return;
default:
throw new UnsupportedOperationException("Could not revert selected record");
}
}
use of io.lumeer.api.model.AuditRecord in project engine by Lumeer.
the class AuditFacade method revertDocumentDelete.
private void revertDocumentDelete(final AuditRecord requestedRecord) {
final AuditRecord auditRecord = auditDao.findLatestAuditRecord(requestedRecord.getParentId(), ResourceType.DOCUMENT, requestedRecord.getResourceId(), AuditType.Deleted);
if (auditRecord == null || !auditRecord.getId().equals(requestedRecord.getId())) {
throw new UnsupportedOperationException("Cannot revert audit record that is not the last.");
}
final Collection collection = collectionDao.getCollectionById(auditRecord.getParentId());
permissionsChecker.checkCreateDocuments(collection);
final Document document = new Document(collection.getId(), ZonedDateTime.now(), getCurrentUserId());
document.setId(auditRecord.getResourceId());
document.setData(auditRecord.getOldState());
permissionsChecker.checkDocumentLimits(document);
final Document storedDocument = documentDao.createDocument(document);
DataDocument storedData = dataDao.createData(collection.getId(), storedDocument.getId(), document.getData());
storedDocument.setData(storedData);
collectionAdapter.updateCollectionMetadata(collection, document.getData().keySet(), Collections.emptySet());
sendDocumentPushNotifications(collection, storedDocument, PusherFacade.CREATE_EVENT_SUFFIX);
checkAuditOnObjectRevert(auditRecord);
}
use of io.lumeer.api.model.AuditRecord in project engine by Lumeer.
the class AuditFacade method getAuditRecordsForLink.
public List<AuditRecord> getAuditRecordsForLink(final String linkTypeId, final String linkInstanceId) {
final LinkType linkType = linkTypeDao.getLinkType(linkTypeId);
final LinkInstance linkInstance = LinkInstanceUtils.loadLinkInstanceWithData(linkInstanceDao, linkDataDao, linkInstanceId);
permissionsChecker.checkEditLinkInstance(linkType, linkInstance);
return auditAdapter.getAuditRecords(linkTypeId, ResourceType.LINK, linkInstanceId, getServiceLevel()).stream().peek(link -> decode(linkType, link)).collect(toList());
}
Aggregations