001/* 002 * Copyright 2012 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.web.workflow.archive; 017import java.util.ArrayList; 018import java.util.List; 019 020import org.apache.cocoon.environment.Request; 021 022import org.ametys.cms.content.archive.ArchiveConstants; 023import org.ametys.cms.repository.Content; 024import org.ametys.core.user.population.PopulationContextHelper; 025import org.ametys.web.repository.content.WebContent; 026 027/** 028 * Runnable engine that archive the contents that have an scheduled archiving 029 * date set before the current date. 030 */ 031public class ArchiveContentsSchedulable extends org.ametys.cms.workflow.archive.ArchiveContentsSchedulable 032{ 033 @Override 034 protected String getArchiveActionUri(String contentId) 035 { 036 return "cocoon://_plugins/web/archives/archive/" + ArchiveConstants.ARCHIVE_WORKFLOW_ACTION_ID + "?contentId=" + contentId; 037 } 038 039 @Override 040 protected void setRequestAttributes(Request request, Content content) 041 { 042 if (content instanceof WebContent) 043 { 044 String siteName = ((WebContent) content).getSiteName(); 045 request.setAttribute("siteName", siteName); 046 047 // Set the population contexts to be able to get allowed users 048 List<String> populationContexts = new ArrayList<>(); 049 populationContexts.add("/sites/" + siteName); 050 populationContexts.add("/sites-fo/" + siteName); 051 052 request.setAttribute(PopulationContextHelper.POPULATION_CONTEXTS_REQUEST_ATTR, populationContexts); 053 } 054 } 055 056 @Override 057 protected List<String> getBodyParamsForContributors (Content content, boolean archived) 058 { 059 List<String> params = super.getBodyParamsForContributors(content, archived); 060 061 if (content instanceof WebContent) 062 { 063 WebContent webContent = (WebContent) content; 064 params.add(webContent.getSite().getTitle()); // {3} 065 } 066 067 return params; 068 } 069 070 @Override 071 protected String _getRequestURI(Content content) 072 { 073 String requestUri = super._getRequestURI(content); 074 if (content != null && content instanceof WebContent) 075 { 076 return requestUri + "/" + ((WebContent) content).getSiteName(); 077 } 078 079 return requestUri; 080 } 081 082 @Override 083 protected String _getContentTitle(Content content) 084 { 085 if (content instanceof WebContent) 086 { 087 return content.getTitle() + " (" + ((WebContent) content).getSiteName() + ")"; 088 } 089 else 090 { 091 return content.getTitle(null); 092 } 093 } 094 095}