Skip to content

Feature 10785 #1397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,15 @@ DeleteRemovedUsersDelay = 30
# Cron to execute the deletion of removed users, empty to deactivate the JOB.
# If DeleteRemovedUsersDelay=0, the JOB is deactivated.
DeleteRemovedUsersCron = 45 22 * * *

# The delay in days after which a removed space is deleted. 0 to deactivate.
DeleteRemovedSpacesDelay = 30
# Cron to execute the deletion of removed spaces, empty to deactivate the JOB.
# If DeleteRemovedSpacesDelay=0, the JOB is deactivated.
DeleteRemovedSpacesCron = 45 23 * * *

# The delay in days after which a removed applications is deleted. 0 to deactivate.
DeleteRemovedApplicationsDelay = 30
# Cron to execute the deletion of removed applications, empty to deactivate the JOB.
# If DeleteRemovedApplicationsDelay=0, the JOB is deactivated.
DeleteRemovedApplicationsCron = 45 0 * * *
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,5 @@ JSPP.copyoptions.dialog.title = Options de copie
JSPP.application.back = Retour \u00e0 l'application
JSPP.application.go = Acc\u00e9der \u00e0 l'application
JSPP.space.go=Acc\u00e9der \u00e0 l'espace


Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,6 @@ JSPP.copyoptions.dialog.title = Copy options
JSPP.application.back = Back to this application
JSPP.application.go = Go to this application
JSPP.space.go=Go to this space



Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,5 @@ JSPP.copyoptions.dialog.title = Copy options
JSPP.application.back = Back to this application
JSPP.application.go = Go to this application

