001/*
002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     matic
016 */
017package org.nuxeo.ecm.platform.management.statuses;
018
019import java.util.Calendar;
020
021import org.nuxeo.ecm.core.api.DocumentModel;
022import org.nuxeo.ecm.core.management.api.Probe;
023import org.nuxeo.ecm.core.management.api.ProbeStatus;
024import org.nuxeo.ecm.core.management.storage.DocumentStoreSessionRunner;
025
026/**
027 * @author Stephane Lacoin (Nuxeo EP Software Engineer)
028 */
029public class PopulateRepositoryProbe implements Probe {
030
031    public static class Runner extends DocumentStoreSessionRunner {
032
033        protected String info;
034
035        @Override
036        public void run() {
037            DocumentModel rootDocument = session.getRootDocument();
038            String name = String.format("%s:%x", PopulateRepositoryProbe.class.getSimpleName(),
039                    Calendar.getInstance().getTimeInMillis());
040            DocumentModel doc = session.createDocumentModel(rootDocument.getPathAsString(), name, "File");
041            doc.setProperty("dublincore", "title", name);
042            doc.setProperty("uid", "major_version", 1L);
043            doc = session.createDocument(doc);
044            session.removeDocument(doc.getRef());
045            info = "Created document " + doc.getPathAsString() + " and  removed it ";
046        }
047
048    }
049
050    @Override
051    public ProbeStatus run() {
052        Runner runner = new Runner();
053        runner.runUnrestricted();
054        return ProbeStatus.newSuccess(runner.info);
055    }
056
057}