001/* 002 * (C) Copyright 2007-2018 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 * Florent Guillaume 018 * Florent Munch 019 */ 020package org.nuxeo.ecm.core.scheduler; 021 022import org.nuxeo.common.xmap.annotation.XNode; 023import org.nuxeo.common.xmap.annotation.XObject; 024import org.nuxeo.ecm.core.api.NuxeoException; 025 026/** 027 * ScheduleImpl extension definition. 028 */ 029@XObject("schedule") 030public class ScheduleImpl implements Schedule { 031 032 @XNode("@id") 033 public String id; 034 035 /** 036 * @since 10.2 037 */ 038 @XNode("@jobFactoryClass") 039 public Class<? extends EventJobFactory> jobFactoryClass = DefaultEventJobFactory.class; 040 041 @XNode("event") 042 public String eventId; 043 044 // BBB compat with old descriptors. use <event> now for consistency with 045 // EventListenerDescriptor 046 @XNode("eventId") 047 public void setEventId(String eventId) { 048 this.eventId = eventId; 049 } 050 051 @XNode("eventCategory") 052 public String eventCategory; 053 054 @XNode("cronExpression") 055 public String cronExpression; 056 057 /** 058 * @since 10.2 059 */ 060 @XNode("timezone") 061 public String timeZone; 062 063 @XNode("username") 064 public String username; 065 066 /** 067 * @since 5.7.3 068 */ 069 @XNode("@enabled") 070 public boolean enabled = true; 071 072 @Override 073 public String getId() { 074 return id; 075 } 076 077 @Override 078 public EventJobFactory getJobFactory() { 079 try { 080 return jobFactoryClass.getDeclaredConstructor().newInstance(); 081 } catch (ReflectiveOperationException e) { 082 throw new NuxeoException("Failed to instantiate job factory " + jobFactoryClass, e); 083 } 084 } 085 086 @Override 087 public String getEventId() { 088 return eventId; 089 } 090 091 @Override 092 public String getEventCategory() { 093 return eventCategory; 094 } 095 096 @Override 097 public String getCronExpression() { 098 return cronExpression; 099 } 100 101 @Override 102 public String getUsername() { 103 return username; 104 } 105 106 @Override 107 public String toString() { 108 return "Schedule " + id + " (cron=" + cronExpression + ')'; 109 } 110 111 @Override 112 public boolean equals(Object obj) { 113 if (obj == null) { 114 return false; 115 } 116 if (!(obj instanceof Schedule)) { 117 return false; 118 } 119 return id.equals(((Schedule) obj).getId()); 120 } 121 122 @Override 123 public int hashCode() { 124 return id.hashCode(); 125 } 126 127 @Override 128 public boolean isEnabled() { 129 return enabled; 130 } 131 132 133 /** 134 * @since 10.2 135 */ 136 @Override 137 public String getTimeZone() { 138 return timeZone; 139 } 140}