existingId = ident==null || !UtilMethods.isSet(ident.getId());
}
if(UtilMethods.isSet(template.getInode())) {
try {
Template existing=(Template) HibernateUtil.load(Template.class, template.getInode());
existingInode = existing==null || !UtilMethods.isSet(existing.getInode());
}
catch(Exception ex) {
existingInode=true;
}
}
Template oldTemplate = !existingId && UtilMethods.isSet(template.getIdentifier())
?findWorkingTemplate(template.getIdentifier(), user, respectFrontendRoles)
:null;
if ((oldTemplate != null) && InodeUtils.isSet(oldTemplate.getInode())) {
if (!permissionAPI.doesUserHavePermission(oldTemplate, PermissionAPI.PERMISSION_READ, user, respectFrontendRoles)) {
throw new DotSecurityException("You don't have permission to read the source file.");
}
}
if (!permissionAPI.doesUserHavePermission(destination, PermissionAPI.PERMISSION_CAN_ADD_CHILDREN, user, respectFrontendRoles)) {
throw new DotSecurityException("You don't have permission to wirte in the destination folder.");
}
if (!permissionAPI.doesUserHavePermissions(PermissionableType.TEMPLATES, PermissionAPI.PERMISSION_EDIT, user)) {
throw new DotSecurityException("You don't have permission to edit templates.");
}
//gets identifier from the current asset
Identifier identifier = null;
if (oldTemplate != null) {
templateFactory.deleteFromCache(oldTemplate);
identifier = identifierAPI.findFromInode(oldTemplate.getIdentifier());
}
else{
identifier = (!existingId) ? APILocator.getIdentifierAPI().createNew(template, destination) :
APILocator.getIdentifierAPI().createNew(template, destination, template.getIdentifier());
template.setIdentifier(identifier.getId());