use of io.lumeer.engine.api.data.DataStorage in project engine by Lumeer.
the class MongoDbStorageFactory method getStorage.
@Override
public DataStorage getStorage(final CacheProvider cacheProvider, final List<StorageConnection> connections, final String database, final Boolean useSsl) {
final DataStorage storage = new MongoDbStorage(morphia);
storage.setCacheProvider(cacheProvider);
storage.connect(connections, database, useSsl);
return storage;
}
use of io.lumeer.engine.api.data.DataStorage 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.engine.api.data.DataStorage in project engine by Lumeer.
the class CronTaskProcessor method process.
// every 15 minutes
@Schedule(hour = "*", minute = "*/15")
public void process() {
final List<Organization> organizations = organizationDao.getAllOrganizations();
organizations.forEach(organization -> {
final DataStorage userDataStorage = getDataStorage(organization.getId());
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));
final List<Collection> collections = projDao.getCollectionDao().getAllCollections();
collections.forEach(collection -> processRules(projDao, collection));
});
});
}
use of io.lumeer.engine.api.data.DataStorage in project engine by Lumeer.
the class MongoDbStorageFactory method getStorage.
@Override
public DataStorage getStorage(final List<StorageConnection> connections, final String database, final Boolean useSsl) {
final DataStorage storage = new MongoDbStorage();
storage.connect(connections, database, useSsl);
return storage;
}
use of io.lumeer.engine.api.data.DataStorage in project engine by Lumeer.
the class DelayedActionProcessor method checkActionResourceExistsAndFillData.
private Collection checkActionResourceExistsAndFillData(final DelayedAction action, final User receiver) {
final String organizationId = action.getData().getString(DelayedAction.DATA_ORGANIZATION_ID);
final String projectId = action.getData().getString(DelayedAction.DATA_PROJECT_ID);
final String collectionId = action.getData().getString(DelayedAction.DATA_COLLECTION_ID);
final String documentId = action.getData().getString(DelayedAction.DATA_DOCUMENT_ID);
try {
if (organizationId != null) {
final DataStorage userDataStorage = getDataStorage(organizationId);
final Organization organization = organizations.computeIfAbsent(organizationId, id -> organizationDao.getOrganizationById(organizationId));
action.getData().append(DelayedAction.DATA_ORGANIZATION_NAME, organization.getName());
action.getData().append(DelayedAction.DATA_ORGANIZATION_CODE, organization.getCode());
action.getData().append(DelayedAction.DATA_ORGANIZATION_ICON, organization.getIcon());
action.getData().append(DelayedAction.DATA_ORGANIZATION_COLOR, organization.getColor());
final DaoContextSnapshot organizationDaoSnapshot = organizationDaoSnapshots.computeIfAbsent(organizationId, id -> getDaoContextSnapshot(userDataStorage, new Workspace(organization, null)));
if (projectId != null) {
final Project project = projects.computeIfAbsent(projectId, id -> organizationDaoSnapshot.getProjectDao().getProjectById(projectId));
action.getData().append(DelayedAction.DATA_PROJECT_NAME, project.getName());
action.getData().append(DelayedAction.DATA_PROJECT_CODE, project.getCode());
action.getData().append(DelayedAction.DATA_PROJECT_ICON, project.getIcon());
action.getData().append(DelayedAction.DATA_PROJECT_COLOR, project.getColor());
final String projectKey = organizationId + ":" + projectId;
final DaoContextSnapshot projectDaoSnapshot = projectDaoSnapshots.computeIfAbsent(projectKey, key -> getDaoContextSnapshot(userDataStorage, new Workspace(organization, project)));
final PermissionAdapter permissionAdapter = permissionAdapters.computeIfAbsent(projectKey, key -> new PermissionAdapter(projectDaoSnapshot.getUserDao(), projectDaoSnapshot.getGroupDao(), projectDaoSnapshot.getViewDao(), projectDaoSnapshot.getLinkTypeDao(), projectDaoSnapshot.getCollectionDao()));
if (receiver != null && !permissionAdapter.canReadWorkspace(organization, project, receiver.getId())) {
return null;
}
if (collectionId != null) {
final Collection collection = collections.computeIfAbsent(collectionId, id -> projectDaoSnapshot.getCollectionDao().getCollectionById(collectionId));
action.getData().append(DelayedAction.DATA_COLLECTION_NAME, collection.getName());
action.getData().append(DelayedAction.DATA_COLLECTION_ICON, collection.getIcon());
action.getData().append(DelayedAction.DATA_COLLECTION_COLOR, collection.getColor());
if (documentId != null) {
final Document document = projectDaoSnapshot.getDocumentDao().getDocumentById(documentId);
document.setData(projectDaoSnapshot.getDataDao().getData(collectionId, documentId));
if (receiver != null && !permissionAdapter.canReadDocument(organization, project, document, collection, receiver.getId())) {
return null;
}
return collection;
}
}
}
}
} catch (ResourceNotFoundException e) {
return null;
}
return null;
}
Aggregations