001/* 002 * Copyright 2016 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.plugins.repository.events; 017 018import java.util.List; 019import java.util.Map; 020 021import javax.jcr.Node; 022import javax.jcr.RepositoryException; 023 024import org.ametys.plugins.repository.RepositoryConstants; 025import org.ametys.runtime.i18n.I18nizableText; 026 027/** 028 * Interface for event types 029 */ 030public interface EventType 031{ 032 /** Constants for event's date property */ 033 public static final String EVENT_DATE = RepositoryConstants.NAMESPACE_PREFIX + ":date"; 034 /** Constants for event's type property */ 035 public static final String EVENT_TYPE = RepositoryConstants.NAMESPACE_PREFIX + ":type"; 036 /** Constants for event's author property */ 037 public static final String EVENT_AUTHOR = RepositoryConstants.NAMESPACE_PREFIX + ":author"; 038 039 /** 040 * Get the ids of the supported event types 041 * @return the ids of the supported event types 042 */ 043 public Map<String, I18nizableText> getSupportedTypes(); 044 045 /** 046 * Store an event with the given event id under the given event holder node 047 * @param eventId the id of the event to store 048 * @param parameters the event parameters 049 * @param eventHolder the event holder 050 * @return the stored node 051 * @throws RepositoryException if an error occurs while manipulating the repository 052 */ 053 public Node storeEvent(String eventId, Map<String, Object> parameters, EventHolder eventHolder) throws RepositoryException; 054 055 /** 056 * Format an event node to JSON 057 * @param eventNode the node of an event 058 * @return the JSON for the node 059 * @throws RepositoryException if an error occurs while manipulating the repository 060 */ 061 public Map<String, Object> event2JSON(Node eventNode) throws RepositoryException; 062 063 /** 064 * Determines if two events can be merged 065 * @param event1 The first event 066 * @param event2 The second event 067 * @return true if the events can be merged 068 */ 069 public boolean isMergeable (Map<String, Object> event1, Map<String, Object> event2); 070 071 /** 072 * Merge events into one event. 073 * Be careful : be sure that the events can be merged calling isMergeable method before 074 * @param events The events to merge 075 * @return Merged event 076 */ 077 public Map<String, Object> mergeEvents(List<Map<String, Object>> events); 078}