Skip to content

Commit

Permalink
Convert 5 arguments model actions
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Lacasse <[email protected]>
  • Loading branch information
lacasseio committed May 23, 2023
1 parent 8461923 commit 51ec179
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import dev.nokee.model.internal.registry.ModelRegistry;
import dev.nokee.model.internal.state.ModelState;
import dev.nokee.model.internal.tags.ModelComponentTag;
import dev.nokee.model.internal.tags.ModelTags;
import dev.nokee.model.internal.type.ModelType;
import dev.nokee.model.internal.type.TypeOf;
import dev.nokee.platform.base.ComponentSources;
Expand Down Expand Up @@ -81,11 +80,13 @@ protected void execute(ModelNode entity, ModelComponentTag<IsLanguageSourceSet>
}
});

// ComponentFromEntity<ParentComponent> read-only self
project.getExtensions().getByType(ModelConfigurer.class).configure(ModelActionWithInputs.of(ModelTags.referenceOf(IsLanguageSourceSet.class), ModelComponentReference.of(ModelPathComponent.class), ModelComponentReference.of(DisplayNameComponent.class), ModelComponentReference.of(ElementNameComponent.class), ModelComponentReference.of(ModelState.IsAtLeastCreated.class), (entity, ignored1, path, displayName, elementName, ignored2) -> {
val parentIdentifier = entity.find(ParentComponent.class).map(parent -> parent.get().get(IdentifierComponent.class).get()).orElse(null);
entity.addComponent(new IdentifierComponent(new DefaultDomainObjectIdentifier(elementName.get(), parentIdentifier, displayName.get(), path.get())));
}));
project.getExtensions().getByType(ModelConfigurer.class).configure(new ModelActionWithInputs.ModelAction5<ModelComponentTag<IsLanguageSourceSet>, ModelPathComponent, DisplayNameComponent, ElementNameComponent, ModelState.IsAtLeastCreated>() {
// ComponentFromEntity<ParentComponent> read-only self
protected void execute(ModelNode entity, ModelComponentTag<IsLanguageSourceSet> ignored1, ModelPathComponent path, DisplayNameComponent displayName, ElementNameComponent elementName, ModelState.IsAtLeastCreated ignored2) {
val parentIdentifier = entity.find(ParentComponent.class).map(parent -> parent.get().get(IdentifierComponent.class).get()).orElse(null);
entity.addComponent(new IdentifierComponent(new DefaultDomainObjectIdentifier(elementName.get(), parentIdentifier, displayName.get(), path.get())));
}
});
project.getExtensions().getByType(ModelConfigurer.class).configure(new OnDiscover(ModelActionWithInputs.of(ModelComponentReference.ofProjection(ModelType.of(new TypeOf<ModelBackedSourceAwareComponentMixIn<? extends ComponentSources, ? extends ComponentSources>>() {})), ModelComponentReference.of(IdentifierComponent.class), (entity, projection, identifier) -> {
val registry = project.getExtensions().getByType(ModelRegistry.class);
Class<ComponentSources> type = (Class<ComponentSources>) sourcesType((ModelType<SourceAwareComponent<? extends ComponentSources>>)projection.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import dev.nokee.model.internal.registry.ModelRegistry;
import dev.nokee.model.internal.state.ModelState;
import dev.nokee.model.internal.state.ModelStates;
import dev.nokee.model.internal.tags.ModelTags;
import dev.nokee.model.internal.tags.ModelComponentTag;
import dev.nokee.model.internal.type.ModelType;
import dev.nokee.model.internal.type.TypeOf;
import dev.nokee.platform.base.Binary;
Expand Down Expand Up @@ -192,13 +192,15 @@ protected void execute(ModelNode entity, ModelState.IsAtLeastFinalized ignored,
.build());
})));

// ComponentFromEntity<ParentComponent> read-only self
project.getExtensions().getByType(ModelConfigurer.class).configure(ModelActionWithInputs.of(ModelTags.referenceOf(IsTask.class), ModelComponentReference.of(ModelPathComponent.class), ModelComponentReference.of(DisplayNameComponent.class), ModelComponentReference.of(ElementNameComponent.class), ModelComponentReference.of(ModelState.IsAtLeastCreated.class), (entity, ignored1, path, displayName, elementName, ignored2) -> {
if (!entity.has(IdentifierComponent.class)) {
val parentIdentifier = entity.find(ParentComponent.class).map(parent -> parent.get().get(IdentifierComponent.class).get()).orElse(null);
entity.addComponent(new IdentifierComponent(new DefaultDomainObjectIdentifier(elementName.get(), parentIdentifier, displayName.get(), path.get())));
project.getExtensions().getByType(ModelConfigurer.class).configure(new ModelActionWithInputs.ModelAction5<ModelComponentTag<IsTask>, ModelPathComponent, DisplayNameComponent, ElementNameComponent, ModelState.IsAtLeastCreated>() {
// ComponentFromEntity<ParentComponent> read-only self
protected void execute(ModelNode entity, ModelComponentTag<IsTask> ignored1, ModelPathComponent path, DisplayNameComponent displayName, ElementNameComponent elementName, ModelState.IsAtLeastCreated ignored2) {
if (!entity.has(IdentifierComponent.class)) {
val parentIdentifier = entity.find(ParentComponent.class).map(parent -> parent.get().get(IdentifierComponent.class).get()).orElse(null);
entity.addComponent(new IdentifierComponent(new DefaultDomainObjectIdentifier(elementName.get(), parentIdentifier, displayName.get(), path.get())));
}
}
}));
});

project.getPluginManager().apply(ComponentElementsCapabilityPlugin.class);

Expand Down

0 comments on commit 51ec179

Please sign in to comment.