Package org.wso2.carbon.registry.search.beans

Examples of org.wso2.carbon.registry.search.beans.AdvancedSearchResultsBean


            PrivilegedCarbonContext.endTenantFlow();
        }
    }

    private void setTenantCredentialsInCarbonContext() {
        PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        cc.setTenantId(ownerTenantId);
        cc.setTenantDomain(ownerTenantDomain);
    }
View Full Code Here


            for (Map.Entry<String, String> e : parameters.entrySet()) {
                params.add(new String[] {e.getKey(), e.getValue()});
            }
            CustomSearchParameterBean parameterBean = new CustomSearchParameterBean();
            parameterBean.setParameterValues(params.toArray(new String[params.size()][]));
            AdvancedSearchResultsBean resultsBean =
                    AdvancedSearchResultsBeanPopulator.populate(null, registry, parameterBean);
            String errorMessage = resultsBean.getErrorMessage();
            if (errorMessage != null) {
                throw new RegistryException(errorMessage);
            }
            return resultsBean.getResourceDataList();
        }
View Full Code Here

*/

    public static AdvancedSearchResultsBean populate(Registry configSystemRegistry, UserRegistry registry,
                                                     CustomSearchParameterBean propertyNameValues) {

        AdvancedSearchResultsBean advancedSearchResultsBean = new AdvancedSearchResultsBean();

        try {

            String[] childPaths =
                    getQueryResult(configSystemRegistry, registry, propertyNameValues.getParameterValues());

            String[][] tempPropValues = propertyNameValues.getParameterValues();

            for (int i = 0; i < tempPropValues.length; i++) {
                if (tempPropValues[i][0].equals("resourcePath")) {
                    String s = tempPropValues[i][1];
                    if (childPaths == null || childPaths.length == 0 && tempPropValues[i][0].indexOf("%") == -1) {
                        tempPropValues[i][1] = tempPropValues[i][1] + "%";
                        String[] s2 = getQueryResult(configSystemRegistry, registry, tempPropValues);
                        tempPropValues[i][1] = tempPropValues[i][1] + "/%";
                        String[] s1 = getQueryResult(configSystemRegistry, registry, tempPropValues);

                        if (s2 != null && s2.length > 0) {
                            Set<String> result = new HashSet<String>();
                            result.addAll(Arrays.asList(s2));
                            if (s1 != null && s1.length > 0) {
                                result.removeAll(Arrays.asList(s1));
                            }
                            childPaths = result.toArray(new String[result.size()]);
                        }
                    }
                    break;
                }
            }


//            if (childPaths == null || childPaths.length == 0 && resourceName.indexOf("%") == -1) {
//                String[] s1 = getQueryResult(configSystemRegistry, registry, resourceName + "%/%",
//                        authorName, updaterName, createdAfter,
//                        createdBefore, updatedAfter, updatedBefore, tags, commentWords,
//                        propertyName, propertyValue,
//                        content);
//                String[] s2 = getQueryResult(configSystemRegistry, registry, resourceName + "%",
//                        authorName, updaterName, createdAfter,
//                        createdBefore, updatedAfter, updatedBefore, tags, commentWords,
//                        propertyName, propertyValue,
//                        content);
//                if (s2 != null && s2.length > 0) {
//                    Set<String> result = new HashSet<String>();
//                    result.addAll(Arrays.asList(s2));
//                    if (s1 != null && s1.length > 0) {
//                        result.removeAll(Arrays.asList(s1));
//                    }
//                    childPaths = result.toArray(new String[result.size()]);
//                }
//            }
            //Temporary fix for CARBON-4562.
            //We should have a search result iterator for advance search.
            //This fix will show only first 25 records
            int resultSize = childPaths.length;
            /*if(resultSize > 40){
              resultSize = 40;
            }*/

            ResourceData[] resourceDataList = new ResourceData[resultSize];
            for (int i = 0; i < resultSize; i++) {

                ResourceData resourceData = new ResourceData();
                resourceData.setResourcePath(childPaths[i]);

                if (childPaths[i] != null) {
                    if (RegistryConstants.ROOT_PATH.equals(childPaths[i])) {
                        resourceData.setName("root");
                    } else {
                        String[] parts = childPaths[i].split(RegistryConstants.PATH_SEPARATOR);
                        resourceData.setName(parts[parts.length - 1]);
                    }
                }

                try {
                    Resource child = registry.get(childPaths[i]);

                    resourceData.setResourceType(child instanceof Collection ?
                                                 "collection" : "resource");
                    resourceData.setAuthorUserName(child.getAuthorUserName());
                    resourceData.setDescription(child.getDescription());
                    resourceData.setAverageRating(registry.getAverageRating(child.getPath()));
                    Calendar createdDateTime = Calendar.getInstance();
                    createdDateTime.setTime(child.getCreatedTime());
                    resourceData.setCreatedOn(createdDateTime);
                    CommonUtil.populateAverageStars(resourceData);

                    child.discard();

                    resourceDataList[i] = resourceData;

                } catch (AuthorizationFailedException e) {
                    // do not show unauthorized resource in search results.
                }

            }

            advancedSearchResultsBean.setResourceDataList(resourceDataList);

        } catch (RegistryException e) {

            String msg = "Failed to get advanced search results. " + e.getMessage();
            advancedSearchResultsBean.setErrorMessage(msg);
        }
        catch (Exception e) {
            log.error("An error occurred while obtaining search results", e);
        }

View Full Code Here

        int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        try {
            UserRegistry userRegistry = RegistryHostObjectContext.getRegistryService().getRegistry(
                    registryHostObject.registry.getUserName(), tenantId);
            Registry configRegistry = RegistryHostObjectContext.getRegistryService().getConfigSystemRegistry(tenantId);
            AdvancedSearchResultsBean resultsBean = registryHostObject.search(configRegistry, userRegistry, parameters);
            if (resultsBean.getResourceDataList() == null) {
                ScriptableObject error = (ScriptableObject) cx.newObject(thisObj);
                error.put("error", error, true);
                error.put("description", error, resultsBean.getErrorMessage());
                return error;
            }
            List<ScriptableObject> results = new ArrayList<ScriptableObject>();
            for (ResourceData resourceData : resultsBean.getResourceDataList()) {
                String resourcePath = resourceData.getResourcePath();
                if (path != null && !resourcePath.startsWith(path)) {
                    continue;
                }
                ScriptableObject result = (ScriptableObject) cx.newObject(thisObj);
View Full Code Here

    }

    private AdvancedSearchResultsBean search(Registry configSystemRegistry, UserRegistry registry,
                                             CustomSearchParameterBean parameters) throws CarbonException {
        RegistryUtils.recordStatistics(parameters);
        AdvancedSearchResultsBean metaDataSearchResultsBean;
        ResourceData[] contentSearchResourceData;
        String[][] tempParameterValues = parameters.getParameterValues();

        //        Doing a validation of all the values sent
        boolean allEmpty = true;
        for (String[] tempParameterValue : tempParameterValues) {
            if (tempParameterValue[1] != null & tempParameterValue[1].trim().length() > 0) {
                allEmpty = false;
                //                Validating all the dates
                if (tempParameterValue[0].equals("createdAfter") || tempParameterValue[0].equals("createdBefore") ||
                        tempParameterValue[0].equals("updatedAfter") || tempParameterValue[0].equals("updatedBefore")) {
                    if (!SearchUtils.validateDateInput(tempParameterValue[1])) {
                        String message = tempParameterValue[0] + " contains illegal characters";
                        return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
                    }
                } else if (tempParameterValue[0].equals("mediaType")) {
                    if (SearchUtils.validateMediaTypeInput(tempParameterValue[1])) {
                        String message = tempParameterValue[0] + " contains illegal characters";
                        return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
                    }
                } else if (tempParameterValue[0].equals("content")) {
                    if (SearchUtils.validateContentInput(tempParameterValue[1])) {
                        String message = tempParameterValue[0] + " contains illegal characters";
                        return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
                    }
                } else if (tempParameterValue[0].equals("tags")) {
                    boolean containsTag = false;
                    for (String str : tempParameterValue[1].split(",")) {
                        if (str.trim().length() > 0) {
                            containsTag = true;
                            break;
                        }
                    }
                    if (!containsTag) {
                        String message = tempParameterValue[0] + " contains illegal characters";
                        return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
                    }
                    if (SearchUtils.validateTagsInput(tempParameterValue[1])) {
                        String message = tempParameterValue[0] + " contains illegal characters";
                        return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
                    }
                } else {
                    if (SearchUtils.validatePathInput(tempParameterValue[1])) {
                        String message = tempParameterValue[0] + " contains illegal characters";
                        return SearchUtils.getEmptyResultBeanWithErrorMsg(message);
                    }
                }
            }
        }

        if (allEmpty) {
            return SearchUtils.getEmptyResultBeanWithErrorMsg("At least one field must be filled");
        }

        boolean onlyContent = true;
        for (String[] tempParameterValue : tempParameterValues) {
            if (!tempParameterValue[0].equals("content") && !tempParameterValue[0].equals("leftOp") &&
                    !tempParameterValue[0].equals("rightOp") && tempParameterValue[1] != null &&
                    tempParameterValue[1].length() > 0) {
                onlyContent = false;
                break;
            }
        }

        for (String[] tempParameterValue : tempParameterValues) {
            if (tempParameterValue[0].equals("content") && tempParameterValue[1] != null &&
                    tempParameterValue[1].length() > 0) {
                try {
                    contentSearchResourceData = search(registry, tempParameterValue[1]);
                } catch (Exception e) {
                    metaDataSearchResultsBean = new AdvancedSearchResultsBean();
                    metaDataSearchResultsBean.setErrorMessage(e.getMessage());
                    return metaDataSearchResultsBean;
                }

                //                If there are no resource paths returned from content, then there is no point of searching for more
                if (contentSearchResourceData != null && contentSearchResourceData.length > 0) {
                    //                    Map<String, ResourceData> resourceDataMap = new HashMap<String, ResourceData>();
                    Map<String, ResourceData> aggregatedMap = new HashMap<String, ResourceData>();

                    for (ResourceData resourceData : contentSearchResourceData) {
                        aggregatedMap.put(resourceData.getResourcePath(), resourceData);
                    }

                    metaDataSearchResultsBean = AdvancedSearchResultsBeanPopulator.populate(configSystemRegistry,
                            registry, parameters);

                    if (metaDataSearchResultsBean != null) {
                        ResourceData[] metaDataResourceData = metaDataSearchResultsBean.getResourceDataList();
                        if (metaDataResourceData != null && metaDataResourceData.length > 0) {

                            List<String> invalidKeys = new ArrayList<String>();
                            for (String key : aggregatedMap.keySet()) {
                                boolean keyFound = false;
                                for (ResourceData resourceData : metaDataResourceData) {
                                    if (resourceData.getResourcePath().equals(key)) {
                                        keyFound = true;
                                        break;
                                    }
                                }
                                if (!keyFound) {
                                    invalidKeys.add(key);
                                }
                            }
                            for (String invalidKey : invalidKeys) {
                                aggregatedMap.remove(invalidKey);
                            }
                        } else if (!onlyContent) {
                            aggregatedMap.clear();
                        }
                    }

                    ArrayList<ResourceData> sortedList = new ArrayList<ResourceData>(aggregatedMap.values());
                    SearchUtils.sortResourceDataList(sortedList);

                    metaDataSearchResultsBean = new AdvancedSearchResultsBean();
                    metaDataSearchResultsBean.setResourceDataList(sortedList.toArray(new ResourceData[sortedList.size()]));
                    return metaDataSearchResultsBean;
                } else {
                    metaDataSearchResultsBean = new AdvancedSearchResultsBean();
                    metaDataSearchResultsBean.setResourceDataList(contentSearchResourceData);
                    return metaDataSearchResultsBean;
                }
            }
        }
        return AdvancedSearchResultsBeanPopulator.populate(configSystemRegistry, registry, parameters);
View Full Code Here

        }

        public void run() {
            try {
                MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
                Event<MessageContext> event = new Event(msgCtx);
                subscriptions = subscriptionManager.getMatchingSubscriptions(event);
            } catch (EventException e) {
                handleException("Matching subscriptions fetching error", e);
            }
View Full Code Here

     * @throws EventException event
     */
    private void processGetStatusRequest(MessageContext mc,
                                         ResponseMessageBuilder messageBuilder)
            throws AxisFault, EventException {
        Subscription subscription =
                SubscriptionMessageBuilder.createGetStatusMessage(mc);
        if (log.isDebugEnabled()) {
            log.debug("GetStatus request recived for SynapseSubscription ID : " +
                    subscription.getId());
        }
        subscription = subscriptionManager.getSubscription(subscription.getId());
        if (subscription != null) {
            if (log.isDebugEnabled()) {
                log.debug("Sending GetStatus responce for SynapseSubscription ID : " +
                        subscription.getId());
            }
            //send the responce
            SOAPEnvelope soapEnvelope = messageBuilder.genGetStatusResponse(subscription);
            dispatchResponse(soapEnvelope, EventingConstants.WSE_GET_STATUS_RESPONSE,
                    mc, false);
View Full Code Here

            // Adding static subscriptions
            List<Subscription> staticSubscriptionList =
                    eventSource.getSubscriptionManager().getStaticSubscriptions();
            for (Iterator<Subscription> iterator = staticSubscriptionList.iterator();
                 iterator.hasNext();) {
                Subscription staticSubscription = iterator.next();
                OMElement staticSubElem =
                        fac.createOMElement("subscription", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                staticSubElem.addAttribute(
                        fac.createOMAttribute("id", nullNS, staticSubscription.getId()));
                OMElement filterElem =
                        fac.createOMElement("filter", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                filterElem.addAttribute(fac.createOMAttribute("source", nullNS,
                        (String) staticSubscription.getFilterValue()));
                filterElem.addAttribute(fac.createOMAttribute("dialect", nullNS,
                        (String) staticSubscription.getFilterDialect()));
                staticSubElem.addChild(filterElem);
                OMElement endpointElem =
                        fac.createOMElement("endpoint", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                OMElement addressElem =
                        fac.createOMElement("address", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                addressElem.addAttribute(
                        fac.createOMAttribute("uri", nullNS, staticSubscription.getEndpointUrl()));
                endpointElem.addChild(addressElem);
                staticSubElem.addChild(endpointElem);
                if (staticSubscription.getExpires() != null) {
                    OMElement expiresElem =
                            fac.createOMElement("expires", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                    fac.createOMText(expiresElem,
                            ConverterUtil.convertToString(staticSubscription.getExpires()));
                    staticSubElem.addChild(expiresElem);
                }
                evenSourceElem.addChild(staticSubElem);
            }
View Full Code Here


    public SynapseSubscription() {
        this.setId(UIDGenerator.generateURNString());
        this.setDeliveryMode(EventingConstants.WSE_DEFAULT_DELIVERY_MODE);
        SubscriptionData subscriptionData = new SubscriptionData();
        subscriptionData.setProperty(SynapseEventingConstants.STATIC_ENTRY, "false");
        this.setSubscriptionData(subscriptionData);
    }
View Full Code Here

                    .getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "class"));
            if (clazz != null) {
                String className = clazz.getAttributeValue();
                try {
                    Class subscriptionManagerClass = Class.forName(className);
                    SubscriptionManager manager =
                            (SubscriptionManager) subscriptionManagerClass.newInstance();
                    Iterator itr = subscriptionManagerElem.getChildrenWithName(PROPERTIES_QNAME);
                    while (itr.hasNext()) {
                        OMElement propElem = (OMElement) itr.next();
                        String propName =
                                propElem.getAttribute(new QName("name")).getAttributeValue();
                        String propValue =
                                propElem.getAttribute(new QName("value")).getAttributeValue();
                        if (propName != null && !"".equals(propName.trim()) &&
                                propValue != null && !"".equals(propValue.trim())) {

                            propName = propName.trim();
                            propValue = propValue.trim();

                            PasswordManager passwordManager =
                                    PasswordManager.getInstance();
                            String key = eventSource.getName() + "." + propName;

                            if (passwordManager.isInitialized()
                                    && passwordManager.isTokenProtected(key)) {
                                eventSource.putConfigurationProperty(propName, propValue);
                                propValue = passwordManager.resolve(propValue);
                            }

                            manager.addProperty(propName, propValue);
                        }
                    }
                    eventSource.setSubscriptionManager(manager);
                    eventSource.getSubscriptionManager()
                            .init(); // Initialise before doing further processing, required for static subscriptions
View Full Code Here

TOP

Related Classes of org.wso2.carbon.registry.search.beans.AdvancedSearchResultsBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.