🧑💻 Improve Formatter
This commit is contained in:
parent
c8ecdce0e0
commit
3799cf822f
@ -8,23 +8,23 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
|
||||
import io.quarkus.panache.common.Parameters;
|
||||
|
||||
import dev.dinauer.metrics.service.model.Bucket;
|
||||
import dev.dinauer.metrics.service.model.BucketUnit;
|
||||
import dev.dinauer.metrics.service.model.Collection;
|
||||
|
||||
@ApplicationScoped
|
||||
public class Repo implements PanacheRepositoryBase<Collection, String>
|
||||
public class Repo implements PanacheRepositoryBase<Bucket, String>
|
||||
{
|
||||
public Optional<Collection> findByProperties(String resource, String name, String timestamp, BucketUnit bucketUnit)
|
||||
public Optional<Bucket> findByProperties(String resource, String name, String timestamp, BucketUnit bucketUnit)
|
||||
{
|
||||
return find("resource = :resource AND name = :name AND timestamp = :timestamp AND bucketUnit = :bucketUnit", Parameters.with("resource", resource).and("name", name).and("timestamp", timestamp).and("bucketUnit", bucketUnit)).firstResultOptional();
|
||||
}
|
||||
|
||||
public List<Collection> findByResourceAndMetricAndTimeUnit(String resource, String name, BucketUnit bucketUnit)
|
||||
public List<Bucket> findByResourceAndMetricAndTimeUnit(String resource, String name, BucketUnit bucketUnit)
|
||||
{
|
||||
return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit ORDER BY timestamp ASC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit));
|
||||
}
|
||||
|
||||
public List<Collection> findByResourceAndMetricAndTimeUnitAndPeriod(String resource, String name, BucketUnit bucketUnit, Long from, Long to)
|
||||
public List<Bucket> findByResourceAndMetricAndTimeUnitAndPeriod(String resource, String name, BucketUnit bucketUnit, Long from, Long to)
|
||||
{
|
||||
return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit AND (unix >= :from AND unix <= :to) ORDER BY timestamp ASC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit).and("from", from).and("to", to));
|
||||
}
|
||||
|
||||
@ -8,8 +8,8 @@ import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
|
||||
import dev.dinauer.metrics.service.client.auth.AuthenticationService;
|
||||
import dev.dinauer.metrics.service.model.Bucket;
|
||||
import dev.dinauer.metrics.service.model.BucketUnit;
|
||||
import dev.dinauer.metrics.service.model.Collection;
|
||||
|
||||
@Path("/{resource}/{metric}")
|
||||
public class Resource
|
||||
@ -34,7 +34,7 @@ public class Resource
|
||||
}
|
||||
|
||||
@GET
|
||||
public List<Collection> get(@PathParam("resource") String resource, @PathParam("metric") String metric, @QueryParam("bucket-unit") Optional<BucketUnit> bucketUnit)
|
||||
public List<Bucket> get(@PathParam("resource") String resource, @PathParam("metric") String metric, @QueryParam("bucket-unit") Optional<BucketUnit> bucketUnit)
|
||||
{
|
||||
if (authenticationService.canRead())
|
||||
{
|
||||
|
||||
@ -9,8 +9,8 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
import dev.dinauer.metrics.service.model.Bucket;
|
||||
import dev.dinauer.metrics.service.model.BucketUnit;
|
||||
import dev.dinauer.metrics.service.model.Collection;
|
||||
import dev.dinauer.metrics.service.utils.BucketConfigProvider;
|
||||
import dev.dinauer.metrics.service.utils.TimestampGenerator;
|
||||
|
||||
@ -34,7 +34,7 @@ public class Service
|
||||
for (BucketUnit unit : bucketConfigProvider.get())
|
||||
{
|
||||
String timestamp = TimestampGenerator.generateTimestamp(now, unit);
|
||||
Collection metrics = repo.findByProperties(resource, metric, timestamp, unit).orElse(new Collection(resource, metric, timestamp, now.toEpochSecond(), unit));
|
||||
Bucket metrics = repo.findByProperties(resource, metric, timestamp, unit).orElse(new Bucket(resource, metric, timestamp, now.toEpochSecond(), unit));
|
||||
for (Map.Entry<String, Double> entry : values.entrySet())
|
||||
{
|
||||
Double value = entry.getValue();
|
||||
@ -47,7 +47,7 @@ public class Service
|
||||
}
|
||||
}
|
||||
|
||||
public List<Collection> get(String resource, String metric, BucketUnit unit)
|
||||
public List<Bucket> get(String resource, String metric, BucketUnit unit)
|
||||
{
|
||||
return repo.findByResourceAndMetricAndTimeUnit(resource, metric, unit);
|
||||
}
|
||||
|
||||
@ -2,7 +2,8 @@ package dev.dinauer.metrics.service.client;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record Client(String id, String password, Permission permission) {
|
||||
public record Client(String id, String password, Permission permission)
|
||||
{
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
|
||||
@ -44,10 +44,12 @@ public class AuthenticationService
|
||||
AuthHeader header = getAuthHeader();
|
||||
switch (header.type())
|
||||
{
|
||||
case BASIC -> {
|
||||
case BASIC:
|
||||
{
|
||||
return basicAuthClientProvider.get(header.credentials());
|
||||
}
|
||||
case BEARER -> {
|
||||
case BEARER:
|
||||
{
|
||||
return bearerAuthClientProvider.get(header.credentials());
|
||||
}
|
||||
}
|
||||
@ -65,7 +67,8 @@ public class AuthenticationService
|
||||
try
|
||||
{
|
||||
return new AuthHeader(AuthType.valueOf(sections[0].toUpperCase()), sections[1]);
|
||||
} catch (IllegalArgumentException e)
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import java.util.Optional;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import jakarta.ws.rs.NotFoundException;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
|
||||
@ -36,9 +37,11 @@ public class BearerAuthClientProvider
|
||||
{
|
||||
return new Client(user.get(), null, Permission.RO);
|
||||
}
|
||||
throw new NotFoundException();
|
||||
}
|
||||
throw new UnauthorizedException();
|
||||
} catch (ParseException e)
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
package dev.dinauer.metrics.service.client.auth.utils;
|
||||
|
||||
public record AuthHeader(AuthType type, String credentials) {
|
||||
public record AuthHeader(AuthType type, String credentials)
|
||||
{
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
package dev.dinauer.metrics.service.client.auth.utils;
|
||||
|
||||
public record BasicAuthCredentials(String clientId, String password) {
|
||||
public record BasicAuthCredentials(String clientId, String password)
|
||||
{
|
||||
}
|
||||
|
||||
@ -14,8 +14,8 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@Entity
|
||||
@Table(name = "collection")
|
||||
public class Collection
|
||||
@Table(name = "bucket")
|
||||
public class Bucket
|
||||
{
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@ -41,6 +41,8 @@ public class Collection
|
||||
@Column(columnDefinition = "text", nullable = false)
|
||||
private String metrics;
|
||||
|
||||
private String owner;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private ZonedDateTime createdAt;
|
||||
@ -49,11 +51,11 @@ public class Collection
|
||||
@Column(name = "updated_at")
|
||||
private ZonedDateTime updatedAt;
|
||||
|
||||
public Collection()
|
||||
public Bucket()
|
||||
{
|
||||
}
|
||||
|
||||
public Collection(String resource, String name, String timestamp, long unixTimestamp, BucketUnit bucketUnit)
|
||||
public Bucket(String resource, String name, String timestamp, long unixTimestamp, BucketUnit bucketUnit)
|
||||
{
|
||||
this.id = UUID.randomUUID().toString();
|
||||
this.resource = resource;
|
||||
@ -86,7 +88,8 @@ public class Collection
|
||||
try
|
||||
{
|
||||
this.metrics = OBJECT_MAPPER.writeValueAsString(metrics);
|
||||
} catch (JsonProcessingException e)
|
||||
}
|
||||
catch (JsonProcessingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -128,7 +131,8 @@ public class Collection
|
||||
return OBJECT_MAPPER.readValue(metrics, new TypeReference<Map<String, Metric>>()
|
||||
{
|
||||
});
|
||||
} catch (JsonProcessingException e)
|
||||
}
|
||||
catch (JsonProcessingException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -144,7 +148,7 @@ public class Collection
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public Collection setCreatedAt(ZonedDateTime createdAt)
|
||||
public Bucket setCreatedAt(ZonedDateTime createdAt)
|
||||
{
|
||||
this.createdAt = createdAt;
|
||||
return this;
|
||||
@ -155,7 +159,7 @@ public class Collection
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public Collection setUpdatedAt(ZonedDateTime updatedAt)
|
||||
public Bucket setUpdatedAt(ZonedDateTime updatedAt)
|
||||
{
|
||||
this.updatedAt = updatedAt;
|
||||
return this;
|
||||
Loading…
x
Reference in New Issue
Block a user