-
Notifications
You must be signed in to change notification settings - Fork 1
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
Move automations linkrel types to separate namespace #293
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 0 additions & 39 deletions
39
...va/com/contentgrid/automations/rest/AutomationAnnotationRepresentationModelAssembler.java
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
...ations-rest/src/main/java/com/contentgrid/spring/automations/AutomationLinkRelations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.contentgrid.spring.automations; | ||
|
||
|
||
import lombok.experimental.UtilityClass; | ||
import org.springframework.hateoas.LinkRelation; | ||
import org.springframework.hateoas.UriTemplate; | ||
import org.springframework.hateoas.mediatype.hal.HalLinkRelation; | ||
|
||
@UtilityClass | ||
public class AutomationLinkRelations { | ||
static final String CURIE = "automation"; | ||
static final UriTemplate TEMPLATE = UriTemplate.of("https://contentgrid.cloud/rels/automation/{rel}"); | ||
|
||
public static final LinkRelation ANNOTATION = HalLinkRelation.curied(CURIE, "annotation"); | ||
public static final String ANNOTATION_STRING = CURIE+":annotation"; | ||
public static final LinkRelation TARGET_ENTITY = HalLinkRelation.curied(CURIE, "target-entity"); | ||
public static final LinkRelation REGISTRATIONS = HalLinkRelation.curied(CURIE, "registrations"); | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...src/main/java/com/contentgrid/spring/automations/ContentGridAutomationsConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.contentgrid.spring.automations; | ||
|
||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; | ||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; | ||
|
||
import com.contentgrid.spring.automations.rest.AutomationAnnotationRepresentationModelAssembler; | ||
import com.contentgrid.spring.automations.rest.AutomationRepresentationModelAssembler; | ||
import com.contentgrid.spring.automations.rest.AutomationsRestController; | ||
import com.contentgrid.spring.data.rest.hal.CurieProviderCustomizer; | ||
import com.contentgrid.thunx.spring.data.context.AbacContextSupplier; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.data.rest.webmvc.RepositoryLinksResource; | ||
import org.springframework.hateoas.server.RepresentationModelProcessor; | ||
|
||
@Import({ | ||
AutomationRepresentationModelAssembler.class, | ||
AutomationAnnotationRepresentationModelAssembler.class | ||
}) | ||
@Configuration(proxyBeanMethods = false) | ||
public class ContentGridAutomationsConfiguration { | ||
|
||
private static final String AUTOMATIONS_RESOURCE = "classpath:automation/automations.json"; | ||
|
||
@Bean | ||
AutomationsRestController automationsRestController( | ||
ResourceLoader resourceLoader, | ||
AutomationRepresentationModelAssembler assembler, | ||
AbacContextSupplier abacContextSupplier | ||
) { | ||
return new AutomationsRestController( | ||
resourceLoader.getResource(AUTOMATIONS_RESOURCE), | ||
assembler, | ||
abacContextSupplier | ||
); | ||
} | ||
|
||
@Bean | ||
CurieProviderCustomizer automationCurieProvider() { | ||
return CurieProviderCustomizer.register(AutomationLinkRelations.CURIE, AutomationLinkRelations.TEMPLATE); | ||
} | ||
|
||
@Bean | ||
RepresentationModelProcessor<RepositoryLinksResource> automationRepositoryLinksRepresentationModelProcessor() { | ||
// This must be a class instead of a lambda so the generic parameter can be determined by spring-hateoas | ||
return new RepresentationModelProcessor<RepositoryLinksResource>() { | ||
@Override | ||
public RepositoryLinksResource process(RepositoryLinksResource model) { | ||
return model.add( | ||
linkTo(methodOn(AutomationsRestController.class).getAutomations()) | ||
.withRel(AutomationLinkRelations.REGISTRATIONS) | ||
); | ||
} | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...contentgrid/spring/automations/rest/AutomationAnnotationRepresentationModelAssembler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.contentgrid.spring.automations.rest; | ||
|
||
import com.contentgrid.spring.automations.AutomationLinkRelations; | ||
import com.contentgrid.spring.automations.rest.AutomationsModel.AutomationAnnotationModel; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration; | ||
import org.springframework.data.rest.core.mapping.ResourceMappings; | ||
import org.springframework.data.rest.webmvc.ProfileController; | ||
import org.springframework.hateoas.Link; | ||
import org.springframework.hateoas.server.RepresentationModelAssembler; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class AutomationAnnotationRepresentationModelAssembler implements | ||
RepresentationModelAssembler<AutomationAnnotationModel, AutomationAnnotationRepresentationModel> { | ||
|
||
private final RepositoryRestConfiguration repositoryRestConfiguration; | ||
private final ResourceMappings mappings; | ||
|
||
@Override | ||
public AutomationAnnotationRepresentationModel toModel(AutomationAnnotationModel annotation) { | ||
return AutomationAnnotationRepresentationModel.from(annotation) | ||
.add(getTargetEntityLink(annotation)); | ||
} | ||
|
||
private Link getTargetEntityLink(AutomationAnnotationModel annotation) { | ||
var profileUrl = ProfileController.getPath(repositoryRestConfiguration, | ||
mappings.getMetadataFor(annotation.getEntityClass())); | ||
|
||
return Link.of(profileUrl, AutomationLinkRelations.TARGET_ENTITY); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...omations/rest/AutomationModelVisitor.java → ...omations/rest/AutomationModelVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...s/rest/AutomationRepresentationModel.java → ...s/rest/AutomationRepresentationModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...tomationRepresentationModelAssembler.java → ...tomationRepresentationModelAssembler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...id/automations/rest/AutomationsModel.java → ...ng/automations/rest/AutomationsModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...tions/rest/AutomationsRestController.java → ...tions/rest/AutomationsRestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ions/rest/AutomationModelVisitorTest.java → ...ions/rest/AutomationModelVisitorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...utomations/rest/AutomationsModelTest.java → ...utomations/rest/AutomationsModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 7 additions & 22 deletions
29
...tentgrid/spring/boot/autoconfigure/automation/ContentGridAutomationAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,20 @@ | ||
package com.contentgrid.spring.boot.autoconfigure.automation; | ||
|
||
import com.contentgrid.automations.rest.AutomationAnnotationRepresentationModelAssembler; | ||
import com.contentgrid.automations.rest.AutomationRepresentationModelAssembler; | ||
import com.contentgrid.automations.rest.AutomationsRestController; | ||
import com.contentgrid.spring.automations.ContentGridAutomationsConfiguration; | ||
import com.contentgrid.spring.boot.autoconfigure.data.web.ContentGridSpringDataRestAutoConfiguration; | ||
import com.contentgrid.thunx.predicates.model.ThunkExpression; | ||
import com.contentgrid.thunx.spring.data.context.AbacContextSupplier; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@AutoConfiguration | ||
@AutoConfiguration( | ||
after = ContentGridSpringDataRestAutoConfiguration.class | ||
) | ||
@ConditionalOnWebApplication | ||
@ConditionalOnClass({ AutomationsRestController.class, AbacContextSupplier.class, ThunkExpression.class }) | ||
vierbergenlars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Import({ | ||
AutomationRepresentationModelAssembler.class, | ||
AutomationAnnotationRepresentationModelAssembler.class | ||
}) | ||
@ConditionalOnClass({ContentGridAutomationsConfiguration.class, AbacContextSupplier.class, ThunkExpression.class}) | ||
@Import(ContentGridAutomationsConfiguration.class) | ||
public class ContentGridAutomationAutoConfiguration { | ||
|
||
@Autowired | ||
private ApplicationContext applicationContext; | ||
|
||
@Bean | ||
AutomationsRestController automationsRestController(AutomationRepresentationModelAssembler assembler, | ||
AbacContextSupplier abacContextSupplier) { | ||
return new AutomationsRestController(applicationContext.getResource("classpath:automation/automations.json"), | ||
assembler, abacContextSupplier); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this just be
automations:automations
? Because it's not like you can register at that endpoint.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, those objects are the automations themselves, are they?
They are registrations for automations; containing automation annotations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's right that you cannot add registrations here, but you can list the registrations that already there.