}
}
if (st.getStructureType() == Structure.STRUCTURE_TYPE_FORM) {
contentlet.setHost(formHost.getIdentifier());
Host host = APILocator.getHostAPI().find(formHost.getIdentifier(), APILocator.getUserAPI().getSystemUser(), false);
if (!perAPI.doesUserHavePermissions(host,"PARENT:"+PermissionAPI.PERMISSION_READ+", CONTENTLETS:"+PermissionAPI.PERMISSION_WRITE+"", user)) {
throw new DotSecurityException("User doesn't have write permissions to Contentlet");
}
}
/**
* If the moderator field is set, a work flow task is created
*/
if(UtilMethods.isSet(moderatorRole)){
if(!UtilMethods.isSet(contentlet.getStringProperty(Contentlet.WORKFLOW_ACTION_KEY)))
contentlet.setStringProperty(Contentlet.WORKFLOW_ACTION_KEY, APILocator.getWorkflowAPI().findEntryAction(contentlet, user).getId());
String contentletTitle = "";
List<Field> fields = FieldsCache.getFieldsByStructureInode(contentlet.getStructureInode());
for (Field fld : fields) {
if(fld.isListed()){
contentletTitle = contentlet.getMap().get(fld.getVelocityVarName()).toString();
contentletTitle = contentletTitle.length() > 250 ? contentletTitle.substring(0,250) : contentletTitle;
}
}
contentlet.setStringProperty(Contentlet.WORKFLOW_COMMENTS_KEY, "A new content titled \"" + UtilHTML.escapeHTMLSpecialChars(contentletTitle.trim()) +
"\" has been posted by " + UtilHTML.escapeHTMLSpecialChars(user.getFullName()) + " ("+user.getEmailAddress()+")");
contentlet.setStringProperty(Contentlet.WORKFLOW_ASSIGN_KEY, roleAPI.loadRoleByKey(moderatorRole).getId());
}
/*
* Saving file and images
*/
if(fileParameters.size() > 0) {
for(Map<String,Object> value : fileParameters) {
Field field = (Field)value.get("field");
//http://jira.dotmarketing.net/browse/DOTCMS-3463
if(field.getFieldType().equals(Field.FieldType.IMAGE.toString())||
field.getFieldType().equals(Field.FieldType.FILE.toString())){
java.io.File uploadedFile = (java.io.File)value.get("file");
try {
if(!UtilMethods.isSet(FileUtil.getBytes(uploadedFile)))
continue;
} catch (IOException e) {
Logger.error(SubmitContentUtil.class, e.getMessage());
}
String title = (String)value.get("title");
Host host = (Host)value.get("host");
addFileToContentlet(contentlet, field,host, uploadedFile, user, title);
}
}
}