Skip to content

Commit

Permalink
add some extra logging
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed May 26, 2024
1 parent 4c50117 commit 7363e26
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import javax.inject.Inject;
import org.dominokit.brix.annotations.Global;
import org.dominokit.brix.events.BrixEvent;
Expand All @@ -45,6 +46,8 @@ public abstract class Presenter<V extends Viewable>

private static final Logger LOGGER = LoggerFactory.getLogger(Presenter.class);

private final String ID = UUID.randomUUID().toString();

@Inject @Global protected AppHistory globalRouter;

@Inject @Global protected BrixEvents events;
Expand All @@ -65,7 +68,7 @@ public abstract class Presenter<V extends Viewable>
private Set<ChildListener> childListeners = new HashSet<>();

public Presenter() {
LOGGER.info("Presenter [" + this.getClass().getCanonicalName() + "] have been created.");
LOGGER.info("Presenter [" + this + "] have been created.");
}

private V getView() {
Expand Down Expand Up @@ -102,11 +105,11 @@ public final TokenFilter getTokenFilter() {
}

protected void postConstruct() {
LOGGER.info("Presenter [" + this.getClass().getCanonicalName() + "] : PostConstruct.");
LOGGER.info("Presenter [" + this + "] : PostConstruct.");
}

private void onAttached() {
LOGGER.info("Presenter [" + this.getClass().getCanonicalName() + "] : Attached.");
LOGGER.info("Presenter [" + this + "] : Attached.");
registerSlots();
onRevealed();
onReady();
Expand All @@ -115,7 +118,7 @@ private void onAttached() {
protected void registerSlots() {}

private void onReady() {
LOGGER.info("Presenter [" + this.getClass().getCanonicalName() + "] : Ready.");
LOGGER.info("Presenter [" + this + "] : Ready.");
Set<ChildListener> temp = new HashSet<>(childListeners);
temp.forEach(
listener -> {
Expand All @@ -125,7 +128,7 @@ private void onReady() {
}

private void onDetached() {
LOGGER.info("Presenter [" + this.getClass().getCanonicalName() + "] : Detached.");
LOGGER.info("Presenter [" + this + "] : Detached.");
onRemoved();
if (active) {
deactivate();
Expand All @@ -139,17 +142,21 @@ protected boolean isAutoReveal() {
@Override
public void onEventReceived(BrixEvent event) {}

protected boolean isEnabled() {
return true;
}

void doActivate() {
if (!active) {
if (!active && isEnabled()) {
if (getAuthorizer().isAuthorized(securityContext, this)) {
LOGGER.info("Presenter [" + this.getClass().getCanonicalName() + "] : Activating.");
LOGGER.info("Presenter [" + this + "] : Activating.");
slotListenerRecord = slots.listen(this);
setAttachHandlers();
setNavigationInterceptor();
eventsListenerRecord = events.register(this);
this.active = true;
onActivated();
LOGGER.info("Presenter [" + this.getClass().getCanonicalName() + "] : Activated.");
LOGGER.info("Presenter [" + this + "] : Activated.");
tryReveal();
} else {
securityContext.reportUnAuthorizedAccess();
Expand Down Expand Up @@ -330,4 +337,9 @@ void registerChildListener(ChildListener listener) {
interface ChildListener {
void invoke();
}

@Override
public String toString() {
return this.getClass().getCanonicalName() + "[" + ID + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@

public interface Viewable {
boolean isAttached();

String getId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static java.util.Objects.nonNull;
import static org.dominokit.domino.ui.utils.Domino.elementOf;

import elemental2.dom.DomGlobal;
import elemental2.dom.Element;
import org.dominokit.brix.api.Slot;
import org.dominokit.brix.api.Viewable;
Expand Down Expand Up @@ -62,6 +63,7 @@ public String getKey() {
public void reveal(Viewable view) {
if (nonNull(view)) {
if (view instanceof IsElement<?>) {
DomGlobal.console.info("Revealing view [" + view.getId() + "] into slot [" + key + "]");
element.clearElement().appendChild((IsElement<? extends Element>) view);
} else {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static java.util.Objects.nonNull;
import static org.dominokit.domino.ui.utils.Domino.elementOf;

import elemental2.dom.DomGlobal;
import elemental2.dom.Element;
import org.dominokit.brix.api.BrixSlots;
import org.dominokit.brix.api.Slot;
Expand Down Expand Up @@ -50,6 +51,8 @@ public void reveal(Viewable view) {
if (nonNull(view)) {
if (view instanceof IsElement<?>) {
remove(currentView);
DomGlobal.console.info(
"Revealing view [" + view.getId() + "] into slot [" + getKey() + "]");
body.appendChild((IsElement<? extends Element>) view);
this.currentView = view;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import dagger.Binds;
import dagger.Lazy;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.IntoSet;
import java.io.IOException;
import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -187,7 +186,8 @@ private void processModule(ImmutableSetMultimap<String, Element> elementsByAnnot
.addStatement("return this.coreComponent")
.build());

generateStartupTasks(elementsByAnnotation, superModule);
TypeSpec typeSpec = generateStartupTasks(moduleName, elementsByAnnotation);
writeFile(typeSpec, element);

elementsByAnnotation
.get(BrixPresenter.class.getCanonicalName())
Expand Down Expand Up @@ -892,24 +892,31 @@ private void generateRoutingTask(Element presenter, TypeSpec.Builder bindingModu
}
}

private void generateStartupTasks(
ImmutableSetMultimap<String, Element> elementsByAnnotation, TypeSpec.Builder superModule) {
private TypeSpec generateStartupTasks(
String moduleName, ImmutableSetMultimap<String, Element> elementsByAnnotation) {

TypeSpec.Builder tasksModule =
TypeSpec.interfaceBuilder(
"Brix" + sourceUtil.capitalizeFirstLetter(moduleName) + "TasksModule_")
.addAnnotation(Module.class);
elementsByAnnotation
.get(Task.class.getCanonicalName())
.forEach(
taskElement -> {
superModule.addMethod(
tasksModule.addMethod(
MethodSpec.methodBuilder(
sourceUtil.smallFirstLetter(taskElement.getSimpleName().toString()))
.addAnnotation(Singleton.class)
.addAnnotation(IntoSet.class)
.addAnnotation(Provides.class)
.addAnnotation(Binds.class)
.addAnnotation(BrixTask.class)
.addModifiers(Modifier.PUBLIC)
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.addParameter(
ParameterSpec.builder(TypeName.get(taskElement.asType()), "task").build())
.returns(StartupTask.class)
.addStatement("return new $T()", taskElement)
.build());
});
return tasksModule.build();
}

private void writeFile(TypeSpec typeSpec, Element element) {
Expand Down
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<domino.history.version>1.0.3</domino.history.version>
<domino.ui.version>2.0.1</domino.ui.version>
<domino.auto.version>1.0.2</domino.auto.version>
<dagger.version>2.51.1</dagger.version>
</properties>

<dependencyManagement>
Expand All @@ -113,21 +114,26 @@
<artifactId>guava</artifactId>
<version>32.0.1-jre</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId>
<version>1.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.dagger/dagger -->
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2.49</version>
<version>${dagger.version}</version>
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-gwt</artifactId>
<version>2.49</version>
<version>${dagger.version}</version>
</dependency>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.49</version>
<version>${dagger.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit 7363e26

Please sign in to comment.