Java Code Examples for org.wso2.carbon.registry.core.Resource#getProperties()

The following examples show how to use org.wso2.carbon.registry.core.Resource#getProperties() . 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: CustomAPIIndexer.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public IndexDocument getIndexedDocument(AsyncIndexer.File2Index fileData) throws SolrException, RegistryException {
    Registry registry = GovernanceUtils
            .getGovernanceSystemRegistry(IndexingManager.getInstance().getRegistry(fileData.tenantId));
    String resourcePath = fileData.path.substring(RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH.length());
    Resource resource = null;

    if (registry.resourceExists(resourcePath)) {
        resource = registry.get(resourcePath);
    }
    if (log.isDebugEnabled()) {
        log.debug("CustomAPIIndexer is currently indexing the api at path " + resourcePath);
    }

    // Here we are adding properties as fields, so that we can search the properties as we do for attributes.
    IndexDocument indexDocument = super.getIndexedDocument(fileData);
    Map<String, List<String>> fields = indexDocument.getFields();
    if (resource != null) {
        Properties properties = resource.getProperties();
        Enumeration propertyNames = properties.propertyNames();
        while (propertyNames.hasMoreElements()) {
            String property = (String) propertyNames.nextElement();
            if (log.isDebugEnabled()) {
                log.debug("API at " + resourcePath + " has " + property + " property");
            }
            if (property.startsWith(APIConstants.API_RELATED_CUSTOM_PROPERTIES_PREFIX)) {
                fields.put((OVERVIEW_PREFIX + property), getLowerCaseList(resource.getPropertyValues(property)));
                if (log.isDebugEnabled()) {
                    log.debug(property + " is added as " + (OVERVIEW_PREFIX + property) + " field for indexing");
                }
            }
        }
        indexDocument.setFields(fields);
    }
    return indexDocument;
}
 
Example 2
Source File: JavaUtil.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * creates the subscription object from the subscription resource
 *
 * @param subscriptionResource
 * @return
 */
public static Subscription getSubscription(Resource subscriptionResource) {

    Subscription subscription = new Subscription();
    subscription.setTenantId(CarbonContext.getThreadLocalCarbonContext().getTenantId());
    Properties properties = subscriptionResource.getProperties();
    if ((properties != null) && (!properties.isEmpty())) {
        for (Enumeration enumeration = properties.propertyNames(); enumeration.hasMoreElements();) {
            String propertyName = (String) enumeration.nextElement();
            if (EventBrokerConstants.EB_RES_SUBSCRIPTION_URL.equals(propertyName)) {
                subscription.setEventSinkURL(
                        subscriptionResource.getProperty(EventBrokerConstants.EB_RES_SUBSCRIPTION_URL));
            } else if (EventBrokerConstants.EB_RES_EVENT_DISPATCHER_NAME.equals(propertyName)) {
                subscription.setEventDispatcherName(
                        subscriptionResource.getProperty(EventBrokerConstants.EB_RES_EVENT_DISPATCHER_NAME));
            } else if (EventBrokerConstants.EB_RES_EXPIRS.equals(propertyName)) {
                subscription.setExpires(
                        ConverterUtil.convertToDateTime(
                                subscriptionResource.getProperty(EventBrokerConstants.EB_RES_EXPIRS)));
            } else if (EventBrokerConstants.EB_RES_OWNER.equals(propertyName)) {
                subscription.setOwner(subscriptionResource.getProperty(EventBrokerConstants.EB_RES_OWNER));
            } else if (EventBrokerConstants.EB_RES_TOPIC_NAME.equals(propertyName)) {
                subscription.setTopicName(subscriptionResource.getProperty(EventBrokerConstants.EB_RES_TOPIC_NAME));
            } else if (EventBrokerConstants.EB_RES_CREATED_TIME.equals(propertyName)) {
                subscription.setCreatedTime(new Date(Long.parseLong(subscriptionResource.getProperty(EventBrokerConstants.EB_RES_CREATED_TIME))));
            } else if (EventBrokerConstants.EB_RES_MODE.equals(propertyName)) {
                subscription.setMode(subscriptionResource.getProperty(EventBrokerConstants.EB_RES_MODE));
            } else {
                subscription.addProperty(propertyName, subscriptionResource.getProperty(propertyName));
            }
        }
    }
    return subscription;
}
 
Example 3
Source File: MetadataApiRegistry.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private List<Property> getRegistryResourceProperties(String registryResourcePath, String applicationId)
        throws RegistryException, MetadataException {
    Registry tempRegistry = getRegistry();
    if (!tempRegistry.resourceExists(registryResourcePath)) {
        return null;
    }

    // We are using only super tenant registry to persist
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

    Resource regResource = tempRegistry.get(registryResourcePath);
    ArrayList<Property> newProperties = new ArrayList<>();
    Properties props = regResource.getProperties();
    Enumeration<?> x = props.propertyNames();
    while (x.hasMoreElements()) {
        String key = (String) x.nextElement();
        List<String> values = regResource.getPropertyValues(key);
        Property property = new Property();
        property.setKey(key);
        String[] valueArr = new String[values.size()];
        property.setValues(values.toArray(valueArr));

        newProperties.add(property);
    }
    return newProperties;
}
 
