001/*
002 * (C) Copyright 2006-2011 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 *     bstefanescu
018 */
019package org.nuxeo.runtime.model.persistence;
020
021import java.util.List;
022
023/**
024 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
025 */
026public interface ContributionPersistenceManager {
027
028    /**
029     * Gets a list with all persisted contributions.
030     */
031    List<Contribution> getContributions();
032
033    /**
034     * Gets a contribution given its name.
035     */
036    Contribution getContribution(String name);
037
038    /**
039     * Persists a new contribution. The contribution will not be installed. You need to explicitly call
040     * {@link #installContribution(Contribution)} to install the contribution.
041     */
042    Contribution addContribution(Contribution contrib);
043
044    /**
045     * Removes a persisted contribution given its name. The contribution will not be uninstalled before being removed.
046     * You need to explicitly call {@link #uninstallContribution(Contribution)} to uninstall it.
047     *
048     * @return true if the contribution was removed, false if the contribution was not found in persistence.
049     */
050    boolean removeContribution(Contribution contrib);
051
052    /**
053     * Installs the contribution given its name. Return true if contribution install succeeds, false if the contribution
054     * is already installed.
055     * <p>
056     * To be able to install a contribution you need to persist it first.
057     */
058    boolean installContribution(Contribution contrib);
059
060    /**
061     * Uninstalls a contribution given is name. If not already installed return false otherwise return true. The
062     * contribution persisted state is not modified by this operation.
063     */
064    boolean uninstallContribution(Contribution contrib);
065
066    /**
067     * Updates in the storage the given contribution modifications.
068     * <p>
069     * A contribution cannot be renamed. The only permitted modifications are changing the description and the auto
070     * start status.
071     * <p>
072     * Return back the contribution object.
073     */
074    Contribution updateContribution(Contribution contribution);
075
076    /**
077     * Checks whether a contribution is currently installed.
078     */
079    boolean isInstalled(Contribution contrib);
080
081    /**
082     * Checks whether a contribution is currently persisted.
083     */
084    boolean isPersisted(Contribution contrib);
085
086    /**
087     * Starts the service. This will install all persisted contributions that are marked as auto-install. See
088     * {@link Contribution#isDisabled()}
089     */
090    void start();
091
092    /**
093     * Stops the service. This will uninstall all installed contributions.
094     */
095    void stop();
096
097}