Search in sources :

Example 1 with Project

use of edu.stanford.bmir.protege.web.server.project.Project in project webprotege by protegeproject.

the class CreateDownloadTask method call.

@Override
public Void call() throws Exception {
    if (Files.exists(downloadPath)) {
        logger.info("{} {} Project download already exists.  Not recreating download. ({})", projectId, userId, downloadPath.toAbsolutePath());
        return null;
    }
    logger.info("{} {} Creating project download", projectId, userId);
    MemoryMonitor memoryMonitor = new MemoryMonitor(logger);
    memoryMonitor.monitorMemoryUsage();
    Project project = projectManager.getProject(projectId, userId);
    memoryMonitor.monitorMemoryUsage();
    ProjectDownloader downloader = new ProjectDownloader(projectDisplayName, project, revisionNumber, format, applicationName);
    logger.info("{} {} Writing download to file: {}", projectId, userId, downloadPath);
    Files.createDirectories(downloadPath.getParent());
    try (BufferedOutputStream outputStream = new BufferedOutputStream(Files.newOutputStream(downloadPath))) {
        downloader.writeProject(outputStream);
    }
    double sizeInMB = Files.size(downloadPath) / (1024.0 * 1024);
    logger.info("{} {} Finished creating download ({} MB)", projectId, userId, String.format("%.4f", sizeInMB));
    memoryMonitor.monitorMemoryUsage();
    return null;
}
Also used : MemoryMonitor(edu.stanford.bmir.protege.web.server.util.MemoryMonitor) Project(edu.stanford.bmir.protege.web.server.project.Project) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with Project

use of edu.stanford.bmir.protege.web.server.project.Project in project webprotege by protegeproject.

the class GetProjectEventsActionHandler method execute.

@Nonnull
@Override
public GetProjectEventsResult execute(@Nonnull GetProjectEventsAction action, @Nonnull ExecutionContext executionContext) {
    EventTag sinceTag = action.getSinceTag();
    ProjectId projectId = action.getProjectId();
    UserId userId = executionContext.getUserId();
    if (!accessManager.hasPermission(forUser(userId), forProject(action.getProjectId()), VIEW_PROJECT)) {
        return getEmptyResult(projectId, sinceTag);
    }
    if (!projectManager.isActive(projectId)) {
        return getEmptyResult(projectId, sinceTag);
    }
    Optional<Project> project = projectManager.getProjectIfActive(projectId);
    if (!project.isPresent()) {
        return getEmptyResult(projectId, sinceTag);
    }
    EventManager<ProjectEvent<?>> eventManager = project.get().getEventManager();
    EventList<ProjectEvent<?>> eventList = eventManager.getEventsFromTag(sinceTag);
    ProjectEventList projectEventList = ProjectEventList.builder(eventList.getStartTag(), projectId, eventList.getEndTag()).addEvents(eventList.getEvents()).build();
    return new GetProjectEventsResult(projectEventList);
}
Also used : Project(edu.stanford.bmir.protege.web.server.project.Project) ProjectResource.forProject(edu.stanford.bmir.protege.web.server.access.ProjectResource.forProject) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) Nonnull(javax.annotation.Nonnull)

Aggregations

Project (edu.stanford.bmir.protege.web.server.project.Project)2 ProjectResource.forProject (edu.stanford.bmir.protege.web.server.access.ProjectResource.forProject)1 MemoryMonitor (edu.stanford.bmir.protege.web.server.util.MemoryMonitor)1 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 BufferedOutputStream (java.io.BufferedOutputStream)1 Nonnull (javax.annotation.Nonnull)1