private static final Log log = LogFactory.getLog(GetVersionsUtil.class);
public static VersionsBean getVersionsBean(UserRegistry userRegistry, String path) throws Exception {
VersionsBean versionsBean = new VersionsBean();
versionsBean.setResourcePath(path);
try {
Resource currentResource = userRegistry.get(path);
if (currentResource != null) {
String isLink = currentResource.getProperty("registry.link");
String mountPoint = currentResource.getProperty("registry.mountpoint");
String targetPoint = currentResource.getProperty("registry.targetpoint");
String actualPath = currentResource.getProperty("registry.actualpath");
if (isLink != null && mountPoint != null && targetPoint != null) {
// path = path.replace(mountPoint, targetPoint);
// This is a symbolic link
currentResource = userRegistry.get(actualPath);
}
}
if (currentResource != null) {
versionsBean.setPermalink(currentResource.getPermanentPath());
currentResource.discard();
}
String[] versions = userRegistry.getVersions(path);
List <VersionPath> versionPaths = new ArrayList <VersionPath> ();
for (String version : versions) {
VersionPath versionPath = new VersionPath();
versionPath.setCompleteVersionPath(version);
versionPath.setActiveResourcePath(path);
ResourcePath resourcePath = new ResourcePath(version);
if (!resourcePath.isCurrentVersion()) {
long versionNumber = Long.parseLong(resourcePath.
getParameterValue(RegistryConstants.VERSION_PARAMETER_NAME));
versionPath.setVersionNumber(versionNumber);
}
Resource versionResource = userRegistry.get(version);
if (versionResource != null) {
versionPath.setUpdater(versionResource.getLastUpdaterUserName());
Calendar versionLastModified = Calendar.getInstance();
versionLastModified.setTime(versionResource.getLastModified());
versionPath.setUpdatedOn(versionLastModified);
versionResource.discard();
}
versionPaths.add(versionPath);
}
versionsBean.setVersionPaths(
versionPaths.toArray(new VersionPath[versionPaths.size()]));
String userName = userRegistry.getUserName();
versionsBean.setLoggedIn(!RegistryConstants.ANONYMOUS_USER.equals(userName));
ResourcePath resourcePath = new ResourcePath(path);
try {
AuthorizationManager authorizer = userRegistry.getUserRealm().getAuthorizationManager();
boolean putAllowed = authorizer.
isUserAuthorized(userName, resourcePath.getPath(), ActionConstants.PUT);
versionsBean.setPutAllowed(putAllowed);
} catch (UserStoreException e) {
String msg = "Failed to check put permissions of user " + userName +
" on the resource " + path + ". " + e.getMessage();