|
|
|
@ -108,10 +108,17 @@ import org.gcube.portlets.widgets.exporter.shared.SaveReportFileExistException;
|
|
|
|
|
import org.gcube.portlets.widgets.exporter.shared.TypeExporter;
|
|
|
|
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
|
|
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.RoleManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayRoleManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.RoleModel;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
import com.liferay.portal.model.User;
|
|
|
|
|
import com.liferay.portal.model.UserModel;
|
|
|
|
|
import com.liferay.portal.service.LockLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
@ -129,10 +136,6 @@ import com.liferay.portlet.documentlibrary.model.DLFileEntry;
|
|
|
|
|
public class ReportServiceImpl extends RemoteServiceServlet implements ReportService {
|
|
|
|
|
|
|
|
|
|
private static final Logger _log = LoggerFactory.getLogger(ReportServiceImpl.class);
|
|
|
|
|
/**
|
|
|
|
|
* used for debugging in eclipse
|
|
|
|
|
*/
|
|
|
|
|
private boolean withinPortal = true;
|
|
|
|
|
|
|
|
|
|
public static final String TEST_SCOPE = "/gcube/devsec/devVRE";
|
|
|
|
|
//public static final String TEST_SCOPE = "/gcube/devNext/NextNext";
|
|
|
|
@ -195,16 +198,26 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|
|
|
|
SessionManager.getInstance().getASLSession(sessionID, user).setUserFullName(fullName);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!withinPortal)
|
|
|
|
|
_log.warn("\n\n****** Starting in Development MODE ******\n\n");
|
|
|
|
|
|
|
|
|
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public static String getDevUser() {
|
|
|
|
|
return "massimiliano.assante";
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return true if you're running into the portal, false if in development
|
|
|
|
|
*/
|
|
|
|
|
private boolean isWithinPortal() {
|
|
|
|
|
try {
|
|
|
|
|
UserLocalServiceUtil.getService();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
|
|
|
|
|
_log.trace("Development Mode ON");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the user saved template names
|
|
|
|
|
*
|
|
|
|
@ -1511,7 +1524,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|
|
|
|
String fullName = username+" FULL";
|
|
|
|
|
String thumbnailURL = "images/Avatar_default.png";
|
|
|
|
|
|
|
|
|
|
if (withinPortal) {
|
|
|
|
|
if (isWithinPortal()) {
|
|
|
|
|
|
|
|
|
|
UserModel user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
|
|
|
|
|
thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId();
|
|
|
|
@ -1641,13 +1654,61 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|
|
|
|
}
|
|
|
|
|
return rsgClient;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* the list of Regional Fishery Management Organizations (RFMO) associated to the current user is constructed by looking at the roles
|
|
|
|
|
* of the current user.
|
|
|
|
|
*
|
|
|
|
|
* @returnt the list of Regional Fishery Management Organizations (RFMO) associated to the current user.
|
|
|
|
|
*/
|
|
|
|
|
private ArrayList<String> getUserRFMOs() {
|
|
|
|
|
if (! isWithinPortal())
|
|
|
|
|
return new ArrayList<String>();
|
|
|
|
|
ArrayList<String> toReturn = new ArrayList<String>();
|
|
|
|
|
RoleManager rm = new LiferayRoleManager();
|
|
|
|
|
ASLSession session = getASLSession();
|
|
|
|
|
try {
|
|
|
|
|
User theUser = OrganizationsUtil.validateUser(session.getUsername());
|
|
|
|
|
List<RoleModel> roles = rm.listRolesByUserAndGroup(""+session.getGroupId(), ""+theUser.getUserId());
|
|
|
|
|
for (RoleModel role : roles) {
|
|
|
|
|
_log.info("Role " + role.getRoleName() + " Adding RFMO");
|
|
|
|
|
if (role.getRoleName().endsWith("-Editor")) {
|
|
|
|
|
String[] splits = role.getRoleName().split("-");
|
|
|
|
|
toReturn.add(splits[0]);
|
|
|
|
|
_log.info("Added grant for RFMO="+splits[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return whether the user is a VRE Manager for this VRE or not.
|
|
|
|
|
*/
|
|
|
|
|
private boolean isVREManager() {
|
|
|
|
|
if (isWithinPortal()) {
|
|
|
|
|
RoleManager rm = new LiferayRoleManager();
|
|
|
|
|
ASLSession session = getASLSession();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
User theUser = OrganizationsUtil.validateUser(session.getUsername());
|
|
|
|
|
List<RoleModel> roles = rm.listRolesByUserAndGroup(""+session.getGroupId(), ""+theUser.getUserId());
|
|
|
|
|
for (RoleModel role : roles)
|
|
|
|
|
if (role.getRoleName().equalsIgnoreCase("VRE-Manager")) return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
_log.warn("Working in Eclipse, returning all rights");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ArrayList<VMEReportBean> listVMEReports() {
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
}
|
|
|
|
|
ArrayList<VMEReportBean> toReturn = new ArrayList<VMEReportBean>();
|
|
|
|
|
ReportType type = new ReportType();
|
|
|
|
|
type.setTypeIdentifier("Vme");
|
|
|
|
@ -1655,10 +1716,35 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|
|
|
|
RsgClient rsgClient = getRsgSecureClient();
|
|
|
|
|
_log.debug("listVMEReports() securedWithEncryptedToken completed");
|
|
|
|
|
|
|
|
|
|
if (isVREManager()) {
|
|
|
|
|
for (ReportEntry re : rsgClient.listReports(type)) {
|
|
|
|
|
String rfmo = re.getOwner();
|
|
|
|
|
String name = re.getIdentifier();
|
|
|
|
|
toReturn.add(new VMEReportBean(""+re.getId(), rfmo, name));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ArrayList<String> allowedRFMOs = getUserRFMOs();
|
|
|
|
|
for (ReportEntry re : rsgClient.listReports(type)) {
|
|
|
|
|
String rfmo = re.getOwner().trim();
|
|
|
|
|
String name = re.getIdentifier();
|
|
|
|
|
for (String allowedRFMO : allowedRFMOs) {
|
|
|
|
|
if (allowedRFMO.compareTo(rfmo) == 0) {
|
|
|
|
|
toReturn.add(new VMEReportBean(""+re.getId(), rfmo, name));
|
|
|
|
|
_log.debug("Added " + rfmo + " - " + name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean isManager = isVREManager();
|
|
|
|
|
ArrayList<String> allowedRFMOs = getUserRFMOs();
|
|
|
|
|
|
|
|
|
|
for (ReportEntry re : rsgClient.listReports(type)) {
|
|
|
|
|
String rfmo = re.getOwner();
|
|
|
|
|
String name = re.getIdentifier();
|
|
|
|
|
toReturn.add(new VMEReportBean(""+re.getId(), rfmo, name));
|
|
|
|
|
if (isManager || allowedRFMOs.contains(rfmo))
|
|
|
|
|
toReturn.add(new VMEReportBean(""+re.getId(), rfmo, name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return toReturn;
|
|
|
|
|