Search in sources :

Example 1 with FileAttachmentAdapter

use of io.lumeer.core.adapter.FileAttachmentAdapter in project engine by Lumeer.

the class FileAttachmentFacade method init.

@PostConstruct
public void init() {
    lumeerS3Client = new LumeerS3Client(configurationProducer);
    adapter = new FileAttachmentAdapter(lumeerS3Client, fileAttachmentDao, configurationProducer.getEnvironment().name());
}
Also used : FileAttachmentAdapter(io.lumeer.core.adapter.FileAttachmentAdapter) LumeerS3Client(io.lumeer.core.util.LumeerS3Client) PostConstruct(javax.annotation.PostConstruct)

Example 2 with FileAttachmentAdapter

use of io.lumeer.core.adapter.FileAttachmentAdapter in project engine by Lumeer.

the class AbstractContextualTask method initialize.

@Override
public ContextualTask initialize(final User initiator, final DaoContextSnapshot daoContextSnapshot, final PusherClient pusherClient, final LumeerS3Client lumeerS3Client, final RequestDataKeeper requestDataKeeper, final ConstraintManager constraintManager, DefaultConfigurationProducer.DeployEnvironment environment, final int recursionDepth) {
    this.initiator = initiator;
    this.daoContextSnapshot = daoContextSnapshot;
    this.pusherClient = pusherClient;
    this.lumeerS3Client = lumeerS3Client;
    this.requestDataKeeper = requestDataKeeper;
    this.constraintManager = constraintManager;
    this.environment = environment;
    this.timeZone = requestDataKeeper.getTimezone();
    this.recursionDepth = recursionDepth;
    collectionAdapter = new CollectionAdapter(daoContextSnapshot.getCollectionDao(), daoContextSnapshot.getFavoriteItemDao(), daoContextSnapshot.getDocumentDao());
    permissionAdapter = new PermissionAdapter(daoContextSnapshot.getUserDao(), daoContextSnapshot.getGroupDao(), daoContextSnapshot.getViewDao(), daoContextSnapshot.getLinkTypeDao(), daoContextSnapshot.getCollectionDao());
    resourceAdapter = new ResourceAdapter(permissionAdapter, daoContextSnapshot.getCollectionDao(), daoContextSnapshot.getLinkTypeDao(), daoContextSnapshot.getViewDao(), daoContextSnapshot.getUserDao());
    viewAdapter = new ViewAdapter(resourceAdapter, daoContextSnapshot.getFavoriteItemDao());
    documentAdapter = new DocumentAdapter(daoContextSnapshot.getResourceCommentDao(), daoContextSnapshot.getFavoriteItemDao());
    linkTypeAdapter = new LinkTypeAdapter(daoContextSnapshot.getLinkTypeDao(), daoContextSnapshot.getLinkInstanceDao());
    linkInstanceAdapter = new LinkInstanceAdapter(daoContextSnapshot.getResourceCommentDao());
    pusherAdapter = new PusherAdapter(getAppId(), new FacadeAdapter(permissionAdapter), resourceAdapter, permissionAdapter, daoContextSnapshot.getViewDao(), daoContextSnapshot.getLinkTypeDao(), daoContextSnapshot.getCollectionDao());
    fileAttachmentAdapter = new FileAttachmentAdapter(getLumeerS3Client(), daoContextSnapshot.getFileAttachmentDao(), environment.name());
    return this;
}
Also used : LinkInstanceAdapter(io.lumeer.core.adapter.LinkInstanceAdapter) PusherAdapter(io.lumeer.core.adapter.PusherAdapter) FileAttachmentAdapter(io.lumeer.core.adapter.FileAttachmentAdapter) ResourceAdapter(io.lumeer.core.adapter.ResourceAdapter) DocumentAdapter(io.lumeer.core.adapter.DocumentAdapter) FacadeAdapter(io.lumeer.core.adapter.FacadeAdapter) CollectionAdapter(io.lumeer.core.adapter.CollectionAdapter) ViewAdapter(io.lumeer.core.adapter.ViewAdapter) LinkTypeAdapter(io.lumeer.core.adapter.LinkTypeAdapter) PermissionAdapter(io.lumeer.core.adapter.PermissionAdapter)

Example 3 with FileAttachmentAdapter

use of io.lumeer.core.adapter.FileAttachmentAdapter 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)

Aggregations

FileAttachmentAdapter (io.lumeer.core.adapter.FileAttachmentAdapter)3 LumeerS3Client (io.lumeer.core.util.LumeerS3Client)2 AuditRecord (io.lumeer.api.model.AuditRecord)1 FileAttachment (io.lumeer.api.model.FileAttachment)1 Organization (io.lumeer.api.model.Organization)1 Project (io.lumeer.api.model.Project)1 CollectionAdapter (io.lumeer.core.adapter.CollectionAdapter)1 DocumentAdapter (io.lumeer.core.adapter.DocumentAdapter)1 FacadeAdapter (io.lumeer.core.adapter.FacadeAdapter)1 LinkInstanceAdapter (io.lumeer.core.adapter.LinkInstanceAdapter)1 LinkTypeAdapter (io.lumeer.core.adapter.LinkTypeAdapter)1 PermissionAdapter (io.lumeer.core.adapter.PermissionAdapter)1 PusherAdapter (io.lumeer.core.adapter.PusherAdapter)1 ResourceAdapter (io.lumeer.core.adapter.ResourceAdapter)1 ViewAdapter (io.lumeer.core.adapter.ViewAdapter)1 DataStorage (io.lumeer.engine.api.data.DataStorage)1 DaoContextSnapshot (io.lumeer.storage.api.dao.context.DaoContextSnapshot)1 ArrayList (java.util.ArrayList)1 PostConstruct (javax.annotation.PostConstruct)1 Schedule (javax.ejb.Schedule)1