public static Container copyContainer (Container currentContainer) throws DotDataException, DotStateException, DotSecurityException {
HostAPI hostAPI = APILocator.getHostAPI();
//gets the new information for the template from the request object
Container newContainer = new Container();
newContainer.copy(currentContainer);
newContainer.setFriendlyName(currentContainer.getFriendlyName()
+ " (COPY) ");
newContainer.setTitle(currentContainer.getTitle() + " (COPY) ");
//Copy the structure
// Structure st = StructureCache.getStructureByInode(currentContainer.getStructureInode());
// newContainer.setStructureInode(st.getInode());
//persists the webasset
HibernateUtil.saveOrUpdate(newContainer);
//Copy the host
Host h;
try {
h = hostAPI.findParentHost(currentContainer, APILocator.getUserAPI().getSystemUser(), false);
} catch (DotSecurityException e) {
Logger.error(ContainerFactory.class, e.getMessage(), e);
throw new DotRuntimeException(e.getMessage(), e);
}
//TreeFactory.saveTree(new Tree(h.getIdentifier(), newContainer.getInode()));
//creates new identifier for this webasset and persists it
Identifier newIdentifier = APILocator.getIdentifierAPI().createNew(newContainer, h);
// save identifier id
HibernateUtil.saveOrUpdate(newContainer);
APILocator.getVersionableAPI().setWorking(newContainer);
if(currentContainer.isLive())
APILocator.getVersionableAPI().setLive(newContainer);
PermissionAPI perAPI = APILocator.getPermissionAPI();
//Copy permissions
perAPI.copyPermissions(currentContainer, newContainer);
//saves to working folder under velocity
ContainerServices.invalidate(newContainer, newIdentifier,
true);
// issue-2093 Copying multiple structures per container
if(currentContainer.getMaxContentlets()>0) {
List<ContainerStructure> sourceCS = APILocator.getContainerAPI().getContainerStructures(currentContainer);
List<ContainerStructure> newContainerCS = new LinkedList<ContainerStructure>();
for (ContainerStructure oldCS : sourceCS) {
ContainerStructure newCS = new ContainerStructure();
newCS.setContainerId(newContainer.getIdentifier());
newCS.setStructureId(oldCS.getStructureId());
newCS.setCode(oldCS.getCode());
newContainerCS.add(newCS);
}