import java.util.List;
public class TagBeanPopulator {
public static TagBean populate(UserRegistry userRegistry, String path) {
TagBean tagBean = new TagBean();
try {
Resource resource = userRegistry.get(path);
org.wso2.carbon.registry.core.Tag[] t = userRegistry.getTags(path);
Tag[] tags = new Tag [t.length];
Tag tag;
for(int i=0; i<t.length; i++) {
tag = new Tag();
tag.setCategory(t[i].getCategory());
tag.setTagCount(t[i].getTagCount());
tag.setTagName(t[i].getTagName());
tags[i] = tag;
}
tagBean.setTags(tags);
ResourcePath resourcePath = new ResourcePath(path);
tagBean.setPathWithVersion(resourcePath.getPathWithVersion());
tagBean.setVersionView(!resourcePath.isCurrentVersion());
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);
tagBean.setPutAllowed(
UserUtil.isPutAllowed(userRegistry.getUserName(), tempPath, userRegistry));
} else if (user != null) {
if (userRegistry.getUserName().equals(user)) {
tagBean.setPutAllowed(true);
} else {
tagBean.setPutAllowed(UserUtil.isPutAllowed(
userRegistry.getUserName(), path, userRegistry));
}
}
} else {
tagBean.setPutAllowed(UserUtil.isPutAllowed(userRegistry.getUserName(), path, userRegistry));
}
tagBean.setLoggedIn(!RegistryConstants.ANONYMOUS_USER.equals(userRegistry.getUserName()));
} catch (RegistryException e) {
String msg = "Failed to get tagging information of resource . " + e.getMessage();
tagBean.setErrorMessage(msg);
}
return tagBean;
}