accounting-manager/src/main/java/org/gcube/portlets/admin/accountingmanager/server/AccountingManagerServiceImp...

141 lines
4.4 KiB
Java

package org.gcube.portlets.admin.accountingmanager.server;
import java.util.ArrayList;
import java.util.Arrays;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.portlets.admin.accountingmanager.client.rpc.AccountingManagerService;
import org.gcube.portlets.admin.accountingmanager.server.amservice.AccountingCaller;
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingType;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterKey;
import org.gcube.portlets.admin.accountingmanager.shared.data.query.SeriesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesResponse;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
import org.gcube.portlets.admin.accountingmanager.shared.session.UserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class AccountingManagerServiceImpl extends RemoteServiceServlet
implements AccountingManagerService {
private static Logger logger = LoggerFactory
.getLogger(AccountingManagerServiceImpl.class);
/**
* {@inheritDoc}
*/
@Override
public void init() throws ServletException {
super.init();
System.out.println("Fix JAXP: jdk.xml.entityExpansionLimit=0");
System.setProperty("jdk.xml.entityExpansionLimit", "0");
System.out.println("initializing AccountingManager");
}
/**
*
* {@inheritDoc}
*/
@Override
public UserInfo hello() throws AccountingManagerServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
UserInfo userInfo = new UserInfo(aslSession.getUsername(),
aslSession.getGroupId(), aslSession.getGroupName(),
aslSession.getScope(), aslSession.getScopeName(),
aslSession.getUserEmailAddress(),
aslSession.getUserFullName());
return userInfo;
} catch (AccountingManagerServiceException e) {
e.printStackTrace();
throw e;
} catch (Throwable e) {
e.printStackTrace();
logger.error("Hello(): " + e.getLocalizedMessage(), e);
throw new AccountingManagerServiceException(e.getLocalizedMessage());
}
}
/**
*
* {@inheritDoc}
*/
@Override
public SeriesResponse getSeries(AccountingType accountingType,
SeriesRequest seriesRequest)
throws AccountingManagerServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
AccountingCaller accountingCaller = new AccountingCaller();
SeriesResponse seriesResponse = accountingCaller.getSeries(
accountingType, seriesRequest);
return seriesResponse;
} catch (AccountingManagerServiceException e) {
e.printStackTrace();
throw e;
} catch (Throwable e) {
e.printStackTrace();
logger.error("getSeries(): " + e.getLocalizedMessage(), e);
throw new AccountingManagerServiceException(e.getLocalizedMessage());
}
}
@Override
public ArrayList<FilterKey> getFilterKeys(AccountingType accountingType)
throws AccountingManagerServiceException {
try {
HttpSession session = this.getThreadLocalRequest().getSession();
SessionUtil.getAslSession(session);
if (accountingType == null) {
return new ArrayList<FilterKey>();
}
switch (accountingType) {
case JOB:
return new ArrayList<FilterKey>();
case PORTLET:
return new ArrayList<FilterKey>();
case SERVICE:
return new ArrayList<FilterKey>(Arrays.asList(new FilterKey("consumerId"),
new FilterKey("host"), new FilterKey("scope"), new FilterKey("serviceName"),new FilterKey("serviceClass")));
case STORAGE:
return new ArrayList<FilterKey>(Arrays.asList(new FilterKey("consumerId"),
new FilterKey("dataType"), new FilterKey("scope"), new FilterKey("providerURI"), new FilterKey("resourceOwner")));
case TASK:
return new ArrayList<FilterKey>();
default:
return new ArrayList<FilterKey>();
}
} catch (AccountingManagerServiceException e) {
e.printStackTrace();
throw e;
} catch (Throwable e) {
e.printStackTrace();
logger.error("getFilterKeys(): " + e.getLocalizedMessage(), e);
throw new AccountingManagerServiceException(e.getLocalizedMessage());
}
}
}