Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api connection #1

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "apibindings/graphql_java_gen"]
path = apibindings/graphql_java_gen
url = [email protected]:Shopify/graphql_java_gen.git
12 changes: 12 additions & 0 deletions apibindings/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="src" path="src-support"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions apibindings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
schema.json
28 changes: 28 additions & 0 deletions apibindings/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ccims-eclipse-plugin-apiBindings</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
9 changes: 9 additions & 0 deletions apibindings/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
1 change: 1 addition & 0 deletions apibindings/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem "graphql_java_gen", :path => "graphql_java_gen"
18 changes: 18 additions & 0 deletions apibindings/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PATH
remote: graphql_java_gen
specs:
graphql_java_gen (0.2.0)
graphql_schema (~> 0.1.1)

GEM
specs:
graphql_schema (0.1.6)

PLATFORMS
ruby

DEPENDENCIES
graphql_java_gen!

BUNDLED WITH
2.1.4
10 changes: 10 additions & 0 deletions apibindings/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ccoms-eclipse-plugin-apiBindings
Bundle-SymbolicName: ccims-eclipse-plugin-apiBindings
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: ccoms.eclipse.plugin.apiBindings
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: com.google.gson;bundle-version="2.8.2"
Export-Package: com.shopify.graphql.support,
de.unistuttgart.iste.rss.ccims.eclipseplugin.apibindings
32 changes: 32 additions & 0 deletions apibindings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# CCIMS Eclipse Plugin Api Bindings
Generated java bindings for the ccims graphql api.

## Submodule
The folder [`graphql_java_gen`](graphql_java_gen) is a git submodule with the actual generator code and some necessary java classes.

These java classes are copied to src-support during the generation.
The copyright and license notice for these files can be found at [src-support/LICENSE.txt](src-support/LICENSE.txt).

## Generating
### Preparations
Install `bash`, `ruby`, `gem` and `bundler`.
Install project dependencies by executing `bundle`.

### Running generation
For the generation we need the graphql intorspection json.
This can be genrated on https://tools.w3cub.com/graphql-to-introspection-json.
But the result from that website must be wrapped into `{ 'data':` at the start and `}` at the end.
The resulting json must be saved in `schema.json`.

Run `generate.sh` without any arguments
This will delete and create the neccesarry folders and generate the code.

### Manual fixing
Due to some problems in the generator, there are some minor bugs generated.
In some classes the class `com.shopify.graphql.support.Query` is imported but conflicts with the generated
`de.unistuttgart.iste.rss.ccims.eclipseplugin.apibindings.Query`. This causes syntax errors.
In these cases just delete the import.

### Using nix
You can use `nix-shell` to perform the preparations and the generation by running:
`nix-shell --run "bash generate.sh"`
5 changes: 5 additions & 0 deletions apibindings/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src-gen/,\
src-support/
output.. = bin/
bin.includes = META-INF/,\
.
33 changes: 33 additions & 0 deletions apibindings/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env

SCHEMA="schema.json"

dir="$(dirname "$(realpath "$0")")"

function fail {
echo "$1"
exit $2
}

if ! which ruby > /dev/null 2>&1 ;then
fail "Need ruby" 11
fi

