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 org.apache.commons.lang3.StringUtils;
019
020import org.ametys.runtime.model.ModelItem;
021import org.ametys.runtime.model.compare.DataChangeType;
022import org.ametys.runtime.model.compare.DataChangeTypeDetail;
023
024/**
025 * One of the changes between 2 contents
026 */
027public class ContentComparatorChange
028{
029    private final String _attributeDataPath;
030    private final String _detailDataPath;
031    private final ModelItem _modelItem;
032    private final DataChangeType _changeType;
033    private final DataChangeTypeDetail _changeTypeDetail;
034    
035    /**
036     * Constructor with no details for this change
037     * @param attributeDataPath path of the attribute data (can be rep[2]/someComposite/someRichText for instance)
038     * @param detailDataPath relative path of the detail (can be lastModified for a RichText for instance)
039     * @param modeItem the model item
040     * @param type type of change
041     */
042    public ContentComparatorChange(String attributeDataPath, String detailDataPath, ModelItem modeItem, DataChangeType type)
043    {
044        this(attributeDataPath, detailDataPath, modeItem, type, DataChangeTypeDetail.NONE);
045    }
046    
047    /**
048     * Constructor with change detail
049     * @param attributeDataPath path of the attribute data (can be rep[2]/someComposite/someRichText for instance)
050     * @param detailDataPath relative path of the detail (can be lastModified for a RichText for instance)
051     * @param modeItem the model item
052     * @param type type of change
053     * @param detail detail of the change
054     */
055    public ContentComparatorChange(String attributeDataPath, String detailDataPath, ModelItem modeItem, DataChangeType type, DataChangeTypeDetail detail)
056    {
057        _attributeDataPath = attributeDataPath;
058        _detailDataPath = detailDataPath;
059        _modelItem = modeItem;
060        _changeType = type;
061        _changeTypeDetail = detail;
062    }
063    
064    /**
065     * path of the change
066     * @return path of the change
067     */
068    public String getPath()
069    {
070        if (StringUtils.isEmpty(_detailDataPath))
071        {
072            return _attributeDataPath;
073        }
074        else
075        {
076            return _attributeDataPath + ModelItem.ITEM_PATH_SEPARATOR + _detailDataPath;
077        }
078    }
079    
080    /**
081     * path of the attribute holding the change (is less specific than {@link #getPath})
082     * @return path of the attribute holding the change
083     */
084    public String getAttributeDataPath()
085    {
086        return _attributeDataPath;
087    }
088    
089    /**
090     * relative path of the detail of the change
091     * @return relative path of the detail of the change
092     */
093    public String getDetailDataPath()
094    {
095        return _detailDataPath;
096    }
097    
098    /**
099     * the model item of the change
100     * @return model item of the change
101     */
102    public ModelItem getModelItem()
103    {
104        return _modelItem;
105    }
106    
107    /**
108     * Type of change
109     * @return Type of change
110     */
111    public DataChangeType getDataChangeType()
112    {
113        return _changeType;
114    }
115    
116    /**
117     * Detail of change
118     * @return Detail of change
119     */
120    public DataChangeTypeDetail getDataChangeTypeDetail()
121    {
122        return _changeTypeDetail;
123    }
124
125    @Override
126    public String toString()
127    {
128        return "ContentComparatorChange [path=" + getPath() + ", changeType=" + _changeType + ", changeTypeDetail=" + _changeTypeDetail + "]";
129    }
130    
131    
132}