Skip to content

Commit

Permalink
#17749 Adding fixes to be able to add an container on non-default hos…
Browse files Browse the repository at this point in the history
…t when it is a container in the default host
  • Loading branch information
jdotcms committed Jan 18, 2020
1 parent 752b8d9 commit 589fc1e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
Expand Up @@ -169,11 +169,18 @@ public Container apply(final VelocityResourceKey key) {

private String getContainerPath(final String path, final String hostName) {

String pathHostName = hostName;
int hostIndexOf = path.indexOf(hostName);
final int lastSlash = path.lastIndexOf(StringPool.FORWARD_SLASH);
hostIndexOf = hostIndexOf > 0? hostIndexOf: path.indexOf(FileAssetContainerUtil.getInstance().getHostName(hostName));

return path.substring(hostIndexOf + hostName.length(), lastSlash);
if (hostIndexOf == -1) {

// there are cases where the host does not exists but the host used is the default, so we need to keep the host name in the path.
pathHostName = FileAssetContainerUtil.getInstance().getHostName(path);
hostIndexOf = path.indexOf(pathHostName);
}

return path.substring(hostIndexOf + pathHostName.length(), lastSlash);
}

// /EDIT_MODE///demo.dotcms.com/application/containers/test?languageid=1/LEGACY_RELATION_TYPE.container
Expand Down
Expand Up @@ -74,6 +74,7 @@ public InputStream getResourceStream(final String filePath) throws ResourceNotFo
}

} catch (Exception e) {
Logger.error(this, e.getMessage(), e);
CacheLocator.getVeloctyResourceCache().addMiss(key.path);
throw new ResourceNotFoundException("Cannot parse velocity file : " + key.path, e);
}
Expand Down
Expand Up @@ -3,6 +3,7 @@

import com.beust.jcommander.internal.Maps;
import com.dotcms.business.WrapInTransaction;
import com.dotcms.contenttype.exception.NotFoundInDbException;
import com.dotcms.rendering.velocity.services.ContainerLoader;
import com.dotcms.rendering.velocity.services.VelocityResourceKey;
import com.dotcms.rendering.velocity.util.VelocityUtil;
Expand Down Expand Up @@ -372,9 +373,21 @@ private Container getContainer(final String containerId, final User user, final
final Optional<Host> hostOpt = HostUtil.getHostFromPathOrCurrentHost(containerId, Constants.CONTAINER_FOLDER_PATH);
final Host containerHost = hostOpt.isPresent()? hostOpt.get():host;
final String relativePath = FileAssetContainerUtil.getInstance().getPathFromFullPath(containerHost.getHostname(), containerId);
return mode.showLive?
this.containerAPI.getLiveContainerByFolderPath (relativePath, containerHost, user, mode.respectAnonPerms):
this.containerAPI.getWorkingContainerByFolderPath(relativePath, containerHost, user, mode.respectAnonPerms);
try {

return mode.showLive ?
this.containerAPI.getLiveContainerByFolderPath(relativePath, containerHost, user, mode.respectAnonPerms) :
this.containerAPI.getWorkingContainerByFolderPath(relativePath, containerHost, user, mode.respectAnonPerms);
} catch (NotFoundInDbException e) {

// if does not found in the host path or current host, tries the default one if it is not the same
final Host defaultHost = WebAPILocator.getHostWebAPI().findDefaultHost(user, false);
if (!defaultHost.getIdentifier().equals(containerHost.getIdentifier())) {

return this.containerAPI.getWorkingContainerByFolderPath(relativePath,
defaultHost, APILocator.getUserAPI().getSystemUser(), false);
}
}
}

final ShortyId containerShorty = this.shortyAPI.getShorty(containerId)
Expand Down

0 comments on commit 589fc1e

Please sign in to comment.