Java Code Examples for org.wso2.carbon.registry.core.session.UserRegistry#get()
The following examples show how to use
org.wso2.carbon.registry.core.session.UserRegistry#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * gets no of verified user challenges * * @param userDTO bean class that contains user and tenant Information * @return no of verified challenges * @throws IdentityException if fails */ public static int getVerifiedChallenges(UserDTO userDTO) throws IdentityException { int noOfChallenges = 0; try { UserRegistry registry = IdentityMgtServiceComponent.getRegistryService(). getConfigSystemRegistry(MultitenantConstants.SUPER_TENANT_ID); String identityKeyMgtPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_CHALLENGES + RegistryConstants.PATH_SEPARATOR + userDTO.getUserId() + RegistryConstants.PATH_SEPARATOR + userDTO.getUserId(); Resource resource; if (registry.resourceExists(identityKeyMgtPath)) { resource = registry.get(identityKeyMgtPath); String property = resource.getProperty(IdentityMgtConstants.VERIFIED_CHALLENGES); if (property != null) { return Integer.parseInt(property); } } } catch (RegistryException e) { log.error("Error while processing userKey", e); } return noOfChallenges; }
Example 2
Source File: CloudServicesUtil.java From attic-stratos with Apache License 2.0 | 6 votes |
public static boolean isCloudServiceActive(String cloudServiceName, int tenantId, UserRegistry govRegistry) throws Exception { // The cloud manager is always active if (StratosConstants.CLOUD_MANAGER_SERVICE.equals(cloudServiceName)) { return true; } String cloudServiceInfoPath = StratosConstants.CLOUD_SERVICE_INFO_STORE_PATH + RegistryConstants.PATH_SEPARATOR + tenantId + RegistryConstants.PATH_SEPARATOR + cloudServiceName; Resource cloudServiceInfoResource; if (govRegistry.resourceExists(cloudServiceInfoPath)) { cloudServiceInfoResource = govRegistry.get(cloudServiceInfoPath); String isActiveStr = cloudServiceInfoResource.getProperty( StratosConstants.CLOUD_SERVICE_IS_ACTIVE_PROP_KEY); return "true".equals(isActiveStr); } return false; }
Example 3
Source File: RegistryTopicManager.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public TopicNode getTopicTree() throws EventBrokerException { try { UserRegistry userRegistry = this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance().getTenantId()); if (!userRegistry.resourceExists(topicStoragePath)) { userRegistry.put(topicStoragePath, userRegistry.newCollection()); } Resource root = userRegistry.get(this.topicStoragePath); TopicNode rootTopic = new TopicNode("/", "/"); buildTopicTree(rootTopic, (Collection) root, userRegistry); return rootTopic; } catch (RegistryException e) { throw new EventBrokerException(e.getMessage(), e); } }
Example 4
Source File: RegistrySubscriptionManager.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public Subscription getSubscription(String id) throws EventBrokerException { try { UserRegistry userRegistry = this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance() .getTenantId()); Resource topicIndexResource = userRegistry.get(this.indexStoragePath); String subscriptionPath = getResourcePath(id, topicIndexResource.getProperty(id)); if (subscriptionPath != null && userRegistry.resourceExists(subscriptionPath)) { Resource subscriptionResource = userRegistry.get(subscriptionPath); Subscription subscription = JavaUtil.getSubscription(subscriptionResource); subscription.setTenantId(EventBrokerHolder.getInstance().getTenantId()); return subscription; } else { return null; } } catch (RegistryException e) { throw new EventBrokerException("Cannot access the registry ", e); } }
Example 5
Source File: CommonUtil.java From carbon-commons with Apache License 2.0 | 6 votes |
/** * validates domain from the successkey * * @param governanceSystemRegistry - The governance system registry * @param domain - tenant domain * @param successKey - successkey * @return true, if successfully validated * @throws RegistryException, if validation failed */ public static boolean validateDomainFromSuccessKey(UserRegistry governanceSystemRegistry, String domain, String successKey) throws RegistryException { String domainValidatorInfoPath = StratosConstants.DOMAIN_VALIDATOR_INFO_PATH + RegistryConstants.PATH_SEPARATOR + domain + RegistryConstants.PATH_SEPARATOR + StratosConstants.VALIDATION_KEY_RESOURCE_NAME; if (governanceSystemRegistry.resourceExists(domainValidatorInfoPath)) { Resource resource = governanceSystemRegistry.get(domainValidatorInfoPath); String actualSuccessKey = resource.getProperty("successKey"); if (actualSuccessKey != null && successKey != null && actualSuccessKey.trim().equals(successKey.trim())) { // the domain is correct return true; } } return false; }
Example 6
Source File: CloudServicesUtil.java From carbon-commons with Apache License 2.0 | 6 votes |
public static boolean isCloudServiceActive(String cloudServiceName, int tenantId, UserRegistry govRegistry) throws Exception { // The cloud manager is always active if (StratosConstants.CLOUD_MANAGER_SERVICE.equals(cloudServiceName)) { return true; } String cloudServiceInfoPath = StratosConstants.CLOUD_SERVICE_INFO_STORE_PATH + RegistryConstants.PATH_SEPARATOR + tenantId + RegistryConstants.PATH_SEPARATOR + cloudServiceName; Resource cloudServiceInfoResource; if (govRegistry.resourceExists(cloudServiceInfoPath)) { cloudServiceInfoResource = govRegistry.get(cloudServiceInfoPath); String isActiveStr = cloudServiceInfoResource.getProperty( StratosConstants.CLOUD_SERVICE_IS_ACTIVE_PROP_KEY); return "true".equals(isActiveStr); } return false; }
Example 7
Source File: MediationSecurityAdminServiceProxy.java From carbon-apimgt with Apache License 2.0 | 6 votes |
public boolean isAliasExist(String alias) throws APIManagementException { UserRegistry registry = GatewayUtils.getRegistry(tenantDomain); PrivilegedCarbonContext.startTenantFlow(); if (tenantDomain != null && StringUtils.isNotEmpty(tenantDomain)) { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); } else { PrivilegedCarbonContext.getThreadLocalCarbonContext() .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); } try { if (registry.resourceExists(APIConstants.API_SYSTEM_CONFIG_SECURE_VAULT_LOCATION)) { Resource resource = registry.get(APIConstants.API_SYSTEM_CONFIG_SECURE_VAULT_LOCATION); if (resource.getProperty(alias) != null) { return true; } } return false; } catch (RegistryException e) { throw new APIManagementException("Error while reading registry resource " + APIConstants.API_SYSTEM_CONFIG_SECURE_VAULT_LOCATION + " for tenant " + tenantDomain); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 8
Source File: CommonUtil.java From attic-stratos with Apache License 2.0 | 6 votes |
/** * validates domain from the successkey * * @param governanceSystemRegistry - The governance system registry * @param domain - tenant domain * @param successKey - successkey * @return true, if successfully validated * @throws RegistryException, if validation failed */ public static boolean validateDomainFromSuccessKey(UserRegistry governanceSystemRegistry, String domain, String successKey) throws RegistryException { String domainValidatorInfoPath = StratosConstants.DOMAIN_VALIDATOR_INFO_PATH + RegistryConstants.PATH_SEPARATOR + domain + RegistryConstants.PATH_SEPARATOR + StratosConstants.VALIDATION_KEY_RESOURCE_NAME; if (governanceSystemRegistry.resourceExists(domainValidatorInfoPath)) { Resource resource = governanceSystemRegistry.get(domainValidatorInfoPath); String actualSuccessKey = resource.getProperty("successKey"); if (actualSuccessKey != null && successKey != null && actualSuccessKey.trim().equals(successKey.trim())) { // the domain is correct return true; } } return false; }
Example 9
Source File: Utils.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * gets no of verified user challenges * * @param userDTO bean class that contains user and tenant Information * @return no of verified challenges * @throws IdentityException if fails */ public static int getVerifiedChallenges(UserDTO userDTO) throws IdentityException { int noOfChallenges = 0; try { UserRegistry registry = IdentityMgtServiceComponent.getRegistryService(). getConfigSystemRegistry(MultitenantConstants.SUPER_TENANT_ID); String identityKeyMgtPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_CHALLENGES + RegistryConstants.PATH_SEPARATOR + userDTO.getUserId() + RegistryConstants.PATH_SEPARATOR + userDTO.getUserId(); Resource resource; if (registry.resourceExists(identityKeyMgtPath)) { resource = registry.get(identityKeyMgtPath); String property = resource.getProperty(IdentityMgtConstants.VERIFIED_CHALLENGES); if (property != null) { return Integer.parseInt(property); } } } catch (RegistryException e) { log.error("Error while processing userKey", e); } return noOfChallenges; }
Example 10
Source File: SequenceUtils.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Gets the velocity template config context with sequence data populated * * @param registry user registry reference * @param resourcePath registry resource path * @param seqType sequence type whether in or out sequence * @param configContext velocity template config context * @return {@link ConfigContext} sequences populated velocity template config context * @throws org.wso2.carbon.registry.api.RegistryException throws when getting registry resource content */ public static ConfigContext getSequenceTemplateConfigContext(UserRegistry registry, String resourcePath, String seqType, ConfigContext configContext) throws org.wso2.carbon.registry.api.RegistryException { Resource regResource; if (registry.resourceExists(resourcePath)) { regResource = registry.get(resourcePath); String[] resources = ((Collection) regResource).getChildren(); JSONObject pathObj = new JSONObject(); if (resources != null) { for (String path : resources) { Resource resource = registry.get(path); String method = resource.getProperty(SOAPToRESTConstants.METHOD); String registryResourceProp = resource.getProperty(SOAPToRESTConstants.Template.RESOURCE_PATH); String resourceName; if (registryResourceProp != null) { resourceName = SOAPToRESTConstants.SequenceGen.PATH_SEPARATOR + registryResourceProp; } else { resourceName = ((ResourceImpl) resource).getName(); resourceName = resourceName.replaceAll(SOAPToRESTConstants.SequenceGen.XML_FILE_RESOURCE_PREFIX, SOAPToRESTConstants.EMPTY_STRING); resourceName = resourceName .replaceAll(SOAPToRESTConstants.SequenceGen.RESOURCE_METHOD_SEPERATOR + method, SOAPToRESTConstants.EMPTY_STRING); resourceName = SOAPToRESTConstants.SequenceGen.PATH_SEPARATOR + resourceName; } String content = RegistryUtils.decodeBytes((byte[]) resource.getContent()); JSONObject contentObj = new JSONObject(); contentObj.put(method, content); pathObj.put(resourceName, contentObj); } } else { log.error("No sequences were found on the resource path: " + resourcePath); } configContext = new SOAPToRESTAPIConfigContext(configContext, pathObj, seqType); } return configContext; }
Example 11
Source File: CarbonRepositoryUtils.java From carbon-commons with Apache License 2.0 | 5 votes |
/** * Save the given DeploymentSynchronizerConfiguration to the registry. The target * configuration registry space will be selected using the specified tenant ID. As a result * the configuration will be stored in the configuration registry of the specified * tenant. * * @param config The configuration to be saved * @param tenantId Tenant ID to select the configuration registry * @throws org.wso2.carbon.registry.core.exceptions.RegistryException if an error occurs while accessing the registry */ public static void persistConfiguration(DeploymentSynchronizerConfiguration config, int tenantId) throws RegistryException { Resource resource; UserRegistry localRepository = getLocalRepository(tenantId); if (!localRepository.resourceExists(DeploymentSynchronizerConstants.CARBON_REPOSITORY)) { resource = localRepository.newResource(); } else { resource = localRepository.get(DeploymentSynchronizerConstants.CARBON_REPOSITORY); } resource.setProperty(DeploymentSynchronizerConstants.AUTO_COMMIT_MODE, String.valueOf(config.isAutoCommit())); resource.setProperty(DeploymentSynchronizerConstants.AUTO_CHECKOUT_MODE, String.valueOf(config.isAutoCheckout())); resource.setProperty(DeploymentSynchronizerConstants.AUTO_SYNC_PERIOD, String.valueOf(config.getPeriod())); resource.setProperty(DeploymentSynchronizerConstants.USE_EVENTING, String.valueOf(config.isUseEventing())); resource.setProperty(DeploymentSynchronizerConstants.REPOSITORY_TYPE, config.getRepositoryType()); resource.setContent(config.isEnabled() ? "enabled" : "disabled"); //Get Repository specific configuration parameters from config object. RepositoryConfigParameter[] parameters = config.getRepositoryConfigParameters(); if (parameters != null && parameters.length != 0) { //Save each Repository specific configuration parameter in registry. for (int i = 0; i < parameters.length; i++) { resource.setProperty(parameters[i].getName(), parameters[i].getValue()); } } localRepository.put(DeploymentSynchronizerConstants.CARBON_REPOSITORY, resource); resource.discard(); }
Example 12
Source File: GatewayUtils.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Add/Update the given registry property from the given tenant registry * path * * @param propertyName property name * @param propertyValue property value * @param path resource path * @param tenantDomain * @throws APIManagementException */ public static void setRegistryProperty(String propertyName, String propertyValue, String path, String tenantDomain) throws APIManagementException { UserRegistry registry = getRegistry(tenantDomain); PrivilegedCarbonContext.startTenantFlow(); if (tenantDomain != null && StringUtils.isNotEmpty(tenantDomain)) { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); } else { PrivilegedCarbonContext.getThreadLocalCarbonContext() .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); } try { Resource resource = registry.get(path); // add or update property if (resource.getProperty(propertyName) != null) { resource.setProperty(propertyName, propertyValue); } else { resource.addProperty(propertyName, propertyValue); } registry.put(resource.getPath(), resource); resource.discard(); } catch (RegistryException e) { throw new APIManagementException("Error while reading registry resource " + path + " for tenant " + tenantDomain); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
Example 13
Source File: RegistrySubscriptionManager.java From carbon-commons with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void unSubscribe(String subscriptionID) throws EventBrokerException { try { UserRegistry userRegistry = this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance() .getTenantId()); String fullPath = this.indexStoragePath; if (userRegistry.resourceExists(fullPath)) { Resource topicIndexResource = userRegistry.get(fullPath); String topicName = topicIndexResource.getProperty(subscriptionID); // delete the subscriptions resource // if the registry is read only there can be situations where the the subscriptions // is not saved to registry and hence the topic name if (topicName != null) { String resourcePath = getResourcePath(subscriptionID, topicName); if (userRegistry.resourceExists(resourcePath)) { userRegistry.delete(resourcePath); } String jMSResourcePath = getJMSSubResourcePath(subscriptionID, topicName); if (userRegistry.resourceExists(jMSResourcePath)) { userRegistry.delete(jMSResourcePath); } } topicIndexResource.removeProperty(subscriptionID); userRegistry.put(fullPath, topicIndexResource); } } catch (RegistryException e) { throw new EventBrokerException("Cannot access the registry ", e); } }
Example 14
Source File: RegistryTopicManager.java From carbon-commons with Apache License 2.0 | 5 votes |
/** * Building the topic tree * * @param topicNode node of the topic * @param resource the resource that holds child topics * @param userRegistry user registry * @throws EventBrokerException */ private void buildTopicTree(TopicNode topicNode, Collection resource, UserRegistry userRegistry) throws EventBrokerException { try { String[] children = resource.getChildren(); if (children != null) { List<TopicNode> nodes = new ArrayList<TopicNode>(); for (String childTopic : children) { Resource childResource = userRegistry.get(childTopic); if (childResource instanceof Collection) { if (childTopic.endsWith("/")) { childTopic = childTopic.substring(0, childTopic.length() - 2); } String nodeName = childTopic.substring(childTopic.lastIndexOf("/") + 1); if (!nodeName.equals(EventBrokerConstants.EB_CONF_WS_SUBSCRIPTION_COLLECTION_NAME) && !nodeName.equals(EventBrokerConstants.EB_CONF_JMS_SUBSCRIPTION_COLLECTION_NAME)) { childTopic = childTopic.substring(childTopic.indexOf(this.topicStoragePath) + this.topicStoragePath.length() + 1); TopicNode childNode = new TopicNode(nodeName, childTopic); nodes.add(childNode); buildTopicTree(childNode, (Collection) childResource, userRegistry); } } } topicNode.setChildren(nodes.toArray(new TopicNode[nodes.size()])); } } catch (RegistryException e) { throw new EventBrokerException(e.getMessage(), e); } }
Example 15
Source File: RegistryTopicManager.java From carbon-commons with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public Subscription[] getJMSSubscriptions(String topicName) throws EventBrokerException { try { Subscription[] subscriptionsArray = new Subscription[0]; UserRegistry userRegistry = this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance().getTenantId()); String resourcePath = JavaUtil.getResourcePath(topicName, this.topicStoragePath); if (!resourcePath.endsWith("/")) { resourcePath = resourcePath + "/"; } resourcePath = resourcePath + EventBrokerConstants.EB_CONF_JMS_SUBSCRIPTION_COLLECTION_NAME; // Get subscriptions if (userRegistry.resourceExists(resourcePath)) { Collection subscriptionCollection = (Collection) userRegistry.get(resourcePath); subscriptionsArray = new Subscription[subscriptionCollection.getChildCount()]; int index = 0; for (String subs : subscriptionCollection.getChildren()) { Collection subscription = (Collection) userRegistry.get(subs); Subscription subscriptionDetails = new Subscription(); subscriptionDetails.setId(subscription.getProperty("Name")); subscriptionDetails.setOwner(subscription.getProperty("Owner")); subscriptionDetails.setCreatedTime(ConverterUtil.convertToDate(subscription.getProperty("createdTime"))); subscriptionsArray[index++] = subscriptionDetails; } } return subscriptionsArray; } catch (RegistryException e) { throw new EventBrokerException("Cannot read the registry resources ", e); } }
Example 16
Source File: CloudServicesUtil.java From carbon-commons with Apache License 2.0 | 4 votes |
public static void setCloudServiceActive(boolean active, String cloudServiceName, int tenantId, CloudServiceConfig cloudServiceConfig) throws Exception { if (cloudServiceConfig.getLabel() == null) { // for the non-labled services, we are not setting/unsetting the // service active return; } UserRegistry govRegistry = CloudCommonServiceComponent.getGovernanceSystemRegistry( MultitenantConstants.SUPER_TENANT_ID); UserRegistry configRegistry = CloudCommonServiceComponent.getConfigSystemRegistry(tenantId); String cloudServiceInfoPath = StratosConstants.CLOUD_SERVICE_INFO_STORE_PATH + RegistryConstants.PATH_SEPARATOR + tenantId + RegistryConstants.PATH_SEPARATOR + cloudServiceName; Resource cloudServiceInfoResource; if (govRegistry.resourceExists(cloudServiceInfoPath)) { cloudServiceInfoResource = govRegistry.get(cloudServiceInfoPath); } else { cloudServiceInfoResource = govRegistry.newCollection(); } cloudServiceInfoResource.setProperty(StratosConstants.CLOUD_SERVICE_IS_ACTIVE_PROP_KEY, active ? "true" : "false"); govRegistry.put(cloudServiceInfoPath, cloudServiceInfoResource); // then we will copy the permissions List<PermissionConfig> permissionConfigs = cloudServiceConfig.getPermissionConfigs(); for (PermissionConfig permissionConfig : permissionConfigs) { String path = permissionConfig.getPath(); String name = permissionConfig.getName(); if (active) { if (!configRegistry.resourceExists(path)) { Collection collection = configRegistry.newCollection(); collection.setProperty(StratosConstants.DISPLAY_NAME, name); configRegistry.put(path, collection); } } else { if (configRegistry.resourceExists(path)) { configRegistry.delete(path); } } } }
Example 17
Source File: CarbonRepositoryUtils.java From carbon-commons with Apache License 2.0 | 4 votes |
/** * Loads the deployment synchronizer configuration from the configuration registry of the * specified tenant. * * @param tenantId Tenant ID * @return a DeploymentSynchronizerConfiguration object or null * @throws org.wso2.carbon.registry.core.exceptions.RegistryException if the registry cannot be accessed */ public static DeploymentSynchronizerConfiguration getDeploymentSyncConfigurationFromRegistry( int tenantId) throws RegistryException { UserRegistry localRepository = getLocalRepository(tenantId); if (!localRepository.resourceExists(DeploymentSynchronizerConstants.CARBON_REPOSITORY)) { return null; } Resource resource = localRepository.get(DeploymentSynchronizerConstants.CARBON_REPOSITORY); DeploymentSynchronizerConfiguration config = new DeploymentSynchronizerConfiguration(); String status = new String((byte[]) resource.getContent()); if ("enabled".equals(status)) { config.setEnabled(true); } config.setAutoCheckout(Boolean.valueOf(resource.getProperty( DeploymentSynchronizerConstants.AUTO_CHECKOUT_MODE))); config.setAutoCommit(Boolean.valueOf(resource.getProperty( DeploymentSynchronizerConstants.AUTO_COMMIT_MODE))); config.setPeriod(Long.valueOf(resource.getProperty( DeploymentSynchronizerConstants.AUTO_SYNC_PERIOD))); config.setUseEventing(Boolean.valueOf(resource.getProperty( DeploymentSynchronizerConstants.USE_EVENTING))); config.setRepositoryType(resource.getProperty( DeploymentSynchronizerConstants.REPOSITORY_TYPE)); ArtifactRepository repository = RepositoryReferenceHolder.getInstance().getRepositoryByType(config.getRepositoryType()); if (repository == null) { throw new RegistryException("No Repository found for type " + config.getRepositoryType()); } List<RepositoryConfigParameter> parameters = repository.getParameters(); //If repository specific configuration parameters are found. if (parameters != null) { //Find the 'value' of each parameter from the registry by parameter 'name' and attach to parameter for (RepositoryConfigParameter parameter : parameters) { parameter.setValue(resource.getProperty(parameter.getName())); } //Attach parameter list to config object. config.setRepositoryConfigParameters(parameters.toArray(new RepositoryConfigParameter[parameters.size()])); } resource.discard(); return config; }
Example 18
Source File: RegistrySubscriptionManager.java From carbon-commons with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void addSubscription(Subscription subscription) throws EventBrokerException { try { UserRegistry userRegistry = this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance() .getTenantId()); String resourcePath = getResourcePath(subscription.getId(), subscription.getTopicName()); Resource resource = userRegistry.newResource(); resource.setProperty(EventBrokerConstants.EB_RES_SUBSCRIPTION_URL, subscription .getEventSinkURL()); resource.setProperty(EventBrokerConstants.EB_RES_EVENT_DISPATCHER_NAME, subscription .getEventDispatcherName()); if (subscription.getExpires() != null) { resource.setProperty(EventBrokerConstants.EB_RES_EXPIRS, ConverterUtil .convertToString(subscription .getExpires())); } resource.setProperty(EventBrokerConstants.EB_RES_OWNER, subscription.getOwner()); resource.setProperty(EventBrokerConstants.EB_RES_TOPIC_NAME, subscription .getTopicName()); resource.setProperty(EventBrokerConstants.EB_RES_CREATED_TIME, System.currentTimeMillis() + ""); resource.setProperty(EventBrokerConstants.EB_RES_MODE, JavaUtil .getSubscriptionMode(subscription .getTopicName())); //set the other properties of the subscription. Map<String, String> properties = subscription.getProperties(); for (String key : properties.keySet()) { resource.setProperty(key, properties.get(key)); } userRegistry.put(resourcePath, resource); // add the subscription index String fullPath = this.indexStoragePath; Resource topicIndexResource; if (userRegistry.resourceExists(fullPath)) { topicIndexResource = userRegistry.get(fullPath); topicIndexResource.addProperty(subscription.getId(), subscription.getTopicName()); } else { topicIndexResource = userRegistry.newResource(); topicIndexResource.addProperty(subscription.getId(), subscription.getTopicName()); } userRegistry.put(fullPath, topicIndexResource); } catch (RegistryException e) { throw new EventBrokerException("Cannot save to registry ", e); } }
Example 19
Source File: RegistryMatchingManager.java From carbon-commons with Apache License 2.0 | 4 votes |
public List<Subscription> getMatchingSubscriptions(String topicName) throws EventBrokerException { // since all the subscriptions for the same topic is stored in the // same path we can get all the subscriptions by getting all the chlid // resources under to topoic name. String topicResourcePath = JavaUtil.getResourcePath(topicName, this.subscriptionStoragePath); if (!topicResourcePath.endsWith("/")) { topicResourcePath += "/"; } topicResourcePath += EventBrokerConstants.EB_CONF_WS_SUBSCRIPTION_COLLECTION_NAME; List<Subscription> matchingSubscriptions = new ArrayList(); try { UserRegistry userRegistry = this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance().getTenantId()); String subscriptionID = null; if (userRegistry.resourceExists(topicResourcePath)) { Collection subscriptions = (Collection) userRegistry.get(topicResourcePath); String[] subscriptionPaths = (String[]) subscriptions.getContent(); for (String subscriptionPath : subscriptionPaths) { Resource resource = userRegistry.get(subscriptionPath); Subscription subscription = JavaUtil.getSubscription(resource); subscriptionID = subscriptionPath.substring(subscriptionPath.lastIndexOf("/") + 1); subscription.setId(subscriptionID); subscription.setTopicName(topicName); // check for expiration Calendar current = Calendar.getInstance(); //Get current date and time if (subscription.getExpires() != null) { if (current.before(subscription.getExpires())) { // add only valid subscriptions by checking the expiration matchingSubscriptions.add(subscription); } } else { // If a expiration dosen't exisits treat it as a never expire subscription, valid till unsubscribe matchingSubscriptions.add(subscription); } } } } catch (RegistryException e) { throw new EventBrokerException("Can not get the Registry ", e); } return matchingSubscriptions; }
Example 20
Source File: RegistryTopicManager.java From carbon-commons with Apache License 2.0 | 4 votes |
/** * Adds a subscriptions to a list using the resource path provided * * @param resourcePath the topic nam * @param subscriptions a list of subscriptions for the topic * @param pathsQueue the topic folder * @param withChildren to add subscriptions to children. i.e subtopics * @throws EventBrokerException */ private void addSubscriptions(String resourcePath, List<Subscription> subscriptions, Queue<String> pathsQueue, boolean withChildren) throws EventBrokerException { try { UserRegistry userRegistry = this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance().getTenantId()); String subscriptionsPath = getSubscriptionsPath(resourcePath); //first if there are subscriptions for this topic add them. else go to the other folders. if (userRegistry.resourceExists(subscriptionsPath)) { Collection collection = (Collection) userRegistry.get(subscriptionsPath); for (String subscriptionPath : collection.getChildren()) { Resource subscriptionResource = userRegistry.get(subscriptionPath); Subscription subscription = JavaUtil.getSubscription(subscriptionResource); subscription.setTopicName(removeResourcePath(resourcePath)); if (subscriptionPath.endsWith("/")) { subscriptionPath = subscriptionsPath.substring(0, subscriptionPath.lastIndexOf("/")); } subscription.setId(subscriptionPath.substring(subscriptionPath.lastIndexOf("/") + 1)); subscriptions.add(subscription); } } // add child subscriptions only for resource collections if (withChildren) { Resource resource = userRegistry.get(resourcePath); if (resource instanceof Collection) { Collection childResources = (Collection) resource; for (String childResourcePath : childResources.getChildren()) { if ((!EventBrokerConstants.EB_CONF_WS_SUBSCRIPTION_COLLECTION_NAME .contains(childResourcePath)) && (!EventBrokerConstants.EB_CONF_JMS_SUBSCRIPTION_COLLECTION_NAME .contains(childResourcePath))) { // i.e. this folder is a topic folder pathsQueue.add(childResourcePath); } } } } } catch (RegistryException e) { throw new EventBrokerException("Cannot access the registry", e); } }