Skip to content

Commit

Permalink
#8 Add Query-Syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
smallcreep committed Dec 18, 2017
1 parent c426681 commit 6b5e547
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 48 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/github/smallcreep/jb/hub/api/Projects.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
* @since 0.2.0
*/
public interface Projects extends Iterable<Project>,
Sortable<Projects>, Subset<Projects>, Partial<Projects> {
Sortable<Projects>, Subset<Projects>, Partial<Projects>,
Searchable<Projects> {

/**
* Get project by id.
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/github/smallcreep/jb/hub/api/Query.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.smallcreep.jb.hub.api;

/**
* JetBrains Hub Query Syntax.
*
* @author Ilia Rogozhin (ilia.rogozhin@gmail.com)
* @version $Id$
* @see <a href="https://www.jetbrains.com/help/hub/Query-Syntax.html">Query Syntax</a>
* @since 0.2.0
*/
public interface Query extends Field {
}
11 changes: 11 additions & 0 deletions src/main/java/com/github/smallcreep/jb/hub/api/RtProjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,15 @@ public Iterator<Project> iterator() {
new RtPagination(this.req, "projects")
).iterator();
}

@Override
public Projects search(final Query query) throws Exception {
return new RtProjects(
this.origin,
this.req
.uri()
.queryParam("query", query.value())
.back()
);
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/github/smallcreep/jb/hub/api/Searchable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.smallcreep.jb.hub.api;

/**
* Searchable interface use for search elements.
*
* @author Ilia Rogozhin (ilia.rogozhin@gmail.com)
* @version $Id$
* @param <T> Type of self searchable request
* @see <a href="https://www.jetbrains.com/help/hub/Query-Syntax.html">Query Syntax</a>
* @since 0.2.0
*/
public interface Searchable<T extends Searchable> {

/**
* Search.
* @param query Query
* @return Self
* @throws Exception If fails
*/
T search(Query query) throws Exception;
}
39 changes: 39 additions & 0 deletions src/main/java/com/github/smallcreep/jb/hub/api/query/Field.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.github.smallcreep.jb.hub.api.query;

import com.github.smallcreep.jb.hub.api.Query;
import org.cactoos.text.FormattedText;

/**
* Simple query field.
*
* @author Ilia Rogozhin (ilia.rogozhin@gmail.com)
* @version $Id$
* @since 0.2.0
*/
public final class Field implements Query {

/**
* Field name.
*/
private final String name;

/**
* Field value.
*/
private final String value;

/**
* Ctor.
* @param name Field name
* @param value Field value
*/
public Field(final String name, final String value) {
this.name = name;
this.value = value;
}

@Override
public String value() throws Exception {
return new FormattedText("%s:%s", this.name, this.value).asString();
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/github/smallcreep/jb/hub/api/query/Or.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.github.smallcreep.jb.hub.api.query;

import com.github.smallcreep.jb.hub.api.Query;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Mapped;
import org.cactoos.iterable.StickyIterable;
import org.cactoos.text.JoinedText;

/**
* Or expression for search.
* @author Ilia Rogozhin (ilia.rogozhin@gmail.com)
* @version $Id$
* @since 0.2.0
*/
public final class Or implements Query {

/**
* Queries.
*/
private final Iterable<Query> queries;

/**
* Ctor.
* @param queries Queries
*/
public Or(final Query... queries) {
this(new IterableOf<>(queries));
}

/**
* Ctor.
* @param queries Queries
*/
public Or(final Iterable<Query> queries) {
this.queries = new StickyIterable<>(queries);
}

@Override
public String value() throws Exception {
return new JoinedText(
" or ",
new Mapped<>(
Query::value,
this.queries
)
).asString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Ilia Rogozhin (ilia.rogozhin@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Different query syntax from JetBrains Hub.
*
* <p><a href="https://www.jetbrains.com/help/hub/Query-Syntax.html">Query Syntax</a></p>
* @author Ilia Rogozhin (ilia.rogozhin@gmail.com)
* @version $Id$
* @since 0.2.0
*/
package com.github.smallcreep.jb.hub.api.query;
65 changes: 18 additions & 47 deletions src/test/java/com/github/smallcreep/jb/hub/api/ProjectsITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.smallcreep.jb.hub.api.fields.NestedField;
import com.github.smallcreep.jb.hub.api.fields.SubFields;
import com.github.smallcreep.jb.hub.api.integration.DefaultAuthByPass;
import com.github.smallcreep.jb.hub.api.query.Or;
import com.github.smallcreep.jb.hub.api.sort.AscSort;
import com.github.smallcreep.json.ObjectHasJson;
import javax.json.Json;
Expand Down Expand Up @@ -38,6 +39,22 @@ public void integrationCheckProjects() throws Exception {
"key"
)
)
.search(
new Or(
new com.github.smallcreep.jb.hub.api.query.Field(
"key",
"AP"
),
new com.github.smallcreep.jb.hub.api.query.Field(
"key",
"GLBL"
),
new com.github.smallcreep.jb.hub.api.query.Field(
"id",
"a5d71886-3b1e-40eb-a266-2f53e331a576"
)
)
)
.fields(
new MultipleFields(
new Field.Simple(
Expand Down Expand Up @@ -213,59 +230,13 @@ public void integrationCheckProjects() throws Exception {
)
.build()
);
final ObjectHasJson fourth = new ObjectHasJson(
Json.createObjectBuilder()
.add(
"id",
"77a3ea4f-9748-4e97-a7e7-d8bc8a8b88ed"
)
.add(
"key",
"TYA"
)
.add(
"resources",
Json.createArrayBuilder()
.add(
Json.createObjectBuilder()
.add(
"id",
"4774a74d-9515-4f5c-af99-37e4da426208"
)
.add(
"key",
"TYA"
)
)
.add(
Json.createObjectBuilder()
.add(
"id",
"d8a6bec7-8fd1-4916-8475-a946c07ac8e2"
)
.add(
"key",
"adminTestYoutrackApi"
)
)
)
.add(
"team",
Json.createObjectBuilder().add(
"type",
"projectTeam"
)
)
.build()
);
MatcherAssert.assertThat(
"Integration request for get projects doesn't correct!",
projects,
Matchers.contains(
first,
second,
third,
fourth
third
)
);
}
Expand Down

1 comment on commit 6b5e547

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 6b5e547 Dec 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:

set -x && set -e && set -o pipefail && cd /tmp/0pdd20171218-4-zjoy0a/smallcreep/jb-hub-client && pdd -v -f /tmp/pdd.xml20171218-11335-tuyti8 [1]: + set -e + set -o pipefail + cd /tmp/0pdd20171218-4-zjoy0a/smallcreep/jb-hub-client + pdd -v -f /tmp/pdd.xml20171218-11335-tuyti8 Found 6 lines in...

Please, copy and paste this stack trace to GitHub:

UserError
set -x && set -e && set -o pipefail && cd /tmp/0pdd20171218-4-zjoy0a/smallcreep/jb-hub-client && pdd -v -f /tmp/pdd.xml20171218-11335-tuyti8 [1]:
+ set -e
+ set -o pipefail
+ cd /tmp/0pdd20171218-4-zjoy0a/smallcreep/jb-hub-client
+ pdd -v -f /tmp/pdd.xml20171218-11335-tuyti8

Found 6 lines in /tmp/0pdd20171218-4-zjoy0a/smallcreep/jb-hub-client/.pdd
My version is 0.19.3
Ruby version is 2.3.3 at x86_64-linux
Reading .
Excluding gradle/**
Excluding build/**/*
103 file(s) found, 176 excluded
/tmp/0pdd20171218-4-zjoy0a/smallcreep/jb-hub-client/gradle/wrapper/gradle-wrapper.jar is a binary file (54712 bytes)
Reading appveyor.yml...
Reading build.gradle...
Reading .gitignore...
Reading secret.gpg.asc...
Reading config/checkstyle/checks.xml...
ERROR: config/checkstyle/checks.xml; puzzle at line #252; @todo found, but puzzle can't be parsed, most probably because @todo is not followed by a puzzle marker, as this page explains: https://github.com/yegor256/pdd#how-to-format. If you can't understand the cause of this issue or you don't know how to fix it, please submit a GitHub issue, we will try to help you: https://github.com/yegor256/pdd/issues. This tool is still in its beta version and we will appreciate your feedback. Here is where you can find more documentation: https://github.com/yegor256/pdd/blob/master/README.md.
Exit code is 1

/app/objects/git_repo.rb:66:in `rescue in xml'
/app/objects/git_repo.rb:63:in `xml'
/app/objects/puzzles.rb:36:in `deploy'
/app/objects/job.rb:36:in `proceed'
/app/objects/job_starred.rb:33:in `proceed'
/app/objects/job_recorded.rb:32:in `proceed'
/app/objects/job_emailed.rb:35:in `proceed'
/app/objects/job_commiterrors.rb:36:in `proceed'
/app/objects/job_detached.rb:49:in `block in exclusive'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:33:in `block in catch'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:33:in `catch'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:33:in `catch'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:106:in `timeout'
/app/objects/job_detached.rb:47:in `exclusive'
/app/objects/job_detached.rb:37:in `block in proceed'
/app/objects/job_detached.rb:37:in `fork'
/app/objects/job_detached.rb:37:in `proceed'
/app/0pdd.rb:350:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1632:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1632:in `block in compile!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:991:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1010:in `route_eval'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:991:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1037:in `block in process_route'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1035:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1035:in `process_route'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:989:in `block in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:988:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:988:in `route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1094:in `block in dispatch!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `block in invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1091:in `dispatch!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:923:in `block in call!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `block in invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:923:in `call!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:913:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/xss_header.rb:18:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/path_traversal.rb:16:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/json_csrf.rb:26:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/frame_options.rb:31:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.3/lib/rack/logger.rb:15:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.3/lib/rack/common_logger.rb:33:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:231:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:224:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.3/lib/rack/head.rb:12:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.3/lib/rack/method_override.rb:22:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:194:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1955:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1499:in `block in call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1726:in `synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1499:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.3/lib/rack/handler/webrick.rb:86:in `service'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'

Please sign in to comment.