Skip to content

Commit

Permalink
fix: change type of PermissionResource.type to String to avoid exce…
Browse files Browse the repository at this point in the history
…ption for non-existing item (#303)
  • Loading branch information
bednar authored Feb 22, 2022
1 parent 4ddda00 commit 0306299
Show file tree
Hide file tree
Showing 33 changed files with 102 additions and 157 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
## 4.4.0 [unreleased]
## 5.0.0 [unreleased]

### Breaking Changes

- Change type of `PermissionResource.type` to `String`. You are able to easily migrate by:
```diff
- resource.setType(PermissionResource.TypeEnum.BUCKETS);
+ resource.setType(PermissionResource.TYPE_BUCKETS);
```

### Bug Fixes
1. [#303](https://github.com/influxdata/influxdb-client-java/pull/303): Change `PermissionResource.type` to `String`

## 4.3.0 [2022-02-18]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public class InfluxDB2ManagementExample {
PermissionResource resource = new PermissionResource();
resource.setId(bucket.getId());
resource.setOrgID("12bdc4164c2e8141");
resource.setType(PermissionResource.TypeEnum.BUCKETS);
resource.setType(PermissionResource.TYPE_BUCKETS);

// Read permission
Permission read = new Permission();
Expand Down
2 changes: 1 addition & 1 deletion client-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<artifactId>influxdb-client</artifactId>
<groupId>com.influxdb</groupId>
<version>4.4.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>influxdb-client-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client-kotlin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<parent>
<artifactId>influxdb-client</artifactId>
<groupId>com.influxdb</groupId>
<version>4.4.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal class ITQueryKotlinApi : AbstractITInfluxDBClientKotlin() {

val resource = PermissionResource()
resource.orgID = organization.id
resource.type = PermissionResource.TypeEnum.BUCKETS
resource.type = PermissionResource.TYPE_BUCKETS
resource.id = bucket.id

val readBucket = Permission()
Expand Down
2 changes: 1 addition & 1 deletion client-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>com.influxdb</groupId>
<artifactId>influxdb-client</artifactId>
<version>4.4.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>influxdb-client-flux</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client-osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<artifactId>influxdb-client</artifactId>
<groupId>com.influxdb</groupId>
<version>4.4.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>influxdb-client-osgi</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client-reactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<parent>
<artifactId>influxdb-client</artifactId>
<groupId>com.influxdb</groupId>
<version>4.4.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void setUp() throws Exception {

PermissionResource resource = new PermissionResource();
resource.setOrgID(organization.getId());
resource.setType(PermissionResource.TypeEnum.BUCKETS);
resource.setType(PermissionResource.TYPE_BUCKETS);
resource.setId(bucket.getId());

Permission readBucket = new Permission();
Expand Down
2 changes: 1 addition & 1 deletion client-scala/cross/2.12/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<parent>
<artifactId>influxdb-client</artifactId>
<groupId>com.influxdb</groupId>
<version>4.4.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion client-scala/cross/2.13/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<parent>
<artifactId>influxdb-client</artifactId>
<groupId>com.influxdb</groupId>
<version>4.4.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ITQueryScalaApiQuery extends AbstractITQueryScalaApi with Matchers {

val resource = new PermissionResource
resource.setOrgID(organization.getId)
resource.setType(PermissionResource.TypeEnum.BUCKETS)
resource.setType(PermissionResource.TYPE_BUCKETS)
resource.setId(bucket.getId)

val readBucket = new Permission
Expand Down
2 changes: 1 addition & 1 deletion client-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<artifactId>influxdb-client</artifactId>
<groupId>com.influxdb</groupId>
<version>4.4.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>influxdb-client-test</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<artifactId>influxdb-client</artifactId>
<groupId>com.influxdb</groupId>
<version>4.4.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>influxdb-client-utils</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ public class InfluxDB2ManagementExample {
PermissionResource resource = new PermissionResource();
resource.setId(bucket.getId());
resource.setOrgID("12bdc4164c2e8141");
resource.setType(PermissionResource.TypeEnum.BUCKETS);
resource.setType(PermissionResource.TYPE_BUCKETS);

// Read permission
Permission read = new Permission();
Expand Down
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<parent>
<artifactId>influxdb-client</artifactId>
<groupId>com.influxdb</groupId>
<version>4.4.0-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,100 +29,34 @@
*/

public class PermissionResource {
/**
* Gets or Sets type
*/
@JsonAdapter(TypeEnum.Adapter.class)
public enum TypeEnum {
AUTHORIZATIONS("authorizations"),

BUCKETS("buckets"),

DASHBOARDS("dashboards"),

ORGS("orgs"),

SOURCES("sources"),

TASKS("tasks"),

TELEGRAFS("telegrafs"),

USERS("users"),

VARIABLES("variables"),

SCRAPERS("scrapers"),

SECRETS("secrets"),

LABELS("labels"),

VIEWS("views"),

DOCUMENTS("documents"),

NOTIFICATIONRULES("notificationRules"),

NOTIFICATIONENDPOINTS("notificationEndpoints"),

CHECKS("checks"),

DBRP("dbrp"),

NOTEBOOKS("notebooks"),

ANNOTATIONS("annotations"),

REMOTES("remotes"),

REPLICATIONS("replications"),

FLOWS("flows"),

FUNCTIONS("functions");

private String value;

TypeEnum(String value) {
this.value = value;
}

public String getValue() {
return value;
}

@Override
public String toString() {
return String.valueOf(value);
}

public static TypeEnum fromValue(String text) {
for (TypeEnum b : TypeEnum.values()) {
if (String.valueOf(b.value).equals(text)) {
return b;
}
}
return null;
}

public static class Adapter extends TypeAdapter<TypeEnum> {
@Override
public void write(final JsonWriter jsonWriter, final TypeEnum enumeration) throws IOException {
jsonWriter.value(enumeration.getValue());
}

@Override
public TypeEnum read(final JsonReader jsonReader) throws IOException {
String value = jsonReader.nextString();
return TypeEnum.fromValue(String.valueOf(value));
}
}
}

// Possible values for type property:
public static String TYPE_AUTHORIZATIONS = "authorizations";
public static String TYPE_BUCKETS = "buckets";
public static String TYPE_DASHBOARDS = "dashboards";
public static String TYPE_ORGS = "orgs";
public static String TYPE_SOURCES = "sources";
public static String TYPE_TASKS = "tasks";
public static String TYPE_TELEGRAFS = "telegrafs";
public static String TYPE_USERS = "users";
public static String TYPE_VARIABLES = "variables";
public static String TYPE_SCRAPERS = "scrapers";
public static String TYPE_SECRETS = "secrets";
public static String TYPE_LABELS = "labels";
public static String TYPE_VIEWS = "views";
public static String TYPE_DOCUMENTS = "documents";
public static String TYPE_NOTIFICATIONRULES = "notificationRules";
public static String TYPE_NOTIFICATIONENDPOINTS = "notificationEndpoints";
public static String TYPE_CHECKS = "checks";
public static String TYPE_DBRP = "dbrp";
public static String TYPE_NOTEBOOKS = "notebooks";
public static String TYPE_ANNOTATIONS = "annotations";
public static String TYPE_REMOTES = "remotes";
public static String TYPE_REPLICATIONS = "replications";
public static String TYPE_FLOWS = "flows";
public static String TYPE_FUNCTIONS = "functions";
public static final String SERIALIZED_NAME_TYPE = "type";
@SerializedName(SERIALIZED_NAME_TYPE)
private TypeEnum type;
private String type;

public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)
Expand All @@ -140,7 +74,7 @@ public TypeEnum read(final JsonReader jsonReader) throws IOException {
@SerializedName(SERIALIZED_NAME_ORG)
private String org;

public PermissionResource type(TypeEnum type) {
public PermissionResource type(String type) {
this.type = type;
return this;
}
Expand All @@ -150,11 +84,11 @@ public PermissionResource type(TypeEnum type) {
* @return type
**/
@ApiModelProperty(required = true, value = "")
public TypeEnum getType() {
public String getType() {
return type;
}

public void setType(TypeEnum type) {
public void setType(String type) {
this.type = type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void setUp() {
PermissionResource resource = new PermissionResource();
resource.setId(bucket.getId());
resource.setOrgID(organization.getId());
resource.setType(PermissionResource.TypeEnum.BUCKETS);
resource.setType(PermissionResource.TYPE_BUCKETS);

//
// Add Permissions to read and write to the Bucket
Expand Down
Loading

0 comments on commit 0306299

Please sign in to comment.