This repository has been archived by the owner on Oct 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [RFR-520] Move pre-oauth classes to v2 package * [RFR-520] Add User model with UUID from OAuth * Documentation & cleanup * Replace hamcrest with Junit.Assertion
- Loading branch information
Showing
14 changed files
with
188 additions
and
74 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright 2022 Cyface GmbH | ||
* | ||
* This file is part of the Cyface API Library. | ||
* | ||
* The Cyface API Library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Cyface API Library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with the Cyface API Library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package de.cyface.api.v2.model; | ||
|
||
import io.vertx.core.json.JsonObject; | ||
import org.bson.types.ObjectId; | ||
|
||
import java.util.Objects; | ||
|
||
import static io.vertx.ext.auth.mongo.MongoAuthorization.DEFAULT_USERNAME_FIELD; | ||
|
||
/** | ||
* This class represents a user. | ||
* | ||
* @author Armin Schnabel | ||
* @version 1.0.1 | ||
* @since 1.0.0 | ||
*/ | ||
public class User { | ||
|
||
/** | ||
* The identifier of the {@link User}. | ||
*/ | ||
private final ObjectId id; | ||
/** | ||
* The username of the {link User}. | ||
*/ | ||
private final String name; | ||
|
||
/** | ||
* Constructs a fully initialized instance of this class. | ||
* | ||
* @param id The identifier of the {@link User}. | ||
* @param name The username of the {link User}. | ||
*/ | ||
public User(final ObjectId id, final String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Constructs a fully initialized instance of this class. | ||
* | ||
* @param databaseValue A role entry from the database. | ||
*/ | ||
public User(final JsonObject databaseValue) { | ||
this.id = new ObjectId(databaseValue.getString("_id")); | ||
this.name = databaseValue.getString(DEFAULT_USERNAME_FIELD); | ||
} | ||
|
||
/** | ||
* @return The identifier of the {@link User}. | ||
*/ | ||
@SuppressWarnings("unused") // Part of the API | ||
public ObjectId getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* @return The identifier of the {@link User} as {@code String}. | ||
*/ | ||
@SuppressWarnings("unused") // Part of the API | ||
public String getIdString() { | ||
return id.toString(); | ||
} | ||
|
||
/** | ||
* @return The username of the {link User}. | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "User{" + | ||
"id=" + id + | ||
", name='" + name + '\'' + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
User user = (User) o; | ||
return id.equals(user.id) && name.equals(user.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name); | ||
} | ||
} |
Oops, something went wrong.