Fixed GCubeUser null on reload session problem

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@141293 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-12-20 17:45:40 +00:00
parent d8d07438e5
commit d79a47c741
7 changed files with 150 additions and 35 deletions

View File

@ -81,6 +81,7 @@ public class AccountingManagerController {
*/
private void sessionExpiredShow() {
Log.error("Session expired");
// CheckSession.showLogoutDialog();
}
@ -569,7 +570,10 @@ public class AccountingManagerController {
+ Constants.EXPORT_SERVLET_ACCOUNTING_TYPE_PARAMETER + "="
+ event.getAccountingType().name() + "&"
+ Constants.CURR_GROUP_ID + "="
+ GCubeClientContext.getCurrentContextId());
+ GCubeClientContext.getCurrentContextId()
+ "&"
+ Constants.CURR_USER_ID + "="
+ GCubeClientContext.getCurrentUserId());
Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), event.getAccountingType().toString(),

View File

@ -85,8 +85,11 @@ public class ExportServlet extends HttpServlet {
try {
String scopeGroupId = request
.getParameter(Constants.CURR_GROUP_ID);
String currUserId = request
.getParameter(Constants.CURR_USER_ID);
serviceCredentials = SessionUtil.getServiceCredentials(request,
scopeGroupId);
scopeGroupId, currUserId);
ScopeProvider.instance.set(serviceCredentials.getScope());
} catch (ServiceException e) {

View File

@ -18,7 +18,10 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.Context;
import org.gcube.portlets.admin.accountingmanager.shared.exception.ServiceException;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
@ -36,12 +39,12 @@ public class SessionUtil {
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest) throws ServiceException {
return getServiceCredentials(httpServletRequest, null);
return getServiceCredentials(httpServletRequest, null, null);
}
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest, String scopeGroupId)
throws ServiceException {
HttpServletRequest httpServletRequest, String scopeGroupId,
String currUserId) throws ServiceException {
ServiceCredentials sCredentials = null;
String userName = null;
@ -62,6 +65,7 @@ public class SessionUtil {
logger.info("Retrieving credential in session!");
PortalContext pContext = PortalContext.getConfiguration();
boolean hasScopeGroupId = false;
boolean hasCurrUserId = false;
if (scopeGroupId != null && !scopeGroupId.isEmpty()) {
hasScopeGroupId = true;
@ -70,6 +74,13 @@ public class SessionUtil {
hasScopeGroupId = false;
}
if (currUserId != null && !currUserId.isEmpty()) {
hasCurrUserId = true;
} else {
hasCurrUserId = false;
}
if (hasScopeGroupId) {
scope = pContext.getCurrentScope(scopeGroupId);
} else {
@ -83,8 +94,22 @@ public class SessionUtil {
throw new ServiceException(error);
}
GCubeUser gCubeUser = pContext.getCurrentUser(httpServletRequest);
GCubeUser gCubeUser = null;
if (hasCurrUserId) {
try {
gCubeUser = new LiferayUserManager().getUserById(Long
.valueOf(currUserId));
} catch (Exception e) {
String error = "Error retrieving gCubeUser for: [userId= "
+ currUserId + ", scope: " + scope + "]";
logger.error(error, e);
throw new ServiceException(error);
}
} else {
gCubeUser = pContext.getCurrentUser(httpServletRequest);
}
if (gCubeUser == null) {
String error = "Error retrieving gCubeUser in scope " + scope
+ ": " + gCubeUser;
@ -110,22 +135,16 @@ public class SessionUtil {
throw new ServiceException(error);
}
String name = gCubeUser
.getFirstName();
String lastName = gCubeUser
.getLastName();
String fullName = gCubeUser
.getFullname();
String name = gCubeUser.getFirstName();
String lastName = gCubeUser.getLastName();
String fullName = gCubeUser.getFullname();
String userAvatarURL = gCubeUser
.getUserAvatarURL();
String userAvatarURL = gCubeUser.getUserAvatarURL();
String email = gCubeUser.getEmail();
String email = gCubeUser
.getEmail();
if (hasScopeGroupId) {
groupId = scopeGroupId;
long gId;
@ -158,7 +177,6 @@ public class SessionUtil {
}
sCredentials = new ServiceCredentials(userName, fullName, name,
lastName, email, scope, groupId, groupName, userAvatarURL,
token);

View File

@ -10,7 +10,9 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesReques
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesJob;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobBasic;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobContext;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobDataContext;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobDataTop;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobDefinition;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.job.SeriesJobTop;
@ -128,11 +130,40 @@ public class AccountingModel4Job extends AccountingModelBuilder {
}
}
} else {
logger.error("Unsupported Serie Definition for Job: "
+ definition);
throw new ServiceException(
"Unsupported Serie Definition for Job: "
+ definition);
if (definition instanceof SeriesJobContext) {
SeriesJobContext seriesJobContext = (SeriesJobContext) definition;
fileName = "JobContext_" + periodType + "_" + startDate
+ "_" + endDate;
header = new ArrayList<>(Arrays.asList(new String[] {
"Value", "Date", "Operation Count", "Duration",
"Max Invocation", "Min Invocation" }));
ArrayList<SeriesJobDataContext> listDataContext = seriesJobContext
.getSeriesJobDataContextList();
for (SeriesJobDataContext seriesDataContext : listDataContext) {
ArrayList<SeriesJobData> listData = seriesDataContext
.getSeries();
for (SeriesJobData seriesData : listData) {
ArrayList<String> data = new ArrayList<>();
data.add(seriesDataContext.getContext());
data.add(sdfCSVDate.format(seriesData.getDate()));
data.add(String.valueOf(seriesData
.getOperationCount()));
data.add(String.valueOf(seriesData.getDuration()));
data.add(String.valueOf(seriesData
.getMaxInvocationTime()));
data.add(String.valueOf(seriesData
.getMinInvocationTime()));
AccountingDataRow csvDataRow = new AccountingDataRow(data);
rows.add(csvDataRow);
}
}
} else {
logger.error("Unsupported Serie Definition for Job: "
+ definition);
throw new ServiceException(
"Unsupported Serie Definition for Job: "
+ definition);
}
}
}
} else {

View File

@ -10,7 +10,9 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesReques
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesService;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceBasic;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceContext;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceDataContext;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceDataTop;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceDefinition;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.service.SeriesServiceTop;
@ -128,11 +130,40 @@ public class AccountingModel4Service extends AccountingModelBuilder {
}
}
} else {
logger.error("Unsupported Serie Definition for Service: "
+ definition);
throw new ServiceException(
"Unsupported Serie Definition for Service: "
+ definition);
if (definition instanceof SeriesServiceContext) {
SeriesServiceContext seriesServiceContext = (SeriesServiceContext) definition;
fileName = "ServiceContext_" + periodType + "_" + startDate
+ "_" + endDate;
header = new ArrayList<>(Arrays.asList(new String[] {
"Value", "Date", "Operation Count", "Duration",
"Max Invocation", "Min Invocation" }));
ArrayList<SeriesServiceDataContext> listDataContext = seriesServiceContext
.getSeriesServiceDataContextList();
for (SeriesServiceDataContext seriesDataContext : listDataContext) {
ArrayList<SeriesServiceData> listData = seriesDataContext
.getSeries();
for (SeriesServiceData seriesData : listData) {
ArrayList<String> data = new ArrayList<>();
data.add(seriesDataContext.getContext());
data.add(sdfCSVDate.format(seriesData.getDate()));
data.add(String.valueOf(seriesData
.getOperationCount()));
data.add(String.valueOf(seriesData.getDuration()));
data.add(String.valueOf(seriesData
.getMaxInvocationTime()));
data.add(String.valueOf(seriesData
.getMinInvocationTime()));
AccountingDataRow csvDataRow = new AccountingDataRow(data);
rows.add(csvDataRow);
}
}
} else {
logger.error("Unsupported Serie Definition for Service: "
+ definition);
throw new ServiceException(
"Unsupported Serie Definition for Service: "
+ definition);
}
}
}
} else {

View File

@ -10,7 +10,9 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesReques
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorage;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageBasic;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageContext;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageData;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageDataContext;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageDataTop;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageDefinition;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.storage.SeriesStorageTop;
@ -121,11 +123,35 @@ public class AccountingModel4Storage extends AccountingModelBuilder {
}
}
} else {
logger.error("Unsupported Serie Definition for Storage: "
+ definition);
throw new ServiceException(
"Unsupported Serie Definition for Storage: "
+ definition);
if (definition instanceof SeriesStorageContext) {
SeriesStorageContext seriesStorageContext = (SeriesStorageContext) definition;
fileName = "StorageContext_" + periodType + "_" + startDate
+ "_" + endDate;
header = new ArrayList<>(
Arrays.asList(new String[] { "Value", "Date",
"Operation Count", "Data Volume" }));
ArrayList<SeriesStorageDataContext> listDataContext = seriesStorageContext
.getSeriesStorageDataContextList();
for (SeriesStorageDataContext seriesDataContext : listDataContext) {
ArrayList<SeriesStorageData> listData = seriesDataContext
.getSeries();
for (SeriesStorageData seriesData : listData) {
ArrayList<String> data = new ArrayList<>();
data.add(seriesDataContext.getContext());
data.add(sdfCSVDate.format(seriesData.getDate()));
data.add(String.valueOf(seriesData.getOperationCount()));
data.add(String.valueOf(seriesData.getDataVolume()));
AccountingDataRow csvDataRow = new AccountingDataRow(data);
rows.add(csvDataRow);
}
}
} else {
logger.error("Unsupported Serie Definition for Storage: "
+ definition);
throw new ServiceException(
"Unsupported Serie Definition for Storage: "
+ definition);
}
}
}
} else {

View File

@ -13,6 +13,7 @@ public class Constants {
public static final boolean TEST_ENABLE = false;
public static final String CURR_GROUP_ID = "CURR_GROUP_ID";
public static final String CURR_USER_ID = "CURR_USER_ID";
public static final String APPLICATION_ID = "org.gcube.portlets.admin.accountingmanager.server.portlet.AccountingManagerPortlet";
public static final String ACCOUNTING_MANAGER_ID = "AccountingManagerId";
@ -38,5 +39,6 @@ public class Constants {
// IS Resource
public static final String ACCOUNTING_NAME = "AccountingManager";
public static final String ACCOUNTING_CATEGORY = "AccountingProfile";
}