Example 4
Source File: SimplePAPStatusDataHandler.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
private synchronized List<StatusHolder> readStatus(String path, String about) throws EntitlementException {

        Resource resource = null;
        Registry registry = null;
        int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        try {
            registry = EntitlementServiceComponent.getRegistryService().
                    getGovernanceSystemRegistry(tenantId);
            if (registry.resourceExists(path)) {
                resource = registry.get(path);
            }
        } catch (RegistryException e) {
            log.error(e);
            throw new EntitlementException("Error while persisting policy status", e);
        }

        List<StatusHolder> statusHolders = new ArrayList<StatusHolder>();
        if (resource != null && resource.getProperties() != null) {
            Properties properties = resource.getProperties();
            for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                PublisherPropertyDTO dto = new PublisherPropertyDTO();
                dto.setId((String) entry.getKey());
                Object value = entry.getValue();
                if (value instanceof ArrayList) {
                    List list = (ArrayList) entry.getValue();
                    if (list != null && list.size() > 0 && list.get(0) != null) {
                        StatusHolder statusHolder = new StatusHolder(about);
                        if (list.size() > 0 && list.get(0) != null) {
                            statusHolder.setType((String) list.get(0));
                        }
                        if (list.size() > 1 && list.get(1) != null) {
                            statusHolder.setTimeInstance((String) list.get(1));
                        } else {
                            continue;
                        }
                        if (list.size() > 2 && list.get(2) != null) {
                            String user = (String) list.get(2);
                            statusHolder.setUser(user);
                        } else {
                            continue;
                        }
                        if (list.size() > 3 && list.get(3) != null) {
                            statusHolder.setKey((String) list.get(3));
                        }
                        if (list.size() > 4 && list.get(4) != null) {
                            statusHolder.setSuccess(Boolean.parseBoolean((String) list.get(4)));
                        }
                        if (list.size() > 5 && list.get(5) != null) {
                            statusHolder.setMessage((String) list.get(5));
                        }
                        if (list.size() > 6 && list.get(6) != null) {
                            statusHolder.setTarget((String) list.get(6));
                        }
                        if (list.size() > 7 && list.get(7) != null) {
                            statusHolder.setTargetAction((String) list.get(7));
                        }
                        if (list.size() > 8 && list.get(8) != null) {
                            statusHolder.setVersion((String) list.get(8));
                        }
                        statusHolders.add(statusHolder);
                    }
                }
            }
        }
        if (statusHolders.size() > 0) {
            StatusHolder[] array = statusHolders.toArray(new StatusHolder[statusHolders.size()]);
            java.util.Arrays.sort(array, new StatusHolderComparator());
            if (statusHolders.size() > maxRecodes) {
                statusHolders = new ArrayList<StatusHolder>();
                for (int i = 0; i < maxRecodes; i++) {
                    statusHolders.add(array[i]);
                }
                persistStatus(path, statusHolders, true);
            } else {
                statusHolders = new ArrayList<StatusHolder>(Arrays.asList(array));
            }
        }

        return statusHolders;
    }
 
Example 5
Source File: PublisherDataHolder.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public PublisherDataHolder(Resource resource, boolean returnSecrets) {
    List<PublisherPropertyDTO> propertyDTOs = new ArrayList<PublisherPropertyDTO>();
    if (resource != null && resource.getProperties() != null) {
        Properties properties = resource.getProperties();
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            PublisherPropertyDTO dto = new PublisherPropertyDTO();
            dto.setId((String) entry.getKey());
            Object value = entry.getValue();
            if (value instanceof ArrayList) {
                List list = (ArrayList) entry.getValue();
                if (list != null && list.size() > 0 && list.get(0) != null) {
                    dto.setValue((String) list.get(0));

                    if (list.size() > 1 && list.get(1) != null) {
                        dto.setDisplayName((String) list.get(1));
                    }
                    if (list.size() > 2 && list.get(2) != null) {
                        dto.setDisplayOrder(Integer.parseInt((String) list.get(2)));
                    }
                    if (list.size() > 3 && list.get(3) != null) {
                        dto.setRequired(Boolean.parseBoolean((String) list.get(3)));
                    }
                    if (list.size() > 4 && list.get(4) != null) {
                        dto.setSecret(Boolean.parseBoolean((String) list.get(4)));
                    }

                    if (dto.isSecret()) {
                        if (returnSecrets) {
                            String password = dto.getValue();
                            try {
                                password = new String(CryptoUtil.getDefaultCryptoUtil().
                                        base64DecodeAndDecrypt(dto.getValue()));
                            } catch (CryptoException e) {
                                log.error(e);
                                // ignore
                            }
                            dto.setValue(password);
                        }
                    }
                }
            }
            if (MODULE_NAME.equals(dto.getId())) {
                moduleName = dto.getValue();
                continue;
            }

            propertyDTOs.add(dto);
        }
    }
    this.propertyDTOs = propertyDTOs.toArray(new PublisherPropertyDTO[propertyDTOs.size()]);
}
 
