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.activities; 017 018import java.util.HashMap; 019import java.util.List; 020import java.util.Map; 021 022import javax.jcr.RepositoryException; 023 024import org.ametys.plugins.repository.data.holder.DataHolder; 025import org.ametys.runtime.i18n.I18nizableText; 026 027/** 028 * Interface for activity types 029 */ 030public interface ActivityType 031{ 032 /** 033 * Get the ids of the supported event types 034 * @return the ids of the supported event types 035 */ 036 public Map<String, I18nizableText> getSupportedEventTypes(); 037 038 /** 039 * Add the value specific to the activity type to the activity 040 * @param activity the activity 041 * @param parameters the activity parameters 042 * @throws RepositoryException if an error occurs while manipulating the repository 043 */ 044 public default void setAdditionalActivityData (Activity activity, Map<String, Object> parameters) throws RepositoryException 045 { 046 // Nothing to set 047 } 048 049 /** 050 * Determines if two activities can be merged 051 * @param activity1 The first activity 052 * @param activity2 The second activity 053 * @return true if the events can be merged 054 */ 055 public boolean isMergeable (Activity activity1, Activity activity2); 056 057 /** 058 * Merge activities into one activity. 059 * Be careful : be sure that the activities can be merged calling isMergeable method before 060 * @param activities The activities to merge 061 * @return Merged activities 062 */ 063 public Map<String, Object> mergeActivities(List<Activity> activities); 064 065 /** 066 * Retrieve data specific to the {@link ActivityType} that needs to be serialized but are not stored in the {@link DataHolder}. 067 * 068 * Those data will be added to the data of the dataHolder 069 * 070 * @param activity the activity to serialize 071 * @return a json map of the specific data 072 */ 073 public default Map<String, Object> additionnalDataToJSONForClient(Activity activity) 074 { 075 return new HashMap<>(); 076 } 077}