Search in sources :

Example 1 with DataStorage

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;
}
Also used : DataStorage(io.lumeer.engine.api.data.DataStorage)

Example 2 with DataStorage

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);
    }
}
Also used : DataStorage(io.lumeer.engine.api.data.DataStorage) Organization(io.lumeer.api.model.Organization) FileAttachment(io.lumeer.api.model.FileAttachment) FileAttachmentAdapter(io.lumeer.core.adapter.FileAttachmentAdapter) ArrayList(java.util.ArrayList) Project(io.lumeer.api.model.Project) LumeerS3Client(io.lumeer.core.util.LumeerS3Client) AuditRecord(io.lumeer.api.model.AuditRecord) DaoContextSnapshot(io.lumeer.storage.api.dao.context.DaoContextSnapshot) Schedule(javax.ejb.Schedule)

Example 3 with DataStorage

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));
        });
    });
}
Also used : DataStorage(io.lumeer.engine.api.data.DataStorage) DaoContextSnapshot(io.lumeer.storage.api.dao.context.DaoContextSnapshot) Schedule(javax.ejb.Schedule)

Example 4 with DataStorage

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;
}
Also used : DataStorage(io.lumeer.engine.api.data.DataStorage)

Example 5 with DataStorage

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;
}
Also used : DataStorage(io.lumeer.engine.api.data.DataStorage) Project(io.lumeer.api.model.Project) Organization(io.lumeer.api.model.Organization) Collection(io.lumeer.api.model.Collection) DataDocument(io.lumeer.engine.api.data.DataDocument) Document(io.lumeer.api.model.Document) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) DaoContextSnapshot(io.lumeer.storage.api.dao.context.DaoContextSnapshot) PermissionAdapter(io.lumeer.core.adapter.PermissionAdapter)

Aggregations

DataStorage (io.lumeer.engine.api.data.DataStorage)5 DaoContextSnapshot (io.lumeer.storage.api.dao.context.DaoContextSnapshot)3 Organization (io.lumeer.api.model.Organization)2 Project (io.lumeer.api.model.Project)2 Schedule (javax.ejb.Schedule)2 AuditRecord (io.lumeer.api.model.AuditRecord)1 Collection (io.lumeer.api.model.Collection)1 Document (io.lumeer.api.model.Document)1 FileAttachment (io.lumeer.api.model.FileAttachment)1 FileAttachmentAdapter (io.lumeer.core.adapter.FileAttachmentAdapter)1 PermissionAdapter (io.lumeer.core.adapter.PermissionAdapter)1 LumeerS3Client (io.lumeer.core.util.LumeerS3Client)1 DataDocument (io.lumeer.engine.api.data.DataDocument)1 ResourceNotFoundException (io.lumeer.storage.api.exception.ResourceNotFoundException)1 ArrayList (java.util.ArrayList)1