Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  import java.util.Calendar;
  import java.util.Date;
  import java.util.List;
  import lombok.Setter;
 import org.quartz.Job;

This job finds all sites that have been softly deleted and checks their deletion time. If it is older than site.soft.deletion.gracetime, they are then really deleted. The value is in days and defaults to 30 if not set.

This does not take into account whether or not site.soft.deletion is enabled since there may be sites which have been softly deleted but then the param is disabled, leaving them in limbo.

Steve Swinsburg (
 public class SoftSiteDeletionJob implements Job {
 	private final int GRACETIME_DEFAULT = 30;
 	public void init() {
 		// Create our security advisor.
 			public SecurityAdvice isAllowed(String userIdString function,
 					String reference) {
 	public void execute(JobExecutionContext jobExecutionContext)"SoftSiteDeletionJob started.");
 		Date graceDate = getGraceDate();
 		// get sites
 		List<Sitesites = .getSites(.nullnullnullnullnull); + " softly deleted site(s) will be processed");
 		// foreach site, check soft deletion time
 		// Note: we could do this in the SQL so we only get a list of sites that
 		// all need to be deleted.
 		// but this would no doubt be db specific so would add extra complexity
 		// to the SQL layer
 		// for now, just do it in code. There won't be many sites to process at
 		// once.
 		for (Site s : sites) {
 			log.debug("Looking at : " + s.getTitle() + " (" + s.getId() + ")");
 			if (!s.isSoftlyDeleted()) {
 				log.warn("Site was in returned list but isn't deleted: " + s.getId());
 			// get calendar for the softly deleted date
 			Date deletedDate = s.getSoftlyDeletedDate();
 			if (deletedDate == null) {
 				log.warn("Site doesn't have a deleted date: " + s.getId());
 			// if this deleted date is before the gracetime, delete the site.
 			if (deletedDate.before(graceDate)) {"Site: " + s.getId() + " is due for deletion");
 				try {"Removed site: " + s.getId());
catch (PermissionException e) {
					log.error("Error removing site: " + s.getId() + ", " + e.getMessage());
catch (IdUnusedException e) {
					log.error("Error removing site: " + s.getId() + ", " + e.getMessage());
finally {
else {"Site: " + s.getId() + " has not passed the gracetime yet and will be skipped.");
		}"SoftSiteDeletionJob completed.");

Time in the past which sites deleted before can be deleted.

	private Date getGraceDate() {
		// get the gracetime config param in days.
		// get calendar for gracetime
		Calendar grace = Calendar.getInstance();
		grace.add(., -gracetime);
		Date graceDate = grace.getTime();
		log.debug("Grace set to: " + graceDate);
		return graceDate;

Setup a security advisor for this transaction
	private void enableSecurityAdvisor() {

Remove security advisor
	private void disableSecurityAdvisor() {
New to GrepCode? Check out our FAQ X