/*
 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     "Stephane Lacoin (aka matic) <slacoin@nuxeo.com>"
 */
package org.nuxeo.ecm.platform.tag;

import java.util.Calendar;

import org.nuxeo.common.utils.IdUtils;
import org.nuxeo.common.utils.Path;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.PathRef;
import org.nuxeo.ecm.core.repository.RepositoryInitializationHandler;

/**
 * @author "Stephane Lacoin (aka matic) <slacoin@nuxeo.com>"
 */
public class TagServiceInitializer extends RepositoryInitializationHandler {

    @Override
    public void doInitializeRepository(CoreSession session)
            throws ClientException {

        Path rootTagPath = new Path(session.getRootDocument().getPathAsString());
        String rootTagName = IdUtils.generateId(TagConstants.TAGS_DIRECTORY);
        rootTagPath = rootTagPath.append(rootTagName);

        if (!session.exists(new PathRef(rootTagPath.toString()))) {
            DocumentModel rootTag = session.createDocumentModel(
                    session.getRootDocument().getPathAsString(),
                    rootTagName,
                    TagConstants.HIDDEN_FOLDER_TYPE);
            rootTag.setPropertyValue("dc:title", TagConstants.TAGS_DIRECTORY);
            rootTag.setPropertyValue("dc:description", "");
            rootTag.setPropertyValue("dc:created", Calendar.getInstance());
            rootTag = session.createDocument(rootTag);
            rootTag = session.saveDocument(rootTag);
            session.save();
        }
    }

}

@@ -991,16 +991,312 @@
 athRef;%0A
+import org.nuxeo.ecm.core.api.security.ACE;%0Aimport org.nuxeo.ecm.core.api.security.ACL;%0Aimport org.nuxeo.ecm.core.api.security.ACP;%0Aimport org.nuxeo.ecm.core.api.security.SecurityConstants;%0Aimport org.nuxeo.ecm.core.api.security.impl.ACLImpl;%0Aimport org.nuxeo.ecm.core.api.security.impl.ACPImpl;%0A
 import o
@@ -2432,32 +2432,350 @@
 cument(rootTag);
+%0A%0A            // Add default permission: Read for everybody%0A            ACE ace = new ACE(%22Everyone%22, SecurityConstants.READ, true);%0A            ACL acl = new ACLImpl();%0A            acl.add(ace);%0A            ACP acp = new ACPImpl();%0A            acp.addACL(acl);%0A            session.setACP(rootTag.getRef(), acp, true);
 %0A            ses

Set new ACL on tag root: Everyone has Read permission