Skip to content

Commit

Permalink
Merge pull request #567 from Heigvd/dev
Browse files Browse the repository at this point in the history
- URL changes
- text editor fix
- icon picker review
- some links can be opened in a new tab browser
- schedule job monitoring
  • Loading branch information
SandraMonnier authored Feb 9, 2024
2 parents f0f1e55 + 3732a48 commit 75ee25b
Show file tree
Hide file tree
Showing 222 changed files with 4,609 additions and 5,413 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 16.18.1
node-version: 16.20.2
cache: yarn
cache-dependency-path: |
colab-webapp/yarn.lock
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 16.18.1
node-version: 16.20.2
cache: yarn
cache-dependency-path: |
colab-webapp/yarn.lock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"strict": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"suppressImplicitAnyIndexErrors": true,
"declaration": true
},
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package ch.colabproject.colab.api.controller;

import ch.colabproject.colab.api.controller.document.ExternalDataManager;
import ch.colabproject.colab.api.controller.monitoring.CronJobLogManager;
import ch.colabproject.colab.api.model.monitoring.CronJobLogName;
import ch.colabproject.colab.api.security.SessionManager;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
Expand Down Expand Up @@ -35,13 +37,18 @@ public class CronTab {
@Inject
private ExternalDataManager externalDataManager;

/** To manage CronJobLogs */
@Inject
private CronJobLogManager cronJobLogManager;

/**
* Each minutes
* Each minute
*/
@Schedule(hour = "*", minute = "*")
public void saveActivityDates() {
logger.trace("CRON: Persist activity dates to database");
sessionManager.writeActivityDatesToDatabase();
cronJobLogManager.updateCronJobLogLastRunTime(CronJobLogName.SAVE_ACTIVITIES_DATE);
}

/**
Expand All @@ -51,6 +58,7 @@ public void saveActivityDates() {
public void dropOldHttpSession() {
logger.info("CRON: drop expired http session");
sessionManager.clearExpiredHttpSessions();
cronJobLogManager.updateCronJobLogLastRunTime(CronJobLogName.DROP_OLD_HTTP_SESSIONS);
}

/**
Expand All @@ -60,5 +68,6 @@ public void dropOldHttpSession() {
public void dropOldUrlMetadata() {
logger.info("CRON: clean url metadata cache");
externalDataManager.clearOutdated();
cronJobLogManager.updateCronJobLogLastRunTime(CronJobLogName.DROP_OLD_URL_METADATA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@

import ch.colabproject.colab.api.model.WithWebsocketChannels;
import ch.colabproject.colab.api.persistence.jpa.card.CardTypeDao;
import ch.colabproject.colab.api.persistence.jpa.project.ProjectDao;
import ch.colabproject.colab.api.persistence.jpa.team.TeamMemberDao;
import ch.colabproject.colab.api.persistence.jpa.user.UserDao;
import ch.colabproject.colab.api.ws.WebsocketMessagePreparer;
import ch.colabproject.colab.api.ws.message.IndexEntry;
import ch.colabproject.colab.api.ws.message.PrecomputedWsMessages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Status;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Transaction sidekick used to collect updated and deleted entities. Once the transaction is
Expand Down Expand Up @@ -69,6 +71,12 @@ public class EntityGatheringBagForPropagation implements Serializable {
@Inject
private CardTypeDao cardTypeDao;

/**
* To resolve nested channels
*/
@Inject
private ProjectDao projectDao;

/**
* TO sudo
*/
Expand Down Expand Up @@ -205,7 +213,7 @@ private void precomputeMessage() {
this.precomputed = true;
requestManager.sudo(() -> {
return this.message = WebsocketMessagePreparer.prepareWsMessage(userDao, teamDao,
cardTypeDao, filtered, deleted);
cardTypeDao, projectDao, filtered, deleted);
});
logger.debug("Precomputed: {}", message);
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ch.colabproject.colab.api.model.user.HttpSession;
import ch.colabproject.colab.api.model.user.User;
import ch.colabproject.colab.api.persistence.jpa.card.CardTypeDao;
import ch.colabproject.colab.api.persistence.jpa.project.ProjectDao;
import ch.colabproject.colab.api.persistence.jpa.team.TeamMemberDao;
import ch.colabproject.colab.api.persistence.jpa.user.UserDao;
import ch.colabproject.colab.api.presence.PresenceManager;
Expand Down Expand Up @@ -157,6 +158,12 @@ public class WebsocketManager {
@Inject
private CardTypeDao cardTypeDao;

/**
* Project persistence handler
*/
@Inject
private ProjectDao projectDao;

/**
* Presence Manager
*/
Expand Down Expand Up @@ -479,8 +486,7 @@ public void processSubscription(
/**
* Add the given session to the set identified by the given channel, in the given map.
*
* @param map map which contains sets
* @param keyId set id
* @param channel websocket channel to which we subscribe
* @param session session to remove from the set
*/
private void subscribe(WebsocketChannel channel, Session session) {
Expand Down Expand Up @@ -676,6 +682,7 @@ private void propagateSignOut(HttpSession httpSession) {
userDao,
teamMemberDao,
cardTypeDao,
projectDao,
httpSession.getChannelsBuilder(),
new WsSignOutMessage(httpSession));
this.propagate(prepareWsMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public ColabConfig getConfig() {
config
.setDisplayCreateLocalAccountButton(ColabConfiguration.getDisplayLocalAccountButton());
config.setYjsApiEndpoint(ColabConfiguration.getYjsUrlWs());
config.setJcrRepositoryFileSizeLimit(ColabConfiguration.getJcrRepositoryFileSizeLimit());
return config;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* The coLAB project
* Copyright (C) 2021-2023 AlbaSim, MEI, HEIG-VD, HES-SO
*
* Licensed under the MIT License
*/
package ch.colabproject.colab.api.controller.monitoring;

import ch.colabproject.colab.api.model.monitoring.CronJobLog;
import ch.colabproject.colab.api.model.monitoring.CronJobLogName;
import ch.colabproject.colab.api.persistence.jpa.monitoring.CronJobLogDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;
import java.time.OffsetDateTime;

/**
* Logic to manage cron job logging
*
* @author mikkelvestergaard
*/
@Stateless
@LocalBean
public class CronJobLogManager {

/**
* logger
*/
private static final Logger logger = LoggerFactory.getLogger(CronJobLogManager.class);

/**
* CronJobLog persistence
*/
@Inject
private CronJobLogDao cronJobLogDao;

/**
* Create a new cronJobLog with given cronJobLogName
*
* @param jobLogName name of the cronJobLog to create
*
* @return created cronJobLog
*/
private CronJobLog createCronJobLog(CronJobLogName jobLogName) {
CronJobLog cronJobLog = new CronJobLog();
cronJobLog.setJobName(jobLogName);
cronJobLogDao.persistCronJobLog(cronJobLog);

return cronJobLog;
}

/**
* Update a cronJobLog's lastRunTime
*
* @param jobName name of cronJob to update
*/
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void updateCronJobLogLastRunTime(CronJobLogName jobName) {
logger.debug("Update cronJobLog lastRunTime {}", jobName);

CronJobLog cronJobLog = cronJobLogDao.findCronJobLogByName(jobName);

if (cronJobLog == null) {
cronJobLog = createCronJobLog(jobName);
}

OffsetDateTime now = OffsetDateTime.now();
cronJobLog.setLastRunTime(now);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public List<InstanceMaker> getInstanceMakersForProject(Long projectId) {
Project project = projectManager.assertAndGetProject(projectId);
logger.debug("Get instanceMakers: {}", project);

return instanceMakerDao.findInstanceMakersByProject(project);
return project.getInstanceMakers();
}

/**
Expand Down Expand Up @@ -148,15 +148,19 @@ public InstanceMaker addAndPersistInstanceMaker(Project model, User user) {
public InstanceMaker addInstanceMaker(Project model, User user) {
logger.debug("Add instance maker to user {} for model {}", user, model);

if (model != null && user != null
&& findInstanceMakerByProjectAndUser(model, user) != null) {
if (model == null) {
throw HttpErrorMessage.dataError(MessageI18nKey.DATA_INTEGRITY_FAILURE);
}

if (user != null && findInstanceMakerByProjectAndUser(model, user) != null) {
throw HttpErrorMessage.dataError(MessageI18nKey.DATA_INTEGRITY_FAILURE);
}

InstanceMaker instanceMaker = new InstanceMaker();

instanceMaker.setUser(user);
instanceMaker.setProject(model);
model.getInstanceMakers().add(instanceMaker);

return instanceMaker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ch.colabproject.colab.api.Helper;
import ch.colabproject.colab.api.controller.RequestManager;
import ch.colabproject.colab.api.controller.ValidationManager;
import ch.colabproject.colab.api.controller.team.InstanceMakerManager;
import ch.colabproject.colab.api.controller.team.TeamManager;
import ch.colabproject.colab.api.controller.token.TokenManager;
import ch.colabproject.colab.api.exceptions.ColabMergeException;
Expand Down Expand Up @@ -36,6 +37,8 @@
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;

import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -92,6 +95,10 @@ public class UserManager {
@Inject
private TeamManager teamManager;

/** InstanceMaker specific logic management */
@Inject
private InstanceMakerManager instanceMakerManager;

/** Account persistence handling */
@Inject
private AccountDao accountDao;
Expand Down Expand Up @@ -149,7 +156,14 @@ public User getUserById(Long id) {
public List<User> getUsersForProject(Long projectId) {
logger.debug("Get users of project #{}", projectId);

return teamManager.getUsersForProject(projectId);
List<User> teamMembers = teamManager.getUsersForProject(projectId);
List<User> instanceMakers = instanceMakerManager.getUsersForProject(projectId);

List<User> allUsers = Lists.newArrayList();
allUsers.addAll(teamMembers);
allUsers.addAll(instanceMakers);

return allUsers;
}

/**
Expand Down
Loading

0 comments on commit 75ee25b

Please sign in to comment.