use of edu.stanford.bmir.protege.web.server.user.UserActivityRecord in project webprotege by protegeproject.
the class GetAvailableProjectsHandler method execute.
@Nonnull
@Override
public GetAvailableProjectsResult execute(@Nonnull GetAvailableProjectsAction action, @Nonnull ExecutionContext executionContext) {
UserId userId = executionContext.getUserId();
Optional<UserActivityRecord> userActivityRecord = userActivityManager.getUserActivityRecord(executionContext.getUserId());
Map<ProjectId, Long> lastOpenedMap = new HashMap<>();
userActivityRecord.ifPresent(record -> record.getRecentProjects().forEach(recent -> lastOpenedMap.put(recent.getProjectId(), recent.getTimestamp())));
List<AvailableProject> availableProjects = projectPermissionsManager.getReadableProjects(userId).stream().map(details -> {
Subject user = forUser(userId);
ProjectResource projectResource = new ProjectResource(details.getProjectId());
boolean downloadable = accessManager.hasPermission(user, projectResource, DOWNLOAD_PROJECT);
boolean trashable = details.getOwner().equals(userId) || accessManager.hasPermission(user, projectResource, MOVE_ANY_PROJECT_TO_TRASH);
long lastOpened = lastOpenedMap.getOrDefault(details.getProjectId(), 0L);
return new AvailableProject(details, downloadable, trashable, lastOpened);
}).collect(toList());
return new GetAvailableProjectsResult(availableProjects);
}
use of edu.stanford.bmir.protege.web.server.user.UserActivityRecord in project webprotege by protegeproject.
the class UserActivityManager method setLastLogin.
public void setLastLogin(@Nonnull UserId userId, long lastLogin) {
if (userId.isGuest()) {
return;
}
getByUserId(userId);
Query<UserActivityRecord> query = queryByUserId(userId);
UpdateOperations<UserActivityRecord> operations = datastore.createUpdateOperations(UserActivityRecord.class).set(LAST_LOGIN, new Date(lastLogin));
datastore.update(query, operations);
}
use of edu.stanford.bmir.protege.web.server.user.UserActivityRecord in project webprotege by protegeproject.
the class UserActivityManager method addRecentProject.
public void addRecentProject(@Nonnull UserId userId, @Nonnull ProjectId projectId, long timestamp) {
if (userId.isGuest()) {
return;
}
UserActivityRecord record = getByUserId(userId);
List<RecentProjectRecord> recentProjects = record.getRecentProjects().stream().filter(recentProject -> !recentProject.getProjectId().equals(projectId)).sorted().collect(toList());
recentProjects.add(0, new RecentProjectRecord(projectId, timestamp));
UserActivityRecord replacement = new UserActivityRecord(record.getUserId(), record.getLastLogin(), record.getLastLogout(), recentProjects);
save(replacement);
}
use of edu.stanford.bmir.protege.web.server.user.UserActivityRecord in project webprotege by protegeproject.
the class UserActivityManager method setLastLogout.
public void setLastLogout(@Nonnull UserId userId, long lastLogout) {
if (userId.isGuest()) {
return;
}
getByUserId(userId);
Query<UserActivityRecord> query = queryByUserId(userId);
UpdateOperations<UserActivityRecord> operations = datastore.createUpdateOperations(UserActivityRecord.class).set(LAST_LOGOUT, new Date(lastLogout));
datastore.update(query, operations);
}
Aggregations