001/* 002 * Copyright 2024 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.properties.section.technical.impl; 017 018import java.util.HashMap; 019import java.util.LinkedHashMap; 020import java.util.Map; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024import org.apache.avalon.framework.service.Serviceable; 025 026import org.ametys.cms.properties.section.technical.AbstractTechnicalItem; 027import org.ametys.core.util.DateUtils; 028import org.ametys.plugins.core.user.UserHelper; 029import org.ametys.plugins.explorer.resources.Resource; 030import org.ametys.plugins.repository.AmetysObject; 031 032/** 033 * Technical section item to display resource updates (creation and modification). 034 */ 035public class ResourceUpdateItem extends AbstractTechnicalItem implements Serviceable 036{ 037 private UserHelper _userHelper; 038 039 @Override 040 public void service(ServiceManager manager) throws ServiceException 041 { 042 _userHelper = (UserHelper) manager.lookup(UserHelper.ROLE); 043 } 044 045 public boolean supports(AmetysObject ametysObject) 046 { 047 return ametysObject instanceof Resource; 048 } 049 050 public Map<String, Object> buildData(AmetysObject ametysObject) 051 { 052 Map<String, Object> resultMap = new LinkedHashMap<>(); 053 054 Resource resource = (Resource) ametysObject; 055 056 Map<String, Object> dataCreator = new HashMap<>(); 057 dataCreator.put("date", DateUtils.dateToString(resource.getCreationDate())); 058 dataCreator.put("user", _userHelper.user2json(resource.getCreator(), true)); 059 resultMap.put("creator", dataCreator); 060 061 Map<String, Object> dataContributor = new HashMap<>(); 062 dataContributor.put("date", DateUtils.dateToString(resource.getLastModified())); 063 dataContributor.put("user", _userHelper.user2json(resource.getLastContributor(), true)); 064 resultMap.put("contributor", dataContributor); 065 066 return resultMap; 067 } 068}