Merge branch 'develop' into f/message_processing

This commit is contained in:
Kai S. K. Engelbart 2020-01-04 16:54:36 +02:00
commit 597385c950
12 changed files with 529 additions and 4 deletions

View File

@ -34,5 +34,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="/envoy-common"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

38
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: CyB3RC0nN0R, delvh, DieGurke, derharry333
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.

View File

@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: CyB3RC0nN0R, delvh, DieGurke
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

10
.github/PULL_REQUEST_TEMPLATE/bugfix.md vendored Normal file
View File

@ -0,0 +1,10 @@
---
name: Bug fix
title: Fixed Bug
labels: bug
assignees: CyB3RC0nN0R, delvh, DieGurke
reviewers: CyB3RC0nN0R, delvh
projects: Envoy
milestone: Envoy v0.3-alpha
---
Fixes #{issue}

View File

@ -0,0 +1,9 @@
---
name: Feature integration
title: Added feature
labels: enhancement
assignees: CyB3RC0nN0R, delvh, DieGurke
reviewers: CyB3RC0nN0R, delvh
projects: Envoy
milestone: Envoy v0.3-alpha
---

View File

@ -0,0 +1,9 @@
---
name: Updated Javadoc
title: Updated Javadoc
labels: documentation
assignees: CyB3RC0nN0R, delvh
reviewers: CyB3RC0nN0R, delvh
projects: Envoy
milestone: Envoy v0.3-alpha
---

22
.github/workflows/stale.yml vendored Normal file
View File

@ -0,0 +1,22 @@
name: Mark stale issues and pull requests
on:
schedule:
- cron: "0 0 * * *"
jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
stale-issue-label: 'no-issue-activity'
days-before-stale: 60
days-before-close: 7
stale-pr-label: 'no-pr-activity'
operations-per-run: 30

File diff suppressed because one or more lines are too long

