001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others. 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 * 016 * Contributors: 017 * Arnaud Kervern 018 */ 019package org.nuxeo.ecm.agenda.operations; 020 021import java.util.Date; 022 023import org.joda.time.DateTime; 024import org.nuxeo.ecm.agenda.AgendaEventBuilder; 025import org.nuxeo.ecm.agenda.AgendaService; 026import org.nuxeo.ecm.automation.core.Constants; 027import org.nuxeo.ecm.automation.core.annotations.Context; 028import org.nuxeo.ecm.automation.core.annotations.Operation; 029import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 030import org.nuxeo.ecm.automation.core.annotations.Param; 031import org.nuxeo.ecm.core.api.CoreSession; 032 033/** 034 * Operation to create a new Agenda Event document 035 * 036 * @author <a href="mailto:[email protected]">Arnaud Kervern</a> 037 * @since 5.6 038 */ 039@Operation(id = CreateAgendaEvent.ID, category = Constants.CAT_DOCUMENT, label = "Create Event", description = "Create a new Event document") 040public class CreateAgendaEvent { 041 protected static final String ID = "VEVENT.Create"; 042 043 @Context 044 protected CoreSession session; 045 046 @Context 047 protected AgendaService agendaService; 048 049 @Param(name = "summary") 050 protected String summary; 051 052 @Param(name = "dtStart") 053 protected Date dtStart; 054 055 @Param(name = "dtEnd", required = false) 056 protected Date dtEnd; 057 058 @Param(name = "contextPath", required = false) 059 protected String contextPath; 060 061 @Param(name = "description", required = false) 062 protected String description = ""; 063 064 @Param(name = "location", required = false) 065 protected String location = ""; 066 067 @OperationMethod 068 public void run() { 069 if (dtEnd == null) { 070 dtEnd = new DateTime(dtStart).plusHours(1).toDate(); 071 } 072 073 AgendaEventBuilder aeb = AgendaEventBuilder.build(summary, dtStart, dtEnd).description(description).location( 074 location); 075 agendaService.createEvent(session, contextPath, aeb.toMap()); 076 } 077}