if [ $# -ne 0 ] ;then
fail "Not expecting any argument"
fi

gitSubmodule="$dir/graphql_java_gen"
originalSupportSrc="$gitSubmodule/support/src/main/java"
originalLicense="$gitSubmodule/LICENSE.txt"
srcSupportFolder="$dir/src-support"
rm -rf "$srcSupportFolder"
cp -r -T "$originalSupportSrc" "$srcSupportFolder"
cp "$originalLicense" "$srcSupportFolder"

srcGenFolder="$dir/src-gen"
pkgFolder="$srcGenFolder/de/unistuttgart/iste/rss/ccims/eclipseplugin/apibindings"
rm -rf "$srcGenFolder"
mkdir --parents "$pkgFolder"

ruby internalGenerate.rb "$SCHEMA" "$pkgFolder"
1 change: 1 addition & 0 deletions apibindings/graphql_java_gen
Submodule graphql_java_gen added at 163f64
24 changes: 24 additions & 0 deletions apibindings/internalGenerate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'graphql_java_gen'
require 'graphql_schema'
require 'json'

schemaFile = File.read(ARGV[0])
schema = GraphQLSchema.new(JSON.parse(schemaFile))

GraphQLJavaGen.new(schema,
package_name: "de.unistuttgart.iste.rss.ccims.eclipseplugin.apibindings",
nest_under: 'Schema', # Not used, but must be defined
custom_scalars: [
GraphQLJavaGen::Scalar.new(
type_name: 'TimeSpan',
java_type: 'Integer',
deserialize_expr: ->(expr) { "jsonAsInteger(#{expr}, key)" },
),
GraphQLJavaGen::Scalar.new(
type_name: 'Date',
java_type: 'Date',
deserialize_expr: ->(expr) { "Date.from(Instant.from(DateTimeFormatter.ISO_INSTANT.parse(jsonAsString(#{expr}, key))))" },
imports: ['java.util.Date', 'java.time.format.DateTimeFormatter', 'java.time.temporal.TemporalAccessor', 'java.time.Instant']
),
]
).save_granular(ARGV[1])
7 changes: 7 additions & 0 deletions apibindings/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [ bash ruby gemrb bundler ];
shellHook = ''
bundle
'';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Generated from graphql_java_gen gem

package de.unistuttgart.iste.rss.ccims.eclipseplugin.apibindings;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.shopify.graphql.support.AbstractResponse;
import com.shopify.graphql.support.Arguments;
import com.shopify.graphql.support.Error;
import com.shopify.graphql.support.Query;
import com.shopify.graphql.support.SchemaViolationError;
import com.shopify.graphql.support.TopLevelResponse;
import com.shopify.graphql.support.Input;

import com.shopify.graphql.support.ID;

import java.time.Instant;

import java.time.format.DateTimeFormatter;

import java.time.temporal.TemporalAccessor;

import java.util.Date;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class AddAssigneeInput implements Serializable {
private ID issue;

private ID userToAssign;

private Input<String> clientMutationId = Input.undefined();

public AddAssigneeInput(ID issue, ID userToAssign) {
this.issue = issue;

this.userToAssign = userToAssign;
}

public ID getIssue() {
return issue;
}

public AddAssigneeInput setIssue(ID issue) {
this.issue = issue;
return this;
}

public ID getUserToAssign() {
return userToAssign;
}

public AddAssigneeInput setUserToAssign(ID userToAssign) {
this.userToAssign = userToAssign;
return this;
}

public String getClientMutationId() {
return clientMutationId.getValue();
}

public Input<String> getClientMutationIdInput() {
return clientMutationId;
}

public AddAssigneeInput setClientMutationId(String clientMutationId) {
this.clientMutationId = Input.optional(clientMutationId);
return this;
}

public AddAssigneeInput setClientMutationIdInput(Input<String> clientMutationId) {
if (clientMutationId == null) {
throw new IllegalArgumentException("Input can not be null");
}
this.clientMutationId = clientMutationId;
return this;
}

public void appendTo(StringBuilder _queryBuilder) {
String separator = "";
_queryBuilder.append('{');

_queryBuilder.append(separator);
separator = ",";
_queryBuilder.append("issue:");
Query.appendQuotedString(_queryBuilder, issue.toString());

_queryBuilder.append(separator);
separator = ",";
_queryBuilder.append("userToAssign:");
Query.appendQuotedString(_queryBuilder, userToAssign.toString());

if (this.clientMutationId.isDefined()) {
_queryBuilder.append(separator);
separator = ",";
_queryBuilder.append("clientMutationID:");
if (clientMutationId.getValue() != null) {
Query.appendQuotedString(_queryBuilder, clientMutationId.getValue().toString());
} else {
_queryBuilder.append("null");
}
}

_queryBuilder.append('}');
}
}
Loading