Index: ivy.xml =================================================================== --- ivy.xml (revision 19862) +++ ivy.xml (working copy) @@ -41,7 +41,7 @@ - + Index: main/plugin-odf-web/src/org/ametys/plugins/odfweb/io/ImportODFWebAction.java =================================================================== --- main/plugin-odf-web/src/org/ametys/plugins/odfweb/io/ImportODFWebAction.java (revision 0) +++ main/plugin-odf-web/src/org/ametys/plugins/odfweb/io/ImportODFWebAction.java (revision 0) @@ -0,0 +1,72 @@ +/* + * Copyright 2012 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ametys.plugins.odfweb.io; + +import java.util.Map; + +import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.cocoon.environment.Redirector; +import org.apache.cocoon.environment.SourceResolver; +import org.apache.commons.lang.BooleanUtils; + +import org.ametys.odf.io.ImportODFAction; +import org.ametys.plugins.odfweb.io.importers.ODFWebImporter; +import org.ametys.web.live.RebuildLiveComponent; + +/** + * This action extends the {@link ImportODFAction}. It imports the ODF and then + * rebuild the live workspace. + */ +public class ImportODFWebAction extends ImportODFAction +{ + /** The rebuild live component */ + protected RebuildLiveComponent _rebuildLiveComponent; + + @Override + public void service(ServiceManager smanager) throws ServiceException + { + super.service(smanager); + _odfImporter = (ODFWebImporter) smanager.lookup(ODFWebImporter.WEB_ROLE); + _rebuildLiveComponent = (RebuildLiveComponent) smanager.lookup(RebuildLiveComponent.ROLE); + } + + @Override + public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception + { + Map result = super.act(redirector, resolver, objectModel, source, parameters); + + // Rebuild live if the import has been successful. + Boolean success = (Boolean) result.get("success"); + if (BooleanUtils.isTrue(success)) + { + // Rebuild live of the site + Map errors = _rebuildLiveComponent.rebuildLiveWorkspace(); + + if (!errors.isEmpty()) + { + String msg = "The ODF has been successfully imported but the rebuilt of the live workspace has failed.\nTry rebuilding the live workspace again."; + getLogger().error(msg); + + result.put("success", false); + result.put("error", msg); + } + } + + return result; + } +} Index: main/plugin-odf-web/src/org/ametys/plugins/odfweb/io/importers/ODFWebImporter.java =================================================================== --- main/plugin-odf-web/src/org/ametys/plugins/odfweb/io/importers/ODFWebImporter.java (revision 0) +++ main/plugin-odf-web/src/org/ametys/plugins/odfweb/io/importers/ODFWebImporter.java (revision 0) @@ -0,0 +1,97 @@ +/* + * Copyright 2012 Anyware Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ametys.plugins.odfweb.io.importers; + +import java.util.Iterator; +import java.util.List; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; +import javax.jcr.Workspace; +import javax.jcr.version.Version; +import javax.jcr.version.VersionHistory; + +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.commons.lang.BooleanUtils; + +import org.ametys.cms.content.archive.ArchiveConstants; +import org.ametys.cms.io.IOConstants; +import org.ametys.cms.io.IOUtils; +import org.ametys.odf.io.importers.ODFImporter; +import org.ametys.plugins.workflow.Workflow; +import org.ametys.plugins.workflow.store.AmetysStep; +import org.ametys.web.WebConstants; + +import com.opensymphony.workflow.spi.Step; + +/** + * ODF web importer + */ +public class ODFWebImporter extends ODFImporter +{ + /** Avalon role. */ + public static final String WEB_ROLE = ODFWebImporter.class.getName(); + + /** The workflow */ + protected Workflow _workflow; + + @Override + public void service(ServiceManager manager) throws ServiceException + { + super.service(manager); + _workflow = (Workflow) manager.lookup(Workflow.ROLE); + } + + @Override + protected void _additionalAdjustementForVersionableNode(Node node, VersionHistory versionHistory) throws RepositoryException + { + Workspace importWorkspace = node.getSession().getWorkspace(); + boolean isArchiveWS = ArchiveConstants.ARCHIVE_WORKSPACE.equals(importWorkspace.getName()); + + // Add live label on validated version. + if (!isArchiveWS) + { + _addLiveLabelIfNecessary(node, versionHistory); + } + } + + /** + * Add the live label on the current version if necessary + * @param node + * @param versionHistory + * @throws RepositoryException + */ + protected void _addLiveLabelIfNecessary(Node node, VersionHistory versionHistory) throws RepositoryException + { + if (node.isNodeType(IOConstants.DEFAULT_CONTENT_NODETYPE) && node.hasProperty(IOConstants.WORKFLOW_ID_PROPERTY)) + { + List currentSteps = _workflow.getCurrentSteps(node.getProperty(IOConstants.WORKFLOW_ID_PROPERTY).getLong()); + Step currentStep = currentSteps.iterator().next(); + + if (currentStep instanceof AmetysStep) + { + Boolean validation = (Boolean) ((AmetysStep) currentStep).getProperty("validation"); + if (BooleanUtils.isTrue(validation)) + { + Iterator versionsIterator = IOUtils.getVersionSortedByCreatedDesc(versionHistory); + Version currentVersion = versionsIterator.next(); + versionHistory.addVersionLabel(currentVersion.getName(), WebConstants.LIVE_LABEL, true); + } + } + } + } +} Index: main/plugin-odf-web/sitemap.xmap =================================================================== --- main/plugin-odf-web/sitemap.xmap (revision 19862) +++ main/plugin-odf-web/sitemap.xmap (working copy) @@ -37,6 +37,8 @@ + + @@ -149,6 +151,16 @@ + + + + + + + + + +