if (name == null) {
name = gwtJahiaNewPortletInstance.getGwtJahiaPortletDefinition().getDefinitionName().replaceAll("/", "___") + Math.round(Math.random() * 1000000l);
}
if (contentManager.checkExistence(parentPath + "/" + name, currentUserSession)) {
throw new GWTJahiaServiceException("A node already exists with name '" + name + "'");
}
JCRNodeWrapper parentNode = currentUserSession.getNode(parentPath);
if (!parentNode.isCheckedOut()) {
parentNode.checkout();
}
JCRPortletNode node = (JCRPortletNode) contentManager.addNode(parentNode, name, gwtJahiaNewPortletInstance.getGwtJahiaPortletDefinition().getPortletType(), null, gwtJahiaNewPortletInstance.getProperties());
node.setApplication(gwtJahiaNewPortletInstance.getGwtJahiaPortletDefinition().getApplicationId(), gwtJahiaNewPortletInstance.getGwtJahiaPortletDefinition().getDefinitionName());
node.revokeAllRoles();
// set modes permissions
if (gwtJahiaNewPortletInstance.getModes() != null) {
for (GWTJahiaNodeACE ace : gwtJahiaNewPortletInstance.getModes().getAce()) {
String user = ace.getPrincipalType() + ":" + ace.getPrincipal();
if (!ace.isInherited()) {
// node.changeRoles(user, ace.getPermissions());
}
}
}
// set roles permissions
if (gwtJahiaNewPortletInstance.getRoles() != null) {
for (GWTJahiaNodeACE ace : gwtJahiaNewPortletInstance.getRoles().getAce()) {
String user = ace.getPrincipalType() + ":" + ace.getPrincipal();
if (!ace.isInherited()) {
// node.changeRoles(user, ace.getPermissions());
}
}
}
// todo default permissions .. ?
// node.changeRoles("g:users", "rw");
// node.changeRoles("g:guest", "r-");
try {
parentNode.save();
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
throw new GWTJahiaServiceException("A system error happened");
}
return navigation.getGWTJahiaNode(node);
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
throw new GWTJahiaServiceException("error");
}
}