All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.enonic.xp.node.NodePublishRequests Maven / Gradle / Ivy

There is a newer version: 7.14.4
Show newest version
package com.enonic.xp.node;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.enonic.xp.annotation.PublicApi;

@PublicApi
public class NodePublishRequests
    implements Iterable
{
    private final Set nodePublishRequests;

    private final Map nodePublishRequestMap;

    private final Set publishAsParentFor = new HashSet<>();

    private final Set publishAsReferredTo = new HashSet<>();

    private final Set publishAsRequested = new HashSet<>();

    private final Set publishAsChildOf = new HashSet<>();

    public int size()
    {
        return this.nodePublishRequests.size();
    }

    public NodePublishRequest get( final NodeId nodeId )
    {
        return nodePublishRequestMap.get( nodeId );
    }

    public Set getPublishAsParentFor()
    {
        return publishAsParentFor;
    }

    public Set getPublishAsChildOf()
    {
        return publishAsChildOf;
    }

    public Set getPublishAsReferredTo()
    {
        return publishAsReferredTo;
    }

    public Set getPublishAsRequested()
    {
        return publishAsRequested;
    }

    @Override
    public Iterator iterator()
    {
        return this.nodePublishRequests.iterator();
    }

    public boolean hasPublishOutsideSelection()
    {
        return !this.publishAsReferredTo.isEmpty() || !this.publishAsParentFor.isEmpty();
    }

    public NodeIds getNodeIds()
    {
        return NodeIds.from( nodePublishRequestMap.keySet() );
    }


    public NodePublishRequests()
    {
        this.nodePublishRequestMap = new HashMap<>();
        this.nodePublishRequests = new HashSet<>();
    }

    public void add( final NodePublishRequest nodePublishRequest )
    {
        if ( nodePublishRequest.reasonParentFor() )
        {
            publishAsParentFor.add( nodePublishRequest );
        }
        else if ( nodePublishRequest.reasonReferredFrom() )
        {
            publishAsReferredTo.add( nodePublishRequest );
        }
        else if ( nodePublishRequest.reasonChildOf() )
        {
            publishAsChildOf.add( nodePublishRequest );
        }
        else
        {
            publishAsRequested.add( nodePublishRequest );
        }

        this.nodePublishRequestMap.put( nodePublishRequest.getNodeId(), nodePublishRequest );
        this.nodePublishRequests.add( nodePublishRequest );
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy