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

Issue 2244 #2594

Closed
wants to merge 20 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions api/src/main/java/com/datastrato/gravitino/Group.java
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();
}
25 changes: 25 additions & 0 deletions api/src/main/java/com/datastrato/gravitino/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
package com.datastrato.gravitino;

import java.util.Map;

/** The interface of a user. The user is the entity which executes every operations. */
public interface User extends Auditable {

/**
* The name of the user.
*
* @return The name of the user.
*/
String name();

/**
* The properties of the user. Note, this method will return null if the properties are not set.
*
* @return The properties of the user.
*/
Map<String, String> properties();
}
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);
}
}
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);
}
}
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;

/** An exception thrown when a user is not found. */
public class NoSuchUserException 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 NoSuchUserException(@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 NoSuchUserException(Throwable cause, String message, Object... args) {
super(cause, message, args);
}
}
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;

/** An exception thrown when a resource already exists. */
public class UserAlreadyExistsException 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 UserAlreadyExistsException(@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 UserAlreadyExistsException(Throwable cause, String message, Object... args) {
super(cause, message, args);
}
}
160 changes: 160 additions & 0 deletions common/src/main/java/com/datastrato/gravitino/dto/GroupDTO.java
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);
}
}
}
Loading
Loading