-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Heng Qin
committed
Mar 20, 2024
1 parent
3530242
commit b22dc29
Showing
28 changed files
with
1,492 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** The interface of a Group. The Group is the entity which contains users. */ | ||
public interface Group extends Auditable { | ||
|
||
/** | ||
* The name of the group. | ||
* | ||
* @return The name of the group. | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* The properties of the group. Note, this method will return null if the properties are not set. | ||
* | ||
* @return The properties of the group. | ||
*/ | ||
Map<String, String> properties(); | ||
|
||
/** | ||
* The users of the group. | ||
* | ||
* @return The users of the group. | ||
*/ | ||
List<String> users(); | ||
} |
36 changes: 36 additions & 0 deletions
36
api/src/main/java/com/datastrato/gravitino/exceptions/GroupAlreadyExistsException.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,36 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
|
||
package com.datastrato.gravitino.exceptions; | ||
|
||
import com.google.errorprone.annotations.FormatMethod; | ||
import com.google.errorprone.annotations.FormatString; | ||
|
||
/** An exception thrown when a resource already exists. */ | ||
public class GroupAlreadyExistsException extends AlreadyExistsException { | ||
|
||
/** | ||
* Constructs a new exception with the specified detail message. | ||
* | ||
* @param message the detail message. | ||
* @param args the arguments to the message. | ||
*/ | ||
@FormatMethod | ||
public GroupAlreadyExistsException(@FormatString String message, Object... args) { | ||
super(message, args); | ||
} | ||
|
||
/** | ||
* Constructs a new exception with the specified detail message and cause. | ||
* | ||
* @param cause the cause. | ||
* @param message the detail message. | ||
* @param args the arguments to the message. | ||
*/ | ||
@FormatMethod | ||
public GroupAlreadyExistsException(Throwable cause, String message, Object... args) { | ||
super(cause, message, args); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
api/src/main/java/com/datastrato/gravitino/exceptions/NoSuchGroupException.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,35 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
|
||
package com.datastrato.gravitino.exceptions; | ||
|
||
import com.google.errorprone.annotations.FormatMethod; | ||
import com.google.errorprone.annotations.FormatString; | ||
|
||
/** Exception thrown when a group with specified name is not existed. */ | ||
public class NoSuchGroupException extends NotFoundException { | ||
/** | ||
* Constructs a new exception with the specified detail message. | ||
* | ||
* @param message the detail message. | ||
* @param args the arguments to the message. | ||
*/ | ||
@FormatMethod | ||
public NoSuchGroupException(@FormatString String message, Object... args) { | ||
super(message, args); | ||
} | ||
|
||
/** | ||
* Constructs a new exception with the specified detail message and cause. | ||
* | ||
* @param cause the cause. | ||
* @param message the detail message. | ||
* @param args the arguments to the message. | ||
*/ | ||
@FormatMethod | ||
public NoSuchGroupException(Throwable cause, String message, Object... args) { | ||
super(cause, message, args); | ||
} | ||
} |
160 changes: 160 additions & 0 deletions
160
common/src/main/java/com/datastrato/gravitino/dto/GroupDTO.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,160 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto; | ||
|
||
import com.datastrato.gravitino.Audit; | ||
import com.datastrato.gravitino.Group; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.Preconditions; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** Represents a Group Data Transfer Object (DTO). */ | ||
public class GroupDTO implements Group { | ||
|
||
@JsonProperty("name") | ||
private String name; | ||
|
||
@Nullable | ||
@JsonProperty("properties") | ||
private Map<String, String> properties; | ||
|
||
@JsonProperty("audit") | ||
private AuditDTO audit; | ||
|
||
@JsonProperty("users") | ||
private List<String> users; | ||
|
||
/** Default constructor for Jackson deserialization. */ | ||
protected GroupDTO() {} | ||
|
||
/** | ||
* Creates a new instance of GroupDTO. | ||
* | ||
* @param name The name of the Group DTO. | ||
* @param users The collection of users which belongs to the group. | ||
* @param properties The properties of the Group DTO. | ||
* @param audit The audit information of the Group DTO. | ||
*/ | ||
protected GroupDTO( | ||
String name, List<String> users, Map<String, String> properties, AuditDTO audit) { | ||
this.name = name; | ||
this.properties = properties; | ||
this.audit = audit; | ||
this.users = users; | ||
} | ||
|
||
/** @return The users of the Group DTO. */ | ||
@Override | ||
public List<String> users() { | ||
return users; | ||
} | ||
|
||
/** @return The name of the Group DTO. */ | ||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
/** @return The properties of the Group DTO. */ | ||
@Override | ||
public Map<String, String> properties() { | ||
return properties; | ||
} | ||
|
||
/** @return The audit information of the Group DTO. */ | ||
@Override | ||
public Audit auditInfo() { | ||
return audit; | ||
} | ||
|
||
/** | ||
* Creates a new Builder for constructing a Group DTO. | ||
* | ||
* @return A new Builder instance. | ||
*/ | ||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
/** | ||
* Builder class for constructing a GroupDTO instance. | ||
* | ||
* @param <S> The type of the builder instance. | ||
*/ | ||
public static class Builder<S extends Builder> { | ||
/** The name of the group. */ | ||
protected String name; | ||
|
||
/** The properties of the group. */ | ||
protected Map<String, String> properties; | ||
|
||
/** The audit information of the group. */ | ||
protected AuditDTO audit; | ||
|
||
/** The users of the group. */ | ||
protected List<String> users; | ||
|
||
/** | ||
* Sets the name of the group. | ||
* | ||
* @param name The name of the group. | ||
* @return The builder instance. | ||
*/ | ||
public S withName(String name) { | ||
this.name = name; | ||
return (S) this; | ||
} | ||
|
||
/** | ||
* Sets the properties of the group. | ||
* | ||
* @param properties The properties of the group. | ||
* @return The builder instance. | ||
*/ | ||
public S withProperties(Map<String, String> properties) { | ||
this.properties = properties; | ||
return (S) this; | ||
} | ||
|
||
/** | ||
* Sets the audit information of the group. | ||
* | ||
* @param audit The audit information of the group. | ||
* @return The builder instance. | ||
*/ | ||
public S withAudit(AuditDTO audit) { | ||
this.audit = audit; | ||
return (S) this; | ||
} | ||
|
||
/** | ||
* Sets the users of the group. | ||
* | ||
* @param users The users of the group. | ||
* @return The builder instance. | ||
*/ | ||
public S withUsers(List<String> users) { | ||
this.users = users; | ||
return (S) this; | ||
} | ||
|
||
/** | ||
* Builds an instance of GroupDTO using the builder's properties. | ||
* | ||
* @return An instance of GroupDTO. | ||
* @throws IllegalArgumentException If the name or audit are not set. | ||
*/ | ||
public GroupDTO build() { | ||
Preconditions.checkArgument(StringUtils.isNotBlank(name), "name cannot be null or empty"); | ||
Preconditions.checkArgument(audit != null, "audit cannot be null"); | ||
Preconditions.checkArgument( | ||
CollectionUtils.isNotEmpty(users), "users cannot be null or empty"); | ||
return new GroupDTO(name, users, properties, audit); | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
common/src/main/java/com/datastrato/gravitino/dto/requests/GroupCreateRequest.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,65 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.dto.requests; | ||
|
||
import com.datastrato.gravitino.rest.RESTRequest; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.Preconditions; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.annotation.Nullable; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import lombok.extern.jackson.Jacksonized; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** Request to create a group. */ | ||
@Getter | ||
@EqualsAndHashCode | ||
@ToString | ||
@Builder | ||
@Jacksonized | ||
public class GroupCreateRequest implements RESTRequest { | ||
|
||
@JsonProperty("name") | ||
private final String name; | ||
|
||
@JsonProperty("users") | ||
private final List<String> users; | ||
|
||
@Nullable | ||
@JsonProperty("properties") | ||
private final Map<String, String> properties; | ||
|
||
/** Default constructor for GroupCreateRequest. (Used for Jackson deserialization.) */ | ||
public GroupCreateRequest() { | ||
this(null, null, null); | ||
} | ||
|
||
/** | ||
* Creates a new GroupCreateRequest. | ||
* | ||
* @param name The name of the group. | ||
* @param users The users of the group. | ||
* @param properties The properties of the group. | ||
*/ | ||
public GroupCreateRequest(String name, List<String> users, Map<String, String> properties) { | ||
super(); | ||
this.name = name; | ||
this.properties = properties; | ||
this.users = users; | ||
} | ||
|
||
@Override | ||
public void validate() throws IllegalArgumentException { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(name), "\"name\" field is required and cannot be empty"); | ||
Preconditions.checkArgument( | ||
CollectionUtils.isEmpty(users), "\"users\" field is required and cannot be empty"); | ||
} | ||
} |
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
Oops, something went wrong.