com.intellij.internal.statistic.connect.RemotelyConfigurableStatisticsService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-impl Show documentation
Show all versions of platform-impl Show documentation
A packaging of the IntelliJ Community Edition platform-impl library.
This is release number 1 of trunk branch 142.
The newest version!
package com.intellij.internal.statistic.connect;
import com.intellij.internal.statistic.StatisticsUploadAssistant;
import com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
public class RemotelyConfigurableStatisticsService implements StatisticsService {
private StatisticsConnectionService myConnectionService;
private StatisticsDataSender sender;
private StatisticsUploadAssistant myAssistant;
public RemotelyConfigurableStatisticsService(@NotNull StatisticsConnectionService connectionService,
@NotNull StatisticsDataSender sender,
@NotNull StatisticsUploadAssistant assistant) {
myConnectionService = connectionService;
this.sender = sender;
myAssistant = assistant;
}
@Override
public StatisticsResult send() {
synchronized (ApplicationStatisticsPersistenceComponent.class) {
final String serviceUrl = myConnectionService.getServiceUrl();
if (serviceUrl == null) {
return new StatisticsResult(StatisticsResult.ResultCode.ERROR_IN_CONFIG, "ERROR");
}
if (!myConnectionService.isTransmissionPermitted()) {
return new StatisticsResult(StatisticsResult.ResultCode.NOT_PERMITTED_SERVER, "NOT_PERMITTED");
}
String content = myAssistant.getData(myConnectionService.getDisabledGroups());
if (StringUtil.isEmptyOrSpaces(content)) {
return new StatisticsResult(StatisticsResult.ResultCode.NOTHING_TO_SEND, "NOTHING_TO_SEND");
}
try {
sender.send(serviceUrl, content);
StatisticsUploadAssistant.updateSentTime();
return new StatisticsResult(StatisticsResult.ResultCode.SEND, content);
}
catch (Exception e) {
return new StatisticsResult(StatisticsResult.ResultCode.SENT_WITH_ERRORS, e.getMessage() != null ? e.getMessage() : "NPE");
}
}
}
@Override
public Notification createNotification(@NotNull final String groupDisplayId, @Nullable NotificationListener listener) {
final String fullProductName = ApplicationNamesInfo.getInstance().getFullProductName();
final String companyName = ApplicationInfo.getInstance().getCompanyName();
String text =
"Please click I agree if you want to help make " + fullProductName +
" better or I don't agree otherwise. more...";
String title = "Help improve " + fullProductName + " by sending anonymous usage statistics to " + companyName;
return new Notification(groupDisplayId, title,
text,
NotificationType.INFORMATION,
listener);
}
@Nullable
@Override
public Map getStatisticsConfigurationLabels() {
// Use defaults
return null;
}
}