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.time.ZonedDateTime; 019import java.util.Optional; 020 021import javax.jcr.Node; 022 023import org.ametys.cms.data.holder.impl.DefaultModifiableModelAwareDataHolder; 024import org.ametys.core.user.UserIdentity; 025import org.ametys.plugins.repository.RepositoryConstants; 026import org.ametys.plugins.repository.data.ametysobject.ModifiableModelAwareDataAwareAmetysObject; 027import org.ametys.plugins.repository.data.holder.ModifiableModelAwareDataHolder; 028import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData; 029import org.ametys.plugins.repository.data.repositorydata.impl.JCRRepositoryData; 030import org.ametys.plugins.repository.jcr.SimpleAmetysObject; 031 032/** 033 * Simple object representing the result of a consistency check. 034 */ 035public class ContentConsistencyResult extends SimpleAmetysObject<ContentConsistencyResultFactory> implements ModifiableModelAwareDataAwareAmetysObject 036{ 037 /** JCR node type for content consistency result */ 038 public static final String CONTENT_CONSISTENCY_RESULT_NODETYPE = RepositoryConstants.NAMESPACE_PREFIX + ":consistencyResult"; 039 040 /** 041 * Creates an {@link ContentConsistencyResult}. 042 * @param node the node backing this result 043 * @param parentPath the parentPath in the Ametys hierarchy 044 * @param factory the factory which created the activity 045 */ 046 public ContentConsistencyResult(Node node, String parentPath, ContentConsistencyResultFactory factory) 047 { 048 super(node, parentPath, factory); 049 } 050 051 /** 052 * Get the content id 053 * @return the content Id 054 */ 055 public String getContentId() 056 { 057 return getValue(ContentConsistencyModel.CONTENT_ID); 058 } 059 060 /** 061 * Get the result date 062 * @return the date 063 */ 064 public ZonedDateTime getDate() 065 { 066 return getValue(ContentConsistencyModel.DATE); 067 } 068 069 /** 070 * Get the unauthorized count 071 * @return the count 072 */ 073 public long getUnauthorizedCount() 074 { 075 return getValue(ContentConsistencyModel.UNAUTHORIZED); 076 } 077 078 /** 079 * Get the unknown count 080 * @return the unknown count 081 */ 082 public long getUnknownCount() 083 { 084 return getValue(ContentConsistencyModel.UNKNOWN); 085 } 086 087 /** 088 * Get the success count 089 * @return the success count 090 */ 091 public long getSuccessCount() 092 { 093 return getValue(ContentConsistencyModel.SUCCESS); 094 } 095 096 /** 097 * Get the not found count 098 * @return the count 099 */ 100 public long getNotFoundCount() 101 { 102 return getValue(ContentConsistencyModel.NOT_FOUND); 103 } 104 105 /** 106 * Get the server error count 107 * @return the count 108 */ 109 public long getServerErrorCount() 110 { 111 return getValue(ContentConsistencyModel.SERVER_ERROR); 112 } 113 114 /** 115 * Get the title 116 * @return the title 117 */ 118 public String getTitle() 119 { 120 return getValue(ContentConsistencyModel.TITLE); 121 } 122 123 /** 124 * Get the content types 125 * @return the content types 126 */ 127 public String[] getContentTypes() 128 { 129 return getValue(ContentConsistencyModel.CONTENT_TYPES); 130 } 131 132 /** 133 * Get the creator 134 * @return the creator 135 */ 136 public UserIdentity getCreator() 137 { 138 return getValue(ContentConsistencyModel.CREATOR); 139 } 140 141 /** 142 * Get the creation date 143 * @return the content creation date 144 */ 145 public ZonedDateTime getCreationDate() 146 { 147 return getValue(ContentConsistencyModel.CREATION_DATE); 148 } 149 150 /** 151 * Get the last major validator 152 * @return the last major validator 153 */ 154 public Optional<UserIdentity> getLastMajorValidator() 155 { 156 return Optional.ofNullable(getValue(ContentConsistencyModel.LAST_MAJOR_VALIDATOR)); 157 } 158 159 /** 160 * Get the last major validation date 161 * @return the last content major validation date 162 */ 163 public ZonedDateTime getLastMajorValidationDate() 164 { 165 return getValue(ContentConsistencyModel.LAST_MAJOR_VALIDATION_DATE); 166 } 167 168 /** 169 * Get the last validator 170 * @return the last validator 171 */ 172 public Optional<UserIdentity> getLastValidator() 173 { 174 return Optional.ofNullable(getValue(ContentConsistencyModel.LAST_VALIDATOR)); 175 } 176 177 /** 178 * Get the last validation date 179 * @return the last content validation date 180 */ 181 public ZonedDateTime getLastValidationDate() 182 { 183 return getValue(ContentConsistencyModel.LAST_VALIDATION_DATE); 184 } 185 186 /** 187 * Get the last contributor 188 * @return the last contributor 189 */ 190 public UserIdentity getLastContributor() 191 { 192 return getValue(ContentConsistencyModel.LAST_CONTRIBUTOR); 193 } 194 195 /** 196 * Get the last modification date 197 * @return the content last modification date 198 */ 199 public ZonedDateTime getLastModificationDate() 200 { 201 return getValue(ContentConsistencyModel.LAST_MODIFICATION_DATE); 202 } 203 204 /** 205 * Get the workflow step 206 * @return the workflow step 207 */ 208 public long getWorkflowStep() 209 { 210 return getValue(ContentConsistencyModel.WORKFLOW_STEP); 211 } 212 213 public ModifiableModelAwareDataHolder getDataHolder() 214 { 215 ModifiableRepositoryData repositoryData = new JCRRepositoryData(getNode()); 216 return new DefaultModifiableModelAwareDataHolder(repositoryData, _getFactory().getContentConsistencyModel()); 217 } 218}