1872: fix sending statistics
This commit is contained in:
parent
26ea8a3a85
commit
bb8979a9c7
5 changed files with 115 additions and 74 deletions
|
|
@ -0,0 +1,70 @@
|
||||||
|
package org.libreplan.web;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||||
|
import org.libreplan.business.users.daos.IUserDAO;
|
||||||
|
import org.libreplan.web.common.GatheredUsageStats;
|
||||||
|
import org.libreplan.web.expensesheet.IExpenseSheetModel;
|
||||||
|
import org.libreplan.web.materials.IMaterialsModel;
|
||||||
|
import org.libreplan.web.orders.IAssignedTaskQualityFormsToOrderElementModel;
|
||||||
|
import org.libreplan.web.orders.IOrderModel;
|
||||||
|
import org.libreplan.web.resources.machine.IMachineModel;
|
||||||
|
import org.libreplan.web.resources.worker.IWorkerModel;
|
||||||
|
import org.libreplan.web.security.SecurityUtils;
|
||||||
|
import org.libreplan.web.workreports.IWorkReportModel;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class StartupApplicationListener implements ApplicationListener {
|
||||||
|
|
||||||
|
private static final Log LOG = LogFactory.getLog(StartupApplicationListener.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IConfigurationDAO configurationDAO;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IUserDAO userDAO;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IOrderModel orderModel;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IWorkReportModel workReportModel;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IWorkerModel workerModel;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMachineModel machineModel;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IExpenseSheetModel expenseSheetModel;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IMaterialsModel materialsModel;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IAssignedTaskQualityFormsToOrderElementModel assignedQualityFormsModel;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(ApplicationEvent event) {
|
||||||
|
// Send data to server
|
||||||
|
if (!SecurityUtils.isGatheredStatsAlreadySent &&
|
||||||
|
configurationDAO.getConfigurationWithReadOnlyTransaction().isAllowToGatherUsageStatsEnabled()) {
|
||||||
|
GatheredUsageStats gatheredUsageStats = new GatheredUsageStats();
|
||||||
|
|
||||||
|
gatheredUsageStats.setupNotAutowiredClasses(userDAO, orderModel, workReportModel, workerModel, machineModel,
|
||||||
|
expenseSheetModel, materialsModel, assignedQualityFormsModel);
|
||||||
|
|
||||||
|
gatheredUsageStats.sendGatheredUsageStatsToServer();
|
||||||
|
SecurityUtils.isGatheredStatsAlreadySent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -21,50 +21,13 @@
|
||||||
|
|
||||||
package org.libreplan.web.common;
|
package org.libreplan.web.common;
|
||||||
|
|
||||||
import static org.libreplan.web.I18nHelper._;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ConcurrentModificationException;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import javax.mail.Session;
|
|
||||||
import javax.mail.Transport;
|
|
||||||
import javax.mail.AuthenticationFailedException;
|
|
||||||
import javax.mail.MessagingException;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
import javax.ws.rs.core.Response.Status;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.cxf.jaxrs.client.WebClient;
|
import org.apache.cxf.jaxrs.client.WebClient;
|
||||||
import org.libreplan.business.calendars.entities.BaseCalendar;
|
import org.libreplan.business.calendars.entities.BaseCalendar;
|
||||||
import org.libreplan.business.common.daos.IConfigurationDAO;
|
import org.libreplan.business.common.daos.IConfigurationDAO;
|
||||||
import org.libreplan.business.common.entities.Configuration;
|
import org.libreplan.business.common.entities.*;
|
||||||
import org.libreplan.business.common.entities.Connector;
|
|
||||||
import org.libreplan.business.common.entities.ConnectorProperty;
|
|
||||||
import org.libreplan.business.common.entities.EntityNameEnum;
|
|
||||||
import org.libreplan.business.common.entities.EntitySequence;
|
|
||||||
import org.libreplan.business.common.entities.LDAPConfiguration;
|
|
||||||
import org.libreplan.business.common.entities.PersonalTimesheetsPeriodicityEnum;
|
|
||||||
import org.libreplan.business.common.entities.PredefinedConnectorProperties;
|
|
||||||
import org.libreplan.business.common.entities.PredefinedConnectors;
|
|
||||||
import org.libreplan.business.common.entities.ProgressType;
|
|
||||||
import org.libreplan.business.common.exceptions.ValidationException;
|
import org.libreplan.business.common.exceptions.ValidationException;
|
||||||
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
|
import org.libreplan.business.costcategories.entities.TypeOfWorkHours;
|
||||||
import org.libreplan.business.users.entities.UserRole;
|
import org.libreplan.business.users.entities.UserRole;
|
||||||
|
|
@ -86,30 +49,17 @@ import org.zkoss.zk.ui.event.EventListener;
|
||||||
import org.zkoss.zk.ui.event.Events;
|
import org.zkoss.zk.ui.event.Events;
|
||||||
import org.zkoss.zk.ui.event.SelectEvent;
|
import org.zkoss.zk.ui.event.SelectEvent;
|
||||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||||
|
import org.zkoss.zul.*;
|
||||||
import org.zkoss.zkplus.spring.SpringUtil;
|
import org.zkoss.zul.api.Window;
|
||||||
import org.zkoss.zul.ListitemRenderer;
|
|
||||||
import org.zkoss.zul.Listbox;
|
|
||||||
import org.zkoss.zul.Grid;
|
|
||||||
import org.zkoss.zul.Combobox;
|
|
||||||
import org.zkoss.zul.Intbox;
|
|
||||||
import org.zkoss.zul.Textbox;
|
|
||||||
import org.zkoss.zul.Radiogroup;
|
|
||||||
import org.zkoss.zul.Listitem;
|
|
||||||
import org.zkoss.zul.Row;
|
|
||||||
import org.zkoss.zul.Constraint;
|
|
||||||
import org.zkoss.zul.RowRenderer;
|
|
||||||
import org.zkoss.zul.Comboitem;
|
|
||||||
import org.zkoss.zul.Radio;
|
|
||||||
import org.zkoss.zul.Button;
|
|
||||||
import org.zkoss.zul.Label;
|
|
||||||
import org.zkoss.zul.Rows;
|
|
||||||
import org.zkoss.zul.SimpleListModel;
|
|
||||||
import org.zkoss.zul.Messagebox;
|
|
||||||
|
|
||||||
import org.zkoss.zul.Window;
|
|
||||||
import org.zkoss.zul.impl.InputElement;
|
import org.zkoss.zul.impl.InputElement;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.libreplan.web.I18nHelper._;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for {@link Configuration} entity.
|
* Controller for {@link Configuration} entity.
|
||||||
*
|
*
|
||||||
|
|
@ -281,7 +231,7 @@ public class ConfigurationController extends GenericForwardComposer {
|
||||||
configurationModel.setDefaultCalendar(calendar);
|
configurationModel.setDefaultCalendar(calendar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() throws InterruptedException {
|
public void save() {
|
||||||
|
|
||||||
if ( getSelectedConnector() != null &&
|
if ( getSelectedConnector() != null &&
|
||||||
"E-mail".equals(getSelectedConnector().getName()) &&
|
"E-mail".equals(getSelectedConnector().getName()) &&
|
||||||
|
|
@ -305,7 +255,6 @@ public class ConfigurationController extends GenericForwardComposer {
|
||||||
sendDataToServer();
|
sendDataToServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( getSelectedConnector() != null &&
|
if ( getSelectedConnector() != null &&
|
||||||
!configurationModel.scheduleOrUnscheduleJobs(getSelectedConnector())) {
|
!configurationModel.scheduleOrUnscheduleJobs(getSelectedConnector())) {
|
||||||
|
|
||||||
|
|
@ -336,7 +285,7 @@ public class ConfigurationController extends GenericForwardComposer {
|
||||||
SecurityUtils.isGatheredStatsAlreadySent = true;
|
SecurityUtils.isGatheredStatsAlreadySent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() throws InterruptedException {
|
public void cancel() {
|
||||||
configurationModel.cancel();
|
configurationModel.cancel();
|
||||||
messages.clearMessages();
|
messages.clearMessages();
|
||||||
messages.showMessage(Level.INFO, _("Changes have been canceled"));
|
messages.showMessage(Level.INFO, _("Changes have been canceled"));
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,7 @@ import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.*;
|
||||||
import java.net.URL;
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
@ -58,7 +57,6 @@ public class GatheredUsageStats {
|
||||||
|
|
||||||
private IAssignedTaskQualityFormsToOrderElementModel assignedTaskQualityFormsToOrderElementModel;
|
private IAssignedTaskQualityFormsToOrderElementModel assignedTaskQualityFormsToOrderElementModel;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Version of this statistics implementation.
|
* Version of this statistics implementation.
|
||||||
* Just increment it, if you will change something related to JSON object.
|
* Just increment it, if you will change something related to JSON object.
|
||||||
|
|
@ -158,14 +156,25 @@ public class GatheredUsageStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateID() {
|
private String generateID() {
|
||||||
|
String ip = null;
|
||||||
|
String hostname = null;
|
||||||
|
|
||||||
// Make hash of ip + hostname
|
// Make hash of ip + hostname
|
||||||
WebAuthenticationDetails details =
|
try {WebAuthenticationDetails details =
|
||||||
(WebAuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails();
|
(WebAuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails();
|
||||||
|
|
||||||
String ip = details.getRemoteAddress();
|
ip = details.getRemoteAddress();
|
||||||
|
Execution execution = Executions.getCurrent();
|
||||||
Execution execution = Executions.getCurrent();
|
hostname = execution.getServerName();
|
||||||
String hostname = execution.getServerName();
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
InetAddress address = InetAddress.getLocalHost();
|
||||||
|
ip = address.getHostAddress();
|
||||||
|
hostname = address.getHostName();
|
||||||
|
} catch (UnknownHostException uhe) {
|
||||||
|
uhe.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String message = ip + hostname;
|
String message = ip + hostname;
|
||||||
byte[] encoded;
|
byte[] encoded;
|
||||||
|
|
@ -189,16 +198,17 @@ public class GatheredUsageStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
|
List<Order> allOrders = orderModel.getAllOrders();
|
||||||
setId(generateID());
|
setId(generateID());
|
||||||
setUsers(getUserRows());
|
setUsers(getUserRows());
|
||||||
setProjects(orderModel.getOrders().size());
|
setProjects(allOrders.size());
|
||||||
setTimesheets(workReportModel.getWorkReportDTOs().size());
|
setTimesheets(workReportModel.getWorkReportDTOs().size());
|
||||||
setWorkers(workerModel.getWorkers().size());
|
setWorkers(workerModel.getWorkers().size());
|
||||||
setMachines(machineModel.getMachines().size());
|
setMachines(machineModel.getMachines().size());
|
||||||
setExpensesheets(expenseSheetModel.getExpenseSheets().size());
|
setExpensesheets(expenseSheetModel.getExpenseSheets().size());
|
||||||
setMaterials(materialsModel.getMaterials().size());
|
setMaterials(materialsModel.getMaterials().size());
|
||||||
setQualityForms(assignedTaskQualityFormsToOrderElementModel.getAssignedQualityForms().size());
|
setQualityForms(assignedTaskQualityFormsToOrderElementModel.getAssignedQualityForms().size());
|
||||||
setOldestDate(orderModel.getOrders());
|
setOldestDate(allOrders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendGatheredUsageStatsToServer(){
|
public void sendGatheredUsageStatsToServer(){
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,8 @@ public interface IOrderModel extends IIntegrationEntityModel {
|
||||||
|
|
||||||
List<Order> getOrders();
|
List<Order> getOrders();
|
||||||
|
|
||||||
|
List<Order> getAllOrders();
|
||||||
|
|
||||||
List<Order> getOrders(Date startDate, Date endDate, List<Label> labels,
|
List<Order> getOrders(Date startDate, Date endDate, List<Label> labels,
|
||||||
List<Criterion> criteria, ExternalCompany customer,
|
List<Criterion> criteria, ExternalCompany customer,
|
||||||
OrderStatusEnum state, Boolean excludeFinishedProject);
|
OrderStatusEnum state, Boolean excludeFinishedProject);
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,16 @@ public class OrderModel extends IntegrationEntityModel implements IOrderModel {
|
||||||
return orders;
|
return orders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<Order> getAllOrders() {
|
||||||
|
getLabelsOnConversation().reattachLabels();
|
||||||
|
List<Order> orders = orderDAO.getOrders();
|
||||||
|
|
||||||
|
initializeOrders(orders);
|
||||||
|
return orders;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<Order> getOrders(Date startDate, Date endDate,
|
public List<Order> getOrders(Date startDate, Date endDate,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue