Examples of AdvancedSearchResultsBean


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

            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

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

*/

    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

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

        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

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

    }

    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
TOP
Copyright © 2018 www.massapi.com. 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.