-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### What changes were proposed in this pull request? This PR proposes to add REST server interface for Tag System ### Why are the changes needed? This is a part of work for Tag system. Fix: #3914 ### Does this PR introduce _any_ user-facing change? Yes ### How was this patch tested? UTs added. --------- Co-authored-by: bknbkn <[email protected]> Co-authored-by: Dev Parikh <[email protected]> Co-authored-by: roryqi <[email protected]> Co-authored-by: JinsYin <[email protected]> Co-authored-by: rqyin <[email protected]>
- Loading branch information
1 parent
529429e
commit 71e6651
Showing
27 changed files
with
3,093 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
common/src/main/java/org/apache/gravitino/dto/requests/TagCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.gravitino.dto.requests; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.Preconditions; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.gravitino.rest.RESTRequest; | ||
|
||
/** Represents a request to create a tag. */ | ||
@Getter | ||
@EqualsAndHashCode | ||
@ToString | ||
public class TagCreateRequest implements RESTRequest { | ||
|
||
@JsonProperty("name") | ||
private final String name; | ||
|
||
@JsonProperty("comment") | ||
@Nullable | ||
private final String comment; | ||
|
||
@JsonProperty("properties") | ||
@Nullable | ||
private Map<String, String> properties; | ||
|
||
/** | ||
* Creates a new TagCreateRequest. | ||
* | ||
* @param name The name of the tag. | ||
* @param comment The comment of the tag. | ||
* @param properties The properties of the tag. | ||
*/ | ||
public TagCreateRequest(String name, String comment, Map<String, String> properties) { | ||
this.name = name; | ||
this.comment = comment; | ||
this.properties = properties; | ||
} | ||
|
||
/** This is the constructor that is used by Jackson deserializer */ | ||
public TagCreateRequest() { | ||
this(null, null, null); | ||
} | ||
|
||
/** | ||
* Validates the request. | ||
* | ||
* @throws IllegalArgumentException If the request is invalid, this exception is thrown. | ||
*/ | ||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(name), "\"name\" is required and cannot be empty"); | ||
} | ||
} |
201 changes: 201 additions & 0 deletions
201
common/src/main/java/org/apache/gravitino/dto/requests/TagUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.gravitino.dto.requests; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.google.common.base.Preconditions; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.gravitino.rest.RESTRequest; | ||
import org.apache.gravitino.tag.TagChange; | ||
|
||
/** Represents a request to update a tag. */ | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = TagUpdateRequest.RenameTagRequest.class, name = "rename"), | ||
@JsonSubTypes.Type( | ||
value = TagUpdateRequest.UpdateTagCommentRequest.class, | ||
name = "updateComment"), | ||
@JsonSubTypes.Type(value = TagUpdateRequest.SetTagPropertyRequest.class, name = "setProperty"), | ||
@JsonSubTypes.Type( | ||
value = TagUpdateRequest.RemoveTagPropertyRequest.class, | ||
name = "removeProperty") | ||
}) | ||
public interface TagUpdateRequest extends RESTRequest { | ||
|
||
/** | ||
* Returns the tag change. | ||
* | ||
* @return the tag change. | ||
*/ | ||
TagChange tagChange(); | ||
|
||
/** The tag update request for renaming a tag. */ | ||
@EqualsAndHashCode | ||
@ToString | ||
class RenameTagRequest implements TagUpdateRequest { | ||
|
||
@Getter | ||
@JsonProperty("newName") | ||
private final String newName; | ||
|
||
/** | ||
* Creates a new RenameTagRequest. | ||
* | ||
* @param newName The new name of the tag. | ||
*/ | ||
public RenameTagRequest(String newName) { | ||
this.newName = newName; | ||
} | ||
|
||
/** This is the constructor that is used by Jackson deserializer */ | ||
public RenameTagRequest() { | ||
this.newName = null; | ||
} | ||
|
||
@Override | ||
public TagChange tagChange() { | ||
return TagChange.rename(newName); | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument(StringUtils.isNotBlank(newName), "\"newName\" must not be blank"); | ||
} | ||
} | ||
|
||
/** The tag update request for updating a tag comment. */ | ||
@EqualsAndHashCode | ||
@ToString | ||
class UpdateTagCommentRequest implements TagUpdateRequest { | ||
|
||
@Getter | ||
@JsonProperty("newComment") | ||
private final String newComment; | ||
|
||
/** | ||
* Creates a new UpdateTagCommentRequest. | ||
* | ||
* @param newComment The new comment of the tag. | ||
*/ | ||
public UpdateTagCommentRequest(String newComment) { | ||
this.newComment = newComment; | ||
} | ||
|
||
/** This is the constructor that is used by Jackson deserializer */ | ||
public UpdateTagCommentRequest() { | ||
this.newComment = null; | ||
} | ||
|
||
@Override | ||
public TagChange tagChange() { | ||
return TagChange.updateComment(newComment); | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(newComment), "\"newComment\" must not be blank"); | ||
} | ||
} | ||
|
||
/** The tag update request for setting a tag property. */ | ||
@EqualsAndHashCode | ||
@ToString | ||
class SetTagPropertyRequest implements TagUpdateRequest { | ||
|
||
@Getter | ||
@JsonProperty("property") | ||
private final String property; | ||
|
||
@Getter | ||
@JsonProperty("value") | ||
private final String value; | ||
|
||
/** | ||
* Creates a new SetTagPropertyRequest. | ||
* | ||
* @param property The property to set. | ||
* @param value The value of the property. | ||
*/ | ||
public SetTagPropertyRequest(String property, String value) { | ||
this.property = property; | ||
this.value = value; | ||
} | ||
|
||
/** This is the constructor that is used by Jackson deserializer */ | ||
public SetTagPropertyRequest() { | ||
this.property = null; | ||
this.value = null; | ||
} | ||
|
||
@Override | ||
public TagChange tagChange() { | ||
return TagChange.setProperty(property, value); | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(property), "\"property\" must not be blank"); | ||
Preconditions.checkArgument(StringUtils.isNotBlank(value), "\"value\" must not be blank"); | ||
} | ||
} | ||
|
||
/** The tag update request for removing a tag property. */ | ||
@EqualsAndHashCode | ||
@ToString | ||
class RemoveTagPropertyRequest implements TagUpdateRequest { | ||
|
||
@Getter | ||
@JsonProperty("property") | ||
private final String property; | ||
|
||
/** | ||
* Creates a new RemoveTagPropertyRequest. | ||
* | ||
* @param property The property to remove. | ||
*/ | ||
public RemoveTagPropertyRequest(String property) { | ||
this.property = property; | ||
} | ||
|
||
/** This is the constructor that is used by Jackson deserializer */ | ||
public RemoveTagPropertyRequest() { | ||
this.property = null; | ||
} | ||
|
||
@Override | ||
public TagChange tagChange() { | ||
return TagChange.removeProperty(property); | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(property), "\"property\" must not be blank"); | ||
} | ||
} | ||
} |
Oops, something went wrong.