Skip to content

Commit

Permalink
runtime-core: Expose stored email address in API
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyknic committed Jan 25, 2017
1 parent d017649 commit 14fa12e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 17 deletions.
Expand Up @@ -37,8 +37,7 @@ public class StatisticsReporterComponentImpl implements StatisticsReporterCompon
private static final Logger LOGGER = LoggerManager.getLogger(StatisticsReporterComponentImpl.class);

private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private @Inject
InfoComponent infoComponent;
private @Inject InfoComponent infoComponent;

@ExecuteBefore(State.STARTED)
public void start() {
Expand Down
Expand Up @@ -16,21 +16,21 @@
*/
package com.speedment.runtime.core.internal.util;

import java.util.Optional;
import java.util.prefs.Preferences;

import static com.speedment.runtime.core.util.StaticClassUtil.instanceNotAllowed;
import static java.util.Objects.requireNonNull;
import java.util.Optional;
import java.util.prefs.Preferences;

/**
*
* @author Emil Forslund
* @since 3.0.2
*/
public final class EmailUtil {
public final class InternalEmailUtil {

private final static String FIELD_NAME = "user_mail";
private final static String DEFAULT_EMAIL = "no-mail-specified";
private final static Preferences PREFERENCES = Preferences.userNodeForPackage(EmailUtil.class);
private final static String FIELD_NAME = "user_mail";
private final static String DEFAULT_EMAIL = "no-mail-specified";
private final static Preferences PREFERENCES = Preferences.userNodeForPackage(InternalEmailUtil.class);

public static boolean hasEmail() {
final String storedEmail = PREFERENCES.get(FIELD_NAME, null);
Expand All @@ -55,7 +55,7 @@ public static void setEmail(String email) {
PREFERENCES.put(FIELD_NAME, email);
}

private EmailUtil() {
private InternalEmailUtil() {
instanceNotAllowed(getClass());
}
}
Expand Up @@ -100,7 +100,7 @@ private static void notifyEvent(InfoComponent infoComponent, final String event,
}

private static Param includeMail() {
return new Param("mail", EmailUtil.getEmail());
return new Param("mail", InternalEmailUtil.getEmail());
}

private static void sendPostRequest(final Collection<Param> params) {
Expand Down
Expand Up @@ -17,7 +17,7 @@
package com.speedment.runtime.core.internal.util.analytics;

import com.speedment.runtime.core.component.InfoComponent;
import com.speedment.runtime.core.internal.util.EmailUtil;
import com.speedment.runtime.core.internal.util.InternalEmailUtil;
import static java.util.stream.Collectors.joining;
import java.util.stream.Stream;

Expand Down Expand Up @@ -46,7 +46,7 @@ public String getContentURI(InfoComponent infoComponent) {
return Stream.of(infoComponent.getTitle(),
infoComponent.getImplementationVersion(),
eventName,
EmailUtil.getEmail()
InternalEmailUtil.getEmail()
).collect(joining(SEPARATOR));
}
}
@@ -0,0 +1,56 @@
package com.speedment.runtime.core.util;

import com.speedment.runtime.core.internal.util.InternalEmailUtil;
import static com.speedment.runtime.core.util.StaticClassUtil.instanceNotAllowed;

/**
* Reads and writes to the internal file where a user's email address is stored.
* This is used by the UI to know if it has already asked for a user's email
* address.
*
* @author Emil Forslund
* @since 3.0.2
*/
public final class EmailUtil {

/**
* Returns {@code true} if an email address has already been entered.
*
* @return {@code true} if an email exists, else {@code false}
*/
public static boolean hasEmail() {
return InternalEmailUtil.hasEmail();
}

/**
* Returns the email address of the current user.
*
* @return the email address
*/
public static String getEmail() {
return InternalEmailUtil.getEmail();
}

/**
* Removes the email address stored on the computer.
*/
public static void removeEmail() {
InternalEmailUtil.removeEmail();
}

/**
* Overwrites the email address stored (if any) with the one specified.
*
* @param email the new email address to store
*/
public static void setEmail(String email) {
InternalEmailUtil.setEmail(email);
}

/**
* Should not be instantiated.
*/
private EmailUtil() {
instanceNotAllowed(getClass());
}
}
Expand Up @@ -23,7 +23,7 @@
import com.speedment.runtime.core.component.ProjectComponent;
import com.speedment.runtime.core.internal.DefaultApplicationBuilder;
import com.speedment.runtime.core.internal.DefaultApplicationMetadata;
import com.speedment.runtime.core.internal.util.EmailUtil;
import com.speedment.runtime.core.internal.util.InternalEmailUtil;
import com.speedment.tool.core.brand.Palette;
import com.speedment.tool.core.internal.component.UserInterfaceComponentImpl;
import com.speedment.tool.core.internal.util.InjectionLoader;
Expand Down Expand Up @@ -65,7 +65,7 @@ public void start(Stage stage) throws Exception {
ui.start(this, stage);

if (projects.getProject().dbmses().noneMatch(dbms -> true)) {
if (EmailUtil.hasEmail()) {
if (InternalEmailUtil.hasEmail()) {
loader.loadAndShow("Connect");
} else {
loader.loadAndShow("MailPrompt");
Expand Down
Expand Up @@ -18,7 +18,7 @@

import com.speedment.common.injector.annotation.Inject;
import com.speedment.generator.core.component.EventComponent;
import com.speedment.runtime.core.internal.util.EmailUtil;
import com.speedment.runtime.core.internal.util.InternalEmailUtil;
import com.speedment.tool.core.component.UserInterfaceComponent;
import com.speedment.tool.core.event.UIEvent;
import com.speedment.tool.core.internal.util.InjectionLoader;
Expand Down Expand Up @@ -70,7 +70,7 @@ public void initialize(URL location, ResourceBundle resources) {

okey.setOnAction(ev -> {
injectionLoader.loadAndShow("Connect");
EmailUtil.setEmail(email.getText());
InternalEmailUtil.setEmail(email.getText());
eventComponent.notify(UIEvent.OPEN_CONNECT_WINDOW);
});

Expand Down

0 comments on commit 14fa12e

Please sign in to comment.