001/*
002 *  Copyright 2023 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.consistency;
017
018import java.util.Collection;
019import java.util.List;
020
021import org.apache.avalon.framework.component.Component;
022import org.apache.avalon.framework.service.ServiceException;
023
024import org.ametys.plugins.repository.AmetysRepositoryException;
025import org.ametys.plugins.repository.data.type.ModelItemTypeExtensionPoint;
026import org.ametys.runtime.model.DefaultElementDefinition;
027import org.ametys.runtime.model.Model;
028import org.ametys.runtime.model.ModelItem;
029import org.ametys.runtime.model.exception.BadItemTypeException;
030import org.ametys.runtime.model.exception.UnknownTypeException;
031import org.ametys.runtime.model.type.ModelItemTypeConstants;
032
033/** 
034 * Model of a consistency check.
035 */
036public class ContentConsistencyModel implements Model, Component
037{
038    /** The avalon role */
039    public static final String ROLE = ContentConsistencyModel.class.getName();
040    
041    /** data path for the server error*/
042    public static final String SERVER_ERROR = "serverError";
043    /** data path for the not found error */
044    public static final String NOT_FOUND = "notFound";
045    /** data path for the unauthorized error */
046    public static final String UNAUTHORIZED = "unauthorized";
047    /** data path for the unknown error */
048    public static final String UNKNOWN = "unknown";
049    /** data path for the success checks */
050    public static final String SUCCESS = "success";
051    /** data path for the date of the check */
052    public static final String DATE = "date";
053    /** data path for the workflow step */
054    public static final String WORKFLOW_STEP = "workflowStep";
055    /** data path for the content types */
056    public static final String CONTENT_TYPES = "contentTypes";
057    /** data path for the title */
058    public static final String TITLE = "title";
059    /** data path for the content id */
060    public static final String CONTENT_ID = "contentId";
061    /** data path for the creator */
062    public static final String CREATOR = "creator";
063    /** data path for the last major validator */
064    public static final String LAST_MAJOR_VALIDATOR = "lastMajorValidator";
065    /** data path for the last validator */
066    public static final String LAST_VALIDATOR = "lastValidator";
067    /** data path for the last contributor */
068    public static final String LAST_CONTRIBUTOR = "contributor";
069    /** data path for the context */
070    public static final String CONTEXT = "context";
071    /** data path for the creation date */
072    public static final String CREATION_DATE = "creationDate";
073    /** data path for the content last major validation date */
074    public static final String LAST_MAJOR_VALIDATION_DATE = "lastMajorValidationDate";
075    /** data path for the content last validation date */
076    public static final String LAST_VALIDATION_DATE = "lastValidationDate";
077    /** data path for the content last modification date */
078    public static final String LAST_MODIFICATION_DATE = "lastModified";
079    
080    private Collection<? extends ModelItem> _modelItems;
081
082    public String getId()
083    {
084        return "ContentConsistency";
085    }
086
087    public String getFamilyId()
088    {
089        return "ContentConsistency";
090    }
091
092    public Collection< ? extends ModelItem> getModelItems()
093    {
094        if (_modelItems == null)
095        {
096            try
097            {
098                _modelItems = List.of(
099                        DefaultElementDefinition.of(CONTENT_ID, false, ModelItemTypeConstants.STRING_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
100                        DefaultElementDefinition.of(CONTEXT, false, ModelItemTypeConstants.STRING_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
101                        DefaultElementDefinition.of(TITLE, false, ModelItemTypeConstants.STRING_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
102                        DefaultElementDefinition.of(CONTENT_TYPES, true, ModelItemTypeConstants.STRING_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
103                        DefaultElementDefinition.of(CREATOR, false, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
104                        DefaultElementDefinition.of(CREATION_DATE, false, ModelItemTypeConstants.DATETIME_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
105                        DefaultElementDefinition.of(LAST_MAJOR_VALIDATOR, false, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
106                        DefaultElementDefinition.of(LAST_MAJOR_VALIDATION_DATE, false, ModelItemTypeConstants.DATETIME_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
107                        DefaultElementDefinition.of(LAST_VALIDATOR, false, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
108                        DefaultElementDefinition.of(LAST_VALIDATION_DATE, false, ModelItemTypeConstants.DATETIME_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
109                        DefaultElementDefinition.of(LAST_CONTRIBUTOR, false, org.ametys.cms.data.type.ModelItemTypeConstants.USER_ELEMENT_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
110                        DefaultElementDefinition.of(LAST_MODIFICATION_DATE, false, ModelItemTypeConstants.DATETIME_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
111                        DefaultElementDefinition.of(WORKFLOW_STEP, false, ModelItemTypeConstants.LONG_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
112                        DefaultElementDefinition.of(DATE, false, ModelItemTypeConstants.DATETIME_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
113                        DefaultElementDefinition.of(SUCCESS, false, ModelItemTypeConstants.LONG_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
114                        DefaultElementDefinition.of(UNKNOWN, false, ModelItemTypeConstants.LONG_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
115                        DefaultElementDefinition.of(UNAUTHORIZED, false, ModelItemTypeConstants.LONG_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
116                        DefaultElementDefinition.of(NOT_FOUND, false, ModelItemTypeConstants.LONG_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC),
117                        DefaultElementDefinition.of(SERVER_ERROR, false, ModelItemTypeConstants.LONG_TYPE_ID, ModelItemTypeExtensionPoint.ROLE_MODEL_AWARE_BASIC)
118                );
119            }
120            catch (UnknownTypeException | BadItemTypeException | ServiceException e)
121            {
122                throw new AmetysRepositoryException("An error occurred while create the content consistency result model", e);
123            }
124        }
125        return _modelItems;
126    }
127}