public class ListMetadataService extends AbstractAdmin {
private static final Log log = LogFactory.getLog(ListMetadataService.class);
public ServiceBean listservices(String criteria)throws RegistryException{
UserRegistry registry = (UserRegistry)getGovernanceRegistry();
ServiceBean bean = new ServiceBean();
Resource resource;
String[] path;
try {
path = ListServiceUtil.filterServices(criteria, registry);
} catch (RegistryException e) {
log.error("An error occurred while obtaining the list of services.", e);
path = new String[0];
}
String[] name = new String[path.length];
String[] namespace = new String[path.length];
boolean[] canDelete = new boolean[path.length];
for(int i=0;i<path.length;i++){
bean.increment();
resource = registry.get(path[i]);
if(path[i].startsWith(RegistryConstants.PATH_SEPARATOR+"trunk")){
try {
OMElement omElement = AXIOMUtil.stringToOM(new String((byte[])resource.getContent()));
Iterator it = omElement.getChildrenWithLocalName("overview");
while (it.hasNext()) {
OMElement element = (OMElement) it.next();
Iterator iterator = element.getChildrenWithLocalName("version");
while (iterator.hasNext()) {
OMElement next = (OMElement) iterator.next();
path[i] = org.wso2.carbon.registry.extensions.utils.CommonUtil.computeServicePathWithVersion(path[i],next.getText());
break;
}
}
} catch (XMLStreamException e) {
log.error("Error parsing the resource content",e);
}
}
name[i] = CommonUtil.getServiceName(resource);
namespace[i] = CommonUtil.getServiceNamespace(resource);
if (registry.getUserRealm() != null && registry.getUserName() != null) {
try {
canDelete[i] =
registry.getUserRealm().getAuthorizationManager().isUserAuthorized(
registry.getUserName(),
RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + path[i],
ActionConstants.DELETE);
} catch (UserStoreException e) {
canDelete[i] = false;
}