diff --git a/.travis.yml b/.travis.yml index ceb5594262..3fbd5db947 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: java +before_install: +- sed -i.bak -e 's|https://nexus.codehaus.org/snapshots/|https://oss.sonatype.org/content/repositories/codehaus-snapshots/|g' ~/.m2/settings.xml install: echo 'Skipping mvn install' before_script: - ./test-whitespaces.sh diff --git a/samples/java/sbt.sample.app/src/main/java/com/ibm/sbt/sample/app/SearchApp.java b/samples/java/sbt.sample.app/src/main/java/com/ibm/sbt/sample/app/SearchApp.java index 873bb97028..d03b0cd077 100644 --- a/samples/java/sbt.sample.app/src/main/java/com/ibm/sbt/sample/app/SearchApp.java +++ b/samples/java/sbt.sample.app/src/main/java/com/ibm/sbt/sample/app/SearchApp.java @@ -54,6 +54,18 @@ EntityList getResultsWithConstraint(String query, Constraint constraint) return getSearchService().getResultsWithConstraint(query, constraint); } + EntityList getMyResults(String query) throws ClientServicesException { + return getSearchService().getMyResults(query); + } + + EntityList getMyResults(String query, Map parameters) throws ClientServicesException { + return getSearchService().getMyResults(query, parameters); + } + + EntityList getMyResultsWithConstraint(String query, Constraint constraint) throws ClientServicesException { + return getSearchService().getMyResultsWithConstraint(query, constraint); + } + /** * Demo. * @@ -74,11 +86,18 @@ public static void main(String[] args) { try { sa = new SearchApp(url, user, password); + System.out.println("*** Public entities:"); EntityList results = sa.getResults(query); for (Result result : results) { System.out.println(result.getTitle() + " " + result.getUpdated()); } + System.out.println("*** Non-public entities accessible by given user:"); + results = sa.getMyResults(query); + for (Result result : results) { + System.out.println(result.getTitle() + " " + result.getUpdated()); + } + } catch (Exception e) { e.printStackTrace(); } diff --git a/sdk/com.ibm.sbt.core/src/main/java/com/ibm/sbt/services/client/connections/search/SearchService.java b/sdk/com.ibm.sbt.core/src/main/java/com/ibm/sbt/services/client/connections/search/SearchService.java index 45b5497554..6dc0b979da 100644 --- a/sdk/com.ibm.sbt.core/src/main/java/com/ibm/sbt/services/client/connections/search/SearchService.java +++ b/sdk/com.ibm.sbt.core/src/main/java/com/ibm/sbt/services/client/connections/search/SearchService.java @@ -35,7 +35,6 @@ import com.ibm.commons.util.StringUtil; import com.ibm.commons.xml.xpath.XPathExpression; import com.ibm.sbt.services.client.ClientServicesException; -import com.ibm.sbt.services.client.ClientService.Args; import com.ibm.sbt.services.client.base.AtomFeedHandler; import com.ibm.sbt.services.client.base.BaseService; import com.ibm.sbt.services.client.base.ConnectionsService; @@ -102,11 +101,13 @@ protected void initServiceMappingKeys(){ /** * Lists the elements in an Atom entry representing the result returned by a search. * + * Queries public (neither private nor restricted) content. + * * @param query * Text to search for - * @param parameters + * @param parameters Map * for additional parameters - * @return EntityList + * @return EntityList<Result> * @throws ClientServicesException */ public EntityList getResults(String query,Map parameters) throws ClientServicesException { @@ -125,11 +126,13 @@ public EntityList getResults(String query,Map parameters /** * Lists the elements in an Atom entry representing the result returned by a search. * + * Queries public (neither private nor restricted) content. + * * @param query * Text to search for - * @param parameters - * for additional parameters - * @return EntityList + * @param parameters Map + * for additional multi-valued parameters + * @return EntityList<Result> * @throws ClientServicesException */ public EntityList getResultsList(String query,Map> parameters) throws ClientServicesException { @@ -186,9 +189,11 @@ protected boolean addParameter(StringBuilder b, boolean first, String name, Stri * entry to make it easier to find the content later. The format of the tags document * is an Atom publishing protocol (APP) categories document. * + * Queries public (neither private nor restricted) content. + * * @param tag {String} - * Single tag to be search for, for multiple tags use other overloaded method - * @return EntityList + * Single tag to search for, for multiple tags use other overloaded method + * @return EntityList<Result> * @throws ClientServicesException */ public EntityList getResultsByTag(String tag) throws ClientServicesException { @@ -204,8 +209,10 @@ public EntityList getResultsByTag(String tag) throws ClientServicesExcep * entry to make it easier to find the content later. The format of the tags document * is an Atom publishing protocol (APP) categories document. * - * @param tags List of Tags to searched for - * @return EntityList + * Queries public (neither private nor restricted) content. + * + * @param tags List of Tags to search for + * @return EntityList<Result> * @throws ClientServicesException */ public EntityList getResultsByTag(List tags) throws ClientServicesException { @@ -219,8 +226,11 @@ public EntityList getResultsByTag(List tags) throws ClientServic * entry to make it easier to find the content later. The format of the tags document * is an Atom publishing protocol (APP) categories document. * - * @param tags List of Tags to searched for - * @return EntityList + * Queries public (neither private nor restricted) content. + * + * @param tags List of Tags to search for + * @param parameters Map for additional parameters + * @return EntityList<Result> * @throws ClientServicesException */ public EntityList getResultsByTag(List tags, @@ -238,9 +248,13 @@ public EntityList getResultsByTag(List tags, } /** + * Lists the elements in an Atom entry representing the result returned by a search. + * + * Queries non-public (private and restricted) content owned by or visible for the authenticated user. + * Requires authentication! * * @param query Text to search for - * @return ResultList + * @return EntityList<Result> * @throws ClientServicesException */ public EntityList getMyResults(String query) throws ClientServicesException { @@ -248,12 +262,16 @@ public EntityList getMyResults(String query) throws ClientServicesExcept } /** + * Lists the elements in an Atom entry representing the result returned by a search. + * + * Queries non-public (private and restricted) content owned by or visible for the authenticated user. + * Requires authentication! * * @param query * Text to search for * @param parameters Map * for additional parameters - * @return EntityList + * @return EntityList<Result> * @throws ClientServicesException */ public EntityList getMyResults(String query, Map parameters) throws ClientServicesException { @@ -261,8 +279,107 @@ public EntityList getMyResults(String query, Map paramet return getResultEntityList(searchQry, parameters); } + /** + * Lists the elements in an Atom entry representing the result returned by a search. + * + * Queries non-public (private and restricted) content owned by or visible for the authenticated user. + * Requires authentication! + * + * @param query + * Text to search for + * @param parameters Map + * for additional multi-valued parameters + * @return EntityList<Result> + * @throws ClientServicesException + * @see {@link #getMyResults(String, Map)} + */ + public EntityList getMyResultsList(String query,Map> parameters) throws ClientServicesException { + if(parameters==null){ + parameters= new HashMap>(); + } + + // The MYSEARCH URL already contains a {query} part which must be referred to here. + // The SEARCH URL (for public entities) requires the query to be added explicitly. + // See getMyResults(String, Map) for the same kind of usage. + StringBuilder searchQry = new StringBuilder(SearchUrls.MYSEARCH.format(this, + SearchUrls.getQuery(query))); + addUrlParameters(searchQry, parameters); + return getResultEntityList(searchQry.toString(), new HashMap()); + } + + /** + * The category document identifies the tags that have been assigned to particular + * items, such as blog posts or community entries. Tags are single-word keywords that + * categorize a posting or entry. A tag classifies the information in the posting or + * entry to make it easier to find the content later. The format of the tags document + * is an Atom publishing protocol (APP) categories document. + * + * Queries non-public (private and restricted) content owned by or visible for the authenticated user. + * Requires authentication! + * + * @param tag {String} + * Single tag to search for, for multiple tags use other overloaded method + * @return EntityList<Result> + * @throws ClientServicesException + */ + public EntityList getMyResultsByTag(String tag) throws ClientServicesException { + List taglist = new ArrayList(); + taglist.add(tag); + return getMyResultsByTag(taglist,null); + } + + /** + * The category document identifies the tags that have been assigned to particular + * items, such as blog posts or community entries. Tags are single-word keywords that + * categorize a posting or entry. A tag classifies the information in the posting or + * entry to make it easier to find the content later. The format of the tags document + * is an Atom publishing protocol (APP) categories document. + * + * Queries non-public (private and restricted) content owned by or visible for the authenticated user. + * Requires authentication! + * + * @param tags List of Tags to search for + * @return EntityList<Result> + * @throws ClientServicesException + */ + public EntityList getMyResultsByTag(List tags) throws ClientServicesException { + return getMyResultsByTag(tags,null); + } + + /** + * The category document identifies the tags that have been assigned to particular + * items, such as blog posts or community entries. Tags are single-word keywords that + * categorize a posting or entry. A tag classifies the information in the posting or + * entry to make it easier to find the content later. The format of the tags document + * is an Atom publishing protocol (APP) categories document. + * + * Queries non-public (private and restricted) content owned by or visible for the authenticated user. + * Requires authentication! + * + * @param tags List of Tags to search for + * @param parameters Map for additional parameters + * @return EntityList<Result> + * @throws ClientServicesException + */ + public EntityList getMyResultsByTag(List tags, + Map parameters) throws ClientServicesException { + // High level wrapper, provides a convenient mechanism for search for + // tags, uses constraints internally + List formattedTags = new ArrayList(); + List constraints = new ArrayList(); + formattedTags = createTagConstraint(tags); + Constraint constraint = new Constraint(); + constraint.setType("category"); + constraint.setValues(formattedTags); + constraints.add(constraint); + return getMyResultsWithConstraint("", constraints,parameters); + } + /** * get people by search query + * + * Queries public (neither private nor restricted) content. + * * @param query Text to search for * @throws ClientServicesException */ @@ -271,12 +388,15 @@ public EntityList getPeople(String query) throws ClientServicesExcep } /** + * get people by search query + * + * Queries public (neither private nor restricted) content. * * @param query * Text to search for * @param parameters Map * for additional parameters - * @return EntityList + * @return EntityList<FacetValue> * @throws ClientServicesException */ public EntityList getPeople(String query,Map parameters) throws ClientServicesException { @@ -293,10 +413,14 @@ public EntityList getPeople(String query,Map paramet } /** + * get my people by search query + * + * Queries non-public (private and restricted) content owned by or visible for the authenticated user. + * Requires authentication! * * @param query * Text to search for - * @return EntityList + * @return EntityList<FacetValue> * @throws ClientServicesException */ public EntityList getMyPeople(String query) throws ClientServicesException { @@ -304,12 +428,16 @@ public EntityList getMyPeople(String query) throws ClientServicesExc } /** + * get my people by search query + * + * Queries non-public (private and restricted) content owned by or visible for the authenticated user. + * Requires authentication! * * @param query * Text to search for * @param parameters Map * for additional parameters - * @return EntityList + * @return EntityList<FacetValue> * @throws ClientServicesException */ public EntityList getMyPeople(String query,Map parameters) throws ClientServicesException { @@ -317,22 +445,31 @@ public EntityList getMyPeople(String query,Map param parameters= new HashMap(); } - parameters.put("query", query); parameters.put("pageSize", "0"); parameters.put("facet", "{\"id\": \"Person\"}"); - String searchQry = SearchUrls.MYSEARCH.format(this); + // The MYSEARCH URL already contains a {query} part which must be referred to here. + // The SEARCH URL (for public entities) requires the query to be added explicitly. + // See getMyResults(String, Map) for the same kind of usage. + String searchQry = SearchUrls.MYSEARCH.format(this, SearchUrls.getQuery(query)); return getFacetValueEntityList(searchQry, parameters); } /** + * Lists the elements in an Atom entry representing the result returned by a search using constraints. + * Constraints may refer to field, category and range metadata. + * The Connections Search API also supports "not-constraints" to search for data NOT matching a constraint, + * but this is not yet supported directly. + * + * Queries public (neither private nor restricted) content. + * * @param query Text to search for * @param constraint Constraint * - * @return EntityList + * @return EntityList<Result> * @throws ClientServicesException * - * @see Search API + * @see Search API */ public EntityList getResultsWithConstraint(String query, Constraint constraint) throws ClientServicesException { List constraintList = new ArrayList(); @@ -341,27 +478,41 @@ public EntityList getResultsWithConstraint(String query, Constraint cons } /** + * Lists the elements in an Atom entry representing the result returned by a search using constraints. + * Constraints may refer to field, category and range metadata. + * The Connections Search API also supports "not-constraints" to search for data NOT matching a constraint, + * but this is not yet supported directly. + * + * Queries public (neither private nor restricted) content. + * * @param query Text to search for - * @param constraints List + * @param constraints List<Constraint> * - * @return EntityList + * @return EntityList<Result> * @throws ClientServicesException * - * @see Search API + * @see Search API */ public EntityList getResultsWithConstraint(String query, List constraints) throws ClientServicesException { return getResultsWithConstraint(query, constraints,null); } /** + * Lists the elements in an Atom entry representing the result returned by a search using constraints. + * Constraints may refer to field, category and range metadata. + * The Connections Search API also supports "not-constraints" to search for data NOT matching a constraint, + * but this is not yet supported directly. + * + * Queries public (neither private nor restricted) content. + * * @param query Text to search for - * @param constraints List - * @param parameters + * @param constraints List<Constraint> + * @param parameters Map for additional parameters * - * @return EntityList + * @return EntityList<Result> * @throws ClientServicesException * - *http://www-10.IBM.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=IBM+Connections+4.0+API+Documentation#action=openDocument&res_title=Constraints&content=pdcontent + * @see Search API */ public EntityList getResultsWithConstraint(String query, List constraints, Map parameters) throws ClientServicesException{ @@ -380,12 +531,90 @@ public EntityList getResultsWithConstraint(String query, ListSearch API + */ + public EntityList getMyResultsWithConstraint(String query, Constraint constraint) throws ClientServicesException { + List constraintList = new ArrayList(); + constraintList.add(constraint); + return getMyResultsWithConstraint(query, constraintList,null); + } + + /** + * Lists the elements in an Atom entry representing the result returned by a search using constraints. + * Constraints may refer to field, category and range metadata. + * The Connections Search API also supports "not-constraints" to search for data NOT matching a constraint, + * but this is not yet supported directly. + * + * Queries non-public (private and restricted) content owned by or visible for the authenticated user. + * Requires authentication! + * + * @param query Text to search for + * @param constraints List<Constraint> + * + * @return EntityList<Result> + * @throws ClientServicesException + * + * @see Search API + */ + public EntityList getMyResultsWithConstraint(String query, List constraints) throws ClientServicesException { + return getMyResultsWithConstraint(query, constraints,null); + } + + /** + * Lists the elements in an Atom entry representing the result returned by a search using constraints. + * Constraints may refer to field, category and range metadata. + * The Connections Search API also supports "not-constraints" to search for data NOT matching a constraint, + * but this is not yet supported directly. + * + * Queries non-public (private and restricted) content owned by or visible for the authenticated user. + * Requires authentication! + * + * @param query Text to search for + * @param constraints List<Constraint> + * @param parameters Map for additional parameters + * + * @return EntityList<Result> + * @throws ClientServicesException + * + * @see Search API + */ + public EntityList getMyResultsWithConstraint(String query, List constraints, Map parameters) throws ClientServicesException{ + + Map> params = new HashMap>(); + // We can not use a map of constraints, since there could be multiple constraints but map can have only one key named constraint + List formattedConstraints = generateConstraintParameter(constraints); + if(parameters == null){ + parameters = new HashMap(); + } + for(Map.Entry entry : parameters.entrySet()){ + List valueList = new ArrayList(); + valueList.add(entry.getValue()); + params.put(entry.getKey(), valueList); + } + params.put("constraint", formattedConstraints); + return getMyResultsList(query, params); + } + /** * Search IBM Connection for available scopes ( Applications in which search can be executed ) * - * @method getScopes - * @return EntityList - * @throws SearchServiceException + * @return EntityList<Scope> + * @throws ClientServicesException */ public EntityList getScopes() throws ClientServicesException { Map params = new HashMap(); @@ -397,8 +626,10 @@ public EntityList getScopes() throws ClientServicesException { /** * Lists the elements in an Atom entry representing the result returned by a search. * + * Queries public (neither private nor restricted) content. + * * @param query Text to search for - * @return ResultList + * @return EntityList<Result> * @throws ClientServicesException */ public EntityList getResults(String query) throws ClientServicesException { @@ -411,7 +642,7 @@ public EntityList getResults(String query) throws ClientServicesExceptio /** * - * @return {IFeedHandler} + * @return IFeedHandler<Result> */ public IFeedHandler getResultFeedHandler() { return new AtomFeedHandler(this) { @@ -424,7 +655,7 @@ protected Result entityInstance(BaseService service, Node node, XPathExpression /** * - * @return {IFeedHandler} + * @return IFeedHandler<Scope> */ public IFeedHandler getScopeFeedHandler() { return new AtomFeedHandler(this) { @@ -437,7 +668,7 @@ protected Scope entityInstance(BaseService service, Node node, XPathExpression x /** * - * @return {IFeedHandler} + * @return IFeedHandler<FacetValue> */ public IFeedHandler getFacetValueFeedHandler(final String facetId) { return new AtomFeedHandler(this) {