}
}
//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);
}