Skip to content
Merged
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
2 changes: 1 addition & 1 deletion commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.polyapi</groupId>
<artifactId>parent-pom</artifactId>
<version>0.2.6-SNAPSHOT</version>
<version>0.3.0-SNAPSHOT</version>
<relativePath>../parent-pom</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.polyapi.commons.api.error;

/**
* Parent exception for all exceptions that want to be handled during the execution of a Poly function.
* Requires a status code that will be returned to the user in case an exception happens.
*/
public abstract class PolyApiExecutionException extends PolyApiException {

/**
* See {@link PolyApiException#PolyApiException()}
*/
public PolyApiExecutionException() {
super();
}

/**
* See {@link PolyApiException#PolyApiException(String)}
*/
public PolyApiExecutionException(String message) {
super(message);
}

/**
* See {@link PolyApiException#PolyApiException(String, Throwable)}
*/
public PolyApiExecutionException(String message, Throwable cause) {
super(message, cause);
}

/**
* See {@link PolyApiException#PolyApiException(Throwable)}
*/
public PolyApiExecutionException(Throwable cause) {
super(cause);
}

public abstract int getStatusCode();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package io.polyapi.commons.api.error.http;

import io.polyapi.commons.api.error.PolyApiException;
import io.polyapi.commons.api.error.PolyApiExecutionException;
import io.polyapi.commons.api.http.Response;
import lombok.Getter;

import java.util.Optional;

/**
* Parent of exceptions thrown when the response from an HTTP request is different than 2XX.
* This class contains an instance of the {@link Response} returned.
*/
@Getter
public class HttpResponseException extends PolyApiException {
public class HttpResponseException extends PolyApiExecutionException {

private final Response response;

Expand All @@ -23,4 +25,9 @@ public HttpResponseException(String message, Response response) {
super(message);
this.response = response;
}

@Override
public int getStatusCode() {
return Optional.ofNullable(response).map(Response::statusCode).orElse(500);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public class UnexpectedInformationalResponseException extends HttpResponseException {

public UnexpectedInformationalResponseException(Response response) {
super(format("An unexpected informational response was received. Status code: %s.", response.statusCode()), response);
}
public UnexpectedInformationalResponseException(Response response) {
super(format("An unexpected informational response was received. Status code: %s.", response.statusCode()), response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.polyapi.commons.api.model;

/**
* Type of a Poly function.
*/
public enum FunctionType {
SERVER, CLIENT;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.polyapi.commons.api.model;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.Boolean.FALSE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Annotation that marks a specific method as a Poly function.
* When uploading functions,
*/
@Target(METHOD)
@Retention(RUNTIME)
public @interface PolyFunction {
FunctionType type() default FunctionType.SERVER;

String context() default "";

String name() default "";

boolean isDeployable() default true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.polyapi.commons.api.model;


import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Annotation that marks a class as generated by Poly.
*/
@Target(TYPE)
@Retention(RUNTIME)
public @interface PolyGeneratedClass {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.polyapi.commons.api.model;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Target(METHOD)
@Retention(RUNTIME)
public @interface RequiredDependencies {
RequiredDependency[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.polyapi.commons.api.model;


import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Target(METHOD)
@Retention(RUNTIME)
@Repeatable(RequiredDependencies.class)
public @interface RequiredDependency {

String groupId() default "";

String artifactId() default ".*";

String version() default ".*";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

/**
* {@link TokenProvider} that always return the same set token.
*
* @deprecated This class should be replaced for one that obtains the token dynamically and refreshes it.
*/
public class HardcodedTokenProvider implements TokenProvider {

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.polyapi</groupId>
<artifactId>parent-pom</artifactId>
<version>0.2.6-SNAPSHOT</version>
<version>0.3.0-SNAPSHOT</version>
<relativePath>../parent-pom</relativePath>
</parent>
<artifactId>library</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion parent-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.polyapi</groupId>
<artifactId>parent-pom</artifactId>
<version>0.2.6-SNAPSHOT</version>
<version>0.3.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Poly API Java parent POM</name>
<url>https://polyapi.io</url>
Expand Down
7 changes: 6 additions & 1 deletion polyapi-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.polyapi</groupId>
<artifactId>parent-pom</artifactId>
<version>0.2.6-SNAPSHOT</version>
<version>0.3.0-SNAPSHOT</version>
<relativePath>../parent-pom</relativePath>
</parent>
<artifactId>polyapi-maven-plugin</artifactId>
Expand All @@ -29,6 +29,11 @@
</license>
</licenses>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.polyapi.plugin.error.deploy;

import io.polyapi.commons.api.error.PolyApiException;
import io.polyapi.plugin.error.PolyApiMavenPluginException;

import java.util.Collection;

/**
* Exception that wraps all the other exceptions thrown when deploying functions.
*/
public class DeploymentWrapperException extends PolyApiMavenPluginException {

public DeploymentWrapperException(Collection<? extends Throwable> suppressedExceptions) {
super("Exceptions occurred while deploying functions.");
suppressedExceptions.forEach(this::addSuppressed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.polyapi.plugin.error.validation;

import java.lang.reflect.Method;

import static java.lang.String.format;

public class InvalidPropertyException extends ValidationException {
public InvalidPropertyException(String propertyName, String propertyValue, Method method, String pattern) {
super(propertyName, format("Property '%s' with value '%s' of method '%s' doesn't match pattern '%s'.", "%s", propertyValue, method, pattern));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.polyapi.plugin.error.validation;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.stream.Collectors;

import static java.lang.String.format;

public class KeywordUseException extends ValidationException {
public KeywordUseException(String propertyName, String propertyValue, Method method, String... keywords) {
super(propertyName, format("Property '%s' with value '%s' of method '%s' uses Java keywords '%s'. Please rename the context accordingly.", "%s", propertyValue, method, Arrays.stream(keywords).collect(Collectors.joining("', '"))));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.polyapi.plugin.error.validation;

import io.polyapi.plugin.error.PolyApiMavenPluginException;
import lombok.Getter;

import static java.lang.String.format;

/**
* Parent class for exceptions thrown for validation purposes. Stores the name of the property being validated and injects it into the message.
*/
@Getter
public class ValidationException extends PolyApiMavenPluginException {

private final String propertyName;
Expand All @@ -33,8 +35,4 @@ public ValidationException(String propertyName, String messageTemplate, Throwabl
super(format(messageTemplate, propertyName), cause);
this.propertyName = propertyName;
}

public String getPropertyName() {
return propertyName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.polyapi.plugin.model.function;


import io.polyapi.commons.api.model.Visibility;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static java.lang.String.format;
import static java.util.stream.Collectors.joining;

@Getter
@Setter
public class CodeObject {
private String packageName;
private String className;
private String methodName;
private String params;
private String code;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class PolyFunction {
private String returnType;
private Visibility visibility;
private Boolean logsEnabled;
private List<String> requirements;

private Map<String, Object> returnTypeSchema;
private List<PolyFunctionArgument> arguments;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.polyapi.plugin.model.function;

import io.polyapi.commons.api.model.FunctionType;

import java.io.InputStream;
import java.util.List;

public record PolyFunctionMetadata(String name, String signature, FunctionType type, InputStream sourceCode, String context, List<String> dependencies, Boolean isDeployable) {

@Override
public String toString() {
return "PolyFunctionMetadata{" +
"name='" + name + '\'' +
", type=" + type +
", context='" + context + '\'' +
", dependencies=" + dependencies +
'}';
}

public String getTypedType() {
return type.name().toLowerCase();
}
}
Loading