protected DatasetConfig doRenameDataset(NamespaceKey oldDatasetPath, NamespaceKey newDatasetPath,
List<NameSpaceContainer> oldDatasetParentEntitiesOnPath, List<NameSpaceContainer> newDatasetParentEntitiesOnPath) throws NamespaceException {
final String newDatasetName = newDatasetPath.getName();
final NamespaceInternalKey oldKey = new NamespaceInternalKey(oldDatasetPath, keyNormalization);
final DatasetConfig datasetConfig = getEntity(oldDatasetPath, DATASET).getDataset();
if (isPhysicalDataset(datasetConfig.getType())) {
throw UserException.validationError()
.message("Failed to rename %s to %s. Renames on physical datasets are not allowed.",
oldDatasetPath, newDatasetPath)
.build(logger);
}
if (datasetConfig.getType() == DatasetType.PHYSICAL_DATASET_HOME_FILE && !newDatasetPath.getPathComponents().get(0).startsWith("@")) {
throw UserException.validationError()
.message("Failed to rename %s to %s. You cannot move a uploaded file in your home directory to a space.",
oldDatasetPath, newDatasetPath)
.build(logger);
}
datasetConfig.setName(newDatasetName);
datasetConfig.setFullPathList(newDatasetPath.getPathComponents());
datasetConfig.setCreatedAt(System.currentTimeMillis());
NamespaceEntity newValue = NamespaceEntity.toEntity(DATASET, newDatasetPath, datasetConfig, keyNormalization);
datasetConfig.setVersion(null);
datasetConfig.setTag(null);
namespace.put(newValue.getPathKey().getKey(), newValue.getContainer());
namespace.delete(oldKey.getKey());
return datasetConfig;
}