log.debug("Storing Trigger: " + newTrigger.getFullName());
ReplaceableItem item = null;
try {
List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
attributes.add(new ReplaceableAttribute(TRIGGER_CLASS, newTrigger
.getClass().getName(), true));
attributes.add(new ReplaceableAttribute(TRIGGER_NAME, newTrigger
.getName(), true));
if (newTrigger.getCalendarName() != null) {
attributes.add(new ReplaceableAttribute(TRIGGER_CALENDAR_NAME,
newTrigger.getCalendarName(), true));
}
attributes.add(new ReplaceableAttribute(TRIGGER_GROUP, newTrigger
.getGroup(), true));
attributes.add(new ReplaceableAttribute(TRIGGER_JOB_GROUP,
newTrigger.getJobGroup(), true));
attributes.add(new ReplaceableAttribute(TRIGGER_JOB_NAME,
newTrigger.getJobName(), true));
attributes.add(new ReplaceableAttribute(TRIGGER_PRIORITY, String
.valueOf(newTrigger.getPriority()), true));
if (newTrigger.getEndTime() != null) {
attributes.add(new ReplaceableAttribute(TRIGGER_END_TIME,
dateFormat.format(newTrigger.getEndTime()), true));
}
if (newTrigger.getStartTime() != null) {
attributes.add(new ReplaceableAttribute(TRIGGER_START_TIME,
dateFormat.format(newTrigger.getStartTime()), true));
}
if (newTrigger.getNextFireTime() != null) {
attributes.add(new ReplaceableAttribute(TRIGGER_NEXT_FIRE_TIME,
dateFormat.format(newTrigger.getNextFireTime()), true));
}
item = new ReplaceableItem(
TriggerWrapper.getTriggerNameKey(newTrigger), attributes);
String json = mapper.writeValueAsString(newTrigger);
attributes.add(new ReplaceableAttribute(TRIGGER_JSON_LENGTH, String
.valueOf(json.length()), true));
// Store the JSON representation in multiple attributes since max
// length is 1024
for (int i = 0; json.length() > i * MAX_ATTR_LENGTH; i++) {
int end = Math.min((i + 1) * MAX_ATTR_LENGTH, json.length());
attributes.add(new ReplaceableAttribute(TRIGGER_JSON
+ String.valueOf(i), json.substring(
i * MAX_ATTR_LENGTH, end), true));
}
amazonSimpleDb.batchPutAttributes(new BatchPutAttributesRequest(
triggerDomain, Collections.singletonList(item)));