Skip to content

Commit

Permalink
What's a service???
Browse files Browse the repository at this point in the history
  • Loading branch information
gdoenlen committed Jul 26, 2024
1 parent ea4b34e commit d25f16f
Show file tree
Hide file tree
Showing 39 changed files with 345 additions and 678 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up the JDK
uses: actions/setup-java@v2
with:
java-version: '19'
java-version: '22'
distribution: 'zulu'
cache: maven
- name: Test with Maven
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<version>1.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>

<!--
Make sure you upgrade the ebean-migration dependency as well.
Expand All @@ -30,7 +30,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.12</version>
<version>1.3.14</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/github/sfxd/trust/core/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public Long getId() {
return this.id;
}

public Entity setId(Long id) {
public void setId(Long id) {
this.id = id;
return this;
}

public boolean isNew() {
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/com/github/sfxd/trust/core/EntityService.java

This file was deleted.

8 changes: 8 additions & 0 deletions src/main/java/com/github/sfxd/trust/core/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.sfxd.trust.core;

import com.github.sfxd.trust.core.users.User;

public interface Message {
User to();
String body();
}
8 changes: 0 additions & 8 deletions src/main/java/com/github/sfxd/trust/core/MessageService.java

This file was deleted.

6 changes: 6 additions & 0 deletions src/main/java/com/github/sfxd/trust/core/Messages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
package com.github.sfxd.trust.core;

public interface Messages {
void send(Message message);
}
31 changes: 22 additions & 9 deletions src/main/java/com/github/sfxd/trust/core/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
package com.github.sfxd.trust.core;

import java.util.Collection;
import java.util.Optional;

import io.ebean.DB;
import io.ebean.Database;
import io.ebean.Query;

/** The base of all finders */
public abstract class Repository<T extends Entity> {

protected final Class<T> clazz;
Expand All @@ -19,16 +17,11 @@ protected Repository(Class<T> clazz) {
this.database = DB.getDefault();
}

/**
* Finds an entity by its id
* @param id the id of the entity you want to find
* @return an optional containing the entity or empty
*/
public Optional<T> findById(Long id) {
public T findById(Long id) {
return this.query()
.where()
.idEq(id)
.findOneOrEmpty();
.findOne();
}

protected Query<T> query() {
Expand All @@ -39,11 +32,31 @@ public void insert(Collection<T> entities) {
this.database.insertAll(entities);
}

public void insert(T entity) {
this.database.insert(entity);
}

public void update(Collection<T> entities) {
this.database.updateAll(entities);
}

public void update(T entity) {
this.database.update(entity);
}

public void delete(Collection<T> entities) {
this.database.deleteAll(entities);
}

public void delete(T entity) {
this.database.delete(entity);
}

public void save(Collection<T> entities) {
this.database.saveAll(entities);
}

public void save(T entity) {
this.database.save(entity);
}
}
25 changes: 19 additions & 6 deletions src/main/java/com/github/sfxd/trust/core/instances/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.sfxd.trust.core.Entity;
import com.github.sfxd.trust.core.instanceusers.InstanceUser;
import com.github.sfxd.trust.core.subscription.Subscription;
import org.apache.commons.lang3.builder.DiffBuilder;
import org.apache.commons.lang3.builder.DiffResult;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
* Represents an SFDC instance. Sandbox or Production.
Expand Down Expand Up @@ -41,7 +44,7 @@ public class Instance extends Entity {
private Environment environment;

@OneToMany(mappedBy = "instance", cascade = CascadeType.REMOVE)
private List<InstanceUser> instanceUsers;
private List<Subscription> subscriptions;

public Instance() {

Expand Down Expand Up @@ -101,12 +104,12 @@ public Instance setEnvironment(Environment environment) {
return this;
}

public List<InstanceUser> getInstanceUsers() {
return this.instanceUsers;
public List<Subscription> getSubscriptions() {
return this.subscriptions;
}

public Instance setInstanceUsers(List<InstanceUser> instanceUsers) {
this.instanceUsers = instanceUsers;
public Instance setSubscriptions(List<Subscription> subscriptions) {
this.subscriptions = subscriptions;
return this;
}

Expand All @@ -118,6 +121,16 @@ public enum Environment {
PRODUCTION
}

public DiffResult<Instance> diff(Instance other) {
return new DiffBuilder<>(other, this, ToStringStyle.DEFAULT_STYLE, false)
.append("status", other.status, this.status)
.append("environment", other.environment, this.environment)
.append("location", other.location, this.location)
.append("releaseNumber", other.releaseNumber, this.releaseNumber)
.append("releaseVersion", other.releaseVersion, this.releaseVersion)
.build();
}

@Override
public boolean equals(Object other) {
if (other instanceof Instance i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
package com.github.sfxd.trust.core.instances;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.stream.Stream;

import javax.inject.Singleton;

import com.github.sfxd.trust.core.Repository;

/** Finder for the Instance model */
@Singleton
class InstanceFinder extends Repository<Instance> {
public class InstanceRepository extends Repository<Instance> {
private static final String KEY = "key";

InstanceFinder() {
InstanceRepository() {
super(Instance.class);
}

Expand All @@ -24,11 +24,11 @@ class InstanceFinder extends Repository<Instance> {
* @param key the instance's unique key you want to find
* @return the matching instances
*/
public Optional<Instance> findByKey(String key) {
public Instance findByKey(String key) {
return this.query()
.where()
.eq(KEY, key)
.findOneOrEmpty();
.findOne();
}

/**
Expand All @@ -37,12 +37,14 @@ public Optional<Instance> findByKey(String key) {
* @param keys the keys you want to filter by
* @return the matching instances
*/
public Stream<Instance> findByKeyIn(Collection<String> keys) {
return this.query()
public Collection<Instance> findByKeyIn(Collection<String> keys) {
var query = this.query()
.fetch("instanceUsers")
.where()
.in(KEY, keys)
.query()
.findStream();
.query();

return Collections.unmodifiableList(query.findList());
}

/**
Expand All @@ -51,11 +53,12 @@ public Stream<Instance> findByKeyIn(Collection<String> keys) {
* @param ids the ids you want to filter by
* @return the matching instances
*/
public Stream<Instance> findByIdIn(Collection<Long> ids) {
return this.query()
public Collection<Instance> findByIdIn(Collection<Long> ids) {
var query = this.query()
.where()
.idIn(ids)
.query()
.findStream();
.query();

return Collections.unmodifiableList(query.findList());
}
}
Loading

0 comments on commit d25f16f

Please sign in to comment.