161
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,161 @@
# Contributing to Envoy
Looking to contribute something to Envoy? **Here's how you can help.**
Please take a moment to review this document in order to make the contribution
process easy and effective for everyone involved.
Following these guidelines helps to communicate that you respect the time of
the developers managing and developing this open source project. In return,
they should reciprocate that respect in addressing your issue or assessing
patches and features.
## Using the issue tracker
The [issue tracker](https://github.com/informatik-ag-ngl/envoy-server-standalone/issues) is
the preferred channel for [bug reports](#bug-reports), [features requests](#feature-requests)
and [submitting pull requests](#pull-requests), but please respect the following
restrictions:
* Please **do not** derail or troll issues. Keep the discussion on topic and
respect the opinions of others.
* Please **do not** post comments consisting solely of "+1" or ":thumbsup:".
Use [GitHub's "reactions" feature](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/)
instead. We reserve the right to delete comments which violate this rule.
However, as we know, we are all software engineers that like being funny hence doing it on purpose. Please also refrain from that kind of behaviour.
## Issues and labels
Our bug tracker utilizes several labels to help organize and identify issues. Here's what they represent and how we use them:
- `Documentation` & `Javadoc`- Issues regarding the documentation of Envoy
- `Enhancement` & `Feature` - Issues suggesting a new feature
- `Maven` - Issues concerned with Maven problems
- `Bug` - Issues concerned with a general bug
For a complete look at our labels, see the [project labels page](https://github.com/informatik-ag-ngl/envoy-server-standalone/labels).
## Bug reports
A bug is a _demonstrable problem_ that is caused by the code in the repository.
Good bug reports are extremely helpful, so thanks!
Guidelines for bug reports:
0. **ensure your problem isn't caused by a simple error in your own code**.
1. **Use the GitHub issue search** &mdash; check if the issue has already been
reported.
2. **Check if the issue has been fixed** &mdash; try to reproduce it using the
latest `master` or development branch in the repository.
3. **Isolate the problem** &mdash; ideally create a reduced test
case and a live example.
A good bug report shouldn't leave others needing to chase you up for more
information. Please try to be as detailed as possible in your report. What is
your environment? What steps will reproduce the issue? These details will help people to fix
any potential bugs.
Example:
> Short and descriptive example bug report title
>
> 1. This is the first step
> 2. This is the second step
> 3. Further steps, etc.
>
> Any other information you want to share that is relevant to the issue being
> reported. This might include the lines of code that you have identified as
> causing the bug, and potential solutions (and your opinions on their
> merits).
## Feature requests
Feature requests are welcome. But take a moment to find out whether your idea
fits with the scope and aims of the project. It's up to *you* to make a strong
case to convince the project's developers of the merits of this feature. Please
provide as much detail and context as possible.
## Pull requests
Good pull requests—patches, improvements, new features—are a fantastic
help. They should remain focused in scope and avoid containing unrelated
commits.
**Please ask first** before embarking on any significant pull request (e.g.
implementing features, refactoring code, porting to a different language),
otherwise you risk spending a lot of time working on something that the
project's developers might not want to merge into the project.
Please adhere to the [coding guidelines](#code-guidelines) used throughout the
project (indentation, accurate comments, etc.) and any other requirements
(such as test coverage).
Adhering to the following process is the best way to get your work
included in the project:
1. Download, clone or [Fork](https://help.github.com/articles/fork-a-repo/) the project, using [https://github.com/informatik-ag-ngl/envoy-server-standalone/](https://github.com/informatik-ag-ngl/envoy-server-standalone/)as Remote.
2. If you cloned a while ago, get the latest changes from upstream:
```bash
git checkout master
git pull upstream master
```
Or, if your IDE of choice supports this, simply use `pull`
3. Create a new topic branch (off the main project development branch) to
contain your feature, change, or fix:
```bash
git checkout -b <topic-branch-name>
```
Or, simply use "New branch" if your IDE supports this
4. Commit your changes in logical chunks. Please adhere to these [git commit
message guidelines](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
or your code is unlikely be merged into the main project. Use Git's
[interactive rebase](https://help.github.com/articles/about-git-rebase/)
feature to tidy up your commits before making them public.
5. Locally merge (or rebase) the upstream development branch into your topic branch:
```bash
git pull [--rebase] upstream master
```
6. Push your topic branch up to your fork:
```bash
git push origin <topic-branch-name>
```
7. [Open a Pull Request](https://help.github.com/articles/about-pull-requests/)
with a clear title and description against the `master` branch.
**IMPORTANT**: By submitting a patch, you agree to allow the project owners to
license your work under the terms of the [MIT License](../LICENSE) (if it
includes code changes) and under the terms of the
[Creative Commons Attribution 3.0 Unported License](https://creativecommons.org/licenses/by/3.0/)
(if it includes documentation changes).
## Code guidelines
### Java
Please use the formatter provided with this project. Especially before saving. For best results, select the option "format code" in the "Save Actions" tab in Preferences in Eclipse, so that you never accidentally forget it.
Every public function (not annotated with `@Override`) must be delivered with Javadoc. For best project-appropriate Javadoc please take a look at the other functions which are all already equipped with Javadoc.
## License
By contributing your code, you agree to license your contribution under the [MIT License](../LICENSE).
By contributing to the documentation, you agree to license your contribution under the [Creative Commons Attribution 3.0 Unported License](https://creativecommons.org/licenses/by/3.0/).

View File

@ -4,20 +4,35 @@ import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import envoy.data.MessageBuilder;
/**
* This class serves as a way to let Hibernate communicate with the server
* without bringing the dependency of JPA/Hibernate into the client.<br>
* It will be referenced as "database message" to clarify between the different
* message objects.<br>
* <br>
* Project: <strong>envoy-server-standalone</strong><br>
* File: <strong>Message.java</strong><br>
* Created: <strong>02.01.2020</strong><br>
*
*
* @author Kai S. K. Engelbart
* @since Envoy Server Standalone v0.1-alpha
*/
@Entity
@Table(name = "messages")
@NamedQueries(
{ @NamedQuery(query = "SELECT m FROM Message m WHERE m.recipient =:recipient AND m.state = 1", name = "getUnreadMessages"), @NamedQuery(
query = "SELECT m FROM Message m WHERE m.sender =:sender AND m.state = :state",
name = "find read messages"//TODO do we need this namedQuery?
), @NamedQuery(query = "SELECT m FROM Message m WHERE m.id = :messageId", name = "get message") }//TODO do we need this namedQuery?
)
public class Message {
@Id
@ -33,49 +48,147 @@ public class Message {
private String text;
private byte[] attachment;
/**
* The constructor for a database object
*
* @since Envoy Server Standalone v0.1-alpha
*/
public Message() {}
// TODO: everything except ID
public Message(envoy.data.Message message) { id = message.getId(); }
/**
* @param message the {@link envoy.data.Message} to convert into a database
* {@link Message}
* @since Envoy Server Standalone v0.1-alpha
*/
public Message(envoy.data.Message message) {
id = message.getId();
status = message.getStatus();
text = message.getText();
}
/**
* @return a database {@link Message} converted into an
* {@link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
public envoy.data.Message toCommonMessage() {
// TODO: Attachment, dates
return new MessageBuilder(sender.getId(), recipient.getId()).setText(text).setDate(creationDate).setStatus(status).build();
}
/**
* @return the id of a {link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
public long getId() { return id; }
/**
* @param id the id to set
* @since Envoy Server Standalone v0.1-alpha
* @see Message#getId()
*/
public void setId(long id) { this.id = id; }
/**
* @return the sender of a {link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
public User getSender() { return sender; }
/**
* @param sender the sender to set
* @since Envoy Server Standalone v0.1-alpha
* @see Message#getSender()
*/
public void setSender(User sender) { this.sender = sender; }
/**
* @return the recipient of a {link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
public User getRecipient() { return recipient; }
/**
* @param recipient the recipient to set
* @since Envoy Server Standalone v0.1-alpha
* @see Message#getRecipient()
*/
public void setRecipient(User recipient) { this.recipient = recipient; }
/**
* @return the date at which a {link envoy.data.Message} has been created
* @since Envoy Server Standalone v0.1-alpha
*/
public Date getCreationDate() { return creationDate; }
/**
* @param creationDate the creation date to set
* @since Envoy Server Standalone v0.1-alpha
* @see Message#getCreationDate()
*/
public void setCreationDate(Date creationDate) { this.creationDate = creationDate; }
/**
* @return the date at which a {link envoy.data.Message} has been received by
* the server
* @since Envoy Server Standalone v0.1-alpha
*/
public Date getReceivedDate() { return receivedDate; }
/**
* @param receivedDate the received date to set
* @since Envoy Server Standalone v0.1-alpha
* @see Message#getReceivedDate()
*/
public void setReceivedDate(Date receivedDate) { this.receivedDate = receivedDate; }
/**
* @return the date at which a {link envoy.data.Message} has been read
* @since Envoy Server Standalone v0.1-alpha
*/
public Date getReadDate() { return readDate; }
/**
* @param readDate the read date to set
* @since Envoy Server Standalone v0.1-alpha
* @see Message#getReadDate()
*/
public void setReadDate(Date readDate) { this.readDate = readDate; }
/**
* @return the status of a {link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
public envoy.data.Message.MessageStatus getStatus() { return status; }
/**
* @param status the new status of a {link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
public void setStatus(envoy.data.Message.MessageStatus status) { this.status = status; }
/**
* @return the text content of a {link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
public String getText() { return text; }
/**
* @param text the new text content of a {@link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
public void setText(String text) { this.text = text; }
/**
* @return the attachment of a {@link envoy.data.Message}
* @since Envoy Server Standalone v0.1-alpha
*/
public byte[] getAttachment() { return attachment; }
/**
* @param attachment the new attachment
* @since Envoy Server Standalone v0.1-alpha
*/
public void setAttachment(byte[] attachment) { this.attachment = attachment; }
}

View File

@ -7,18 +7,27 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* This class serves as a way to let Hibernate communicate with the server
* without bringing the dependency of JPA/Hibernate into the client.<br>
* It will be referenced as "database user" to clarify between the different
* user objects.<br>
* <br>
* Project: <strong>envoy-server-standalone</strong><br>
* File: <strong>User.java</strong><br>
* Created: <strong>02.01.2020</strong><br>
*
*
* @author Kai S. K. Engelbart
* @since Envoy Server Standalone v0.1-alpha
*/
@Entity
@Table(name = "users")
@NamedQuery(query = "SELECT u FROM DBUser u WHERE u.id = :id", name = "getUserById")
public class User {
@Id
@ -31,27 +40,81 @@ public class User {
private envoy.data.User.UserStatus status;
private List<User> contacts;
/**
* @return the id of a {link envoy.data.User}
* @since Envoy Server Standalone v0.1-alpha
*/
public long getId() { return id; }
/**
* @param id the id to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getId
*/
public void setId(long id) { this.id = id; }
/**
* @return the name of a {link envoy.data.User}
* @since Envoy Server Standalone v0.1-alpha
*/
public String getName() { return name; }
/**
* @param name the username to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getName()
*/
public void setName(String name) { this.name = name; }
/**
* @return the passwordHash of a {link envoy.data.User}
* @since Envoy Server Standalone v0.1-alpha
*/
public byte[] getPasswordHash() { return passwordHash; }
/**
* @param passwordHash the password hash to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getPasswordHash()
*/
public void setPasswordHash(byte[] passwordHash) { this.passwordHash = passwordHash; }
/**
* @return the last date an {link envoy.data.User} has been online
* @since Envoy Server Standalone v0.1-alpha
*/
public Date getLastSeen() { return lastSeen; }
/**
* @param lastSeen the latest date at which has been seen to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getLastSeen()
*/
public void setLastSeen(Date lastSeen) { this.lastSeen = lastSeen; }
/**
* @return the status of a {link envoy.data.User}
* @since Envoy Server Standalone v0.1-alpha
*/
public envoy.data.User.UserStatus getStatus() { return status; }
/**
* @param status the status to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getStatus()
*/
public void setStatus(envoy.data.User.UserStatus status) { this.status = status; }
/**
* @return the contacts of a {link envoy.data.User}
* @since Envoy Server Standalone v0.1-alpha
*/
public List<User> getContacts() { return contacts; }
/**
* @param contacts the contacts to set
* @since Envoy Server Standalone v0.1-alpha
* @see User#getContacts()
*/
public void setContacts(List<User> contacts) { this.contacts = contacts; }
}

View File

@ -0,0 +1,78 @@
package envoy.server.database;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import org.hibernate.Session;
import envoy.server.data.Message;
import envoy.server.data.User;
/**
* Project: <strong>envoy-server-standalone</strong><br>
* File: <strong>PersistenceManager.java</strong><br>
* Created: <strong>1 Jan 2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy Server Standalone v0.1-alpha
*/
public class PersistenceManager {
private EntityManager entityManager = Persistence.createEntityManagerFactory("envoy").createEntityManager();
/**
* Adds a {@link User} to the database.
*
* @param User the {@link User} to add to the database
* @since Envoy Server Standalone v0.1-alpha
*/
public void addUser(User User) { entityManager.persist(User); }
/**
* Adds a {@link Message} to the database.
*
* @param message the {@link Message} to add to the database
* @since Envoy Server Standalone v0.1-alpha
*/
public void addMessage(Message message) { entityManager.persist(message); }
/**
* Updates a {@link User} in the database
*
* @param user the {@link User} to add to the database
* @since Envoy Server Standalone v0.1-alpha
*/
public void updateUser(User user) { entityManager.unwrap(Session.class).merge(user); }
/**
* Updates a {@link Message} in the database.
*
* @param message the message to update
* @since Envoy Server Standalone v0.1-alpha
*/
public void updateMessage(Message message) { entityManager.unwrap(Session.class).merge(message); }
/**
* Searches for a user with a specific id.
*
* @param id - the id to search for
* @return the user with the specified id
* @since Envoy Server Standalone v0.1-alpha
*/
public User getUserById(long id) { return (User) entityManager.createNamedQuery("getUserById").setParameter("id", id).getSingleResult(); }
/**
* Returns all messages received while being offline.
*
* @param user - the user who wants to receive his unread messages
* @return all messages that the client does not yet have (unread messages)
* @since Envoy Server Standalone v0.1-alpha
*/
@SuppressWarnings("unchecked")
public List<Message> getUnreadMessages(User user) {
// TODO may need to be changed to clientId
return entityManager.createNamedQuery("getUnreadMessages").setParameter("recipient", user).getResultList();
}
}