ActionRequestImpl reqImpl = (ActionRequestImpl) req;
HttpServletRequest httpReq = reqImpl.getHttpServletRequest();
// gets the current container being edited from the request object
WebAsset webAsset = (WebAsset) req.getAttribute(webKey);
Identifier identifier = com.dotmarketing.business.APILocator.getIdentifierAPI().find(webAsset);
// gets working container
WebAsset workingWebAsset = (WebAsset) APILocator.getVersionableAPI().findWorkingVersion(identifier,APILocator.getUserAPI().getSystemUser(),false);
// gets live container
WebAsset liveWebAsset = (WebAsset) APILocator.getVersionableAPI().findLiveVersion(identifier,APILocator.getUserAPI().getSystemUser(),false);
// gets folder parent
String parentInode = req.getParameter("parent");
if (parentInode != null && parentInode.length() != 0 && !parentInode.equals("")) {
// the new parent is being passed through the request
Folder parent = (Folder) InodeFactory.getInode(parentInode, Folder.class);
// Checking permissions
_checkCopyAndMovePermissions(webAsset, parent, user, httpReq, "move");
// gets old parent
Folder oldParent = APILocator.getFolderAPI().findParentFolder(workingWebAsset, user, false);
Logger.debug(this, "Old Parent Folder=" + oldParent.getInode());
oldParent.deleteChild(workingWebAsset);
if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) {
oldParent.deleteChild(liveWebAsset);
}
// Adding to new parent
Logger.debug(this, "Parent Folder=" + parent.getInode());
parent.addChild(workingWebAsset);
if ((liveWebAsset != null) && (InodeUtils.isSet(liveWebAsset.getInode()))) {
parent.addChild(liveWebAsset);
}
// gets identifier for this webasset and changes the uri and
// persists it
Host newHost = hostAPI.findParentHost(parent, user, false);
identifier.setHostId(newHost.getIdentifier());
identifier.setURI(workingWebAsset.getURI(parent));
APILocator.getIdentifierAPI().save(identifier);
SessionMessages.add(httpReq, "message", "message." + webAsset.getType() + ".move");
}