Identifier htmlPageIdentifier = APILocator.getIdentifierAPI().find(htmlPage);
Identifier containerIdentifier = APILocator.getIdentifierAPI().find(container);
if (InodeUtils.isSet(identifier.getInode()) && InodeUtils.isSet(htmlPageIdentifier.getInode()) && InodeUtils.isSet(containerIdentifier.getInode())) {
MultiTree mTree = new MultiTree(htmlPageIdentifier.getInode(),containerIdentifier.getInode(),identifier.getInode());
java.util.List<MultiTree> treeList= MultiTreeFactory.getMultiTree(htmlPage, container);
for (int i = 0; i < treeList.size(); i++) {
if(treeList.get(i).getChild().equals(identifier.getInode())){
duplicateContentCheck = true;
session.setAttribute("duplicatedErrorMessage","Content already exists in the same container on the page");
}
}
if(!duplicateContentCheck){
MultiTreeFactory.saveMultiTree(mTree);
//Updating the last mod user and last mod date of the page
htmlPage.setModDate(new Date());
htmlPage.setModUser(user.getUserId());
HibernateUtil.saveOrUpdate(htmlPage);
}
} else {
Logger.error(this, "Error found trying to associate the contentlet inode: " + contentlet.getInode() + "(iden: " + identifier.getInode() + ") " +
"to the container: " + container.getInode() + "(iden: " + containerIdentifier.getInode() + ") " +
"of the page: " + htmlPage.getInode() + "(iden: " + htmlPageIdentifier.getInode() + ") " +
"the system was unable to find some the identifiers (tree error?)!");
}
} catch (DotRuntimeException e) {
Logger.error(this, "Unable to add content to page", e);
} finally {
try {
HibernateUtil.commitTransaction();
}catch(Exception e){
session.setAttribute("duplicatedErrorMessage","Content already exists in the same container on the page");
//res.sendRedirect(referer);
}
}
_sendToReferral(req, res, referer);
return;
}
if (cmd!=null && cmd.equals("removeChild")) {
try {
Logger.debug(DirectorAction.class, "Director :: removeChild");
HibernateUtil.startTransaction();
Contentlet contentlet = new Contentlet();
String cInode = req.getParameter("contentlet");
if(InodeUtils.isSet(cInode)){
contentlet = conAPI.find(cInode, user, true);
}
Container container = (Container) InodeFactory.getInode(req.getParameter("container"), Container.class);
HTMLPage htmlPage = (HTMLPage) InodeFactory.getInode(req.getParameter("htmlPage"), HTMLPage.class);
boolean hasPermissionOnPage = perAPI.doesUserHavePermission(htmlPage, PERMISSION_CAN_ADD_CHILDREN, user, false);
boolean hasPermissionOnContainer = perAPI.doesUserHavePermission(container, PERMISSION_READ, user, false);
if(Config.getBooleanProperty("SIMPLE_PAGE_CONTENT_PERMISSIONING", true))
hasPermissionOnContainer = true;
if(!hasPermissionOnContainer || !hasPermissionOnPage) {
throw new DotSecurityException("User has no permission to remove content from container = " + req.getParameter("container") + " on page = " + req.getParameter("htmlPage"));
}
Identifier identifier = APILocator.getIdentifierAPI().find(contentlet);
Logger.debug(DirectorAction.class, "Identifier of Contentlet to be removed=" + identifier.getInode());
Contentlet contentletWorking = conAPI.findContentletByIdentifier(identifier.getInode(), false, contentlet.getLanguageId(), user, true);
Contentlet liveContentlet = conAPI.findContentletByIdentifier(identifier.getInode(), false, contentlet.getLanguageId(), user, true);
Logger.debug(DirectorAction.class, "\n\nContentlet Working to be removed=" + contentletWorking.getInode());
Identifier htmlPageIdentifier = APILocator.getIdentifierAPI().find(htmlPage);
Identifier containerIdentifier = APILocator.getIdentifierAPI().find(container);
MultiTree multiTree = MultiTreeFactory.getMultiTree(htmlPageIdentifier,containerIdentifier,identifier);
Logger.debug(DirectorAction.class, "multiTree=" + multiTree);
MultiTreeFactory.deleteMultiTree(multiTree);
//Updating the last mod user and last mod date of the page
htmlPage.setModDate(new Date());
htmlPage.setModUser(user.getUserId());
HibernateUtil.saveOrUpdate(htmlPage);
} catch (DotRuntimeException e) {
Logger.error(this, "Unable to remove content from page", e);
} finally {
HibernateUtil.commitTransaction();
}
_sendToReferral(req, res, referer);
return;
}
if (cmd!=null && cmd.equals("makeHomePage")) {
Logger.debug(DirectorAction.class, "Director :: makeHomePage");
if (InodeUtils.isSet(req.getParameter("htmlPage"))) {
HTMLPage htmlPage = (HTMLPage) InodeFactory.getInode(req.getParameter("htmlPage"), HTMLPage.class);
Folder folder = APILocator.getFolderAPI().findParentFolder(htmlPage, user, false);
UserPreference up = UserPreferencesFactory.getUserPreferenceValue(user.getUserId(),WebKeys.USER_PREFERENCE_HOME_PAGE);
if (up.getId()>0) {
up.setValue(htmlPage.getURI(folder));
}
else {
up.setUserId(user.getUserId());
up.setPreference(WebKeys.USER_PREFERENCE_HOME_PAGE);
up.setValue(htmlPage.getURI(folder));
}
UserPreferencesFactory.saveUserPreference(up);
}
else {
//the user clicked on set with no page that means unsetting the page
UserPreferencesFactory.deleteUserPreference(user.getUserId(),WebKeys.USER_PREFERENCE_HOME_PAGE);
}
_sendToReferral(req, res, referer);
return;
}
if (cmd!=null && cmd.equals("moveUp")) {
Logger.debug(DirectorAction.class, "Director :: moveUp");
Contentlet contentlet = new Contentlet();
String cInode = req.getParameter("contentlet");
if(InodeUtils.isSet(cInode)){
contentlet = conAPI.find(cInode, user, true);
}
Container container = (Container) InodeFactory.getInode(req.getParameter("container"), Container.class);
HTMLPage htmlPage = (HTMLPage) InodeFactory.getInode(req.getParameter("htmlPage"), HTMLPage.class);
boolean hasPermissionOnPage = perAPI.doesUserHavePermission(htmlPage, PERMISSION_CAN_ADD_CHILDREN, user, false);
boolean hasPermissionOnContainer = perAPI.doesUserHavePermission(container, PERMISSION_READ, user, false);
if(Config.getBooleanProperty("SIMPLE_PAGE_CONTENT_PERMISSIONING", true))
hasPermissionOnContainer = true;
if(!hasPermissionOnContainer || !hasPermissionOnPage) {
throw new DotSecurityException("User has no permission to reorder content on container = " + req.getParameter("container") + " on page = " + req.getParameter("htmlPage"));
}
String staticContainer = req.getParameter("static");
Logger.debug(DirectorAction.class, "staticContainer=" + staticContainer);
java.util.List cletList = new ArrayList();
String sort = (container.getSortContentletsBy() == null) ? "tree_order" : container.getSortContentletsBy();
Identifier idenHtmlPage = APILocator.getIdentifierAPI().find(htmlPage);
Identifier idenContainer = APILocator.getIdentifierAPI().find(container);
cletList = conAPI.findPageContentlets(idenHtmlPage.getInode(),idenContainer.getInode(), sort, true,contentlet.getLanguageId(), user, false);
Logger.debug(DirectorAction.class, "Number of contentlets = " + cletList.size());
int newPosition = cletList.indexOf(contentlet) -1;
if( newPosition >= 0 ) {
idenContainer = APILocator.getIdentifierAPI().find(container);
idenHtmlPage = APILocator.getIdentifierAPI().find(htmlPage);
int x = 0;
Iterator i = cletList.iterator();
while (i.hasNext()) {
Identifier iden;
MultiTree multiTree;
Contentlet c = (Contentlet) i.next();
Logger.debug(DirectorAction.class, "Contentlet inode = " + c.getInode());
if( newPosition == x ) {
iden = APILocator.getIdentifierAPI().find(contentlet);
multiTree = MultiTreeFactory.getMultiTree(idenHtmlPage,idenContainer,iden);
multiTree.setTreeOrder(x);
MultiTreeFactory.saveMultiTree(multiTree);
x++;
}
if (!c.getInode().equalsIgnoreCase(contentlet.getInode())) {
iden = APILocator.getIdentifierAPI().find(c);
multiTree = MultiTreeFactory.getMultiTree(idenHtmlPage,idenContainer,iden);
multiTree.setTreeOrder(x);
MultiTreeFactory.saveMultiTree(multiTree);
x++;
}
}
}
_sendToReferral(req, res, referer);
return;
}
if (cmd!=null && cmd.equals("moveDown")) {
Logger.debug(DirectorAction.class, "Director :: moveDown");
Contentlet contentlet = new Contentlet();
String cInode = req.getParameter("contentlet");
if(InodeUtils.isSet(cInode)){
contentlet = conAPI.find(cInode, user, true);
}
Container container = (Container) InodeFactory.getInode(req.getParameter("container"), Container.class);
HTMLPage htmlPage = (HTMLPage) InodeFactory.getInode(req.getParameter("htmlPage"), HTMLPage.class);
String staticContainer = req.getParameter("static");
boolean hasPermissionOnPage = perAPI.doesUserHavePermission(htmlPage, PERMISSION_CAN_ADD_CHILDREN, user, false);
boolean hasPermissionOnContainer = perAPI.doesUserHavePermission(container, PERMISSION_READ, user, false);
if(Config.getBooleanProperty("SIMPLE_PAGE_CONTENT_PERMISSIONING", true))
hasPermissionOnContainer = true;
if(!hasPermissionOnContainer || !hasPermissionOnPage) {
throw new DotSecurityException("User has no permission to reorder content on container = " + req.getParameter("container") + " on page = " + req.getParameter("htmlPage"));
}
Logger.debug(DirectorAction.class, "staticContainer=" + staticContainer);
java.util.List cletList = new ArrayList();
String sort = (container.getSortContentletsBy() == null) ? "tree_order" : container.getSortContentletsBy();
Identifier idenHtmlPage = APILocator.getIdentifierAPI().find(htmlPage);
Identifier idenContainer = APILocator.getIdentifierAPI().find(container);
cletList = conAPI.findPageContentlets(idenHtmlPage.getInode(),idenContainer.getInode(), sort, true,contentlet.getLanguageId(),user,false);
Logger.debug(DirectorAction.class, "Number of contentlets = " + cletList.size());
int newPosition = cletList.indexOf(contentlet) + 1;
if( newPosition < cletList.size() ) {
idenContainer = APILocator.getIdentifierAPI().find(container);
idenHtmlPage = APILocator.getIdentifierAPI().find(htmlPage);
int x = 0;
Iterator i = cletList.iterator();
while (i.hasNext()) {
Identifier iden;
MultiTree multiTree;
Contentlet c = (Contentlet) i.next();
Logger.debug(DirectorAction.class, "Contentlet inode = " + c.getInode());
if (!c.getInode().equalsIgnoreCase(contentlet.getInode())) {
iden = APILocator.getIdentifierAPI().find(c);
multiTree = MultiTreeFactory.getMultiTree(idenHtmlPage,idenContainer,iden);
multiTree.setTreeOrder(x);
MultiTreeFactory.saveMultiTree(multiTree);
x++;
}
if( newPosition == x ) {
iden = APILocator.getIdentifierAPI().find(contentlet);
multiTree = MultiTreeFactory.getMultiTree(idenHtmlPage,idenContainer,iden);
multiTree.setTreeOrder(x);
MultiTreeFactory.saveMultiTree(multiTree);
x++;
}
}