Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GraphQL inheritance/interface support #1303

Open
wants to merge 15 commits into
base: elide-5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ dependency-reduced-pom.xml
.project
*/.project
*/*/.project
*.factorypath
*.vscode
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
branches:
only:
- master
- elide-5.x
- "/^[0-9]+\\.[0-9]+(\\.[0-9]+|-(alpha|beta)-[0-9]+)/"

install: true
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ Add Lifecycle hooks to your models to embed custom business logic that execute i
@Include(rootLevel = true)
@ReadPermission("Everyone")
@CreatePermission("Admin OR Publisher")
@DeletePermission("Noone")
@UpdatePermission("Noone")
@DeletePermission("None")
@UpdatePermission("None")
@LifeCycleHookBinding(operation = UPDATE, hook = BookCreationHook.class, phase = PRECOMMIT)
public class Book {

@Id
Expand All @@ -146,9 +147,13 @@ public class Book {

@ManyToMany(mappedBy = "books")
private Set<Author> authors;
}

public class BookCreationHook implements LifeCycleHook<Book> {

@OnCreatePreCommit
public void onCreate(RequestScope scope) {
@Override
public void execute(LifeCycleHookBinding.Operation operation, Book book,
RequestScope requestScope, Optional<ChangeSpec> changes) {
//Do something
}
}
Expand Down
4 changes: 3 additions & 1 deletion checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
<suppressions>
<!-- Suppress generated sources -->
<suppress files="[/\\]src[/\\]test[/\\]" checks="(JavadocType|LineLength|MethodLength)"/>
<suppress files="[/\\]src[/\\]test[/\\]" checks="(JavadocType|LineLength|MethodLength|MethodCount)"/>
<suppress files="[/\\]src[/\\]main[/\\]webapp[/\\]WEB-INF[/\\]api-docs[/\\]" checks=".*"/>
<suppress files="[/\\]target[/\\]" checks=".*"/>
<suppress files="\.csv" checks=".*"/>
<suppress files="\.json" checks="LineLength"/>
<suppress files="\.hbs" checks="LineLength"/>
</suppressions>
3 changes: 1 addition & 2 deletions elide-annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.yahoo.elide</groupId>
<artifactId>elide-parent-pom</artifactId>
<version>4.6.3-SNAPSHOT</version>
<version>5.0.0-pr10-SNAPSHOT</version>
</parent>

<licenses>
Expand Down Expand Up @@ -53,5 +53,4 @@
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2020, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.annotation;

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

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

/**
* Versions API Models.
*/
@Target({PACKAGE})
@Retention(RUNTIME)
public @interface ApiVersion {

/**
* Models in this package are tied to this API version.
* @return the string (default = "")
*/
String version() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

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

Expand All @@ -20,6 +19,5 @@
*/
@Target({METHOD, FIELD, TYPE, PACKAGE})
@Retention(RUNTIME)
@Inherited
public @interface Exclude {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

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

Expand All @@ -18,7 +17,6 @@
*/
@Target({TYPE, PACKAGE})
@Retention(RUNTIME)
@Inherited
public @interface Include {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2020, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.annotation;

import com.yahoo.elide.functions.LifeCycleHook;

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

/**
* Executes arbitrary logic (a lifecycle hook) when an Elide model is read or written.
*/
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(LifeCycleHookBindings.class)
public @interface LifeCycleHookBinding {

enum Operation {
CREATE,
READ,
UPDATE,
DELETE
};

enum TransactionPhase {
PRESECURITY,
PRECOMMIT,
POSTCOMMIT
}

/**
* The function to invoke when this life cycle triggers.
* @return the function class.
*/
Class<? extends LifeCycleHook> hook();

/**
* Which CRUD operation to trigger on.
* @return CREATE, READ, UPDATE, or DELETE
*/
Operation operation();

/**
* Which transaction phase to trigger on.
* @return PRESECURITY, PRECOMMIT, or POSTCOMMIT
*/
TransactionPhase phase() default TransactionPhase.PRECOMMIT;

/**
* Controls how often the hook is invoked:
* A hook is invoked once per class per request (when bound to the model).
* A hook is invoked once per field per request (when bound to a model field or method).
* A hook is invoked one or more times per class per request (when bound to a model and oncePerRequest is false).
* @return true or false.
*/
boolean oncePerRequest() default true;
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
/*
* Copyright 2016, Yahoo Inc.
* Copyright 2020, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.annotation;


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

/**
* On Delete trigger annotation.
*
* The invoked function takes a RequestScope as parameter.
* @see com.yahoo.elide.security.RequestScope
* A group of repeatable LifeCycleHookBinding annotations.
*/
@Target({ElementType.METHOD})
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface OnDeletePreSecurity {

public @interface LifeCycleHookBindings {
LifeCycleHookBinding[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2020, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.annotation;

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

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

/**
* Marks that the given entity cannot be added to another collection after creation of the entity.
*/
@Target({TYPE, PACKAGE})
@Retention(RUNTIME)
@Inherited
public @interface NonTransferable {

/**
* If NonTransferable is used at the package level, it can be disabled for individual entities by setting
* this flag to false.
* @return true if enabled.
*/
boolean enabled() default true;
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.