Example 6
Source File: SimplePAPStatusDataHandler.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
private synchronized List<StatusHolder> readStatus(String path, String about) throws EntitlementException {

        Resource resource = null;
        Registry registry = null;
        int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        try {
            registry = EntitlementServiceComponent.getRegistryService().
                    getGovernanceSystemRegistry(tenantId);
            if (registry.resourceExists(path)) {
                resource = registry.get(path);
            }
        } catch (RegistryException e) {
            log.error(e);
            throw new EntitlementException("Error while persisting policy status", e);
        }

        List<StatusHolder> statusHolders = new ArrayList<StatusHolder>();
        if (resource != null && resource.getProperties() != null) {
            Properties properties = resource.getProperties();
            for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                PublisherPropertyDTO dto = new PublisherPropertyDTO();
                dto.setId((String) entry.getKey());
                Object value = entry.getValue();
                if (value instanceof ArrayList) {
                    List list = (ArrayList) entry.getValue();
                    if (list != null && list.size() > 0 && list.get(0) != null) {
                        StatusHolder statusHolder = new StatusHolder(about);
                        if (list.size() > 0 && list.get(0) != null) {
                            statusHolder.setType((String) list.get(0));
                        }
                        if (list.size() > 1 && list.get(1) != null) {
                            statusHolder.setTimeInstance((String) list.get(1));
                        } else {
                            continue;
                        }
                        if (list.size() > 2 && list.get(2) != null) {
                            String user = (String) list.get(2);
                            statusHolder.setUser(user);
                        } else {
                            continue;
                        }
                        if (list.size() > 3 && list.get(3) != null) {
                            statusHolder.setKey((String) list.get(3));
                        }
                        if (list.size() > 4 && list.get(4) != null) {
                            statusHolder.setSuccess(Boolean.parseBoolean((String) list.get(4)));
                        }
                        if (list.size() > 5 && list.get(5) != null) {
                            statusHolder.setMessage((String) list.get(5));
                        }
                        if (list.size() > 6 && list.get(6) != null) {
                            statusHolder.setTarget((String) list.get(6));
                        }
                        if (list.size() > 7 && list.get(7) != null) {
                            statusHolder.setTargetAction((String) list.get(7));
                        }
                        if (list.size() > 8 && list.get(8) != null) {
                            statusHolder.setVersion((String) list.get(8));
                        }
                        statusHolders.add(statusHolder);
                    }
                }
            }
        }
        if (statusHolders.size() > 0) {
            StatusHolder[] array = statusHolders.toArray(new StatusHolder[statusHolders.size()]);
            java.util.Arrays.sort(array, new StatusHolderComparator());
            if (statusHolders.size() > maxRecodes) {
                statusHolders = new ArrayList<StatusHolder>();
                for (int i = 0; i < maxRecodes; i++) {
                    statusHolders.add(array[i]);
                }
                persistStatus(path, statusHolders, true);
            } else {
                statusHolders = new ArrayList<StatusHolder>(Arrays.asList(array));
            }
        }

        return statusHolders;
    }
 
Example 7
Source File: PublisherDataHolder.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public PublisherDataHolder(Resource resource, boolean returnSecrets) {
    List<PublisherPropertyDTO> propertyDTOs = new ArrayList<PublisherPropertyDTO>();
    if (resource != null && resource.getProperties() != null) {
        Properties properties = resource.getProperties();
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            PublisherPropertyDTO dto = new PublisherPropertyDTO();
            dto.setId((String) entry.getKey());
            Object value = entry.getValue();
            if (value instanceof ArrayList) {
                List list = (ArrayList) entry.getValue();
                if (list != null && list.size() > 0 && list.get(0) != null) {
                    dto.setValue((String) list.get(0));

                    if (list.size() > 1 && list.get(1) != null) {
                        dto.setDisplayName((String) list.get(1));
                    }
                    if (list.size() > 2 && list.get(2) != null) {
                        dto.setDisplayOrder(Integer.parseInt((String) list.get(2)));
                    }
                    if (list.size() > 3 && list.get(3) != null) {
                        dto.setRequired(Boolean.parseBoolean((String) list.get(3)));
                    }
                    if (list.size() > 4 && list.get(4) != null) {
                        dto.setSecret(Boolean.parseBoolean((String) list.get(4)));
                    }

                    if (dto.isSecret()) {
                        if (returnSecrets) {
                            String password = dto.getValue();
                            try {
                                password = new String(CryptoUtil.getDefaultCryptoUtil().
                                        base64DecodeAndDecrypt(dto.getValue()));
                            } catch (CryptoException e) {
                                log.error(e);
                                // ignore
                            }
                            dto.setValue(password);
                        }
                    }
                }
            }
            if (MODULE_NAME.equals(dto.getId())) {
                moduleName = dto.getValue();
                continue;
            }

            propertyDTOs.add(dto);
        }
    }
    this.propertyDTOs = propertyDTOs.toArray(new PublisherPropertyDTO[propertyDTOs.size()]);
}