public class DependenciesBeanPopulator {
public static DependenciesBean populate(UserRegistry userRegistry, String path) {
DependenciesBean dependenciesBean = new DependenciesBean();
ResourcePath resourcePath = new ResourcePath(path);
try {
Association[] asso = CommonUtil.getAssociations(userRegistry,
(resourcePath.isCurrentVersion() ?
resourcePath.getPath() : resourcePath.getPathWithVersion()));
Resource resource = userRegistry.get(path);
AssociationBean[] beans = new AssociationBean[asso.length];
for (int i = 0; i < beans.length; i++) {
Association as = asso[i];
beans[i] = new AssociationBean(as.getSourcePath(), as.getDestinationPath(),
as.getAssociationType());
}
dependenciesBean.setAssociationBeans(beans);
dependenciesBean.setVersionView(!resourcePath.isCurrentVersion());
dependenciesBean.setPathWithVersion(resourcePath.getPathWithVersion());
List mountPoints = resource.getPropertyValues("registry.mountpoint");
List targetPoints = resource.getPropertyValues("registry.targetpoint");
// List paths = resource.getPropertyValues("registry.path");
List actualPaths = resource.getPropertyValues("registry.actualpath");
String user = resource.getProperty("registry.user");
if (resource.getProperty("registry.link") != null) {
if(mountPoints != null && targetPoints != null) {
// String mountPoint = (String)mountPoints.get(0);
// String targetPoint = (String)targetPoints.get(0);
// String tempPath;
// if (targetPoint.equals(RegistryConstants.PATH_SEPARATOR) && !path.equals(mountPoint)) {
// tempPath = ((String)paths.get(0)).substring(mountPoint.length());
// } else {
// tempPath = targetPoint + ((String)paths.get(0)).substring(mountPoint.length());
// }
String tempPath = (String)actualPaths.get(0);
dependenciesBean.setPutAllowed(
UserUtil.isPutAllowed(userRegistry.getUserName(), tempPath, userRegistry));
} else if (user != null) {
if (userRegistry.getUserName().equals(user)) {
dependenciesBean.setPutAllowed(true);
} else {
dependenciesBean.setPutAllowed(UserUtil.isPutAllowed(
userRegistry.getUserName(), path, userRegistry));
}
}
} else {
dependenciesBean.setPutAllowed(UserUtil.isPutAllowed(userRegistry.getUserName(), path, userRegistry));
}
dependenciesBean.setLoggedIn(!RegistryConstants.ANONYMOUS_USER.equals(userRegistry.getUserName()));
} catch (RegistryException e) {
String msg = "Failed to get dependencies of resource " +
resourcePath + ". " + e.getMessage();
dependenciesBean.setErrorMessage(msg);
}
return dependenciesBean;
}