001/*
002 * (C) Copyright 2009 Nuxeo SA (http://nuxeo.com/) and others.
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 *
016 * Contributors:
017 *     arussel
018 */
019package org.nuxeo.ecm.platform.routing.core.impl;
020
021import java.io.Serializable;
022import java.util.List;
023
024import org.nuxeo.ecm.core.api.CoreSession;
025import org.nuxeo.ecm.core.api.DocumentModel;
026import org.nuxeo.ecm.platform.routing.api.DocumentRouteStepsContainer;
027import org.nuxeo.ecm.platform.routing.api.DocumentRoutingConstants;
028
029/**
030 * @author arussel
031 */
032public class DocumentRouteStepsContainerImpl extends DocumentRouteElementImpl implements DocumentRouteStepsContainer {
033
034    private static final long serialVersionUID = 1L;
035
036    public DocumentRouteStepsContainerImpl(DocumentModel doc, ElementRunner runner) {
037        super(doc, runner);
038    }
039
040    public void setAttachedDocuments(List<String> documentIds) {
041        document.setPropertyValue(DocumentRoutingConstants.ATTACHED_DOCUMENTS_PROPERTY_NAME,
042                (Serializable) documentIds);
043    }
044
045    @SuppressWarnings("unchecked")
046    public List<String> getAttachedDocuments() {
047        return (List<String>) document.getPropertyValue(DocumentRoutingConstants.ATTACHED_DOCUMENTS_PROPERTY_NAME);
048    }
049
050    @Override
051    public void setDone(CoreSession session) {
052        followTransition(ElementLifeCycleTransistion.toDone, session, false);
053    }
054
055    @Override
056    public void validate(CoreSession session) {
057        // validate this routeModel
058        EventFirer.fireEvent(session, this, null, DocumentRoutingConstants.Events.beforeRouteValidated.name());
059        setValidated(session);
060        EventFirer.fireEvent(session, this, null, DocumentRoutingConstants.Events.afterRouteValidated.name());
061        setReadOnly(session);
062    }
063}