001package org.nuxeo.ecm.agenda.operations; 002 003import java.util.Date; 004 005import org.joda.time.DateTime; 006import org.nuxeo.ecm.agenda.AgendaEventBuilder; 007import org.nuxeo.ecm.agenda.AgendaService; 008import org.nuxeo.ecm.automation.core.Constants; 009import org.nuxeo.ecm.automation.core.annotations.Context; 010import org.nuxeo.ecm.automation.core.annotations.Operation; 011import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 012import org.nuxeo.ecm.automation.core.annotations.Param; 013import org.nuxeo.ecm.core.api.CoreSession; 014 015/** 016 * Operation to create a new Agenda Event document 017 * 018 * @author <a href="mailto:akervern@nuxeo.com">Arnaud Kervern</a> 019 * @since 5.6 020 */ 021@Operation(id = CreateAgendaEvent.ID, category = Constants.CAT_DOCUMENT, label = "Create Event", description = "Create a new Event document") 022public class CreateAgendaEvent { 023 protected static final String ID = "VEVENT.Create"; 024 025 @Context 026 protected CoreSession session; 027 028 @Context 029 protected AgendaService agendaService; 030 031 @Param(name = "summary") 032 protected String summary; 033 034 @Param(name = "dtStart") 035 protected Date dtStart; 036 037 @Param(name = "dtEnd", required = false) 038 protected Date dtEnd; 039 040 @Param(name = "contextPath", required = false) 041 protected String contextPath; 042 043 @Param(name = "description", required = false) 044 protected String description = ""; 045 046 @Param(name = "location", required = false) 047 protected String location = ""; 048 049 @OperationMethod 050 public void run() { 051 if (dtEnd == null) { 052 dtEnd = new DateTime(dtStart).plusHours(1).toDate(); 053 } 054 055 AgendaEventBuilder aeb = AgendaEventBuilder.build(summary, dtStart, dtEnd).description(description).location( 056 location); 057 agendaService.createEvent(session, contextPath, aeb.toMap()); 058 } 059}