{
currentUser = APILocator.getUserAPI().getSystemUser();
}
else
{
return new ActionForward("/dotCMS/login?referrer="+mapping.findForward("addEvent").getPath(),true);
}
}
String startDateDate = request.getParameter("startDateDate");
String startDateTime = request.getParameter("startDateTime");
String endDateDate = request.getParameter("endDateDate");
String endDateTime = request.getParameter("endDateTime");
String description = request.getParameter("description");
String[] categoriesArray = request.getParameterValues("categories");
String title = request.getParameter("title");
String tags = request.getParameter("tags");
String location = request.getParameter("location");
String link = request.getParameter("link");
String options =
(request.getParameter("options") != null?PublicEncryptionFactory.decryptString(request.getParameter("options")):"").replaceAll(" ", "");
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm");
SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("MM/dd/yyyy");
Date startDate = null;
Date endDate = null;
try {
startDate = dateFormat.parse(startDateDate + " " + startDateTime);
} catch (ParseException e) {
ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.invalid", "From date"));
saveMessages(request, ae);
return mapping.findForward("addEvent");
}
try {
endDate = dateFormat.parse(endDateDate + " " + endDateTime);
} catch (ParseException e) {
ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.invalid", "To date"));
saveMessages(request, ae);
return mapping.findForward("addEvent");
}
try {
endDate = dateFormat.parse(endDateDate + " " + endDateTime);
} catch (ParseException e) {
ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.invalid", "To date"));
saveMessages(request, ae);
return mapping.findForward("addEvent");
}
if(!request.getParameter("recurrenceOccurs").equals("never")){
try {
dateOnlyFormat.parse(request.getParameter("recurrenceEnds"));
} catch (ParseException e) {
ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.invalid", "Recurrence end date"));
saveMessages(request, ae);
return mapping.findForward("addEvent");
}
}
//Checking for the folder to store the submitted files
Host host = hostWebAPI.getCurrentHost(request);
Event event = new Event();
Language language = langAPI.getDefaultLanguage();
Folder folder = APILocator.getFolderAPI().findFolderByPath(path, host,APILocator.getUserAPI().getSystemUser(),false);
Structure structure = StructureCache.getStructureByName("Event");
event.setStructureInode(structure.getInode());
if (!InodeUtils.isSet(folder.getInode())){
folder = APILocator.getFolderAPI().createFolders(path, host,userAPI.getSystemUser(),false);
}
List<Category> categoriesList = new ArrayList<Category>();
if (categoriesArray != null) {
for (String cat : categoriesArray ) {
Category node = (Category) catAPI.find(cat, currentUser, respectFrontendRoles);
if(node!=null){
categoriesList.add(node);
}
}
}
event.setStartDate(startDate);
event.setEndDate(endDate);
event.setTitle(title);
event.setTags(tags);
event.setLocation(location);
event.setLink(link);
event.setDescription(description);
event.setLanguageId(language.getId());
FileAsset cmsFile = null;
FileAsset cmsImage = null;
//Get file type parameters
if (request instanceof UploadServletRequest)
{
UploadServletRequest uploadReq = (UploadServletRequest) request;
java.io.File file = uploadReq.getFile("file");
java.io.File image = uploadReq.getFile("image");
if(file != null && file.length() > 0) {
String fileName = uploadReq.getFileName("file");
cmsFile = saveFile(currentUser, host, file, folder, fileName);
event.setProperty("file", cmsFile.getIdentifier());
}
if(image != null && image.length() > 0) {
String fileName = uploadReq.getFileName("image");
cmsImage = saveFile(currentUser, host, image, folder, fileName);
event.setProperty("image", cmsImage.getIdentifier());
}
}
try {
PermissionAPI perAPI = APILocator.getPermissionAPI();
List<Permission> pers = perAPI.getPermissions(event.getStructure());
APILocator.getContentletAPI().checkin(event, categoriesList, pers, currentUser, false);
APILocator.getVersionableAPI().setWorking(event);
} catch (DotContentletValidationException ex) {
Map<String, List<Field>> fields = ex.getNotValidFields();
List<Field> reqFields = fields.get("required");
for(Field f : reqFields) {
if(!f.getFieldType().equals(Field.FieldType.CATEGORY.toString())) {
ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.contentlet.required", f.getFieldName()));
} else {
ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.contentlet.category.required", f.getFieldName()));
}
}
saveMessages(request, ae);
return mapping.findForward("addEvent");
} catch (DotSecurityException e) {
ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("you-do-not-have-the-required-permissions"));
saveMessages(request, ae);
return mapping.findForward("addEvent");
}
Contentlet cont = conAPI.find(event.getInode(), currentUser, respectFrontendRoles);
if(cmsFile != null) {
conAPI.addFileToContentlet(cont, cmsFile.getInode(), "Event:file", currentUser, true);
}
if(cmsImage != null) {
conAPI.addFileToContentlet(cont, cmsImage.getInode(), "Event:image", currentUser, true);
}
if(!request.getParameter("recurrenceOccurs").equals("never")){
EventForm ef = (EventForm) lf;
//EventRecurrence recurrence = new EventRecurrence();
Date startRecurrenceDate = startDate;
Date endRecurrenceDate = ef.getRecurrenceEndsDate();
event.setRecurs(true);
event.setRecurrenceStart(startRecurrenceDate);
event.setRecurrenceEnd(endRecurrenceDate);
event.setNoRecurrenceEnd(ef.isNoEndDate());
SimpleDateFormat dateFormatS = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
event.setOriginalStartDate(dateFormatS.parse(ef.getOriginalStartDate()));
String baseEventId = ef.getDisconnectedFrom();
if(UtilMethods.isSet(baseEventId)){
event.setDisconnectedFrom(baseEventId);
event.setOriginalStartDate(dateFormatS.parse(ef.getOriginalStartDate()));
}
if(ef.getRecurrenceOccurs().equals("daily")){
event.setRecurrenceInterval(ef.getRecurrenceIntervalDaily());
event.setOccursEnum(Event.Occurrency.DAILY);
}else if(ef.getRecurrenceOccurs().equals("monthly")){
event.setRecurrenceDayOfWeek(ef.getRecurrenceDayOfWeek());
event.setRecurrenceWeekOfMonth(ef.getRecurrenceWeekOfMonth());
event.setRecurrenceInterval(ef.getRecurrenceIntervalMonthly());
event.setOccursEnum(Event.Occurrency.MONTHLY);
}else if(ef.getRecurrenceOccurs().equals("weekly")){
String[] recurrenceDaysOfWeek = ef.getRecurrenceDaysOfWeek();
String daysOfWeek = "";
for (String day : recurrenceDaysOfWeek) {
daysOfWeek += day + ",";
}
event.setRecurrenceDaysOfWeek(daysOfWeek);
event.setRecurrenceInterval(ef.getRecurrenceIntervalWeekly());
event.setOccursEnum(Event.Occurrency.WEEKLY);
}else if(ef.getRecurrenceOccurs().equals("annually")){
event.setRecurrenceInterval(ef.getRecurrenceIntervalYearly());
event.setOccursEnum(Event.Occurrency.WEEKLY);
event.setRecurrenceDayOfWeek(ef.getRecurrenceDayOfWeek());
event.setRecurrenceWeekOfMonth(ef.getRecurrenceWeekOfMonth());
event.setRecurrenceMonthOfYear(ef.getRecurrenceMonthOfYear());
}
List<Category> eventCategories = catAPI.getParents(event, currentUser, true);
List<Permission> eventPermissions = perAPI.getPermissions(event);
APILocator.getContentletAPI().checkin(event, eventCategories, eventPermissions, currentUser, false);
if(UtilMethods.isSet(baseEventId)){
Event baseEvent = eventAPI.find(baseEventId, true, currentUser, true);
baseEvent.addDateToIgnore(dateFormatS.parse(ef.getOriginalStartDate()));
eventCategories = catAPI.getParents(baseEvent, currentUser, true);
eventPermissions = perAPI.getPermissions(baseEvent);
APILocator.getContentletAPI().checkin(baseEvent, eventCategories, eventPermissions, currentUser, false);
}
} else {
if(options.contains("autoPublish=true")) {
try {
conAPI.publish(event, currentUser, false);
} catch(DotSecurityException ex) {
Logger.debug(AddEvent.class, ex.toString());
}
}
}
ActionForward af = mapping.findForward("viewCalendar");
HibernateUtil.commitTransaction();
if(!APILocator.getContentletAPI().isInodeIndexed(event.getInode())){
Logger.error(this, "Timed out while waiting for index to return");
}
return af;