JSPP.space.go = Go to this space
JSPP.space.go = Go to this space

Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,5 @@ JSPP.copyoptions.dialog.title = Options de copie
JSPP.application.back = Retour \u00e0 l'application
JSPP.application.go = Acc\u00e9der \u00e0 l'application
JSPP.space.go=Acc\u00e9der \u00e0 l'espace


Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,53 @@ public static String getDeletionOfRemovedGroupsCron() {
public static int getDeletionOfRemovedGroupsDayDelay() {
return settings.getInteger("DeleteRemovedGroupsDelay", 30);
}

/**
* Gets the cron of the JOB execution in charge of deleting the removed spaces.
* @return cron as string, empty to deactivate the JOB.
*/
public static String getDeletionOfRemovedSpacesCron() {
return settings.getString("DeleteRemovedSpacesCron", "");
}

/**
* Gets the delay in days after which a removed space can be deleted.
* @return day delay as int, 0 to deactivate the automatic deletion of removed spaces.
*/
public static int getDeletionOfRemovedSpacesDayDelay() {
return settings.getInteger("DeleteRemovedSpacesDelay", 30);
}

/**
* Indicates if the automatic deletion of removed spaces is enabled.
* @return true if enabled, false otherwise.
*/
public static boolean isAutomaticDeletionOfRemovedSpacesEnabled() {
return isDefined(getDeletionOfRemovedSpacesCron()) && getDeletionOfRemovedGroupsDayDelay() > 0;
}

/**
* Gets the cron of the JOB execution in charge of deleting the removed spaces.
* @return cron as string, empty to deactivate the JOB.
*/
public static String getDeletionOfRemovedApplicationsCron() {
return settings.getString("DeleteRemovedApplicationsCron", "");
}

/**
* Gets the delay in days after which a removed space can be deleted.
* @return day delay as int, 0 to deactivate the automatic deletion of removed spaces.
*/
public static int getDeletionOfRemovedApplicationsDayDelay() {
return settings.getInteger("DeleteRemovedApplicationsDelay", 30);
}

/**
* Indicates if the automatic deletion of removed spaces is enabled.
* @return true if enabled, false otherwise.
*/
public static boolean isAutomaticDeletionOfRemovedApplicationsEnabled() {
return isDefined(getDeletionOfRemovedApplicationsCron())
&& getDeletionOfRemovedApplicationsDayDelay() > 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (C) 2000 - 2024 Silverpeas
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* As a special exception to the terms and conditions of version 3.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* Open Source Software ("FLOSS") applications as described in Silverpeas's
* FLOSS exception. You should have received a copy of the text describing
* the FLOSS exception, and it is also available here:
* "https://www.silverpeas.org/legal/floss_exception.html"
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.silverpeas.core.admin.service;

import org.silverpeas.core.admin.user.model.User;
import org.silverpeas.core.annotation.Service;
import org.silverpeas.core.initialization.Initialization;
import org.silverpeas.core.scheduler.Job;
import org.silverpeas.core.scheduler.JobExecutionContext;
import org.silverpeas.core.scheduler.Scheduler;
import org.silverpeas.core.scheduler.SchedulerProvider;
import org.silverpeas.core.scheduler.trigger.JobTrigger;
import org.silverpeas.kernel.logging.SilverLogger;

import javax.inject.Inject;
import java.time.LocalDate;

import static org.silverpeas.core.admin.AdminSettings.*;
import static org.silverpeas.core.util.DateUtil.toLocalDate;

/**
* Batch in charge of the deletion of removed component instances.
*
* @author mmoquillon
*/
@Service
public class DeleteRemovedApplicationsScheduler implements Initialization {

protected static final String JOB_NAME = "DeleteRemovedApplicationsJob";

@Inject
private Administration admin;

@Override
public void init() throws Exception {
if (isAutomaticDeletionOfRemovedApplicationsEnabled()) {
final Scheduler scheduler = SchedulerProvider.getVolatileScheduler();
scheduler.unscheduleJob(JOB_NAME);
scheduler.scheduleJob(new DeleteRemovedApplicationsJob(),
JobTrigger.triggerAt(getDeletionOfRemovedApplicationsCron()));
}
}

private class DeleteRemovedApplicationsJob extends Job {

DeleteRemovedApplicationsJob() {
super(JOB_NAME);
}

@Override
public void execute(final JobExecutionContext context) {
if (isAutomaticDeletionOfRemovedApplicationsEnabled()) {
try {
var allRemovedApps = admin.getRemovedComponents();
LocalDate now = LocalDate.now();
for (var removedApp : allRemovedApps) {
LocalDate stateSaveDayDateWithDelay = toLocalDate(removedApp.getRemovalDate())
.plusDays(getDeletionOfRemovedSpacesDayDelay());
if (stateSaveDayDateWithDelay.isBefore(now) ||
stateSaveDayDateWithDelay.isEqual(now)) {
admin.deleteComponentInst(User.getSystemUser().getId(), removedApp.getId(), true);
}
}
} catch (AdminException e) {
SilverLogger.getLogger(this).error(e.getMessage(), e);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (C) 2000 - 2024 Silverpeas
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* As a special exception to the terms and conditions of version 3.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* Open Source Software ("FLOSS") applications as described in Silverpeas's
* FLOSS exception. You should have received a copy of the text describing
* the FLOSS exception, and it is also available here:
* "https://www.silverpeas.org/legal/floss_exception.html"
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.silverpeas.core.admin.service;

import org.silverpeas.core.admin.user.model.User;
import org.silverpeas.core.annotation.Service;
import org.silverpeas.core.initialization.Initialization;
import org.silverpeas.core.scheduler.Job;
import org.silverpeas.core.scheduler.JobExecutionContext;
import org.silverpeas.core.scheduler.Scheduler;
import org.silverpeas.core.scheduler.SchedulerProvider;
import org.silverpeas.core.scheduler.trigger.JobTrigger;
import org.silverpeas.kernel.logging.SilverLogger;

import javax.inject.Inject;
import java.time.LocalDate;

import static org.silverpeas.core.admin.AdminSettings.*;
import static org.silverpeas.core.util.DateUtil.toLocalDate;

/**
* Batch in charge of the deletion of removed spaces.
*
* @author mmoquillon
*/
@Service
public class DeleteRemovedSpacesScheduler implements Initialization {

protected static final String JOB_NAME = "DeleteRemovedSpacesJob";

@Inject
private Administration admin;

@Override
public void init() throws Exception {
if (isAutomaticDeletionOfRemovedSpacesEnabled()) {
final Scheduler scheduler = SchedulerProvider.getVolatileScheduler();
scheduler.unscheduleJob(JOB_NAME);
scheduler.scheduleJob(new DeleteRemovedSpacesJob(),
JobTrigger.triggerAt(getDeletionOfRemovedSpacesCron()));
}
}

private class DeleteRemovedSpacesJob extends Job {

DeleteRemovedSpacesJob() {
super(JOB_NAME);
}

@Override
public void execute(final JobExecutionContext context) {
if (isAutomaticDeletionOfRemovedSpacesEnabled()) {
try {
var allRemovedSpaces = admin.getRemovedSpaces();
LocalDate now = LocalDate.now();
for (var removedSpace : allRemovedSpaces) {
LocalDate stateSaveDayDateWithDelay = toLocalDate(removedSpace.getRemovalDate())
.plusDays(getDeletionOfRemovedSpacesDayDelay());
if (stateSaveDayDateWithDelay.isBefore(now) ||
stateSaveDayDateWithDelay.isEqual(now)) {
admin.deleteSpaceInstById(User.getSystemUser().getId(), removedSpace.getId(), true);
}
}
} catch (AdminException e) {
SilverLogger.getLogger(this).error(e.getMessage(), e);
}
}
}
}
}
Loading