001/*
002 *  Copyright 2018 Anyware Services
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 */
016package org.ametys.cms.content.compare;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import org.ametys.cms.contenttype.MetadataSet;
022import org.ametys.cms.repository.Content;
023
024/**
025 * Result of a comparison between 2 contents
026 */
027public class ContentComparatorResult
028{
029    private Content _content1;
030    private Content _content2;
031    private String _metadataSetName;
032    private MetadataSet _metadataSet;
033    
034    private boolean _areEquals;
035    private List<ContentComparatorChange> _changes;
036    
037    /**
038     * Create a new result from 2 contents
039     * @param content1 1st content
040     * @param content2 2nd content
041     */
042    public ContentComparatorResult(Content content1, Content content2)
043    {
044        this(content1, content2, null, null);
045    }
046    
047    /**
048     * Create a new result from 2 contents and the name of a metadataSet
049     * @param content1 1st content
050     * @param content2 2nd content
051     * @param metadataSetName name of the MetadataSet
052     * @param metadataSet MetadataSet
053     */
054    public ContentComparatorResult(Content content1, Content content2, String metadataSetName, MetadataSet metadataSet)
055    {
056        this._content1 = content1;
057        this._content2 = content2;
058        this._metadataSetName = metadataSetName;
059        this._metadataSet = metadataSet;
060        if (content1 != null && content2 != null)
061        {
062            this._areEquals = true;
063        }
064        else
065        {
066            this._areEquals = false;
067        }
068        this._changes = new ArrayList<>();
069    }
070    
071    /**
072     * are the contents equals ?
073     * @return true if equals
074     */
075    public boolean areEquals()
076    {
077        return this._areEquals;
078    }
079    
080    /**
081     * If contents are not equals, a list of {@link ContentComparatorChange} is generated
082     * @return list of {@link ContentComparatorChange}
083     */
084    public List<ContentComparatorChange> getChanges()
085    {
086        return this._changes;
087    }
088    
089    /**
090     * get the 1st content of the comparison
091     * @return 1st content
092     */
093    public Content getContent1()
094    {
095        return this._content1;
096    }
097    
098    /**
099     * get the 1st content of the comparison
100     * @return 2nd content
101     */
102    public Content getContent2()
103    {
104        return this._content2;
105    }
106    
107    /**
108     * get the name of the MetadataSet
109     * @return MetadataSet Name (can be null)
110     */
111    public String getMetadataSetName()
112    {
113        return this._metadataSetName;
114    }
115    
116    /**
117     * get the metadataSet (generated from the metadataSet name, of from all metadatas)
118     * @return MetadataSet
119     */
120    public MetadataSet getMetadataSet()
121    {
122        return this._metadataSet;
123    }
124    
125    /**
126     * add a change to the list
127     * @param change a new change
128     */
129    protected void addChange(ContentComparatorChange change)
130    {
131        this._changes.add(change);
132    }
133    
134    /**
135     * declare that the 2 contents are not equals
136     */
137    protected void setNotEquals()
138    {
139        this._areEquals = false;
140    }
141}